summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis/qabstract3daxis.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-03-12 09:25:51 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-03-24 09:34:40 +0200
commitba812351a1577163a1c9794b667f2b4e3acb9373 (patch)
tree85b64bb39b8e48641ef27eda504251b2d33586a7 /src/datavisualization/axis/qabstract3daxis.cpp
parentb6621d5651e2f8c8ed4ab4a99d15a36823ac897c (diff)
Introduce value axis formatter
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ää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis/qabstract3daxis.cpp')
-rw-r--r--src/datavisualization/axis/qabstract3daxis.cpp85
1 files changed, 57 insertions, 28 deletions
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;