summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-02-17 19:15:40 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-17 14:50:14 -0800
commit31ee4dac65bd6e8b0c3583fc0245cc83a90542d5 (patch)
tree06f1574051bce9fc533a5d2c47d66b5c0d89e5e6 /qt-ui
parentd81223b3f4031ec2f33db164351fb369aeed6b8c (diff)
downloadsubsurface-31ee4dac65bd6e8b0c3583fc0245cc83a90542d5.tar.gz
Make part of the context menu work (gas change event)
The code of the context menu and the gas change event callback is mostly the same as the old profile, with minimum modifications, as this changes the order of the code on the callback to make it a bit saner (declare variables first, call code later). This also fixes a bug on the model that was not cleaning itself in the correct way after a call to clear. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp2
-rw-r--r--qt-ui/profile/diveprofileitem.h1
-rw-r--r--qt-ui/profile/profilewidget2.cpp78
-rw-r--r--qt-ui/profile/profilewidget2.h4
4 files changed, 83 insertions, 2 deletions
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index 700ca6503..111196588 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -100,6 +100,8 @@ void DivePlotDataModel::clear()
if (rowCount() != 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
pInfo.nr = 0;
+ diveId = -1;
+ dcNr = -1;
endRemoveRows();
}
}
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index b51958104..e8bac0421 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -142,7 +142,6 @@ private:
int meanDepth;
DiveTextItem *leftText;
DiveTextItem *rightText;
- DiveCartesianAxis *axis;
};
class PartialPressureGasItem : public AbstractProfilePolygonItem{
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 659ac1cb4..bba1a96a8 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -10,6 +10,7 @@
#include "divetextitem.h"
#include "divetooltipitem.h"
#include "animationfunctions.h"
+#include "planner.h"
#include <QSignalTransition>
#include <QPropertyAnimation>
#include <QMenu>
@@ -543,3 +544,80 @@ void ProfileWidget2::setProfileState()
event->setVisible(true);
}
}
+
+extern struct ev_select *ev_namelist;
+extern int evn_allocated;
+extern int evn_used;
+
+void ProfileWidget2::contextMenuEvent(QContextMenuEvent* event)
+{
+ if (selected_dive == -1)
+ return;
+ QMenu m;
+ QMenu *gasChange = m.addMenu(tr("Add Gas Change"));
+ GasSelectionModel *model = GasSelectionModel::instance();
+ model->repopulate();
+ int rowCount = model->rowCount();
+ for (int i = 0; i < rowCount; i++) {
+ QAction *action = new QAction(&m);
+ action->setText( model->data(model->index(i, 0),Qt::DisplayRole).toString());
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
+ action->setData(event->globalPos());
+ gasChange->addAction(action);
+ }
+ 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) {
+ EventItem *item = dynamic_cast<EventItem*>(i);
+ if (!item)
+ continue;
+ 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()));
+ m.addAction(action);
+ action = new QAction(&m);
+ action->setText(tr("Hide similar events"));
+ 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++) {
+ if (ev_namelist[i].plot_ev == false) {
+ some_hidden = true;
+ break;
+ }
+ }
+ if (some_hidden) {
+ action = m.addAction(tr("Unhide all events"), this, SLOT(unhideEvents()));
+ action->setData(event->globalPos());
+ }
+ m.exec(event->globalPos());
+}
+
+void ProfileWidget2::changeGas()
+{
+ QAction *action = qobject_cast<QAction*>(sender());
+ QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
+ QString gas = action->text();
+ // backup the things on the dataModel, since we will clear that out.
+ int diveComputer = dataModel->dcShown();
+ int diveId = dataModel->id();
+ int o2, he;
+ int seconds = timeAxis->valueAt(scenePos);
+ struct dive *d = getDiveById(diveId);
+
+ validate_gas(gas.toUtf8().constData(), &o2, &he);
+ add_gas_switch_event(d, get_dive_dc(d, diveComputer), seconds, get_gasidx(d, o2, he));
+ // this means we potentially have a new tank that is being used and needs to be shown
+ fixup_dive(d);
+ MainWindow::instance()->information()->updateDiveInfo(selected_dive);
+ mark_divelist_changed(true);
+ // force the redraw of the dive.
+ //TODO: find a way to make this do not need a full redraw
+ dataModel->clear();
+ plotDives(QList<dive*>() << getDiveById(diveId));
+} \ No newline at end of file
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index b7cdbff4d..44f92f707 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -54,11 +54,13 @@ public slots: // Necessary to call from QAction's signals.
void settingsChanged();
void setEmptyState();
void setProfileState();
-
+ void changeGas();
protected:
virtual void resizeEvent(QResizeEvent* event);
virtual void wheelEvent(QWheelEvent* event);
virtual void mouseMoveEvent(QMouseEvent* event);
+ virtual void contextMenuEvent(QContextMenuEvent* event);
+
private: /*methods*/
void fixBackgroundPos();
void scrollViewTo(const QPoint& pos);