Refactored ensemble parameter legends

This commit is contained in:
Gaute Lindkvist 2019-12-02 14:05:41 +01:00
parent c4951a5a03
commit f56a34843a
17 changed files with 249 additions and 220 deletions

View File

@ -495,7 +495,8 @@ void RicSummaryCurveCreator::updatePreviewCurvesFromCurveDefinitions(
size_t colorIndex = std::count_if( allCurveSets.begin(),
allCurveSets.end(),
[]( RimEnsembleCurveSet* curveSet ) {
return curveSet->colorMode() == RimEnsembleCurveSet::SINGLE_COLOR;
return curveSet->colorMode() ==
RimEnsembleCurveSet::ColorMode::SINGLE_COLOR;
} );
curveSet->setColor( RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f( colorIndex ) );
@ -792,7 +793,7 @@ void RicSummaryCurveCreator::applyAppearanceToAllPreviewCurves()
int colorIndex = 0;
for ( auto& curveSet : m_previewPlot->ensembleCurveSetCollection()->curveSets() )
{
if ( curveSet->colorMode() != RimEnsembleCurveSet::SINGLE_COLOR ) continue;
if ( curveSet->colorMode() != RimEnsembleCurveSet::ColorMode::SINGLE_COLOR ) continue;
curveSet->setColor( RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f( colorIndex++ ) );
}
}

View File

@ -431,7 +431,7 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin
if ( ensembleColoringStyle == PARAMETER || ensembleColoringStyle == LOG_PARAMETER )
{
curveSet->setColorMode( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM );
curveSet->setColorMode( RimEnsembleCurveSet::ColorMode::BY_ENSEMBLE_PARAM );
curveSet->setEnsembleParameter( ensembleColoringParameter );
if ( ensembleColoringStyle == LOG_PARAMETER )
@ -487,7 +487,7 @@ void RicSummaryPlotFeatureImpl::createSummaryPlotsFromArgumentLine( const QStrin
curveSet->setSummaryAddress( addr );
if ( ensembleColoringStyle == PARAMETER || ensembleColoringStyle == LOG_PARAMETER )
{
curveSet->setColorMode( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM );
curveSet->setColorMode( RimEnsembleCurveSet::ColorMode::BY_ENSEMBLE_PARAM );
curveSet->setEnsembleParameter( ensembleColoringParameter );
if ( ensembleColoringStyle == LOG_PARAMETER )
{

View File

@ -37,6 +37,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.h
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.h
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.h
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -77,6 +78,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimDerivedEnsembleCaseCollection.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSummaryPlotFilterTextCurveSetEditor.cpp
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleParameterColorHandlerInterface.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -140,8 +140,8 @@ QList<caf::PdmOptionItemInfo>
auto nameParameterPairs = curveSet->ensembleParameters();
for ( auto& nameParamPair : nameParameterPairs )
{
options.push_back( caf::PdmOptionItemInfo( RimEnsembleCurveSet::ensembleParameterUiName( nameParamPair ),
nameParamPair.first ) );
options.push_back(
caf::PdmOptionItemInfo( EnsembleParameter::uiName( nameParamPair ), nameParamPair.first ) );
}
}
}

View File

@ -46,6 +46,7 @@
#include "RimSummaryFilter.h"
#include "RimSummaryPlot.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuPlotMainWindow.h"
#include "RiuQwtPlotCurve.h"
#include "RiuSummaryCurveDefSelectionDialog.h"
@ -56,6 +57,7 @@
#include "cafPdmUiListEditor.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTreeOrdering.h"
#include "cafTitledOverlayFrame.h"
#include "cvfScalarMapper.h"
@ -75,20 +77,6 @@
RiuQwtSymbol::PointSymbolEnum statisticsCurveSymbolFromAddress( const RifEclipseSummaryAddress& address );
int statisticsCurveSymbolSize( RiuQwtSymbol::PointSymbolEnum symbol );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleCurveSet::ColorMode>::setUp()
{
addItem( RimEnsembleCurveSet::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM, "BY_ENSEMBLE_PARAM", "By Ensemble Parameter" );
setDefault( RimEnsembleCurveSet::SINGLE_COLOR );
}
} // namespace caf
CAF_PDM_SOURCE_INIT( RimEnsembleCurveSet, "RimEnsembleCurveSet" );
//--------------------------------------------------------------------------------------------------
@ -124,7 +112,13 @@ RimEnsembleCurveSet::RimEnsembleCurveSet()
m_yPushButtonSelectSummaryAddress.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
m_yPushButtonSelectSummaryAddress = false;
CAF_PDM_InitField( &m_colorMode, "ColorMode", caf::AppEnum<ColorMode>( SINGLE_COLOR ), "Coloring Mode", "", "", "" );
CAF_PDM_InitField( &m_colorMode,
"ColorMode",
caf::AppEnum<ColorMode>( ColorMode::SINGLE_COLOR ),
"Coloring Mode",
"",
"",
"" );
CAF_PDM_InitField( &m_color, "Color", cvf::Color3f( cvf::Color3::BLACK ), "Color", "", "", "" );
@ -189,7 +183,12 @@ RimEnsembleCurveSet::~RimEnsembleCurveSet()
if ( parentPlot && parentPlot->viewer() )
{
m_qwtPlotCurveForLegendText->detach();
parentPlot->removeEnsembleCurveSetLegend( this );
parentPlot->viewer()->removeOverlayFrame( m_legendOverlayFrame );
}
if ( m_legendOverlayFrame )
{
m_legendOverlayFrame->setParent( nullptr );
delete m_legendOverlayFrame;
}
delete m_qwtPlotCurveForLegendText;
@ -381,6 +380,14 @@ RimRegularLegendConfig* RimEnsembleCurveSet::legendConfig()
return m_legendConfig;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QFrame* RimEnsembleCurveSet::legendFrame() const
{
return m_legendOverlayFrame;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -442,7 +449,7 @@ void RimEnsembleCurveSet::setEnsembleParameter( const QString& parameterName )
//--------------------------------------------------------------------------------------------------
EnsembleParameter::Type RimEnsembleCurveSet::currentEnsembleParameterType() const
{
if ( m_colorMode() == BY_ENSEMBLE_PARAM )
if ( m_colorMode() == ColorMode::BY_ENSEMBLE_PARAM )
{
RimSummaryCaseCollection* group = m_yValuesSummaryCaseCollection();
QString parameterName = m_ensembleParameter();
@ -456,29 +463,6 @@ EnsembleParameter::Type RimEnsembleCurveSet::currentEnsembleParameterType() cons
return EnsembleParameter::TYPE_NONE;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimEnsembleCurveSet::ensembleParameterUiName( const RimEnsembleCurveSet::NameParameterPair& paramPair )
{
QString stem = paramPair.first;
QString variationString;
if ( paramPair.second.isNumeric() )
{
switch ( paramPair.second.variationBin )
{
case EnsembleParameter::LOW_VARIATION:
variationString = QString( " (Low variation)" );
case EnsembleParameter::MEDIUM_VARIATION:
break;
case EnsembleParameter::HIGH_VARIATION:
variationString = QString( " (High variation)" );
break;
}
}
return QString( "%1%2" ).arg( stem ).arg( variationString );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -669,11 +653,11 @@ void RimEnsembleCurveSet::appendColorGroup( caf::PdmUiOrdering& uiOrdering )
m_colorMode.uiCapability()->setUiReadOnly( !m_yValuesSummaryCaseCollection() );
colorsGroup->add( &m_colorMode );
if ( m_colorMode == SINGLE_COLOR )
if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
colorsGroup->add( &m_color );
}
else if ( m_colorMode == BY_ENSEMBLE_PARAM )
else if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
m_ensembleParameter.uiCapability()->setUiReadOnly( !m_yValuesSummaryCaseCollection() );
colorsGroup->add( &m_ensembleParameter );
@ -685,7 +669,7 @@ void RimEnsembleCurveSet::appendColorGroup( caf::PdmUiOrdering& uiOrdering )
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ )
{
if ( m_colorMode == BY_ENSEMBLE_PARAM )
if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
uiTreeOrdering.add( m_legendConfig() );
}
@ -779,21 +763,21 @@ QList<caf::PdmOptionItemInfo> RimEnsembleCurveSet::calculateValueOptions( const
}
else if ( fieldNeedingOptions == &m_colorMode )
{
auto singleColorOption = caf::AppEnum<RimEnsembleCurveSet::ColorMode>( RimEnsembleCurveSet::SINGLE_COLOR );
auto byEnsParamOption = caf::AppEnum<RimEnsembleCurveSet::ColorMode>( RimEnsembleCurveSet::BY_ENSEMBLE_PARAM );
auto singleColorOption = ColorModeEnum( ColorMode::SINGLE_COLOR );
auto byEnsParamOption = ColorModeEnum( ColorMode::BY_ENSEMBLE_PARAM );
options.push_back( caf::PdmOptionItemInfo( singleColorOption.uiText(), RimEnsembleCurveSet::SINGLE_COLOR ) );
options.push_back( caf::PdmOptionItemInfo::fromEnumClass( singleColorOption.uiText(), ColorMode::SINGLE_COLOR ) );
if ( !ensembleParameters().empty() )
{
options.push_back(
caf::PdmOptionItemInfo( byEnsParamOption.uiText(), RimEnsembleCurveSet::BY_ENSEMBLE_PARAM ) );
caf::PdmOptionItemInfo::fromEnumClass( byEnsParamOption.uiText(), ColorMode::BY_ENSEMBLE_PARAM ) );
}
}
else if ( fieldNeedingOptions == &m_ensembleParameter )
{
for ( const auto& paramPair : ensembleParameters() )
{
options.push_back( caf::PdmOptionItemInfo( ensembleParameterUiName( paramPair ), paramPair.first ) );
options.push_back( caf::PdmOptionItemInfo( EnsembleParameter::uiName( paramPair ), paramPair.first ) );
}
}
else if ( fieldNeedingOptions == &m_yValuesSummaryAddressUiField )
@ -841,7 +825,7 @@ void RimEnsembleCurveSet::appendOptionItemsForSummaryAddresses( QList<caf::PdmOp
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::updateCurveColors()
{
if ( m_colorMode == BY_ENSEMBLE_PARAM )
if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
RimSummaryCaseCollection* group = m_yValuesSummaryCaseCollection();
@ -938,7 +922,7 @@ void RimEnsembleCurveSet::updateCurveColors()
}
}
}
else if ( m_colorMode == SINGLE_COLOR )
else if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
for ( auto& curve : m_curves )
{
@ -954,14 +938,22 @@ void RimEnsembleCurveSet::updateCurveColors()
firstAncestorOrThisOfType( plot );
if ( plot && plot->viewer() )
{
if ( m_yValuesSummaryCaseCollection() && isCurvesVisible() && m_colorMode == BY_ENSEMBLE_PARAM &&
if ( m_yValuesSummaryCaseCollection() && isCurvesVisible() && m_colorMode == ColorMode::BY_ENSEMBLE_PARAM &&
m_legendConfig->showLegend() )
{
plot->addOrUpdateEnsembleCurveSetLegend( this );
if ( !m_legendOverlayFrame )
{
m_legendOverlayFrame = new RiuCvfOverlayItemWidget( plot->viewer(), plot->viewer()->canvas() );
}
m_legendOverlayFrame->updateFromOverlayItem( m_legendConfig()->titledOverlayFrame() );
plot->viewer()->addOverlayFrame( m_legendOverlayFrame );
}
else
{
plot->removeEnsembleCurveSetLegend( this );
if ( !m_legendOverlayFrame.isNull() )
{
plot->viewer()->removeOverlayFrame( m_legendOverlayFrame );
}
}
plot->viewer()->scheduleReplot();
}
@ -1278,7 +1270,7 @@ void RimEnsembleCurveSet::updateEnsembleLegendItem()
{
QwtSymbol* symbol = nullptr;
if ( m_colorMode == SINGLE_COLOR )
if ( m_colorMode == ColorMode::SINGLE_COLOR )
{
symbol = new QwtSymbol( QwtSymbol::HLine );
@ -1289,7 +1281,7 @@ void RimEnsembleCurveSet::updateEnsembleLegendItem()
symbol->setPen( curvePen );
symbol->setSize( 6, 6 );
}
else if ( m_colorMode == BY_ENSEMBLE_PARAM )
else if ( m_colorMode == ColorMode::BY_ENSEMBLE_PARAM )
{
QPixmap p = QPixmap( ":/Legend.png" );

View File

@ -37,10 +37,11 @@
#include "cafPdmPtrField.h"
#include "RifEclipseSummaryAddressQMetaType.h"
#include "RimEnsembleParameterColorHandlerInterface.h"
#include "cafPdmProxyValueField.h"
class QwtPlot;
class QwtPlotCurve;
#include <QPointer>
class RimSummaryCase;
class RimSummaryCaseCollection;
class RimSummaryCurve;
@ -50,25 +51,21 @@ class RimSummaryPlotSourceStepping;
class RimSummaryCurveAutoName;
class RimEnsembleCurveFilterCollection;
class RimEnsembleStatistics;
class QKeyEvent;
class RimEnsembleStatisticsCase;
class RiuCvfOverlayItemWidget;
class QwtPlot;
class QwtPlotCurve;
class QKeyEvent;
//==================================================================================================
///
//==================================================================================================
class RimEnsembleCurveSet : public caf::PdmObject
class RimEnsembleCurveSet : public caf::PdmObject, public RimEnsembleParameterColorHandlerInterface
{
CAF_PDM_HEADER_INIT;
public:
enum ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
typedef std::pair<QString, EnsembleParameter> NameParameterPair;
RimEnsembleCurveSet();
~RimEnsembleCurveSet() override;
@ -90,7 +87,6 @@ public:
void deleteEnsembleCurves();
void deleteStatisticsCurves();
RimRegularLegendConfig* legendConfig();
void onLegendDefinitionChanged();
void setSummaryCaseCollection( RimSummaryCaseCollection* sumCaseCollection );
@ -98,12 +94,14 @@ public:
RimEnsembleCurveFilterCollection* filterCollection() const;
ColorMode colorMode() const;
void setColorMode( ColorMode mode );
void setEnsembleParameter( const QString& parameterName );
void updateEnsembleLegendItem();
ColorMode colorMode() const override;
void setColorMode( ColorMode mode ) override;
void setEnsembleParameter( const QString& parameterName ) override;
void updateEnsembleLegendItem() override;
RimRegularLegendConfig* legendConfig() override;
QFrame* legendFrame() const override;
EnsembleParameter::Type currentEnsembleParameterType() const;
static QString ensembleParameterUiName( const NameParameterPair& paramPair );
void updateAllCurves();
void updateStatisticsCurves();
@ -169,7 +167,7 @@ private:
caf::PdmField<RifEclipseSummaryAddress> m_yValuesSummaryAddressUiField;
caf::PdmField<bool> m_yPushButtonSelectSummaryAddress;
caf::PdmField<caf::AppEnum<ColorMode>> m_colorMode;
caf::PdmField<ColorModeEnum> m_colorMode;
caf::PdmField<cvf::Color3f> m_color;
caf::PdmField<QString> m_ensembleParameter;
@ -185,6 +183,7 @@ private:
caf::PdmChildField<RimSummaryCurveAutoName*> m_summaryAddressNameTools;
QwtPlotCurve* m_qwtPlotCurveForLegendText;
QPointer<RiuCvfOverlayItemWidget> m_legendOverlayFrame;
std::unique_ptr<RimEnsembleStatisticsCase> m_ensembleStatCase;

View File

@ -0,0 +1,17 @@
#include "RimEnsembleParameterColorHandlerInterface.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
namespace caf
{
template <>
void AppEnum<RimEnsembleParameterColorHandlerInterface::ColorMode>::setUp()
{
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR, "SINGLE_COLOR", "Single Color" );
addItem( RimEnsembleParameterColorHandlerInterface::ColorMode::BY_ENSEMBLE_PARAM,
"BY_ENSEMBLE_PARAM",
"By Ensemble Parameter" );
setDefault( RimEnsembleParameterColorHandlerInterface::ColorMode::SINGLE_COLOR );
}
} // namespace caf

View File

@ -0,0 +1,49 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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 "RimSummaryCaseCollection.h"
#include "cafAppEnum.h"
#include <utility>
class RimRegularLegendConfig;
class RiuCvfOverlayItemWidget;
class QFrame;
class RimEnsembleParameterColorHandlerInterface
{
public:
enum class ColorMode
{
SINGLE_COLOR,
BY_ENSEMBLE_PARAM
};
using ColorModeEnum = caf::AppEnum<ColorMode>;
using NameParameterPair = EnsembleParameter::NameParameterPair;
public:
virtual ColorMode colorMode() const = 0;
virtual void setColorMode( ColorMode mode ) = 0;
virtual void setEnsembleParameter( const QString& parameterName ) = 0;
virtual void updateEnsembleLegendItem() = 0;
virtual RimRegularLegendConfig* legendConfig() = 0;
virtual QFrame* legendFrame() const = 0;
};

View File

@ -127,6 +127,30 @@ void EnsembleParameter::sortByBinnedVariation( std::vector<NameParameterPair>& p
return lhs.second.variationBin > rhs.second.variationBin;
} );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString EnsembleParameter::uiName( const NameParameterPair& paramPair )
{
QString stem = paramPair.first;
QString variationString;
if ( paramPair.second.isNumeric() )
{
switch ( paramPair.second.variationBin )
{
case LOW_VARIATION:
variationString = QString( " (Low variation)" );
case MEDIUM_VARIATION:
break;
case HIGH_VARIATION:
variationString = QString( " (High variation)" );
break;
}
}
return QString( "%1%2" ).arg( stem ).arg( variationString );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -89,6 +89,8 @@ public:
static void sortByBinnedVariation( std::vector<NameParameterPair>& parameterVector );
static QString uiName( const NameParameterPair& paramPair );
private:
double stdDeviation() const;
};

View File

@ -683,7 +683,7 @@ size_t RimSummaryPlot::singleColorCurveCount() const
{
auto allCurveSets = ensembleCurveSetCollection()->curveSets();
size_t colorIndex = std::count_if( allCurveSets.begin(), allCurveSets.end(), []( RimEnsembleCurveSet* curveSet ) {
return curveSet->colorMode() == RimEnsembleCurveSet::SINGLE_COLOR;
return curveSet->colorMode() == RimEnsembleCurveSet::ColorMode::SINGLE_COLOR;
} );
colorIndex += curveCount();
@ -711,7 +711,7 @@ void RimSummaryPlot::applyDefaultCurveAppearances()
int colorIndex = 0;
for ( auto& curveSet : this->ensembleCurveSetCollection()->curveSets() )
{
if ( curveSet->colorMode() != RimEnsembleCurveSet::SINGLE_COLOR ) continue;
if ( curveSet->colorMode() != RimEnsembleCurveSet::ColorMode::SINGLE_COLOR ) continue;
curveSet->setColor( RiaColorTables::summaryCurveDefaultPaletteColors().cycledColor3f( colorIndex++ ) );
}
}
@ -1227,9 +1227,10 @@ void RimSummaryPlot::deleteCurves( const std::vector<RimSummaryCurve*>& curves )
curveSet->deleteCurve( curve );
if ( curveSet->curves().empty() )
{
if ( curveSet->colorMode() == RimEnsembleCurveSet::BY_ENSEMBLE_PARAM && m_plotWidget )
if ( curveSet->colorMode() == RimEnsembleCurveSet::ColorMode::BY_ENSEMBLE_PARAM &&
m_plotWidget )
{
m_plotWidget->removeEnsembleCurveSetLegend( curveSet );
m_plotWidget->removeOverlayFrame( curveSet->legendFrame() );
}
m_ensembleCurveSetCollection->deleteCurveSet( curveSet );
}
@ -1526,28 +1527,6 @@ void RimSummaryPlot::cleanupBeforeClose()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet )
{
if ( m_plotWidget )
{
m_plotWidget->addOrUpdateEnsembleCurveSetLegend( curveSet );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet )
{
if ( m_plotWidget )
{
m_plotWidget->removeEnsembleCurveSetLegend( curveSet );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -170,9 +170,6 @@ public:
void onAxisSelected( int axis, bool toggle ) override;
void addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet );
void removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSet );
public:
// RimViewWindow overrides
QWidget* createViewWidget( QWidget* mainWindowParent = nullptr ) override;

View File

@ -59,6 +59,8 @@ RiuCvfOverlayItemWidget::~RiuCvfOverlayItemWidget() {}
//--------------------------------------------------------------------------------------------------
void RiuCvfOverlayItemWidget::updateFromOverlayItem( caf::TitledOverlayFrame* item )
{
item->setRenderSize( item->preferredSize() );
unsigned int width = item->renderSize().x();
unsigned int height = item->renderSize().y();

View File

@ -429,6 +429,38 @@ void RiuQwtPlotWidget::setWidgetState( const QString& widgetState )
m_plotStyleSheet.setWidgetState( this, widgetState );
}
//--------------------------------------------------------------------------------------------------
/// Adds an overlay frame. The overlay frame becomes the responsibility of the plot widget
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::addOverlayFrame( QFrame* overlayFrame )
{
if ( std::find( m_overlayFrames.begin(), m_overlayFrames.end(), overlayFrame ) == m_overlayFrames.end() )
{
overlayFrame->setParent( this );
m_overlayFrames.push_back( overlayFrame );
updateLayout();
}
}
//--------------------------------------------------------------------------------------------------
/// Remove the overlay widget. The frame becomes the responsibility of the caller
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::removeOverlayFrame( QFrame* overlayFrame )
{
overlayFrame->hide();
overlayFrame->setParent( nullptr );
m_overlayFrames.removeOne( overlayFrame );
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::updateLayout()
{
QwtPlot::updateLayout();
updateOverlayFrameLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -642,6 +674,36 @@ caf::UiStyleSheet RiuQwtPlotWidget::createCanvasStyleSheet() const
return styleSheet;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::updateOverlayFrameLayout()
{
const int spacing = 5;
int startMarginX = this->canvas()->pos().x() + spacing;
int startMarginY = this->canvas()->pos().y() + spacing;
int xpos = startMarginX;
int ypos = startMarginY;
int maxColumnWidth = 0;
for ( QPointer<QFrame> frame : m_overlayFrames )
{
if ( !frame.isNull() )
{
if ( ypos + frame->height() + spacing > this->canvas()->height() )
{
xpos += spacing + maxColumnWidth;
ypos = startMarginY;
maxColumnWidth = 0;
}
frame->move( xpos, ypos );
ypos += frame->height() + spacing;
maxColumnWidth = std::max( maxColumnWidth, frame->width() );
frame->show();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -100,6 +100,10 @@ public:
void scheduleReplot();
void setWidgetState( const QString& widgetState );
void addOverlayFrame( QFrame* overlayWidget );
void removeOverlayFrame( QFrame* overlayWidget );
void updateLayout() override;
protected:
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
@ -128,6 +132,8 @@ private:
caf::UiStyleSheet createPlotStyleSheet() const;
caf::UiStyleSheet createCanvasStyleSheet() const;
void updateOverlayFrameLayout();
private:
caf::PdmPointer<RimPlot> m_plotDefinition;
QPoint m_clickPosition;
@ -136,6 +142,8 @@ private:
QPointer<QwtPlotPicker> m_plotPicker;
bool m_draggable;
QList<QPointer<QFrame>> m_overlayFrames;
struct CurveColors
{
QColor lineColor;

View File

@ -22,6 +22,7 @@
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimEnsembleParameterColorHandlerInterface.h"
#include "RimMainPlotCollection.h"
#include "RimPlot.h"
#include "RimRegularLegendConfig.h"
@ -156,57 +157,6 @@ void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
setAxisScaleDraw( QwtPlot::xBottom, new QwtScaleDraw() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSetToShowLegendFor )
{
RiuCvfOverlayItemWidget* overlayWidget = nullptr;
auto it = m_ensembleLegendWidgets.find( curveSetToShowLegendFor );
if ( it == m_ensembleLegendWidgets.end() || it->second == nullptr )
{
overlayWidget = new RiuCvfOverlayItemWidget( this, canvas() );
m_ensembleLegendWidgets[curveSetToShowLegendFor] = overlayWidget;
}
else
{
overlayWidget = it->second;
}
if ( overlayWidget )
{
caf::TitledOverlayFrame* overlayItem = curveSetToShowLegendFor->legendConfig()->titledOverlayFrame();
overlayItem->setRenderSize( overlayItem->preferredSize() );
overlayWidget->updateFromOverlayItem( curveSetToShowLegendFor->legendConfig()->titledOverlayFrame() );
overlayWidget->show();
}
this->updateLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSetToShowLegendFor )
{
auto it = m_ensembleLegendWidgets.find( curveSetToShowLegendFor );
if ( it != m_ensembleLegendWidgets.end() )
{
if ( it->second != nullptr )
{
it->second->hide();
it->second->setParent( nullptr );
delete it->second;
}
m_ensembleLegendWidgets.erase( it );
}
this->updateLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -303,15 +253,6 @@ void RiuSummaryQwtPlot::setDefaults()
useDateBasedTimeAxis( dateFormat, timeFormat );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::updateLayout()
{
QwtPlot::updateLayout();
updateLegendLayout();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -338,41 +279,3 @@ void RiuSummaryQwtPlot::onZoomedSlot()
plotDefinition()->setAutoScaleYEnabled( false );
plotDefinition()->updateZoomFromQwt();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::updateLegendLayout()
{
const int spacing = 5;
int startMarginX = this->canvas()->pos().x() + spacing;
int startMarginY = this->canvas()->pos().y() + spacing;
int xpos = startMarginX;
int ypos = startMarginY;
int maxColumnWidth = 0;
RimSummaryPlot* summaryPlot = dynamic_cast<RimSummaryPlot*>( plotDefinition() );
if ( !summaryPlot || !summaryPlot->ensembleCurveSetCollection() ) return;
for ( RimEnsembleCurveSet* curveSet : summaryPlot->ensembleCurveSetCollection()->curveSets() )
{
auto pairIt = m_ensembleLegendWidgets.find( curveSet );
if ( pairIt != m_ensembleLegendWidgets.end() )
{
if ( ypos + pairIt->second->height() + spacing > this->canvas()->height() )
{
xpos += spacing + maxColumnWidth;
ypos = startMarginY;
maxColumnWidth = 0;
}
RiuCvfOverlayItemWidget* overlayWidget = pairIt->second;
overlayWidget->move( xpos, ypos );
ypos += pairIt->second->height() + spacing;
maxColumnWidth = std::max( maxColumnWidth, pairIt->second->width() );
}
}
}

View File

@ -26,7 +26,7 @@
#include <QPointer>
class RimEnsembleCurveSet;
class RimEnsembleParameterColorHandlerInterface;
class RiuCvfOverlayItemWidget;
class RiuQwtPlotZoomer;
class RiuQwtPlotWheelZoomer;
@ -52,9 +52,6 @@ public:
void useTimeBasedTimeAxis();
void addOrUpdateEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSetToShowLegendFor );
void removeEnsembleCurveSetLegend( RimEnsembleCurveSet* curveSetToShowLegendFor );
RimViewWindow* ownerViewWindow() const override;
void setLegendFontSize( int fontSize );
@ -66,7 +63,6 @@ protected:
void keyPressEvent( QKeyEvent* ) override;
void contextMenuEvent( QContextMenuEvent* ) override;
void setDefaults();
void updateLayout() override;
bool isZoomerActive() const override;
void endZoomOperations() override;
@ -74,10 +70,6 @@ private slots:
void onZoomedSlot();
private:
void updateLegendLayout();
std::map<caf::PdmPointer<RimEnsembleCurveSet>, QPointer<RiuCvfOverlayItemWidget>> m_ensembleLegendWidgets;
QPointer<RiuQwtPlotZoomer> m_zoomerLeft;
QPointer<RiuQwtPlotZoomer> m_zoomerRight;
QPointer<RiuQwtPlotWheelZoomer> m_wheelZoomer;