From 597dccff9c6dd55fe7640b39d40a548d3a0df34f Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Fri, 22 May 2015 11:58:16 +0100 Subject: [PATCH] Reinstating Interval functions: RENAMING/RENUMBERING .. rename a number of intervals in one go --- src/AnalysisSidebar.cpp | 117 +++++++++++++++++++--------------------- src/AnalysisSidebar.h | 2 - src/IntervalItem.cpp | 2 +- src/RideItem.cpp | 6 +-- src/RideItem.h | 8 +-- 5 files changed, 63 insertions(+), 72 deletions(-) diff --git a/src/AnalysisSidebar.cpp b/src/AnalysisSidebar.cpp index 2f4d0a5c5..ac5449bcb 100644 --- a/src/AnalysisSidebar.cpp +++ b/src/AnalysisSidebar.cpp @@ -671,45 +671,59 @@ AnalysisSidebar::sortIntervals() void AnalysisSidebar::renameIntervalsSelected() { -#if 0 - QString string; + QTreeWidgetItem *userIntervals = trees.value(RideFileInterval::USER, NULL); - // set string to first interval selected - for (int i=0; iathlete->allIntervals->childCount();i++) { - if (context->athlete->allIntervals->child(i)->isSelected()) { - string = context->athlete->allIntervals->child(i)->text(0); - break; + // what are we renaming? + if (context->currentRideItem() && userIntervals && userIntervals->childCount() && + context->currentRideItem()->intervalsSelected(RideFileInterval::USER).count()) { + + QString string = context->currentRideItem()->intervalsSelected(RideFileInterval::USER).first()->name; + + // type in a name and we will renumber all the intervals + // in the same fashion -- esp if the last characters are + RenameIntervalDialog dialog(string, this); + dialog.setFixedWidth(320); + + if (dialog.exec()) { + + int number = 1; + + // does it end in a number? + // if so we use that to renumber from + QRegExp ends("^(.*)([0-9]+)$"); + if (ends.exactMatch(string)) { + + string = ends.cap(1); + number = ends.cap(2).toInt(); + + } else if (!string.endsWith(" ")) string += " "; + + // now go and renumber from 'number' with prefix 'string' + for(int j=0; jchildCount(); j++) { + + // get pointer to the IntervalItem for this item + QVariant v = userIntervals->child(j)->data(0, Qt::UserRole); + + // make the IntervalItem selected flag reflect the current selection state + IntervalItem *item = static_cast(v.value()); + + // is it selected and linked ? + if (item && item->selected && item->rideInterval) { + + // set item and ride + item->rideInterval->name = item->name = + QString("%1%2").arg(string).arg(number++); + + // update tree to reflect changes! + userIntervals->child(j)->setText(0, item->name); + } + } + + // mark dirty and tell the charts it changed + const_cast(context->currentRideItem())->setDirty(true); + context->notifyIntervalsChanged(); } } - - // type in a name and we will renumber all the intervals - // in the same fashion -- esp if the last characters are - RenameIntervalDialog dialog(string, this); - dialog.setFixedWidth(320); - - if (dialog.exec()) { - - int number = 1; - - // does it end in a number? - // if so we use that to renumber from - QRegExp ends("^(.*[^0-9])([0-9]+)$"); - if (ends.exactMatch(string)) { - - string = ends.cap(1); - number = ends.cap(2).toInt(); - - } else if (!string.endsWith(" ")) string += " "; - - // now go and renumber from 'number' with prefix 'string' - for (int i=0; iathlete->allIntervals->childCount();i++) { - if (context->athlete->allIntervals->child(i)->isSelected()) - context->athlete->allIntervals->child(i)->setText(0, QString("%1%2").arg(string).arg(number++)); - } - - context->athlete->updateRideFileIntervals(); // will emit intervalChanged() signal - } -#endif } void @@ -748,6 +762,7 @@ AnalysisSidebar::deleteIntervalSelected() userIntervals->removeChild(item); delete item; } + context->notifyIntervalsChanged(); } } @@ -780,35 +795,10 @@ AnalysisSidebar::deleteInterval() } } } + context->notifyIntervalsChanged(); } } -void -AnalysisSidebar::renameIntervalSelected() -{ -#if 0 - // go edit the name - for (int i=0; iathlete->allIntervals->childCount();) { - if (context->athlete->allIntervals->child(i)->isSelected()) { - context->athlete->allIntervals->child(i)->setFlags(context->athlete->allIntervals->child(i)->flags() | Qt::ItemIsEditable); - context->athlete->intervalWidget->editItem(context->athlete->allIntervals->child(i), 0); - break; - } else i++; - } - context->athlete->updateRideFileIntervals(); // will emit intervalChanged() signal -#endif -} - -void -AnalysisSidebar::renameInterval() -{ -#if 0 - // go edit the name - activeInterval->setFlags(activeInterval->flags() | Qt::ItemIsEditable); - context->athlete->intervalWidget->editItem(activeInterval, 0); -#endif -} - void AnalysisSidebar::editIntervalSelected() { @@ -834,6 +824,9 @@ AnalysisSidebar::editIntervalSelected() // update tree to reflect changes! userIntervals->child(j)->setText(0, activeInterval->name); + + // tell the charts ! + context->notifyIntervalsChanged(); return; } } diff --git a/src/AnalysisSidebar.h b/src/AnalysisSidebar.h index 0adc1af85..7e741c48e 100644 --- a/src/AnalysisSidebar.h +++ b/src/AnalysisSidebar.h @@ -75,10 +75,8 @@ class AnalysisSidebar : public QWidget void findPowerPeaks(); void editInterval(); // from right click void deleteInterval(); // from right click - void renameInterval(); // from right click void zoomInterval(); // from right click void sortIntervals(); // from menu popup - void renameIntervalSelected(void); // from menu popup void renameIntervalsSelected(void); // from menu popup -- rename a series void editIntervalSelected(); // from menu popup void deleteIntervalSelected(void); // from menu popup diff --git a/src/IntervalItem.cpp b/src/IntervalItem.cpp index be7a5a5f5..551398183 100644 --- a/src/IntervalItem.cpp +++ b/src/IntervalItem.cpp @@ -218,7 +218,7 @@ EditIntervalDialog::cancelClicked() RenameIntervalDialog::RenameIntervalDialog(QString &string, QWidget *parent) : QDialog(parent, Qt::Dialog), string(string) { - setWindowTitle(tr("Renumber Intervals")); + setWindowTitle(tr("Rename Intervals")); QVBoxLayout *mainLayout = new QVBoxLayout(this); // Grid diff --git a/src/RideItem.cpp b/src/RideItem.cpp index 8dd228e6b..6a7a4370a 100644 --- a/src/RideItem.cpp +++ b/src/RideItem.cpp @@ -1180,7 +1180,7 @@ RideItem::updateIntervals() context->notifyIntervalsUpdate(this); } -QList RideItem::intervalsSelected() +QList RideItem::intervalsSelected() const { QList returning; foreach(IntervalItem *p, intervals_) { @@ -1189,7 +1189,7 @@ QList RideItem::intervalsSelected() return returning; } -QList RideItem::intervalsSelected(RideFileInterval::intervaltype type) +QList RideItem::intervalsSelected(RideFileInterval::intervaltype type) const { QList returning; foreach(IntervalItem *p, intervals_) { @@ -1198,7 +1198,7 @@ QList RideItem::intervalsSelected(RideFileInterval::intervaltype return returning; } -QList RideItem::intervals(RideFileInterval::intervaltype type) +QList RideItem::intervals(RideFileInterval::intervaltype type) const { QList returning; foreach(IntervalItem *p, intervals_) { diff --git a/src/RideItem.h b/src/RideItem.h index 151784d23..fe487a2f2 100644 --- a/src/RideItem.h +++ b/src/RideItem.h @@ -127,10 +127,10 @@ class RideItem : public QObject double getWeight(); // when retrieving interval lists we can provide criteria too - QList &intervals() { return intervals_; } - QList intervalsSelected(); - QList intervals(RideFileInterval::intervaltype); - QList intervalsSelected(RideFileInterval::intervaltype); + QList &intervals() { return intervals_; } + QList intervalsSelected() const; + QList intervals(RideFileInterval::intervaltype) const; + QList intervalsSelected(RideFileInterval::intervaltype) const; bool removeInterval(IntervalItem *x); // metadata