summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/profile/diveeventitem.cpp123
-rw-r--r--qt-ui/profile/diveeventitem.h29
-rw-r--r--qt-ui/profile/profilewidget2.cpp19
-rw-r--r--qt-ui/profile/profilewidget2.h8
-rw-r--r--subsurface.pro6
5 files changed, 183 insertions, 2 deletions
diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp
new file mode 100644
index 000000000..a6153f96f
--- /dev/null
+++ b/qt-ui/profile/diveeventitem.cpp
@@ -0,0 +1,123 @@
+#include "diveeventitem.h"
+#include "diveplotdatamodel.h"
+#include "divecartesianaxis.h"
+#include "dive.h"
+#include <QDebug>
+
+DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
+ vAxis(NULL), hAxis(NULL), internalEvent(NULL), dataModel(NULL)
+{
+ setFlag(ItemIgnoresTransformations);
+}
+
+
+void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
+{
+ hAxis = axis;
+ recalculate();
+}
+
+void DiveEventItem::setModel(DivePlotDataModel* model)
+{
+ dataModel = model;
+ recalculate();
+}
+
+void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
+{
+ vAxis = axis;
+ recalculate();
+}
+
+void DiveEventItem::setEvent(struct event* ev)
+{
+ internalEvent = ev;
+ setupPixmap();
+ setupToolTipString();
+ recalculate();
+}
+
+void DiveEventItem::setupPixmap()
+{
+#define EVENT_PIXMAP( PIX ) QPixmap(QString(PIX)).scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation)
+ if(!internalEvent->name){
+ setPixmap(EVENT_PIXMAP(":warning"));
+ } else if ((strcmp(internalEvent->name, "bookmark") == 0)) {
+ setPixmap(EVENT_PIXMAP(":flag"));
+ } else if(strcmp(internalEvent->name, "heading") == 0){
+ setPixmap(EVENT_PIXMAP(":flag"));
+ } else {
+ setPixmap(EVENT_PIXMAP(":warning"));
+ }
+#undef EVENT_PIXMAP
+}
+
+void DiveEventItem::setupToolTipString()
+{
+ //TODO Fix this. :)
+#if 0
+ This needs to be redone, but right now the events are being plotted and I liked pretty much the code.
+
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
+ EventItem *item = new EventItem(ev, 0, isGrayscale);
+ item->setPos(x, y);
+ scene()->addItem(item);
+
+ /* we display the event on screen - so translate (with the correct context for events) */
+ QString name = gettextFromC::instance()->tr(ev->name);
+ if (ev->value) {
+ if (ev->name && strcmp(ev->name, "gaschange") == 0) {
+ int he = get_he(&dive->cylinder[entry->cylinderindex].gasmix);
+ int o2 = get_o2(&dive->cylinder[entry->cylinderindex].gasmix);
+
+ name += ": ";
+ if (he)
+ name += QString("%1/%2").arg((o2 + 5) / 10).arg((he + 5) / 10);
+ else if (is_air(o2, he))
+ name += tr("air");
+ else
+ name += QString(tr("EAN%1")).arg((o2 + 5) / 10);
+
+ } else if (ev->name && !strcmp(ev->name, "SP change")) {
+ name += QString(":%1").arg((double) ev->value / 1000);
+ } else {
+ name += QString(":%1").arg(ev->value);
+ }
+ } else if (ev->name && name == "SP change") {
+ name += "\n" + tr("Bailing out to OC");
+ } else {
+ name += ev->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
+ ev->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
+ }
+
+ //item->setToolTipController(toolTip);
+ //item->addToolTip(name);
+ item->setToolTip(name);
+#endif
+}
+
+void DiveEventItem::eventVisibilityChanged(const QString& eventName, bool visible)
+{
+
+}
+
+void DiveEventItem::recalculate()
+{
+ if (!vAxis || !hAxis || !internalEvent || !dataModel){
+ return;
+ }
+ qDebug() << "Calculating.";
+ QModelIndexList result = dataModel->match(dataModel->index(0,DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds );
+ if(result.isEmpty()){
+ hide();
+ return;
+ }
+ if(!isVisible()){
+ 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);
+ setPos(x, y);
+}
diff --git a/qt-ui/profile/diveeventitem.h b/qt-ui/profile/diveeventitem.h
new file mode 100644
index 000000000..896036e8d
--- /dev/null
+++ b/qt-ui/profile/diveeventitem.h
@@ -0,0 +1,29 @@
+#ifndef DIVEEVENTITEM_H
+#define DIVEEVENTITEM_H
+
+#include "divepixmapitem.h"
+
+class DiveCartesianAxis;
+class DivePlotDataModel;
+struct event;
+
+class DiveEventItem : public DivePixmapItem {
+ Q_OBJECT
+public:
+ DiveEventItem(QObject* parent = 0);
+ void setEvent(struct event *ev);
+ void eventVisibilityChanged(const QString& eventName, bool visible);
+ void setVerticalAxis(DiveCartesianAxis *axis);
+ void setHorizontalAxis(DiveCartesianAxis *axis);
+ void setModel(DivePlotDataModel *model);
+ void recalculate();
+private:
+ void setupToolTipString();
+ void setupPixmap();
+ DiveCartesianAxis *vAxis;
+ DiveCartesianAxis *hAxis;
+ DivePlotDataModel *dataModel;
+ struct event* internalEvent;
+};
+
+#endif \ No newline at end of file
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 89f20eb9b..a3db75d4c 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -6,6 +6,7 @@
#include "diveprofileitem.h"
#include "helpers.h"
#include "profile.h"
+#include "diveeventitem.h"
#include <QStateMachine>
#include <QSignalTransition>
@@ -13,6 +14,7 @@
#include <QMenu>
#include <QContextMenuEvent>
+
#ifndef QT_NO_DEBUG
#include <QTableView>
#endif
@@ -262,6 +264,8 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
int maxtime = get_maxtime(&pInfo);
int maxdepth = get_maxdepth(&pInfo);
+ // It seems that I'll have a lot of boilerplate setting the model / axis for
+ // each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
profileYAxis->setMaximum(qMax<long>(pInfo.maxdepth + M_OR_FT(10,30), maxdepth * 2 / 3));
profileYAxis->updateTicks();
timeAxis->setMaximum(maxtime);
@@ -280,6 +284,21 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
diveProfileItem->setVerticalDataColumn(DivePlotDataModel::DEPTH);
diveProfileItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
scene()->addItem(diveProfileItem);
+
+ qDeleteAll(eventItems);
+ eventItems.clear();
+
+ struct event *event = currentdc->events;
+ while (event) {
+ DiveEventItem *item = new DiveEventItem();
+ item->setHorizontalAxis(timeAxis);
+ item->setVerticalAxis(profileYAxis);
+ item->setModel(dataModel);
+ item->setEvent(event);
+ scene()->addItem(item);
+ eventItems.push_back(item);
+ event = event->next;
+ }
emit startProfileState();
}
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index bea433fef..7d0e7189e 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -14,6 +14,8 @@
// * It needs to be dynamic, things should *flow* on it, not just appear / disappear.
// */
#include "graphicsview-common.h"
+
+class DiveEventItem;
struct DivePlotDataModel;
struct DivePixmapItem;
struct DiveRectItem;
@@ -24,6 +26,7 @@ struct TimeAxis;
struct dive;
struct QStateMachine;
struct DiveCartesianPlane;
+struct plot_info;
class ProfileWidget2 : public QGraphicsView {
Q_OBJECT
@@ -57,6 +60,10 @@ private:
QStateMachine *stateMachine;
DivePixmapItem *background ;
+ // All those here should probably be merged into one structure,
+ // So it's esyer to replicate for more dives later.
+ // In the meantime, keep it here.
+ struct plot_info *plotInfo;
DepthAxis *profileYAxis ;
DiveCartesianAxis *gasYAxis;
TimeAxis *timeAxis;
@@ -64,6 +71,7 @@ private:
DiveRectItem *timeController;
DiveProfileItem *diveProfileItem;
DiveCartesianPlane *cartesianPlane;
+ QList<DiveEventItem*> eventItems;
};
#endif \ No newline at end of file
diff --git a/subsurface.pro b/subsurface.pro
index 671b7698b..b557357e5 100644
--- a/subsurface.pro
+++ b/subsurface.pro
@@ -71,7 +71,8 @@ HEADERS = \
qt-ui/profile/animationfunctions.h \
qt-ui/profile/divecartesianaxis.h \
qt-ui/profile/diveplotdatamodel.h \
- qt-ui/profile/diveprofileitem.h
+ qt-ui/profile/diveprofileitem.h \
+ qt-ui/profile/diveeventitem.h
SOURCES = \
deco.c \
@@ -131,7 +132,8 @@ SOURCES = \
qt-ui/profile/animationfunctions.cpp \
qt-ui/profile/divecartesianaxis.cpp \
qt-ui/profile/diveplotdatamodel.cpp \
- qt-ui/profile/diveprofileitem.cpp
+ qt-ui/profile/diveprofileitem.cpp \
+ qt-ui/profile/diveeventitem.cpp
linux*: SOURCES += linux.c
mac: SOURCES += macos.c