mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Add initial support for a visual tracker of gas used
This shows a color-coded bar at the bottom of the graph that corresponds with the active gas. Todo: - text that explicitly states gas on the left edge of the bar - better vertical positioning of the bar - ability to turn this on and off Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9015160199
commit
fa3c18d83b
5 changed files with 144 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "planner.h"
|
||||
#include "device.h"
|
||||
#include "ruleritem.h"
|
||||
#include "tankitem.h"
|
||||
#include "dive.h"
|
||||
#include "pref.h"
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
@ -89,6 +90,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
|
|||
mouseFollowerVertical(new DiveLineItem()),
|
||||
mouseFollowerHorizontal(new DiveLineItem()),
|
||||
rulerItem(new RulerItem2()),
|
||||
tankItem(new TankItem()),
|
||||
isGrayscale(false),
|
||||
printMode(false),
|
||||
shouldCalculateMaxTime(true),
|
||||
|
@ -160,6 +162,7 @@ void ProfileWidget2::addItemsToScene()
|
|||
scene()->addItem(rulerItem);
|
||||
scene()->addItem(rulerItem->sourceNode());
|
||||
scene()->addItem(rulerItem->destNode());
|
||||
scene()->addItem(tankItem);
|
||||
scene()->addItem(mouseFollowerHorizontal);
|
||||
scene()->addItem(mouseFollowerVertical);
|
||||
QPen pen(QColor(Qt::red).lighter());
|
||||
|
@ -177,6 +180,7 @@ void ProfileWidget2::setupItemOnScene()
|
|||
toolTipItem->setZValue(9998);
|
||||
toolTipItem->setTimeAxis(timeAxis);
|
||||
rulerItem->setZValue(9997);
|
||||
tankItem->setZValue(100);
|
||||
|
||||
profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom);
|
||||
profileYAxis->setMinimum(0);
|
||||
|
@ -219,6 +223,7 @@ void ProfileWidget2::setupItemOnScene()
|
|||
diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale));
|
||||
|
||||
rulerItem->setAxis(timeAxis, profileYAxis);
|
||||
tankItem->setHorizontalAxis(timeAxis);
|
||||
|
||||
setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
||||
setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
|
||||
|
@ -409,6 +414,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
|
|||
// reset some item visibility on printMode changes
|
||||
toolTipItem->setVisible(!printMode);
|
||||
rulerItem->setVisible(prefs.rulergraph && !printMode);
|
||||
tankItem->setVisible(true);
|
||||
|
||||
if (currentState == EMPTY)
|
||||
setProfileState();
|
||||
|
@ -487,6 +493,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
|
|||
cylinderPressureAxis->setMaximum(pInfo.maxpressure);
|
||||
|
||||
rulerItem->setPlotInfo(pInfo);
|
||||
tankItem->setData(dataModel, &pInfo, &displayed_dive);
|
||||
meanDepth->setVisible(prefs.show_average_depth);
|
||||
meanDepth->setMeanDepth(pInfo.meandepth);
|
||||
meanDepth->setLine(0, 0, timeAxis->posAtValue(currentdc->duration.seconds), 0);
|
||||
|
@ -727,6 +734,7 @@ void ProfileWidget2::setEmptyState()
|
|||
diveCeiling->setVisible(false);
|
||||
reportedCeiling->setVisible(false);
|
||||
rulerItem->setVisible(false);
|
||||
tankItem->setVisible(false);
|
||||
pn2GasItem->setVisible(false);
|
||||
po2GasItem->setVisible(false);
|
||||
pheGasItem->setVisible(false);
|
||||
|
@ -809,6 +817,7 @@ void ProfileWidget2::setProfileState()
|
|||
}
|
||||
}
|
||||
rulerItem->setVisible(prefs.rulergraph);
|
||||
tankItem->setVisible(true);
|
||||
#define HIDE_ALL(TYPE, CONTAINER) \
|
||||
Q_FOREACH (TYPE *item, CONTAINER) item->setVisible(false);
|
||||
HIDE_ALL(DiveHandler, handles);
|
||||
|
|
|
@ -40,6 +40,7 @@ class DiveCalculatedTissue;
|
|||
class PartialPressureGasItem;
|
||||
class PartialGasPressureAxis;
|
||||
class AbstractProfilePolygonItem;
|
||||
class TankItem;
|
||||
class DiveHandler;
|
||||
class QGraphicsSimpleTextItem;
|
||||
class QModelIndex;
|
||||
|
@ -164,6 +165,7 @@ private:
|
|||
DiveLineItem *mouseFollowerVertical;
|
||||
DiveLineItem *mouseFollowerHorizontal;
|
||||
RulerItem2 *rulerItem;
|
||||
TankItem *tankItem;
|
||||
bool isGrayscale;
|
||||
bool printMode;
|
||||
|
||||
|
|
97
qt-ui/profile/tankitem.cpp
Normal file
97
qt-ui/profile/tankitem.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "tankitem.h"
|
||||
#include "diveplotdatamodel.h"
|
||||
#include "profile.h"
|
||||
#include <QGradient>
|
||||
#include <QDebug>
|
||||
|
||||
TankItem::TankItem(QObject *parent) :
|
||||
QGraphicsRectItem(),
|
||||
dataModel(0),
|
||||
dive(0),
|
||||
pInfo(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d)
|
||||
{
|
||||
pInfo = plotInfo;
|
||||
dive = d;
|
||||
dataModel = model;
|
||||
connect(dataModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)));
|
||||
modelDataChanged();
|
||||
}
|
||||
|
||||
void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
||||
{
|
||||
// We don't have enougth data to calculate things, quit.
|
||||
|
||||
if (!dive || !dataModel || !pInfo || !pInfo->nr)
|
||||
return;
|
||||
|
||||
// remove the old rectangles
|
||||
foreach (QGraphicsRectItem *r, rects) {
|
||||
delete(r);
|
||||
}
|
||||
rects.clear();
|
||||
|
||||
// define the position on the profile
|
||||
qreal width, left, yPos, height;
|
||||
yPos = 95.0;
|
||||
height = 3.0;
|
||||
|
||||
// set up the three patterns
|
||||
QLinearGradient nitrox(QPointF(0, yPos), QPointF(0, yPos + height));
|
||||
nitrox.setColorAt(0.0, Qt::green);
|
||||
nitrox.setColorAt(0.49, Qt::green);
|
||||
nitrox.setColorAt(0.5, Qt::yellow);
|
||||
nitrox.setColorAt(1.0, Qt::yellow);
|
||||
QLinearGradient trimix(QPointF(0, yPos), QPointF(0, yPos + height));
|
||||
trimix.setColorAt(0.0, Qt::green);
|
||||
trimix.setColorAt(0.49, Qt::green);
|
||||
trimix.setColorAt(0.5, Qt::red);
|
||||
trimix.setColorAt(1.0, Qt::red);
|
||||
QColor air(Qt::blue);
|
||||
air.lighter();
|
||||
|
||||
// walk the list and figure out which tanks go where
|
||||
struct plot_data *entry = pInfo->entry;
|
||||
int cylIdx = entry->cylinderindex;
|
||||
int i = -1;
|
||||
int startTime = 0;
|
||||
struct gasmix *gas = &dive->cylinder[cylIdx].gasmix;
|
||||
while (++i < pInfo->nr) {
|
||||
entry = &pInfo->entry[i];
|
||||
if (entry->cylinderindex == cylIdx)
|
||||
continue;
|
||||
width = hAxis->posAtValue(entry->sec) - hAxis->posAtValue(startTime);
|
||||
left = hAxis->posAtValue(startTime);
|
||||
QGraphicsRectItem *rect = new QGraphicsRectItem(left, yPos, width, height, this);
|
||||
if (gasmix_is_air(gas))
|
||||
rect->setBrush(air);
|
||||
else if (gas->he.permille)
|
||||
rect->setBrush(trimix);
|
||||
else
|
||||
rect->setBrush(nitrox);
|
||||
rects << rect;
|
||||
cylIdx = entry->cylinderindex;
|
||||
gas = &dive->cylinder[cylIdx].gasmix;
|
||||
startTime = entry->sec;
|
||||
}
|
||||
width = hAxis->posAtValue(entry->sec) - hAxis->posAtValue(startTime);
|
||||
left = hAxis->posAtValue(startTime);
|
||||
QGraphicsRectItem *rect = new QGraphicsRectItem(left, yPos, width, height, this);
|
||||
if (gasmix_is_air(gas))
|
||||
rect->setBrush(air);
|
||||
else if (gas->he.permille)
|
||||
rect->setBrush(trimix);
|
||||
else
|
||||
rect->setBrush(nitrox);
|
||||
rects << rect;
|
||||
}
|
||||
|
||||
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
|
||||
{
|
||||
hAxis = horizontal;
|
||||
connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged()));
|
||||
modelDataChanged();
|
||||
}
|
34
qt-ui/profile/tankitem.h
Normal file
34
qt-ui/profile/tankitem.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef TANKITEM_H
|
||||
#define TANKITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QModelIndex>
|
||||
#include "divelineitem.h"
|
||||
#include "divecartesianaxis.h"
|
||||
#include "dive.h"
|
||||
|
||||
class TankItem : public QObject, public QGraphicsRectItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
|
||||
public:
|
||||
explicit TankItem(QObject *parent = 0);
|
||||
void setHorizontalAxis(DiveCartesianAxis *horizontal);
|
||||
void setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
|
||||
|
||||
private:
|
||||
DivePlotDataModel *dataModel;
|
||||
DiveCartesianAxis *hAxis;
|
||||
int hDataColumn;
|
||||
struct dive *dive;
|
||||
struct plot_info *pInfo;
|
||||
QList<QGraphicsRectItem *> rects;
|
||||
};
|
||||
|
||||
#endif // TANKITEM_H
|
|
@ -83,6 +83,7 @@ HEADERS = \
|
|||
qt-ui/profile/diveeventitem.h \
|
||||
qt-ui/profile/divetooltipitem.h \
|
||||
qt-ui/profile/ruleritem.h \
|
||||
qt-ui/profile/tankitem.h \
|
||||
qt-ui/updatemanager.h \
|
||||
qt-ui/divelogexportdialog.h \
|
||||
qt-ui/usersurvey.h \
|
||||
|
@ -162,6 +163,7 @@ SOURCES = \
|
|||
qt-ui/profile/diveeventitem.cpp \
|
||||
qt-ui/profile/divetooltipitem.cpp \
|
||||
qt-ui/profile/ruleritem.cpp \
|
||||
qt-ui/profile/tankitem.cpp \
|
||||
qt-ui/updatemanager.cpp \
|
||||
qt-ui/divelogexportdialog.cpp \
|
||||
qt-ui/usersurvey.cpp \
|
||||
|
|
Loading…
Reference in a new issue