diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2021-04-25 22:35:41 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-04-26 08:24:28 -0700 |
commit | c34f0b88a255401a5603413e59656cf4fe4967ca (patch) | |
tree | e70245463c8aede474801da52f5f50c354f814ad /profile-widget | |
parent | 78f4d7b2b921f4c1f1f313c5d3b1ed393144a9da (diff) | |
download | subsurface-c34f0b88a255401a5603413e59656cf4fe4967ca.tar.gz |
profile: move checking for DiveTextItem into its own function
When creating the context menu, a special menu is created for
the dive computer name.
This was checked in a loop, that set a flag and exited early.
This can all be simplified by moving the loop into its own
function. No more flag, less indentation. Overall better.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/profilewidget2.cpp | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index b8b655e04..3e73a54b4 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1342,6 +1342,16 @@ static QString printCylinderDescription(int i, const cylinder_t *cylinder) return label; } +static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textItem) +{ + while (item) { + if (item == textItem) + return true; + item = item->parentItem(); + } + return false; +} + void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) { if (currentState == ADD || currentState == PLAN) { @@ -1349,36 +1359,26 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) return; } QMenu m; - bool isDCName = false; if (!d) return; // figure out if we are ontop of the dive computer name in the profile QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos())); - if (sceneItem) { - QGraphicsItem *parentItem = sceneItem; - while (parentItem) { - if (parentItem == diveComputerText) { - isDCName = true; - break; - } - parentItem = parentItem->parentItem(); - } - if (isDCName) { - if (dc == 0 && number_of_computers(d) == 1) - // nothing to do, can't delete or reorder - return; - // create menu to show when right clicking on dive computer name - if (dc > 0) - m.addAction(tr("Make first dive computer"), this, &ProfileWidget2::makeFirstDC); - if (number_of_computers(d) > 1) { - m.addAction(tr("Delete this dive computer"), this, &ProfileWidget2::deleteCurrentDC); - m.addAction(tr("Split this dive computer into own dive"), this, &ProfileWidget2::splitCurrentDC); - } - m.exec(event->globalPos()); - // don't show the regular profile context menu + if (isDiveTextItem(sceneItem, diveComputerText)) { + if (dc == 0 && number_of_computers(d) == 1) + // nothing to do, can't delete or reorder return; + // create menu to show when right clicking on dive computer name + if (dc > 0) + m.addAction(tr("Make first dive computer"), this, &ProfileWidget2::makeFirstDC); + if (number_of_computers(d) > 1) { + m.addAction(tr("Delete this dive computer"), this, &ProfileWidget2::deleteCurrentDC); + m.addAction(tr("Split this dive computer into own dive"), this, &ProfileWidget2::splitCurrentDC); } + m.exec(event->globalPos()); + // don't show the regular profile context menu + return; } + // create the profile context menu QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos())); qreal sec_val = timeAxis->valueAt(scenePos); |