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