tst_qpieseries.cpp
563 lines
| 18.0 KiB
| text/x-c
|
CppLexer
|
r1105 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
#include <QtTest/QtTest> | ||||
|
r1119 | #include <qchartview.h> | ||
#include <qchart.h> | ||||
|
r1105 | #include <qpieseries.h> | ||
#include <qpieslice.h> | ||||
|
r1180 | #include <qpiemodelmapper.h> | ||
#include <QStandardItemModel> | ||||
|
r1109 | #include <tst_definitions.h> | ||
|
r1105 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
|
r1119 | Q_DECLARE_METATYPE(QPieSlice*) | ||
|
r1291 | Q_DECLARE_METATYPE(QList<QPieSlice*>) | ||
|
r1119 | |||
|
r1105 | class tst_qpieseries : public QObject | ||
{ | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
|
r1255 | void properties(); | ||
|
r1105 | void append(); | ||
|
r1301 | void appendAnimated(); | ||
|
r1105 | void insert(); | ||
|
r1301 | void insertAnimated(); | ||
|
r1105 | void remove(); | ||
|
r1301 | void removeAnimated(); | ||
|
r1119 | void calculatedValues(); | ||
void clickedSignal(); | ||||
void hoverSignal(); | ||||
|
r1323 | void sliceSeries(); | ||
|
r1105 | |||
private: | ||||
|
r1119 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | ||
|
r1105 | |||
private: | ||||
|
r1301 | QChartView *m_view; | ||
QPieSeries *m_series; | ||||
|
r1105 | }; | ||
void tst_qpieseries::initTestCase() | ||||
{ | ||||
|
r1119 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | ||
|
r1291 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); | ||
|
r1105 | } | ||
void tst_qpieseries::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_qpieseries::init() | ||||
{ | ||||
|
r1301 | m_view = new QChartView(); | ||
m_series = new QPieSeries(m_view); | ||||
|
r1105 | } | ||
void tst_qpieseries::cleanup() | ||||
{ | ||||
|
r1301 | delete m_view; | ||
m_view = 0; | ||||
m_series = 0; | ||||
|
r1105 | } | ||
|
r1255 | void tst_qpieseries::properties() | ||
|
r1105 | { | ||
|
r1301 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); | ||
QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); | ||||
QSignalSpy sizeSpy(m_series, SIGNAL(pieSizeChanged())); | ||||
QSignalSpy startAngleSpy(m_series, SIGNAL(pieStartAngleChanged())); | ||||
QSignalSpy endAngleSpy(m_series, SIGNAL(pieEndAngleChanged())); | ||||
QSignalSpy horPosSpy(m_series, SIGNAL(horizontalPositionChanged())); | ||||
QSignalSpy verPosSpy(m_series, SIGNAL(verticalPositionChanged())); | ||||
QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); | ||||
QVERIFY(m_series->count() == 0); | ||||
QVERIFY(m_series->isEmpty()); | ||||
QCOMPARE(m_series->sum(), 0.0); | ||||
QCOMPARE(m_series->horizontalPosition(), 0.5); | ||||
QCOMPARE(m_series->verticalPosition(), 0.5); | ||||
QCOMPARE(m_series->pieSize(), 0.7); | ||||
QCOMPARE(m_series->pieStartAngle(), 0.0); | ||||
QCOMPARE(m_series->pieEndAngle(), 360.0); | ||||
m_series->append("s1", 1); | ||||
m_series->append("s2", 1); | ||||
m_series->append("s3", 1); | ||||
m_series->insert(1, new QPieSlice("s4", 1)); | ||||
m_series->remove(m_series->slices().first()); | ||||
QCOMPARE(m_series->count(), 3); | ||||
QCOMPARE(m_series->sum(), 3.0); | ||||
m_series->clear(); | ||||
QCOMPARE(m_series->count(), 0); | ||||
QCOMPARE(m_series->sum(), 0.0); | ||||
|
r1255 | QCOMPARE(countSpy.count(), 6); | ||
QCOMPARE(sumSpy.count(), 6); | ||||
|
r1301 | m_series->setPieSize(-1.0); | ||
QCOMPARE(m_series->pieSize(), 0.0); | ||||
m_series->setPieSize(0.0); | ||||
m_series->setPieSize(0.9); | ||||
m_series->setPieSize(2.0); | ||||
QCOMPARE(m_series->pieSize(), 1.0); | ||||
|
r1255 | QCOMPARE(sizeSpy.count(), 3); | ||
|
r1301 | m_series->setPieStartAngle(0); | ||
m_series->setPieStartAngle(-180); | ||||
m_series->setPieStartAngle(180); | ||||
|
r1255 | QCOMPARE(startAngleSpy.count(), 2); | ||
|
r1301 | m_series->setPieEndAngle(360); | ||
m_series->setPieEndAngle(-180); | ||||
m_series->setPieEndAngle(180); | ||||
|
r1255 | QCOMPARE(endAngleSpy.count(), 2); | ||
|
r1301 | m_series->setHorizontalPosition(0.5); | ||
m_series->setHorizontalPosition(-1.0); | ||||
QCOMPARE(m_series->horizontalPosition(), 0.0); | ||||
m_series->setHorizontalPosition(1.0); | ||||
m_series->setHorizontalPosition(2.0); | ||||
QCOMPARE(m_series->horizontalPosition(), 1.0); | ||||
|
r1255 | QCOMPARE(horPosSpy.count(), 2); | ||
|
r1301 | m_series->setVerticalPosition(0.5); | ||
m_series->setVerticalPosition(-1.0); | ||||
QCOMPARE(m_series->verticalPosition(), 0.0); | ||||
m_series->setVerticalPosition(1.0); | ||||
m_series->setVerticalPosition(2.0); | ||||
QCOMPARE(m_series->verticalPosition(), 1.0); | ||||
|
r1255 | QCOMPARE(verPosSpy.count(), 2); | ||
|
r1105 | } | ||
void tst_qpieseries::append() | ||||
{ | ||||
|
r1301 | m_view->chart()->addSeries(m_series); | ||
QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | ||||
|
r1105 | |||
// append pointer | ||||
QPieSlice *slice1 = 0; | ||||
|
r1301 | QVERIFY(!m_series->append(slice1)); | ||
|
r1206 | slice1 = new QPieSlice("slice 1", 1); | ||
|
r1301 | QVERIFY(m_series->append(slice1)); | ||
QVERIFY(!m_series->append(slice1)); | ||||
QCOMPARE(m_series->count(), 1); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 1); | ||
QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice1); | ||||
|
r1105 | |||
|
r1324 | // try to append same slice to another series | ||
QPieSeries series2; | ||||
QVERIFY(!series2.append(slice1)); | ||||
|
r1105 | // append pointer list | ||
QList<QPieSlice *> list; | ||||
|
r1301 | QVERIFY(!m_series->append(list)); | ||
|
r1105 | list << (QPieSlice *) 0; | ||
|
r1301 | QVERIFY(!m_series->append(list)); | ||
|
r1105 | list.clear(); | ||
|
r1206 | list << new QPieSlice("slice 2", 2); | ||
list << new QPieSlice("slice 3", 3); | ||||
|
r1301 | QVERIFY(m_series->append(list)); | ||
QVERIFY(!m_series->append(list)); | ||||
QCOMPARE(m_series->count(), 3); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 2); | ||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | ||||
QCOMPARE(added.count(), 2); | ||||
QCOMPARE(added, list); | ||||
|
r1105 | |||
// append operator | ||||
|
r1291 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); | ||
|
r1301 | *m_series << slice4; | ||
*m_series << slice1; // fails because already added | ||||
QCOMPARE(m_series->count(), 4); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 3); | ||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice4); | ||||
|
r1105 | |||
// append with params | ||||
|
r1301 | QPieSlice *slice5 = m_series->append("slice 5", 5); | ||
|
r1105 | QVERIFY(slice5 != 0); | ||
|
r1125 | QCOMPARE(slice5->value(), 5.0); | ||
|
r1105 | QCOMPARE(slice5->label(), QString("slice 5")); | ||
|
r1301 | QCOMPARE(m_series->count(), 5); | ||
|
r1291 | QCOMPARE(addedSpy.count(), 4); | ||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice5); | ||||
|
r1105 | |||
// check slices | ||||
|
r1301 | QVERIFY(!m_series->isEmpty()); | ||
for (int i=0; i<m_series->count(); i++) { | ||||
QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | ||||
QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | ||||
|
r1105 | } | ||
} | ||||
|
r1301 | void tst_qpieseries::appendAnimated() | ||
{ | ||||
m_view->chart()->setAnimationOptions(QChart::AllAnimations); | ||||
} | ||||
|
r1105 | void tst_qpieseries::insert() | ||
{ | ||||
|
r1301 | m_view->chart()->addSeries(m_series); | ||
QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | ||||
|
r1105 | |||
// insert one slice | ||||
QPieSlice *slice1 = 0; | ||||
|
r1301 | QVERIFY(!m_series->insert(0, slice1)); | ||
|
r1206 | slice1 = new QPieSlice("slice 1", 1); | ||
|
r1301 | QVERIFY(!m_series->insert(-1, slice1)); | ||
QVERIFY(!m_series->insert(5, slice1)); | ||||
QVERIFY(m_series->insert(0, slice1)); | ||||
QVERIFY(!m_series->insert(0, slice1)); | ||||
QCOMPARE(m_series->count(), 1); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 1); | ||
QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice1); | ||||
|
r1105 | |||
|
r1324 | // try to insert same slice to another series | ||
QPieSeries series2; | ||||
QVERIFY(!series2.insert(0, slice1)); | ||||
|
r1105 | // add some more slices | ||
|
r1301 | QPieSlice *slice2 = m_series->append("slice 2", 2); | ||
QPieSlice *slice4 = m_series->append("slice 4", 4); | ||||
QCOMPARE(m_series->count(), 3); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 3); | ||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice2); | ||||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice4); | ||||
|
r1105 | |||
// insert between slices | ||||
|
r1291 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); | ||
|
r1301 | m_series->insert(2, slice3); | ||
QCOMPARE(m_series->count(), 4); | ||||
|
r1291 | QCOMPARE(addedSpy.count(), 4); | ||
added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | ||||
QCOMPARE(added.count(), 1); | ||||
QCOMPARE(added.first(), slice3); | ||||
|
r1105 | |||
// check slices | ||||
|
r1301 | for (int i=0; i<m_series->count(); i++) { | ||
QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | ||||
QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | ||||
|
r1105 | } | ||
} | ||||
|
r1301 | void tst_qpieseries::insertAnimated() | ||
{ | ||||
m_view->chart()->setAnimationOptions(QChart::AllAnimations); | ||||
} | ||||
|
r1105 | void tst_qpieseries::remove() | ||
{ | ||||
|
r1301 | m_view->chart()->addSeries(m_series); | ||
QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | ||||
|
r1105 | |||
// add some slices | ||||
|
r1301 | QPieSlice *slice1 = m_series->append("slice 1", 1); | ||
QPieSlice *slice2 = m_series->append("slice 2", 2); | ||||
QPieSlice *slice3 = m_series->append("slice 3", 3); | ||||
|
r1105 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | ||
QSignalSpy spy2(slice2, SIGNAL(destroyed())); | ||||
QSignalSpy spy3(slice3, SIGNAL(destroyed())); | ||||
|
r1301 | QCOMPARE(m_series->count(), 3); | ||
|
r1105 | |||
// null pointer remove | ||||
|
r1301 | QVERIFY(!m_series->remove(0)); | ||
|
r1105 | |||
// remove first | ||||
|
r1301 | QVERIFY(m_series->remove(slice1)); | ||
QVERIFY(!m_series->remove(slice1)); | ||||
QCOMPARE(m_series->count(), 2); | ||||
QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | ||||
|
r1291 | QCOMPARE(removedSpy.count(), 1); | ||
QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | ||||
QCOMPARE(removed.count(), 1); | ||||
QCOMPARE(removed.first(), slice1); | ||||
|
r1105 | |||
// remove all | ||||
|
r1301 | m_series->clear(); | ||
QVERIFY(m_series->isEmpty()); | ||||
QVERIFY(m_series->slices().isEmpty()); | ||||
QCOMPARE(m_series->count(), 0); | ||||
|
r1291 | QCOMPARE(removedSpy.count(), 2); | ||
removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); | ||||
QCOMPARE(removed.count(), 2); | ||||
QCOMPARE(removed.first(), slice2); | ||||
QCOMPARE(removed.last(), slice3); | ||||
|
r1105 | |||
// check that slices were actually destroyed | ||||
|
r1109 | TRY_COMPARE(spy1.count(), 1); | ||
TRY_COMPARE(spy2.count(), 1); | ||||
TRY_COMPARE(spy3.count(), 1); | ||||
|
r1105 | } | ||
|
r1301 | void tst_qpieseries::removeAnimated() | ||
{ | ||||
m_view->chart()->setAnimationOptions(QChart::AllAnimations); | ||||
} | ||||
|
r1105 | void tst_qpieseries::calculatedValues() | ||
{ | ||||
|
r1301 | m_view->chart()->addSeries(m_series); | ||
|
r1119 | |||
|
r1224 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); | ||
|
r1274 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); | ||
QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); | ||||
QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); | ||||
|
r1224 | |||
|
r1119 | // add a slice | ||
|
r1301 | m_series->append(slice1); | ||
bool ok; | ||||
verifyCalculatedData(*m_series, &ok); | ||||
|
r1119 | if (!ok) | ||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 1); | ||
QCOMPARE(startAngleSpy.count(), 0); | ||||
QCOMPARE(angleSpanSpy.count(), 1); | ||||
|
r1105 | |||
|
r1119 | // add some more slices | ||
QList<QPieSlice *> list; | ||||
|
r1206 | list << new QPieSlice("slice 2", 2); | ||
list << new QPieSlice("slice 3", 3); | ||||
|
r1301 | m_series->append(list); | ||
verifyCalculatedData(*m_series, &ok); | ||||
|
r1119 | if (!ok) | ||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 2); | ||
QCOMPARE(startAngleSpy.count(), 0); | ||||
QCOMPARE(angleSpanSpy.count(), 2); | ||||
|
r1119 | |||
// remove a slice | ||||
|
r1301 | m_series->remove(list.first()); // remove slice 2 | ||
verifyCalculatedData(*m_series, &ok); | ||||
|
r1119 | if (!ok) | ||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 3); | ||
QCOMPARE(startAngleSpy.count(), 0); | ||||
QCOMPARE(angleSpanSpy.count(), 3); | ||||
|
r1119 | |||
// insert a slice | ||||
|
r1301 | m_series->insert(0, new QPieSlice("Slice 4", 4)); | ||
verifyCalculatedData(*m_series, &ok); | ||||
|
r1119 | if (!ok) | ||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 4); | ||
QCOMPARE(startAngleSpy.count(), 1); | ||||
QCOMPARE(angleSpanSpy.count(), 4); | ||||
|
r1119 | |||
|
r1207 | // modify pie angles | ||
|
r1301 | m_series->setPieStartAngle(-90); | ||
m_series->setPieEndAngle(90); | ||||
verifyCalculatedData(*m_series, &ok); | ||||
|
r1207 | if (!ok) | ||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 4); | ||
QCOMPARE(startAngleSpy.count(), 3); | ||||
QCOMPARE(angleSpanSpy.count(), 6); | ||||
|
r1207 | |||
|
r1119 | // clear all | ||
|
r1301 | m_series->clear(); | ||
verifyCalculatedData(*m_series, &ok); | ||||
if (!ok) | ||||
return; | ||||
|
r1274 | QCOMPARE(percentageSpy.count(), 4); | ||
QCOMPARE(startAngleSpy.count(), 3); | ||||
QCOMPARE(angleSpanSpy.count(), 6); | ||||
|
r1105 | } | ||
|
r1119 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | ||
|
r1105 | { | ||
|
r1119 | *ok = false; | ||
qreal sum = 0; | ||||
foreach (const QPieSlice *slice, series.slices()) | ||||
sum += slice->value(); | ||||
QCOMPARE(series.sum(), sum); | ||||
qreal startAngle = series.pieStartAngle(); | ||||
qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | ||||
foreach (const QPieSlice *slice, series.slices()) { | ||||
qreal ratio = slice->value() / sum; | ||||
qreal sliceSpan = pieAngleSpan * ratio; | ||||
QCOMPARE(slice->startAngle(), startAngle); | ||||
|
r1274 | QCOMPARE(slice->angleSpan(), sliceSpan); | ||
|
r1119 | QCOMPARE(slice->percentage(), ratio); | ||
startAngle += sliceSpan; | ||||
} | ||||
if (!series.isEmpty()) | ||||
|
r1274 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); | ||
|
r1105 | |||
|
r1119 | *ok = true; | ||
|
r1105 | } | ||
|
r1119 | |||
|
r1105 | void tst_qpieseries::clickedSignal() | ||
{ | ||||
|
r1301 | // add some slices | ||
QPieSlice *s1 = m_series->append("slice 1", 1); | ||||
QPieSlice *s2 = m_series->append("slice 2", 1); | ||||
QPieSlice *s3 = m_series->append("slice 3", 1); | ||||
QPieSlice *s4 = m_series->append("slice 4", 1); | ||||
QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); | ||||
|
r1119 | |||
// add series to the chart | ||||
|
r1301 | m_view->chart()->legend()->setVisible(false); | ||
m_view->resize(200, 200); | ||||
m_view->chart()->addSeries(m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1119 | |||
|
r1245 | // if you devide the chart in four equal tiles these | ||
// are the center points of those tiles | ||||
QPoint p1(90.25, 90); | ||||
QPoint p2(150, 90); | ||||
QPoint p3(90, 150); | ||||
QPoint p4(150, 150); | ||||
QPoint center(120, 120); | ||||
|
r1301 | m_series->setPieSize(1.0); | ||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | ||||
|
r1245 | TRY_COMPARE(clickSpy.count(), 5); // all hit | ||
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4); | ||||
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1); | ||||
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | ||||
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2); | ||||
clickSpy.clear(); | ||||
|
r1301 | m_series->setPieSize(0.5); | ||
m_series->setVerticalPosition(0.25); | ||||
m_series->setHorizontalPosition(0.25); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | ||||
|
r1245 | TRY_COMPARE(clickSpy.count(), 1); | ||
clickSpy.clear(); | ||||
|
r1301 | m_series->setVerticalPosition(0.25); | ||
m_series->setHorizontalPosition(0.75); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | ||||
|
r1245 | TRY_COMPARE(clickSpy.count(), 1); | ||
clickSpy.clear(); | ||||
|
r1301 | m_series->setVerticalPosition(0.75); | ||
m_series->setHorizontalPosition(0.25); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | ||||
|
r1245 | TRY_COMPARE(clickSpy.count(), 1); | ||
clickSpy.clear(); | ||||
|
r1301 | m_series->setVerticalPosition(0.75); | ||
m_series->setHorizontalPosition(0.75); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits | ||||
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | ||||
|
r1245 | TRY_COMPARE(clickSpy.count(), 1); | ||
clickSpy.clear(); | ||||
|
r1105 | } | ||
void tst_qpieseries::hoverSignal() | ||||
{ | ||||
|
r1301 | // add some slices | ||
m_series->setPieSize(1.0); | ||||
QPieSlice *s1 = m_series->append("slice 1", 1); | ||||
m_series->append("slice 2", 2); | ||||
m_series->append("slice 3", 3); | ||||
|
r1119 | |||
// add series to the chart | ||||
|
r1301 | m_view->chart()->legend()->setVisible(false); | ||
m_view->resize(200, 200); | ||||
m_view->chart()->addSeries(m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1119 | |||
// first move to right top corner | ||||
|
r1301 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | ||
|
r1128 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
|
r1119 | |||
// move inside the slice | ||||
// pie rectangle: QRectF(60,60 121x121) | ||||
|
r1301 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); | ||
QTest::mouseMove(m_view->viewport(), QPoint(139, 85)); | ||||
|
r1129 | TRY_COMPARE(hoverSpy.count(), 1); | ||
|
r1119 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | ||
QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | ||||
// move outside the slice | ||||
|
r1301 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | ||
|
r1129 | TRY_COMPARE(hoverSpy.count(), 2); | ||
|
r1119 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | ||
QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | ||||
|
r1105 | } | ||
|
r1323 | void tst_qpieseries::sliceSeries() | ||
{ | ||||
QPieSlice *slice = new QPieSlice(); | ||||
QVERIFY(!slice->series()); | ||||
delete slice; | ||||
slice = new QPieSlice(m_series); | ||||
QVERIFY(!slice->series()); | ||||
m_series->append(slice); | ||||
QCOMPARE(slice->series(), m_series); | ||||
slice = new QPieSlice(); | ||||
m_series->insert(0, slice); | ||||
QCOMPARE(slice->series(), m_series); | ||||
} | ||||
|
r1105 | QTEST_MAIN(tst_qpieseries) | ||
#include "tst_qpieseries.moc" | ||||