crash fix.

On Thu, Feb 27, 2014 at 3:41 PM, Tomaz Canabrava <tcanabr...@kde.org> wrote:

>
>
From de171a82209f36c626546e0d68d15b541ab87318 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Thu, 27 Feb 2014 16:42:00 -0300
Subject: [PATCH 8/8] Make the ruler Work. (caution, fonts are BIIIG )

This patch makes the ruler work again, the problem is that
the fonts are *terribly* big, I'll fix that on the next commit.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/profile/profilewidget2.cpp | 18 +++++++++++++-----
 qt-ui/profile/ruleritem.cpp      |  3 +++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index ca176a3..ee9e80b 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -172,6 +172,8 @@ void ProfileWidget2::setupItemOnScene()
 	diveComputerText->setAlignment(Qt::AlignRight | Qt::AlignTop);
 	diveComputerText->setBrush(getColor(TIME_TEXT));
 
+	rulerItem->setAxis(timeAxis, profileYAxis);
+
 	setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
 	setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1);
 	for(int i = 0; i < 16; i++){
@@ -364,7 +366,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 		heartBeatAxis->setVisible(false);
 	}
 	timeAxis->setMaximum(maxtime);
-
+	rulerItem->setPlotInfo(pInfo);
 	int i, incr;
 	static int increments[8] = { 10, 20, 30, 60, 5*60, 10*60, 15*60, 30*60 };
 	/* Time markers: at most every 10 seconds, but no more than 12 markers.
@@ -434,10 +436,16 @@ void ProfileWidget2::settingsChanged()
 		plotDives(QList<dive*>() << getDiveById(diveId));
 	}
 
-	bool rulerVisible = s.value("rulergraph", false).toBool();
-	rulerItem->setVisible(rulerVisible);
-	rulerItem->destNode()->setVisible(rulerVisible );
-	rulerItem->sourceNode()->setVisible(rulerVisible );
+	if(currentState == PROFILE){
+		bool rulerVisible = s.value("rulergraph", false).toBool();
+		rulerItem->setVisible(rulerVisible);
+		rulerItem->destNode()->setVisible(rulerVisible );
+		rulerItem->sourceNode()->setVisible(rulerVisible );
+	}else{
+		rulerItem->setVisible(false);
+		rulerItem->destNode()->setVisible(false);
+		rulerItem->sourceNode()->setVisible(false);
+	}
 }
 
 void ProfileWidget2::resizeEvent(QResizeEvent* event)
diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
index 3c53d3d..d2b06f7 100644
--- a/qt-ui/profile/ruleritem.cpp
+++ b/qt-ui/profile/ruleritem.cpp
@@ -3,6 +3,7 @@
 #include <QFontMetrics>
 #include <QPainter>
 #include <QGraphicsScene>
+#include <QDebug>
 
 #include <stdint.h>
 
@@ -171,6 +172,8 @@ void RulerItem2::setPlotInfo(plot_info info)
 {
 	pInfo = info;
 	recalculate();
+	dest->recalculate();
+	source->recalculate();
 }
 
 void RulerItem2::setAxis(DiveCartesianAxis* time, DiveCartesianAxis* depth)
-- 
1.9.0

From 568f0db59e319995a7bc252005b09c4f7df9b18b Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tomaz.canabr...@intel.com>
Date: Thu, 27 Feb 2014 16:28:19 -0300
Subject: [PATCH 7/8] Remove the pInfo as pointer, make it a real structure
 instead.

This removes the invalid pointer stage crash.

Signed-off-by: Tomaz Canabrava <tomaz.canabr...@intel.com>
---
 qt-ui/profile/ruleritem.cpp | 34 +++++++++++++++++++++-------------
 qt-ui/profile/ruleritem.h   | 10 ++++++----
 2 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp
index e3362ad..3c53d3d 100644
--- a/qt-ui/profile/ruleritem.cpp
+++ b/qt-ui/profile/ruleritem.cpp
@@ -9,7 +9,7 @@
 #include "profile.h"
 #include "display.h"
 
-RulerNodeItem2::RulerNodeItem2() : entry(NULL) , ruler(NULL)
+RulerNodeItem2::RulerNodeItem2(struct plot_info& info) : pInfo(info), entry(NULL) , ruler(NULL)
 {
 	setRect(QRect(QPoint(-8,8),QPoint(8,-8)));
 	setBrush(QColor(0xff, 0, 0, 127));
@@ -26,17 +26,17 @@ void RulerNodeItem2::setRuler(RulerItem2 *r)
 
 void RulerNodeItem2::recalculate()
 {
-	struct plot_data *data = pInfo->entry+(pInfo->nr-1);
+	struct plot_data *data = pInfo.entry+(pInfo.nr-1);
 	uint16_t count = 0;
 	if (x() < 0) {
 		setPos(0, y());
 	} else if (x() > timeAxis->posAtValue(data->sec)) {
 		setPos(timeAxis->posAtValue(data->sec), y());
 	} else {
-		data = pInfo->entry;
+		data = pInfo.entry;
 		count=0;
-		while (timeAxis->posAtValue(data->sec) < x() && count < pInfo->nr) {
-			data = pInfo->entry+count;
+		while (timeAxis->posAtValue(data->sec) < x() && count < pInfo.nr) {
+			data = pInfo.entry+count;
 			count++;
 		}
 		setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth));
@@ -58,13 +58,12 @@ QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &v
 }
 
 RulerItem2::RulerItem2():
-	pInfo(NULL),
 	timeAxis(NULL),
 	depthAxis(NULL),
-	source(new RulerNodeItem2()),
-	dest(new RulerNodeItem2())
+	source(new RulerNodeItem2(pInfo)),
+	dest(new RulerNodeItem2(pInfo))
 {
-
+	memset(&pInfo, 0, sizeof(pInfo));
 	source->setRuler(this);
 	dest->setRuler(this);
 }
@@ -76,7 +75,7 @@ void RulerItem2::recalculate()
 	QFont font;
 	QFontMetrics fm(font);
 
-	if (timeAxis == NULL || depthAxis == NULL || pInfo == NULL)
+	if (timeAxis == NULL || depthAxis == NULL || pInfo.nr == 0)
 		return;
 
 	prepareGeometryChange();
@@ -168,10 +167,19 @@ QPainterPath RulerItem2::shape() const
 	return path;
 }
 
-void RulerItem2::setPlotInfo(plot_info* info)
+void RulerItem2::setPlotInfo(plot_info info)
 {
 	pInfo = info;
-	dest->pInfo = info;
-	source->pInfo = info;
+	recalculate();
+}
+
+void RulerItem2::setAxis(DiveCartesianAxis* time, DiveCartesianAxis* depth)
+{
+	timeAxis = time;
+	depthAxis = depth;
+	dest->depthAxis = depth;
+	dest->timeAxis = time;
+	source->depthAxis = depth;
+	source->timeAxis = time;
 	recalculate();
 }
diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h
index 29b7923..714bf09 100644
--- a/qt-ui/profile/ruleritem.h
+++ b/qt-ui/profile/ruleritem.h
@@ -5,6 +5,7 @@
 #include <QGraphicsEllipseItem>
 #include <QGraphicsObject>
 #include "divecartesianaxis.h"
+#include "display.h"
 
 struct plot_data;
 class RulerItem2;
@@ -14,7 +15,7 @@ class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem
 	Q_OBJECT
 	friend class RulerItem2;
 public:
-	explicit RulerNodeItem2();
+	explicit RulerNodeItem2(struct plot_info& info);
 	void setRuler(RulerItem2 *r);
 	void recalculate();
 
@@ -22,7 +23,7 @@ protected:
 	QVariant itemChange(GraphicsItemChange change, const QVariant & value );
 
 private:
-	struct plot_info *pInfo;
+	struct plot_info &pInfo;
 	struct plot_data *entry;
 	RulerItem2* ruler;
 	DiveCartesianAxis *timeAxis;
@@ -36,15 +37,16 @@ public:
 	explicit RulerItem2();
 	void recalculate();
 
-	void setPlotInfo(struct plot_info *pInfo);
+	void setPlotInfo(struct plot_info pInfo);
 	RulerNodeItem2* sourceNode() const;
 	RulerNodeItem2* destNode() const;
 	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
 	QRectF boundingRect() const;
 	QPainterPath shape() const;
+	void setAxis(DiveCartesianAxis *time, DiveCartesianAxis *depth);
 
 private:
-	struct plot_info *pInfo;
+	struct plot_info pInfo;
 	QPointF startPoint, endPoint;
 	RulerNodeItem2 *source, *dest;
 	QString text;
-- 
1.9.0

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

Reply via email to