summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-16 13:31:52 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-16 13:31:52 -0300
commit225b13a22da446860c1f1b5cceeb52ba366ae77d (patch)
tree9386b562fb9ce96b77b960e380a4660a7998239f /qt-ui
parentcbbc7d99ea039b0b5bd676ec1802555d3707e0af (diff)
downloadsubsurface-225b13a22da446860c1f1b5cceeb52ba366ae77d.tar.gz
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 <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp212
-rw-r--r--qt-ui/maintab.h6
2 files changed, 162 insertions, 56 deletions
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)
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 8c398a77d..5180b26e2 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -9,11 +9,12 @@
#include <QTabWidget>
#include <QDialog>
+#include <QMap>
#include "models.h"
class QCompleter;
-
+struct dive;
namespace Ui
{
class MainTab;
@@ -76,8 +77,7 @@ private:
Ui::MainTab *ui;
WeightModel *weightModel;
CylindersModel *cylindersModel;
- NotesBackup notesBackup;
- struct dive* currentDive;
+ QMap<dive*, NotesBackup> notesBackup;
QPushButton *addCylinder;
QPushButton *addWeight;
enum { NONE, DIVE, TRIP } editMode;