mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
c2d98b378b
commit
83d10ce89a
2 changed files with 13 additions and 25 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue