diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-01-30 22:13:24 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | de579c1a1ad823fbc42d7e3122b77b03626283c3 (patch) | |
tree | afcb74e7c30f5235ba899fa02ca5e2b5e4ce581a /desktop-widgets | |
parent | a12adf8e2a5a9fc2471874e69d31ce50bbaf4cb8 (diff) | |
download | subsurface-de579c1a1ad823fbc42d7e3122b77b03626283c3.tar.gz |
Undo: implement undo of air and water temperature editing
Mostly trivial. Since now on editing the field is re-set, the
validation function becomes unnecessary.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/command.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/command.h | 2 | ||||
-rw-r--r-- | desktop-widgets/command_edit.cpp | 44 | ||||
-rw-r--r-- | desktop-widgets/command_edit.h | 18 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 58 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 5 |
6 files changed, 90 insertions, 47 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index 37c53235d..c178c408a 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -155,4 +155,14 @@ void editVisibility(const QVector<dive *> dives, int newValue, int oldValue) execute(new EditVisibility(dives, newValue, oldValue)); } +void editAirTemp(const QVector<dive *> dives, int newValue, int oldValue) +{ + execute(new EditAirTemp(dives, newValue, oldValue)); +} + +void editWaterTemp(const QVector<dive *> dives, int newValue, int oldValue) +{ + execute(new EditWaterTemp(dives, newValue, oldValue)); +} + } // namespace Command diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index bc3e36cae..3161120fd 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -57,6 +57,8 @@ void editSuit(const QVector<dive *> dives, const QString &newValue, const QStrin void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue); 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); } // namespace Command diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp index 0480378b8..dc90ccd5e 100644 --- a/desktop-widgets/command_edit.cpp +++ b/desktop-widgets/command_edit.cpp @@ -145,7 +145,7 @@ DiveField EditRating::fieldId() const return DiveField::RATING; } -// ***** Visibility **** +// ***** Visibility ***** void EditVisibility::set(struct dive *d, int value) const { d->visibility = value; @@ -166,6 +166,48 @@ DiveField EditVisibility::fieldId() const return DiveField::VISIBILITY; } +// ***** Air Temperature ***** +void EditAirTemp::set(struct dive *d, int value) const +{ + d->airtemp.mkelvin = value > 0 ? (uint32_t)value : 0u; +} + +int EditAirTemp::data(struct dive *d) const +{ + return (int)d->airtemp.mkelvin; +} + +QString EditAirTemp::fieldName() const +{ + return tr("air temperature"); +} + +DiveField EditAirTemp::fieldId() const +{ + return DiveField::AIR_TEMP; +} + +// ***** Water Temperature ***** +void EditWaterTemp::set(struct dive *d, int value) const +{ + d->watertemp.mkelvin = value > 0 ? (uint32_t)value : 0u; +} + +int EditWaterTemp::data(struct dive *d) const +{ + return (int)d->watertemp.mkelvin; +} + +QString EditWaterTemp::fieldName() const +{ + return tr("water temperature"); +} + +DiveField EditWaterTemp::fieldId() const +{ + return DiveField::WATER_TEMP; +} + // ***** 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 diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h index 831f7f971..cc4ea2374 100644 --- a/desktop-widgets/command_edit.h +++ b/desktop-widgets/command_edit.h @@ -83,6 +83,24 @@ public: DiveField fieldId() const override; }; +class EditAirTemp : 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 EditWaterTemp : 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 EditMode : public EditBase<int> { int index; public: diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 2f6c8c8cd..202c75071 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -342,6 +342,12 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field) return; switch(field) { + case DiveField::AIR_TEMP: + ui.airtemp->setText(get_temperature_string(current_dive->airtemp, true)); + break; + case DiveField::WATER_TEMP: + ui.watertemp->setText(get_temperature_string(current_dive->watertemp, true)); + break; case DiveField::RATING: ui.rating->setCurrentStars(current_dive->rating); break; @@ -804,11 +810,6 @@ void MainTab::acceptChanges() struct dive *cd = current_dive; // now check if something has changed and if yes, edit the selected dives that // were identical with the master dive shown (and mark the divelist as changed) - if (displayed_dive.airtemp.mkelvin != cd->airtemp.mkelvin) - MODIFY_DIVES(selectedDives, EDIT_VALUE(airtemp.mkelvin)); - if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin) - MODIFY_DIVES(selectedDives, EDIT_VALUE(watertemp.mkelvin)); - if (displayed_dive.dive_site != cd->dive_site) MODIFY_DIVES(selectedDives, EDIT_VALUE(dive_site)); @@ -1091,13 +1092,12 @@ void MainTab::on_depth_textChanged(const QString &text) MainWindow::instance()->graphics->plotDive(); } -void MainTab::on_airtemp_textChanged(const QString &text) +void MainTab::on_airtemp_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - displayed_dive.airtemp.mkelvin = parseTemperatureToMkelvin(text); - markChangedWidget(ui.airtemp); - validate_temp_field(ui.airtemp, text); + Command::editAirTemp(getSelectedDivesCurrentLast(), + parseTemperatureToMkelvin(ui.airtemp->text()), current_dive->airtemp.mkelvin); } void MainTab::divetype_Changed(int index) @@ -1108,41 +1108,13 @@ void MainTab::divetype_Changed(int index) get_dive_dc(current_dive, dc_number)->divemode); } -void MainTab::on_watertemp_textChanged(const QString &text) +void MainTab::on_watertemp_editingFinished() { - if (editMode == IGNORE || acceptingEdit == true) + if (editMode == IGNORE || acceptingEdit == true || !current_dive) return; - displayed_dive.watertemp.mkelvin = parseTemperatureToMkelvin(text); - markChangedWidget(ui.watertemp); - validate_temp_field(ui.watertemp, text); -} - -void MainTab::validate_temp_field(QLineEdit *tempField, const QString &text) -{ - static bool missing_unit = false; - static bool missing_precision = false; - if (!text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°[CF]){0,1}$")) && - !text.isEmpty() && - !text.contains(QRegExp("^[-+]$"))) { - if (text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.][0-9]+){0,1}(°)$")) && !missing_unit) { - if (!missing_unit) { - missing_unit = true; - return; - } - } - if (text.contains(QRegExp("^[-+]{0,1}[0-9]+([,.]){0,1}(°[CF]){0,1}$")) && !missing_precision) { - if (!missing_precision) { - missing_precision = true; - return; - } - } - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::red).lighter()); - tempField->setPalette(p); - } else { - missing_unit = false; - missing_precision = false; - } + Command::editWaterTemp(getSelectedDivesCurrentLast(), + parseTemperatureToMkelvin(ui.watertemp->text()), + current_dive->watertemp.mkelvin); } void MainTab::on_dateEdit_dateChanged(const QDate &date) diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 14a077ba9..36f9a64a9 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -80,12 +80,11 @@ slots: void on_diveTripLocation_textEdited(const QString& text); void on_notes_textChanged(); void on_notes_editingFinished(); - void on_airtemp_textChanged(const QString &text); + void on_airtemp_editingFinished(); void on_duration_textChanged(const QString &text); void on_depth_textChanged(const QString &text); void divetype_Changed(int); - void on_watertemp_textChanged(const QString &text); - void validate_temp_field(QLineEdit *tempField, const QString &text); + void on_watertemp_editingFinished(); void on_dateEdit_dateChanged(const QDate &date); void on_timeEdit_timeChanged(const QTime & time); void on_rating_valueChanged(int value); |