mirror of
https://github.com/OPM/ResInsight.git
synced 2026-09-03 20:53:13 -05:00
#1321 Applied new plot marker tracker class to well log plots
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
#include "RimWellLogCurve.h"
|
#include "RimWellLogCurve.h"
|
||||||
|
|
||||||
#include "RiuMainPlotWindow.h"
|
#include "RiuMainPlotWindow.h"
|
||||||
|
#include "RiuQwtCurvePointTracker.h"
|
||||||
|
|
||||||
#include "qwt_legend.h"
|
#include "qwt_legend.h"
|
||||||
#include "qwt_plot_curve.h"
|
#include "qwt_plot_curve.h"
|
||||||
@@ -48,53 +49,6 @@
|
|||||||
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
|
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
|
||||||
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
|
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
class RiuWellLogTrackQwtPicker : public QwtPlotPicker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit RiuWellLogTrackQwtPicker(QWidget *canvas)
|
|
||||||
: QwtPlotPicker(canvas)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
virtual QwtText trackerText(const QPoint& pos) const override
|
|
||||||
{
|
|
||||||
QwtText txt;
|
|
||||||
|
|
||||||
const RiuWellLogTrack* wellLogTrack = dynamic_cast<const RiuWellLogTrack*>(this->plot());
|
|
||||||
if (wellLogTrack)
|
|
||||||
{
|
|
||||||
QString depthString;
|
|
||||||
QString valueString;
|
|
||||||
QPointF closestPoint = wellLogTrack->closestCurvePoint(pos, &valueString, &depthString);
|
|
||||||
if (!closestPoint.isNull())
|
|
||||||
{
|
|
||||||
QString str = valueString;
|
|
||||||
|
|
||||||
if (!depthString.isEmpty())
|
|
||||||
{
|
|
||||||
str += QString(" (%1)").arg(depthString);
|
|
||||||
}
|
|
||||||
|
|
||||||
txt.setText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
RiuWellLogTrack* nonConstPlot = const_cast<RiuWellLogTrack*>(wellLogTrack);
|
|
||||||
nonConstPlot->updateClosestCurvePointMarker(closestPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
return txt;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -111,14 +65,8 @@ RiuWellLogTrack::RiuWellLogTrack(RimWellLogTrack* plotTrackDefinition, QWidget*
|
|||||||
setDefaults();
|
setDefaults();
|
||||||
|
|
||||||
// Create a plot picker to display values next to mouse cursor
|
// Create a plot picker to display values next to mouse cursor
|
||||||
m_plotPicker = new RiuWellLogTrackQwtPicker(this->canvas());
|
|
||||||
m_plotPicker->setTrackerMode(QwtPicker::AlwaysOn);
|
|
||||||
|
|
||||||
m_plotMarker = new QwtPlotMarker;
|
m_curvePointTracker = new RiuQwtCurvePointTracker(this, false);
|
||||||
|
|
||||||
// QwtPlotMarker takes ownership of the symbol, it is deleted in destructor of QwtPlotMarker
|
|
||||||
QwtSymbol* mySymbol = new QwtSymbol(QwtSymbol::Ellipse, Qt::NoBrush, QPen(Qt::black, 2.0), QSize(12, 12));
|
|
||||||
m_plotMarker->setSymbol(mySymbol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -128,100 +76,8 @@ RiuWellLogTrack::~RiuWellLogTrack()
|
|||||||
{
|
{
|
||||||
m_grid->detach();
|
m_grid->detach();
|
||||||
delete m_grid;
|
delete m_grid;
|
||||||
|
|
||||||
m_plotMarker->detach();
|
|
||||||
delete m_plotMarker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
QPointF RiuWellLogTrack::closestCurvePoint(const QPoint& pos, QString* valueString, QString* depthString) const
|
|
||||||
{
|
|
||||||
QPointF samplePoint;
|
|
||||||
|
|
||||||
QwtPlotCurve* closestCurve = nullptr;
|
|
||||||
double distMin = DBL_MAX;
|
|
||||||
int closestPointSampleIndex = -1;
|
|
||||||
|
|
||||||
const QwtPlotItemList& itmList = itemList();
|
|
||||||
for (QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
|
|
||||||
{
|
|
||||||
if ((*it)->rtti() == QwtPlotItem::Rtti_PlotCurve)
|
|
||||||
{
|
|
||||||
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
|
|
||||||
double dist = DBL_MAX;
|
|
||||||
int candidateSampleIndex = candidateCurve->closestPoint(pos, &dist);
|
|
||||||
if (dist < distMin)
|
|
||||||
{
|
|
||||||
closestCurve = candidateCurve;
|
|
||||||
distMin = dist;
|
|
||||||
closestPointSampleIndex = candidateSampleIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (closestCurve && distMin < 50)
|
|
||||||
{
|
|
||||||
samplePoint = closestCurve->sample(closestPointSampleIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (depthString)
|
|
||||||
{
|
|
||||||
const QwtScaleDraw* depthAxisScaleDraw = axisScaleDraw(QwtPlot::yLeft);
|
|
||||||
if (depthAxisScaleDraw)
|
|
||||||
{
|
|
||||||
*depthString = depthAxisScaleDraw->label(samplePoint.y()).text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valueString && closestCurve)
|
|
||||||
{
|
|
||||||
const QwtScaleDraw* xAxisScaleDraw = axisScaleDraw(closestCurve->xAxis());
|
|
||||||
if (xAxisScaleDraw)
|
|
||||||
{
|
|
||||||
*valueString = xAxisScaleDraw->label(samplePoint.x()).text();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return samplePoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
void RiuWellLogTrack::updateClosestCurvePointMarker(const QPointF& pos)
|
|
||||||
{
|
|
||||||
bool replotRequired = false;
|
|
||||||
|
|
||||||
if (!pos.isNull())
|
|
||||||
{
|
|
||||||
if (!m_plotMarker->plot())
|
|
||||||
{
|
|
||||||
m_plotMarker->attach(this);
|
|
||||||
|
|
||||||
replotRequired = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_plotMarker->value() != pos)
|
|
||||||
{
|
|
||||||
m_plotMarker->setValue(pos.x(), pos.y());
|
|
||||||
|
|
||||||
replotRequired = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (m_plotMarker->plot())
|
|
||||||
{
|
|
||||||
m_plotMarker->detach();
|
|
||||||
|
|
||||||
replotRequired = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (replotRequired) this->replot();
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
@@ -452,12 +308,7 @@ QSize RiuWellLogTrack::minimumSizeHint() const
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuWellLogTrack::leaveEvent(QEvent *)
|
void RiuWellLogTrack::leaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
if (m_plotMarker->plot())
|
m_curvePointTracker->removeMarkerOnFocusLeave();
|
||||||
{
|
|
||||||
m_plotMarker->detach();
|
|
||||||
|
|
||||||
replot();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
class RimWellLogTrack;
|
class RimWellLogTrack;
|
||||||
|
|
||||||
|
class RiuQwtCurvePointTracker;
|
||||||
|
|
||||||
class QwtLegend;
|
class QwtLegend;
|
||||||
class QwtPicker;
|
class QwtPicker;
|
||||||
class QwtPlotGrid;
|
class QwtPlotGrid;
|
||||||
@@ -61,17 +63,12 @@ protected:
|
|||||||
virtual void leaveEvent(QEvent *) override;
|
virtual void leaveEvent(QEvent *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class RiuWellLogTrackQwtPicker;
|
|
||||||
QPointF closestCurvePoint(const QPoint& pos, QString* valueString, QString* depthString) const;
|
|
||||||
void updateClosestCurvePointMarker(const QPointF& pos);
|
|
||||||
|
|
||||||
void setDefaults();
|
void setDefaults();
|
||||||
void selectClosestCurve(const QPoint& pos);
|
void selectClosestCurve(const QPoint& pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmPointer<RimWellLogTrack> m_plotTrackDefinition;
|
caf::PdmPointer<RimWellLogTrack> m_plotTrackDefinition;
|
||||||
QwtPlotGrid* m_grid;
|
QwtPlotGrid* m_grid;
|
||||||
QwtPicker* m_plotPicker;
|
RiuQwtCurvePointTracker* m_curvePointTracker;
|
||||||
QwtPlotMarker* m_plotMarker;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user