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/tab-widgets/maintab.cpp | |
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/tab-widgets/maintab.cpp')
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 58 |
1 files changed, 15 insertions, 43 deletions
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) |