From 225b13a22da446860c1f1b5cceeb52ba366ae77d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 16 Aug 2013 13:31:52 -0300 Subject: Enable Multi Dive Editing. This patch enables multi dive editing on the selected dives. It's a bit of big patch where I reworked how it worked since it was written just for a single dive. this means that this can introduce bugs - I'v tested it quite a bit but a thing could slip thru my fingers. :) How this is supposed to work: Select a few dives that you want ( one or more ) then click on the field that you wanna edit / multi edit, and press 'accept'. *only* the edited field will be modified thru all dives. Next patch - I'll change the bg color of the edited fields.A Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 212 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 159 insertions(+), 53 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 13709ba23..ca1be6963 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -24,7 +24,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui(new Ui::MainTab()), weightModel(new WeightModel()), cylindersModel(new CylindersModel()), - currentDive(0), editMode(NONE) { ui->setupUi(this); @@ -140,7 +139,7 @@ void MainTab::equipmentPlusUpdate() void MainTab::enableEdition() { - if (ui->editAccept->isVisible() || !currentDive) + if (ui->editAccept->isVisible() || !selected_dive) return; ui->editAccept->setChecked(true); @@ -200,6 +199,7 @@ void MainTab::clearStats() void MainTab::updateDiveInfo(int dive) { + editMode = NONE; // This method updates ALL tabs whenever a new dive or trip is // selected. // If exactly one trip has been selected, we show the location / notes @@ -212,7 +212,7 @@ void MainTab::updateDiveInfo(int dive) process_selected_dives(); process_all_dives(d, &prevd); - currentDive = d; + UPDATE_TEXT(d, notes); UPDATE_TEXT(d, location); UPDATE_TEXT(d, suit); @@ -379,24 +379,39 @@ void MainTab::on_editAccept_clicked(bool edit) mainWindow()->dive_list()->setEnabled(!edit); if (edit) { + + // We may be editing one or more dives here. backup everything. + notesBackup.clear(); + if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) { // we are editing trip location and notes ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready.")); ui->diveNotesMessage->animatedShow(); - notesBackup.notes = ui->notes->toPlainText(); - notesBackup.location = ui->location->text(); + notesBackup[NULL].notes = ui->notes->toPlainText(); + notesBackup[NULL].location = ui->location->text(); editMode = TRIP; } else { ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo when ready.")); ui->diveNotesMessage->animatedShow(); - notesBackup.buddy = ui->buddy->text(); - notesBackup.suit = ui->suit->text(); - notesBackup.notes = ui->notes->toPlainText(); - notesBackup.divemaster = ui->divemaster->text(); - notesBackup.location = ui->location->text(); - notesBackup.rating = ui->rating->currentStars(); - notesBackup.visibility = ui->visibility->currentStars(); - editMode = DIVE; + + // We may be editing one or more dives here. backup everything. + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + notesBackup[mydive].buddy = QString(mydive->buddy); + notesBackup[mydive].suit = QString(mydive->suit); + notesBackup[mydive].notes = QString(mydive->notes); + notesBackup[mydive].divemaster = QString(mydive->divemaster); + notesBackup[mydive].location = QString(mydive->location); + notesBackup[mydive].rating = mydive->rating; + notesBackup[mydive].visibility = mydive->visibility; + } + editMode = DIVE; } } else { ui->diveNotesMessage->animatedHide(); @@ -404,38 +419,72 @@ void MainTab::on_editAccept_clicked(bool edit) ui->editReset->hide(); /* now figure out if things have changed */ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) { - if (notesBackup.notes != ui->notes->toPlainText() || - notesBackup.location != ui->location->text()) + if (notesBackup[NULL].notes != ui->notes->toPlainText() || + notesBackup[NULL].location != ui->location->text()) mark_divelist_changed(TRUE); } else { - if (notesBackup.buddy != ui->buddy->text() || - notesBackup.suit != ui->suit->text() || - notesBackup.notes != ui->notes->toPlainText() || - notesBackup.divemaster != ui->divemaster->text() || - notesBackup.location != ui->location->text() || - notesBackup.visibility != ui->visibility->currentStars() || - notesBackup.rating != ui->rating->currentStars()) + struct dive *curr = current_dive; + if (notesBackup[curr].buddy != ui->buddy->text() || + notesBackup[curr].suit != ui->suit->text() || + notesBackup[curr].notes != ui->notes->toPlainText() || + notesBackup[curr].divemaster != ui->divemaster->text() || + notesBackup[curr].location != ui->location->text() || + notesBackup[curr].rating != ui->visibility->currentStars() || + notesBackup[curr].visibility != ui->rating->currentStars()) + mark_divelist_changed(TRUE); - if (notesBackup.location != ui->location->text()) + if (notesBackup[curr].location != ui->location->text()) mainWindow()->globe()->reload(); } editMode = NONE; } } +#define EDIT_TEXT2(what, text) \ + textByteArray = text.toLocal8Bit(); \ + free(what);\ + what = strdup(textByteArray.data()); + +#define EDIT_TEXT(what, text) \ + QByteArray textByteArray = text.toLocal8Bit(); \ + free(what);\ + what = strdup(textByteArray.data()); + void MainTab::on_editReset_clicked() { if (!ui->editAccept->isChecked()) return; - ui->notes->setText(notesBackup.notes); - ui->location->setText(notesBackup.location); - if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() != 1) { - ui->buddy->setText(notesBackup.buddy); - ui->suit->setText(notesBackup.suit); - ui->divemaster->setText(notesBackup.divemaster); - ui->rating->setCurrentStars(notesBackup.rating); - ui->visibility->setCurrentStars(notesBackup.visibility); + if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1){ + ui->notes->setText(notesBackup[NULL].notes ); + ui->location->setText(notesBackup[NULL].location); + }else{ + struct dive *curr = current_dive; + ui->notes->setText(notesBackup[curr].notes ); + ui->location->setText(notesBackup[curr].location); + ui->buddy->setText(notesBackup[curr].buddy); + ui->suit->setText(notesBackup[curr].suit); + ui->divemaster->setText(notesBackup[curr].divemaster); + ui->rating->setCurrentStars(notesBackup[curr].rating); + ui->visibility->setCurrentStars(notesBackup[curr].visibility); + + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + QByteArray textByteArray; + EDIT_TEXT2(mydive->buddy, notesBackup[mydive].buddy); + EDIT_TEXT2(mydive->suit, notesBackup[mydive].suit); + EDIT_TEXT2(mydive->notes, notesBackup[mydive].notes); + EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster); + EDIT_TEXT2(mydive->location, notesBackup[mydive].location); + mydive->rating = notesBackup[mydive].rating; + mydive->visibility = notesBackup[mydive].visibility; + } } ui->editAccept->setChecked(false); ui->diveNotesMessage->animatedHide(); @@ -451,58 +500,98 @@ void MainTab::on_editReset_clicked() ui->editAccept->hide(); ui->editReset->hide(); + notesBackup.clear(); editMode = NONE; } - -#define EDIT_TEXT(what, text) \ - QByteArray textByteArray = text.toLocal8Bit(); \ - free(what);\ - what = strdup(textByteArray.data()); - +#undef EDIT_TEXT2 void MainTab::on_buddy_textChanged(const QString& text) { - if (!currentDive) + if (editMode == NONE) return; - EDIT_TEXT(currentDive->buddy, text); + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + EDIT_TEXT(mydive->buddy, text); + } } void MainTab::on_divemaster_textChanged(const QString& text) { - if (!currentDive) + if (editMode == NONE) return; - EDIT_TEXT(currentDive->divemaster, text); + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + EDIT_TEXT(mydive->divemaster, text); + } } void MainTab::on_location_textChanged(const QString& text) { + if (editMode == NONE) + return; if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) { // we are editing a trip dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE){ - if (!currentDive) - return; - EDIT_TEXT(currentDive->location, text); + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + EDIT_TEXT(mydive->location, text); + } } } void MainTab::on_suit_textChanged(const QString& text) { - if (!currentDive) + if (editMode == NONE) return; - EDIT_TEXT(currentDive->suit, text); + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + EDIT_TEXT(mydive->suit, text); + } } void MainTab::on_notes_textChanged() { + if (editMode == NONE) + return; if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) { // we are editing a trip dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText()); } else if (editMode == DIVE) { - if (!currentDive) - return; - EDIT_TEXT(currentDive->notes, ui->notes->toPlainText()); + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + EDIT_TEXT(mydive->notes, ui->notes->toPlainText()); + } } } @@ -510,16 +599,33 @@ void MainTab::on_notes_textChanged() void MainTab::on_rating_valueChanged(int value) { - if (!currentDive) + if (editMode == NONE) return; - currentDive->rating = value; + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + mydive->rating = value; + } } void MainTab::on_visibility_valueChanged(int value) { - if (!currentDive) + if (editMode == NONE) return; - currentDive->visibility = value; + struct dive *mydive; + for (int i = 0; i < dive_table.nr; i++) { + mydive = get_dive(i); + if (!mydive) + continue; + if (!mydive->selected) + continue; + + mydive->visibility = value; + } } void MainTab::hideEvent(QHideEvent* event) -- cgit v1.2.3-70-g09d2 From b7fe4087a6b8461f029969a38222dd941e0b298d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 16 Aug 2013 15:38:18 -0300 Subject: Change bg of edited parts of the dive on the interface Change the background color of edited parts of the dive on the interface. Specially util if you are editing multi dives in a single step, and went to eat something or did anything else for five minutes, then come back and don't quite remember what did you changed. now it's in a cute yellowish background. Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index ca1be6963..9f962be8b 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -19,6 +19,7 @@ #include #include #include +#include MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui(new Ui::MainTab()), @@ -438,6 +439,12 @@ void MainTab::on_editAccept_clicked(bool edit) } editMode = NONE; } + QPalette p; + ui->buddy->setPalette(p); + ui->notes->setPalette(p); + ui->location->setPalette(p); + ui->divemaster->setPalette(p); + ui->suit->setPalette(p); } #define EDIT_TEXT2(what, text) \ @@ -501,6 +508,12 @@ void MainTab::on_editReset_clicked() ui->editAccept->hide(); ui->editReset->hide(); notesBackup.clear(); + QPalette p; + ui->buddy->setPalette(p); + ui->notes->setPalette(p); + ui->location->setPalette(p); + ui->divemaster->setPalette(p); + ui->suit->setPalette(p); editMode = NONE; } #undef EDIT_TEXT2 @@ -518,6 +531,10 @@ void MainTab::on_buddy_textChanged(const QString& text) EDIT_TEXT(mydive->buddy, text); } + + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); + ui->buddy->setPalette(p); } void MainTab::on_divemaster_textChanged(const QString& text) @@ -534,6 +551,9 @@ void MainTab::on_divemaster_textChanged(const QString& text) EDIT_TEXT(mydive->divemaster, text); } + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); + ui->divemaster->setPalette(p); } void MainTab::on_location_textChanged(const QString& text) @@ -555,6 +575,10 @@ void MainTab::on_location_textChanged(const QString& text) EDIT_TEXT(mydive->location, text); } } + + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); + ui->location->setPalette(p); } void MainTab::on_suit_textChanged(const QString& text) @@ -571,6 +595,10 @@ void MainTab::on_suit_textChanged(const QString& text) EDIT_TEXT(mydive->suit, text); } + + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); + ui->suit->setPalette(p); } void MainTab::on_notes_textChanged() @@ -593,6 +621,10 @@ void MainTab::on_notes_textChanged() EDIT_TEXT(mydive->notes, ui->notes->toPlainText()); } } + + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); + ui->notes->setPalette(p); } #undef EDIT_TEXT -- cgit v1.2.3-70-g09d2 From 2b6c3b4c0cb094a06bc832573f68be00de9d7293 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 16 Aug 2013 15:52:40 -0300 Subject: Good deal of code cleanup. This is a bit of code cleanup that I'm not sure that will pass, since it's all macro-based, but I don't have a thing against macros at all. Sometimes they helps us keep a better and cleaner code base. I think I managed to remove around 120 lines of code, wich isn't much, but I replaced it by 14. and the code is now easyer to maintain, so hooray. Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 126 ++++++++++++++---------------------------------------- 1 file changed, 32 insertions(+), 94 deletions(-) (limited to 'qt-ui/maintab.cpp') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 9f962be8b..768a521f0 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -517,43 +517,38 @@ void MainTab::on_editReset_clicked() editMode = NONE; } #undef EDIT_TEXT2 -void MainTab::on_buddy_textChanged(const QString& text) -{ - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->buddy, text); + +#define EDIT_SELECTED_DIVES( WHAT ) \ + if (editMode == NONE) \ + return; \ + struct dive *mydive; \ +\ + for (int i = 0; i < dive_table.nr; i++) { \ + mydive = get_dive(i); \ + if (!mydive) \ + continue; \ + if (!mydive->selected) \ + continue; \ +\ + WHAT; \ } +void markChangedWidget(QWidget *w){ QPalette p; p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->buddy->setPalette(p); + w->setPalette(p); +} + +void MainTab::on_buddy_textChanged(const QString& text) +{ + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->buddy, text) ); + markChangedWidget(ui->buddy); } void MainTab::on_divemaster_textChanged(const QString& text) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->divemaster, text); - } - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->divemaster->setPalette(p); + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) ); + markChangedWidget(ui->divemaster); } void MainTab::on_location_textChanged(const QString& text) @@ -565,40 +560,16 @@ void MainTab::on_location_textChanged(const QString& text) dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE){ - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - EDIT_TEXT(mydive->location, text); - } + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ) } - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->location->setPalette(p); + markChangedWidget(ui->location); } void MainTab::on_suit_textChanged(const QString& text) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->suit, text); - } - - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->suit->setPalette(p); + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) ); + markChangedWidget(ui->suit); } void MainTab::on_notes_textChanged() @@ -610,54 +581,21 @@ void MainTab::on_notes_textChanged() dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText()); } else if (editMode == DIVE) { - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->notes, ui->notes->toPlainText()); - } + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) ); } - - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->notes->setPalette(p); + markChangedWidget(ui->notes); } #undef EDIT_TEXT void MainTab::on_rating_valueChanged(int value) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - mydive->rating = value; - } + EDIT_SELECTED_DIVES(mydive->rating = value ); } void MainTab::on_visibility_valueChanged(int value) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - mydive->visibility = value; - } + EDIT_SELECTED_DIVES( mydive->visibility = value ); } void MainTab::hideEvent(QHideEvent* event) -- cgit v1.2.3-70-g09d2