#2448 Summary plot: Retain auto zoom for axes you haven't modified the range for.

This commit is contained in:
Gaute Lindkvist 2018-05-11 13:18:53 +02:00
parent 9f1ea2c42a
commit f0be8214b0
6 changed files with 182 additions and 126 deletions

View File

@ -83,6 +83,7 @@ RimSummaryAxisProperties::RimSummaryAxisProperties()
numberOfDecimals.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Set Range Automatically", "", "", "");
CAF_PDM_InitField(&isLogarithmicScaleEnabled, "LogarithmicScale", false, "Logarithmic Scale", "", "", "");
updateOptionSensitivity();
@ -251,6 +252,22 @@ bool RimSummaryAxisProperties::showUnitText() const
return m_displayUnitText();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryAxisProperties::isAutoZoom() const
{
return m_isAutoZoom();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryAxisProperties::setAutoZoom(bool enableAutoZoom)
{
m_isAutoZoom = enableAutoZoom;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -278,13 +295,13 @@ void RimSummaryAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* chang
{
if (visibleRangeMin > visibleRangeMax) visibleRangeMax = oldValue.toDouble();
rimSummaryPlot->disableAutoZoom();
m_isAutoZoom = false;
}
else if (changedField == &visibleRangeMin)
{
if (visibleRangeMin > visibleRangeMax) visibleRangeMin = oldValue.toDouble();
rimSummaryPlot->disableAutoZoom();
m_isAutoZoom = false;
}
if (changedField == &isLogarithmicScaleEnabled)

View File

@ -61,6 +61,8 @@ public:
bool showDescription() const;
bool showAcronym() const;
bool showUnitText() const;
bool isAutoZoom() const;
void setAutoZoom(bool enableAutoZoom);
caf::PdmField<QString> customTitle;
caf::PdmField<int> titleFontSize;
@ -98,6 +100,7 @@ private:
caf::PdmField<bool> m_displayShortName;
caf::PdmField<bool> m_displayLongName;
caf::PdmField<bool> m_displayUnitText;
caf::PdmField<bool> m_isAutoZoom;
caf::PdmField<QString> m_name;
QwtPlot::Axis m_axis;

View File

@ -120,9 +120,9 @@ RimSummaryPlot::RimSummaryPlot()
m_timeAxisProperties.uiCapability()->setUiTreeHidden(true);
m_timeAxisProperties = new RimSummaryTimeAxisProperties;
CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Auto Zoom", "", "", "");
m_isAutoZoom.uiCapability()->setUiHidden(true);
CAF_PDM_InitField(&m_isAutoZoom_OBSOLETE, "AutoZoom", true, "Auto Zoom", "", "", "");
m_isAutoZoom_OBSOLETE.uiCapability()->setUiHidden(true);
m_isAutoZoom_OBSOLETE.xmlCapability()->setIOWritable(false);
setAsPlotMdiWindow();
m_isCrossPlot = false;
@ -153,8 +153,6 @@ void RimSummaryPlot::updateAxes()
updateAxis(RiaDefines::PLOT_AXIS_LEFT);
updateAxis(RiaDefines::PLOT_AXIS_RIGHT);
updateZoomInQwt();
if (m_isCrossPlot)
{
updateBottomXAxis();
@ -163,6 +161,8 @@ void RimSummaryPlot::updateAxes()
{
updateTimeAxis();
}
updateZoomInQwt();
}
//--------------------------------------------------------------------------------------------------
@ -619,8 +619,38 @@ void RimSummaryPlot::updateAxis(RiaDefines::PlotAxis plotAxis)
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateZoomForAxis(RiaDefines::PlotAxis plotAxis)
{
if (plotAxis == RiaDefines::PLOT_AXIS_BOTTOM)
{
if (m_isCrossPlot)
{
if (m_bottomAxisProperties->isAutoZoom())
{
m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true);
}
else
{
m_qwtPlot->setAxisScale(QwtPlot::xBottom, m_bottomAxisProperties->visibleRangeMin(), m_bottomAxisProperties->visibleRangeMax());
}
}
else
{
if (m_timeAxisProperties->isAutoZoom())
{
m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true);
}
else
{
m_qwtPlot->setAxisScale(QwtPlot::xBottom, m_timeAxisProperties->visibleRangeMin(), m_timeAxisProperties->visibleRangeMax());
}
}
}
else
{
RimSummaryAxisProperties* yAxisProps = yAxisPropertiesLeftOrRight(plotAxis);
if (yAxisProps->isAutoZoom())
{
if (yAxisProps->isLogarithmicScaleEnabled)
{
std::vector<double> yValues;
@ -657,6 +687,12 @@ void RimSummaryPlot::updateZoomForAxis(RiaDefines::PlotAxis plotAxis)
{
m_qwtPlot->setAxisAutoScale(yAxisProps->qwtPlotAxisType(), true);
}
}
else
{
m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), yAxisProps->visibleRangeMin(), yAxisProps->visibleRangeMax());
}
}
}
//--------------------------------------------------------------------------------------------------
@ -895,53 +931,15 @@ void RimSummaryPlot::updateCaseNameHasChanged()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setZoomWindow(const QwtInterval& leftAxis, const QwtInterval& rightAxis, const QwtInterval& timeAxis)
{
m_leftYAxisProperties->visibleRangeMax = leftAxis.maxValue();
m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue();
m_leftYAxisProperties->updateConnectedEditors();
m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue();
m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue();
m_rightYAxisProperties->updateConnectedEditors();
if (m_isCrossPlot)
{
m_bottomAxisProperties->visibleRangeMax = timeAxis.maxValue();
m_bottomAxisProperties->visibleRangeMin = timeAxis.minValue();
m_bottomAxisProperties->updateConnectedEditors();
}
else
{
m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue());
m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue());
m_timeAxisProperties->updateConnectedEditors();
}
disableAutoZoom();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::zoomAll()
{
if (m_qwtPlot)
{
m_qwtPlot->setAxisAutoScale(QwtPlot::xBottom, true);
setAutoZoomForAllAxes(true);
updateZoomInQwt();
updateAxisRangesFromQwt();
updateZoomForAxis(RiaDefines::PLOT_AXIS_LEFT);
updateZoomForAxis(RiaDefines::PLOT_AXIS_RIGHT);
m_qwtPlot->replot();
}
updateZoomWindowFromQwt();
m_isAutoZoom = true;
}
//--------------------------------------------------------------------------------------------------
@ -1260,42 +1258,15 @@ void RimSummaryPlot::onLoadDataAndUpdate()
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateZoomInQwt()
{
if (!m_qwtPlot) return;
if (m_isAutoZoom)
if (m_qwtPlot)
{
zoomAll();
}
else
{
setZoomIntervalsInQwtPlot();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setZoomIntervalsInQwtPlot()
{
QwtInterval left, right, time;
updateZoomForAxis(RiaDefines::PLOT_AXIS_BOTTOM);
updateZoomForAxis(RiaDefines::PLOT_AXIS_LEFT);
updateZoomForAxis(RiaDefines::PLOT_AXIS_RIGHT);
left.setMinValue(m_leftYAxisProperties->visibleRangeMin());
left.setMaxValue(m_leftYAxisProperties->visibleRangeMax());
right.setMinValue(m_rightYAxisProperties->visibleRangeMin());
right.setMaxValue(m_rightYAxisProperties->visibleRangeMax());
if (m_isCrossPlot)
{
time.setMinValue(m_bottomAxisProperties->visibleRangeMin());
time.setMaxValue(m_bottomAxisProperties->visibleRangeMax());
m_qwtPlot->replot();
}
else
{
time.setMinValue(m_timeAxisProperties->visibleRangeMin());
time.setMaxValue(m_timeAxisProperties->visibleRangeMax());
}
m_qwtPlot->setZoomWindow(left, right, time);
}
//--------------------------------------------------------------------------------------------------
@ -1303,20 +1274,59 @@ void RimSummaryPlot::setZoomIntervalsInQwtPlot()
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::updateZoomWindowFromQwt()
{
if (!m_qwtPlot) return;
QwtInterval left, right, time;
m_qwtPlot->currentVisibleWindow(&left, &right, &time);
setZoomWindow(left, right, time);
updateAxisRangesFromQwt();
setAutoZoomForAllAxes(false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::disableAutoZoom()
void RimSummaryPlot::updateAxisRangesFromQwt()
{
m_isAutoZoom = false;
if (!m_qwtPlot) return;
QwtInterval leftAxis, rightAxis, timeAxis;
m_qwtPlot->currentVisibleWindow(&leftAxis, &rightAxis, &timeAxis);
m_leftYAxisProperties->visibleRangeMax = leftAxis.maxValue();
m_leftYAxisProperties->visibleRangeMin = leftAxis.minValue();
m_leftYAxisProperties->updateConnectedEditors();
m_rightYAxisProperties->visibleRangeMax = rightAxis.maxValue();
m_rightYAxisProperties->visibleRangeMin = rightAxis.minValue();
m_rightYAxisProperties->updateConnectedEditors();
if (m_isCrossPlot)
{
m_bottomAxisProperties->visibleRangeMax = timeAxis.maxValue();
m_bottomAxisProperties->visibleRangeMin = timeAxis.minValue();
m_bottomAxisProperties->updateConnectedEditors();
}
else
{
m_timeAxisProperties->setVisibleRangeMin(timeAxis.minValue());
m_timeAxisProperties->setVisibleRangeMax(timeAxis.maxValue());
m_timeAxisProperties->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::setAutoZoomForAllAxes(bool enableAutoZoom)
{
m_leftYAxisProperties->setAutoZoom(enableAutoZoom);
m_rightYAxisProperties->setAutoZoom(enableAutoZoom);
if (m_isCrossPlot)
{
m_bottomAxisProperties->setAutoZoom(enableAutoZoom);
}
else
{
m_timeAxisProperties->setAutoZoom(enableAutoZoom);
}
}
//--------------------------------------------------------------------------------------------------
@ -1458,6 +1468,11 @@ void RimSummaryPlot::initAfterRead()
m_summaryCurveCollection->addCurve(curve);
}
if (!m_isAutoZoom_OBSOLETE())
{
setAutoZoomForAllAxes(false);
}
RimProject* proj = nullptr;
this->firstAncestorOrThisOfType(proj);
if (proj)

View File

@ -89,13 +89,9 @@ public:
void updateAxes();
virtual void zoomAll() override;
void setZoomWindow(const QwtInterval& leftAxis,
const QwtInterval& rightAxis,
const QwtInterval& timeAxis);
void updateZoomInQwt();
void updateZoomWindowFromQwt();
void disableAutoZoom();
bool isLogarithmicScaleEnabled(RiaDefines::PlotAxis plotAxis) const;
@ -154,11 +150,14 @@ private:
RimSummaryAxisProperties* yAxisPropertiesLeftOrRight(RiaDefines::PlotAxis leftOrRightPlotAxis) const;
void updateAxis(RiaDefines::PlotAxis plotAxis);
void updateZoomForAxis(RiaDefines::PlotAxis plotAxis);
void updateTimeAxis();
void updateBottomXAxis();
void setZoomIntervalsInQwtPlot();
void updateAxisRangesFromQwt();
void setAutoZoomForAllAxes(bool enableAutoZoom);
private:
caf::PdmField<bool> m_showPlotTitle;
@ -174,7 +173,6 @@ private:
caf::PdmChildArrayField<RimAsciiDataCurve*> m_asciiDataCurves;
caf::PdmField<bool> m_isAutoZoom;
caf::PdmChildField<RimSummaryAxisProperties*> m_leftYAxisProperties;
caf::PdmChildField<RimSummaryAxisProperties*> m_rightYAxisProperties;
@ -191,4 +189,6 @@ private:
// Obsolete fields
caf::PdmChildArrayField<RimSummaryCurve*> m_summaryCurves_OBSOLETE;
caf::PdmChildArrayField<RimSummaryCurveFilter_OBSOLETE*> m_curveFilters_OBSOLETE;
caf::PdmField<bool> m_isAutoZoom_OBSOLETE;
};

View File

@ -82,6 +82,7 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
CAF_PDM_InitField(&titleFontSize, "FontSize", 11, "Font Size", "", "", "");
CAF_PDM_InitField(&valuesFontSize, "ValuesFontSize", 11, "Font Size", "", "", "");
CAF_PDM_InitField(&m_isAutoZoom, "AutoZoom", true, "Set Range Automatically", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_timeMode, "TimeMode", "Time Mode", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_timeUnit, "TimeUnit", "Time Unit", "", "", "");
@ -158,6 +159,22 @@ void RimSummaryTimeAxisProperties::setVisibleRangeMax(double value)
auto s = m_visibleDateRangeMax().toString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryTimeAxisProperties::isAutoZoom() const
{
return m_isAutoZoom;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryTimeAxisProperties::setAutoZoom(bool enableAutoZoom)
{
m_isAutoZoom = enableAutoZoom;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -362,7 +379,7 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
}
updateTimeVisibleRange();
rimSummaryPlot->disableAutoZoom();
m_isAutoZoom = false;
}
else if (changedField == &m_visibleDateRangeMin)
{
@ -373,12 +390,12 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
}
updateTimeVisibleRange();
rimSummaryPlot->disableAutoZoom();
m_isAutoZoom = false;
}
else if (changedField == &m_visibleTimeRangeMin || changedField == &m_visibleTimeRangeMax)
{
updateDateVisibleRange();
rimSummaryPlot->disableAutoZoom();
m_isAutoZoom = false;
}
else if (changedField == &m_timeMode)
{

View File

@ -78,6 +78,9 @@ public:
void setVisibleRangeMin(double value);
void setVisibleRangeMax(double value);
bool isAutoZoom() const;
void setAutoZoom(bool enableAutoZoom);
bool isActive() const;
protected:
@ -100,4 +103,5 @@ private:
caf::PdmField<QDateTime> m_visibleDateRangeMax;
caf::PdmField<double> m_visibleTimeRangeMin;
caf::PdmField<double> m_visibleTimeRangeMax;
caf::PdmField<bool> m_isAutoZoom;
};