diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 33d0da2..e9b6847 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -29,7 +29,7 @@ Bar::Bar(QBarSet *barset, QString category, QGraphicsItem *parent) : QGraphicsRe m_category(category), m_barset(barset) { - setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); + setAcceptedMouseButtons(Qt::LeftButton /*| Qt::RightButton*/); setAcceptHoverEvents(true); } diff --git a/test/auto/qbarseries/tst_qbarseries.cpp b/test/auto/qbarseries/tst_qbarseries.cpp index d4cab5a..a378ec9 100644 --- a/test/auto/qbarseries/tst_qbarseries.cpp +++ b/test/auto/qbarseries/tst_qbarseries.cpp @@ -21,9 +21,13 @@ #include #include #include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE +Q_DECLARE_METATYPE(QBarSet*) + class tst_QBarSeries : public QObject { Q_OBJECT @@ -59,6 +63,8 @@ private slots: void categories(); void setLabelsVisible_data(); void setLabelsVisible(); + void mouseclick_data(); + void mouseclick(); private: QBarSeries* m_barseries; @@ -71,6 +77,7 @@ private: void tst_QBarSeries::initTestCase() { + qRegisterMetaType("QBarSet*"); } void tst_QBarSeries::cleanupTestCase() @@ -417,6 +424,143 @@ void tst_QBarSeries::setLabelsVisible() } } +void tst_QBarSeries::mouseclick_data() +{ + +} + +void tst_QBarSeries::mouseclick() +{ + QBarSeries* series = new QBarSeries(); + QBarCategories categories; + categories << "test1" << "test2" << "test3"; + series->setCategories(categories); + + QBarSet* set1 = new QBarSet(QString("set 1")); + *set1 << 10 << 10 << 10; + series->appendBarSet(set1); + + QBarSet* set2 = new QBarSet(QString("set 2")); + *set2 << 10 << 10 << 10; + series->appendBarSet(set2); + + QSignalSpy setSpy1(set1, SIGNAL(clicked(QString))); + QSignalSpy setSpy2(set2, SIGNAL(clicked(QString))); + QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,QString))); + + QChartView view(new QChart()); + view.resize(400,300); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + +//==================================================================================== +// barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(100,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + QList setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + QList seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(190,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(130,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(220,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(310,180)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// no event cases + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(1,1)); // Outside of both sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(1,1)); // Right mouse button outside and inside sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(100,180)); // barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(190,180)); // barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(280,180)); // barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(130,180)); // barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(220,180)); // barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(310,180)); // barset 2, category test3 + + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 0); +} + /* bool setModel(QAbstractItemModel *model); void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); diff --git a/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp b/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp index 6fc0b64..2706852 100644 --- a/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp +++ b/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp @@ -21,9 +21,13 @@ #include #include #include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE +Q_DECLARE_METATYPE(QBarSet*) + class tst_QPercentBarSeries : public QObject { Q_OBJECT @@ -39,6 +43,8 @@ private slots: void qpercentbarseries(); void type_data(); void type(); + void mouseclick_data(); + void mouseclick(); private: QPercentBarSeries* m_barseries; @@ -46,6 +52,7 @@ private: void tst_QPercentBarSeries::initTestCase() { + qRegisterMetaType("QBarSet*"); } void tst_QPercentBarSeries::cleanupTestCase() @@ -83,6 +90,142 @@ void tst_QPercentBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); } +void tst_QPercentBarSeries::mouseclick_data() +{ + +} + +void tst_QPercentBarSeries::mouseclick() +{ + QPercentBarSeries* series = new QPercentBarSeries(); + QBarCategories categories; + categories << "test1" << "test2" << "test3"; + series->setCategories(categories); + + QBarSet* set1 = new QBarSet(QString("set 1")); + *set1 << 10 << 10 << 10; + series->appendBarSet(set1); + + QBarSet* set2 = new QBarSet(QString("set 2")); + *set2 << 10 << 10 << 10; + series->appendBarSet(set2); + + QSignalSpy setSpy1(set1, SIGNAL(clicked(QString))); + QSignalSpy setSpy2(set2, SIGNAL(clicked(QString))); + QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,QString))); + + QChartView view(new QChart()); + view.resize(400,300); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + +//==================================================================================== +// barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + QList setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + QList seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(205,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(205,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// no event cases + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(1,1)); // Outside of both sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(1,1)); // Right mouse button outside and inside sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(115,230)); // barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(205,230)); // barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(300,230)); // barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(115,140)); // barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(205,140)); // barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(300,140)); // barset 2, category test3 + + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 0); +} /* bool setModel(QAbstractItemModel *model); diff --git a/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp b/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp index a4ff457..d2a888e 100644 --- a/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp +++ b/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp @@ -21,9 +21,13 @@ #include #include #include +#include +#include QTCOMMERCIALCHART_USE_NAMESPACE +Q_DECLARE_METATYPE(QBarSet*) + class tst_QStackedBarSeries : public QObject { Q_OBJECT @@ -39,6 +43,8 @@ private slots: void qstackedbarseries(); void type_data(); void type(); + void mouseclick_data(); + void mouseclick(); private: QStackedBarSeries* m_barseries; @@ -46,6 +52,7 @@ private: void tst_QStackedBarSeries::initTestCase() { + qRegisterMetaType("QBarSet*"); } void tst_QStackedBarSeries::cleanupTestCase() @@ -83,6 +90,143 @@ void tst_QStackedBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); } +void tst_QStackedBarSeries::mouseclick_data() +{ + +} + +void tst_QStackedBarSeries::mouseclick() +{ + QStackedBarSeries* series = new QStackedBarSeries(); + QBarCategories categories; + categories << "test1" << "test2" << "test3"; + series->setCategories(categories); + + QBarSet* set1 = new QBarSet(QString("set 1")); + *set1 << 10 << 10 << 10; + series->appendBarSet(set1); + + QBarSet* set2 = new QBarSet(QString("set 2")); + *set2 << 10 << 10 << 10; + series->appendBarSet(set2); + + QSignalSpy setSpy1(set1, SIGNAL(clicked(QString))); + QSignalSpy setSpy2(set2, SIGNAL(clicked(QString))); + QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,QString))); + + QChartView view(new QChart()); + view.resize(400,300); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + +//==================================================================================== +// barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + QList setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + QList seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(205,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,230)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 1); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy1.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set1); + +//==================================================================================== +// barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(115,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test1")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(205,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test2")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// barset 2, category test3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,140)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 1); + QCOMPARE(seriesSpy.count(), 1); + setSpyArg = setSpy2.takeFirst(); + QVERIFY(setSpyArg.at(0).type() == QVariant::String); + QVERIFY(setSpyArg.at(0).toString().compare(QString("test3")) == 0); + + seriesSpyArg = seriesSpy.takeFirst(); + QCOMPARE(qvariant_cast(seriesSpyArg.at(0)), set2); + +//==================================================================================== +// no event cases + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(1,1)); // Outside of both sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(1,1)); // Right mouse button outside and inside sets + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(115,230)); // barset 1, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(205,230)); // barset 1, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(300,230)); // barset 1, category test3 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(115,140)); // barset 2, category test1 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(205,140)); // barset 2, category test2 + QTest::mouseClick(view.viewport(), Qt::RightButton, 0, QPoint(300,140)); // barset 2, category test3 + + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(setSpy1.count(), 0); + QCOMPARE(setSpy2.count(), 0); + QCOMPARE(seriesSpy.count(), 0); +} + /* bool setModel(QAbstractItemModel *model); void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);