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>
This commit is contained in:
Berthold Stoeger 2020-09-12 12:51:34 +02:00 committed by Dirk Hohndel
parent 762c5276fd
commit 72312bec2f
2 changed files with 7 additions and 1 deletions

View file

@ -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]

View file

@ -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));
}