From 3658cf22a67b5a31a2aa673c4c79280c49d5a7a0 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Wed, 19 Mar 2014 20:02:02 +0000 Subject: [PATCH] Implement Interval Hover in PfPv .. only from interval list .. need to also implement from chart hover too --- src/PfPvPlot.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++---- src/PfPvPlot.h | 4 +++- src/PfPvWindow.cpp | 44 ++++++++++++++++------------------ src/PfPvWindow.h | 2 ++ 4 files changed, 79 insertions(+), 30 deletions(-) diff --git a/src/PfPvPlot.cpp b/src/PfPvPlot.cpp index b5b469e67..25a513ca5 100644 --- a/src/PfPvPlot.cpp +++ b/src/PfPvPlot.cpp @@ -144,7 +144,7 @@ public: PfPvPlot::PfPvPlot(Context *context) - : rideItem (NULL), context(context), cp_ (0), cad_ (85), cl_ (0.175), shade_zones(true) + : rideItem (NULL), context(context), hover(NULL), cp_ (0), cad_ (85), cl_ (0.175), shade_zones(true) { static_cast(canvas())->setFrameStyle(QFrame::NoFrame); @@ -218,7 +218,7 @@ PfPvPlot::configChanged() // frame with inverse of background QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); - sym->setSize(6); + sym->setSize(4); sym->setPen(QPen(Qt::red)); sym->setBrush(QBrush(Qt::red)); curve->setSymbol(sym); @@ -482,7 +482,7 @@ PfPvPlot::setData(RideItem *_rideItem) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); - sym->setSize(6); + sym->setSize(4); sym->setPen(QPen(Qt::red)); sym->setBrush(QBrush(Qt::red)); curve->setSymbol(sym); @@ -504,6 +504,55 @@ PfPvPlot::setData(RideItem *_rideItem) replot(); } +void +PfPvPlot::intervalHover(RideFileInterval x) +{ + if (!isVisible()) return; + if (context->isCompareIntervals) return; + if (!rideItem) return; + if (!rideItem->ride()); + + // zap the old one + if (hover) { + hover->detach(); + delete hover; + hover = NULL; + } + + // collect the data + QVector aepfArray, cpvArray; + foreach(const RideFilePoint *p1, rideItem->ride()->dataPoints()) { + + if (p1->secs < x.start || p1->secs > x.stop) continue; + + if (p1->watts != 0 && p1->cad != 0) { + double aepf = (p1->watts * 60.0) / (p1->cad * cl_ * 2.0 * PI); + double cpv = (p1->cad * cl_ * 2.0 * PI) / 60.0; + + aepfArray << aepf; + cpvArray << cpv; + } + } + + // any data ? + if (aepfArray.size()) { + QwtSymbol *sym = new QwtSymbol; + sym->setStyle(QwtSymbol::Ellipse); + sym->setSize(4); + sym->setPen(QPen(Qt::gray)); + sym->setBrush(QBrush(Qt::gray)); + + hover = new QwtPlotCurve(); + hover->setSymbol(sym); + hover->setStyle(QwtPlotCurve::Dots); + hover->setRenderHint(QwtPlotItem::RenderAntialiased); + hover->setSamples(cpvArray, aepfArray); + hover->attach(this); + } + + replot(); // refresh +} + void PfPvPlot::showIntervals(RideItem *_rideItem) { @@ -627,7 +676,7 @@ PfPvPlot::showIntervals(RideItem *_rideItem) QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); - sym->setSize(6); + sym->setSize(4); sym->setBrush(QBrush(Qt::NoBrush)); QPen pen; @@ -1081,7 +1130,7 @@ PfPvPlot::showCompareIntervals() QwtSymbol *sym = new QwtSymbol; sym->setStyle(QwtSymbol::Ellipse); - sym->setSize(6); + sym->setSize(4); sym->setBrush(QBrush(Qt::NoBrush)); QPen pen; diff --git a/src/PfPvPlot.h b/src/PfPvPlot.h index 43117b1f9..1c1322faa 100644 --- a/src/PfPvPlot.h +++ b/src/PfPvPlot.h @@ -20,13 +20,13 @@ #ifndef _GC_QaPlot_h #define _GC_QaPlot_h 1 #include "GoldenCheetah.h" +#include "RideFile.h" #include #include #include // forward references -class RideFile; class RideItem; struct RideFilePoint; class QwtPlotCurve; @@ -76,6 +76,7 @@ class PfPvPlot : public QwtPlot public slots: void configChanged(); + void intervalHover(RideFileInterval); signals: void changedCP( const QString& ); @@ -90,6 +91,7 @@ class PfPvPlot : public QwtPlot Context *context; QwtPlotCurve *curve; + QwtPlotCurve *hover; QList intervalCurves; QwtPlotCurve *cpCurve; QList zoneCurves; diff --git a/src/PfPvWindow.cpp b/src/PfPvWindow.cpp index 8eb5004bc..a48fd92c6 100644 --- a/src/PfPvWindow.cpp +++ b/src/PfPvWindow.cpp @@ -21,6 +21,7 @@ #include "Athlete.h" #include "PfPvPlot.h" #include "RideItem.h" +#include "RideFile.h" #include "Settings.h" #include "Colors.h" #include @@ -166,36 +167,25 @@ PfPvWindow::PfPvWindow(Context *context) : cl->addWidget(frameIntervalPfPvCheckBox); cl->addStretch(); - connect(pfPvPlot, SIGNAL(changedCP(const QString&)), - qaCPValue, SLOT(setText(const QString&)) ); - connect(pfPvPlot, SIGNAL(changedCAD(const QString&)), - qaCadValue, SLOT(setText(const QString&)) ); - connect(pfPvPlot, SIGNAL(changedCL(const QString&)), - qaClValue, SLOT(setText(const QString&)) ); - connect(qaCPValue, SIGNAL(editingFinished()), - this, SLOT(setQaCPFromLineEdit())); - connect(qaCadValue, SIGNAL(editingFinished()), - this, SLOT(setQaCADFromLineEdit())); - connect(qaClValue, SIGNAL(editingFinished()), - this, SLOT(setQaCLFromLineEdit())); - connect(shadeZonesPfPvCheckBox, SIGNAL(stateChanged(int)), - this, SLOT(setShadeZonesPfPvFromCheckBox())); - connect(rShade, SIGNAL(stateChanged(int)), - this, SLOT(setrShadeZonesPfPvFromCheckBox())); - connect(mergeIntervalPfPvCheckBox, SIGNAL(stateChanged(int)), - this, SLOT(setMergeIntervalsPfPvFromCheckBox())); - connect(rMergeInterval, SIGNAL(stateChanged(int)), - this, SLOT(setrMergeIntervalsPfPvFromCheckBox())); - connect(frameIntervalPfPvCheckBox, SIGNAL(stateChanged(int)), - this, SLOT(setFrameIntervalsPfPvFromCheckBox())); - connect(rFrameInterval, SIGNAL(stateChanged(int)), - this, SLOT(setrFrameIntervalsPfPvFromCheckBox())); + connect(pfPvPlot, SIGNAL(changedCP(const QString&)), qaCPValue, SLOT(setText(const QString&)) ); + connect(pfPvPlot, SIGNAL(changedCAD(const QString&)), qaCadValue, SLOT(setText(const QString&)) ); + connect(pfPvPlot, SIGNAL(changedCL(const QString&)), qaClValue, SLOT(setText(const QString&)) ); + connect(qaCPValue, SIGNAL(editingFinished()), this, SLOT(setQaCPFromLineEdit())); + connect(qaCadValue, SIGNAL(editingFinished()), this, SLOT(setQaCADFromLineEdit())); + connect(qaClValue, SIGNAL(editingFinished()), this, SLOT(setQaCLFromLineEdit())); + connect(shadeZonesPfPvCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setShadeZonesPfPvFromCheckBox())); + connect(rShade, SIGNAL(stateChanged(int)), this, SLOT(setrShadeZonesPfPvFromCheckBox())); + connect(mergeIntervalPfPvCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setMergeIntervalsPfPvFromCheckBox())); + connect(rMergeInterval, SIGNAL(stateChanged(int)), this, SLOT(setrMergeIntervalsPfPvFromCheckBox())); + connect(frameIntervalPfPvCheckBox, SIGNAL(stateChanged(int)), this, SLOT(setFrameIntervalsPfPvFromCheckBox())); + connect(rFrameInterval, SIGNAL(stateChanged(int)), this, SLOT(setrFrameIntervalsPfPvFromCheckBox())); connect(doubleClickPicker, SIGNAL(doubleClicked(int, int)), this, SLOT(doubleClicked(int, int))); // GC signals connect(this, SIGNAL(rideItemChanged(RideItem*)), this, SLOT(rideSelected())); connect(context, SIGNAL(intervalSelected()), this, SLOT(intervalSelected())); connect(context, SIGNAL(intervalsChanged()), this, SLOT(intervalSelected())); + connect(context, SIGNAL(intervalHover(RideFileInterval)), this, SLOT(intervalHover(RideFileInterval))); connect(context->athlete, SIGNAL(zonesChanged()), this, SLOT(zonesChanged())); connect(context, SIGNAL(configChanged()), this, SLOT(configChanged())); connect(context, SIGNAL(configChanged()), pfPvPlot, SLOT(configChanged())); @@ -254,6 +244,12 @@ PfPvWindow::rideSelected() qaCPValue->setText(QString("%1").arg(pfPvPlot->getCP())); } +void +PfPvWindow::intervalHover(RideFileInterval x) +{ + pfPvPlot->intervalHover(x); +} + void PfPvWindow::intervalSelected() { diff --git a/src/PfPvWindow.h b/src/PfPvWindow.h index 6ba793618..a5ea0303e 100644 --- a/src/PfPvWindow.h +++ b/src/PfPvWindow.h @@ -19,6 +19,7 @@ #ifndef _GC_PfPvWindow_h #define _GC_PfPvWindow_h 1 #include "GoldenCheetah.h" +#include "RideFile.h" #include #include @@ -90,6 +91,7 @@ class PfPvWindow : public GcChartWindow void rideSelected(); void intervalSelected(); + void intervalHover(RideFileInterval); void zonesChanged(); protected slots: