mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-13 16:18:42 +00:00
Rename/Renumber intervals
.. will use entered text and append 1,2,3 etc .. or if entry ends with a number, will start from that .. eg; "Int#3" will result in "Int#3", "Int#4" .. "Int#n" Fixes #513.
This commit is contained in:
@@ -23,3 +23,52 @@ IntervalItem::IntervalItem(const RideFile *ride, QString name, double start, dou
|
||||
{
|
||||
setText(0, name);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
* Interval rename dialog
|
||||
*--------------------------------------------------------------------*/
|
||||
RenameIntervalDialog::RenameIntervalDialog(QString &string, QWidget *parent) :
|
||||
QDialog(parent, Qt::Dialog), string(string)
|
||||
{
|
||||
setWindowTitle(tr("Renumber Intervals"));
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
|
||||
// Grid
|
||||
QGridLayout *grid = new QGridLayout;
|
||||
QLabel *name = new QLabel("Name");
|
||||
|
||||
nameEdit = new QLineEdit(this);
|
||||
nameEdit->setText(string);
|
||||
|
||||
grid->addWidget(name, 0,0);
|
||||
grid->addWidget(nameEdit, 0,1);
|
||||
|
||||
mainLayout->addLayout(grid);
|
||||
|
||||
// Buttons
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
applyButton = new QPushButton(tr("&OK"), this);
|
||||
cancelButton = new QPushButton(tr("&Cancel"), this);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
buttonLayout->addWidget(applyButton);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
// connect up slots
|
||||
connect(applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
||||
}
|
||||
|
||||
void
|
||||
RenameIntervalDialog::applyClicked()
|
||||
{
|
||||
// get the values back
|
||||
string = nameEdit->text();
|
||||
accept();
|
||||
}
|
||||
|
||||
void
|
||||
RenameIntervalDialog::cancelClicked()
|
||||
{
|
||||
reject();
|
||||
}
|
||||
|
||||
@@ -35,5 +35,24 @@ class IntervalItem : public QTreeWidgetItem
|
||||
IntervalItem(const RideFile *, QString, double, double, double, double, int);
|
||||
void setDisplaySequence(int seq) { displaySequence = seq; }
|
||||
};
|
||||
|
||||
class RenameIntervalDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
G_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
RenameIntervalDialog(QString &, QWidget *);
|
||||
|
||||
public slots:
|
||||
void applyClicked();
|
||||
void cancelClicked();
|
||||
|
||||
private:
|
||||
QString &string;
|
||||
QPushButton *applyButton, *cancelButton;
|
||||
QLineEdit *nameEdit;
|
||||
};
|
||||
#endif // _GC_IntervalItem_h
|
||||
|
||||
|
||||
@@ -1258,12 +1258,6 @@ MainWindow::showTreeContextMenuPopup(const QPoint &pos)
|
||||
QAction *actDeleteRide = new QAction(tr("Delete Activity"), treeWidget);
|
||||
connect(actDeleteRide, SIGNAL(triggered(void)), this, SLOT(deleteRide()));
|
||||
|
||||
QAction *actBestInt = new QAction(tr("Find Best Intervals"), treeWidget);
|
||||
connect(actBestInt, SIGNAL(triggered(void)), this, SLOT(addIntervals()));
|
||||
|
||||
QAction *actPowerPeaks = new QAction(tr("Find Power Peaks"), treeWidget);
|
||||
connect(actPowerPeaks, SIGNAL(triggered(void)), this, SLOT(findPowerPeaks()));
|
||||
|
||||
QAction *actSplitRide = new QAction(tr("Split Activity"), treeWidget);
|
||||
connect(actSplitRide, SIGNAL(triggered(void)), this, SLOT(splitRide()));
|
||||
|
||||
@@ -1273,8 +1267,6 @@ MainWindow::showTreeContextMenuPopup(const QPoint &pos)
|
||||
}
|
||||
|
||||
menu.addAction(actDeleteRide);
|
||||
menu.addAction(actBestInt);
|
||||
menu.addAction(actPowerPeaks);
|
||||
menu.addAction(actSplitRide);
|
||||
#ifdef GC_HAVE_LIBOAUTH
|
||||
QAction *actTweetRide = new QAction(tr("Tweet Activity"), treeWidget);
|
||||
@@ -1341,8 +1333,11 @@ MainWindow::intervalPopup()
|
||||
connect(actFindBest, SIGNAL(triggered(void)), this, SLOT(addIntervals(void)));
|
||||
menu.addAction(actFindPeak);
|
||||
menu.addAction(actFindBest);
|
||||
|
||||
if (intervalWidget->selectedItems().count()) menu.addSeparator();
|
||||
}
|
||||
|
||||
|
||||
if (intervalWidget->selectedItems().count() == 1) {
|
||||
|
||||
// we can zoom, rename etc if only 1 interval is selected
|
||||
@@ -1363,6 +1358,10 @@ MainWindow::intervalPopup()
|
||||
QAction *actDeleteInt = new QAction(tr("Delete selected intervals"), intervalWidget);
|
||||
connect(actDeleteInt, SIGNAL(triggered(void)), this, SLOT(deleteIntervalSelected(void)));
|
||||
menu.addAction(actDeleteInt);
|
||||
|
||||
QAction *actRenameInt = new QAction(tr("Rename selected intervals"), intervalWidget);
|
||||
connect(actRenameInt, SIGNAL(triggered(void)), this, SLOT(renameIntervalsSelected(void)));
|
||||
menu.addAction(actRenameInt);
|
||||
}
|
||||
|
||||
menu.exec(analSidebar->mapToGlobal((QPoint(intervalItem->pos().x()+intervalItem->width()-20, intervalItem->pos().y()))));
|
||||
@@ -2353,6 +2352,47 @@ MainWindow::updateRideFileIntervals()
|
||||
which->setDirty(true);
|
||||
}
|
||||
|
||||
// rename multiple intervals
|
||||
void
|
||||
MainWindow::renameIntervalsSelected()
|
||||
{
|
||||
QString string;
|
||||
|
||||
// set string to first interval selected
|
||||
for (int i=0; i<allIntervals->childCount();i++) {
|
||||
if (allIntervals->child(i)->isSelected()) {
|
||||
string = allIntervals->child(i)->text(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 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<allIntervals->childCount();i++) {
|
||||
if (allIntervals->child(i)->isSelected())
|
||||
allIntervals->child(i)->setText(0, QString("%1%2").arg(string).arg(number++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MainWindow::deleteIntervalSelected()
|
||||
{
|
||||
|
||||
@@ -346,6 +346,7 @@ class MainWindow : public QMainWindow
|
||||
void renameInterval(); // from right click
|
||||
void zoomInterval(); // from right click
|
||||
void renameIntervalSelected(void); // from menu popup
|
||||
void renameIntervalsSelected(void); // from menu popup -- rename a series
|
||||
void deleteIntervalSelected(void); // from menu popup
|
||||
void zoomIntervalSelected(void); // from menu popup
|
||||
void frontInterval();
|
||||
|
||||
Reference in New Issue
Block a user