From 63dbaa25d9aae1ac3bb0bc24092a148e5e56ceca Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Fri, 22 May 2015 17:20:02 +0100 Subject: [PATCH] Reinstating Interval functions: ADD ON GOOGLE MAP .. by click and drag --- src/AllPlotWindow.cpp | 13 ++------ src/GoogleMapControl.cpp | 67 +++++++++++++++++----------------------- src/IntervalItem.cpp | 28 +++++++++++++++++ src/IntervalItem.h | 4 +++ 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/src/AllPlotWindow.cpp b/src/AllPlotWindow.cpp index 7525eb994..82affe9ac 100644 --- a/src/AllPlotWindow.cpp +++ b/src/AllPlotWindow.cpp @@ -2018,18 +2018,9 @@ AllPlotWindow::setEndSelection(AllPlot* plot, double xValue, bool newInterval, Q // are we adjusting an existing interval? - if so delete it and readd it if (users.count() > 0 && users.last()->name.startsWith(name)) { - // update interval + // update interval - could do via a IntervalItem::setXX() function IntervalItem *interval = users.last(); - interval->rideInterval->start = interval->start = duration1; - interval->rideInterval->stop = interval->stop = duration2; - interval->startKM = distance1; - interval->stopKM = distance2; - interval->refresh(); - - // update ridefile - ride->setDirty(true); - - // + interval->setValues(interval->name, duration1, duration2, distance1, distance2); } else { diff --git a/src/GoogleMapControl.cpp b/src/GoogleMapControl.cpp index 0a1334cbb..c47d320e8 100644 --- a/src/GoogleMapControl.cpp +++ b/src/GoogleMapControl.cpp @@ -765,16 +765,15 @@ void WebBridge::hoverPath(double lat, double lng) { if (point) { -#if 0 //XXX REFACTOR -- HOW TO CREATE AND EDIT AN INTERVAL! RideItem *rideItem = gm->property("ride").value(); QString name = QString(tr("Selection #%1 ")).arg(selection); - int count = + if (rideItem->intervals(RideFileInterval::USER).count()) { - if (count > 0) { - IntervalItem *bottom = (IntervalItem *) allIntervals->child(count-1); - if (bottom->text(0).startsWith(name)) { //delete allIntervals->takeChild(count-1); + IntervalItem *last = rideItem->intervals(RideFileInterval::USER).last(); + + if (last->name.startsWith(name) && last->rideInterval) { QList list = searchPoint(lat, lng); @@ -783,80 +782,70 @@ WebBridge::hoverPath(double lat, double lng) RideFilePoint* secondPoint = list.at(0); if (secondPoint->secs>point->secs) { - bottom->start = point->secs; - bottom->stop = secondPoint->secs; + last->rideInterval->start = last->start = point->secs; + last->rideInterval->stop = last->stop = secondPoint->secs; } else { - bottom->stop = point->secs; - bottom->start = secondPoint->secs; + last->rideInterval->stop = last->stop = point->secs; + last->rideInterval->start = last->start = secondPoint->secs; } + last->startKM = last->rideItem()->ride()->timeToDistance(last->start); + last->stopKM = last->rideItem()->ride()->timeToDistance(last->stop); + + // update metrics + last->refresh(); + + // mark dirty + last->rideItem()->setDirty(true); // overlay a shaded route - gm->drawTempInterval(bottom); + gm->drawTempInterval(last); + + // update charts etc + context->notifyIntervalsChanged(); } } } - - - - // add average power to the end of the selection name //name += QString("(%1 watts)").arg(round((wattsTotal && arrayLength) ? wattsTotal/arrayLength : 0)); // now update the RideFileIntervals and all the plots etc //context->athlete->updateRideFileIntervals(); - -#endif } } void WebBridge::clickPath(double lat, double lng) { - -#if 0 //XXX REFACTOR HOW TO SELECT AND EDIT AND INTERVAL selection++; RideItem *rideItem = gm->property("ride").value(); QString name = QString(tr("Selection #%1 ")).arg(selection); QList list = searchPoint(lat, lng); if (list.count() > 0) { + point = list.at(0); - QTreeWidgetItem *allIntervals = context->athlete->mutableIntervalItems(); + IntervalItem *add = rideItem->newInterval(name, point->secs, point->secs, 0, 0); + add->selected = true; - QTreeWidgetItem *last = new IntervalItem(rideItem->ride(), name, point->secs, point->secs, 0, 0, - allIntervals->childCount()+1, RideFileInterval::USER); - last->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); - allIntervals->addChild(last); + // rebuild list in sidebar + context->notifyIntervalsUpdate(rideItem); - context->athlete->intervalTreeWidget()->clearSelection(); - context->athlete->intervalTreeWidget()->setItemSelected(last, true); - } - else + } else { point = NULL; -#endif + } } void WebBridge::mouseup() { -#if 0 //XXX REFACTOR CREATE AND EDIT NEW INTERVAL + // clear the temorary highlighter if (point) { gm->clearTempInterval(); - QTreeWidgetItem *allIntervals = context->athlete->mutableIntervalItems(); - int count = allIntervals->childCount(); - - if (count > 0) { - IntervalItem *bottom = (IntervalItem *) allIntervals->child(count-1); - context->athlete->intervalTreeWidget()->setItemSelected(bottom, true); - } - - context->athlete->updateRideFileIntervals(); point = NULL; } -#endif } diff --git a/src/IntervalItem.cpp b/src/IntervalItem.cpp index 551398183..ce8c613ca 100644 --- a/src/IntervalItem.cpp +++ b/src/IntervalItem.cpp @@ -54,6 +54,34 @@ IntervalItem::setFrom(IntervalItem &other) selected = false; } +void +IntervalItem::setValues(QString name, double duration1, double duration2, + double distance1, double distance2) +{ + // apply the update + this->name = name; + start = duration1; + stop = duration2; + startKM = distance1; + stopKM = distance2; + + // only accept changes if we can send on + if (type == RideFileInterval::USER && rideInterval) { + + // update us and our ridefileinterval + rideInterval->start = start = duration1; + rideInterval->stop = stop = duration2; + startKM = distance1; + stopKM = distance2; + + // update ridefile + rideItem_->setDirty(true); + } + + // update metrics + refresh(); +} + void IntervalItem::refresh() { diff --git a/src/IntervalItem.h b/src/IntervalItem.h index 7ca6d12f2..ec82db3c2 100644 --- a/src/IntervalItem.h +++ b/src/IntervalItem.h @@ -44,6 +44,10 @@ class IntervalItem // set from other void setFrom(IntervalItem &other); + // change basic values, will also apply to ridefile + void setValues(QString name, double duration1, double duration2, + double distance1, double distance2); + // is this interval currently selected ? bool selected;