Skip to content

Commit

Permalink
Send a single signal with no parameters when plot is zoomed
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Sep 15, 2023
1 parent 64d2cf1 commit 435ebbf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions ApplicationLibCode/UserInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ list(
${CMAKE_CURRENT_LIST_DIR}/RiuTextContentFrame.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtLegendOverlayContentFrame.h
${CMAKE_CURRENT_LIST_DIR}/RiuMatrixPlotWidget.h
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotZoomerMultiAxes.h
)

list(APPEND QT_UI_FILES)
Expand Down
12 changes: 2 additions & 10 deletions ApplicationLibCode/UserInterface/RiuGridCrossQwtPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,14 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot( RimGridCrossPlot* plot, QWidget* paren
m_zoomerLeft->setTrackerMode( QwtPicker::AlwaysOff );
m_zoomerLeft->initMousePattern( 1 );

// Attach a zoomer for the right axis
m_zoomerRight = new RiuQwtPlotZoomer( qwtPlot()->canvas() );
m_zoomerRight->setAxes( QwtAxis::XTop, QwtAxis::YRight );
m_zoomerRight->setTrackerMode( QwtPicker::AlwaysOff );
m_zoomerRight->initMousePattern( 1 );

// MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner( qwtPlot()->canvas() );
panner->setMouseButton( Qt::MiddleButton );

auto wheelZoomer = new RiuQwtPlotWheelZoomer( qwtPlot() );

connect( wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
connect( m_zoomerRight, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
connect( m_zoomerLeft, SIGNAL( zoomed() ), SLOT( onZoomedSlot() ) );
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );
connect( this,
SIGNAL( plotItemSelected( std::shared_ptr<RiuPlotItem>, bool, int ) ),
Expand Down Expand Up @@ -254,7 +247,7 @@ bool RiuGridCrossQwtPlot::curveText( const QwtPlotCurve* curve, QString* curveTi
//--------------------------------------------------------------------------------------------------
bool RiuGridCrossQwtPlot::isZoomerActive() const
{
return m_zoomerLeft->isActiveAndValid() || m_zoomerRight->isActiveAndValid();
return m_zoomerLeft->isActiveAndValid();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -263,7 +256,6 @@ bool RiuGridCrossQwtPlot::isZoomerActive() const
void RiuGridCrossQwtPlot::endZoomOperations()
{
m_zoomerLeft->endZoomOperation();
m_zoomerRight->endZoomOperation();
}

//--------------------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion ApplicationLibCode/UserInterface/RiuGridCrossQwtPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ private slots:
QwtPlotMarker* m_selectedPointMarker;

QPointer<RiuQwtPlotZoomer> m_zoomerLeft;
QPointer<RiuQwtPlotZoomer> m_zoomerRight;
};
15 changes: 8 additions & 7 deletions ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ void RiuQwtPlotZoomerMultiAxes::zoomFromScreenCoords( const QRectF& screenCoords
const double screenX2 = screenCoords.right();
double domainX1 = map.invTransform( screenX1 );
double domainX2 = map.invTransform( screenX2 );
if ( !plot->axisScaleDiv( axisId ).isIncreasing() ) qSwap( domainX1, domainX2 );
if ( domainX1 > domainX2 ) qSwap( domainX1, domainX2 );

plot->setAxisScale( axisId, domainX1, domainX2 );
}
else
{
const double screenY1 = screenCoords.top();
const double screenY2 = screenCoords.bottom();
const double screenY1 = screenCoords.bottom();
const double screenY2 = screenCoords.top();
double domainY1 = map.invTransform( screenY1 );
double domainY2 = map.invTransform( screenY2 );
if ( plot->axisScaleDiv( axisId ).isIncreasing() ) qSwap( domainY1, domainY2 );

plot->setAxisScale( axisId, domainY1, domainY2 );
}
}

plot->setAutoReplot( doReplot );
plot->replot();
}

plot->setAutoReplot( doReplot );
plot->replot();

emit zoomed();
}
4 changes: 4 additions & 0 deletions ApplicationLibCode/UserInterface/RiuQwtPlotZoomerMultiAxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
//--------------------------------------------------------------------------------------------------
class RiuQwtPlotZoomerMultiAxes : public QwtPlotPicker
{
Q_OBJECT
public:
explicit RiuQwtPlotZoomerMultiAxes( QWidget*, bool doReplot = true );

Q_SIGNALS:
void zoomed();

protected:
bool end( bool ok = true ) override;

Expand Down
2 changes: 1 addition & 1 deletion ApplicationLibCode/UserInterface/RiuSummaryQwtPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot( RimSummaryPlot* plot, QWidget* parent /*=
m_wheelZoomer = new RiuQwtPlotWheelZoomer( m_plotWidget->qwtPlot() );

connect( m_wheelZoomer, SIGNAL( zoomUpdated() ), SLOT( onZoomedSlot() ) );
connect( m_zoomerLeft, SIGNAL( zoomed( const QRectF& ) ), SLOT( onZoomedSlot() ) );
connect( m_zoomerLeft, SIGNAL( zoomed() ), SLOT( onZoomedSlot() ) );
connect( panner, SIGNAL( panned( int, int ) ), SLOT( onZoomedSlot() ) );

setDefaults();
Expand Down

0 comments on commit 435ebbf

Please sign in to comment.