aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tab-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-29 23:02:13 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-15 11:07:15 -0700
commit1641147e7b77db69f829cf9b41de4c313d45e3ed (patch)
treecdca626fe8e3700b07636ac473e0c3e11be01107 /desktop-widgets/tab-widgets
parentcdb3bcb1a641e27cf157530bf637ee4a9851b401 (diff)
downloadsubsurface-1641147e7b77db69f829cf9b41de4c313d45e3ed.tar.gz
Undo: don't create spurious undo commands for temperature fields
When tabbing through the dive-info fields we get *EditingFinished signals. This would create undo commands. The undo commands should recognize if nothing changed. But for the temperature fields, owing to rounding, an unchanged text could actually represent a different value. This would lead to very confusing situations: 1) Edit air temperature 2) Press tab to finish editing 3) Focus goes to water temperature 4) Try to undo change in menu 5) When opening the menu water temperature loses focus 6) Water temperature is edited 7) Undo undos the water temperature, not the air temperature 8) Goto 4 Fortunately, QLineEdit fields have the isModified() member function that returns true if the field was changed by the user. Use this to prevent this case. This is not a general method, i.e. it has to applied to every field with that problem. But it is less intrusive than subclassing the QLineEdit class. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index c9758dec9..34dcd6c05 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -753,7 +753,10 @@ void MainTab::on_depth_editingFinished()
void MainTab::on_airtemp_editingFinished()
{
- if (editMode == IGNORE || !current_dive)
+ // If the field wasn't modified by the user, don't post a new undo command.
+ // Owing to rounding errors, this might lead to undo commands that have
+ // no user visible effects. These can be very confusing.
+ if (editMode == IGNORE || !ui.airtemp->isModified() || !current_dive)
return;
Command::editAirTemp(parseTemperatureToMkelvin(ui.airtemp->text()), false);
}
@@ -767,7 +770,10 @@ void MainTab::divetype_Changed(int index)
void MainTab::on_watertemp_editingFinished()
{
- if (editMode == IGNORE || !current_dive)
+ // If the field wasn't modified by the user, don't post a new undo command.
+ // Owing to rounding errors, this might lead to undo commands that have
+ // no user visible effects. These can be very confusing.
+ if (editMode == IGNORE || !ui.watertemp->isModified() || !current_dive)
return;
Command::editWaterTemp(parseTemperatureToMkelvin(ui.watertemp->text()), false);
}