aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-17 17:54:47 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-17 14:04:47 -0800
commit35979537d9fc42987648db39f64f6bc01052ed17 (patch)
treed2ef715ab34060cc60aef9ade25637104df00a1b /qt-ui
parent4ff73cf5370a3233a4caf29ded6e738e3d02b3a0 (diff)
downloadsubsurface-35979537d9fc42987648db39f64f6bc01052ed17.tar.gz
Plot the Temperature Text.
I Moved the 'plot text' method of the Old Graphics to the new layout - this one was mostly unchanged as it was already good as is. And used the TemperatureProfileItem to also display texts. This was the first implementation of the new system that uses *less* code than the original one, wich makes me happy. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/graphicsview-common.h7
-rw-r--r--qt-ui/profile/diveprofileitem.cpp79
-rw-r--r--qt-ui/profile/diveprofileitem.h8
-rw-r--r--qt-ui/profilegraphics.cpp21
-rw-r--r--qt-ui/profilegraphics.h2
5 files changed, 96 insertions, 21 deletions
diff --git a/qt-ui/graphicsview-common.h b/qt-ui/graphicsview-common.h
index 0c260a89e..c00b2d69c 100644
--- a/qt-ui/graphicsview-common.h
+++ b/qt-ui/graphicsview-common.h
@@ -36,4 +36,11 @@ extern QMap<color_indice_t, QVector<QColor> > profile_color;
void fill_profile_color();
QColor getColor(const color_indice_t i);
+struct text_render_options {
+ double size;
+ color_indice_t color;
+ double hpos, vpos;
+};
+
+typedef text_render_options text_render_options_t;
#endif
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index 3e6b05a09..32679b565 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -2,12 +2,17 @@
#include "diveplotdatamodel.h"
#include "divecartesianaxis.h"
#include "graphicsview-common.h"
+#include "divetextitem.h"
#include "profile.h"
+#include "dive.h"
+#include "profilegraphics.h"
#include <QPen>
#include <QPainter>
#include <QLinearGradient>
#include <QDebug>
+#include <QApplication>
+#include <QGraphicsItem>
AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
@@ -117,15 +122,46 @@ void DiveTemperatureItem::modelDataChanged()
// Ignore empty values. things do not look good with '0' as temperature in kelvin...
QPolygonF poly;
+ int last = -300, last_printed_temp = 0, sec = 0;
for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) {
- qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal();
- if(!verticalValue)
+ int mkelvin = dataModel->index(i, vDataColumn).data().toInt();
+ if(!mkelvin)
continue;
- qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal();
- QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue));
+ int sec = dataModel->index(i, hDataColumn).data().toInt();
+ QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin));
poly.append(point);
+
+ /* don't print a temperature
+ * if it's been less than 5min and less than a 2K change OR
+ * if it's been less than 2min OR if the change from the
+ * last print is less than .4K (and therefore less than 1F) */
+ if (((sec < last + 300) && (abs(mkelvin - last_printed_temp) < 2000)) ||
+ (sec < last + 120) ||
+ (abs(mkelvin - last_printed_temp) < 400))
+ continue;
+ last = sec;
+ if (mkelvin > 200000)
+ createTextItem(sec,mkelvin);
+ last_printed_temp = mkelvin;
}
setPolygon(poly);
+
+ /* it would be nice to print the end temperature, if it's
+ * different or if the last temperature print has been more
+ * than a quarter of the dive back */
+ int last_temperature = dataModel->data(dataModel->index(dataModel->rowCount()-1, DivePlotDataModel::TEMPERATURE)).toInt();
+ if (last_temperature > 200000 && ((abs(last_temperature - last_printed_temp) > 500) || ((double)last / (double)sec < 0.75))){
+ createTextItem(sec, last_temperature);
+ }
+}
+
+void DiveTemperatureItem::createTextItem(int sec, int mkelvin)
+{
+ double deg;
+ const char *unit;
+ static text_render_options_t tro = {TEMP_TEXT_SIZE, TEMP_TEXT, LEFT, TOP};
+ deg = get_temp_units(mkelvin, &unit);
+ plotText(&tro, QPointF(hAxis->posAtValue(sec), vAxis->posAtValue(mkelvin)), QString("%1%2").arg(deg, 0, 'f', 1).arg(unit), this); //"%.2g%s"
}
void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
@@ -146,7 +182,6 @@ void DiveGasPressureItem::modelDataChanged()
QPolygonF boundingPoly; // This is the "Whole Item", but a pressure can be divided in N Polygons.
polygons.clear();
-#define M_PRESSURE( ROW )
for (int i = 0; i < dataModel->rowCount(); i++) {
int sPressure = dataModel->index(i, DivePlotDataModel::SENSOR_PRESSURE).data().toInt();
int iPressure = dataModel->index(i, DivePlotDataModel::INTERPOLATED_PRESSURE).data().toInt();
@@ -181,4 +216,36 @@ void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
painter->drawLine(poly[i-1],poly[i]);
}
}
-} \ No newline at end of file
+}
+
+QGraphicsItemGroup *plotText(text_render_options_t* tro, const QPointF& pos, const QString& text, QGraphicsItem *parent)
+{
+ QFont fnt(qApp->font());
+ QFontMetrics fm(fnt);
+
+ /*
+ if (printMode)
+ fnt.setPixelSize(tro->size);
+ */
+
+ QGraphicsItemGroup *group = new QGraphicsItemGroup(parent);
+ QPainterPath textPath;
+ /* addText() uses bottom-left text baseline and the -3 offset is probably slightly off
+ * for different font sizes. */
+ textPath.addText(0, fm.height() - 3, fnt, text);
+ QPainterPathStroker stroker;
+ stroker.setWidth(3);
+ QGraphicsPathItem *strokedItem = new QGraphicsPathItem(stroker.createStroke(textPath), group);
+ strokedItem->setBrush(QBrush(getColor(TEXT_BACKGROUND)));
+ strokedItem->setPen(Qt::NoPen);
+
+ QGraphicsPathItem *textItem = new QGraphicsPathItem(textPath, group);
+ textItem->setBrush(QBrush(getColor(tro->color)));
+ textItem->setPen(Qt::NoPen);
+
+ group->setPos(pos);
+ //group->setPos(pos.x() + dx, pos.y() + dy);
+// if (!printMode)
+ group->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+ return group;
+}
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index ddecef947..2002c904a 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -3,7 +3,7 @@
#include <QObject>
#include <QGraphicsPolygonItem>
-
+#include "graphicsview-common.h"
/* This is the Profile Item, it should be used for quite a lot of things
on the profile view. The usage should be pretty simple:
@@ -18,6 +18,7 @@
This is a generically item and should be used as a base for others, I think...
*/
+class DiveTextItem;
class DiveCartesianAxis;
class QAbstractTableModel;
@@ -57,6 +58,8 @@ public:
DiveTemperatureItem();
virtual void modelDataChanged();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+private:
+ void createTextItem(int seconds, int mkelvin);
};
class DiveGasPressureItem : public AbstractProfilePolygonItem{
@@ -67,4 +70,7 @@ public:
private:
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
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index c907d2529..454bca65a 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -38,12 +38,6 @@ static struct graphics_context last_gc;
static double plot_scale = SCALE_SCREEN;
#endif
-struct text_render_options {
- double size;
- color_indice_t color;
- double hpos, vpos;
-};
-
extern struct ev_select *ev_namelist;
extern int evn_allocated;
extern int evn_used;
@@ -436,24 +430,25 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
scene()->addItem(rect);
/* Depth profile */
- plot_depth_profile();
- plot_events(dc);
+ plot_depth_profile(); // TODO: PARTIALLY PORTED.
+ plot_events(dc); // PORTED
- if (rulerEnabled && !printMode)
+ if (rulerEnabled && !printMode) // TODO: NOT PORTED.
create_ruler();
/* Temperature profile */
- plot_temperature_profile();
+ plot_temperature_profile(); // PORTED
/* Cylinder pressure plot */
- plot_cylinder_pressure();
+ plot_cylinder_pressure(); // PORTED
- /* Text on top of all graphs.. */
+ /* Text on top of all graphs.. */ // TODO: NOT PORTED, ANY TEXT.
plot_temperature_text();
plot_depth_text();
plot_cylinder_pressure_text();
plot_deco_text();
+ // NOT PORTED.
/* Put the dive computer name in the lower left corner */
gc.leftx = 0; gc.rightx = 1.0;
gc.topy = 0; gc.bottomy = 1.0;
@@ -463,11 +458,13 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
// The Time ruler should be right after the DiveComputer:
timeMarkers->setPos(0, diveComputer->y());
+ // NOT PORTED.
if (PP_GRAPHS_ENABLED) {
plot_pp_gas_profile();
plot_pp_text();
}
+ // NOT PORTED.
plot_depth_scale();
#if 0
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 1be02bcb1..8881d0321 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -10,10 +10,8 @@
#include <QPushButton>
#include <QGraphicsProxyWidget>
-struct text_render_options;
struct graphics_context;
struct plot_info;
-typedef struct text_render_options text_render_options_t;
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.