From 1641147e7b77db69f829cf9b41de4c313d45e3ed Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 29 May 2019 23:02:13 +0200 Subject: 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 --- desktop-widgets/tab-widgets/maintab.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'desktop-widgets/tab-widgets') 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); } -- cgit v1.2.3-70-g09d2