#1173 Made the legend a separate hide/show entity, and changed the overall layout of the well allocation plot

This commit is contained in:
Jacob Støren
2017-02-13 08:40:27 +01:00
parent 30ea467f0e
commit 321b9e2d62
12 changed files with 1490 additions and 1171 deletions

View File

@@ -10,6 +10,7 @@ ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.h
${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.h
${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.h
${CEE_CURRENT_LIST_DIR}RimWellFlowRateCurve.h
${CEE_CURRENT_LIST_DIR}RimWellAllocationPlotLegend.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -18,6 +19,7 @@ ${CEE_CURRENT_LIST_DIR}RimFlowPlotCollection.cpp
${CEE_CURRENT_LIST_DIR}RimWellAllocationPlot.cpp
${CEE_CURRENT_LIST_DIR}RimTotalWellAllocationPlot.cpp
${CEE_CURRENT_LIST_DIR}RimWellFlowRateCurve.cpp
${CEE_CURRENT_LIST_DIR}RimWellAllocationPlotLegend.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -180,6 +180,7 @@ void RimTotalWellAllocationPlot::loadDataAndUpdate()
QWidget* RimTotalWellAllocationPlot::createViewWidget(QWidget* mainWindowParent)
{
m_wellTotalAllocationPlotWidget = new RiuNightchartsWidget(mainWindowParent);
m_wellTotalAllocationPlotWidget->showLegend(false);
return m_wellTotalAllocationPlotWidget;
}

View File

@@ -42,6 +42,7 @@
#include "RigAccWellFlowCalculator.h"
#include "RimProject.h"
#include "RiuWellLogTrack.h"
#include "RimWellAllocationPlotLegend.h"
CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot");
@@ -79,9 +80,12 @@ RimWellAllocationPlot::RimWellAllocationPlot()
CAF_PDM_InitFieldNoDefault(&m_totalWellAllocationPlot, "TotalWellFlowPlot", "Total Well Flow", "", "", "");
m_totalWellAllocationPlot.uiCapability()->setUiHidden(true);
m_totalWellAllocationPlot = new RimTotalWellAllocationPlot;
CAF_PDM_InitFieldNoDefault(&m_wellAllocationPlotLegend, "WellAllocLegend", "Legend", "", "", "");
m_wellAllocationPlotLegend.uiCapability()->setUiHidden(true);
m_wellAllocationPlotLegend = new RimWellAllocationPlotLegend;
this->setAsPlotMdiWindow();
}
@@ -264,6 +268,7 @@ void RimWellAllocationPlot::updateFromWell()
/// Pie chart
m_totalWellAllocationPlot->clearSlices();
m_wellAllocationPlotWidget->clearLegend();
if (wfCalculator)
{
@@ -293,13 +298,16 @@ void RimWellAllocationPlot::updateFromWell()
color = cvf::Color3f::DARK_GRAY;
m_totalWellAllocationPlot->addSlice(tracerVal.first, color, 100*tracerVal.second/sumTracerVals);
m_wellAllocationPlotWidget->addLegendItem(tracerVal.first, color, 100*tracerVal.second/sumTracerVals);
}
}
}
m_wellAllocationPlotWidget->showLegend(m_wellAllocationPlotLegend->isShowingLegend());
m_totalWellAllocationPlot->updateConnectedEditors();
accumulatedWellFlowPlot()->updateConnectedEditors();
m_wellAllocationPlotWidget->updateGeometry();
}
//--------------------------------------------------------------------------------------------------
@@ -514,6 +522,14 @@ void RimWellAllocationPlot::removeFromMdiAreaAndDeleteViewWidget()
deleteViewWidget();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::showPlotLegend(bool doShow)
{
m_wellAllocationPlotWidget->showLegend(doShow);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -31,6 +31,7 @@ class RimEclipseResultCase;
class RimEclipseWell;
class RimFlowDiagSolution;
class RimTotalWellAllocationPlot;
class RimWellAllocationPlotLegend;
class RimWellLogPlot;
class RiuWellAllocationPlot;
class RimWellLogTrack;
@@ -70,6 +71,7 @@ public:
void removeFromMdiAreaAndDeleteViewWidget();
void showPlotLegend(bool doShow);
protected:
// Overridden PDM methods
virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; }
@@ -107,4 +109,6 @@ private:
caf::PdmChildField<RimWellLogPlot*> m_accumulatedWellFlowPlot;
caf::PdmChildField<RimTotalWellAllocationPlot*> m_totalWellAllocationPlot;
caf::PdmChildField<RimWellAllocationPlotLegend*> m_wellAllocationPlotLegend;
};

View File

@@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimWellAllocationPlotLegend.h"
#include "RimWellAllocationPlot.h"
CAF_PDM_SOURCE_INIT(RimWellAllocationPlotLegend, "WellAllocationPlotLegend");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellAllocationPlotLegend::RimWellAllocationPlotLegend()
{
CAF_PDM_InitObject("Well Allocation Plot Legend", ":/newIcon16x16.png", "", "");
CAF_PDM_InitField(&m_showLegend, "ShowPlotLegend", true, "Show Plot Legend", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellAllocationPlotLegend::~RimWellAllocationPlotLegend()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimWellAllocationPlotLegend::objectToggleField()
{
return &m_showLegend;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlotLegend::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (changedField == &m_showLegend)
{
RimWellAllocationPlot* walp;
firstAncestorOrThisOfType(walp);
if (walp) walp->showPlotLegend(m_showLegend());
}
}

View File

@@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmField.h"
#include "cafPdmObject.h"
//==================================================================================================
///
///
//==================================================================================================
class RimWellAllocationPlotLegend : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimWellAllocationPlotLegend();
virtual ~RimWellAllocationPlotLegend();
bool isShowingLegend() { return m_showLegend();}
protected:
virtual caf::PdmFieldHandle* objectToggleField() override;
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
private:
caf::PdmField<bool> m_showLegend;
};

View File

@@ -25,6 +25,9 @@
RiuNightchartsWidget::RiuNightchartsWidget(QWidget* parent) :
QWidget(parent)
{
m_showLegend = true;
m_showPie = true;
updateSizePolicy();
clear();
}
@@ -36,6 +39,51 @@ void RiuNightchartsWidget::setType(Nightcharts::type t)
m_chart.setType(t);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuNightchartsWidget::showLegend(bool doShow)
{
m_showLegend = doShow;
updateSizePolicy();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuNightchartsWidget::showPie(bool doShow)
{
m_showPie = doShow;
updateSizePolicy();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuNightchartsWidget::updateSizePolicy()
{
if (m_showPie && m_showLegend)
{
this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
}
else if (m_showPie && !m_showLegend )
{
this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
}
else if (!m_showPie && m_showLegend )
{
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}
else
{
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -45,8 +93,49 @@ void RiuNightchartsWidget::clear()
m_chart.setType(Nightcharts::Pie);
m_chart.setLegendType(Nightcharts::Vertical);
m_marginLeft = 16;
m_marginTop = 16;
m_marginLeft = 10;
m_marginTop = 10;
m_maxNameWidth = 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuNightchartsWidget::sizeHint() const
{
int widthHint = 0;
int heightHint = 0;
int maxPieSize = 180;
if ( m_showLegend )
{
QPainter painter;
int lineHeight = painter.fontMetrics().height();
int lineCount = m_chart.pieceCount();
int exactLegendHeight = (lineCount + lineCount-1) * lineHeight;
widthHint = m_maxNameWidth + 5 + lineHeight;
heightHint = exactLegendHeight;
}
if (m_showPie)
{
widthHint = widthHint + maxPieSize;
heightHint = heightHint > maxPieSize ? heightHint : maxPieSize;
}
if ( m_showPie || m_showLegend )
{
widthHint += 2*m_marginLeft;
heightHint += 2*m_marginTop;
return QSize(widthHint, heightHint);
}
else
{
return QSize();
}
}
//--------------------------------------------------------------------------------------------------
@@ -59,21 +148,45 @@ void RiuNightchartsWidget::paintEvent(QPaintEvent* e)
if(!m_chart.pieceCount()) return ;
QPainter painter;
QFont font;
painter.begin(this);
int w = (this->width() - m_marginLeft - 150);
int h = (this->height() - m_marginTop - 100);
int size = (w<h)?w:h;
m_chart.setCords(m_marginLeft, m_marginTop,size, size);
m_chart.draw(&painter);
m_chart.drawLegend(&painter);
int legendWidth = 170;
int legendMargin = 20;
if (!m_showLegend)
{
legendWidth = 0;
legendMargin = 0;
}
int w = (this->width() - 2* m_marginLeft - legendWidth - legendMargin);
int h = (this->height() - 2* m_marginTop );
int size = ( w < h ) ? w : h;
if ( m_showPie )
{
m_chart.setCords(m_marginLeft, m_marginTop, size, size);
m_chart.setLegendCords(m_marginLeft + size + legendMargin, m_marginTop);
}
else
{
m_chart.setLegendCords(m_marginLeft, m_marginTop);
}
if (m_showPie) m_chart.draw(&painter);
if ( m_showLegend) m_chart.drawLegend(&painter);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuNightchartsWidget::addItem(QString name, QColor color, float value)
void RiuNightchartsWidget::addItem(const QString& name, const QColor& color, float value)
{
m_chart.addPiece(name,color,value);
m_chart.addPiece(name, color, value);
QPainter painter;
int textWidth = painter.fontMetrics().width(name + " (00 %)");
m_maxNameWidth = textWidth > m_maxNameWidth ? textWidth: m_maxNameWidth;
}

View File

@@ -33,16 +33,27 @@ class RiuNightchartsWidget : public QWidget
public:
explicit RiuNightchartsWidget(QWidget* parent = 0);
void addItem(QString name, QColor color, float value);
void addItem(const QString& name, const QColor& color, float value);
void setType(Nightcharts::type type);
void showLegend(bool doShow);
void showPie(bool doShow);
void clear();
virtual QSize sizeHint() const override;
protected:
virtual void paintEvent(QPaintEvent* e);
private:
void updateSizePolicy();
Nightcharts m_chart;
int m_marginLeft;
int m_marginTop;
int m_marginLeft;
int m_marginTop;
bool m_showLegend;
bool m_showPie;
int m_maxNameWidth;
};

View File

@@ -27,6 +27,8 @@
#include <QBoxLayout>
#include <QLabel>
#include "RiuNightchartsWidget.h"
#include "cvfColor3.h"
@@ -59,11 +61,19 @@ RiuWellAllocationPlot::RiuWellAllocationPlot(RimWellAllocationPlot* plotDefiniti
mainLayout->addWidget(m_titleLabel, 0, Qt::AlignCenter);
QHBoxLayout* plotWidgetsLayout = new QHBoxLayout();
mainLayout->addLayout(plotWidgetsLayout, 10);
auto plotWidgetsLayout = new QHBoxLayout();
auto rightColumnLayout = new QVBoxLayout();
mainLayout->addLayout(plotWidgetsLayout);
plotWidgetsLayout->addLayout(rightColumnLayout);
m_legendWidget = new RiuNightchartsWidget(this);
rightColumnLayout->addWidget(m_legendWidget);
m_legendWidget->showPie(false);
QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget(this);
plotWidgetsLayout->addWidget(totalFlowAllocationWidget);
rightColumnLayout->addWidget(totalFlowAllocationWidget);
rightColumnLayout->addStretch();
QWidget* wellFlowWidget = m_plotDefinition->accumulatedWellFlowPlot()->createViewWidget(this);
plotWidgetsLayout->addWidget(wellFlowWidget);
@@ -106,6 +116,39 @@ void RiuWellAllocationPlot::hideTitle()
m_titleLabel->hide();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::showLegend(bool doShow)
{
if (doShow)
m_legendWidget->show();
else
m_legendWidget->hide();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::addLegendItem(const QString& name, const cvf::Color3f& color, float value)
{
QColor sliceColor(color.rByte(), color.gByte(), color.bByte());
m_legendWidget->addItem(name, sliceColor, value);
m_legendWidget->updateGeometry();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellAllocationPlot::clearLegend()
{
m_legendWidget->clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -26,9 +26,14 @@
#include <QFrame>
class RimWellAllocationPlot;
class RiuNightchartsWidget;
class QLabel;
namespace cvf {
class Color3f;
}
//==================================================================================================
//
//
@@ -45,7 +50,9 @@ public:
void showTitle(const QString& title);
void hideTitle();
void showLegend(bool doShow);
void addLegendItem(const QString& name, const cvf::Color3f& color, float value);
void clearLegend();
protected:
virtual QSize sizeHint() const override;
virtual QSize minimumSizeHint() const override;
@@ -55,6 +62,7 @@ private:
private:
caf::PdmPointer<RimWellAllocationPlot> m_plotDefinition;
QPointer<RiuNightchartsWidget> m_legendWidget;
QPointer<QLabel> m_titleLabel;
};

View File

@@ -55,6 +55,8 @@ RiuWellLogPlot::RiuWellLogPlot(RimWellLogPlot* plotDefinition, QWidget* parent)
m_scrollBar->setOrientation(Qt::Vertical);
m_scrollBar->setVisible(true);
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
connect(m_scrollBar, SIGNAL(valueChanged(int)), this, SLOT(slotSetMinDepth(int)));
}
@@ -193,6 +195,14 @@ void RiuWellLogPlot::setDepthZoomAndReplot(double minDepth, double maxDepth)
updateScrollBar(minDepth, maxDepth);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiuWellLogPlot::sizeHint() const
{
return QSize(1,1);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -268,7 +278,7 @@ void RiuWellLogPlot::placeChildWidgets(int height, int width)
int maxLegendHeight = 0;
if (m_plotDefinition->isTrackLegendsVisible())
if (m_plotDefinition && m_plotDefinition->isTrackLegendsVisible())
{
for ( int tIdx = 0; tIdx < trackCount; ++tIdx )
{

View File

@@ -54,13 +54,14 @@ public:
void setDepthZoomAndReplot(double minDepth, double maxDepth);
public slots:
public slots:
void updateChildrenLayout();
protected:
virtual void resizeEvent(QResizeEvent *event);
virtual void showEvent(QShowEvent *);
virtual void changeEvent(QEvent *);
virtual QSize sizeHint() const override;
private:
void updateScrollBar(double minDepth, double maxDepth);