Skip to content

Commit 4798a87

Browse files
committed
Refactor based on review
Harmonize plot title enablement for sub-plots Encapsulate tracking annotation management in RimCorrelationReportPlot Improve snapshot capture in RimCorrelationReportPlot
1 parent c49b698 commit 4798a87

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationMatrixPlot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void RimCorrelationMatrixPlot::updatePlotTitle()
662662
if ( m_plotWidget )
663663
{
664664
m_plotWidget->setPlotTitle( m_description );
665-
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && !isSubPlot() );
665+
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle );
666666
if ( isMdiWindow() )
667667
{
668668
m_plotWidget->setPlotTitleFontSize( titleFontSize() );

ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationPlot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void RimCorrelationPlot::updatePlotTitle()
268268
m_description = QString( "%1, %2 at %3" ).arg( vectorName ).arg( ensemble->name() ).arg( timeStepString() );
269269
}
270270
m_plotWidget->setPlotTitle( m_description );
271-
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && !isSubPlot() );
271+
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle );
272272
m_plotWidget->setPlotTitleFontSize( titleFontSize() );
273273
}
274274

ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimCorrelationReportPlot.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,10 @@ class TimeReadoutPicker : public QwtPlotPicker
113113
auto* timeAxisProps = m_summaryPlot->timeAxisProperties();
114114
if ( timeAxisProps )
115115
{
116-
if ( m_trackingAnnotation )
117-
{
118-
timeAxisProps->removeAnnotation( m_trackingAnnotation );
119-
m_trackingAnnotation = nullptr;
120-
}
116+
removeTrackingAnnotation( timeAxisProps );
121117
auto* anno = RimTimeAxisAnnotation::createTimeAnnotation( timeTValue, TRACKING_ANNOTATION_COLOR );
122118
anno->setPenStyle( Qt::DashLine );
123119
timeAxisProps->appendAnnotation( anno );
124-
m_trackingAnnotation = anno;
125120
}
126121

127122
m_summaryPlot->updateAnnotationsInPlotWidget();
@@ -132,22 +127,34 @@ class TimeReadoutPicker : public QwtPlotPicker
132127

133128
void widgetLeaveEvent( QEvent* ) override
134129
{
135-
if ( m_trackingAnnotation && m_summaryPlot )
130+
if ( !m_summaryPlot ) return;
131+
132+
auto* timeAxisProps = m_summaryPlot->timeAxisProperties();
133+
if ( timeAxisProps && removeTrackingAnnotation( timeAxisProps ) )
136134
{
137-
auto* timeAxisProps = m_summaryPlot->timeAxisProperties();
138-
if ( timeAxisProps )
139-
{
140-
timeAxisProps->removeAnnotation( m_trackingAnnotation );
141-
m_trackingAnnotation = nullptr;
142-
}
143135
m_summaryPlot->updateAnnotationsInPlotWidget();
144136
m_summaryPlot->updatePlotWidgetFromAxisRanges();
145137
}
146138
}
147139

148140
private:
149-
caf::PdmPointer<RimSummaryPlot> m_summaryPlot;
150-
mutable caf::PdmPointer<RimTimeAxisAnnotation> m_trackingAnnotation;
141+
static bool removeTrackingAnnotation( RimSummaryTimeAxisProperties* timeAxisProps )
142+
{
143+
if ( !timeAxisProps ) return false;
144+
for ( auto* anno : timeAxisProps->annotations() )
145+
{
146+
// Identify the tracking annotation by its pen style, which is unique among time axis annotations. This way we don't interfere
147+
// with the selected-time annotation, which is also on the time axis.
148+
if ( anno->penStyle() == Qt::DashLine )
149+
{
150+
timeAxisProps->removeAnnotation( dynamic_cast<RimTimeAxisAnnotation*>( anno ) );
151+
return true;
152+
}
153+
}
154+
return false;
155+
}
156+
157+
caf::PdmPointer<RimSummaryPlot> m_summaryPlot;
151158
};
152159

153160
namespace
@@ -280,8 +287,15 @@ QString RimCorrelationReportPlot::description() const
280287
//--------------------------------------------------------------------------------------------------
281288
QImage RimCorrelationReportPlot::snapshotWindowContent()
282289
{
283-
if ( m_viewWidget ) return m_viewWidget->grab().toImage();
284-
return {};
290+
QImage image;
291+
292+
if ( m_viewWidget )
293+
{
294+
QPixmap pix = m_viewWidget->grab();
295+
image = pix.toImage();
296+
}
297+
298+
return image;
285299
}
286300

287301
//--------------------------------------------------------------------------------------------------
@@ -580,13 +594,8 @@ void RimCorrelationReportPlot::onLoadDataAndUpdate()
580594
m_parameterResultCrossPlot->setAxisValueFontSize( m_axisValueFontSize() );
581595

582596
m_correlationMatrixPlot->loadDataAndUpdate();
583-
if ( m_correlationMatrixPlot->viewer() ) m_correlationMatrixPlot->viewer()->setPlotTitleEnabled( true );
584-
585597
m_correlationPlot->loadDataAndUpdate();
586-
if ( m_correlationPlot->viewer() ) m_correlationPlot->viewer()->setPlotTitleEnabled( true );
587-
588598
m_parameterResultCrossPlot->loadDataAndUpdate();
589-
if ( m_parameterResultCrossPlot->viewer() ) m_parameterResultCrossPlot->viewer()->setPlotTitleEnabled( true );
590599

591600
if ( m_showSummaryPlot() )
592601
{

ApplicationLibCode/ProjectDataModel/CorrelationPlots/RimParameterResultCrossPlot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,6 @@ void RimParameterResultCrossPlot::updatePlotTitle()
658658
QString( "%1 x %2, %3 at %4" ).arg( vectorName ).arg( m_ensembleParameter ).arg( ensemble->name() ).arg( timeStepString() );
659659
}
660660
m_plotWidget->setPlotTitle( m_description );
661-
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle && !isSubPlot() );
661+
m_plotWidget->setPlotTitleEnabled( m_showPlotTitle );
662662
m_plotWidget->setPlotTitleFontSize( titleFontSize() );
663663
}

0 commit comments

Comments
 (0)