mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
254beef5d4
commit
58aeb6ce40
6 changed files with 94 additions and 10 deletions
|
@ -143,15 +143,16 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
|
||||||
QPointF p = pos();
|
QPointF p = pos();
|
||||||
|
|
||||||
double size = max - min;
|
double size = max - min;
|
||||||
double percent = value / size;
|
double distanceFromOrigin = value - min;
|
||||||
|
double percent = (value - min) / size;
|
||||||
double realSize = orientation == Qt::Horizontal ?
|
double realSize = orientation == Qt::Horizontal ?
|
||||||
m.x2() - m.x1() :
|
m.x2() - m.x1() :
|
||||||
m.y2() - m.y1();
|
m.y2() - m.y1();
|
||||||
double retValue = realSize * percent;
|
double retValue = realSize * percent;
|
||||||
retValue = (orientation == Qt::Horizontal) ?
|
double adjusted = (orientation == Qt::Horizontal) ?
|
||||||
retValue + m.x1() + p.x() :
|
retValue + m.x1() + p.x() :
|
||||||
retValue + m.y1() + p.y();
|
retValue + m.y1() + p.y();
|
||||||
return retValue;
|
return adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal DiveCartesianAxis::percentAt(const QPointF& p)
|
qreal DiveCartesianAxis::percentAt(const QPointF& p)
|
||||||
|
@ -192,6 +193,12 @@ QString TimeAxis::textForValue(double value)
|
||||||
return QString::number(value / 60);
|
return QString::number(value / 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TemperatureAxis::textForValue(double value)
|
||||||
|
{
|
||||||
|
return QString::number(mkelvin_to_C( (int) value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DiveCartesianPlane::setLeftAxis(DiveCartesianAxis* axis)
|
void DiveCartesianPlane::setLeftAxis(DiveCartesianAxis* axis)
|
||||||
{
|
{
|
||||||
leftAxis = axis;
|
leftAxis = axis;
|
||||||
|
|
|
@ -46,12 +46,18 @@ protected:
|
||||||
|
|
||||||
class DepthAxis : public DiveCartesianAxis {
|
class DepthAxis : public DiveCartesianAxis {
|
||||||
protected:
|
protected:
|
||||||
QString textForValue(double value);
|
QString textForValue(double value);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimeAxis : public DiveCartesianAxis {
|
class TimeAxis : public DiveCartesianAxis {
|
||||||
protected:
|
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
|
// This is a try. Maybe the CartesianPlane should have the X and Y
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QLinearGradient>
|
#include <QLinearGradient>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
|
AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
|
||||||
hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
|
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(1, getColor(DEPTH_BOTTOM));
|
||||||
pat.setColorAt(0, getColor(DEPTH_TOP));
|
pat.setColorAt(0, getColor(DEPTH_TOP));
|
||||||
setBrush(QBrush(pat));
|
setBrush(QBrush(pat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
|
@ -47,8 +47,15 @@ protected:
|
||||||
class DiveProfileItem : public AbstractProfilePolygonItem{
|
class DiveProfileItem : public AbstractProfilePolygonItem{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||||
virtual void modelDataChanged();
|
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
|
#endif
|
|
@ -13,7 +13,7 @@
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
|
@ -27,6 +27,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
stateMachine(new QStateMachine(this)),
|
stateMachine(new QStateMachine(this)),
|
||||||
background (new DivePixmapItem()),
|
background (new DivePixmapItem()),
|
||||||
profileYAxis(new DepthAxis()),
|
profileYAxis(new DepthAxis()),
|
||||||
|
temperatureAxis(new TemperatureAxis()),
|
||||||
gasYAxis(new DiveCartesianAxis()),
|
gasYAxis(new DiveCartesianAxis()),
|
||||||
timeAxis(new TimeAxis()),
|
timeAxis(new TimeAxis()),
|
||||||
depthController(new DiveRectItem()),
|
depthController(new DiveRectItem()),
|
||||||
|
@ -60,6 +61,13 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
|
||||||
profileYAxis->setX(2);
|
profileYAxis->setX(2);
|
||||||
profileYAxis->setTickSize(1);
|
profileYAxis->setTickSize(1);
|
||||||
gasYAxis->setLine(0, 0, 0, 20);
|
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->setLine(0,0,96,0);
|
||||||
timeAxis->setX(3);
|
timeAxis->setX(3);
|
||||||
timeAxis->setTickSize(1);
|
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.
|
// 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 <<
|
QList<QGraphicsItem*> stateItems; stateItems << background << profileYAxis << gasYAxis <<
|
||||||
timeAxis << depthController << timeController;
|
timeAxis << depthController << timeController << temperatureAxis;
|
||||||
Q_FOREACH(QGraphicsItem *item, stateItems) {
|
Q_FOREACH(QGraphicsItem *item, stateItems) {
|
||||||
scene()->addItem(item);
|
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.
|
// 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->setMaximum(qMax<long>(pInfo.maxdepth + M_OR_FT(10,30), maxdepth * 2 / 3));
|
||||||
profileYAxis->updateTicks();
|
profileYAxis->updateTicks();
|
||||||
|
temperatureAxis->setMinimum(pInfo.mintemp);
|
||||||
|
temperatureAxis->setMaximum(pInfo.maxtemp);
|
||||||
|
temperatureAxis->updateTicks();
|
||||||
timeAxis->setMaximum(maxtime);
|
timeAxis->setMaximum(maxtime);
|
||||||
timeAxis->updateTicks();
|
timeAxis->updateTicks();
|
||||||
dataModel->setDive(current_dive, pInfo);
|
dataModel->setDive(current_dive, pInfo);
|
||||||
|
@ -299,6 +310,20 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
|
||||||
eventItems.push_back(item);
|
eventItems.push_back(item);
|
||||||
event = event->next;
|
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();
|
emit startProfileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
// */
|
// */
|
||||||
#include "graphicsview-common.h"
|
#include "graphicsview-common.h"
|
||||||
|
|
||||||
|
class TemperatureAxis;
|
||||||
class DiveEventItem;
|
class DiveEventItem;
|
||||||
struct DivePlotDataModel;
|
struct DivePlotDataModel;
|
||||||
struct DivePixmapItem;
|
struct DivePixmapItem;
|
||||||
|
@ -26,6 +27,7 @@ struct TimeAxis;
|
||||||
struct dive;
|
struct dive;
|
||||||
struct QStateMachine;
|
struct QStateMachine;
|
||||||
struct DiveCartesianPlane;
|
struct DiveCartesianPlane;
|
||||||
|
struct DiveTemperatureItem;
|
||||||
struct plot_info;
|
struct plot_info;
|
||||||
|
|
||||||
class ProfileWidget2 : public QGraphicsView {
|
class ProfileWidget2 : public QGraphicsView {
|
||||||
|
@ -66,11 +68,13 @@ private:
|
||||||
struct plot_info *plotInfo;
|
struct plot_info *plotInfo;
|
||||||
DepthAxis *profileYAxis ;
|
DepthAxis *profileYAxis ;
|
||||||
DiveCartesianAxis *gasYAxis;
|
DiveCartesianAxis *gasYAxis;
|
||||||
|
TemperatureAxis *temperatureAxis;
|
||||||
TimeAxis *timeAxis;
|
TimeAxis *timeAxis;
|
||||||
DiveRectItem *depthController;
|
DiveRectItem *depthController;
|
||||||
DiveRectItem *timeController;
|
DiveRectItem *timeController;
|
||||||
DiveProfileItem *diveProfileItem;
|
DiveProfileItem *diveProfileItem;
|
||||||
DiveCartesianPlane *cartesianPlane;
|
DiveCartesianPlane *cartesianPlane;
|
||||||
|
DiveTemperatureItem *temperatureItem;
|
||||||
QList<DiveEventItem*> eventItems;
|
QList<DiveEventItem*> eventItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue