From 30bef2bb179ebceb0d864433fb61c0c391f585bc Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 13 Oct 2016 09:33:50 +0200 Subject: [PATCH] #853 Support zooming when two y-axis are present --- .../ProjectDataModel/RimDefines.cpp | 2 +- .../ProjectDataModel/RimSummaryPlot.cpp | 66 +++++++++++------ .../ProjectDataModel/RimSummaryPlot.h | 16 ++-- .../UserInterface/RiuSummaryQwtPlot.cpp | 74 ++++++++++--------- .../UserInterface/RiuSummaryQwtPlot.h | 18 +++-- 5 files changed, 106 insertions(+), 70 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimDefines.cpp b/ApplicationCode/ProjectDataModel/RimDefines.cpp index 5b9d9f47e5..c590e393f1 100644 --- a/ApplicationCode/ProjectDataModel/RimDefines.cpp +++ b/ApplicationCode/ProjectDataModel/RimDefines.cpp @@ -57,7 +57,7 @@ namespace caf void caf::AppEnum< RimDefines::PlotAxis >::setUp() { addItem(RimDefines::PLOT_AXIS_LEFT, "PLOT_AXIS_LEFT", "Left"); - //addItem(RimDefines::PLOT_AXIS_RIGHT, "PLOT_AXIS_RIGHT", "Right"); + addItem(RimDefines::PLOT_AXIS_RIGHT, "PLOT_AXIS_RIGHT", "Right"); setDefault(RimDefines::PLOT_AXIS_LEFT); } diff --git a/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp b/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp index 44d2816f51..0098ce4b5c 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp +++ b/ApplicationCode/ProjectDataModel/RimSummaryPlot.cpp @@ -264,18 +264,19 @@ QWidget* RimSummaryPlot::viewer() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimSummaryPlot::setZoomWindow(const QRectF& zoomWindow) +void RimSummaryPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis) { - if(!zoomWindow.isEmpty()) - { - m_leftYAxisProperties->visibleRangeMax = zoomWindow.bottom(); - m_leftYAxisProperties->visibleRangeMin = zoomWindow.top(); - m_leftYAxisProperties->updateConnectedEditors(); + m_leftYAxisProperties->visibleRangeMax = leftAxis.maxValue(); + m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue(); + m_leftYAxisProperties->updateConnectedEditors(); - m_timeAxisProperties->setVisibleRangeMin(zoomWindow.left()); - m_timeAxisProperties->setVisibleRangeMax(zoomWindow.right()); - m_timeAxisProperties->updateConnectedEditors(); - } + m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue(); + m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue(); + m_rightYAxisProperties->updateConnectedEditors(); + + m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue()); + m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue()); + m_timeAxisProperties->updateConnectedEditors(); disableAutoZoom(); } @@ -320,10 +321,10 @@ void RimSummaryPlot::zoomAll() } m_qwtPlot->replot(); - - this->setZoomWindow(m_qwtPlot->currentVisibleWindow()); } + updateZoomFromQwt(); + m_isAutoZoom = true; } @@ -423,10 +424,9 @@ void RimSummaryPlot::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering { uiTreeOrdering.add(&m_timeAxisProperties); uiTreeOrdering.add(&m_leftYAxisProperties); - //uiTreeOrdering.add(&m_rightYAxisProperties); + uiTreeOrdering.add(&m_rightYAxisProperties); uiTreeOrdering.add(&m_curveFilters); uiTreeOrdering.add(&m_curves); - uiTreeOrdering.setForgetRemainingFields(true); } //-------------------------------------------------------------------------------------------------- @@ -464,16 +464,40 @@ void RimSummaryPlot::updateZoomInQwt() } else { - QRectF visibleWindow; - visibleWindow.setBottom(m_leftYAxisProperties->visibleRangeMin()); - visibleWindow.setTop(m_leftYAxisProperties->visibleRangeMax()); - visibleWindow.setLeft(m_timeAxisProperties->visibleRangeMin()); - visibleWindow.setRight(m_timeAxisProperties->visibleRangeMax()); - - m_qwtPlot->setZoomWindow(visibleWindow); + setZoomIntervalsInQwtPlot(); } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::setZoomIntervalsInQwtPlot() +{ + QwtInterval left, right, time; + + left.setMinValue(m_leftYAxisProperties->visibleRangeMin()); + left.setMaxValue(m_leftYAxisProperties->visibleRangeMax()); + right.setMinValue(m_rightYAxisProperties->visibleRangeMin()); + right.setMaxValue(m_rightYAxisProperties->visibleRangeMax()); + time.setMinValue(m_timeAxisProperties->visibleRangeMin()); + time.setMaxValue(m_timeAxisProperties->visibleRangeMax()); + + m_qwtPlot->setZoomWindow(left, right, time); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryPlot::updateZoomFromQwt() +{ + if (!m_qwtPlot) return; + + QwtInterval left, right, time; + m_qwtPlot->currentVisibleWindow(&left, &right, &time); + + setZoomWindow(left, right, time); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/RimSummaryPlot.h index ff2429bd3f..967d305435 100644 --- a/ApplicationCode/ProjectDataModel/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/RimSummaryPlot.h @@ -40,6 +40,7 @@ class RimSummaryTimeAxisProperties; class PdmUiTreeOrdering; class QwtPlotCurve; +class QwtInterval; //================================================================================================== /// @@ -66,12 +67,16 @@ public: QWidget* viewer(); - void setZoomWindow(const QRectF& zoomWindow); - virtual void zoomAll() override; - void updateZoomInQwt(); - void disableAutoZoom(); - void updateAxes(); + virtual void zoomAll() override; + void setZoomWindow(const QwtInterval& leftAxis, + const QwtInterval& rightAxis, + const QwtInterval& timeAxis); + + void updateZoomInQwt(); + void updateZoomFromQwt(); + void disableAutoZoom(); + bool isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) const; protected: @@ -94,6 +99,7 @@ private: std::vector curvesForAxis(RimDefines::PlotAxis plotAxis) const; void updateTimeAxis(); + void setZoomIntervalsInQwtPlot(); private: diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp index b5da7aadb5..e8f6bcd76c 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.cpp @@ -52,18 +52,23 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa setDefaults(); // LeftButton for the zooming - m_zoomer = new QwtPlotZoomer(canvas()); - m_zoomer->setRubberBandPen(QColor(Qt::black)); - m_zoomer->setTrackerMode(QwtPicker::AlwaysOff); - m_zoomer->setTrackerPen(QColor(Qt::black)); - m_zoomer->initMousePattern(1); + m_zoomerLeft = new QwtPlotZoomer(canvas()); + m_zoomerLeft->setRubberBandPen(QColor(Qt::black)); + m_zoomerLeft->setTrackerMode(QwtPicker::AlwaysOff); + m_zoomerLeft->setTrackerPen(QColor(Qt::black)); + m_zoomerLeft->initMousePattern(1); // MidButton for the panning QwtPlotPanner* panner = new QwtPlotPanner(canvas()); panner->setMouseButton(Qt::MidButton); - connect(m_zoomer, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot())); + connect(m_zoomerLeft, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot())); connect(panner, SIGNAL(panned( int , int )), SLOT(onZoomedSlot())); + + // Attach a zoomer for the right axis + m_zoomerRight = new QwtPlotZoomer(canvas()); + m_zoomerRight->setAxis(xTop, yRight); + m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff); } //-------------------------------------------------------------------------------------------------- @@ -91,45 +96,37 @@ RimSummaryPlot* RiuSummaryQwtPlot::ownerPlotDefinition() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuSummaryQwtPlot::setYAxisTitle(const QString& title) +void RiuSummaryQwtPlot::currentVisibleWindow(QwtInterval* leftAxis, QwtInterval* rightAxis, QwtInterval* timeAxis) const { - QwtText axisTitleY = axisTitle(QwtPlot::yLeft); - axisTitleY.setText(title); - setAxisTitle(QwtPlot::yLeft, axisTitleY); + *leftAxis = axisScaleDiv(yLeft).interval(); + *rightAxis = axisScaleDiv(yRight).interval(); + *timeAxis = axisScaleDiv(xBottom).interval(); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuSummaryQwtPlot::zoomAll() +void RiuSummaryQwtPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis) { - setAxisAutoScale(yLeft, true); - setAxisAutoScale(xBottom, true); + { + QRectF zoomWindow; + zoomWindow.setLeft(timeAxis.minValue()); + zoomWindow.setRight(timeAxis.maxValue()); + zoomWindow.setTop(leftAxis.maxValue()); + zoomWindow.setBottom(leftAxis.minValue()); - m_zoomer->setZoomBase(true); -} + m_zoomerLeft->zoom(zoomWindow); + } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QRectF RiuSummaryQwtPlot::currentVisibleWindow() const -{ - QRectF scaleRect; - scaleRect.setLeft(axisScaleDiv(xBottom).lowerBound()); - scaleRect.setRight(axisScaleDiv(xBottom).upperBound()); + { + QRectF zoomWindow; + zoomWindow.setLeft(timeAxis.minValue()); + zoomWindow.setRight(timeAxis.maxValue()); + zoomWindow.setTop(rightAxis.maxValue()); + zoomWindow.setBottom(rightAxis.minValue()); - scaleRect.setBottom(axisScaleDiv(yLeft).upperBound()); - scaleRect.setTop(axisScaleDiv(yLeft).lowerBound()); - - return scaleRect; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuSummaryQwtPlot::setZoomWindow(const QRectF& zoomWindow) -{ - m_zoomer->zoom(zoomWindow); + m_zoomerRight->zoom(zoomWindow); + } } //-------------------------------------------------------------------------------------------------- @@ -292,5 +289,10 @@ void RiuSummaryQwtPlot::selectClosestCurve(const QPoint& pos) //-------------------------------------------------------------------------------------------------- void RiuSummaryQwtPlot::onZoomedSlot() { - m_plotDefinition->setZoomWindow(currentVisibleWindow()); + QwtInterval left, right, time; + currentVisibleWindow(&left, &right, &time); + + this->setZoomWindow(left, right, time); + + m_plotDefinition->updateZoomFromQwt(); } diff --git a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h index 66e67c88cd..ba5102fede 100644 --- a/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuSummaryQwtPlot.h @@ -26,6 +26,7 @@ class QwtPlotCurve; class QwtPlotGrid; class QwtPlotZoomer; +class QwtInterval; class RimSummaryPlot; @@ -42,11 +43,14 @@ public: virtual ~RiuSummaryQwtPlot(); RimSummaryPlot* ownerPlotDefinition(); - void setYAxisTitle(const QString& title); - void zoomAll(); - QRectF currentVisibleWindow() const; - void setZoomWindow(const QRectF& zoomWindow); + void currentVisibleWindow(QwtInterval* leftAxis, + QwtInterval* rightAxis, + QwtInterval* timeAxis) const; + + void setZoomWindow(const QwtInterval& leftAxis, + const QwtInterval& rightAxis, + const QwtInterval& timeAxis); protected: virtual bool eventFilter(QObject* watched, QEvent* event); @@ -61,8 +65,8 @@ private slots: private: QwtPlotGrid* m_grid; caf::PdmPointer m_plotDefinition; - QPointer m_zoomer; + + QPointer m_zoomerLeft; + QPointer m_zoomerRight; }; - -