From 254beef5d4c0ead123556ffbc5e37dd2cc81366e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 16 Jan 2014 16:21:23 -0200 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'qt-ui/profile/diveprofileitem.cpp') diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 398d71220..1a96d7009 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -7,43 +7,43 @@ #include #include -DiveProfileItem::DiveProfileItem(): QObject(), QGraphicsPolygonItem(), +AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1) { } -void DiveProfileItem::setHorizontalAxis(DiveCartesianAxis* horizontal) +void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal) { hAxis = horizontal; modelDataChanged(); } -void DiveProfileItem::setHorizontalDataColumn(int column) +void AbstractProfilePolygonItem::setHorizontalDataColumn(int column) { hDataColumn = column; modelDataChanged(); } -void DiveProfileItem::setModel(QAbstractTableModel* model) +void AbstractProfilePolygonItem::setModel(QAbstractTableModel* model) { dataModel = model; modelDataChanged(); } -void DiveProfileItem::setVerticalAxis(DiveCartesianAxis* vertical) +void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis* vertical) { vAxis = vertical; modelDataChanged(); } -void DiveProfileItem::setVerticalDataColumn(int column) +void AbstractProfilePolygonItem::setVerticalDataColumn(int column) { vDataColumn = column; modelDataChanged(); } -void DiveProfileItem::modelDataChanged() +void AbstractProfilePolygonItem::modelDataChanged() { // We don't have enougth data to calculate things, quit. if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1) @@ -62,13 +62,6 @@ void DiveProfileItem::modelDataChanged() poly.append(point); } 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) { @@ -92,3 +85,15 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o 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)); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2