summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-01-28 18:35:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitf11ac405933f2bc124dcff05ec44dd6860cf712c (patch)
tree502d7f9880076455324bb762e011555f7f452ae2
parent45ef87954669c765cb7b317384066c6eb88dc5d3 (diff)
downloadsubsurface-f11ac405933f2bc124dcff05ec44dd6860cf712c.tar.gz
Undo: implement undo of dive mode editing
Add a new UndoCommand for dive mode editing. This one is a bit special, as the mode is associated with a dive computer (DC), not a dive. Thus the edit command has an additional parameter, viz. the index of the DC. This does not fit properly to the EditBase class, as this class isn't aware of additional parameters and therefore this parameter is not sent via signals. At the moment this doesn't matter. In any case, the semantics of editing are weird and therefore let's do the simple thing (derive from EditBase) and let's see what the future brings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/command.cpp5
-rw-r--r--desktop-widgets/command.h1
-rw-r--r--desktop-widgets/command_edit.cpp42
-rw-r--r--desktop-widgets/command_edit.h10
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp28
-rw-r--r--desktop-widgets/tab-widgets/maintab.h1
6 files changed, 72 insertions, 15 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index 7336a5b62..7eff9a4c1 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -135,4 +135,9 @@ void editNotes(const QVector<dive *> dives, const QString &newValue, const QStri
execute(new EditNotes(dives, newValue, oldValue));
}
+void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue)
+{
+ execute(new EditMode(dives, index, newValue, oldValue));
+}
+
} // namespace Command
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index 4c31baa6e..e1139bd99 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -53,6 +53,7 @@ void purgeUnusedDiveSites();
// 4) Dive editing related commands
void editNotes(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
+void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue);
} // namespace Command
diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp
index aab3dc791..5ead59998 100644
--- a/desktop-widgets/command_edit.cpp
+++ b/desktop-widgets/command_edit.cpp
@@ -76,6 +76,9 @@ void EditBase<T>::redo()
undo();
}
+// Implementation of virtual functions
+
+// ***** Notes *****
void EditNotes::set(struct dive *d, QString s) const
{
free(d->notes);
@@ -97,4 +100,43 @@ DiveField EditNotes::fieldId() const
return DiveField::NOTES;
}
+// ***** Mode *****
+// Editing the dive mode has very peculiar semantics for historic reasons:
+// Since the dive-mode depends on the dive computer, the i-th dive computer
+// of each dive will be edited. If the dive has less than i dive computers,
+// the default dive computer will be edited.
+// The index "i" will be stored as an additional payload with the command.
+// Thus, we need an explicit constructor. Since the actual handling is done
+// by the base class, which knows nothing about this index, it will not be
+// sent via signals. Currently this is not needed. Should it turn out to
+// become necessary, then we might either
+// - Not derive EditMode from EditBase.
+// - Change the semantics of the mode-editing.
+// The future will tell.
+EditMode::EditMode(const QVector<dive *> &dives, int indexIn, int newValue, int oldValue)
+ : EditBase(dives, newValue, oldValue), index(indexIn)
+{
+}
+
+void EditMode::set(struct dive *d, int i) const
+{
+ get_dive_dc(d, index)->divemode = (enum divemode_t)i;
+ update_setpoint_events(d, get_dive_dc(d, index));
+}
+
+int EditMode::data(struct dive *d) const
+{
+ return get_dive_dc(d, index)->divemode;
+}
+
+QString EditMode::fieldName() const
+{
+ return tr("dive mode");
+}
+
+DiveField EditMode::fieldId() const
+{
+ return DiveField::MODE;
+}
+
} // namespace Command
diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h
index 5f5924e67..d91121c7d 100644
--- a/desktop-widgets/command_edit.h
+++ b/desktop-widgets/command_edit.h
@@ -56,6 +56,16 @@ public:
DiveField fieldId() const override;
};
+class EditMode : public EditBase<int> {
+ int index;
+public:
+ EditMode(const QVector<dive *> &dives, int indexIn, int newValue, int oldValue);
+ void set(struct dive *d, int i) const override;
+ int data(struct dive *d) const override;
+ QString fieldName() const override;
+ DiveField fieldId() const override;
+};
+
} // namespace Command
#endif
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 02e0a65be..49cf5312c 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -345,6 +345,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
case DiveField::NOTES:
updateNotes(current_dive);
break;
+ case DiveField::MODE:
+ updateMode(current_dive);
+ break;
default:
break;
}
@@ -399,6 +402,12 @@ void MainTab::updateNotes(const struct dive *d)
}
}
+void MainTab::updateMode(struct dive *d)
+{
+ ui.DiveType->setCurrentIndex(get_dive_dc(d, dc_number)->divemode);
+ MainWindow::instance()->graphics->recalcCeiling();
+}
+
void MainTab::updateDiveInfo(bool clear)
{
ui.location->refreshDiveSiteCache();
@@ -424,7 +433,7 @@ void MainTab::updateDiveInfo(bool clear)
UPDATE_TEXT(displayed_dive, buddy);
UPDATE_TEMP(displayed_dive, airtemp);
UPDATE_TEMP(displayed_dive, watertemp);
- ui.DiveType->setCurrentIndex(get_dive_dc(&displayed_dive, dc_number)->divemode);
+ updateMode(&displayed_dive);
if (!clear) {
struct dive_site *ds = NULL;
@@ -558,7 +567,6 @@ void MainTab::updateDiveInfo(bool clear)
}
ui.duration->setText(render_seconds_to_string(displayed_dive.duration.seconds));
ui.depth->setText(get_depth_string(displayed_dive.maxdepth, true));
- ui.DiveType->setCurrentIndex(get_dive_dc(&displayed_dive, dc_number)->divemode);
volume_t gases[MAX_CYLINDERS] = {};
get_gas_used(&displayed_dive, gases);
@@ -795,14 +803,6 @@ void MainTab::acceptChanges()
MODIFY_DIVES(selectedDives, EDIT_VALUE(visibility));
if (displayed_dive.airtemp.mkelvin != cd->airtemp.mkelvin)
MODIFY_DIVES(selectedDives, EDIT_VALUE(airtemp.mkelvin));
- if (displayed_dc->divemode != current_dc->divemode) {
- MODIFY_DIVES(selectedDives,
- if (get_dive_dc(mydive, dc_number)->divemode == current_dc->divemode || copyPaste)
- get_dive_dc(mydive, dc_number)->divemode = displayed_dc->divemode;
- );
- MODIFY_DIVES(selectedDives, update_setpoint_events(mydive, get_dive_dc(mydive, dc_number)));
- do_replot = true;
- }
if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin)
MODIFY_DIVES(selectedDives, EDIT_VALUE(watertemp.mkelvin));
@@ -1099,12 +1099,10 @@ void MainTab::on_airtemp_textChanged(const QString &text)
void MainTab::divetype_Changed(int index)
{
- if (editMode == IGNORE)
+ if (editMode == IGNORE || !current_dive)
return;
- displayed_dc->divemode = (enum divemode_t) index;
- update_setpoint_events(&displayed_dive, displayed_dc);
- markChangedWidget(ui.DiveType);
- MainWindow::instance()->graphics->recalcCeiling();
+ Command::editMode(getSelectedDivesCurrentLast(), dc_number, (enum divemode_t)index,
+ get_dive_dc(current_dive, dc_number)->divemode);
}
void MainTab::on_watertemp_textChanged(const QString &text)
diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h
index e8fdd0ac4..2ac463aec 100644
--- a/desktop-widgets/tab-widgets/maintab.h
+++ b/desktop-widgets/tab-widgets/maintab.h
@@ -68,6 +68,7 @@ slots:
void addWeight_clicked();
void updateDiveInfo(bool clear = false);
void updateNotes(const struct dive *d);
+ void updateMode(struct dive *d);
void updateDepthDuration();
void acceptChanges();
void rejectChanges();