aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-21 14:05:29 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-21 09:39:42 -0800
commit9d33640bea9332ca5afb3df71f7a12da9c29e080 (patch)
treeca18df037282a8100deab83c7bb66d8420b70064
parent21d34db3a94e004affdaceb091382b251071d89d (diff)
downloadsubsurface-9d33640bea9332ca5afb3df71f7a12da9c29e080.tar.gz
Add the gas presssure profile texts.
This just adds the texts for the gas profile. I've also added a method on the dataModel() to return the diveId of the last used dive in a way that the other methods can use it. This code is almost 1-to-1 with the old one, a bit of thinkering can be used to merge this loop with the upper one. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp6
-rw-r--r--qt-ui/profile/diveplotdatamodel.h2
-rw-r--r--qt-ui/profile/diveprofileitem.cpp58
-rw-r--r--qt-ui/profile/diveprofileitem.h9
4 files changed, 66 insertions, 9 deletions
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index b0532f6a9..e393696dc 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -95,8 +95,14 @@ void DivePlotDataModel::setDive(dive* d,const plot_info& pInfo)
if (d)
dc = select_dc(&d->dc);
+ diveId = d->id;
plotData = pInfo.entry;
sampleCount = pInfo.nr;
beginInsertRows(QModelIndex(), 0, sampleCount-1);
endInsertRows();
}
+
+int DivePlotDataModel::id() const
+{
+ return diveId;
+}
diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h
index 3d4d4958b..3afc580cf 100644
--- a/qt-ui/profile/diveplotdatamodel.h
+++ b/qt-ui/profile/diveplotdatamodel.h
@@ -19,9 +19,11 @@ public:
void clear();
void setDive(struct dive *d, const plot_info& pInfo);
plot_data* data();
+ int id() const;
private:
int sampleCount;
plot_data *plotData;
+ int diveId;
};
#endif \ No newline at end of file
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index f33ebeec7..031acf816 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -32,7 +32,7 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
modelDataChanged();
}
-void AbstractProfilePolygonItem::setModel(QAbstractTableModel* model)
+void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
{
dataModel = model;
modelDataChanged();
@@ -69,6 +69,9 @@ void AbstractProfilePolygonItem::modelDataChanged()
poly.append(point);
}
setPolygon(poly);
+
+ qDeleteAll(texts);
+ texts.clear();
}
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
@@ -104,13 +107,10 @@ void DiveProfileItem::modelDataChanged(){
pat.setColorAt(0, getColor(DEPTH_TOP));
setBrush(QBrush(pat));
- qDeleteAll(texts);
- texts.clear();
-
int last = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
- struct plot_data *entry = static_cast<DivePlotDataModel*>(dataModel)->data()+i;
+ struct plot_data *entry = dataModel->data()+i;
if (entry->depth < 2000)
continue;
@@ -243,6 +243,54 @@ void DiveGasPressureItem::modelDataChanged()
polygons.last().push_back(point); // The polygon thta will be plotted.
}
setPolygon(boundingPoly);
+
+ int mbar, cyl;
+ int seen_cyl[MAX_CYLINDERS] = { false, };
+ int last_pressure[MAX_CYLINDERS] = { 0, };
+ int last_time[MAX_CYLINDERS] = { 0, };
+ struct plot_data *entry;
+ struct dive *dive = getDiveById(dataModel->id());
+ Q_ASSERT(dive != NULL);
+
+ cyl = -1;
+ for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
+ entry = dataModel->data() + i;
+ mbar = GET_PRESSURE(entry);
+
+ if (!mbar)
+ continue;
+ if (cyl != entry->cylinderindex) {
+ cyl = entry->cylinderindex;
+ if (!seen_cyl[cyl]) {
+ plot_pressure_value(mbar, entry->sec, Qt::AlignLeft | Qt::AlignBottom);
+// plot_gas_value(mbar, entry->sec, LEFT, TOP,
+// get_o2(&dive->cylinder[cyl].gasmix),
+// get_he(&dive->cylinder[cyl].gasmix));
+ seen_cyl[cyl] = true;
+ }
+ }
+ last_pressure[cyl] = mbar;
+ last_time[cyl] = entry->sec;
+ }
+
+ for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ if (last_time[cyl]) {
+ plot_pressure_value(last_pressure[cyl], last_time[cyl], Qt::AlignHCenter | Qt::AlignTop);
+ }
+ }
+}
+
+void DiveGasPressureItem::plot_pressure_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> flags)
+{
+ const char *unit;
+ int pressure = get_pressure_units(mbar, &unit);
+ //static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, xalign, yalign};
+ DiveTextItem *text = new DiveTextItem(this);
+ text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar));
+ text->setText(QString("%1 %2").arg(pressure).arg(unit));
+ text->setAlignment(flags);
+ text->setBrush(getColor(PRESSURE_TEXT));
+ texts.push_back(text);
}
void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index b9be3edf4..bd1170f39 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -18,6 +18,7 @@
This is a generically item and should be used as a base for others, I think...
*/
+class DivePlotDataModel;
class DiveTextItem;
class DiveCartesianAxis;
class QAbstractTableModel;
@@ -32,7 +33,7 @@ public:
AbstractProfilePolygonItem();
void setVerticalAxis(DiveCartesianAxis *vertical);
void setHorizontalAxis(DiveCartesianAxis *horizontal);
- void setModel(QAbstractTableModel *model);
+ void setModel(DivePlotDataModel *model);
void setHorizontalDataColumn(int column);
void setVerticalDataColumn(int column);
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
@@ -41,7 +42,7 @@ public slots:
protected:
DiveCartesianAxis *hAxis;
DiveCartesianAxis *vAxis;
- QAbstractTableModel *dataModel;
+ DivePlotDataModel *dataModel;
int hDataColumn;
int vDataColumn;
QList<DiveTextItem*> texts;
@@ -69,13 +70,13 @@ private:
class DiveGasPressureItem : public AbstractProfilePolygonItem{
Q_OBJECT
+
public:
virtual void modelDataChanged();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private:
+ void plot_pressure_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> align);
QVector<QPolygonF> polygons;
};
-QGraphicsItemGroup *plotText(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent);
-
#endif \ No newline at end of file