diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp index ebbdbc8c8b..13b4584273 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryCurveCreator.cpp @@ -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++ ) ); } } diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp index 3f73745439..b255fa9359 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicSummaryPlotFeatureImpl.cpp @@ -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 ) { diff --git a/ApplicationCode/ProjectDataModel/Summary/CMakeLists_files.cmake b/ApplicationCode/ProjectDataModel/Summary/CMakeLists_files.cmake index 2de9d1ed87..ff24487ddc 100644 --- a/ApplicationCode/ProjectDataModel/Summary/CMakeLists_files.cmake +++ b/ApplicationCode/ProjectDataModel/Summary/CMakeLists_files.cmake @@ -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 diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp index 369969e9a8..200e66a25f 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveFilter.cpp @@ -140,8 +140,8 @@ QList 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 ) ); } } } diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp index a7396418cd..d6dd4752cf 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp @@ -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::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( SINGLE_COLOR ), "Coloring Mode", "", "", "" ); + CAF_PDM_InitField( &m_colorMode, + "ColorMode", + caf::AppEnum( 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 RimEnsembleCurveSet::calculateValueOptions( const } else if ( fieldNeedingOptions == &m_colorMode ) { - auto singleColorOption = caf::AppEnum( RimEnsembleCurveSet::SINGLE_COLOR ); - auto byEnsParamOption = caf::AppEnum( 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( QListviewer() ) { - 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" ); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.h b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.h index bf98f96c91..bb59583e74 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleCurveSet.h @@ -37,10 +37,11 @@ #include "cafPdmPtrField.h" #include "RifEclipseSummaryAddressQMetaType.h" +#include "RimEnsembleParameterColorHandlerInterface.h" #include "cafPdmProxyValueField.h" -class QwtPlot; -class QwtPlotCurve; +#include + 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 NameParameterPair; - RimEnsembleCurveSet(); ~RimEnsembleCurveSet() override; @@ -90,20 +87,21 @@ public: void deleteEnsembleCurves(); void deleteStatisticsCurves(); - RimRegularLegendConfig* legendConfig(); - void onLegendDefinitionChanged(); + void onLegendDefinitionChanged(); void setSummaryCaseCollection( RimSummaryCaseCollection* sumCaseCollection ); RimSummaryCaseCollection* summaryCaseCollection() const; 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,9 +167,9 @@ private: caf::PdmField m_yValuesSummaryAddressUiField; caf::PdmField m_yPushButtonSelectSummaryAddress; - caf::PdmField> m_colorMode; - caf::PdmField m_color; - caf::PdmField m_ensembleParameter; + caf::PdmField m_colorMode; + caf::PdmField m_color; + caf::PdmField m_ensembleParameter; caf::PdmField> m_plotAxis; @@ -184,7 +182,8 @@ private: caf::PdmProxyValueField m_autoGeneratedName; caf::PdmChildField m_summaryAddressNameTools; - QwtPlotCurve* m_qwtPlotCurveForLegendText; + QwtPlotCurve* m_qwtPlotCurveForLegendText; + QPointer m_legendOverlayFrame; std::unique_ptr m_ensembleStatCase; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.cpp b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.cpp new file mode 100644 index 0000000000..12d56ae03b --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.cpp @@ -0,0 +1,17 @@ +#include "RimEnsembleParameterColorHandlerInterface.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +namespace caf +{ +template <> +void AppEnum::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 diff --git a/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.h b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.h new file mode 100644 index 0000000000..ffb41aa92b --- /dev/null +++ b/ApplicationCode/ProjectDataModel/Summary/RimEnsembleParameterColorHandlerInterface.h @@ -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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RimSummaryCaseCollection.h" +#include "cafAppEnum.h" + +#include + +class RimRegularLegendConfig; +class RiuCvfOverlayItemWidget; + +class QFrame; + +class RimEnsembleParameterColorHandlerInterface +{ +public: + enum class ColorMode + { + SINGLE_COLOR, + BY_ENSEMBLE_PARAM + }; + using ColorModeEnum = caf::AppEnum; + 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; +}; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp index d54785a247..b41246705a 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.cpp @@ -127,6 +127,30 @@ void EnsembleParameter::sortByBinnedVariation( std::vector& 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 ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h index 62be3de1bc..533b62fd75 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h @@ -89,6 +89,8 @@ public: static void sortByBinnedVariation( std::vector& parameterVector ); + static QString uiName( const NameParameterPair& paramPair ); + private: double stdDeviation() const; }; diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 8cf3559e16..80ad71ab11 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -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& 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 ); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index c122505c15..e9b2915687 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -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; diff --git a/ApplicationCode/UserInterface/RiuCvfOverlayItemWidget.cpp b/ApplicationCode/UserInterface/RiuCvfOverlayItemWidget.cpp index 4ff4efdaca..45dab304fa 100644 --- a/ApplicationCode/UserInterface/RiuCvfOverlayItemWidget.cpp +++ b/ApplicationCode/UserInterface/RiuCvfOverlayItemWidget.cpp @@ -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(); diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp index 094e0a235a..248d4c7386 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.cpp @@ -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 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(); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h index 1265385162..b6e14ec6e3 100644 --- a/ApplicationCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationCode/UserInterface/RiuQwtPlotWidget.h @@ -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 m_plotDefinition; QPoint m_clickPosition; @@ -136,6 +142,8 @@ private: QPointer m_plotPicker; bool m_draggable; + QList> m_overlayFrames; + struct CurveColors { QColor lineColor; diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index 75c39eea7d..9cbc4c88a5 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -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( 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() ); - } - } -} diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h index e243bc462e..db6a04588e 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h @@ -26,7 +26,7 @@ #include -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, QPointer> m_ensembleLegendWidgets; - QPointer m_zoomerLeft; QPointer m_zoomerRight; QPointer m_wheelZoomer;