diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-05 13:05:45 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-06 08:41:52 -0700 |
commit | 64a5f10cfe9bf82bcab3efc99961bd20cf602df9 (patch) | |
tree | 51fe0a0b46137a76c898224a6b30f050ec5abda8 /desktop-widgets | |
parent | fb76eb9a1a25387b1963914a9118b84d96c9826e (diff) | |
download | subsurface-64a5f10cfe9bf82bcab3efc99961bd20cf602df9.tar.gz |
delegate: don't add WSInfo entry in delegate
The weightsystem info for new weightsystem types is added by the
undo command. Remove this redundant code. Use the lookup only to
determine the weight and the canonical name (i.e. use the capitalization
according to the saved entry, in analogy to tanks).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/modeldelegates.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 36c22a532..ed7278b4c 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -336,19 +336,16 @@ void WSInfoDelegate::setModelData(QWidget*, QAbstractItemModel*, const QModelInd { WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); WSInfoModel *wsim = WSInfoModel::instance(); - QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, currCombo.activeText, 1, Qt::MatchFixedString | Qt::MatchWrap); - int row; - if (matches.isEmpty()) { - // we need to add this puppy - wsim->insertRows(wsim->rowCount(), 1); - wsim->setData(wsim->index(wsim->rowCount() - 1, 0), currCombo.activeText); - row = wsim->rowCount() - 1; - } else { - row = matches.first().row(); + QString weightName = currCombo.activeText; + QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, weightName, 1, Qt::MatchFixedString | Qt::MatchWrap); + int grams = 0; + if (!matches.isEmpty()) { + int row = matches.first().row(); + weightName = matches.first().data().toString(); + grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt(); } - int grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt(); - mymodel->setTempWS(currCombo.currRow, weightsystem_t{ { grams }, copy_qstring(currCombo.activeText) }); + mymodel->setTempWS(currCombo.currRow, weightsystem_t{ { grams }, copy_qstring(weightName) }); } WSInfoDelegate::WSInfoDelegate(QObject *parent) : ComboBoxDelegate(WSInfoModel::instance(), parent, true) |