From 8eee160313af65d1775742e96f9a0fd90a0ab3cd Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Wed, 10 Jul 2019 15:12:12 +0200 Subject: [PATCH] Fixes ticket:2166 & ticket:5561 Show values of all the curves at a point. --- OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp | 4 ++ OMPlot/OMPlot/OMPlotGUI/PlotCurve.h | 2 + OMPlot/OMPlot/OMPlotGUI/PlotPicker.cpp | 56 +++++++++++++++----------- OMPlot/OMPlot/OMPlotGUI/PlotPicker.h | 3 +- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp b/OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp index 4c8b1489ec0..49efa57d119 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp @@ -62,6 +62,10 @@ PlotCurve::PlotCurve(QString fileName, QString name, QString xVariableName, QStr setLegendIconSize(QSize(30, 30)); #endif mpPlotDirectPainter = new QwtPlotDirectPainter(); + mpPointMarker = new QwtPlotMarker(); + mpPointMarker->attach(mpParentPlot); + mpPointMarker->setVisible(false); + mpPointMarker->setSymbol(new QwtSymbol(QwtSymbol::Rect, QColor(Qt::red), QColor(Qt::red), QSize(6, 6))); } PlotCurve::~PlotCurve() diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotCurve.h b/OMPlot/OMPlot/OMPlotGUI/PlotCurve.h index ea2dce66bfc..346f95b7365 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotCurve.h +++ b/OMPlot/OMPlot/OMPlotGUI/PlotCurve.h @@ -55,6 +55,7 @@ class PlotCurve : public QwtPlotCurve Plot *mpParentPlot; QwtPlotDirectPainter *mpPlotDirectPainter; + QwtPlotMarker *mpPointMarker; public: PlotCurve(QString fileName, QString name, QString xVariableName, QString yVariableName, QString unit, QString displayUnit, Plot *pParent); ~PlotCurve(); @@ -99,6 +100,7 @@ class PlotCurve : public QwtPlotCurve void toggleVisibility(); void setData(const double* xData, const double* yData, int size); QwtPlotDirectPainter* getPlotDirectPainter() {return mpPlotDirectPainter;} + QwtPlotMarker* getPointMarker() const {return mpPointMarker;} #if QWT_VERSION < 0x060000 virtual void updateLegend(QwtLegend *legend) const; #endif diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotPicker.cpp b/OMPlot/OMPlot/OMPlotGUI/PlotPicker.cpp index 92d65546ba7..df0bd729825 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotPicker.cpp +++ b/OMPlot/OMPlot/OMPlotGUI/PlotPicker.cpp @@ -88,27 +88,26 @@ PlotPicker::PlotPicker(QWidget *pCanvas, Plot *pPlot) : QwtPlotPicker(pCanvas) { mpPlot = pPlot; - mpPointMarker = new QwtPlotMarker(); - mpPointMarker->attach(mpPlot); - mpPointMarker->setVisible(false); - mpPointMarker->setSymbol(new QwtSymbol(QwtSymbol::Rect, QColor(Qt::red), QColor(Qt::red), QSize(6, 6))); } /*! - * \brief PlotPicker::curveAtPosition - * Checks the curve at the mouse position. - * Finds the closest point on the curve and then checks if this point is close enough to our mouse position. + * \brief PlotPicker::curvesAtPosition + * Checks the curves at the mouse position. + * Finds the closest point on the curves and then checks if this point is close enough to our mouse position. * \param pos - * \param pPlotCurve - * \param index + * \param indexes * \return */ -bool PlotPicker::curveAtPosition(const QPoint pos, PlotCurve *&pPlotCurve, int &index) const +QList PlotPicker::curvesAtPosition(const QPoint pos, QList *indexes) const { QPointF posF = invTransform(pos); + int index = -1; + QList plotCurvesList; + PlotCurve *pPlotCurve = 0; const QwtPlotItemList plotCurves = plot()->itemList(QwtPlotItem::Rtti_PlotCurve); for (int i = 0 ; i < plotCurves.size() ; i++) { pPlotCurve = static_cast(plotCurves[i]); + pPlotCurve->getPointMarker()->setVisible(false); if (pPlotCurve->isVisible()) { // find the closest point index = pPlotCurve->closestPoint(pos); @@ -140,13 +139,14 @@ bool PlotPicker::curveAtPosition(const QPoint pos, PlotCurve *&pPlotCurve, int & QPointF curvePointA(pPlotCurve->mXAxisVector.at(index), pPlotCurve->mYAxisVector.at(index)); QPointF curvePointB(pPlotCurve->mXAxisVector.at(index1), pPlotCurve->mYAxisVector.at(index1)); if (containsPoint(posF, curvePointA, curvePointB, x, y)) { - return true; + plotCurvesList.append(pPlotCurve); + indexes->append(index); } } } } } - return false; + return plotCurvesList; } /*! @@ -158,24 +158,32 @@ bool PlotPicker::curveAtPosition(const QPoint pos, PlotCurve *&pPlotCurve, int & */ QwtText PlotPicker::trackerText(const QPoint &pos) const { - int index = -1; - PlotCurve *pPlotCurve = 0; - if (curveAtPosition(pos, pPlotCurve, index)) { - mpPointMarker->setValue(pPlotCurve->mXAxisVector.at(index), pPlotCurve->mYAxisVector.at(index)); - mpPointMarker->setVisible(true); + QList indexes; + QList plotCurves = curvesAtPosition(pos, &indexes); + if (!plotCurves.isEmpty()) { QString timeUnit = ""; if (!mpPlot->getParentPlotWindow()->getTimeUnit().isEmpty()) { timeUnit = QString("%1").arg(mpPlot->getParentPlotWindow()->getTimeUnit()); } - QString toolTip = QString("Name: %1 %2
Value: %3 at %4 %5
Filename: %6") - .arg(pPlotCurve->getName()).arg(pPlotCurve->getDisplayUnit()) - .arg(pPlotCurve->mYAxisVector.at(index)) - .arg(pPlotCurve->mXAxisVector.at(index)) - .arg(timeUnit) - .arg(pPlotCurve->getFileName()); + QString toolTip; + for (int i = 0 ; i < plotCurves.size() ; i++) { + PlotCurve *pPlotCurve = plotCurves.at(i); + int index = indexes.at(i); + pPlotCurve->getPointMarker()->setValue(pPlotCurve->mXAxisVector.at(index), pPlotCurve->mYAxisVector.at(index)); + pPlotCurve->getPointMarker()->setVisible(true); + + if (i > 0) { + toolTip += QString("

"); + } + toolTip += QString("Name: %1 %2
Value: %3 at %4 %5
Filename: %6") + .arg(pPlotCurve->getName()).arg(pPlotCurve->getDisplayUnit()) + .arg(pPlotCurve->mYAxisVector.at(index)) + .arg(pPlotCurve->mXAxisVector.at(index)) + .arg(timeUnit) + .arg(pPlotCurve->getFileName()); + } QToolTip::showText(canvas()->mapToGlobal(pos), toolTip, nullptr); } else { - mpPointMarker->setVisible(false); QToolTip::hideText(); } return QString(""); diff --git a/OMPlot/OMPlot/OMPlotGUI/PlotPicker.h b/OMPlot/OMPlot/OMPlotGUI/PlotPicker.h index 7e9926661a3..cb58ac8cdc4 100644 --- a/OMPlot/OMPlot/OMPlotGUI/PlotPicker.h +++ b/OMPlot/OMPlot/OMPlotGUI/PlotPicker.h @@ -42,11 +42,10 @@ class PlotPicker : public QwtPlotPicker { public: PlotPicker(QWidget *pCanvas, Plot *pPlot); - bool curveAtPosition(const QPoint pos, PlotCurve *&pPlotCurve, int &index) const; + QList curvesAtPosition(const QPoint pos, QList *indexes) const; virtual QwtText trackerText(const QPoint &pos) const; private: Plot *mpPlot; - QwtPlotMarker *mpPointMarker; }; }