mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2724 Ensemble curves. Show case name in mouse tracking tooltip
This commit is contained in:
@@ -32,8 +32,8 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQwtCurvePointTracker::RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal)
|
||||
: QwtPlotPicker(plot->canvas()), m_plot(plot), m_isMainAxisHorizontal(isMainAxisHorizontal)
|
||||
RiuQwtCurvePointTracker::RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal, IPlotCurveInfoTextProvider* curveInfoTextProvider)
|
||||
: QwtPlotPicker(plot->canvas()), m_plot(plot), m_isMainAxisHorizontal(isMainAxisHorizontal), m_curveInfoTextProvider(curveInfoTextProvider)
|
||||
{
|
||||
this->setTrackerMode(QwtPicker::AlwaysOn);
|
||||
m_plotMarker = new QwtPlotMarker;
|
||||
@@ -91,12 +91,15 @@ QwtText RiuQwtCurvePointTracker::trackerText(const QPoint& pos) const
|
||||
QwtPlot::Axis relatedYAxis = QwtPlot::yLeft;
|
||||
QwtPlot::Axis relatedXAxis = QwtPlot::xBottom;
|
||||
|
||||
QString curveInfoText;
|
||||
QString mainAxisValueString;
|
||||
QString valueAxisValueString;
|
||||
QPointF closestPoint = closestCurvePoint(pos, &valueAxisValueString, &mainAxisValueString, &relatedXAxis, &relatedYAxis);
|
||||
QPointF closestPoint = closestCurvePoint(pos, &curveInfoText, &valueAxisValueString, &mainAxisValueString, &relatedXAxis, &relatedYAxis);
|
||||
if ( !closestPoint.isNull() )
|
||||
{
|
||||
QString str = valueAxisValueString;
|
||||
QString str = !curveInfoText.isEmpty() ?
|
||||
QString("%1: %2").arg(curveInfoText).arg(valueAxisValueString) :
|
||||
valueAxisValueString;
|
||||
|
||||
if ( !mainAxisValueString.isEmpty() )
|
||||
{
|
||||
@@ -115,7 +118,12 @@ QwtText RiuQwtCurvePointTracker::trackerText(const QPoint& pos) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QPointF RiuQwtCurvePointTracker::closestCurvePoint(const QPoint& cursorPosition, QString* valueAxisValueString, QString* mainAxisValueString, QwtPlot::Axis* relatedXAxis, QwtPlot::Axis* relatedYAxis) const
|
||||
QPointF RiuQwtCurvePointTracker::closestCurvePoint(const QPoint& cursorPosition,
|
||||
QString* curveInfoText,
|
||||
QString* valueAxisValueString,
|
||||
QString* mainAxisValueString,
|
||||
QwtPlot::Axis* relatedXAxis,
|
||||
QwtPlot::Axis* relatedYAxis) const
|
||||
{
|
||||
QPointF samplePoint;
|
||||
|
||||
@@ -160,6 +168,11 @@ QPointF RiuQwtCurvePointTracker::closestCurvePoint(const QPoint& cursorPosition,
|
||||
else
|
||||
mainAxisSampleVal = samplePoint.y();
|
||||
|
||||
if (curveInfoText && closestCurve && m_curveInfoTextProvider)
|
||||
{
|
||||
*curveInfoText = m_curveInfoTextProvider->curveInfoText(closestCurve);
|
||||
}
|
||||
|
||||
if ( dateScaleDraw )
|
||||
{
|
||||
QDateTime date = dateScaleDraw->toDateTime(mainAxisSampleVal);
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
#include <QPointer>
|
||||
|
||||
class QwtPlotMarker;
|
||||
class QwtPlotCurve;
|
||||
class IPlotCurveInfoTextProvider;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Class to add mouse over-tracking of curve points with text marker
|
||||
@@ -30,7 +33,7 @@ class QwtPlotMarker;
|
||||
class RiuQwtCurvePointTracker : public QwtPlotPicker
|
||||
{
|
||||
public:
|
||||
explicit RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal);
|
||||
explicit RiuQwtCurvePointTracker(QwtPlot* plot, bool isMainAxisHorizontal, IPlotCurveInfoTextProvider* curveInfoTextProvider = nullptr);
|
||||
~RiuQwtCurvePointTracker();
|
||||
|
||||
protected:
|
||||
@@ -39,7 +42,8 @@ protected:
|
||||
void removeMarkerOnFocusLeave();
|
||||
|
||||
virtual QwtText trackerText(const QPoint& pos) const override;
|
||||
QPointF closestCurvePoint(const QPoint& cursorPosition,
|
||||
QPointF closestCurvePoint(const QPoint& cursorPosition,
|
||||
QString* curveInfoText,
|
||||
QString* valueAxisValueString,
|
||||
QString* mainAxisValueString,
|
||||
QwtPlot::Axis* relatedXAxis,
|
||||
@@ -51,5 +55,14 @@ protected:
|
||||
QPointer<QwtPlot> m_plot;
|
||||
QwtPlotMarker* m_plotMarker;
|
||||
bool m_isMainAxisHorizontal;
|
||||
IPlotCurveInfoTextProvider* m_curveInfoTextProvider;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Interface for retrieving curve info text
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class IPlotCurveInfoTextProvider
|
||||
{
|
||||
public:
|
||||
virtual QString curveInfoText(QwtPlotCurve* curve) = 0;
|
||||
};
|
||||
|
||||
@@ -57,9 +57,49 @@
|
||||
#include "RimRegularLegendConfig.h"
|
||||
#include "cafTitledOverlayFrame.h"
|
||||
#include "RimEnsembleCurveSetCollection.h"
|
||||
#include "RimMainPlotCollection.h"
|
||||
#include "RimSummaryPlotCollection.h"
|
||||
#include "RimSummaryCase.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class EnsembleCurveInfoTextProvider : public IPlotCurveInfoTextProvider
|
||||
{
|
||||
public:
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual QString curveInfoText(QwtPlotCurve* curve) override
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
RimSummaryCurve* sumCurve = nullptr;
|
||||
|
||||
// Lookup RimSummaryCurve from QwtPlotCurve
|
||||
for (auto const plot : project->mainPlotCollection->summaryPlotCollection()->summaryPlots())
|
||||
{
|
||||
RimSummaryPlot* sumPlot = plot->qwtPlot()->ownerPlotDefinition();
|
||||
for (auto const curveSet : sumPlot->ensembleCurveSets()->curveSets())
|
||||
{
|
||||
for (auto const currSumCurve : curveSet->curves())
|
||||
{
|
||||
if (currSumCurve->qwtPlotCurve() == curve)
|
||||
{
|
||||
sumCurve = currSumCurve;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sumCurve && sumCurve->summaryCaseY() ? sumCurve->summaryCaseY()->caseName() : "";
|
||||
}
|
||||
};
|
||||
static EnsembleCurveInfoTextProvider ensembleCurveInfoTextProvider;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -376,7 +416,7 @@ void RiuSummaryQwtPlot::setCommonPlotBehaviour(QwtPlot* plot)
|
||||
plot->canvas()->installEventFilter(plot);
|
||||
plot->plotLayout()->setAlignCanvasToScales(true);
|
||||
|
||||
new RiuQwtCurvePointTracker(plot, true);
|
||||
new RiuQwtCurvePointTracker(plot, true, &ensembleCurveInfoTextProvider);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user