From 11060078d8d35bbcdb5335e25c3949cc85c5d563 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 1 Apr 2022 15:57:11 +0200 Subject: [PATCH] RiuQwtPlotWidget: fix actions on selection of axis. --- .../AnalysisPlots/RimAnalysisPlot.cpp | 6 +-- .../AnalysisPlots/RimAnalysisPlot.h | 2 +- .../Flow/RimWellDistributionPlot.cpp | 2 +- .../Flow/RimWellDistributionPlot.h | 2 +- .../GridCrossPlots/RimGridCrossPlot.cpp | 6 +-- .../GridCrossPlots/RimGridCrossPlot.h | 2 +- .../ProjectDataModel/RimPlot.cpp | 2 +- ApplicationLibCode/ProjectDataModel/RimPlot.h | 4 +- .../Summary/RimSummaryPlot.cpp | 23 +---------- .../ProjectDataModel/Summary/RimSummaryPlot.h | 2 +- .../WellLog/RimWellLogTrack.cpp | 2 +- .../WellLog/RimWellLogTrack.h | 2 +- .../UserInterface/RiuQwtPlotWidget.cpp | 41 +++++++++++-------- .../UserInterface/RiuQwtPlotWidget.h | 4 +- 14 files changed, 47 insertions(+), 53 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp b/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp index dee648804b..ed4ea897ae 100644 --- a/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp @@ -905,12 +905,12 @@ void RimAnalysisPlot::updateAxes() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimAnalysisPlot::onAxisSelected( int axis, bool toggle ) +void RimAnalysisPlot::onAxisSelected( RiuPlotAxis axis, bool toggle ) { RiuPlotMainWindowTools::showPlotMainWindow(); caf::PdmObject* itemToSelect = nullptr; - if ( axis == QwtAxis::YLeft ) + if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ) { if ( m_barOrientation == BARS_VERTICAL ) { @@ -921,7 +921,7 @@ void RimAnalysisPlot::onAxisSelected( int axis, bool toggle ) itemToSelect = this; } } - else if ( axis == QwtAxis::XBottom ) + else if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM ) { if ( m_barOrientation == BARS_HORIZONTAL ) { diff --git a/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.h b/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.h index 53a70a0636..a844881374 100644 --- a/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.h +++ b/ApplicationLibCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.h @@ -135,7 +135,7 @@ private: void reattachAllCurves() override {} void updateAxes() override; - void onAxisSelected( int axis, bool toggle ) override; + void onAxisSelected( RiuPlotAxis axis, bool toggle ) override; void setAutoScaleXEnabled( bool enabled ) override {} void setAutoScaleYEnabled( bool enabled ) override {} void updateLegend() override{}; diff --git a/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.cpp b/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.cpp index b7d01acf39..0f17609e86 100644 --- a/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.cpp @@ -231,7 +231,7 @@ caf::PdmObject* RimWellDistributionPlot::findPdmObjectFromPlotCurve( const RiuPl //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellDistributionPlot::onAxisSelected( int /*axis*/, bool /*toggle*/ ) +void RimWellDistributionPlot::onAxisSelected( RiuPlotAxis /*axis*/, bool /*toggle*/ ) { // cvf::Trace::show("RimWellDistributionPlot::onAxisSelected()"); } diff --git a/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.h b/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.h index 1949837277..26f60d80e4 100644 --- a/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Flow/RimWellDistributionPlot.h @@ -60,7 +60,7 @@ public: void reattachAllCurves() override; void detachAllCurves() override; caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override; - void onAxisSelected( int axis, bool toggle ) override; + void onAxisSelected( RiuPlotAxis axis, bool toggle ) override; // RimPlotWindow implementations QString description() const override; diff --git a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp index 6f26414d52..52b7f95e77 100644 --- a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.cpp @@ -372,15 +372,15 @@ caf::PdmObject* RimGridCrossPlot::findPdmObjectFromPlotCurve( const RiuPlotCurve //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimGridCrossPlot::onAxisSelected( int axis, bool toggle ) +void RimGridCrossPlot::onAxisSelected( RiuPlotAxis axis, bool toggle ) { RiuPlotMainWindowTools::showPlotMainWindow(); RimPlotAxisProperties* properties = nullptr; - if ( axis == QwtAxis::YLeft ) + if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ) { properties = m_yAxisProperties; } - else if ( axis == QwtAxis::XBottom ) + else if ( axis.axis() == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM ) { properties = m_xAxisProperties; } diff --git a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h index 36d460f79d..38259d11dc 100644 --- a/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h +++ b/ApplicationLibCode/ProjectDataModel/GridCrossPlots/RimGridCrossPlot.h @@ -105,7 +105,7 @@ public: void setAutoScaleXEnabled( bool enabled ) override; void setAutoScaleYEnabled( bool enabled ) override; caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override; - void onAxisSelected( int axis, bool toggle ) override; + void onAxisSelected( RiuPlotAxis axis, bool toggle ) override; bool isDeletable() const override; diff --git a/ApplicationLibCode/ProjectDataModel/RimPlot.cpp b/ApplicationLibCode/ProjectDataModel/RimPlot.cpp index c221fd53f9..aabcfb98fd 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPlot.cpp @@ -320,6 +320,6 @@ void RimPlot::onPlotItemSelected( std::shared_ptr, bool, int ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimPlot::onAxisSelected( int axis, bool toggle ) +void RimPlot::onAxisSelected( RiuPlotAxis axis, bool toggle ) { } diff --git a/ApplicationLibCode/ProjectDataModel/RimPlot.h b/ApplicationLibCode/ProjectDataModel/RimPlot.h index 48d7aae63e..a2395c04af 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPlot.h +++ b/ApplicationLibCode/ProjectDataModel/RimPlot.h @@ -22,6 +22,8 @@ #include "RimPlotWindow.h" +#include "RiuPlotAxis.h" + #include "cafAppEnum.h" #include "cafPdmChildArrayField.h" #include "cafPdmField.h" @@ -119,7 +121,7 @@ protected: virtual void handleWheelEvent( QWheelEvent* event ); private slots: - virtual void onAxisSelected( int axis, bool toggle ); + virtual void onAxisSelected( RiuPlotAxis axis, bool toggle ); virtual void onPlotItemSelected( std::shared_ptr selectedItem, bool toggleItem, int sampleIndex ); void onPlotSelected( bool toggle ); void onViewerDestroyed(); diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp index 214d19b290..99506b52cf 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp @@ -377,30 +377,11 @@ caf::PdmObject* RimSummaryPlot::findPdmObjectFromPlotCurve( const RiuPlotCurve* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::onAxisSelected( int axis, bool toggle ) +void RimSummaryPlot::onAxisSelected( RiuPlotAxis axis, bool toggle ) { RiuPlotMainWindowTools::showPlotMainWindow(); - caf::PdmObject* itemToSelect = nullptr; - if ( axis == QwtAxis::YLeft ) - { - itemToSelect = m_leftYAxisProperties_OBSOLETE; - } - else if ( axis == QwtAxis::YRight ) - { - itemToSelect = m_rightYAxisProperties_OBSOLETE; - } - else if ( axis == QwtAxis::XBottom ) - { - if ( m_isCrossPlot ) - { - itemToSelect = m_bottomAxisProperties_OBSOLETE; - } - else - { - itemToSelect = m_timeAxisProperties_OBSOLETE; - } - } + caf::PdmObject* itemToSelect = axisPropertiesForPlotAxis( axis ); if ( toggle ) { diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h index e16977c485..e1072259f5 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -178,7 +178,7 @@ public: caf::PdmObject* findPdmObjectFromPlotCurve( const RiuPlotCurve* curve ) const override; - void onAxisSelected( int axis, bool toggle ) override; + void onAxisSelected( RiuPlotAxis axis, bool toggle ) override; static constexpr int precision() { diff --git a/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.cpp b/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.cpp index a82850a5d1..a480312be5 100644 --- a/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.cpp +++ b/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.cpp @@ -1043,7 +1043,7 @@ void RimWellLogTrack::updateZoomFromParentPlot() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimWellLogTrack::onAxisSelected( int axis, bool toggle ) +void RimWellLogTrack::onAxisSelected( RiuPlotAxis axis, bool toggle ) { if ( toggle ) { diff --git a/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.h b/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.h index 0eaa609bed..59e2357cb5 100644 --- a/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.h +++ b/ApplicationLibCode/ProjectDataModel/WellLog/RimWellLogTrack.h @@ -210,7 +210,7 @@ public: QString asciiDataForPlotExport() const override; - void onAxisSelected( int axis, bool toggle ) override; + void onAxisSelected( RiuPlotAxis axis, bool toggle ) override; void onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector& referringObjects ) override; diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp index 19b7c6d4d5..ff8c87a4be 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.cpp @@ -95,7 +95,7 @@ RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent ) setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); connect( this, SIGNAL( plotSelected( bool ) ), plotDefinition, SLOT( onPlotSelected( bool ) ) ); - connect( this, SIGNAL( axisSelected( int, bool ) ), plotDefinition, SLOT( onAxisSelected( int, bool ) ) ); + connect( this, SIGNAL( axisSelected( RiuPlotAxis, bool ) ), plotDefinition, SLOT( onAxisSelected( RiuPlotAxis, bool ) ) ); connect( this, SIGNAL( plotItemSelected( std::shared_ptr, bool, int ) ), plotDefinition, @@ -562,9 +562,9 @@ bool RiuQwtPlotWidget::eventFilter( QObject* watched, QEvent* event ) m_clickPosition = mouseEvent->pos(); } - if ( watched == this && !m_plot->canvas()->geometry().contains( mouseEvent->pos() ) ) + if ( watched == m_plot && !m_plot->canvas()->geometry().contains( mouseEvent->pos() ) ) { - if ( mouseEvent->type() == QMouseEvent::MouseButtonRelease && ( mouseEvent->button() == Qt::LeftButton ) && + if ( mouseEvent->type() == QMouseEvent::MouseButtonPress && ( mouseEvent->button() == Qt::LeftButton ) && !m_clickPosition.isNull() ) { QWidget* childClicked = m_plot->childAt( m_clickPosition ); @@ -784,15 +784,20 @@ RimViewWindow* RiuQwtPlotWidget::ownerViewWindow() const //-------------------------------------------------------------------------------------------------- void RiuQwtPlotWidget::onAxisSelected( QwtScaleWidget* scale, bool toggleItemInSelection ) { - int axisId = -1; for ( int i = 0; i < QwtAxis::AxisPositions; ++i ) { - if ( scale == m_plot->axisWidget( i ) ) + QwtAxis::Position pos = static_cast( i ); + int count = m_plot->axesCount( pos ); + for ( int id = 0; id < count; id++ ) { - axisId = i; + QwtAxisId axisId( pos, id ); + if ( scale == m_plot->axisWidget( axisId ) ) + { + emit axisSelected( findPlotAxisForQwtAxis( axisId ), toggleItemInSelection ); + return; + } } } - emit axisSelected( axisId, toggleItemInSelection ); } //-------------------------------------------------------------------------------------------------- @@ -1247,6 +1252,18 @@ void RiuQwtPlotWidget::pruneAxes( const std::set& usedAxes ) { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuPlotAxis RiuQwtPlotWidget::findPlotAxisForQwtAxis( const QwtAxisId& qwtAxisId ) const +{ + for ( auto [plotAxis, qwtMapping] : m_axisMapping ) + if ( qwtMapping == qwtAxisId ) return plotAxis; + + CAF_ASSERT( false ); + return RiuPlotAxis::defaultLeft(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -1261,20 +1278,12 @@ void RiuQwtPlotWidget::moveAxis( RiuPlotAxis oldAxis, RiuPlotAxis newAxis ) return count; }; - auto findPlotAxisForQwtAxis = [this]( const QwtAxisId& qwtAxisId ) { - for ( auto [plotAxis, qwtMapping] : m_axisMapping ) - if ( qwtMapping == qwtAxisId ) return plotAxis; - - CAF_ASSERT( false ); - return RiuPlotAxis::defaultLeft(); - }; - auto isLastItem = [this]( RiuPlotAxis plotAxis, int count ) { auto qwtAxis = toQwtPlotAxis( plotAxis ); return qwtAxis.id == ( count - 1 ); }; - auto removeAxis = [this, countAxis, isLastItem, findPlotAxisForQwtAxis]( RiuPlotAxis plotAxis ) { + auto removeAxis = [this, countAxis, isLastItem]( RiuPlotAxis plotAxis ) { auto qwtAxisPos = RiuQwtPlotTools::toQwtPlotAxisEnum( plotAxis.axis() ); int count = countAxis( plotAxis.axis() ); diff --git a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h index 26bdabbedb..0649e8b5a9 100644 --- a/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h +++ b/ApplicationLibCode/UserInterface/RiuQwtPlotWidget.h @@ -175,7 +175,7 @@ public: signals: void plotSelected( bool toggleSelection ); - void axisSelected( int axisId, bool toggleSelection ); + void axisSelected( RiuPlotAxis axisId, bool toggleSelection ); void plotItemSelected( std::shared_ptr plotItem, bool toggleSelection, int sampleIndex ); void onKeyPressEvent( QKeyEvent* event ); void onWheelEvent( QWheelEvent* event ); @@ -200,6 +200,8 @@ protected: void setAxisScaleType( QwtAxisId axis, RiuQwtPlotWidget::AxisScaleType axisScaleType ); void setAxisScale( QwtAxisId axis, double min, double max ); + RiuPlotAxis findPlotAxisForQwtAxis( const QwtAxisId& qwtAxisId ) const; + private: void selectClosestPlotItem( const QPoint& pos, bool toggleItemInSelection = false ); static int defaultMinimumWidth();