##// END OF EJS Templates
Fixed a bug with QChart::axis getters with no series defined
Tero Ahola -
r2384:c871e96450b9
parent child
Show More
@@ -313,25 +313,10 void QChart::zoom(qreal factor)
313 313 */
314 314 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
315 315 {
316 if(!series && d_ptr->m_dataset->series().size()>0){
317 series = d_ptr->m_dataset->series().first();
318 }
319
320 QList<QAbstractAxis*> axes = series->attachedAxes();
321 QAbstractAxis* bottom=0;
322 QAbstractAxis* top=0;
323
324 foreach(QAbstractAxis* axis, axes){
325
326 if(axis->alignment()==Qt::AlignTop){
327 top=axis;
328 }
329
330 if(axis->alignment()==Qt::AlignBottom){
331 bottom=axis;
332 }
333 }
334 return bottom?bottom:top;
316 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
317 if (axisList.count())
318 return axisList[0];
319 return 0;
335 320 }
336 321
337 322 /*!
@@ -340,31 +325,15 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
340 325 */
341 326 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
342 327 {
343 if(!series && d_ptr->m_dataset->series().size()>0) {
344 series = d_ptr->m_dataset->series().first();
345 }
346
347 QList<QAbstractAxis*> axes = series->attachedAxes();
348
349 QAbstractAxis* left=0;
350 QAbstractAxis* right=0;
351
352 foreach(QAbstractAxis* axis, axes){
353
354 if(axis->alignment()==Qt::AlignLeft){
355 left=axis;
356 }
357
358 if(axis->alignment()==Qt::AlignRight){
359 right=axis;
360 }
361 }
362
363 return left?left:right;
328 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
329 if (axisList.count())
330 return axisList[0];
331 return 0;
364 332 }
365 333
366 334 /*!
367 Returns the axes added for the \a series with \a orientation
335 Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the
336 specified orientation are returned.
368 337 \sa addAxis(), createDefaultAxes()
369 338 */
370 339 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
@@ -377,11 +346,9 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSerie
377 346 result << axis;
378 347 }
379 348 } else {
380 foreach (QAbstractSeries *s, QChart::series()) {
381 foreach (QAbstractAxis *axis, s->attachedAxes()){
382 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
383 result << axis;
384 }
349 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
350 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
351 result << axis;
385 352 }
386 353 }
387 354
@@ -264,6 +264,7 void tst_ChartDataSet::removeAxis()
264 264
265 265 m_dataset->removeAxis(axis);
266 266
267 QCOMPARE(m_dataset->axes().count(),0);
267 268 QCOMPARE(m_dataset->series().count(),0);
268 269 TRY_COMPARE(spy0.count(), 0);
269 270 TRY_COMPARE(spy1.count(), 1);
@@ -431,14 +431,15 void tst_QChart::removeAllSeries()
431 431 m_view->show();
432 432 QTest::qWaitForWindowShown(m_view);
433 433 m_chart->createDefaultAxes();
434 QCOMPARE(m_chart->axes().count(), 2);
434 435 QVERIFY(m_chart->axisY(series0)!=0);
435 436 QVERIFY(m_chart->axisY(series1)!=0);
436 437 QVERIFY(m_chart->axisY(series2)!=0);
437 438
438 439 m_chart->removeAllSeries();
439 QVERIFY(m_chart->axisY(series0)==0);
440 QVERIFY(m_chart->axisY(series1)==0);
441 QVERIFY(m_chart->axisY(series2)==0);
440 QCOMPARE(m_chart->axes().count(), 2);
441 QVERIFY(m_chart->axisX() != 0);
442 QVERIFY(m_chart->axisY() != 0);
442 443 QCOMPARE(deleteSpy1.count(), 1);
443 444 QCOMPARE(deleteSpy2.count(), 1);
444 445 QCOMPARE(deleteSpy3.count(), 1);
@@ -461,6 +462,8 void tst_QChart::removeSeries()
461 462 m_chart->setAxisY(axis,series);
462 463 QCOMPARE(m_chart->axisY(series),axis);
463 464 m_chart->removeSeries(series);
465 QCOMPARE(m_chart->axes().count(), 1);
466 QVERIFY(m_chart->axisY() != 0);
464 467 QVERIFY(m_chart->axisY(series)==0);
465 468 QCOMPARE(deleteSpy.count(), 0);
466 469 }
General Comments 0
You need to be logged in to leave comments. Login now