summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/engine/bars3drenderer.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-19 13:32:31 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-09-22 09:35:46 +0300
commit36bc54f5720bddb9899e64d665117ac1e1b5bc94 (patch)
tree71d903cacc81c7a664ce0e05a167791234f7cf62 /src/datavisualization/engine/bars3drenderer.cpp
parent105e85170d35f7086dc96d1853298fcf8d680e06 (diff)
Allow setting the floor level on bar graphs.
Task-number: QTRD-3313 Change-Id: Ie0f8e36af8698081a6937c360043773da895b6e6 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/engine/bars3drenderer.cpp')
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index e9cd9d43..9f3c2e2a 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -77,7 +77,9 @@ Bars3DRenderer::Bars3DRenderer(Bars3DController *controller)
m_haveGradientSeries(false),
m_zeroPosition(0.0f),
m_xScaleFactor(1.0f),
- m_zScaleFactor(1.0f)
+ m_zScaleFactor(1.0f),
+ m_floorLevel(0.0f),
+ m_actualFloorLevel(0.0f)
{
m_axisCacheY.setScale(2.0f);
m_axisCacheY.setTranslate(-1.0f);
@@ -209,7 +211,7 @@ void Bars3DRenderer::updateData()
calculateSceneScalingFactors();
- m_zeroPosition = m_axisCacheY.formatter()->positionAt(0.0f);
+ m_zeroPosition = m_axisCacheY.formatter()->positionAt(m_actualFloorLevel);
foreach (SeriesRenderCache *baseCache, m_renderCacheList) {
BarSeriesRenderCache *cache = static_cast<BarSeriesRenderCache *>(baseCache);
@@ -2457,14 +2459,8 @@ void Bars3DRenderer::updateAxisRange(QAbstract3DAxis::AxisOrientation orientatio
{
Abstract3DRenderer::updateAxisRange(orientation, min, max);
- if (orientation == QAbstract3DAxis::AxisOrientationY) {
- // Check if we have negative values
- if (min < 0)
- m_hasNegativeValues = true;
- else if (min >= 0)
- m_hasNegativeValues = false;
+ if (orientation == QAbstract3DAxis::AxisOrientationY)
calculateHeightAdjustment();
- }
}
void Bars3DRenderer::updateAxisReversed(QAbstract3DAxis::AxisOrientation orientation, bool enable)
@@ -2602,24 +2598,33 @@ void Bars3DRenderer::calculateSceneScalingFactors()
void Bars3DRenderer::calculateHeightAdjustment()
{
+ float min = m_axisCacheY.min();
+ float max = m_axisCacheY.max();
GLfloat newAdjustment = 1.0f;
- GLfloat maxAbs = qFabs(m_axisCacheY.max());
-
- if (m_axisCacheY.max() < 0.0f) {
- m_heightNormalizer = GLfloat(qFabs(m_axisCacheY.min()) - qFabs(m_axisCacheY.max()));
- maxAbs = qFabs(m_axisCacheY.max()) - qFabs(m_axisCacheY.min());
+ m_actualFloorLevel = qBound(min, m_floorLevel, max);
+ GLfloat maxAbs = qFabs(max - m_actualFloorLevel);
+
+ // Check if we have negative values
+ if (min < m_actualFloorLevel)
+ m_hasNegativeValues = true;
+ else if (min >= m_actualFloorLevel)
+ m_hasNegativeValues = false;
+
+ if (max < m_actualFloorLevel) {
+ m_heightNormalizer = GLfloat(qFabs(min) - qFabs(max));
+ maxAbs = qFabs(max) - qFabs(min);
} else {
- m_heightNormalizer = GLfloat(m_axisCacheY.max() - m_axisCacheY.min());
+ m_heightNormalizer = GLfloat(max - min);
}
// Height fractions are used in gradient calculations and are therefore doubled
// Note that if max or min is exactly zero, we still consider it outside the range
- if (m_axisCacheY.max() <= 0.0f || m_axisCacheY.min() >= 0.0f) {
+ if (max <= m_actualFloorLevel || min >= m_actualFloorLevel) {
m_noZeroInRange = true;
m_gradientFraction = 2.0f;
} else {
m_noZeroInRange = false;
- GLfloat minAbs = qFabs(m_axisCacheY.min());
+ GLfloat minAbs = qFabs(min - m_actualFloorLevel);
m_gradientFraction = qMax(minAbs, maxAbs) / m_heightNormalizer * 2.0f;
}
@@ -2835,4 +2840,12 @@ void Bars3DRenderer::updateAspectRatio(float ratio)
Q_UNUSED(ratio)
}
+void Bars3DRenderer::updateFloorLevel(float level)
+{
+ foreach (SeriesRenderCache *cache, m_renderCacheList)
+ cache->setDataDirty(true);
+ m_floorLevel = level;
+ calculateHeightAdjustment();
+}
+
QT_END_NAMESPACE_DATAVISUALIZATION