summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/diveeventitem.cpp14
-rw-r--r--qt-ui/profile/profilewidget2.cpp70
-rw-r--r--qt-ui/profile/profilewidget2.h4
3 files changed, 80 insertions, 8 deletions
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
index 1fd4ef07a..cb04d6e56 100644
--- a/qt-ui/profile/diveeventitem.cpp
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -4,8 +4,12 @@
#include "animationfunctions.h"
#include "libdivecomputer.h"
#include "dive.h"
+#include "profile.h"
#include <QDebug>
+extern struct ev_select *ev_namelist;
+extern int evn_used;
+
DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent),
vAxis(NULL),
hAxis(NULL),
@@ -107,6 +111,7 @@ void DiveEventItem::eventVisibilityChanged(const QString &eventName, bool visibl
void DiveEventItem::recalculatePos(bool instant)
{
+ bool hidden = false;
if (!vAxis || !hAxis || !internalEvent || !dataModel)
return;
@@ -116,9 +121,12 @@ void DiveEventItem::recalculatePos(bool instant)
hide();
return;
}
- if (!isVisible())
+ for (int i = 0; i < evn_used; i++) {
+ if (!strcmp(internalEvent->name, ev_namelist[i].ev_name) && ev_namelist[i].plot_ev == false)
+ hidden = true;
+ }
+ if (!isVisible() && !hidden)
show();
-
int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
qreal x = hAxis->posAtValue(internalEvent->time.seconds);
qreal y = vAxis->posAtValue(depth);
@@ -126,4 +134,6 @@ void DiveEventItem::recalculatePos(bool instant)
Animations::moveTo(this, x, y);
else
setPos(x, y);
+ if (isVisible() && hidden)
+ hide();
}
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 <libdivecomputer/parser.h>
#include <QSignalTransition>
#include <QPropertyAnimation>
#include <QMenu>
@@ -21,6 +22,7 @@
#include <QSettings>
#include <QScrollBar>
#include <QtCore/qmath.h>
+#include <QMessageBox>
#ifndef QT_NO_DEBUG
#include <QTableView>
@@ -672,11 +674,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
}
QAction *action = m.addAction(tr("Add Bookmark"), this, SLOT(addBookmark()));
action->setData(event->globalPos());
- QList<QGraphicsItem *> itemsAtPos = scene()->items(mapToScene(mapFromGlobal(event->globalPos())));
- Q_FOREACH(QGraphicsItem * i, itemsAtPos) {
- DiveEventItem *item = dynamic_cast<DiveEventItem *>(i);
- if (!item)
- continue;
+ QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
+ if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
action = new QAction(&m);
action->setText(tr("Remove Event"));
action->setData(QVariant::fromValue<void *>(item)); // so we know what to remove.
@@ -687,7 +686,6 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
action->setData(QVariant::fromValue<void *>(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<QAction *>(sender());
+ DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
+ 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<QAction *>(sender());
+ DiveEventItem *item = static_cast<DiveEventItem *>(action->data().value<void *>());
+ 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 = &current_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<QAction *>(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<QAction *>(sender());
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index b5339edef..f02ca4058 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -74,6 +74,10 @@ slots: // Necessary to call from QAction's signals.
void setEmptyState();
void setProfileState();
void changeGas();
+ void addBookmark();
+ void hideEvents();
+ void unhideEvents();
+ void removeEvent();
protected:
virtual void resizeEvent(QResizeEvent *event);