summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-12 12:51:34 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-12 10:36:36 -0700
commit72312bec2f4dcde3150a2d989bd729237c704d66 (patch)
treee167e4123847d0c5587c765346eb5868e2344a24
parent762c5276fd7e49ec5f4e76973c1159b31e4fec63 (diff)
downloadsubsurface-72312bec2f4dcde3150a2d989bd729237c704d66.tar.gz
desktop: on weight type change, don't overwrite weight if already set
When importing from other software, it happens that weights are imported without their type. When the user changes the type, the imported weight is overwritten, which is not exactly a friendly behavior. On the other hand, when changing the type after creation of a weight entry, it is preferrable to set a default weight. This is convenient for people who commonly use the same weight. As a compromise, set the default weight only if it was unset. We recognize this by a weight value of 0 g. Fixes #2938 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--CHANGELOG.md1
-rw-r--r--qt-models/weightmodel.cpp7
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8881c821..d539a28eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,4 @@
+desktop: don't overwrite already set weights when changing weight type [#2938]
desktop: do substring search for equipment types
planner: properly initialize salinity
desktop: add an "Edit Gas Change" right-click option [#2910]
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index 6b5f9e70d..020e14c24 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -86,11 +86,16 @@ void WeightModel::setTempWS(int row, weightsystem_t ws)
// It is really hard to get the editor-close-hints and setModelData calls under
// control. Therefore, if the row is set to the already existing entry, don't
// enter temporary mode.
- if (same_string(d->weightsystems.weightsystems[row].description, ws.description)) {
+ const weightsystem_t &oldWS = d->weightsystems.weightsystems[row];
+ if (same_string(oldWS.description, ws.description)) {
free_weightsystem(ws);
} else {
tempRow = row;
tempWS = ws;
+
+ // If the user had already set a weight, don't overwrite that
+ if (oldWS.weight.grams)
+ tempWS.weight = oldWS.weight;
}
dataChanged(index(row, TYPE), index(row, WEIGHT));
}