diff --git a/src/AllPlotInterval.cpp b/src/AllPlotInterval.cpp index bd679923f..8395547ca 100644 --- a/src/AllPlotInterval.cpp +++ b/src/AllPlotInterval.cpp @@ -95,12 +95,12 @@ AllPlotInterval::AllPlotInterval(QWidget *parent, Context *context): setPalette(pal); // tick draw - TimeScaleDraw *tsd = new TimeScaleDraw(&this->bydist) ; - tsd->setTickLength(QwtScaleDiv::MajorTick, 3); - setAxisScaleDraw(QwtPlot::xBottom, tsd); - pal.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); - pal.setColor(QPalette::Text, GColor(CPLOTMARKER)); - axisWidget(QwtPlot::xBottom)->setPalette(pal); + //TimeScaleDraw *tsd = new TimeScaleDraw(&this->bydist) ; + //tsd->setTickLength(QwtScaleDiv::MajorTick, 3); + //setAxisScaleDraw(QwtPlot::xBottom, tsd); + //pal.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); + //pal.setColor(QPalette::Text, GColor(CPLOTMARKER)); + //axisWidget(QwtPlot::xBottom)->setPalette(pal); enableAxis(xBottom, false); setAxisVisible(xBottom, false); @@ -145,27 +145,56 @@ AllPlotInterval::setDataFromRide(RideItem *_rideItem) void AllPlotInterval::refreshIntervals() { - sortIntervals(); + placeIntervals(); refreshIntervalCurve(); //refreshIntervalMarkers(); } // Compare two RideFileInterval on duration. - bool intervalBiggerThan(const RideFileInterval &i1, const RideFileInterval &i2) +bool intervalBiggerThan(const RideFileInterval &i1, const RideFileInterval &i2) { return (i1.stop-i1.start) > (i2.stop-i2.start); } void -AllPlotInterval::sortIntervals() +AllPlotInterval::sortIntervals(QList &intervals, QList< QList > &intervalsGroups) +{ + // Sort by duration + qSort(intervals.begin(), intervals.end(), intervalBiggerThan); + + QList matchesGroup; + + for (int i=0; i 0) + intervalsGroups.append(matchesGroup); + +} + +void +AllPlotInterval::placeIntervals() { QList intervals = rideItem->ride()->intervals(); - qSort(intervals.begin(), intervals.end(), intervalBiggerThan); + QList< QList > intervalsGroups; + + sortIntervals(intervals, intervalsGroups); intervalLigns.clear(); - QList intervalsLign1; - intervalLigns.append(intervalsLign1); + if (intervalsGroups.count()>0) + intervalLigns.append(intervalsGroups.at(0)); + else { + QList intervalsLign1; + intervalLigns.append(intervalsLign1); + } while (intervals.count()>0) { const RideFileInterval &interval = intervals.first(); @@ -176,6 +205,11 @@ AllPlotInterval::sortIntervals() while (!placed) { bool place = true; + /*if (interval.isPeak()) { + intervals.removeFirst(); + placed = true; + }*/ + foreach(const RideFileInterval &placedinterval, intervalLigns.at(lign)) { if (interval.stop>placedinterval.start && interval.startdetach(); - delete mrk; + QColor color; + if (interval.isPeak()) { + color = Qt::lightGray; + } else if (interval.isMatch()) { + color = Qt::red; } - markers.clear(); - - QRegExp wkoAuto("^(Peak *[0-9]*(s|min)|Entire workout|Find #[0-9]*) *\\([^)]*\\)$"); - - int level=0; - foreach(const QList &intervalsLign, intervalLigns) { - - foreach(const RideFileInterval &interval, intervalsLign) { - - bool wko = false; - - // skip WKO autogenerated peak intervals - if (wkoAuto.exactMatch(interval.name)) wko = true; - - QwtPlotMarker *mrk = new QwtPlotMarker; - markers.append(mrk); - mrk->attach(this); - mrk->setLineStyle(QwtPlotMarker::NoLine); - mrk->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); - - if (wko) mrk->setLinePen(QPen(QColor(127,127,127,127), 0, Qt::DashLine)); - else mrk->setLinePen(QPen(GColor(CPLOTMARKER), 0, Qt::DashLine)); - - // put matches on second line down - QString name(interval.name); - if (interval.name.startsWith(tr("Match"))) name = QString("\n%1").arg(interval.name); - - QwtText text(!wko ? name : ""); - - if (!wko) { - text.setFont(QFont("Helvetica", 10, QFont::Bold)); - if (interval.name.startsWith(tr("Match"))) - text.setColor(GColor(CWBAL)); - else - text.setColor(GColor(CPLOTMARKER)); - } - - mrk->setYAxis(yLeft); - if (!bydist) - mrk->setValue(interval.start / 60.0, 3000*intervalLigns.count()-2200-3000*level); - else - mrk->setValue((context->athlete->useMetricUnits ? 1 : MILES_PER_KM) * - rideItem->ride()->timeToDistance(interval.start), 3000*intervalLigns.count()-2200-3000*level); - mrk->setLabel(text); - - /*qDebug() << "width()" << width() << "widthMM()" << widthMM() << devicePixelRatio(); - - double widthInt = transform(QwtPlot::xBottom, interval.stop) - transform(QwtPlot::xBottom, interval.start); - - qDebug() << "widthInt" << widthInt << interval.stop << transform(QwtPlot::xBottom, interval.stop) << interval.start << transform(QwtPlot::xBottom, interval.start); - int width = 0; - - do { - QFontMetrics fontMetrics( mrk->label().font() ); - width = fontMetrics.width( text.text() ); - qDebug() << "width" << width; - - if (width > widthInt) - text.setText(text.text().left(text.text().size()-2)); - - } while (width > widthInt ); - */ - - } - level++; + else { + color = GColor(CINTERVALHIGHLIGHTER); } + + QPen ihlPen = QPen(color); + intervalCurve->setPen(ihlPen); + QColor ihlbrush = QColor(color); + if (!selected) + ihlbrush.setAlpha(128); + intervalCurve->setPen(ihlbrush); // fill below the line + intervalCurve->setBrush(ihlbrush); // fill below the line } - - void AllPlotInterval::refreshIntervalCurve() { - foreach(QwtPlotIntervalCurve *curve, curves) { + foreach(QwtPlotIntervalCurve *curve, curves.values()) { curve->detach(); delete curve; } @@ -291,12 +270,7 @@ AllPlotInterval::refreshIntervalCurve() QwtPlotIntervalCurve *intervalCurve = new QwtPlotIntervalCurve(); intervalCurve->setYAxis(QwtAxis::yLeft); - QPen ihlPen = QPen(GColor(CINTERVALHIGHLIGHTER)); - intervalCurve->setPen(ihlPen); - QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER)); - ihlbrush.setAlpha(128); - intervalCurve->setPen(ihlbrush); // fill below the line - intervalCurve->setBrush(ihlbrush); // fill below the line + setColorForIntervalCurve(intervalCurve, interval, false); int max = 3000*intervalLigns.count(); intervalCurve->setSamples(new AllPlotIntervalData(this, context, level, max, rideItem, interval)); @@ -313,14 +287,9 @@ AllPlotInterval::intervalHover(RideFileInterval chosen) { foreach(RideFileInterval interval, curves.keys()) { if (chosen == interval || context->athlete->allIntervalItems()->child(rideItem->ride()->intervals().indexOf(interval))->isSelected()) { - QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER)); - ihlbrush.setAlpha(255); - curves.value(interval)->setBrush(ihlbrush); + setColorForIntervalCurve(curves.value(interval), interval, true); } else { - QColor ihlbrush = QColor(GColor(CINTERVALHIGHLIGHTER)); - ihlbrush.setAlpha(128); - curves.value(interval)->setPen(ihlbrush); - curves.value(interval)->setBrush(ihlbrush); + setColorForIntervalCurve(curves.value(interval), interval, false); } } replot(); diff --git a/src/AllPlotInterval.h b/src/AllPlotInterval.h index a627a26b7..68ad1819c 100644 --- a/src/AllPlotInterval.h +++ b/src/AllPlotInterval.h @@ -76,9 +76,9 @@ class AllPlotInterval : public QwtPlot protected: - void sortIntervals(); + void sortIntervals(QList &intervals, QList > &intervalsGroups); + void placeIntervals(); void refreshIntervalCurve(); - void refreshIntervalMarkers(); Context *context; RideItem *rideItem; @@ -90,6 +90,7 @@ class AllPlotInterval : public QwtPlot QMap curves; private: + void setColorForIntervalCurve(QwtPlotIntervalCurve *intervalCurve, const RideFileInterval &interval, bool selected); AllPlotIntervalCanvasPicker *canvasPicker; // allow point selection/hover LTMToolTip *tooltip; diff --git a/src/RideFile.h b/src/RideFile.h index fc62e38ec..f8013a57a 100644 --- a/src/RideFile.h +++ b/src/RideFile.h @@ -90,6 +90,9 @@ struct RideFileInterval bool operator< (RideFileInterval right) const { return start < right.start; } bool operator== (RideFileInterval right) const { return start == right.start && stop == right.stop; } bool operator!= (RideFileInterval right) const { return start != right.start || stop != right.stop; } + + bool isPeak() const { return QRegExp("^(Peak *[0-9]*(s|min)|Entire workout|Find #[0-9]*) *\\([^)]*\\)$").exactMatch(name); } + bool isMatch() const { return QRegExp("^(Match ).*").exactMatch(name); } }; struct RideFileCalibration