diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-05-06 10:19:43 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-05-06 11:13:24 -0700 |
commit | bcf973190c07aecea2358af155a7190967faf054 (patch) | |
tree | da96b0a0795c1c2442552abc321f4e459d815c8a /qt-ui/maintab.cpp | |
parent | 217c82f6c4207a5afe086d15edb29db59e523575 (diff) | |
download | subsurface-bcf973190c07aecea2358af155a7190967faf054.tar.gz |
Only change identical fields when editing multiple dives
This was broken when porting to Qt - we used to do this correctly in the
Gtk version.
When editing multiple dives we show the current dive to the user and allow
them to edit that and then apply those edits to all selected dives. The
way this is SUPPOSED to work is that we only change those selected dives
that had the same value for the edited field as the current_dive had for
that field.
Let's say you select ten dives. The current dive shows divemaster Joe. You
change that to divemaster Jim. Then only the selected dives that had
divemaster Joe should change to Jim. All other dives should stay
unchanged.
This seems to implement that logic.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r-- | qt-ui/maintab.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 68960897d..b5e2ea887 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -728,11 +728,6 @@ void MainTab::resetPallete() free(what); \ what = strdup(textByteArray.data()); -#define EDIT_TEXT(what, text) \ - QByteArray textByteArray = text.toUtf8(); \ - free(what); \ - what = strdup(textByteArray.data()); - void MainTab::rejectChanges() { EditMode lastMode = editMode; @@ -859,6 +854,21 @@ void MainTab::rejectChanges() WHAT; \ } while (0) +// this macro is rather fragile and is intended to be used as WHAT inside +// an invocation of EDIT_SELECTED_DIVES(WHAT) +#define EDIT_TEXT(what, text) \ + if ((!mydive->what && !current_dive->what) || \ + (mydive->what && current_dive->what && strcmp(mydive->what, current_dive->what) == 0)) { \ + QByteArray textByteArray = text.toUtf8(); \ + free(mydive->what); \ + mydive->what = strdup(textByteArray.data()); \ + } + +#define EDIT_TRIP_TEXT(what, text) \ + QByteArray textByteArray = text.toUtf8(); \ + free(what); \ + what = strdup(textByteArray.data()); + void markChangedWidget(QWidget *w) { QPalette p; @@ -874,7 +884,7 @@ void MainTab::on_buddy_textChanged() for (int i = 0; i < text_list.size(); i++) text_list[i] = text_list[i].trimmed(); QString text = text_list.join(", "); - EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->buddy, text)); + EDIT_SELECTED_DIVES(EDIT_TEXT(buddy, text)); markChangedWidget(ui.buddy); } @@ -884,7 +894,7 @@ void MainTab::on_divemaster_textChanged() for (int i = 0; i < text_list.size(); i++) text_list[i] = text_list[i].trimmed(); QString text = text_list.join(", "); - EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->divemaster, text)); + EDIT_SELECTED_DIVES(EDIT_TEXT(divemaster, text)); markChangedWidget(ui.divemaster); } @@ -959,7 +969,7 @@ void MainTab::on_location_textChanged(const QString &text) if (editMode == TRIP && MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { // we are editing a trip dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin(); - EDIT_TEXT(currentTrip->location, text); + EDIT_TRIP_TEXT(currentTrip->location, text); } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { // if we have a location text and haven't edited the coordinates, try to fill the coordinates // from the existing dives @@ -981,7 +991,7 @@ void MainTab::on_location_textChanged(const QString &text) } } } - EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->location, text)); + EDIT_SELECTED_DIVES(EDIT_TEXT(location, text)); MainWindow::instance()->globe()->repopulateLabels(); } markChangedWidget(ui.location); @@ -989,7 +999,7 @@ void MainTab::on_location_textChanged(const QString &text) void MainTab::on_suit_textChanged(const QString &text) { - EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->suit, text)); + EDIT_SELECTED_DIVES(EDIT_TEXT(suit, text)); markChangedWidget(ui.suit); } @@ -1000,14 +1010,15 @@ void MainTab::on_notes_textChanged() if (editMode == TRIP && MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) { // we are editing a trip dive_trip_t *currentTrip = *MainWindow::instance()->dive_list()->selectedTrips().begin(); - EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText()); + EDIT_TRIP_TEXT(currentTrip->notes, ui.notes->toPlainText()); } else if (editMode == DIVE || editMode == ADD || editMode == MANUALLY_ADDED_DIVE) { - EDIT_SELECTED_DIVES(EDIT_TEXT(mydive->notes, ui.notes->toPlainText())); + EDIT_SELECTED_DIVES(EDIT_TEXT(notes, ui.notes->toPlainText())); } markChangedWidget(ui.notes); } #undef EDIT_TEXT +#undef EDIT_TRIP_TEXT void MainTab::on_coordinates_textChanged(const QString &text) { |