summaryrefslogtreecommitdiffstats
path: root/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-03-28 14:51:26 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-04-01 08:28:57 +0300
commitfe3c9ec0a9fb734e83eb70bc725c303a9d36cd6d (patch)
tree4996d94f8a7e4498fa8431c9dcc65526a99889bb /src/datavisualization/axis/qlogvalue3daxisformatter.cpp
parent25f48fc046bbce83abeeef0a6081de9f5efcd6d7 (diff)
Axis formatter customization example
Also refactored the formatter api somewhat: - Removed virtual from allowNegatives and allowZero and added a setter function for those. This will make it cleaner if we need to add similar properties to the axis formatter in the future, as no new virtual methods can be added without breaking BC. - Changed the labelValues array to labelStrings list, as it makes more sense to directly format the strings in recalculate. Change-Id: I3ea005afa984bb756845ca356b999762e0807415 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/axis/qlogvalue3daxisformatter.cpp')
-rw-r--r--src/datavisualization/axis/qlogvalue3daxisformatter.cpp70
1 files changed, 31 insertions, 39 deletions
diff --git a/src/datavisualization/axis/qlogvalue3daxisformatter.cpp b/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
index e8c2fbad..128d784d 100644
--- a/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
+++ b/src/datavisualization/axis/qlogvalue3daxisformatter.cpp
@@ -96,6 +96,8 @@ QLogValue3DAxisFormatter::QLogValue3DAxisFormatter(QLogValue3DAxisFormatterPriva
QObject *parent) :
QValue3DAxisFormatter(d, parent)
{
+ setAllowNegatives(false);
+ setAllowZero(false);
}
/*!
@@ -104,6 +106,8 @@ QLogValue3DAxisFormatter::QLogValue3DAxisFormatter(QLogValue3DAxisFormatterPriva
QLogValue3DAxisFormatter::QLogValue3DAxisFormatter(QObject *parent) :
QValue3DAxisFormatter(new QLogValue3DAxisFormatterPrivate(this), parent)
{
+ setAllowNegatives(false);
+ setAllowZero(false);
}
/*!
@@ -200,22 +204,6 @@ bool QLogValue3DAxisFormatter::showEdgeLabels() const
/*!
* \internal
*/
-bool QLogValue3DAxisFormatter::allowNegatives() const
-{
- return false;
-}
-
-/*!
- * \internal
- */
-bool QLogValue3DAxisFormatter::allowZero() const
-{
- return false;
-}
-
-/*!
- * \internal
- */
QValue3DAxisFormatter *QLogValue3DAxisFormatter::createNewInstance() const
{
return new QLogValue3DAxisFormatter();
@@ -257,14 +245,6 @@ void QLogValue3DAxisFormatter::populateCopy(QValue3DAxisFormatter &copy) const
/*!
* \internal
*/
-QString QLogValue3DAxisFormatter::labelForIndex(int index) const
-{
- return dptrc()->labelForIndex(index);
-}
-
-/*!
- * \internal
- */
QLogValue3DAxisFormatterPrivate *QLogValue3DAxisFormatter::dptr()
{
return static_cast<QLogValue3DAxisFormatterPrivate *>(d_ptr.data());
@@ -305,6 +285,7 @@ void QLogValue3DAxisFormatterPrivate::recalculate()
int subGridCount = m_axis->subSegmentCount() - 1;
int segmentCount = m_axis->segmentCount();
+ QString labelFormat = m_axis->labelFormat();
qreal segmentStep;
if (m_base > 0.0) {
// Update parent axis segment counts
@@ -336,36 +317,53 @@ void QLogValue3DAxisFormatterPrivate::recalculate()
m_gridPositions.resize(segmentCount + 1);
m_subGridPositions.resize(segmentCount * subGridCount);
m_labelPositions.resize(segmentCount + 1);
- m_labelValues.resize(segmentCount + 1);
+ m_labelStrings.clear();
+ m_labelStrings.reserve(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);
+ if (m_showEdgeLabels)
+ m_labelStrings << qptr()->stringForValue(qreal(m_min), labelFormat);
+ else
+ m_labelStrings << QString();
index++;
}
for (int i = 0; i < segmentCount; i++) {
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);
+ m_labelStrings << qptr()->stringForValue(qPow(m_base, minDiff + qreal(i) + logMin),
+ labelFormat);
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);
+ QString finalLabel;
+ if (m_showEdgeLabels || m_evenMaxSegment)
+ finalLabel = qptr()->stringForValue(qreal(m_max), labelFormat);
+
+ if (m_labelStrings.size() > segmentCount)
+ m_labelStrings.replace(segmentCount, finalLabel);
+ else
+ m_labelStrings << finalLabel;
} 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
+ // Label string list needs to be repopulated
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_labelStrings << qptr()->stringForValue(qreal(m_min), labelFormat);
+ for (int i = 1; i < m_labelPositions.size() - 1; i++)
+ m_labelStrings[i] = qptr()->stringForValue(qExp(segmentStep * qreal(i)
+ * m_logRangeNormalizer + m_logMin),
+ labelFormat);
+ m_labelStrings << qptr()->stringForValue(qreal(m_max), labelFormat);
m_evenMaxSegment = true;
m_evenMinSegment = true;
@@ -426,15 +424,9 @@ float QLogValue3DAxisFormatterPrivate::valueAt(float position) const
return float(qExp(logValue));
}
-QString QLogValue3DAxisFormatterPrivate::labelForIndex(int index) const
+QLogValue3DAxisFormatter *QLogValue3DAxisFormatterPrivate::qptr()
{
- if (((index == m_gridPositions.size() - 1 && !m_evenMaxSegment)
- || (index == 0 && !m_evenMinSegment))
- && !m_showEdgeLabels) {
- return QString();
- } else {
- return QValue3DAxisFormatterPrivate::labelForIndex(index);
- }
+ return static_cast<QLogValue3DAxisFormatter *>(q_ptr);
}
QT_END_NAMESPACE_DATAVISUALIZATION