#853 Support zooming when two y-axis are present

This commit is contained in:
Magne Sjaastad 2016-10-13 09:33:50 +02:00
parent a816454494
commit 30bef2bb17
5 changed files with 106 additions and 70 deletions

View File

@ -57,7 +57,7 @@ namespace caf
void caf::AppEnum< RimDefines::PlotAxis >::setUp() void caf::AppEnum< RimDefines::PlotAxis >::setUp()
{ {
addItem(RimDefines::PLOT_AXIS_LEFT, "PLOT_AXIS_LEFT", "Left"); 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); setDefault(RimDefines::PLOT_AXIS_LEFT);
} }

View File

@ -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 = leftAxis.maxValue();
{ m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue();
m_leftYAxisProperties->visibleRangeMax = zoomWindow.bottom(); m_leftYAxisProperties->updateConnectedEditors();
m_leftYAxisProperties->visibleRangeMin = zoomWindow.top();
m_leftYAxisProperties->updateConnectedEditors();
m_timeAxisProperties->setVisibleRangeMin(zoomWindow.left()); m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue();
m_timeAxisProperties->setVisibleRangeMax(zoomWindow.right()); m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue();
m_timeAxisProperties->updateConnectedEditors(); m_rightYAxisProperties->updateConnectedEditors();
}
m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue());
m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue());
m_timeAxisProperties->updateConnectedEditors();
disableAutoZoom(); disableAutoZoom();
} }
@ -320,10 +321,10 @@ void RimSummaryPlot::zoomAll()
} }
m_qwtPlot->replot(); m_qwtPlot->replot();
this->setZoomWindow(m_qwtPlot->currentVisibleWindow());
} }
updateZoomFromQwt();
m_isAutoZoom = true; m_isAutoZoom = true;
} }
@ -423,10 +424,9 @@ void RimSummaryPlot::defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering
{ {
uiTreeOrdering.add(&m_timeAxisProperties); uiTreeOrdering.add(&m_timeAxisProperties);
uiTreeOrdering.add(&m_leftYAxisProperties); uiTreeOrdering.add(&m_leftYAxisProperties);
//uiTreeOrdering.add(&m_rightYAxisProperties); uiTreeOrdering.add(&m_rightYAxisProperties);
uiTreeOrdering.add(&m_curveFilters); uiTreeOrdering.add(&m_curveFilters);
uiTreeOrdering.add(&m_curves); uiTreeOrdering.add(&m_curves);
uiTreeOrdering.setForgetRemainingFields(true);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -464,16 +464,40 @@ void RimSummaryPlot::updateZoomInQwt()
} }
else else
{ {
QRectF visibleWindow; setZoomIntervalsInQwtPlot();
visibleWindow.setBottom(m_leftYAxisProperties->visibleRangeMin());
visibleWindow.setTop(m_leftYAxisProperties->visibleRangeMax());
visibleWindow.setLeft(m_timeAxisProperties->visibleRangeMin());
visibleWindow.setRight(m_timeAxisProperties->visibleRangeMax());
m_qwtPlot->setZoomWindow(visibleWindow);
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -40,6 +40,7 @@ class RimSummaryTimeAxisProperties;
class PdmUiTreeOrdering; class PdmUiTreeOrdering;
class QwtPlotCurve; class QwtPlotCurve;
class QwtInterval;
//================================================================================================== //==================================================================================================
/// ///
@ -66,12 +67,16 @@ public:
QWidget* viewer(); QWidget* viewer();
void setZoomWindow(const QRectF& zoomWindow);
virtual void zoomAll() override;
void updateZoomInQwt();
void disableAutoZoom();
void updateAxes(); 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; bool isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) const;
protected: protected:
@ -94,6 +99,7 @@ private:
std::vector<RimSummaryCurve*> curvesForAxis(RimDefines::PlotAxis plotAxis) const; std::vector<RimSummaryCurve*> curvesForAxis(RimDefines::PlotAxis plotAxis) const;
void updateTimeAxis(); void updateTimeAxis();
void setZoomIntervalsInQwtPlot();
private: private:

View File

@ -52,18 +52,23 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
setDefaults(); setDefaults();
// LeftButton for the zooming // LeftButton for the zooming
m_zoomer = new QwtPlotZoomer(canvas()); m_zoomerLeft = new QwtPlotZoomer(canvas());
m_zoomer->setRubberBandPen(QColor(Qt::black)); m_zoomerLeft->setRubberBandPen(QColor(Qt::black));
m_zoomer->setTrackerMode(QwtPicker::AlwaysOff); m_zoomerLeft->setTrackerMode(QwtPicker::AlwaysOff);
m_zoomer->setTrackerPen(QColor(Qt::black)); m_zoomerLeft->setTrackerPen(QColor(Qt::black));
m_zoomer->initMousePattern(1); m_zoomerLeft->initMousePattern(1);
// MidButton for the panning // MidButton for the panning
QwtPlotPanner* panner = new QwtPlotPanner(canvas()); QwtPlotPanner* panner = new QwtPlotPanner(canvas());
panner->setMouseButton(Qt::MidButton); 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())); 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); *leftAxis = axisScaleDiv(yLeft).interval();
axisTitleY.setText(title); *rightAxis = axisScaleDiv(yRight).interval();
setAxisTitle(QwtPlot::yLeft, axisTitleY); *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 zoomWindow;
//-------------------------------------------------------------------------------------------------- zoomWindow.setLeft(timeAxis.minValue());
QRectF RiuSummaryQwtPlot::currentVisibleWindow() const zoomWindow.setRight(timeAxis.maxValue());
{ zoomWindow.setTop(rightAxis.maxValue());
QRectF scaleRect; zoomWindow.setBottom(rightAxis.minValue());
scaleRect.setLeft(axisScaleDiv(xBottom).lowerBound());
scaleRect.setRight(axisScaleDiv(xBottom).upperBound());
scaleRect.setBottom(axisScaleDiv(yLeft).upperBound()); m_zoomerRight->zoom(zoomWindow);
scaleRect.setTop(axisScaleDiv(yLeft).lowerBound()); }
return scaleRect;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::setZoomWindow(const QRectF& zoomWindow)
{
m_zoomer->zoom(zoomWindow);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -292,5 +289,10 @@ void RiuSummaryQwtPlot::selectClosestCurve(const QPoint& pos)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuSummaryQwtPlot::onZoomedSlot() void RiuSummaryQwtPlot::onZoomedSlot()
{ {
m_plotDefinition->setZoomWindow(currentVisibleWindow()); QwtInterval left, right, time;
currentVisibleWindow(&left, &right, &time);
this->setZoomWindow(left, right, time);
m_plotDefinition->updateZoomFromQwt();
} }

View File

@ -26,6 +26,7 @@
class QwtPlotCurve; class QwtPlotCurve;
class QwtPlotGrid; class QwtPlotGrid;
class QwtPlotZoomer; class QwtPlotZoomer;
class QwtInterval;
class RimSummaryPlot; class RimSummaryPlot;
@ -42,11 +43,14 @@ public:
virtual ~RiuSummaryQwtPlot(); virtual ~RiuSummaryQwtPlot();
RimSummaryPlot* ownerPlotDefinition(); RimSummaryPlot* ownerPlotDefinition();
void setYAxisTitle(const QString& title);
void zoomAll();
QRectF currentVisibleWindow() const; void currentVisibleWindow(QwtInterval* leftAxis,
void setZoomWindow(const QRectF& zoomWindow); QwtInterval* rightAxis,
QwtInterval* timeAxis) const;
void setZoomWindow(const QwtInterval& leftAxis,
const QwtInterval& rightAxis,
const QwtInterval& timeAxis);
protected: protected:
virtual bool eventFilter(QObject* watched, QEvent* event); virtual bool eventFilter(QObject* watched, QEvent* event);
@ -61,8 +65,8 @@ private slots:
private: private:
QwtPlotGrid* m_grid; QwtPlotGrid* m_grid;
caf::PdmPointer<RimSummaryPlot> m_plotDefinition; caf::PdmPointer<RimSummaryPlot> m_plotDefinition;
QPointer<QwtPlotZoomer> m_zoomer;
QPointer<QwtPlotZoomer> m_zoomerLeft;
QPointer<QwtPlotZoomer> m_zoomerRight;
}; };