Allow user to stop tracking a segment

.. in case you add one that isn't useful.
This commit is contained in:
Mark Liversedge
2015-05-29 12:42:41 +01:00
parent 41890c852a
commit 082ee3b4c0
6 changed files with 55 additions and 1 deletions

View File

@@ -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()
{

View File

@@ -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

View File

@@ -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; }

View File

@@ -199,6 +199,7 @@ interval_tuple: string ':' string {
else if ($1 == "type") jc->interval.type = static_cast<RideFileInterval::intervaltype>($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<int>(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()) {

View File

@@ -226,6 +226,7 @@ RouteSegment::search(RideItem *item, RideFile*ride, QList<IntervalItem*>&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<routes.count(); i++) {
if (routes.at(i).id() == identifier) {
deleteRoute(i);
return;
}
}
}
void
Routes::deleteRoute(int index)
{

View File

@@ -101,6 +101,7 @@ class Routes : public QObject { // top-level object with API and map of segments
void readRoutes();
int newRoute(QString name);
void createRouteFromInterval(IntervalItem *activeInterval);
void deleteRoute(QUuid);
void deleteRoute(int);
void writeRoutes();