mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#853 Support zooming when two y-axis are present
This commit is contained in:
parent
a816454494
commit
30bef2bb17
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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<RimSummaryCurve*> curvesForAxis(RimDefines::PlotAxis plotAxis) const;
|
||||
|
||||
void updateTimeAxis();
|
||||
void setZoomIntervalsInQwtPlot();
|
||||
|
||||
|
||||
private:
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<RimSummaryPlot> m_plotDefinition;
|
||||
QPointer<QwtPlotZoomer> m_zoomer;
|
||||
|
||||
QPointer<QwtPlotZoomer> m_zoomerLeft;
|
||||
QPointer<QwtPlotZoomer> m_zoomerRight;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user