aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-27 17:09:08 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-28 11:31:18 -0800
commit9f6ebf96a73c9663ea20a8c3e245bc3d9a4f3747 (patch)
treee9f4392b6fc3d54154c5cf546041271285ecda9c /qt-ui/profile
parent7a07665d89aa26d37a8aa8defd20cbe1a569c874 (diff)
downloadsubsurface-9f6ebf96a73c9663ea20a8c3e245bc3d9a4f3747.tar.gz
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 <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/divecartesianaxis.cpp12
-rw-r--r--qt-ui/profile/divetextitem.cpp8
-rw-r--r--qt-ui/profile/profilewidget2.cpp17
3 files changed, 30 insertions, 7 deletions
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp
index 7a58e3bb4..5b7f9cfad 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 163bb64f4..72ba480a9 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 007ca8a68..3a65fdd66 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);