diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-03-02 22:02:33 +0100 |
---|---|---|
committer | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-07 00:13:35 +0200 |
commit | 83d10ce89a1544044ea907e39f498183adb554f2 (patch) | |
tree | 03e92f96bfa3f4d06fec242d39bff0dd3343e173 /profile-widget | |
parent | c2d98b378b06420600af479dc561bf5f55126ebb (diff) | |
download | subsurface-83d10ce89a1544044ea907e39f498183adb554f2.tar.gz |
cleanup: use lambda to transport event-time to context menu actions
This is not such a big gain as for addDivemodeSwitch(), but still
simpler. Therefore, let's do it for consistency.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/profilewidget2.cpp | 32 | ||||
-rw-r--r-- | profile-widget/profilewidget2.h | 6 |
2 files changed, 13 insertions, 25 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 53baa917c..8da3de72c 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1457,15 +1457,11 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) gasChange->addAction(action); } } - QAction *setpointAction = m.addAction(tr("Add setpoint change"), this, &ProfileWidget2::addSetpointChange); - setpointAction->setData(event->globalPos()); - QAction *action = m.addAction(tr("Add bookmark"), this, &ProfileWidget2::addBookmark); - action->setData(event->globalPos()); - QAction *splitAction = m.addAction(tr("Split dive into two"), this, &ProfileWidget2::splitDive); - splitAction->setData(event->globalPos()); + m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); }); + m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); }); + m.addAction(tr("Split dive into two"), [this, seconds]() { splitDive(seconds); }); const struct event *ev = NULL; enum divemode_t divemode = UNDEF_COMP_TYPE; - QString gas = action->text(); get_current_divemode(current_dc, seconds, &ev, &divemode); QMenu *changeMode = m.addMenu(tr("Change divemode")); @@ -1492,7 +1488,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) m.addAction(tr("Edit the profile"), this, SIGNAL(editCurrentDive())); if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) { - action = new QAction(&m); + QAction *action = new QAction(&m); action->setText(tr("Remove event")); action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove. connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent())); @@ -1631,11 +1627,9 @@ void ProfileWidget2::removeEvent() } } -void ProfileWidget2::addBookmark() +void ProfileWidget2::addBookmark(int seconds) { - QAction *action = qobject_cast<QAction *>(sender()); - QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); - add_event(current_dc, lrint(timeAxis->valueAt(scenePos)), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); + add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); invalidate_dive_cache(current_dive); mark_divelist_changed(true); replot(); @@ -1649,26 +1643,20 @@ void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode) replot(); } -void ProfileWidget2::addSetpointChange() +void ProfileWidget2::addSetpointChange(int seconds) { - QAction *action = qobject_cast<QAction *>(sender()); - QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); - SetpointDialog::instance()->setpointData(current_dc, lrint(timeAxis->valueAt(scenePos))); + SetpointDialog::instance()->setpointData(current_dc, seconds); SetpointDialog::instance()->show(); } -void ProfileWidget2::splitDive() +void ProfileWidget2::splitDive(int seconds) { #ifndef SUBSURFACE_MOBILE // Make sure that this is an actual dive and we're not in add mode dive *d = get_dive_by_uniq_id(displayed_dive.id); if (!d) return; - QAction *action = qobject_cast<QAction *>(sender()); - QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); - duration_t time; - time.seconds = lrint(timeAxis->valueAt(scenePos)); - Command::splitDives(d, time); + Command::splitDives(d, duration_t{ seconds }); #endif } diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 4d47cb622..342032567 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -115,9 +115,6 @@ slots: // Necessary to call from QAction's signals. void removePictures(const QVector<QString> &fileUrls); void setPlanState(); void setAddState(); - void addSetpointChange(); - void splitDive(); - void addBookmark(); void hideEvents(); void unhideEvents(); void removeEvent(); @@ -175,6 +172,9 @@ private: void clearPictures(); void plotPicturesInternal(const struct dive *d, bool synchronous); void addDivemodeSwitch(int seconds, int divemode); + void addBookmark(int seconds); + void splitDive(int seconds); + void addSetpointChange(int seconds); private: DivePlotDataModel *dataModel; int zoomLevel; |