From 972eab3e58666e307384637b042a6da074c4006a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 27 Jan 2014 16:21:13 -0200
Subject: [PATCH 3/5] Do not create label if string is empty.

Do not create a text label if the returned string
is empty. also, fixed a potential crash after
not creating a label and adding it to the list
of created labels.t

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divecartesianaxis.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index f655700..d968077 100644
--- a/qt-ui/profile/divecartesianaxis.cpp
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -121,12 +121,15 @@ void DiveCartesianAxis::updateTicks()
 		DiveTextItem *label = NULL;
 
 		if (showText){
+			QString text = textForValue(currValue);
+			if(text.isEmpty())
+				continue; // Do not create or do anything with an empty string.
 			label = new DiveTextItem(this);
 			label->setText(textForValue(currValue));
 			label->setBrush(QBrush(textColor));
 			label->setBrush(colorForValue(currValue));
+			labels.push_back(label);
 		}
-		labels.push_back(label);
 		if (orientation == RightToLeft || orientation == LeftToRight) {
 			if(showText){
 				label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
-- 
1.8.5.3

From 41ff24aa2317e960e4e5c3d559ebe3a2ea2fc5f8 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 27 Jan 2014 17:09:08 -0200
Subject: [PATCH 4/5] Use the same behavior as the old Time Markers

This commit adds the same behavior for the old time
markers on the new ones.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divecartesianaxis.cpp | 12 ++++++++----
 qt-ui/profile/divetextitem.cpp      |  8 +++++---
 qt-ui/profile/profilewidget2.cpp    | 17 +++++++++++++++++
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index d968077..30d83e5 100644
--- a/qt-ui/profile/divecartesianaxis.cpp
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -71,6 +71,7 @@ void DiveCartesianAxis::updateTicks()
 	}
 	if (steps < 1)
 		return;
+
 	if (!labels.isEmpty() && labels.size() > steps) {
 		while (labels.size() > steps) {
 				DiveTextItem *removedText = labels.takeLast();
@@ -102,12 +103,14 @@ void DiveCartesianAxis::updateTicks()
 		} else {
 			childPos = begin - i * stepSize;
 		}
+
 		labels[i]->setText(textForValue(currValue));
 		if ( orientation == LeftToRight || orientation == RightToLeft) {
 			labels[i]->animateMoveTo(childPos, m.y1() + tickSize);
 		} else {
 			labels[i]->animateMoveTo(m.x1() - tickSize, childPos);
 		}
+		labels[i]->setVisible( i % 2 );
 	}
 
 	// Add's the rest of the needed Ticks / Text.
@@ -121,9 +124,6 @@ void DiveCartesianAxis::updateTicks()
 		DiveTextItem *label = NULL;
 
 		if (showText){
-			QString text = textForValue(currValue);
-			if(text.isEmpty())
-				continue; // Do not create or do anything with an empty string.
 			label = new DiveTextItem(this);
 			label->setText(textForValue(currValue));
 			label->setBrush(QBrush(textColor));
@@ -143,6 +143,7 @@ void DiveCartesianAxis::updateTicks()
 				label->animateMoveTo(m.x1() - tickSize, childPos);
 			}
 		}
+		label->setVisible( i % 2 );
 	}
 }
 
@@ -283,7 +284,10 @@ QColor TimeAxis::colorForValue(double value)
 
 QString TimeAxis::textForValue(double value)
 {
-	return QString::number(value / 60);
+	int nr = value / 60;
+	if (maximum() < 600 )
+		return QString("%1:%2").arg(nr).arg( (int)value%60, 2, 10, QChar('0'));
+	return  QString::number(nr);
 }
 
 QString TemperatureAxis::textForValue(double value)
diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp
index 163bb64..72ba480 100644
--- a/qt-ui/profile/divetextitem.cpp
+++ b/qt-ui/profile/divetextitem.cpp
@@ -42,11 +42,13 @@ const QString& DiveTextItem::text()
 
 void DiveTextItem::updateText()
 {
-	if(internalText.isEmpty())
-		return;
-
 	delete textItem;
+	textItem = NULL;
 	delete textBackgroundItem;
+	textBackgroundItem = NULL;
+	if(internalText.isEmpty()){
+		return;
+	}
 
 	QFont fnt(qApp->font());
 	QFontMetrics fm(fnt);
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 007ca8a..3a65fdd 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -387,6 +387,23 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
 	temperatureAxis->setMinimum(pInfo.mintemp);
 	temperatureAxis->setMaximum(pInfo.maxtemp);
 	timeAxis->setMaximum(maxtime);
+
+	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.
+	 * We start out with 10 seconds and increment up to 30 minutes,
+	 * depending on the dive time.
+	 * This allows for 6h dives - enough (I hope) for even the craziest
+	 * divers - but just in case, for those 8h depth-record-breaking dives,
+	 * we double the interval if this still doesn't get us to 12 or fewer
+	 * time markers */
+	i = 0;
+	while (i < 7 && maxtime / increments[i] > 12)
+		i++;
+	incr = increments[i];
+	while (maxtime / incr > 12)
+		incr *= 2;
+	timeAxis->setTickInterval(incr);
 	timeAxis->updateTicks();
 	cylinderPressureAxis->setMinimum(pInfo.minpressure);
 	cylinderPressureAxis->setMaximum(pInfo.maxpressure);
-- 
1.8.5.3

From 49bb2f70cda2cc49cf0e3e99c9a4c0667d7bd438 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Mon, 27 Jan 2014 17:18:35 -0200
Subject: [PATCH 5/5] Fixed an issue added on the last commit

The last commit made the time and all other axis
to behave like the time axis. not cool

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 qt-ui/profile/divecartesianaxis.cpp | 12 ++++++++++--
 qt-ui/profile/divecartesianaxis.h   |  5 ++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index 30d83e5..0b122fd 100644
--- a/qt-ui/profile/divecartesianaxis.cpp
+++ b/qt-ui/profile/divecartesianaxis.cpp
@@ -110,7 +110,6 @@ void DiveCartesianAxis::updateTicks()
 		} else {
 			labels[i]->animateMoveTo(m.x1() - tickSize, childPos);
 		}
-		labels[i]->setVisible( i % 2 );
 	}
 
 	// Add's the rest of the needed Ticks / Text.
@@ -143,7 +142,6 @@ void DiveCartesianAxis::updateTicks()
 				label->animateMoveTo(m.x1() - tickSize, childPos);
 			}
 		}
-		label->setVisible( i % 2 );
 	}
 }
 
@@ -290,6 +288,16 @@ QString TimeAxis::textForValue(double value)
 	return  QString::number(nr);
 }
 
+void TimeAxis::updateTicks()
+{
+	DiveCartesianAxis::updateTicks();
+	if (maximum() > 600){
+		for(int i = 0; i < labels.count(); i++){
+			labels[i]->setVisible(i % 2);
+		}
+	}
+}
+
 QString TemperatureAxis::textForValue(double value)
 {
 	return QString::number(mkelvin_to_C( (int) value));
diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h
index e4366ea..3f18fe8 100644
--- a/qt-ui/profile/divecartesianaxis.h
+++ b/qt-ui/profile/divecartesianaxis.h
@@ -36,7 +36,7 @@ public:
 	void animateChangeLine(const QLineF& newLine);
 	int unitSystem;
 public slots:
-	void updateTicks();
+	virtual void updateTicks();
 signals:
 	void sizeChanged();
 	void maxChanged();
@@ -66,6 +66,9 @@ private slots:
 };
 
 class TimeAxis : public DiveCartesianAxis {
+	Q_OBJECT
+public:
+	virtual void updateTicks();
 protected:
 	QString textForValue(double value);
 	QColor colorForValue(double value);
-- 
1.8.5.3

_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to