summaryrefslogtreecommitdiffstats
path: root/src/datavisualization
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-03-27 14:26:07 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-03-28 07:47:21 +0200
commitfffa26dc1470ad6562e390133314fc149134b8e5 (patch)
tree425aa473c79671bd48111a12e5a94ad62e68bb53 /src/datavisualization
parent1e99ff2c532977d21776f5f363b8171ef147a7d9 (diff)
Improve axis formatter flexibility
Number of grid lines and labels are no longer tied to segment count. Change-Id: I517ebc905f1f70e2e00ae86c05fd0e49e922845d Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization')
-rw-r--r--src/datavisualization/axis/qlogvalue3daxisformatter.cpp143
-rw-r--r--src/datavisualization/axis/qlogvalue3daxisformatter.h8
-rw-r--r--src/datavisualization/axis/qlogvalue3daxisformatter_p.h5
-rw-r--r--src/datavisualization/axis/qvalue3daxis.cpp6
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter.cpp93
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter.h1
-rw-r--r--src/datavisualization/axis/qvalue3daxisformatter_p.h1
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp4
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp6
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp6
10 files changed, 143 insertions, 130 deletions
diff --git a/src/datavisualization/axis/qlogvalue3daxisformatter.cpp b/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
index 17ae4476..e8c2fbad 100644
--- a/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
+++ b/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
@@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* \qmlproperty real LogValueAxis3DFormatter::base
*
* The \a base of the logarithm used to map axis values. If the base is non-zero, the parent axis
- * segment count will be automatically adjusted whenever the axis formatter is recalculated.
+ * segment count will be ignored when the grid line and label positions are calculated.
* If you want the range to be divided into equal segments like normal value axis, set this
* property value to zero.
*
@@ -66,22 +66,24 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
/*!
* \qmlproperty bool LogValueAxis3DFormatter::autoSubGrid
*
- * If this property value is set to \c true, the parent axis sub-segment count is adjusted
- * automatically according to the base property value. The number of subsegments is set to
- * base value minus one, rounded down.
+ * If this property value is set to \c true, the parent axis sub-segment count is ignored
+ * when calculating sub-grid line positions. The sub-grid positions are generated automatically
+ * according to the base property value.
+ * The number of sub-grid lines is set to base value minus one, rounded down.
+ * This property is ignored when base property value is zero.
* Defaults to \c true.
*
* \sa base, ValueAxis3D::subSegmentCount
*/
/*!
- * \qmlproperty bool LogValueAxis3DFormatter::showMaxLabel
+ * \qmlproperty bool LogValueAxis3DFormatter::showEdgeLabels
*
- * When the base property is non-zero, the segments that get automatically generated and depending
- * on the range, the last segment is often smaller than the other segments. In extreme cases this
- * can lead to overlapping labels on the last two grid lines. By setting this property to \c false,
- * you can suppress showing the max label for the axis in cases where the segments do not exactly
- * fit the axis.
+ * When the base property value is non-zero, the whole axis range is often not equally divided into
+ * segments. The first and last segments are often smaller than the other segments.
+ * In extreme cases this can lead to overlapping labels on the first and last two grid lines.
+ * By setting this property to \c false, you can suppress showing the minimum and maximum labels
+ * for the axis in cases where the segments do not exactly fit the axis.
* Defaults to \c true.
*
* \sa base, AbstractAxis3D::labels
@@ -115,7 +117,7 @@ QLogValue3DAxisFormatter::~QLogValue3DAxisFormatter()
* \property QLogValue3DAxisFormatter::base
*
* The \a base of the logarithm used to map axis values. If the base is non-zero, the parent axis
- * segment count will be automatically adjusted whenever the axis formatter is recalculated.
+ * segment count will be ignored when the grid line and label positions are calculated.
* If you want the range to be divided into equal segments like normal value axis, set this
* property value to zero.
*
@@ -146,9 +148,11 @@ qreal QLogValue3DAxisFormatter::base() const
/*!
* \property QLogValue3DAxisFormatter::autoSubGrid
*
- * If this property value is set to \c true, the parent axis sub-segment count is adjusted
- * automatically according to the base property value. The number of subsegments is set to
- * base value minus one, rounded up.
+ * If this property value is set to \c true, the parent axis sub-segment count is ignored
+ * when calculating sub-grid line positions. The sub-grid positions are generated automatically
+ * according to the base property value.
+ * The number of sub-grid lines is set to base value minus one, rounded down.
+ * This property is ignored when base property value is zero.
* Defaults to \c true.
*
* \sa base, QValue3DAxis::subSegmentCount
@@ -168,29 +172,29 @@ bool QLogValue3DAxisFormatter::autoSubGrid() const
}
/*!
- * \property QLogValue3DAxisFormatter::showMaxLabel
+ * \property QLogValue3DAxisFormatter::showEdgeLabels
*
- * When the base property is non-zero, the segments get automatically generated, and depending
- * on the range, the last segment is often smaller than the other segments. In extreme cases this
- * can lead to overlapping labels on the last two grid lines. By setting this property to \c false,
- * you can suppress showing the max label for the axis in cases where the segments do not exactly
- * fit the axis.
+ * When the base property value is non-zero, the whole axis range is often not equally divided into
+ * segments. The first and last segments are often smaller than the other segments.
+ * In extreme cases this can lead to overlapping labels on the first and last two grid lines.
+ * By setting this property to \c false, you can suppress showing the minimum and maximum labels
+ * for the axis in cases where the segments do not exactly fit the axis.
* Defaults to \c true.
*
* \sa base, QAbstract3DAxis::labels
*/
-void QLogValue3DAxisFormatter::setShowMaxLabel(bool enabled)
+void QLogValue3DAxisFormatter::setShowEdgeLabels(bool enabled)
{
- if (dptr()->m_showMaxLabel != enabled) {
- dptr()->m_showMaxLabel = enabled;
+ if (dptr()->m_showEdgeLabels != enabled) {
+ dptr()->m_showEdgeLabels = enabled;
markDirty(true);
- emit showMaxLabelChanged(enabled);
+ emit showEdgeLabelsChanged(enabled);
}
}
-bool QLogValue3DAxisFormatter::showMaxLabel() const
+bool QLogValue3DAxisFormatter::showEdgeLabels() const
{
- return dptrc()->m_showMaxLabel;
+ return dptrc()->m_showEdgeLabels;
}
/*!
@@ -277,13 +281,14 @@ const QLogValue3DAxisFormatterPrivate *QLogValue3DAxisFormatter::dptrc() const
// QLogValue3DAxisFormatterPrivate
QLogValue3DAxisFormatterPrivate::QLogValue3DAxisFormatterPrivate(QLogValue3DAxisFormatter *q)
: QValue3DAxisFormatterPrivate(q),
- m_base(10.0f),
- m_logMin(0.0f),
- m_logMax(0.0f),
- m_logRangeNormalizer(0.0f),
+ m_base(10.0),
+ m_logMin(0.0),
+ m_logMax(0.0),
+ m_logRangeNormalizer(0.0),
m_autoSubGrid(true),
- m_showMaxLabel(true),
- m_evenSegments(true)
+ m_showEdgeLabels(true),
+ m_evenMinSegment(true),
+ m_evenMaxSegment(true)
{
}
@@ -298,57 +303,78 @@ void QLogValue3DAxisFormatterPrivate::recalculate()
m_logMax = qLn(qreal(m_max));
m_logRangeNormalizer = m_logMax - m_logMin;
+ int subGridCount = m_axis->subSegmentCount() - 1;
+ int segmentCount = m_axis->segmentCount();
+ qreal segmentStep;
if (m_base > 0.0) {
// Update parent axis segment counts
qreal logMin = qLn(qreal(m_min)) / qLn(m_base);
qreal logMax = qLn(qreal(m_max)) / qLn(m_base);
qreal logRangeNormalizer = logMax - logMin;
- int segmentCount = qCeil(logRangeNormalizer);
+ qreal minDiff = qCeil(logMin) - logMin;
+ qreal maxDiff = logMax - qFloor(logMax);
+
+ m_evenMinSegment = qFuzzyCompare(0.0, minDiff);
+ m_evenMaxSegment = qFuzzyCompare(0.0, maxDiff);
+
+ segmentCount = qRound(logRangeNormalizer - minDiff - maxDiff);
+
+ if (!m_evenMinSegment)
+ segmentCount++;
+ if (!m_evenMaxSegment)
+ segmentCount++;
+
+ segmentStep = 1.0 / logRangeNormalizer;
- m_axis->setSegmentCount(segmentCount);
if (m_autoSubGrid) {
- int subSegmentCount = qCeil(m_base) - 1;
- if (subSegmentCount < 1)
- subSegmentCount = 1;
- m_axis->setSubSegmentCount(subSegmentCount);
+ subGridCount = qCeil(m_base) - 2; // -2 for subgrid because subsegment count is base - 1
+ if (subGridCount < 0)
+ subGridCount = 0;
}
- resetArrays();
+ m_gridPositions.resize(segmentCount + 1);
+ m_subGridPositions.resize(segmentCount * subGridCount);
+ m_labelPositions.resize(segmentCount + 1);
+ m_labelValues.resize(segmentCount + 1);
// Calculate segment positions
+ int index = 0;
+ if (!m_evenMinSegment) {
+ m_gridPositions[0] = 0.0f;
+ m_labelPositions[0] = 0.0f;
+ m_labelValues[0] = qreal(m_min);
+ index++;
+ }
for (int i = 0; i < segmentCount; i++) {
- float gridValue = float(i) / float(logRangeNormalizer);
- m_gridPositions[i] = gridValue;
- m_labelPositions[i] = gridValue;
- m_labelValues[i] = qPow(m_base, qreal(i) + logMin);
+ float gridValue = float((minDiff + qreal(i)) / qreal(logRangeNormalizer));
+ m_gridPositions[index] = gridValue;
+ m_labelPositions[index] = gridValue;
+ m_labelValues[index] = qPow(m_base, minDiff + qreal(i) + logMin);
+ index++;
}
// Ensure max value doesn't suffer from any rounding errors
m_gridPositions[segmentCount] = 1.0f;
m_labelPositions[segmentCount] = 1.0f;
m_labelValues[segmentCount] = qreal(m_max);
- float lastDiff = 1.0f - m_labelPositions.at(segmentCount - 1);
- float firstDiff = m_labelPositions.at(1) - m_labelPositions.at(0);
- m_evenSegments = qFuzzyCompare(lastDiff, firstDiff);
} else {
// Grid lines and label positions are the same as the parent class, so call parent impl
// first to populate those
QValue3DAxisFormatterPrivate::doRecalculate();
// Label value array needs to be repopulated
- qreal segmentStep = 1.0 / qreal(m_axis->segmentCount());
+ segmentStep = 1.0 / qreal(segmentCount);
for (int i = 0; i < m_labelPositions.size(); i++)
m_labelValues[i] = qExp(segmentStep * qreal(i) * m_logRangeNormalizer + m_logMin);
- m_evenSegments = true;
+ m_evenMaxSegment = true;
+ m_evenMinSegment = true;
}
-
// Subgrid line positions are logarithmically spaced
- int subGridCount = m_axis->subSegmentCount() - 1;
if (subGridCount > 0) {
- float firstSegmentRange = valueAt(m_gridPositions.at(1)) - m_min;
- float subSegmentStep = firstSegmentRange / float(subGridCount + 1);
+ float oneSegmentRange = valueAt(float(segmentStep)) - m_min;
+ float subSegmentStep = oneSegmentRange / float(subGridCount + 1);
// Since the logarithm has the same curvature across whole axis range, we can just calculate
// subgrid positions for the first segment and replicate them to other segments.
@@ -359,12 +385,16 @@ void QLogValue3DAxisFormatterPrivate::recalculate()
actualSubSegmentSteps[i] = currentSubPosition;
}
- int segmentCount = m_axis->segmentCount();
+ float firstPartialSegmentAdjustment = float(segmentStep) - m_gridPositions.at(1);
for (int i = 0; i < segmentCount; i++) {
for (int j = 0; j < subGridCount; j++) {
float position = m_gridPositions.at(i) + actualSubSegmentSteps.at(j);
+ if (!m_evenMinSegment && i == 0)
+ position -= firstPartialSegmentAdjustment;
if (position > 1.0f)
position = 1.0f;
+ if (position < 0.0f)
+ position = 0.0f;
m_subGridPositions[i * subGridCount + j] = position;
}
}
@@ -398,10 +428,13 @@ float QLogValue3DAxisFormatterPrivate::valueAt(float position) const
QString QLogValue3DAxisFormatterPrivate::labelForIndex(int index) const
{
- if (index == m_gridPositions.size() - 1 && !m_evenSegments && !m_showMaxLabel)
+ if (((index == m_gridPositions.size() - 1 && !m_evenMaxSegment)
+ || (index == 0 && !m_evenMinSegment))
+ && !m_showEdgeLabels) {
return QString();
- else
+ } else {
return QValue3DAxisFormatterPrivate::labelForIndex(index);
+ }
}
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/axis/qlogvalue3daxisformatter.h b/src/datavisualization/axis/qlogvalue3daxisformatter.h
index 33466492..e9683821 100644
--- a/src/datavisualization/axis/qlogvalue3daxisformatter.h
+++ b/src/datavisualization/axis/qlogvalue3daxisformatter.h
@@ -31,7 +31,7 @@ class QT_DATAVISUALIZATION_EXPORT QLogValue3DAxisFormatter : public QValue3DAxis
Q_PROPERTY(qreal base READ base WRITE setBase NOTIFY baseChanged)
Q_PROPERTY(bool autoSubGrid READ autoSubGrid WRITE setAutoSubGrid NOTIFY autoSubGridChanged)
- Q_PROPERTY(bool showMaxLabel READ showMaxLabel WRITE setShowMaxLabel NOTIFY showMaxLabelChanged)
+ Q_PROPERTY(bool showEdgeLabels READ showEdgeLabels WRITE setShowEdgeLabels NOTIFY showEdgeLabelsChanged)
protected:
explicit QLogValue3DAxisFormatter(QLogValue3DAxisFormatterPrivate *d, QObject *parent = 0);
@@ -43,13 +43,13 @@ public:
qreal base() const;
void setAutoSubGrid(bool enabled);
bool autoSubGrid() const;
- void setShowMaxLabel(bool enabled);
- bool showMaxLabel() const;
+ void setShowEdgeLabels(bool enabled);
+ bool showEdgeLabels() const;
signals:
void baseChanged(qreal base);
void autoSubGridChanged(bool enabled);
- void showMaxLabelChanged(bool enabled);
+ void showEdgeLabelsChanged(bool enabled);
protected:
virtual bool allowNegatives() const;
diff --git a/src/datavisualization/axis/qlogvalue3daxisformatter_p.h b/src/datavisualization/axis/qlogvalue3daxisformatter_p.h
index 44b5c80c..6638e2c7 100644
--- a/src/datavisualization/axis/qlogvalue3daxisformatter_p.h
+++ b/src/datavisualization/axis/qlogvalue3daxisformatter_p.h
@@ -60,10 +60,11 @@ protected:
qreal m_logMax;
qreal m_logRangeNormalizer;
bool m_autoSubGrid;
- bool m_showMaxLabel;
+ bool m_showEdgeLabels;
private:
- bool m_evenSegments;
+ bool m_evenMinSegment;
+ bool m_evenMaxSegment;
friend class QLogValue3DAxisFormatter;
};
diff --git a/src/datavisualization/axis/qvalue3daxis.cpp b/src/datavisualization/axis/qvalue3daxis.cpp
index b0b8caa6..b957de4d 100644
--- a/src/datavisualization/axis/qvalue3daxis.cpp
+++ b/src/datavisualization/axis/qvalue3daxis.cpp
@@ -266,11 +266,13 @@ void QValue3DAxisPrivate::updateLabels()
m_labelsDirty = false;
+ int labelCount = m_formatter->labelPositions().size();
+
QStringList newLabels;
- newLabels.reserve(m_segmentCount + 1);
+ newLabels.reserve(labelCount);
m_formatter->d_ptr->recalculate();
- for (int i = 0; i <= m_segmentCount; i++)
+ for (int i = 0; i < labelCount; i++)
newLabels.append(m_formatter->labelForIndex(i));
if (m_labels != newLabels)
diff --git a/src/datavisualization/axis/qvalue3daxisformatter.cpp b/src/datavisualization/axis/qvalue3daxisformatter.cpp
index 7c7db398..92940a1b 100644
--- a/src/datavisualization/axis/qvalue3daxisformatter.cpp
+++ b/src/datavisualization/axis/qvalue3daxisformatter.cpp
@@ -59,7 +59,7 @@ QValue3DAxisFormatter::QValue3DAxisFormatter(QValue3DAxisFormatterPrivate *d, QO
}
/*!
- * Constructs a new QValue3DAxisFormatter instance with optional \a parent.
+ * Constructs a new QValue3DAxisFormatter instance with an optional \a parent.
*/
QValue3DAxisFormatter::QValue3DAxisFormatter(QObject *parent) :
QObject(parent),
@@ -104,19 +104,16 @@ QValue3DAxisFormatter *QValue3DAxisFormatter::createNewInstance() const
}
/*!
- * This method populates the label and grid line position arrays and the label value array, as well
- * as calculates any values needed for mapping between value and position. It is allowed to access
- * the parent axis from inside this function.
+ * This method resizes and populates the label and grid line position arrays and the label value
+ * array, as well as calculates any values needed for mapping between value and position.
+ * It is allowed to access the parent axis from inside this function.
*
- * This method must be reimplemented in a subclass. The resetArrays() method must be called
- * in the subclass implementation before the position arrays are recalculated. If the subclass
- * implementation changes any parent axis values, these changes must be done before
- * the resetPositionArrays() call.
+ * This method must be reimplemented in a subclass.
*
- * See gridPositions(), subGridPositions(), and labelPositions() documentation about the arrays
- * that need to be populated.
+ * See gridPositions(), subGridPositions(), labelPositions(), and labelValues() methods for
+ * documentation about the arrays that need to be resized and populated.
*
- * \sa gridPositions(), subGridPositions(), labelPositions(), axis(), resetArrays()
+ * \sa gridPositions(), subGridPositions(), labelPositions(), labelValues(), axis()
*/
void QValue3DAxisFormatter::recalculate()
{
@@ -124,13 +121,14 @@ void QValue3DAxisFormatter::recalculate()
}
/*!
- * The parent axis uses this method to request axis label strings for label \a index.
- * Reimplement this method if default labeling is not sufficient.
+ * The parent axis uses this method to request axis label strings for label \a index,
+ * using the value stored in label values array and QValue3DAxis::labelFormat property.
+ * Reimplement this method in a subclass if the default labeling is not sufficient.
* If an empty string is returned, the label is not shown.
*
* \return A string formatted using axis label formatter.
*
- * \sa stringForValue()
+ * \sa stringForValue(), labelValues(), QValue3DAxis::labelFormat
*/
QString QValue3DAxisFormatter::labelForIndex(int index) const
{
@@ -139,7 +137,8 @@ QString QValue3DAxisFormatter::labelForIndex(int index) const
/*!
* Reimplement this method in a subclass to resolve the formatted string for a given \a value
- * if the default formatting provided by QValue3DAxis::labelFormat property is not sufficient.
+ * if the default formatting rules specified for QValue3DAxis::labelFormat property are not
+ * sufficient.
*
* \return the formatted label string using \a value and \a format.
*
@@ -181,7 +180,8 @@ float QValue3DAxisFormatter::valueAt(float position) const
}
/*!
- * Copies all relevant values from this formatter to the \a copy.
+ * Copies all necessary values for resolving positions, values, and strings with this formatter
+ * from this formatter to the \a copy.
* When reimplementing this method in a subclass, call the the superclass version at some point.
* The renderer uses this method to cache a copy of the the formatter.
*
@@ -193,18 +193,6 @@ void QValue3DAxisFormatter::populateCopy(QValue3DAxisFormatter &copy) const
}
/*!
- * Resets the position arrays based on values read from the parent axis.
- * This must be called in recalculate method before the arrays are accessed in subclasses,
- * but after any changes to the values of the parent axis.
- *
- * \sa gridPositions(), subGridPositions(), labelPositions(), axis(), recalculate()
- */
-void QValue3DAxisFormatter::resetArrays()
-{
- d_ptr->resetArrays();
-}
-
-/*!
* Marks this formatter dirty, prompting the renderer to make a new copy of its cache on the next
* renderer synchronization. This method should be called by a subclass whenever the formatter
* is changed in a way that affects the resolved values. Specify \c true for \a labelsChange
@@ -228,11 +216,11 @@ QValue3DAxis *QValue3DAxisFormatter::axis() const
/*!
* \return a reference to the array of normalized grid line positions.
- * The array size is equal to the segment count of the parent axis plus one.
+ * The default array size is equal to the segment count of the parent axis plus one, but
+ * a subclassed implementation of recalculate method may resize the array differently.
* The values should be between 0.0 (for minimum value) and 1.0 (for maximum value), inclusive.
- * The grid line at the index zero corresponds to the minimum value of the axis.
*
- * \sa QValue3DAxis::segmentCount
+ * \sa QValue3DAxis::segmentCount, recalculate()
*/
QVector<float> &QValue3DAxisFormatter::gridPositions() const
{
@@ -241,11 +229,12 @@ QVector<float> &QValue3DAxisFormatter::gridPositions() const
/*!
* \return a reference to the array of normalized subgrid line positions.
- * The array size is equal to segment count of the parent axis times sub-segment count of the parent
- * axis minus one.
+ * The default array size is equal to segment count of the parent axis times sub-segment count
+ * of the parent axis minus one, but a subclassed implementation of recalculate method may resize
+ * the array differently.
* The values should be between 0.0 (for minimum value) and 1.0 (for maximum value), inclusive.
*
- * \sa QValue3DAxis::segmentCount, QValue3DAxis::subSegmentCount
+ * \sa QValue3DAxis::segmentCount, QValue3DAxis::subSegmentCount, recalculate()
*/
QVector<float> &QValue3DAxisFormatter::subGridPositions() const
{
@@ -254,11 +243,13 @@ QVector<float> &QValue3DAxisFormatter::subGridPositions() const
/*!
* \return a reference to the array of normalized label positions.
- * The array size is equal to the segment count of the parent axis plus one.
+ * The default array size is equal to the segment count of the parent axis plus one, but
+ * a subclassed implementation of recalculate method may resize the array differently.
* The values should be between 0.0 (for minimum value) and 1.0 (for maximum value), inclusive.
- * The label at the index zero corresponds to the minimum value of the axis.
+ * The default behavior is that the label at the index zero corresponds to the minimum value
+ * of the axis.
*
- * \sa QValue3DAxis::segmentCount, QAbstract3DAxis::labels
+ * \sa QValue3DAxis::segmentCount, QAbstract3DAxis::labels, recalculate()
*/
QVector<float> &QValue3DAxisFormatter::labelPositions() const
{
@@ -267,7 +258,7 @@ QVector<float> &QValue3DAxisFormatter::labelPositions() const
/*!
* \return a reference to the array of values used to generate label strings.
- * The array size is equal to the size of the label positions array and
+ * The array size must be equal to the size of the label positions array and
* the indexes correspond to that array as well.
*
* \sa labelPositions()
@@ -310,11 +301,15 @@ void QValue3DAxisFormatterPrivate::recalculate()
void QValue3DAxisFormatterPrivate::doRecalculate()
{
- resetArrays();
-
int segmentCount = m_axis->segmentCount();
int subGridCount = m_axis->subSegmentCount() - 1;
+ m_gridPositions.resize(segmentCount + 1);
+ m_subGridPositions.resize(segmentCount * subGridCount);
+
+ m_labelPositions.resize(segmentCount + 1);
+ m_labelValues.resize(segmentCount + 1);
+
// Use qreals for intermediate calculations for better accuracy on label values
qreal segmentStep = 1.0 / qreal(segmentCount);
qreal subSegmentStep = 0;
@@ -358,6 +353,7 @@ void QValue3DAxisFormatterPrivate::doPopulateCopy(QValue3DAxisFormatterPrivate &
QString QValue3DAxisFormatterPrivate::labelForIndex(int index) const
{
+ Q_ASSERT(index < m_labelValues.size());
return q_ptr->stringForValue(m_labelValues.at(index), m_axis->labelFormat());
}
@@ -397,23 +393,6 @@ void QValue3DAxisFormatterPrivate::setAxis(QValue3DAxis *axis)
m_axis = axis;
}
-void QValue3DAxisFormatterPrivate::resetArrays()
-{
- m_gridPositions.clear();
- m_subGridPositions.clear();
- m_labelPositions.clear();
- m_labelValues.clear();
-
- int segmentCount = m_axis->segmentCount();
- int subGridCount = m_axis->subSegmentCount() - 1;
-
- m_gridPositions.resize(segmentCount + 1);
- m_subGridPositions.resize(segmentCount * subGridCount);
-
- m_labelPositions.resize(segmentCount + 1);
- m_labelValues.resize(segmentCount + 1);
-}
-
void QValue3DAxisFormatterPrivate::markDirty(bool labelsChange)
{
m_needsRecalculate = true;
diff --git a/src/datavisualization/axis/qvalue3daxisformatter.h b/src/datavisualization/axis/qvalue3daxisformatter.h
index 548135c0..970087d3 100644
--- a/src/datavisualization/axis/qvalue3daxisformatter.h
+++ b/src/datavisualization/axis/qvalue3daxisformatter.h
@@ -49,7 +49,6 @@ protected:
virtual float valueAt(float position) const;
virtual void populateCopy(QValue3DAxisFormatter &copy) const;
- void resetArrays();
void markDirty(bool labelsChange = false);
QValue3DAxis *axis() const;
diff --git a/src/datavisualization/axis/qvalue3daxisformatter_p.h b/src/datavisualization/axis/qvalue3daxisformatter_p.h
index b6749fb3..7e661b62 100644
--- a/src/datavisualization/axis/qvalue3daxisformatter_p.h
+++ b/src/datavisualization/axis/qvalue3daxisformatter_p.h
@@ -57,7 +57,6 @@ public:
float valueAt(float position) const;
void setAxis(QValue3DAxis *axis);
- void resetArrays();
void markDirty(bool labelsChange);
public slots:
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 0cad8522..b928e5f0 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -434,7 +434,7 @@ void Bars3DRenderer::drawSlicedScene()
// Draw grid labels
int labelNbr = 0;
- int labelCount = m_axisCacheY.labels().size();
+ int labelCount = m_axisCacheY.labelCount();
QVector3D backLabelRotation(0.0f, 0.0f, 0.0f);
QVector3D labelTrans = QVector3D(scaleFactor + labelMargin, 0.0f, 0.0f);
@@ -1665,7 +1665,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
// Y Labels
int labelNbr = 0;
- int labelCount = m_axisCacheY.labels().size();
+ int labelCount = m_axisCacheY.labelCount();
GLfloat labelMarginXTrans = labelMargin;
GLfloat labelMarginZTrans = labelMargin;
GLfloat labelXTrans = rowScaleFactor;
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index 49595052..909d434f 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -1262,7 +1262,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
// Z Labels
if (m_axisCacheZ.segmentCount() > 0) {
- int labelCount = m_axisCacheZ.labelItems().size();
+ int labelCount = m_axisCacheZ.labelCount();
#ifndef USE_UNIFORM_SCALING
GLfloat labelXTrans = (aspectRatio * m_areaSize.width())
/ m_scaleFactor + labelMargin + m_backgroundMargin;
@@ -1310,7 +1310,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
}
// X Labels
if (m_axisCacheX.segmentCount() > 0) {
- int labelCount = m_axisCacheX.labelItems().size();
+ int labelCount = m_axisCacheX.labelCount();
#ifndef USE_UNIFORM_SCALING
GLfloat labelZTrans = (aspectRatio * m_areaSize.height())
/ m_scaleFactor + labelMargin + m_backgroundMargin;
@@ -1358,7 +1358,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
}
// Y Labels
if (m_axisCacheY.segmentCount() > 0) {
- int labelCount = m_axisCacheY.labelItems().size();
+ int labelCount = m_axisCacheY.labelCount();
int labelNbr = 0;
#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z
GLfloat labelXTrans = (aspectRatio* m_areaSize.width())
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index 86972fdc..0f9a3f10 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -1739,7 +1739,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Z Labels
QVector3D positionZComp(0.0f, 0.0f, 0.0f);
if (m_axisCacheZ.segmentCount() > 0) {
- int labelCount = m_axisCacheZ.labelItems().size();
+ int labelCount = m_axisCacheZ.labelCount();
int labelNbr = 0;
GLfloat labelXTrans = m_scaleXWithBackground + labelMargin;
GLfloat labelYTrans = -backgroundMargin;
@@ -1781,7 +1781,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
}
// X Labels
if (m_axisCacheX.segmentCount() > 0) {
- int labelCount = m_axisCacheX.labelItems().size();
+ int labelCount = m_axisCacheX.labelCount();
int labelNbr = 0;
GLfloat labelZTrans = m_scaleZWithBackground + labelMargin;
@@ -1824,7 +1824,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
}
// Y Labels
if (m_axisCacheY.segmentCount() > 0) {
- int labelCount = m_axisCacheY.labelItems().size();
+ int labelCount = m_axisCacheY.labelCount();
int labelNbr = 0;
GLfloat labelXTrans = m_scaleXWithBackground;