diff options
-rw-r--r-- | core/subsurface-qt/DiveListNotifier.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/command.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command_edit.cpp | 48 | ||||
-rw-r--r-- | desktop-widgets/command_edit.h | 18 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 59 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 4 |
7 files changed, 113 insertions, 30 deletions
diff --git a/core/subsurface-qt/DiveListNotifier.h b/core/subsurface-qt/DiveListNotifier.h index 10cc4bb4d..d9ef4152b 100644 --- a/core/subsurface-qt/DiveListNotifier.h +++ b/core/subsurface-qt/DiveListNotifier.h @@ -14,6 +14,8 @@ // Use "enum class" to not polute the global name space. enum class DiveField { DATETIME, + DEPTH, + DURATION, AIR_TEMP, WATER_TEMP, DIVESITE, diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index bb37eb816..2f73477fe 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -165,6 +165,16 @@ void editWaterTemp(const QVector<dive *> dives, int newValue, int oldValue) execute(new EditWaterTemp(dives, newValue, oldValue)); } +void editDepth(const QVector<dive *> dives, int newValue, int oldValue) +{ + execute(new EditDepth(dives, newValue, oldValue)); +} + +void editDuration(const QVector<dive *> dives, int newValue, int oldValue) +{ + execute(new EditDuration(dives, newValue, oldValue)); +} + void editDiveSite(const QVector<dive *> dives, struct dive_site *newValue, struct dive_site *oldValue) { execute(new EditDiveSite(dives, newValue, oldValue)); diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index d89f54bf7..4754a6937 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -59,6 +59,8 @@ void editRating(const QVector<dive *> dives, int newValue, int oldValue); void editVisibility(const QVector<dive *> dives, int newValue, int oldValue); void editAirTemp(const QVector<dive *> dives, int newValue, int oldValue); void editWaterTemp(const QVector<dive *> dives, int newValue, int oldValue); +void editDepth(const QVector<dive *> dives, int newValue, int oldValue); +void editDuration(const QVector<dive *> dives, int newValue, int oldValue); void editDiveSite(const QVector<dive *> dives, struct dive_site *newValue, struct dive_site *oldValue); void editDiveSiteNew(const QVector<dive *> dives, const QString &newName, struct dive_site *oldValue); void editTags(const QVector<dive *> &dives, const QStringList &newList, struct dive *d); diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index 8366db153..73080061b 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -215,6 +215,54 @@ DiveField EditWaterTemp::fieldId() const return DiveField::WATER_TEMP; } +// ***** Duration ***** +void EditDuration::set(struct dive *d, int value) const +{ + d->dc.duration.seconds = value; + d->duration = d->dc.duration; + d->dc.meandepth.mm = 0; + d->dc.samples = 0; +} + +int EditDuration::data(struct dive *d) const +{ + return d->duration.seconds; +} + +QString EditDuration::fieldName() const +{ + return tr("duration"); +} + +DiveField EditDuration::fieldId() const +{ + return DiveField::DURATION; +} + +// ***** Depth ***** +void EditDepth::set(struct dive *d, int value) const +{ + d->dc.maxdepth.mm = value; + d->maxdepth = d->dc.maxdepth; + d->dc.meandepth.mm = 0; + d->dc.samples = 0; +} + +int EditDepth::data(struct dive *d) const +{ + return d->maxdepth.mm; +} + +QString EditDepth::fieldName() const +{ + return tr("depth"); +} + +DiveField EditDepth::fieldId() const +{ + return DiveField::DEPTH; +} + // ***** DiveSite ***** void EditDiveSite::set(struct dive *d, struct dive_site *dive_site) const { diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h index d10da4325..081ea11bb 100644 --- a/desktop-widgets/command_edit.h +++ b/desktop-widgets/command_edit.h @@ -102,6 +102,24 @@ public: DiveField fieldId() const override; }; +class EditDuration : public EditBase<int> { +public: + using EditBase<int>::EditBase; // Use constructor of base class. + void set(struct dive *d, int value) const override; + int data(struct dive *d) const override; + QString fieldName() const override; + DiveField fieldId() const override; +}; + +class EditDepth : public EditBase<int> { +public: + using EditBase<int>::EditBase; // Use constructor of base class. + void set(struct dive *d, int value) const override; + int data(struct dive *d) const override; + QString fieldName() const override; + DiveField fieldId() const override; +}; + class EditDiveSite : public EditBase<struct dive_site *> { public: using EditBase<struct dive_site *>::EditBase; // Use constructor of base class. diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 77a6c9f5c..8992a645d 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -333,6 +333,13 @@ void MainTab::enableEdition(EditMode newEditMode) } } +static void profileFromDive(struct dive *d) +{ + DivePlannerPointsModel::instance()->loadFromDive(d); + MainWindow::instance()->graphics->setReplot(true); + MainWindow::instance()->graphics->plotDive(current_dive, true); +} + // This function gets called if a field gets updated by an undo command. // Refresh the corresponding UI field. void MainTab::divesEdited(const QVector<dive *> &, DiveField field) @@ -342,6 +349,14 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) return; switch(field) { + case DiveField::DURATION: + ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds)); + profileFromDive(current_dive); + break; + case DiveField::DEPTH: + ui.depth->setText(get_depth_string(current_dive->maxdepth, true)); + profileFromDive(current_dive); + break; case DiveField::AIR_TEMP: ui.airtemp->setText(get_temperature_string(current_dive->airtemp, true)); break; @@ -724,6 +739,13 @@ static QVector<dive *> getSelectedDivesCurrentLast() return res; } +// When editing depth and duration, we only edit a single dive. Therefore, return the current dive as a list +static QVector<dive *> getCurrentAsList() +{ + return current_dive ? QVector<dive *> { current_dive } + : QVector<dive *> { }; +} + void MainTab::acceptChanges() { int i, addedId = -1; @@ -1009,41 +1031,22 @@ void MainTab::on_divemaster_editingFinished() Command::editDiveMaster(getSelectedDivesCurrentLast(), stringToList(ui.divemaster->toPlainText()), current_dive); } -void MainTab::on_duration_textChanged(const QString &text) +void MainTab::on_duration_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - // parse this - MainWindow::instance()->graphics->setReplot(false); - if (!isEditing()) - enableEdition(); - displayed_dive.dc.duration.seconds = parseDurationToSeconds(text); - displayed_dive.duration = displayed_dive.dc.duration; - displayed_dive.dc.meandepth.mm = 0; - displayed_dive.dc.samples = 0; - DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); - markChangedWidget(ui.duration); - MainWindow::instance()->graphics->setReplot(true); - MainWindow::instance()->graphics->plotDive(); + // Duration editing is special: we only edit the current dive. + Command::editDuration(getCurrentAsList(), parseDurationToSeconds(ui.duration->text()), displayed_dive.dc.duration.seconds); } -void MainTab::on_depth_textChanged(const QString &text) +void MainTab::on_depth_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - // don't replot until we set things up the way we want them - MainWindow::instance()->graphics->setReplot(false); - if (!isEditing()) - enableEdition(); - displayed_dive.dc.maxdepth.mm = parseLengthToMm(text); - displayed_dive.maxdepth = displayed_dive.dc.maxdepth; - displayed_dive.dc.meandepth.mm = 0; - displayed_dive.dc.samples = 0; - DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); - markChangedWidget(ui.depth); - MainWindow::instance()->graphics->setReplot(true); - MainWindow::instance()->graphics->plotDive(); + + // Depth editing is special: we only edit the current dive. + Command::editDepth(getCurrentAsList(), parseLengthToMm(ui.depth->text()), current_dive->dc.maxdepth.mm); } void MainTab::on_airtemp_editingFinished() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 2cb82b0bd..f9d7417f5 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -81,8 +81,8 @@ slots: void on_notes_textChanged(); void on_notes_editingFinished(); void on_airtemp_editingFinished(); - void on_duration_textChanged(const QString &text); - void on_depth_textChanged(const QString &text); + void on_duration_editingFinished(); + void on_depth_editingFinished(); void divetype_Changed(int); void on_watertemp_editingFinished(); void on_dateEdit_dateChanged(const QDate &date); |