mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Transform the DiveProfileItem to an Abstract Generalization
The DiveProfileItem contained much of the complexity and algorithms for almost all line-based items on the canvas, so I transformed that to a general abstraction and implemented a new DiveProfileItem that uses it. this should reduce a bit of code since the implementation of the PP Graphs, Temperature Cylinder Pressure and maybe a few others will only need to reimplement the paint() and the modelDataChanged() methods. The rest is ready. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1f80788286
commit
254beef5d4
4 changed files with 37 additions and 27 deletions
|
@ -14,19 +14,19 @@ DiveEventItem::DiveEventItem(QObject* parent): DivePixmapItem(parent),
|
||||||
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
|
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis* axis)
|
||||||
{
|
{
|
||||||
hAxis = axis;
|
hAxis = axis;
|
||||||
recalculate();
|
recalculatePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveEventItem::setModel(DivePlotDataModel* model)
|
void DiveEventItem::setModel(DivePlotDataModel* model)
|
||||||
{
|
{
|
||||||
dataModel = model;
|
dataModel = model;
|
||||||
recalculate();
|
recalculatePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
|
void DiveEventItem::setVerticalAxis(DiveCartesianAxis* axis)
|
||||||
{
|
{
|
||||||
vAxis = axis;
|
vAxis = axis;
|
||||||
recalculate();
|
recalculatePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveEventItem::setEvent(struct event* ev)
|
void DiveEventItem::setEvent(struct event* ev)
|
||||||
|
@ -34,7 +34,7 @@ void DiveEventItem::setEvent(struct event* ev)
|
||||||
internalEvent = ev;
|
internalEvent = ev;
|
||||||
setupPixmap();
|
setupPixmap();
|
||||||
setupToolTipString();
|
setupToolTipString();
|
||||||
recalculate();
|
recalculatePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveEventItem::setupPixmap()
|
void DiveEventItem::setupPixmap()
|
||||||
|
@ -102,12 +102,11 @@ void DiveEventItem::eventVisibilityChanged(const QString& eventName, bool visibl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveEventItem::recalculate()
|
void DiveEventItem::recalculatePos()
|
||||||
{
|
{
|
||||||
if (!vAxis || !hAxis || !internalEvent || !dataModel){
|
if (!vAxis || !hAxis || !internalEvent || !dataModel){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "Calculating.";
|
|
||||||
QModelIndexList result = dataModel->match(dataModel->index(0,DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds );
|
QModelIndexList result = dataModel->match(dataModel->index(0,DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds );
|
||||||
if(result.isEmpty()){
|
if(result.isEmpty()){
|
||||||
hide();
|
hide();
|
||||||
|
|
|
@ -16,9 +16,9 @@ public:
|
||||||
void setVerticalAxis(DiveCartesianAxis *axis);
|
void setVerticalAxis(DiveCartesianAxis *axis);
|
||||||
void setHorizontalAxis(DiveCartesianAxis *axis);
|
void setHorizontalAxis(DiveCartesianAxis *axis);
|
||||||
void setModel(DivePlotDataModel *model);
|
void setModel(DivePlotDataModel *model);
|
||||||
void recalculate();
|
|
||||||
private:
|
private:
|
||||||
void setupToolTipString();
|
void setupToolTipString();
|
||||||
|
void recalculatePos();
|
||||||
void setupPixmap();
|
void setupPixmap();
|
||||||
DiveCartesianAxis *vAxis;
|
DiveCartesianAxis *vAxis;
|
||||||
DiveCartesianAxis *hAxis;
|
DiveCartesianAxis *hAxis;
|
||||||
|
|
|
@ -7,43 +7,43 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QLinearGradient>
|
#include <QLinearGradient>
|
||||||
|
|
||||||
DiveProfileItem::DiveProfileItem(): 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)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
|
void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
|
||||||
{
|
{
|
||||||
hAxis = horizontal;
|
hAxis = horizontal;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::setHorizontalDataColumn(int column)
|
void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
|
||||||
{
|
{
|
||||||
hDataColumn = column;
|
hDataColumn = column;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::setModel(QAbstractTableModel* model)
|
void AbstractProfilePolygonItem::setModel(QAbstractTableModel* model)
|
||||||
{
|
{
|
||||||
dataModel = model;
|
dataModel = model;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::setVerticalAxis(DiveCartesianAxis* vertical)
|
void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis* vertical)
|
||||||
{
|
{
|
||||||
vAxis = vertical;
|
vAxis = vertical;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::setVerticalDataColumn(int column)
|
void AbstractProfilePolygonItem::setVerticalDataColumn(int column)
|
||||||
{
|
{
|
||||||
vDataColumn = column;
|
vDataColumn = column;
|
||||||
modelDataChanged();
|
modelDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::modelDataChanged()
|
void AbstractProfilePolygonItem::modelDataChanged()
|
||||||
{
|
{
|
||||||
// We don't have enougth data to calculate things, quit.
|
// We don't have enougth data to calculate things, quit.
|
||||||
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
|
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
|
||||||
|
@ -62,13 +62,6 @@ void DiveProfileItem::modelDataChanged()
|
||||||
poly.append(point);
|
poly.append(point);
|
||||||
}
|
}
|
||||||
setPolygon(poly);
|
setPolygon(poly);
|
||||||
|
|
||||||
// This is the blueish gradient that the Depth Profile should have.
|
|
||||||
// It's a simple QLinearGradient with 2 stops, starting from top to bottom.
|
|
||||||
QLinearGradient pat(0, poly.boundingRect().top(), 0, poly.boundingRect().bottom());
|
|
||||||
pat.setColorAt(1, getColor(DEPTH_BOTTOM));
|
|
||||||
pat.setColorAt(0, getColor(DEPTH_TOP));
|
|
||||||
setBrush(QBrush(pat));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
|
||||||
|
@ -92,3 +85,15 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
|
||||||
painter->drawLine(polygon()[i-1],polygon()[i]);
|
painter->drawLine(polygon()[i-1],polygon()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveProfileItem::modelDataChanged(){
|
||||||
|
AbstractProfilePolygonItem::modelDataChanged();
|
||||||
|
if(polygon().isEmpty())
|
||||||
|
return;
|
||||||
|
// This is the blueish gradient that the Depth Profile should have.
|
||||||
|
// It's a simple QLinearGradient with 2 stops, starting from top to bottom.
|
||||||
|
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
|
||||||
|
pat.setColorAt(1, getColor(DEPTH_BOTTOM));
|
||||||
|
pat.setColorAt(0, getColor(DEPTH_TOP));
|
||||||
|
setBrush(QBrush(pat));
|
||||||
|
}
|
|
@ -21,22 +21,22 @@
|
||||||
class DiveCartesianAxis;
|
class DiveCartesianAxis;
|
||||||
class QAbstractTableModel;
|
class QAbstractTableModel;
|
||||||
|
|
||||||
class DiveProfileItem : public QObject, public QGraphicsPolygonItem{
|
class AbstractProfilePolygonItem : public QObject, public QGraphicsPolygonItem{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
Q_PROPERTY(QPointF pos WRITE setPos READ pos)
|
||||||
Q_PROPERTY(qreal x WRITE setX READ x)
|
Q_PROPERTY(qreal x WRITE setX READ x)
|
||||||
Q_PROPERTY(qreal y WRITE setY READ y)
|
Q_PROPERTY(qreal y WRITE setY READ y)
|
||||||
public:
|
public:
|
||||||
DiveProfileItem();
|
AbstractProfilePolygonItem();
|
||||||
void setVerticalAxis(DiveCartesianAxis *vertical);
|
void setVerticalAxis(DiveCartesianAxis *vertical);
|
||||||
void setHorizontalAxis(DiveCartesianAxis *horizontal);
|
void setHorizontalAxis(DiveCartesianAxis *horizontal);
|
||||||
void setModel(QAbstractTableModel *model);
|
void setModel(QAbstractTableModel *model);
|
||||||
void setHorizontalDataColumn(int column);
|
void setHorizontalDataColumn(int column);
|
||||||
void setVerticalDataColumn(int column);
|
void setVerticalDataColumn(int column);
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
|
||||||
public slots:
|
public slots:
|
||||||
void modelDataChanged();
|
virtual void modelDataChanged();
|
||||||
private:
|
protected:
|
||||||
DiveCartesianAxis *hAxis;
|
DiveCartesianAxis *hAxis;
|
||||||
DiveCartesianAxis *vAxis;
|
DiveCartesianAxis *vAxis;
|
||||||
QAbstractTableModel *dataModel;
|
QAbstractTableModel *dataModel;
|
||||||
|
@ -44,5 +44,11 @@ private:
|
||||||
int vDataColumn;
|
int vDataColumn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DiveProfileItem : public AbstractProfilePolygonItem{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||||
|
virtual void modelDataChanged();
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue