##// END OF EJS Templates
Fix niceNumbers legacy support
Michal Klocek -
r2314:9f65e31516fe
parent child
Show More
@@ -24,6 +24,7
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QLineSeries>
26 #include <QLineSeries>
27 #include <QValueAxis>
27
28
28 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
29
30
@@ -46,6 +47,7 int main(int argc, char *argv[])
46 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->legend()->hide();
48 chart->legend()->hide();
48 chart->createDefaultAxes();
49 chart->createDefaultAxes();
50 qobject_cast<QValueAxis*>(chart->axisX())->setNiceNumbersEnabled(true);
49
51
50 ChartView *chartView = new ChartView(chart);
52 ChartView *chartView = new ChartView(chart);
51 chartView->setRenderHint(QPainter::Antialiasing);
53 chartView->setRenderHint(QPainter::Antialiasing);
@@ -57,5 +59,7 int main(int argc, char *argv[])
57 window.grabGesture(Qt::PinchGesture);
59 window.grabGesture(Qt::PinchGesture);
58 window.show();
60 window.show();
59
61
62 qobject_cast<QValueAxis*>(chart->axisX())->setMax(600);
63
60 return a.exec();
64 return a.exec();
61 }
65 }
@@ -240,14 +240,25 int QValueAxis::tickCount() const
240
240
241 void QValueAxis::setNiceNumbersEnabled(bool enable)
241 void QValueAxis::setNiceNumbersEnabled(bool enable)
242 {
242 {
243 Q_UNUSED(enable);
243 Q_D(QValueAxis);
244 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
244 qWarning()<<"This function is depreciated, it can lead to unexpected behaviour.Use applyNiceNumbers(). ";
245 if(enable) {
246 QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
247 QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
248 applyNiceNumbers();
249 }
250 else {
251 QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers()));
252 QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers()));
253 }
254 d->m_niceNumbersEnabled=true;
245 }
255 }
246
256
247 bool QValueAxis::niceNumbersEnabled() const
257 bool QValueAxis::niceNumbersEnabled() const
248 {
258 {
259 Q_D(const QValueAxis);
249 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
260 qWarning()<<"This function is depreciated.Use applyNiceNumbers().";
250 return false;
261 return d->m_niceNumbersEnabled;
251 }
262 }
252
263
253 void QValueAxis::setLabelFormat(const QString &format)
264 void QValueAxis::setLabelFormat(const QString &format)
@@ -273,12 +284,15 QAbstractAxis::AxisType QValueAxis::type() const
273 void QValueAxis::applyNiceNumbers()
284 void QValueAxis::applyNiceNumbers()
274 {
285 {
275 Q_D(QValueAxis);
286 Q_D(QValueAxis);
287 if(d->m_applying) return;
276 qreal min = d->m_min;
288 qreal min = d->m_min;
277 qreal max = d->m_max;
289 qreal max = d->m_max;
278 int ticks = d->m_tickCount;
290 int ticks = d->m_tickCount;
279 AbstractDomain::looseNiceNumbers(min,max,ticks);
291 AbstractDomain::looseNiceNumbers(min,max,ticks);
292 d->m_applying=true;
280 d->setRange(min,max);
293 d->setRange(min,max);
281 setTickCount(ticks);
294 setTickCount(ticks);
295 d->m_applying=false;
282 }
296 }
283
297
284 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
298 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -288,7 +302,9 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
288 m_min(0),
302 m_min(0),
289 m_max(0),
303 m_max(0),
290 m_tickCount(5),
304 m_tickCount(5),
291 m_format(QString::null)
305 m_format(QString::null),
306 m_applying(false),
307 m_niceNumbersEnabled(false)
292 {
308 {
293
309
294 }
310 }
@@ -309,7 +325,6 void QValueAxisPrivate::setMin(const QVariant &min)
309
325
310 void QValueAxisPrivate::setMax(const QVariant &max)
326 void QValueAxisPrivate::setMax(const QVariant &max)
311 {
327 {
312
313 Q_Q(QValueAxis);
328 Q_Q(QValueAxis);
314 bool ok;
329 bool ok;
315 qreal value = max.toReal(&ok);
330 qreal value = max.toReal(&ok);
@@ -349,8 +364,8 void QValueAxisPrivate::setRange(qreal min, qreal max)
349 }
364 }
350
365
351 if (changed) {
366 if (changed) {
352 emit q->rangeChanged(min, max);
353 emit rangeChanged(min,max);
367 emit rangeChanged(min,max);
368 emit q->rangeChanged(min, max);
354 }
369 }
355 }
370 }
356
371
@@ -60,6 +60,8 private:
60 qreal m_max;
60 qreal m_max;
61 int m_tickCount;
61 int m_tickCount;
62 QString m_format;
62 QString m_format;
63 bool m_applying;
64 bool m_niceNumbersEnabled; //TODO: this depreciated
63 Q_DECLARE_PUBLIC(QValueAxis)
65 Q_DECLARE_PUBLIC(QValueAxis)
64 };
66 };
65
67
General Comments 0
You need to be logged in to leave comments. Login now