summaryrefslogtreecommitdiffstats
path: root/profile-widget/profilewidget2.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-03-02 21:48:53 +0100
committerGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-07 00:13:35 +0200
commitc4c3e62ab0b3abed940ca16009b47b3dab61f068 (patch)
treef23c3ea26bd6c85341ec5298459b666fdb8dd3c0 /profile-widget/profilewidget2.cpp
parentdee7fd9f308caae16045038b67dedd604a4d0ac2 (diff)
downloadsubsurface-c4c3e62ab0b3abed940ca16009b47b3dab61f068.tar.gz
profile: use lambda for addDivemodeSwitch calls
The data was transported via the action in a most complicated way: The text was backtranslated. Simply use a lambda - perhaps hard to read, but much simpler to follow and less brittle. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/profilewidget2.cpp')
-rw-r--r--profile-widget/profilewidget2.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 43ebf0777..ebc760cac 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1472,22 +1472,19 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
if (divemode != OC) {
QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[OC]));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch()));
- action->setData(event->globalPos());
+ connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, OC); });
changeMode->addAction(action);
}
if (divemode != CCR) {
QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[CCR]));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch()));
- action->setData(event->globalPos());
+ connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, CCR); });
changeMode->addAction(action);
}
if (divemode != PSCR) {
QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[PSCR]));
- connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch()));
- action->setData(event->globalPos());
+ connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, PSCR); });
changeMode->addAction(action);
}
@@ -1646,15 +1643,9 @@ void ProfileWidget2::addBookmark()
replot();
}
-void ProfileWidget2::addDivemodeSwitch()
+void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode)
{
- int i;
- QAction *action = qobject_cast<QAction *>(sender());
- QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
- for (i = 0; i < NUM_DIVEMODE; i++)
- if (gettextFromC::tr(divemode_text_ui[i]) == action->text())
- add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), SAMPLE_EVENT_BOOKMARK, 0, i,
- QT_TRANSLATE_NOOP("gettextFromC", "modechange"));
+ add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, divemode, QT_TRANSLATE_NOOP("gettextFromC", "modechange"));
invalidate_dive_cache(current_dive);
mark_divelist_changed(true);
replot();