mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: use lambdas to transport DiveEventItem to actions
The removeEvent(), hideEvents() and editName() actions need the DiveEventItem they are applied to. This was transported via QAction's user-data, which means casting to void and back. By using lambdas instead, this can be made perfectly type-safe: First we are 100% sure that we have a DiveEventItem because we check the result of a dynamic_cast<>. Then we can pass it to the even using its proper type. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
83d10ce89a
commit
76a41f45c7
2 changed files with 9 additions and 18 deletions
|
@ -1490,20 +1490,17 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
||||||
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
|
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
|
||||||
QAction *action = new QAction(&m);
|
QAction *action = new QAction(&m);
|
||||||
action->setText(tr("Remove event"));
|
action->setText(tr("Remove event"));
|
||||||
action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove.
|
connect(action, &QAction::triggered, [this,item] { removeEvent(item); });
|
||||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(removeEvent()));
|
|
||||||
m.addAction(action);
|
m.addAction(action);
|
||||||
action = new QAction(&m);
|
action = new QAction(&m);
|
||||||
action->setText(tr("Hide similar events"));
|
action->setText(tr("Hide similar events"));
|
||||||
action->setData(QVariant::fromValue<void *>(item));
|
connect(action, &QAction::triggered, [this, item] { hideEvents(item); });
|
||||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents()));
|
|
||||||
m.addAction(action);
|
m.addAction(action);
|
||||||
struct event *dcEvent = item->getEvent();
|
struct event *dcEvent = item->getEvent();
|
||||||
if (dcEvent->type == SAMPLE_EVENT_BOOKMARK) {
|
if (dcEvent->type == SAMPLE_EVENT_BOOKMARK) {
|
||||||
action = new QAction(&m);
|
action = new QAction(&m);
|
||||||
action->setText(tr("Edit name"));
|
action->setText(tr("Edit name"));
|
||||||
action->setData(QVariant::fromValue<void *>(item));
|
connect(action, &QAction::triggered, [this, item] { editName(item); });
|
||||||
connect(action, SIGNAL(triggered(bool)), this, SLOT(editName()));
|
|
||||||
m.addAction(action);
|
m.addAction(action);
|
||||||
}
|
}
|
||||||
#if 0 // TODO::: FINISH OR DISABLE
|
#if 0 // TODO::: FINISH OR DISABLE
|
||||||
|
@ -1575,10 +1572,8 @@ void ProfileWidget2::makeFirstDC()
|
||||||
Command::moveDiveComputerToFront(current_dive, dc_number);
|
Command::moveDiveComputerToFront(current_dive, dc_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileWidget2::hideEvents()
|
void ProfileWidget2::hideEvents(DiveEventItem *item)
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
|
||||||
DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
|
|
||||||
struct event *event = item->getEvent();
|
struct event *event = item->getEvent();
|
||||||
|
|
||||||
if (QMessageBox::question(this,
|
if (QMessageBox::question(this,
|
||||||
|
@ -1610,10 +1605,8 @@ void ProfileWidget2::unhideEvents()
|
||||||
item->show();
|
item->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileWidget2::removeEvent()
|
void ProfileWidget2::removeEvent(DiveEventItem *item)
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
|
||||||
DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
|
|
||||||
struct event *event = item->getEvent();
|
struct event *event = item->getEvent();
|
||||||
|
|
||||||
if (QMessageBox::question(this, TITLE_OR_TEXT(
|
if (QMessageBox::question(this, TITLE_OR_TEXT(
|
||||||
|
@ -1730,10 +1723,8 @@ double ProfileWidget2::getFontPrintScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef SUBSURFACE_MOBILE
|
#ifndef SUBSURFACE_MOBILE
|
||||||
void ProfileWidget2::editName()
|
void ProfileWidget2::editName(DiveEventItem *item)
|
||||||
{
|
{
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
|
||||||
DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
|
|
||||||
struct event *event = item->getEvent();
|
struct event *event = item->getEvent();
|
||||||
bool ok;
|
bool ok;
|
||||||
QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"),
|
QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"),
|
||||||
|
|
|
@ -115,10 +115,7 @@ slots: // Necessary to call from QAction's signals.
|
||||||
void removePictures(const QVector<QString> &fileUrls);
|
void removePictures(const QVector<QString> &fileUrls);
|
||||||
void setPlanState();
|
void setPlanState();
|
||||||
void setAddState();
|
void setAddState();
|
||||||
void hideEvents();
|
|
||||||
void unhideEvents();
|
void unhideEvents();
|
||||||
void removeEvent();
|
|
||||||
void editName();
|
|
||||||
void makeFirstDC();
|
void makeFirstDC();
|
||||||
void deleteCurrentDC();
|
void deleteCurrentDC();
|
||||||
void splitCurrentDC();
|
void splitCurrentDC();
|
||||||
|
@ -175,6 +172,9 @@ private:
|
||||||
void addBookmark(int seconds);
|
void addBookmark(int seconds);
|
||||||
void splitDive(int seconds);
|
void splitDive(int seconds);
|
||||||
void addSetpointChange(int seconds);
|
void addSetpointChange(int seconds);
|
||||||
|
void removeEvent(DiveEventItem *item);
|
||||||
|
void hideEvents(DiveEventItem *item);
|
||||||
|
void editName(DiveEventItem *item);
|
||||||
private:
|
private:
|
||||||
DivePlotDataModel *dataModel;
|
DivePlotDataModel *dataModel;
|
||||||
int zoomLevel;
|
int zoomLevel;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue