From 401aa210ffb33cfefc94906a4cc476e00c4b1cff Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 15 Mar 2014 21:12:34 -0700 Subject: New profile: add event manipulation to context menu This got lost when we switched to the new profile. Remove event works. Hide events does call hide() on the DiveEventItem but for some reason it stays visible. I'll hope for one of the more experienced Qt people to fix that. Signed-off-by: Dirk Hohndel --- qt-ui/profile/profilewidget2.cpp | 70 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 6 deletions(-) (limited to 'qt-ui/profile/profilewidget2.cpp') diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index f16b3a48d..7e0aba001 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -13,6 +13,7 @@ #include "planner.h" #include "device.h" #include "ruleritem.h" +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #ifndef QT_NO_DEBUG #include @@ -672,11 +674,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) } QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark())); action->setData(event->globalPos()); - QList itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos()))); - Q_FOREACH(QGraphicsItem * i, itemsAtPos) { - DiveEventItem *item = dynamic_cast(i); - if (!item) - continue; + QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos())); + if (DiveEventItem *item = dynamic_cast(sceneItem)) { action = new QAction(&m); action->setText(tr("Remove Event")); action->setData(QVariant::fromValue(item)); // so we know what to remove. @@ -687,7 +686,6 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) action->setData(QVariant::fromValue(item)); connect(action, SIGNAL(triggered(bool)), this, SLOT(hideEvents())); m.addAction(action); - break; } bool some_hidden = false; for (int i = 0; i < evn_used; i++) { @@ -703,6 +701,66 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) m.exec(event->globalPos()); } +void ProfileWidget2::hideEvents() +{ + QAction *action = qobject_cast(sender()); + DiveEventItem *item = static_cast(action->data().value()); + struct event *event = item->getEvent(); + + if (QMessageBox::question(MainWindow::instance(), + TITLE_OR_TEXT(tr("Hide events"), tr("Hide all %1 events?").arg(event->name)), + QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { + if (event->name) { + for (int i = 0; i < evn_used; i++) { + if (!strcmp(event->name, ev_namelist[i].ev_name)) { + ev_namelist[i].plot_ev = false; + break; + } + } + } + item->hide(); + replot(); + } +} + +void ProfileWidget2::unhideEvents() +{ + for (int i = 0; i < evn_used; i++) { + ev_namelist[i].plot_ev = true; + } + replot(); +} + +void ProfileWidget2::removeEvent() +{ + QAction *action = qobject_cast(sender()); + DiveEventItem *item = static_cast(action->data().value()); + struct event *event = item->getEvent(); + + if (QMessageBox::question(MainWindow::instance(), TITLE_OR_TEXT( + tr("Remove the selected event?"), + tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))), + QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { + struct event **ep = ¤t_dc->events; + while (ep && *ep != event) + ep = &(*ep)->next; + if (ep) { + *ep = event->next; + free(event); + } + mark_divelist_changed(true); + replot(); + } +} + +void ProfileWidget2::addBookmark() +{ + QAction *action = qobject_cast(sender()); + QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); + add_event(current_dc, timeAxis->valueAt(scenePos), SAMPLE_EVENT_BOOKMARK, 0, 0, "bookmark"); + replot(); +} + void ProfileWidget2::changeGas() { QAction *action = qobject_cast(sender()); -- cgit v1.2.3-70-g09d2