#4222 Implement picking to display point value in Grid Cross Plot

This commit is contained in:
Gaute Lindkvist
2019-03-26 11:33:55 +01:00
parent 9bb657c642
commit 5b7bf99b82
9 changed files with 130 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 B

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -18,10 +18,13 @@
#include "RiuGridCrossQwtPlot.h"
#include "RiuCvfOverlayItemWidget.h"
#include "RiuRimQwtPlotCurve.h"
#include "RiuQwtCurvePointTracker.h"
#include "RiuWidgetDragger.h"
#include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCurveSet.h"
#include "RimGridCrossPlotCurve.h"
#include "RimRegularLegendConfig.h"
#include "cafCmdFeatureMenuBuilder.h"
@@ -32,6 +35,9 @@
#include "RimPlotAxisProperties.h"
#include "RiuPlotAnnotationTool.h"
#include "qwt_text.h"
#include "qwt_text_engine.h"
#include <QLabel>
#include <QMenu>
#include <QResizeEvent>
@@ -45,6 +51,26 @@ RiuGridCrossQwtPlot::RiuGridCrossQwtPlot(RimViewWindow* ownerViewWindow, QWidget
{
m_annotationTool = std::unique_ptr<RiuPlotAnnotationTool>(new RiuPlotAnnotationTool());
m_infoBox = new RiuDraggableOverlayFrame(this, canvas());
m_selectedPointMarker = new QwtPlotMarker;
// QwtPlotMarker takes ownership of the symbol, it is deleted in destructor of QwtPlotMarker
QwtSymbol* mySymbol = new QwtSymbol(QwtSymbol::Ellipse, QBrush(QColor(255, 255, 255, 50)), QPen(Qt::black, 2.0), QSize(10, 10));
m_selectedPointMarker->setSymbol(mySymbol);
m_selectedPointMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignVCenter);
m_selectedPointMarker->setSpacing(3);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuGridCrossQwtPlot::~RiuGridCrossQwtPlot()
{
if (m_selectedPointMarker->plot())
{
m_selectedPointMarker->detach();
}
delete m_selectedPointMarker;
}
//--------------------------------------------------------------------------------------------------
@@ -306,3 +332,48 @@ void RiuGridCrossQwtPlot::contextMenuEvent(QContextMenuEvent* event)
menu.exec(event->globalPos());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::selectSample(QwtPlotCurve* curve, int sampleNumber)
{
QPointF sample = curve->sample(sampleNumber);
m_selectedPointMarker->setValue(sample);
m_selectedPointMarker->setAxes(QwtPlot::xBottom, QwtPlot::yLeft);
m_selectedPointMarker->attach(this);
QString curveName = curveText(curve);
QwtText curveLabel(QString("<div style=\"margin: 4px;\"><b>%1:</b><br/>%2, %3</div>").arg(curveName).arg(sample.x()).arg(sample.y()), QwtText::RichText);
curveLabel.setBackgroundBrush(QBrush(QColor(250, 250, 250, 220)));
curveLabel.setPaintAttribute(QwtText::PaintBackground);
curveLabel.setBorderPen(QPen(Qt::black, 1.0));
curveLabel.setBorderRadius(2.0);
m_selectedPointMarker->setLabel(curveLabel);
replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGridCrossQwtPlot::clearSampleSelection()
{
m_selectedPointMarker->detach();
replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuGridCrossQwtPlot::curveText(const QwtPlotCurve* curve) const
{
auto riuCurve = dynamic_cast<const RiuRimQwtPlotCurve*>(curve);
if (riuCurve)
{
auto crossPlotCurve = dynamic_cast<const RimGridCrossPlotCurve*>(riuCurve->ownerRimCurve());
if (crossPlotCurve)
{
return crossPlotCurve->curveName();
}
}
return "";
}

View File

@@ -28,15 +28,16 @@
#include <memory>
class RimGridCrossPlotCurveSet;
class RimPlotAxisProperties;
class RiuCvfOverlayItemWidget;
class RiuDraggableOverlayFrame;
class RiuPlotAnnotationTool;
class RimPlotAxisProperties;
namespace caf
{
class TitledOverlayFrame;
}
//==================================================================================================
//
//
@@ -48,7 +49,7 @@ class RiuGridCrossQwtPlot : public RiuQwtPlot
public:
RiuGridCrossQwtPlot(RimViewWindow* ownerViewWindow, QWidget* parent = nullptr);
~RiuGridCrossQwtPlot();
void addOrUpdateCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void removeCurveSetLegend(RimGridCrossPlotCurveSet* curveSetToShowLegendFor);
void updateLegendSizesToMatchPlot();
@@ -62,6 +63,9 @@ protected:
bool resizeOverlayItemToFitPlot(caf::TitledOverlayFrame* overlayItem);
void contextMenuEvent(QContextMenuEvent*) override;
void selectSample(QwtPlotCurve* curve, int sampleNumber) override;
void clearSampleSelection() override;
QString curveText(const QwtPlotCurve* curves) const;
private:
typedef caf::PdmPointer<RimGridCrossPlotCurveSet> CurveSetPtr;
typedef QPointer<RiuCvfOverlayItemWidget> LegendPtr;
@@ -70,4 +74,6 @@ private:
InfoBoxPtr m_infoBox;
std::map<CurveSetPtr, LegendPtr> m_legendWidgets;
std::unique_ptr<RiuPlotAnnotationTool> m_annotationTool;
QwtPlotMarker* m_selectedPointMarker;
};

View File

@@ -34,9 +34,11 @@
#include "qwt_plot_grid.h"
#include "qwt_plot_layout.h"
#include "qwt_plot_magnifier.h"
#include "qwt_plot_marker.h"
#include "qwt_plot_panner.h"
#include "qwt_plot_zoomer.h"
#include "qwt_scale_engine.h"
#include "qwt_symbol.h"
#include <QEvent>
#include <QMenu>
@@ -122,6 +124,20 @@ QSize RiuQwtPlot::minimumSizeHint() const
return QSize(0, 100);
}
//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
void RiuQwtPlot::selectSample(QwtPlotCurve* curve, int sampleNumber)
{
}
//--------------------------------------------------------------------------------------------------
/// Empty default implementation
//--------------------------------------------------------------------------------------------------
void RiuQwtPlot::clearSampleSelection()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -165,7 +181,7 @@ void RiuQwtPlot::selectClosestCurve(const QPoint& pos)
{
QwtPlotCurve* closestCurve = nullptr;
double distMin = DBL_MAX;
int closestCurvePoint = -1;
const QwtPlotItemList& itmList = itemList();
for(QwtPlotItemIterator it = itmList.begin(); it != itmList.end(); it++)
{
@@ -173,17 +189,19 @@ void RiuQwtPlot::selectClosestCurve(const QPoint& pos)
{
QwtPlotCurve* candidateCurve = static_cast<QwtPlotCurve*>(*it);
double dist = DBL_MAX;
candidateCurve->closestPoint(pos, &dist);
int curvePoint = candidateCurve->closestPoint(pos, &dist);
if(dist < distMin)
{
closestCurve = candidateCurve;
distMin = dist;
closestCurvePoint = curvePoint;
}
}
}
if (closestCurve && distMin < 20)
{
CVF_ASSERT(closestCurvePoint >= 0);
caf::PdmObject* selectedPlotObject = ownerPlotDefinition()->findRimPlotObjectFromQwtCurve(closestCurve);
if (selectedPlotObject)
@@ -195,9 +213,18 @@ void RiuQwtPlot::selectClosestCurve(const QPoint& pos)
{
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem(selectedPlotObject);
}
}
}
}
if (closestCurve && distMin < 10)
{
selectSample(closestCurve, closestCurvePoint);
}
else
{
clearSampleSelection();
}
}
//--------------------------------------------------------------------------------------------------

View File

@@ -57,8 +57,10 @@ protected:
bool eventFilter(QObject* watched, QEvent* event) override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
QSize minimumSizeHint() const override;
virtual void selectSample(QwtPlotCurve* curve, int sampleNumber);
virtual void clearSampleSelection();
private:
void selectClosestCurve(const QPoint& pos);

View File

@@ -148,6 +148,14 @@ void RiuQwtSymbol::renderSymbolLabel(QPainter *painter, const QPointF& position)
painter->drawText(labelRect.topLeft(), m_label);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtSymbol::setLabel(const QString& label)
{
m_label = label;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -62,6 +62,7 @@ public:
void renderSymbols(QPainter *painter, const QPointF *points, int numPoints) const override;
void renderSymbolLabel(QPainter *painter, const QPointF& position) const;
QString label() const { return m_label; }
void setLabel(const QString& label);
void setLabelPosition(LabelPosition labelPosition);

View File

@@ -36,3 +36,11 @@ RimPlotCurve * RiuRimQwtPlotCurve::ownerRimCurve()
{
return m_ownerRimCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const RimPlotCurve* RiuRimQwtPlotCurve::ownerRimCurve() const
{
return m_ownerRimCurve;
}

View File

@@ -29,6 +29,7 @@ public:
explicit RiuRimQwtPlotCurve(RimPlotCurve* ownerRimCurve, const QString &title = QString::null);
RimPlotCurve * ownerRimCurve();
const RimPlotCurve * ownerRimCurve() const;
private:
caf::PdmPointer<RimPlotCurve> m_ownerRimCurve;