AllPlot: plot references lines

This commit is contained in:
Damien
2013-07-18 21:51:07 +02:00
parent caeaef6ea9
commit f72e2bf135
5 changed files with 115 additions and 2 deletions

View File

@@ -804,6 +804,7 @@ AllPlot::recalc()
}
setYMax();
refreshReferenceLines();
refreshIntervalMarkers();
refreshCalibrationMarkers();
refreshZoneLabels();
@@ -874,6 +875,70 @@ AllPlot::refreshCalibrationMarkers()
}
}
void
AllPlot::refreshReferenceLines()
{
foreach(QwtPlotCurve *referenceLine, referenceLines) {
referenceLine->detach();
delete referenceLine;
}
referenceLines.clear();
if (rideItem->ride()) {
foreach(const RideFilePoint *referencePoint, rideItem->ride()->referencePoints()) {
QwtPlotCurve *referenceLine;
QVector<double> xaxis;
QVector<double> yaxis;
if (bydist) {
xaxis.append(referencePlot == NULL ? smoothDistance.first() : referencePlot->smoothDistance.first());
xaxis.append(referencePlot == NULL ? smoothDistance.last() : referencePlot->smoothDistance.last());
} else {
xaxis.append(referencePlot == NULL ? smoothTime.first() : referencePlot->smoothTime.first());
xaxis.append(referencePlot == NULL ? smoothTime.last() : referencePlot->smoothTime.last());
}
if (referencePoint->watts != 0) {
referenceLine = new QwtPlotCurve(tr("Power Ref"));
referenceLine->setYAxis(yLeft);
QPen wattsPen = QPen(GColor(CPOWER));
wattsPen.setWidth(1);
wattsPen.setStyle(Qt::DashLine);
referenceLine->setPen(wattsPen);
yaxis.append(referencePoint->watts);
yaxis.append(referencePoint->watts);
} else if (referencePoint->hr != 0) {
referenceLine = new QwtPlotCurve(tr("Heart Rate Ref"));
referenceLine->setYAxis(yLeft);
QPen hrPen = QPen(GColor(CHEARTRATE));
hrPen.setWidth(1);
hrPen.setStyle(Qt::DashLine);
referenceLine->setPen(hrPen);
yaxis.append(referencePoint->hr);
yaxis.append(referencePoint->hr);
} else if (referencePoint->cad != 0) {
referenceLine = new QwtPlotCurve(tr("Cadence Ref"));
referenceLine->setYAxis(yLeft);
QPen cadPen = QPen(GColor(CCADENCE));
cadPen.setWidth(1);
cadPen.setStyle(Qt::DashLine);
referenceLine->setPen(cadPen);
yaxis.append(referencePoint->cad);
yaxis.append(referencePoint->cad);
}
referenceLine->setData(xaxis,yaxis);
referenceLine->attach(this);
referenceLine->setVisible(true);
referenceLines.append(referenceLine);
}
}
}
void
AllPlot::setYMax()
{
@@ -1210,6 +1275,7 @@ AllPlot::setDataFromPlot(AllPlot *plot, int startidx, int stopidx)
}
refreshReferenceLines();
refreshIntervalMarkers();
refreshCalibrationMarkers();
refreshZoneLabels();
@@ -1353,6 +1419,16 @@ AllPlot::setDataFromRide(RideItem *_rideItem)
foreach(QwtPlotMarker *mrk, d_mrk)
delete mrk;
d_mrk.clear();
foreach(QwtPlotMarker *mrk, cal_mrk)
delete mrk;
cal_mrk.clear();
foreach(QwtPlotCurve *referenceLine, referenceLines) {
referenceLine->detach();
delete referenceLine;
}
referenceLines.clear();
}
}

View File

@@ -62,6 +62,7 @@ class AllPlot : public QwtPlot
void refreshZoneLabels();
void refreshIntervalMarkers();
void refreshCalibrationMarkers();
void refreshReferenceLines();
void setAxisTitle(int axis, QString label);
// refresh data / plot parameters
@@ -132,6 +133,7 @@ class AllPlot : public QwtPlot
QwtPlotCurve *balanceRCurve;
QwtPlotCurve *intervalHighlighterCurve; // highlight selected intervals on the Plot
QList <AllPlotZoneLabel *> zoneLabels;
QVector<QwtPlotCurve*> referenceLines;
// source data
QVector<double> hrArray;

View File

@@ -221,8 +221,8 @@ references: REFERENCES ':' '[' reference_list ']'
JsonPoint = RideFilePoint();
}
reference_list: reference | reference_list ',' reference;
reference: '{' series '}' { //JsonRide->appendReference(JsonPoint);
//JsonPoint = RideFilePoint();
reference: '{' series '}' { JsonRide->appendReference(JsonPoint);
JsonPoint = RideFilePoint();
}
/*
@@ -442,6 +442,30 @@ JsonFileReader::writeRideFile(Context *, const RideFile *ride, QFile &file) cons
out <<"\n\t\t]";
}
//
// REFERENCES
//
if (!ride->referencePoints().empty()) {
out << ",\n\t\t\"REFERENCES\":[\n";
bool first = true;
foreach (RideFilePoint *p, ride->referencePoints()) {
if (first) first=false;
else out << ",\n";
out << "\t\t\t{ ";
if (p->watts > 0) out << " \"WATTS\":" << QString("%1").arg(p->watts);
if (p->cad > 0) out << " \"CAD\":" << QString("%1").arg(p->cad);
if (p->hr > 0) out << " \"HR\":" << QString("%1").arg(p->hr);
// sample points in here!
out << " }";
}
out <<"\n\t\t]";
}
//
// SAMPLES
//

View File

@@ -843,6 +843,12 @@ RideFile::getWeight()
return weight_;
}
void RideFile::appendReference(const RideFilePoint &point)
{
referencePoints_.append(new RideFilePoint(point.secs,point.cad,point.hr,point.km,point.kph,point.nm,point.watts,point.alt,point.lon,point.lat,
point.headwind, point.slope, point.temp, point.lrbalance, point.interval));
}
bool
RideFile::parseRideFileName(const QString &name, QDateTime *dt)
{

View File

@@ -164,6 +164,10 @@ class RideFile : public QObject // QObject to emit signals
calibrations_.append(RideFileCalibration(start, value, name));
}
// Working with REFERENCES
void appendReference(const RideFilePoint &);
const QVector<RideFilePoint*> &referencePoints() const { return referencePoints_; }
// Index offset calculations
double timeToDistance(double) const; // get distance in km at time in secs
int timeIndex(double) const; // get index offset for time in secs
@@ -217,6 +221,7 @@ class RideFile : public QObject // QObject to emit signals
QDateTime startTime_; // time of day that the ride started
double recIntSecs_; // recording interval in seconds
QVector<RideFilePoint*> dataPoints_;
QVector<RideFilePoint*> referencePoints_;
RideFilePoint* minPoint;
RideFilePoint* maxPoint;
RideFilePoint* avgPoint;