Reinstating Interval functions: RENAMING/RENUMBERING

.. rename a number of intervals in one go
This commit is contained in:
Mark Liversedge
2015-05-22 11:58:16 +01:00
parent 70d6fd192b
commit 597dccff9c
5 changed files with 63 additions and 72 deletions

View File

@@ -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; i<context->athlete->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; j<userIntervals->childCount(); 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<IntervalItem*>(v.value<void*>());
// 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<RideItem*>(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; i<context->athlete->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; i<context->athlete->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;
}
}

View File

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

View File

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

View File

@@ -1180,7 +1180,7 @@ RideItem::updateIntervals()
context->notifyIntervalsUpdate(this);
}
QList<IntervalItem*> RideItem::intervalsSelected()
QList<IntervalItem*> RideItem::intervalsSelected() const
{
QList<IntervalItem*> returning;
foreach(IntervalItem *p, intervals_) {
@@ -1189,7 +1189,7 @@ QList<IntervalItem*> RideItem::intervalsSelected()
return returning;
}
QList<IntervalItem*> RideItem::intervalsSelected(RideFileInterval::intervaltype type)
QList<IntervalItem*> RideItem::intervalsSelected(RideFileInterval::intervaltype type) const
{
QList<IntervalItem*> returning;
foreach(IntervalItem *p, intervals_) {
@@ -1198,7 +1198,7 @@ QList<IntervalItem*> RideItem::intervalsSelected(RideFileInterval::intervaltype
return returning;
}
QList<IntervalItem*> RideItem::intervals(RideFileInterval::intervaltype type)
QList<IntervalItem*> RideItem::intervals(RideFileInterval::intervaltype type) const
{
QList<IntervalItem*> returning;
foreach(IntervalItem *p, intervals_) {

View File

@@ -127,10 +127,10 @@ class RideItem : public QObject
double getWeight();
// when retrieving interval lists we can provide criteria too
QList<IntervalItem*> &intervals() { return intervals_; }
QList<IntervalItem*> intervalsSelected();
QList<IntervalItem*> intervals(RideFileInterval::intervaltype);
QList<IntervalItem*> intervalsSelected(RideFileInterval::intervaltype);
QList<IntervalItem*> &intervals() { return intervals_; }
QList<IntervalItem*> intervalsSelected() const;
QList<IntervalItem*> intervals(RideFileInterval::intervaltype) const;
QList<IntervalItem*> intervalsSelected(RideFileInterval::intervaltype) const;
bool removeInterval(IntervalItem *x);
// metadata