#8521 Summary Plot: Allow moving axis to other side of plot.

This commit is contained in:
Kristian Bendiksen
2022-02-09 15:14:32 +01:00
committed by Magne Sjaastad
parent 3e9d2a0af0
commit 6591de716b
6 changed files with 70 additions and 9 deletions

View File

@@ -51,6 +51,7 @@ CAF_PDM_SOURCE_INIT( RimPlotAxisProperties, "SummaryYAxisProperties" );
RimPlotAxisProperties::RimPlotAxisProperties()
: settingsChanged( this )
, logarithmicChanged( this )
, axisPositionChanged( this )
, m_enableTitleTextSettings( true )
, m_isRangeSettingsEnabled( true )
{
@@ -199,6 +200,8 @@ void RimPlotAxisProperties::defineUiOrdering( QString uiConfigName, caf::PdmUiOr
}
scaleGroup.add( &m_valuesFontSize );
scaleGroup.add( &m_plotAxis );
uiOrdering.skipRemainingFields( true );
}
@@ -421,6 +424,11 @@ void RimPlotAxisProperties::fieldChangedByUi( const caf::PdmFieldHandle* changed
{
logarithmicChanged.send( m_isLogarithmicScaleEnabled() );
}
else if ( changedField == &m_plotAxis )
{
RiuPlotAxis oldPlotAxis = RiuPlotAxis( (RiaDefines::PlotAxis)oldValue.toInt(), m_plotAxisIndex );
axisPositionChanged.send( this, oldPlotAxis, plotAxisType() );
}
else
{
settingsChanged.send();

View File

@@ -51,8 +51,9 @@ public:
};
public:
caf::Signal<> settingsChanged;
caf::Signal<bool> logarithmicChanged;
caf::Signal<> settingsChanged;
caf::Signal<bool> logarithmicChanged;
caf::Signal<RimPlotAxisProperties*, RiuPlotAxis, RiuPlotAxis> axisPositionChanged;
public:
RimPlotAxisProperties();
@@ -124,9 +125,9 @@ private:
caf::PdmField<double> m_visibleRangeMin;
caf::PdmField<double> m_visibleRangeMax;
caf::PdmField<QString> m_name;
caf::PdmField<QString> m_name;
caf::PdmField<caf::AppEnum<RiaDefines::PlotAxis>> m_plotAxis;
caf::PdmField<int> m_plotAxisIndex;
caf::PdmField<int> m_plotAxisIndex;
caf::PdmField<bool> m_isLogarithmicScaleEnabled;

View File

@@ -231,7 +231,10 @@ void RimSummaryPlot::updateAxes()
//--------------------------------------------------------------------------------------------------
bool RimSummaryPlot::isLogarithmicScaleEnabled( RiuPlotAxis plotAxis ) const
{
return axisPropertiesForPlotAxis( plotAxis )->isLogarithmicScaleEnabled();
auto axisProperties = axisPropertiesForPlotAxis( plotAxis );
if ( !axisProperties ) return false;
return axisProperties->isLogarithmicScaleEnabled();
}
//--------------------------------------------------------------------------------------------------
@@ -824,6 +827,8 @@ void RimSummaryPlot::updateAxis( RiaDefines::PlotAxis plotAxis )
void RimSummaryPlot::updateZoomForAxis( RiuPlotAxis plotAxis )
{
RimPlotAxisPropertiesInterface* yAxisProps = axisPropertiesForPlotAxis( plotAxis );
if ( !yAxisProps ) return;
if ( yAxisProps->isAutoZoom() )
{
if ( yAxisProps->isLogarithmicScaleEnabled() )
@@ -957,8 +962,6 @@ RimPlotAxisPropertiesInterface* RimSummaryPlot::axisPropertiesForPlotAxis( RiuPl
if ( axisProperties->plotAxisType() == plotAxis ) return axisProperties;
}
CVF_ASSERT( false && "No axis properties found for axis" );
return nullptr;
}
@@ -1692,6 +1695,7 @@ void RimSummaryPlot::connectAxisSignals( RimPlotAxisProperties* axis )
{
axis->settingsChanged.connect( this, &RimSummaryPlot::axisSettingsChanged );
axis->logarithmicChanged.connect( this, &RimSummaryPlot::axisLogarithmicChanged );
axis->axisPositionChanged.connect( this, &RimSummaryPlot::axisPositionChanged );
}
//--------------------------------------------------------------------------------------------------
@@ -1710,6 +1714,40 @@ void RimSummaryPlot::axisLogarithmicChanged( const caf::SignalEmitter* emitter,
loadDataAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::axisPositionChanged( const caf::SignalEmitter* emitter,
RimPlotAxisProperties* axisProperties,
RiuPlotAxis oldPlotAxis,
RiuPlotAxis newPlotAxis )
{
if ( !axisProperties ) return;
if ( plotWidget() && plotWidget()->isMultiAxisSupported() )
{
// Make sure the new axis on the correct side exists.
RiuPlotAxis fixedUpPlotAxis = plotWidget()->createNextPlotAxis( newPlotAxis.axis() );
// The index can change so need to update.
axisProperties->setNameAndAxis( axisProperties->name(), fixedUpPlotAxis.axis(), fixedUpPlotAxis.index() );
// Move all attached curves
for ( auto curve : summaryCurves() )
{
if ( curve->axisY() == oldPlotAxis ) curve->setLeftOrRightAxisY( fixedUpPlotAxis );
}
// Remove the now unused axis (but keep the default axis)
if ( oldPlotAxis != RiuPlotAxis::defaultLeft() && oldPlotAxis != RiuPlotAxis::defaultRight() )
{
auto oldAxisProperties = axisPropertiesForPlotAxis( oldPlotAxis );
if ( oldAxisProperties ) m_axisProperties.removeChildObject( oldAxisProperties );
}
}
updateAxes();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -256,6 +256,11 @@ private:
void connectAxisSignals( RimPlotAxisProperties* axis );
void axisSettingsChanged( const caf::SignalEmitter* emitter );
void axisLogarithmicChanged( const caf::SignalEmitter* emitter, bool isLogarithmic );
void axisPositionChanged( const caf::SignalEmitter* emitter,
RimPlotAxisProperties* axisProperties,
RiuPlotAxis oldPlotAxis,
RiuPlotAxis newPlotAxis );
void assignPlotAxis( RimSummaryCurve* curve );
private:

View File

@@ -114,7 +114,15 @@ bool RiuPlotAxis::operator<( const RiuPlotAxis& rhs ) const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuPlotAxis::operator==( const RiuPlotAxis& rhs )
bool RiuPlotAxis::operator==( const RiuPlotAxis& rhs ) const
{
return m_axis == rhs.m_axis && m_index == rhs.m_index;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiuPlotAxis::operator!=( const RiuPlotAxis& rhs ) const
{
return !( *this == rhs );
}

View File

@@ -38,7 +38,8 @@ public:
int index() const;
bool operator<( const RiuPlotAxis& rhs ) const;
bool operator==( const RiuPlotAxis& rhs );
bool operator==( const RiuPlotAxis& rhs ) const;
bool operator!=( const RiuPlotAxis& rhs ) const;
private:
RiaDefines::PlotAxis m_axis;