mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
21d34db3a9
commit
9d33640bea
4 changed files with 66 additions and 9 deletions
|
@ -95,8 +95,14 @@ void DivePlotDataModel::setDive(dive* d,const plot_info& pInfo)
|
||||||
|
|
||||||
if (d)
|
if (d)
|
||||||
dc = select_dc(&d->dc);
|
dc = select_dc(&d->dc);
|
||||||
|
diveId = d->id;
|
||||||
plotData = pInfo.entry;
|
plotData = pInfo.entry;
|
||||||
sampleCount = pInfo.nr;
|
sampleCount = pInfo.nr;
|
||||||
beginInsertRows(QModelIndex(), 0, sampleCount-1);
|
beginInsertRows(QModelIndex(), 0, sampleCount-1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DivePlotDataModel::id() const
|
||||||
|
{
|
||||||
|
return diveId;
|
||||||
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
void setDive(struct dive *d, const plot_info& pInfo);
|
void setDive(struct dive *d, const plot_info& pInfo);
|
||||||
plot_data* data();
|
plot_data* data();
|
||||||
|
int id() const;
|
||||||
private:
|
private:
|
||||||
int sampleCount;
|
int sampleCount;
|
||||||
plot_data *plotData;
|
plot_data *plotData;
|
||||||
|
int diveId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -32,7 +32,7 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractProfilePolygonItem::setModel(QAbstractTableModel* model)
|
void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
|
||||||
{
|
{
|
||||||
dataModel = model;
|
dataModel = model;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
|
@ -69,6 +69,9 @@ void AbstractProfilePolygonItem::modelDataChanged()
|
||||||
poly.append(point);
|
poly.append(point);
|
||||||
}
|
}
|
||||||
setPolygon(poly);
|
setPolygon(poly);
|
||||||
|
|
||||||
|
qDeleteAll(texts);
|
||||||
|
texts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
||||||
|
@ -104,13 +107,10 @@ void DiveProfileItem::modelDataChanged(){
|
||||||
pat.setColorAt(0, getColor(DEPTH_TOP));
|
pat.setColorAt(0, getColor(DEPTH_TOP));
|
||||||
setBrush(QBrush(pat));
|
setBrush(QBrush(pat));
|
||||||
|
|
||||||
qDeleteAll(texts);
|
|
||||||
texts.clear();
|
|
||||||
|
|
||||||
int last = -1;
|
int last = -1;
|
||||||
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
|
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)
|
if (entry->depth < 2000)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -243,6 +243,54 @@ void DiveGasPressureItem::modelDataChanged()
|
||||||
polygons.last().push_back(point); // The polygon thta will be plotted.
|
polygons.last().push_back(point); // The polygon thta will be plotted.
|
||||||
}
|
}
|
||||||
setPolygon(boundingPoly);
|
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)
|
void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
This is a generically item and should be used as a base for others, I think...
|
This is a generically item and should be used as a base for others, I think...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class DivePlotDataModel;
|
||||||
class DiveTextItem;
|
class DiveTextItem;
|
||||||
class DiveCartesianAxis;
|
class DiveCartesianAxis;
|
||||||
class QAbstractTableModel;
|
class QAbstractTableModel;
|
||||||
|
@ -32,7 +33,7 @@ public:
|
||||||
AbstractProfilePolygonItem();
|
AbstractProfilePolygonItem();
|
||||||
void setVerticalAxis(DiveCartesianAxis *vertical);
|
void setVerticalAxis(DiveCartesianAxis *vertical);
|
||||||
void setHorizontalAxis(DiveCartesianAxis *horizontal);
|
void setHorizontalAxis(DiveCartesianAxis *horizontal);
|
||||||
void setModel(QAbstractTableModel *model);
|
void setModel(DivePlotDataModel *model);
|
||||||
void setHorizontalDataColumn(int column);
|
void setHorizontalDataColumn(int column);
|
||||||
void setVerticalDataColumn(int column);
|
void setVerticalDataColumn(int column);
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
|
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
|
||||||
|
@ -41,7 +42,7 @@ public slots:
|
||||||
protected:
|
protected:
|
||||||
DiveCartesianAxis *hAxis;
|
DiveCartesianAxis *hAxis;
|
||||||
DiveCartesianAxis *vAxis;
|
DiveCartesianAxis *vAxis;
|
||||||
QAbstractTableModel *dataModel;
|
DivePlotDataModel *dataModel;
|
||||||
int hDataColumn;
|
int hDataColumn;
|
||||||
int vDataColumn;
|
int vDataColumn;
|
||||||
QList<DiveTextItem*> texts;
|
QList<DiveTextItem*> texts;
|
||||||
|
@ -69,13 +70,13 @@ private:
|
||||||
|
|
||||||
class DiveGasPressureItem : public AbstractProfilePolygonItem{
|
class DiveGasPressureItem : public AbstractProfilePolygonItem{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void modelDataChanged();
|
virtual void modelDataChanged();
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||||
private:
|
private:
|
||||||
|
void plot_pressure_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> align);
|
||||||
QVector<QPolygonF> polygons;
|
QVector<QPolygonF> polygons;
|
||||||
};
|
};
|
||||||
|
|
||||||
QGraphicsItemGroup *plotText(text_render_options_t *tro,const QPointF& pos, const QString& text, QGraphicsItem *parent);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Reference in a new issue