diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2014-01-16 18:39:13 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-17 06:18:25 +0700 |
commit | 58aeb6ce4014899e040a3ef8f4483f18fb44b432 (patch) | |
tree | 9e81e0fded3a1038ffa089e7b1bd49429d529df6 /qt-ui/profile | |
parent | 254beef5d4c0ead123556ffbc5e37dd2cc81366e (diff) | |
download | subsurface-58aeb6ce4014899e040a3ef8f4483f18fb44b432.tar.gz |
Added the Temperature Graph.
Added the Temperature Graph with its related classes. A Temperature Axis
is also created so the item is plotted on the right place.
Currently the Temperature Axis is just like the depth axis - top is
zero, wich means that the graph is inverted.
Also, the Temperature axis is being displayed as this helps debugging.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/divecartesianaxis.cpp | 13 | ||||
-rw-r--r-- | qt-ui/profile/divecartesianaxis.h | 10 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 37 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.h | 11 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 29 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.h | 4 |
6 files changed, 94 insertions, 10 deletions
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index 08138408e..a7721561c 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -143,15 +143,16 @@ qreal DiveCartesianAxis::posAtValue(qreal value) QPointF p = pos(); double size = max - min; - double percent = value / size; + double distanceFromOrigin = value - min; + double percent = (value - min) / size; double realSize = orientation == Qt::Horizontal ? m.x2() - m.x1() : m.y2() - m.y1(); double retValue = realSize * percent; - retValue = (orientation == Qt::Horizontal) ? + double adjusted = (orientation == Qt::Horizontal) ? retValue + m.x1() + p.x() : retValue + m.y1() + p.y(); - return retValue; + return adjusted; } qreal DiveCartesianAxis::percentAt(const QPointF& p) @@ -192,6 +193,12 @@ QString TimeAxis::textForValue(double value) return QString::number(value / 60); } +QString TemperatureAxis::textForValue(double value) +{ + return QString::number(mkelvin_to_C( (int) value)); +} + + void DiveCartesianPlane::setLeftAxis(DiveCartesianAxis* axis) { leftAxis = axis; diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h index eb50c1f92..6add27548 100644 --- a/qt-ui/profile/divecartesianaxis.h +++ b/qt-ui/profile/divecartesianaxis.h @@ -46,12 +46,18 @@ protected: class DepthAxis : public DiveCartesianAxis { protected: - QString textForValue(double value); + QString textForValue(double value); }; class TimeAxis : public DiveCartesianAxis { protected: - QString textForValue(double value); + QString textForValue(double value); +}; + +class TemperatureAxis : public DiveCartesianAxis{ + Q_OBJECT +protected: + QString textForValue(double value); }; // This is a try. Maybe the CartesianPlane should have the X and Y diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 1a96d7009..44a3feb5e 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -6,6 +6,7 @@ #include <QPen> #include <QPainter> #include <QLinearGradient> +#include <QDebug> AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1) @@ -96,4 +97,38 @@ void DiveProfileItem::modelDataChanged(){ pat.setColorAt(1, getColor(DEPTH_BOTTOM)); pat.setColorAt(0, getColor(DEPTH_TOP)); setBrush(QBrush(pat)); -}
\ No newline at end of file +} + +DiveTemperatureItem::DiveTemperatureItem() +{ + QPen pen; + pen.setBrush(QBrush(getColor(::TEMP_PLOT))); + pen.setCosmetic(true); + pen.setWidth(2); + setPen(pen); +} + +void DiveTemperatureItem::modelDataChanged() +{ + // We don't have enougth data to calculate things, quit. + if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1) + return; + + // Ignore empty values. things do not look good with '0' as temperature in kelvin... + QPolygonF poly; + for (int i = 0, modelDataCount = dataModel->rowCount(); i < modelDataCount; i++) { + qreal verticalValue = dataModel->index(i, vDataColumn).data().toReal(); + if(!verticalValue) + continue; + qreal horizontalValue = dataModel->index(i, hDataColumn).data().toReal(); + QPointF point( hAxis->posAtValue(horizontalValue), vAxis->posAtValue(verticalValue)); + poly.append(point); + } + setPolygon(poly); +} + +void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + painter->setPen(pen()); + painter->drawPolyline(polygon()); +} diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index 171dec053..45c90a1bf 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -47,8 +47,15 @@ protected: class DiveProfileItem : public AbstractProfilePolygonItem{ Q_OBJECT public: - virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - virtual void modelDataChanged(); + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + virtual void modelDataChanged(); }; +class DiveTemperatureItem : public AbstractProfilePolygonItem{ + Q_OBJECT +public: + DiveTemperatureItem(); + virtual void modelDataChanged(); + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); +}; #endif
\ No newline at end of file diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index a3db75d4c..2276c1aa8 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -13,7 +13,7 @@ #include <QPropertyAnimation> #include <QMenu> #include <QContextMenuEvent> - +#include <QDebug> #ifndef QT_NO_DEBUG #include <QTableView> @@ -27,6 +27,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : stateMachine(new QStateMachine(this)), background (new DivePixmapItem()), profileYAxis(new DepthAxis()), + temperatureAxis(new TemperatureAxis()), gasYAxis(new DiveCartesianAxis()), timeAxis(new TimeAxis()), depthController(new DiveRectItem()), @@ -60,6 +61,13 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : profileYAxis->setX(2); profileYAxis->setTickSize(1); gasYAxis->setLine(0, 0, 0, 20); + + temperatureAxis->setOrientation(Qt::Vertical); + temperatureAxis->setLine(0, 60, 0, 90); + temperatureAxis->setX(3); + temperatureAxis->setTickSize(2); + temperatureAxis->setTickInterval(300); + timeAxis->setLine(0,0,96,0); timeAxis->setX(3); timeAxis->setTickSize(1); @@ -73,7 +81,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : // insert in the same way it's declared on the Enum. This is needed so we don't use an map. QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis << - timeAxis << depthController << timeController; + timeAxis << depthController << timeController << temperatureAxis; Q_FOREACH(QGraphicsItem *item, stateItems) { scene()->addItem(item); } @@ -268,6 +276,9 @@ void ProfileWidget2::plotDives(QList<dive*> dives) // each item, I'll mostly like to fix this in the future, but I'll keep at this for now. profileYAxis->setMaximum(qMax<long>(pInfo.maxdepth + M_OR_FT(10,30), maxdepth * 2 / 3)); profileYAxis->updateTicks(); + temperatureAxis->setMinimum(pInfo.mintemp); + temperatureAxis->setMaximum(pInfo.maxtemp); + temperatureAxis->updateTicks(); timeAxis->setMaximum(maxtime); timeAxis->updateTicks(); dataModel->setDive(current_dive, pInfo); @@ -299,6 +310,20 @@ void ProfileWidget2::plotDives(QList<dive*> dives) eventItems.push_back(item); event = event->next; } + + if(temperatureItem){ + scene()->removeItem(temperatureItem); + delete temperatureItem; + } + temperatureItem = new DiveTemperatureItem(); + temperatureItem->setHorizontalAxis(timeAxis); + temperatureItem->setVerticalAxis(temperatureAxis); + temperatureItem->setModel(dataModel); + temperatureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE); + temperatureItem->setHorizontalDataColumn(DivePlotDataModel::TIME); + scene()->addItem(temperatureItem); + + emit startProfileState(); } diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index 7d0e7189e..e3289f911 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -15,6 +15,7 @@ // */ #include "graphicsview-common.h" +class TemperatureAxis; class DiveEventItem; struct DivePlotDataModel; struct DivePixmapItem; @@ -26,6 +27,7 @@ struct TimeAxis; struct dive; struct QStateMachine; struct DiveCartesianPlane; +struct DiveTemperatureItem; struct plot_info; class ProfileWidget2 : public QGraphicsView { @@ -66,11 +68,13 @@ private: struct plot_info *plotInfo; DepthAxis *profileYAxis ; DiveCartesianAxis *gasYAxis; + TemperatureAxis *temperatureAxis; TimeAxis *timeAxis; DiveRectItem *depthController; DiveRectItem *timeController; DiveProfileItem *diveProfileItem; DiveCartesianPlane *cartesianPlane; + DiveTemperatureItem *temperatureItem; QList<DiveEventItem*> eventItems; }; |