Print CCR cylinder pressure labels in a nonoverlapping way.
The oxygen and diluent cylinder pressures with CCR dives are often fairly similar, within the range 100-180 bar. This causes the cylinder pressure text for the two cylinders to be overprinted, either with the labels at the start of the dive or with the pressure labels at the end of the dive. This patch minimises the overprinting by writing cylinder info for the top graph above the graph, and the cylinder information for the bottom graph below the graph. The text for the bottom graph will therefore not overlap with the top graph and vice versa. See attached image of before-this-patch (above) and after-this_patch (below) dive profile.
Signed-off-by: willem ferguson <[email protected]>
>From 7da856a47a5e86556b702d911e701f6596ee0e79 Mon Sep 17 00:00:00 2001 From: willem ferguson <[email protected]> Date: Sun, 11 Jan 2015 14:33:06 +0200 Subject: [PATCH 2/2] Print CCR cylinder pressure labels in a nonoverlapping way Print CCR cylinder pressure labels in a nonoverlapping way. The oxygen and diluent cylinder pressures with CCR dives are often fairly similar, within the range 100-180 bar. This causes the cylinder pressure text for the two cylinders to be overprinted, either with the labels at the start of the dive or with the pressure labels at the end of the dive. This patch minimises the overprinting by writing cylinder info for the top graph above the graph, and the cylinder information for the bottom graph below the graph. The text for the bottom graph will therefore not overlap with the top graph and vice versa. See attached image of before-this-patch (above) and after-this_patch (below) dive profile. Signed-off-by: willem ferguson <[email protected]> --- qt-ui/profile/diveprofileitem.cpp | 56 ++++++++++++++++++++++++++++++--------- qt-ui/profile/diveprofileitem.h | 4 +-- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index c049d91..8d2b810 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -635,7 +635,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo o2mbar = GET_O2CYLINDER_PRESSURE(entry); if (entry->cylinderindex != last_index) { - polygons.append(QPolygonF()); // this is the polygon that will be actually drawned on screen. + polygons.append(QPolygonF()); // this is the polygon that will be actually drawn on screen. last_index = entry->cylinderindex; } if (!mbar) { @@ -662,30 +662,54 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo cyl = -1; o2mbar = 0; + + double print_y_offset[8][3] = { { 0, -0.5, -0.5 }, { 0, -0.5, -0.5 }, { 0, -0.5, -0.5 }, { 0, -0.5, -0.5 }, + { 0, -0.5, -0.5 } ,{ 0, -0.5, -0.5 }, { 0, -0.5, -0.5 }, { 0, -0.5, -0.5 } }; + // CCR dives: These are offset values used to print the gas lables and pressures on a CCR dive profile at + // appropriate Y-coordinates: One triplet of values for each of 8 cylinders. + // Order within a triplet: start gas lable, start gas pressure, end gas pressure. + // The array is initialised with default values that apply to non-CCR dives. + + bool offsets_initialised = false; + int o2cyl, dilcyl; for (int i = 0, count = dataModel->rowCount(); i < count; i++) { entry = dataModel->data().entry + i; mbar = GET_PRESSURE(entry); if (displayed_dive.dc.dctype == CCR && displayed_dive.oxygen_cylinder_index >= 0) o2mbar = GET_O2CYLINDER_PRESSURE(entry); - if (o2mbar) { + // The first time an o2 value is detected, see if the oxygen cyl pressure graph starts above or below the dil graph + if (!offsets_initialised) { + o2cyl = displayed_dive.oxygen_cylinder_index; + dilcyl = displayed_dive.diluent_cylinder_index; + if ((o2mbar > mbar)) { // If above, write o2 start cyl pressure above graph and diluent pressure below graph: + print_y_offset[o2cyl][0] = -5; // y offset for oxygen gas lable + print_y_offset[o2cyl][1] = -3; // y offset for oxygen start pressure value + print_y_offset[dilcyl][0] = 2; // y offset for diluent gas lable + print_y_offset[dilcyl][1] = 2; // y offset for diluent start pressure value + } else { + print_y_offset[o2cyl][0] = 2; // write o2 start cyl pressure below graph + print_y_offset[o2cyl][1] = 0; + print_y_offset[dilcyl][0] = -5; // and diluent pressure above graph. + } + offsets_initialised = true; + } if (!seen_cyl[displayed_dive.oxygen_cylinder_index]) { - plotPressureValue(o2mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom); - plotGasValue(o2mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom, displayed_dive.cylinder[displayed_dive.oxygen_cylinder_index].gasmix); + plotPressureValue(o2mbar, print_y_offset[o2cyl][1], entry->sec, Qt::AlignRight | Qt::AlignBottom); + plotGasValue(o2mbar, print_y_offset[o2cyl][0], entry->sec, Qt::AlignRight | Qt::AlignBottom, displayed_dive.cylinder[displayed_dive.oxygen_cylinder_index].gasmix); seen_cyl[displayed_dive.oxygen_cylinder_index] = true; } last_pressure[displayed_dive.oxygen_cylinder_index] = o2mbar; last_time[displayed_dive.oxygen_cylinder_index] = entry->sec; } - if (!mbar) continue; if (cyl != entry->cylinderindex) { cyl = entry->cylinderindex; if (!seen_cyl[cyl]) { - plotPressureValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignTop); - plotGasValue(mbar, entry->sec, Qt::AlignRight | Qt::AlignBottom, + plotPressureValue(mbar, print_y_offset[cyl][1], entry->sec, Qt::AlignRight | Qt::AlignTop); + plotGasValue(mbar, print_y_offset[cyl][0], entry->sec, Qt::AlignRight | Qt::AlignBottom, displayed_dive.cylinder[cyl].gasmix); seen_cyl[cyl] = true; } @@ -694,30 +718,38 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo last_time[cyl] = entry->sec; } + if ((o2cyl + dilcyl < 14) && (o2cyl + dilcyl >= 0)) { // At first, skip uninitialised values of o2cyl and dilcyl + if (last_pressure[o2cyl] > last_pressure[dilcyl]) { // If oxygen cyl pressure graph ends above diluent graph: + print_y_offset[dilcyl][2] = 2; // write diluent cyl end pressure underneath the graph + } else { + print_y_offset[o2cyl][2] = 2; // write oxygen cyl end pressure underneath the graph + } + } + for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { if (last_time[cyl]) { - plotPressureValue(last_pressure[cyl], last_time[cyl], Qt::AlignLeft | Qt::AlignTop); + plotPressureValue(last_pressure[cyl], print_y_offset[cyl][2], last_time[cyl], Qt::AlignLeft | Qt::AlignTop); } } } -void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlags<Qt::AlignmentFlag> flags) +void DiveGasPressureItem::plotPressureValue(int mbar, double pressure_offset, int sec, QFlags<Qt::AlignmentFlag> flags) { const char *unit; int pressure = get_pressure_units(mbar, &unit); DiveTextItem *text = new DiveTextItem(this); - text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) - 0.5); + text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) + pressure_offset); text->setText(QString("%1 %2").arg(pressure).arg(unit)); text->setAlignment(flags); text->setBrush(getColor(PRESSURE_TEXT)); texts.push_back(text); } -void DiveGasPressureItem::plotGasValue(int mbar, int sec, QFlags<Qt::AlignmentFlag> flags, struct gasmix gasmix) +void DiveGasPressureItem::plotGasValue(int mbar, double gasname_offset, int sec, QFlags<Qt::AlignmentFlag> flags, struct gasmix gasmix) { QString gas = gasToStr(gasmix); DiveTextItem *text = new DiveTextItem(this); - text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar)); + text->setPos(hAxis->posAtValue(sec), vAxis->posAtValue(mbar) + gasname_offset); text->setText(gas); text->setAlignment(flags); text->setBrush(getColor(PRESSURE_TEXT)); diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index b0693cd..a9c11ed 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -165,8 +165,8 @@ public: virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); private: - void plotPressureValue(int mbar, int sec, QFlags<Qt::AlignmentFlag> align); - void plotGasValue(int mbar, int sec, QFlags<Qt::AlignmentFlag> align, struct gasmix gasmix); + void plotPressureValue(int mbar, double offset, int sec, QFlags<Qt::AlignmentFlag> align); + void plotGasValue(int mbar, double offset, int sec, QFlags<Qt::AlignmentFlag> align, struct gasmix gasmix); QVector<QPolygonF> polygons; }; -- 1.9.1
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
