diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-05-20 06:11:32 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-20 06:11:32 +0900 |
commit | b303f217a9d66ef031c58534b3796ddefbe362c5 (patch) | |
tree | 7c127cdffb59e42a68be4f4a15ebb35efb262f88 | |
parent | 4d14059d7c309534d9932375958b561fa464bde2 (diff) | |
download | subsurface-b303f217a9d66ef031c58534b3796ddefbe362c5.tar.gz |
Dive list: add context menu function to renumber dive(s)
No attempt is made to ensure that what the user does is sane. So this can
result in duplicate numbers, non-consecutive numbers, non-monotonous
numbers, whatever floats the users boat.
You can renumber a single dive or all selected dives (with a starting
number given that is applied to the oldest selected dive and then for each
newer selected dive that number is incremented by one).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.h | 2 | ||||
-rw-r--r-- | qt-ui/divelistview.cpp | 7 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 1 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 1 | ||||
-rw-r--r-- | qt-ui/simplewidgets.cpp | 18 | ||||
-rw-r--r-- | qt-ui/simplewidgets.h | 2 | ||||
-rw-r--r-- | subsurfacestartup.c | 11 |
7 files changed, 32 insertions, 10 deletions
@@ -554,7 +554,7 @@ extern unsigned int dc_airtemp(struct divecomputer *dc); extern unsigned int dc_watertemp(struct divecomputer *dc); extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded); extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded); -extern void renumber_dives(int nr); +extern void renumber_dives(int start_nr, bool selected_only); extern void copy_events(struct dive *s, struct dive *d); extern void copy_cylinders(struct dive *s, struct dive *d); extern void copy_samples(struct dive *s, struct dive *d); diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index e6eff5fc4..e6d82d5bc 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -529,6 +529,12 @@ void DiveListView::mergeDives() MainWindow::instance()->refreshDisplay(); } +void DiveListView::renumberDives() +{ + RenumberDialog::instance()->renumberOnlySelected(); + RenumberDialog::instance()->show(); +} + void DiveListView::merge_trip(const QModelIndex &a, int offset) { int i = a.row() + offset; @@ -768,6 +774,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) if (amount_selected > 1 && consecutive_selected()) popup.addAction(tr("merge selected dives"), this, SLOT(mergeDives())); if (amount_selected >= 1) { + popup.addAction(tr("renumber dive(s)"), this, SLOT(renumberDives())); popup.addAction(tr("save As"), this, SLOT(saveSelectedDivesAs())); popup.addAction(tr("export As UDDF"), this, SLOT(exportSelectedDivesAsUDDF())); popup.addAction(tr("export As CSV"), this, SLOT(exportSelectedDivesAsCSV())); diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index d946b1854..132d92f1f 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -48,6 +48,7 @@ slots: void addToTripAbove(); void addToTripBelow(); void mergeDives(); + void renumberDives(); void saveSelectedDivesAs(); void exportSelectedDivesAsUDDF(); void exportSelectedDivesAsCSV(); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index efa50bc0c..6ff0a68a4 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -444,6 +444,7 @@ void MainWindow::on_actionAddDive_triggered() void MainWindow::on_actionRenumber_triggered() { + RenumberDialog::instance()->renumberOnlySelected(false); RenumberDialog::instance()->show(); } diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index 8932baf15..b34f74c50 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -16,8 +16,9 @@ #include <QDateTime> #include <QShortcut> #include "exif.h" -#include "../dive.h" -#include "../file.h" +#include "dive.h" +#include "file.h" +#include "display.h" #include "mainwindow.h" #include "helpers.h" @@ -117,15 +118,24 @@ RenumberDialog *RenumberDialog::instance() return self; } +void RenumberDialog::renumberOnlySelected(bool selected) +{ + if (selected && amount_selected == 1) + ui.groupBox->setTitle(tr("New number")); + else + ui.groupBox->setTitle(tr("New starting number")); + selectedOnly = selected; +} + void RenumberDialog::buttonClicked(QAbstractButton *button) { if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { qDebug() << "Renumbering."; - renumber_dives(ui.spinBox->value()); + renumber_dives(ui.spinBox->value(), selectedOnly); } } -RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent) +RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false) { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); diff --git a/qt-ui/simplewidgets.h b/qt-ui/simplewidgets.h index d43d2bbcc..aa82e4a29 100644 --- a/qt-ui/simplewidgets.h +++ b/qt-ui/simplewidgets.h @@ -40,6 +40,7 @@ class RenumberDialog : public QDialog { Q_OBJECT public: static RenumberDialog *instance(); + void renumberOnlySelected(bool selected = true); private slots: void buttonClicked(QAbstractButton *button); @@ -47,6 +48,7 @@ slots: private: explicit RenumberDialog(QWidget *parent); Ui::RenumberDialog ui; + bool selectedOnly; }; class ShiftTimesDialog : public QDialog { diff --git a/subsurfacestartup.c b/subsurfacestartup.c index 471fea64e..4ae426d1c 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -149,13 +149,14 @@ void parse_argument(const char *arg) } while (*++p); } -void renumber_dives(int nr) +void renumber_dives(int start_nr, bool selected_only) { - int i; + int i, nr = start_nr; + struct dive *dive; - for (i = 0; i < dive_table.nr; i++) { - struct dive *dive = dive_table.dives[i]; - dive->number = nr + i; + for_each_dive (i, dive) { + if (dive->selected) + dive->number = nr++; } mark_divelist_changed(true); } |