From ba812351a1577163a1c9794b667f2b4e3acb9373 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 12 Mar 2014 09:25:51 +0200 Subject: Introduce value axis formatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently only used for label formatting. Also some other preparatory changes for logaxis. Task-number: QTRD-2787 Note: Not to be merged until 1.0 is released Change-Id: I2d7ab70b9c51677d0edd5b0226fb779c9e346286 Reviewed-by: Tomi Korpipää --- src/datavisualization/axis/qabstract3daxis.cpp | 85 +++++++++++++++++--------- 1 file changed, 57 insertions(+), 28 deletions(-) (limited to 'src/datavisualization/axis/qabstract3daxis.cpp') diff --git a/src/datavisualization/axis/qabstract3daxis.cpp b/src/datavisualization/axis/qabstract3daxis.cpp index 3a327caa..e01f980c 100644 --- a/src/datavisualization/axis/qabstract3daxis.cpp +++ b/src/datavisualization/axis/qabstract3daxis.cpp @@ -265,9 +265,7 @@ QAbstract3DAxisPrivate::QAbstract3DAxisPrivate(QAbstract3DAxis *q, QAbstract3DAx m_isDefaultAxis(false), m_min(0.0f), m_max(10.0f), - m_autoAdjust(true), - m_onlyPositiveValues(false), - m_allowMinMaxSame(false) + m_autoAdjust(true) { } @@ -293,14 +291,25 @@ void QAbstract3DAxisPrivate::updateLabels() void QAbstract3DAxisPrivate::setRange(float min, float max) { bool adjusted = false; - if (m_onlyPositiveValues) { - if (min < 0.0f) { - min = 0.0f; - adjusted = true; - } - if (max < 0.0f) { - max = 0.0f; - adjusted = true; + if (!allowNegatives()) { + if (allowZero()) { + if (min < 0.0f) { + min = 0.0f; + adjusted = true; + } + if (max < 0.0f) { + max = 0.0f; + adjusted = true; + } + } else { + if (min <= 0.0f) { + min = 1.0f; + adjusted = true; + } + if (max <= 0.0f) { + max = 1.0f; + adjusted = true; + } } } // If min >= max, we adjust ranges so that @@ -312,8 +321,8 @@ void QAbstract3DAxisPrivate::setRange(float min, float max) m_min = min; minDirty = true; } - if (m_max != max || min > max || (!m_allowMinMaxSame && min == max)) { - if (min > max || (!m_allowMinMaxSame && min == max)) { + if (m_max != max || min > max || (!allowMinMaxSame() && min == max)) { + if (min > max || (!allowMinMaxSame() && min == max)) { m_max = min + 1.0f; adjusted = true; } else { @@ -339,17 +348,25 @@ void QAbstract3DAxisPrivate::setRange(float min, float max) void QAbstract3DAxisPrivate::setMin(float min) { - if (m_onlyPositiveValues) { - if (min < 0.0f) { - min = 0.0f; - qWarning() << "Warning: Tried to set negative minimum for an axis that only supports" - " positive values:" << min; + if (!allowNegatives()) { + if (allowZero()) { + if (min < 0.0f) { + min = 0.0f; + qWarning() << "Warning: Tried to set negative minimum for an axis that only" + "supports positive values and zero:" << min; + } + } else { + if (min <= 0.0f) { + min = 1.0f; + qWarning() << "Warning: Tried to set negative or zero minimum for an axis that only" + "supports positive values:" << min; + } } } if (m_min != min) { bool maxChanged = false; - if (min > m_max || (!m_allowMinMaxSame && min == m_max)) { + if (min > m_max || (!allowMinMaxSame() && min == m_max)) { float oldMax = m_max; m_max = min + 1.0f; qWarning() << "Warning: Tried to set minimum to equal or larger than maximum for" @@ -368,22 +385,34 @@ void QAbstract3DAxisPrivate::setMin(float min) void QAbstract3DAxisPrivate::setMax(float max) { - if (m_onlyPositiveValues) { - if (max < 0.0f) { - max = 0.0f; - qWarning() << "Warning: Tried to set negative maximum for an axis that only supports" - " positive values:" << max; + if (!allowNegatives()) { + if (allowZero()) { + if (max < 0.0f) { + max = 0.0f; + qWarning() << "Warning: Tried to set negative maximum for an axis that only" + "supports positive values and zero:" << max; + } + } else { + if (max <= 0.0f) { + max = 1.0f; + qWarning() << "Warning: Tried to set negative or zero maximum for an axis that only" + "supports positive values:" << max; + } } } if (m_max != max) { bool minChanged = false; - if (m_min > max || (!m_allowMinMaxSame && m_min == max)) { + if (m_min > max || (!allowMinMaxSame() && m_min == max)) { float oldMin = m_min; m_min = max - 1.0f; - if (m_onlyPositiveValues && m_min < 0.0f) { - m_min = 0.0f; - if (!m_allowMinMaxSame && max == 0.0f) { + if (!allowNegatives() && m_min < 0.0f) { + if (allowZero()) { + m_min = 0.0f; + } else { + m_min = max / 2.0f; // Need some positive value smaller than max + } + if (!allowMinMaxSame() && max == 0.0f) { m_min = oldMin; qWarning() << "Unable to set maximum value to zero."; return; -- cgit v1.2.3