##// END OF EJS Templates
QValueAxis: added posibility to specify label format
Marek Rosa -
r1854:4846aebc38ef
parent child
Show More
@@ -25,6 +25,7
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include <qmath.h>
26 #include <qmath.h>
27 #include <QDateTime>
27 #include <QDateTime>
28 #include <QValueAxis>
28
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
@@ -360,9 +361,13 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int
360
361
361 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
362 int n = qMax(int(-qFloor(log10((max-min)/(ticks-1)))),0);
362 n++;
363 n++;
364
365 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
366 QByteArray array = axis->labelFormat().toAscii();
363 for (int i=0; i< ticks; i++) {
367 for (int i=0; i< ticks; i++) {
364 qreal value = min + (i * (max - min)/ (ticks-1));
368 qreal value = min + (i * (max - min)/ (ticks-1));
365 labels << QString::number(value,'f',n);
369 QString label;
370 labels << label.sprintf(array, value);;
366 }
371 }
367 }
372 }
368
373
@@ -248,6 +248,18 bool QValueAxis::niceNumbersEnabled() const
248 return d->m_niceNumbers;
248 return d->m_niceNumbers;
249 }
249 }
250
250
251 void QValueAxis::setLabelFormat(const QString &format)
252 {
253 Q_D(QValueAxis);
254 d->m_format = format;
255 }
256
257 QString QValueAxis::labelFormat() const
258 {
259 Q_D(const QValueAxis);
260 return d->m_format;
261 }
262
251 /*!
263 /*!
252 Returns the type of the axis
264 Returns the type of the axis
253 */
265 */
@@ -263,7 +275,8 QValueAxisPrivate::QValueAxisPrivate(QValueAxis* q):
263 m_min(0),
275 m_min(0),
264 m_max(0),
276 m_max(0),
265 m_tickCount(5),
277 m_tickCount(5),
266 m_niceNumbers(false)
278 m_niceNumbers(false),
279 m_format("%g")
267 {
280 {
268
281
269 }
282 }
@@ -56,6 +56,9 public:
56 void setTickCount(int count);
56 void setTickCount(int count);
57 int tickCount() const;
57 int tickCount() const;
58
58
59 void setLabelFormat(const QString &format);
60 QString labelFormat() const;
61
59 void setNiceNumbersEnabled(bool enable = true);
62 void setNiceNumbersEnabled(bool enable = true);
60 bool niceNumbersEnabled() const;
63 bool niceNumbersEnabled() const;
61
64
@@ -64,6 +64,7 private:
64 qreal m_max;
64 qreal m_max;
65 int m_tickCount;
65 int m_tickCount;
66 bool m_niceNumbers;
66 bool m_niceNumbers;
67 QString m_format;
67 Q_DECLARE_PUBLIC(QValueAxis)
68 Q_DECLARE_PUBLIC(QValueAxis)
68 };
69 };
69
70
General Comments 0
You need to be logged in to leave comments. Login now