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>
This commit is contained in:
Berthold Stoeger 2020-03-02 21:48:53 +01:00
parent dee7fd9f30
commit c4c3e62ab0
2 changed files with 6 additions and 15 deletions

View file

@ -1472,22 +1472,19 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
if (divemode != OC) { if (divemode != OC) {
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[OC])); action->setText(gettextFromC::tr(divemode_text_ui[OC]));
connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch())); connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, OC); });
action->setData(event->globalPos());
changeMode->addAction(action); changeMode->addAction(action);
} }
if (divemode != CCR) { if (divemode != CCR) {
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[CCR])); action->setText(gettextFromC::tr(divemode_text_ui[CCR]));
connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch())); connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, CCR); });
action->setData(event->globalPos());
changeMode->addAction(action); changeMode->addAction(action);
} }
if (divemode != PSCR) { if (divemode != PSCR) {
QAction *action = new QAction(&m); QAction *action = new QAction(&m);
action->setText(gettextFromC::tr(divemode_text_ui[PSCR])); action->setText(gettextFromC::tr(divemode_text_ui[PSCR]));
connect(action, SIGNAL(triggered(bool)), this, SLOT(addDivemodeSwitch())); connect(action, &QAction::triggered, [this, seconds](){ addDivemodeSwitch(seconds, PSCR); });
action->setData(event->globalPos());
changeMode->addAction(action); changeMode->addAction(action);
} }
@ -1646,15 +1643,9 @@ void ProfileWidget2::addBookmark()
replot(); replot();
} }
void ProfileWidget2::addDivemodeSwitch() void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode)
{ {
int i; add_event(current_dc, seconds, SAMPLE_EVENT_BOOKMARK, 0, divemode, QT_TRANSLATE_NOOP("gettextFromC", "modechange"));
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"));
invalidate_dive_cache(current_dive); invalidate_dive_cache(current_dive);
mark_divelist_changed(true); mark_divelist_changed(true);
replot(); replot();

View file

@ -118,7 +118,6 @@ slots: // Necessary to call from QAction's signals.
void addSetpointChange(); void addSetpointChange();
void splitDive(); void splitDive();
void addBookmark(); void addBookmark();
void addDivemodeSwitch();
void hideEvents(); void hideEvents();
void unhideEvents(); void unhideEvents();
void removeEvent(); void removeEvent();
@ -175,6 +174,7 @@ private:
const double *thresholdSettingsMin, const double *thresholdSettingsMax); const double *thresholdSettingsMin, const double *thresholdSettingsMax);
void clearPictures(); void clearPictures();
void plotPicturesInternal(const struct dive *d, bool synchronous); void plotPicturesInternal(const struct dive *d, bool synchronous);
void addDivemodeSwitch(int seconds, int divemode);
private: private:
DivePlotDataModel *dataModel; DivePlotDataModel *dataModel;
int zoomLevel; int zoomLevel;