mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +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)
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue