diff --git a/src/AnalysisSidebar.cpp b/src/AnalysisSidebar.cpp index 77f8e0ab8..0b09dc42d 100644 --- a/src/AnalysisSidebar.cpp +++ b/src/AnalysisSidebar.cpp @@ -37,6 +37,9 @@ // working with routes #include "Route.h" +// the ride cache +#include "RideCache.h" + AnalysisSidebar::AnalysisSidebar(Context *context) : QWidget(context->mainWindow), context(context) { QVBoxLayout *mainLayout = new QVBoxLayout(this); @@ -558,6 +561,14 @@ AnalysisSidebar::showIntervalMenu(const QPoint &pos) menu.addAction(actDeleteInt); } + if (type == RideFileInterval::ROUTE) { + // stop identifying this segment + QAction *actDeleteRoute = new QAction(tr("Stop tracking this segment"), intervalTree); + connect(actDeleteRoute, SIGNAL(triggered(void)), this, SLOT(deleteRoute(void))); + menu.addAction(actDeleteRoute); + + } + // BACK / FRONT NOT AVAILABLE YET //QAction *actFrontInt = new QAction(tr("Bring to Front"), intervalTree); //QAction *actBackInt = new QAction(tr("Send to back"), intervalTree); @@ -570,7 +581,7 @@ AnalysisSidebar::showIntervalMenu(const QPoint &pos) if (type != RideFileInterval::ROUTE && context->currentRideItem() && context->currentRideItem()->present.contains("G")) { - QAction *actRoute = new QAction(tr("Create as a route"), intervalTree); + QAction *actRoute = new QAction(tr("Create a route segment"), intervalTree); connect(actRoute, SIGNAL(triggered(void)), this, SLOT(createRouteIntervalSelected(void))); menu.addAction(actRoute); } @@ -774,6 +785,24 @@ AnalysisSidebar::deleteInterval() } } +void +AnalysisSidebar::deleteRoute() +{ + // stop tracking this route across rides + if (activeInterval) { + + // if refresh is running cancel it ! + context->athlete->rideCache->cancel(); + + // zap it + context->athlete->routes->deleteRoute(activeInterval->route); + activeInterval = NULL; // it goes below. + + // the fingerprint for routes has changed, refresh is inevitable sadly + context->athlete->rideCache->refresh(); + } +} + void AnalysisSidebar::editIntervalSelected() { diff --git a/src/AnalysisSidebar.h b/src/AnalysisSidebar.h index 2c6a2eb37..3654faecf 100644 --- a/src/AnalysisSidebar.h +++ b/src/AnalysisSidebar.h @@ -73,6 +73,7 @@ class AnalysisSidebar : public QWidget void addIntervals(); void editInterval(); // from right click void deleteInterval(); // from right click + void deleteRoute(); // stop tracking this route void zoomInterval(); // from right click void sortIntervals(); // from menu popup void renameIntervalsSelected(void); // from menu popup -- rename a series diff --git a/src/IntervalItem.h b/src/IntervalItem.h index 741e8894c..b29cd2a2f 100644 --- a/src/IntervalItem.h +++ b/src/IntervalItem.h @@ -63,6 +63,7 @@ class IntervalItem double startKM, stopKM; // by Distance int displaySequence; // order to display on ride plots QColor color; // color to use on plots that differentiate by color + QUuid route; // the route this interval is for // order to show on plot void setDisplaySequence(int seq) { displaySequence = seq; } diff --git a/src/RideDB.y b/src/RideDB.y index f2ccca8dd..771fd2d92 100644 --- a/src/RideDB.y +++ b/src/RideDB.y @@ -199,6 +199,7 @@ interval_tuple: string ':' string { else if ($1 == "type") jc->interval.type = static_cast($3.toInt()); else if ($1 == "color") jc->interval.color = QColor($3); else if ($1 == "seq") jc->interval.displaySequence = $3.toInt(); + else if ($1 == "route") jc->interval.route = QUuid($3); } interval_metrics: METRICS ':' '{' interval_metrics_list '}' ; @@ -404,6 +405,7 @@ void RideCache::save() firstInterval = false; stream << "\t\t\t{\n"; + // interval main data stream << "\t\t\t\"name\":\"" << protect(interval->name) <<"\",\n"; stream << "\t\t\t\"start\":\"" << interval->start <<"\",\n"; @@ -412,8 +414,15 @@ void RideCache::save() stream << "\t\t\t\"stopKM\":\"" << interval->stopKM <<"\",\n"; stream << "\t\t\t\"type\":\"" << static_cast(interval->type) <<"\",\n"; stream << "\t\t\t\"color\":\"" << interval->color.name() <<"\",\n"; + + // routes have a segment identifier + if (interval->type == RideFileInterval::ROUTE) { + stream << "\t\t\t\"route\":\"" << interval->route.toString() <<"\",\n"; // last one no ',\n' see METRICS below.. + } + stream << "\t\t\t\"seq\":\"" << interval->displaySequence <<"\""; // last one no ',\n' see METRICS below.. + // check if we have any non-zero metrics bool hasMetrics=false; foreach(double v, interval->metrics()) { diff --git a/src/Route.cpp b/src/Route.cpp index dbcbc61f4..43ffd39c9 100644 --- a/src/Route.cpp +++ b/src/Route.cpp @@ -226,6 +226,7 @@ RouteSegment::search(RideItem *item, RideFile*ride, QList&here) ++found, QColor(Qt::gray), RideFileInterval::ROUTE); + intervalItem->route = id(); here << intervalItem; // reset to restart find on next iteration @@ -322,6 +323,18 @@ Routes::newRoute(QString name) return 0; // always add at the top } +void +Routes::deleteRoute(QUuid identifier) +{ + // find via Identifier then delete + for(int i=0; i