and now, with ceilings. <3
( works with the preferences too. )



On Tue, Jan 21, 2014 at 3:42 PM, Tomaz Canabrava <tcanabr...@kde.org> wrote:

> last forgotten one.
>
>
> On Tue, Jan 21, 2014 at 3:37 PM, Tomaz Canabrava <tcanabr...@kde.org>wrote:
>
>>
>>
>
From 831690f9e4c051a2414c2b1217db6f9cc8b1f420 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 21 Jan 2014 17:07:22 -0200
Subject: [PATCH 09/11] Show Dive Computer Ceiling

This patch adds Dive Computer Calculated Ceiling on the Profile Graph
as a 'hole' on it. There's an item that paints it in red - maybe
we shouldn't offer an option here and show that only in red?

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/diveprofileitem.cpp | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index 9ea1023..f2d9b4e 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -6,6 +6,7 @@
 #include "profile.h"
 #include "dive.h"
 #include "profilegraphics.h"
+#include "preferences.h"
 
 #include <QPen>
 #include <QPainter>
@@ -17,7 +18,7 @@
 AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
 	hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
 {
-
+	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(modelDataChanged()));
 }
 
 void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
@@ -79,7 +80,7 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
 
 	// This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here,
 	// after all we need to plot the correct velocities colors later.
-	setPen(QPen());
+	setPen(Qt::NoPen);
 	QGraphicsPolygonItem::paint(painter, option, widget);
 
 	// Here we actually paint the boundaries of the Polygon using the colors that the model provides.
@@ -100,6 +101,24 @@ void DiveProfileItem::modelDataChanged(){
 	AbstractProfilePolygonItem::modelDataChanged();
 	if(polygon().isEmpty())
 		return;
+
+	/* Show any ceiling we may have encountered */
+	if (prefs.profile_dc_ceiling) {
+		QPolygonF p = polygon();
+		plot_data *entry = dataModel->data() + dataModel->rowCount()-1;
+		for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) {
+			if (!entry->in_deco) {
+				/* not in deco implies this is a safety stop, no ceiling */
+				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
+			} else if (entry->stopdepth < entry->depth) {
+				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
+			} else {
+				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
+			}
+		}
+		setPolygon(p);
+	}
+
 		// 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());
-- 
1.8.5.3

From 489ccd9a087a2f8898e80cb2f3ee2fecaef87a34 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 21 Jan 2014 17:11:04 -0200
Subject: [PATCH 10/11] If we draw ceilings in red, do not dug a hole on the
 profile.

This is a try to speed paints up a bit. since we will draw the
red ceiling on top of the profile, I don't see a reason to
dug a hole on it, creating an more complex shape to be passed
to the painter. easyer shapes are easyer to draw. ( I think )

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/diveprofileitem.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index f2d9b4e..d9fa78a 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -103,7 +103,7 @@ void DiveProfileItem::modelDataChanged(){
 		return;
 
 	/* Show any ceiling we may have encountered */
-	if (prefs.profile_dc_ceiling) {
+	if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
 		QPolygonF p = polygon();
 		plot_data *entry = dataModel->data() + dataModel->rowCount()-1;
 		for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) {
-- 
1.8.5.3

From 83b3bd35f15540a6aed65fa3e47c4853992e906a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 21 Jan 2014 17:34:36 -0200
Subject: [PATCH 11/11] Draw the Ceiling in red if preferences are marked for
 that.

This code actually use the preferences for something. it will
show and hide the calculated ceiling in red if the prefrerences
are changed for that. One bad thing that I did in this commit
( so it was easy to try ) is that a preference change will
redraw the whole graph - not optimized. I'll make this better
in a later commit so that only the affected items will be redrawn

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/diveprofileitem.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 qt-ui/profile/diveprofileitem.h   |  7 +++++++
 qt-ui/profile/profilewidget2.cpp  | 15 ++++++++++++++-
 qt-ui/profile/profilewidget2.h    |  3 +++
 4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index d9fa78a..d7bfe50 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -364,3 +364,42 @@ void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsI
 {
 	QGraphicsPolygonItem::paint(painter, option, widget);
 }
+
+
+void DiveReportedCeiling::modelDataChanged()
+{
+	if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
+		return;
+
+	if (prefs.profile_dc_ceiling){
+		setVisible(prefs.profile_red_ceiling);
+	}else{
+		setVisible(false);
+	}
+
+	QPolygonF p;
+	p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0)));
+	plot_data *entry = dataModel->data();
+	for (int i = 0, count = dataModel->rowCount(); i < count; i++, entry++) {
+		if (entry->in_deco && entry->stopdepth) {
+			if (entry->stopdepth < entry->depth) {
+				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->stopdepth)));
+			} else {
+				p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(entry->depth)));
+			}
+		} else {
+			p.append(QPointF(hAxis->posAtValue(entry->sec), vAxis->posAtValue(0)));
+		}
+	}
+	setPolygon(p);
+	QLinearGradient pat(0, p.boundingRect().top(), 0, p.boundingRect().bottom());
+	pat.setColorAt(0, getColor(CEILING_SHALLOW));
+	pat.setColorAt(1, getColor(CEILING_DEEP));
+	setPen(QPen(QBrush(Qt::NoBrush),0));
+	setBrush(pat);
+}
+
+void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+{
+	QGraphicsPolygonItem::paint(painter, option, widget);
+}
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index 9e71eac..9b737db 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -87,4 +87,11 @@ public:
 	virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
 };
 
+class DiveReportedCeiling : public AbstractProfilePolygonItem{
+	Q_OBJECT
+
+public:
+	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 790b2c6..b5610e4 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -39,7 +39,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
 	cartesianPlane(new DiveCartesianPlane()),
 	meanDepth(new DiveLineItem()),
 	diveComputerText(new DiveTextItem()),
-	diveCeiling(NULL)
+	diveCeiling(NULL),
+	reportedCeiling(NULL)
 {
 	setScene(new QGraphicsScene());
 	scene()->setSceneRect(0, 0, 100, 100);
@@ -386,6 +387,18 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 		allTissues.append(tissueItem);
 		scene()->addItem(tissueItem);
 	}
+
+	if(reportedCeiling){
+		scene()->removeItem(reportedCeiling);
+		delete reportedCeiling;
+	}
+	reportedCeiling = new DiveReportedCeiling();
+	reportedCeiling->setHorizontalAxis(timeAxis);
+	reportedCeiling->setVerticalAxis(profileYAxis);
+	reportedCeiling->setModel(dataModel);
+	reportedCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING);
+	reportedCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME);
+	scene()->addItem(reportedCeiling);
 	emit startProfileState();
 }
 
diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h
index 37508ce..3699419 100644
--- a/qt-ui/profile/profilewidget2.h
+++ b/qt-ui/profile/profilewidget2.h
@@ -16,6 +16,7 @@
 #include "graphicsview-common.h"
 #include "divelineitem.h"
 
+class DiveReportedCeiling;
 class DiveTextItem;
 class TemperatureAxis;
 class DiveEventItem;
@@ -33,6 +34,7 @@ struct DiveTemperatureItem;
 struct plot_info;
 struct DiveGasPressureItem;
 struct DiveCalculatedCeiling;
+struct DiveReportedCeiling;
 
 class ProfileWidget2 : public QGraphicsView {
 	Q_OBJECT
@@ -86,6 +88,7 @@ private:
 	DiveTextItem *diveComputerText;
 	DiveCalculatedCeiling *diveCeiling;
 	QList<DiveCalculatedCeiling*> allTissues;
+	DiveReportedCeiling *reportedCeiling;
 };
 
 #endif
-- 
1.8.5.3

From cb151a65185ffc0335578723ae7eef72c0f2452b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 21 Jan 2014 18:16:19 -0200
Subject: [PATCH 12/12] Better use of the Preferences Changed Signal.

When the preferences changed signal is fired, the items that
can change it's visual based on the preferences now have to
reimplement the preferencesChanged method, so they know
if they need to be reploted on screen. I already implemented
that for two of the items ( ProfileDepth and Ceiling )
but others might need that too.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 qt-ui/profile/diveprofileitem.cpp | 35 +++++++++++++++++++++++++++--------
 qt-ui/profile/diveprofileitem.h   |  6 ++++++
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index d7bfe50..1640fd6 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -18,7 +18,11 @@
 AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(),
 	hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
 {
-	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(modelDataChanged()));
+	connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(preferencesChanged()));
+}
+
+void AbstractProfilePolygonItem::preferencesChanged()
+{
 }
 
 void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis* horizontal)
@@ -36,6 +40,7 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
 void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
 {
 	dataModel = model;
+	connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged()));
 	modelDataChanged();
 }
 
@@ -102,6 +107,9 @@ void DiveProfileItem::modelDataChanged(){
 	if(polygon().isEmpty())
 		return;
 
+	show_reported_ceiling = prefs.profile_dc_ceiling;
+	reported_ceiling_in_red = prefs.profile_red_ceiling;
+
 	/* Show any ceiling we may have encountered */
 	if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
 		QPolygonF p = polygon();
@@ -124,7 +132,7 @@ void DiveProfileItem::modelDataChanged(){
 	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));
+	setBrush(QBrush(pat));AbstractProfilePolygonItem::preferencesChanged();
 
 	int last = -1;
 	for (int i = 0, count  = dataModel->rowCount(); i < count; i++) {
@@ -148,6 +156,14 @@ void DiveProfileItem::modelDataChanged(){
 	}
 }
 
+void DiveProfileItem::preferencesChanged()
+{
+	//TODO: Only modelDataChanged() here if we need to rebuild the graph ( for instance,
+	// if the prefs.profile_dc_ceiling are enabled, but prefs.profile_red_ceiling is disabled
+	// and only if it changed something. let's not waste cpu cycles repoloting something we don't need to.
+		modelDataChanged();
+}
+
 void DiveProfileItem::plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color)
 {
 	int decimals;
@@ -371,12 +387,6 @@ void DiveReportedCeiling::modelDataChanged()
 	if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
 		return;
 
-	if (prefs.profile_dc_ceiling){
-		setVisible(prefs.profile_red_ceiling);
-	}else{
-		setVisible(false);
-	}
-
 	QPolygonF p;
 	p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0)));
 	plot_data *entry = dataModel->data();
@@ -399,6 +409,15 @@ void DiveReportedCeiling::modelDataChanged()
 	setBrush(pat);
 }
 
+void DiveReportedCeiling::preferencesChanged()
+{
+	if (prefs.profile_dc_ceiling){
+		setVisible(prefs.profile_red_ceiling);
+	}else{
+		setVisible(false);
+	}
+}
+
 void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
 {
 	QGraphicsPolygonItem::paint(painter, option, widget);
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index 9b737db..57b1e70 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -38,6 +38,7 @@ public:
 	void setVerticalDataColumn(int column);
 	virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
 public slots:
+	virtual void preferencesChanged();
 	virtual void modelDataChanged();
 protected:
 	DiveCartesianAxis *hAxis;
@@ -54,7 +55,11 @@ class DiveProfileItem : public AbstractProfilePolygonItem{
 public:
 	virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
 	virtual void modelDataChanged();
+	virtual void preferencesChanged();
 	void plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color);
+private:
+	unsigned int show_reported_ceiling;
+	unsigned int reported_ceiling_in_red;
 };
 
 class DiveTemperatureItem : public AbstractProfilePolygonItem{
@@ -93,5 +98,6 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem{
 public:
 	virtual void modelDataChanged();
 	virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+	virtual void preferencesChanged();
 };
 #endif
\ No newline at end of file
-- 
1.8.5.3

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to