From bf05f30a9a649e03ba6dd679d4bc944a0a76f2e3 2012-05-04 14:57:40 From: Michal Klocek Date: 2012-05-04 14:57:40 Subject: [PATCH] Merge branch 'master' of https://git.it.local/repos/QtCommercialDevel-13049/charts --- diff --git a/.gitignore b/.gitignore index 4aa405b..d76d5c0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ examples/*/*/*[.]app !examples/tutorials/* !examples/tutorials/*/* !examples/ja_JP/*/* -demos/*/* !demos/spectrum/* demos/spectrum/bin !demos/*/*[.]* diff --git a/demos/chartthemes/themewidget.cpp b/demos/chartthemes/themewidget.cpp index eb6d557..205fb14 100644 --- a/demos/chartthemes/themewidget.cpp +++ b/demos/chartthemes/themewidget.cpp @@ -216,7 +216,8 @@ QChart* ThemeWidget::createBarChart(int valueCount) const for (int i(0); i < valueCount; i++) categories << QString::number(i); - QStackedBarSeries* series = new QStackedBarSeries(categories, chart); + QStackedBarSeries* series = new QStackedBarSeries(chart); + series->setCategories(categories); for (int i(0); i < m_dataTable.count(); i++) { QBarSet *set = new QBarSet("Bar set " + QString::number(i)); foreach (Data data, m_dataTable[i]) diff --git a/demos/qmlchart/qml/qmlchart/View1.qml b/demos/qmlchart/qml/qmlchart/View1.qml index 1332bf6..b76d5c1 100644 --- a/demos/qmlchart/qml/qmlchart/View1.qml +++ b/demos/qmlchart/qml/qmlchart/View1.qml @@ -31,9 +31,9 @@ Rectangle { legend: Chart.LegendBottom PieSeries { - horizontalPosition: 0.2 - verticalPosition: 0.3 - size: 0.4 + horizontalPosition: 0.5 + verticalPosition: 0.5 + size: 0.7 slices: [ PieSlice { label: "Volkswagen"; value: 13.5 }, PieSlice { label: "Toyota"; value: 10.9 }, @@ -43,10 +43,5 @@ Rectangle { PieSlice { label: "Others"; value: 52.0 } ] } - - BarSeries { - barCategories: [ "2008", "2009", "2010", "2011", "2012" ] - // data implementation missing - } } } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index faa869c..97e2cf3 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -31,20 +31,20 @@ Rectangle { legend: Chart.LegendTop AreaSeries { - name: "Finnish" + name: "Swedish" points: [ - XyPoint { x: 0; y: 0 }, - XyPoint { x: 1; y: 0 }, - XyPoint { x: 2; y: 0 }, - XyPoint { x: 3; y: 0 }, - XyPoint { x: 4; y: 0 }, + XyPoint { x: 0; y: 1 }, + XyPoint { x: 1; y: 1 }, + XyPoint { x: 2; y: 3 }, + XyPoint { x: 3; y: 3 }, + XyPoint { x: 4; y: 2 }, XyPoint { x: 5; y: 0 }, - XyPoint { x: 6; y: 1 }, - XyPoint { x: 7; y: 0 }, - XyPoint { x: 8; y: 0 }, - XyPoint { x: 9; y: 0 }, - XyPoint { x: 10; y: 0 }, - XyPoint { x: 11; y: 1 } + XyPoint { x: 6; y: 2 }, + XyPoint { x: 7; y: 1 }, + XyPoint { x: 8; y: 2 }, + XyPoint { x: 9; y: 1 }, + XyPoint { x: 10; y: 3 }, + XyPoint { x: 11; y: 3 } ] lowerPoints: [ XyPoint { x: 0; y: 0 }, @@ -95,20 +95,20 @@ Rectangle { } AreaSeries { - name: "Swedish" + name: "Finnish" points: [ - XyPoint { x: 0; y: 1 }, - XyPoint { x: 1; y: 1 }, - XyPoint { x: 2; y: 3 }, - XyPoint { x: 3; y: 3 }, - XyPoint { x: 4; y: 2 }, + XyPoint { x: 0; y: 0 }, + XyPoint { x: 1; y: 0 }, + XyPoint { x: 2; y: 0 }, + XyPoint { x: 3; y: 0 }, + XyPoint { x: 4; y: 0 }, XyPoint { x: 5; y: 0 }, - XyPoint { x: 6; y: 2 }, - XyPoint { x: 7; y: 1 }, - XyPoint { x: 8; y: 2 }, - XyPoint { x: 9; y: 1 }, - XyPoint { x: 10; y: 3 }, - XyPoint { x: 11; y: 3 } + XyPoint { x: 6; y: 1 }, + XyPoint { x: 7; y: 0 }, + XyPoint { x: 8; y: 0 }, + XyPoint { x: 9; y: 0 }, + XyPoint { x: 10; y: 0 }, + XyPoint { x: 11; y: 1 } ] lowerPoints: [ XyPoint { x: 0; y: 0 }, diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml new file mode 100644 index 0000000..5c3f9ad --- /dev/null +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtCommercial.Chart 1.0 + +Rectangle { + anchors.fill: parent + + Chart { + title: "Bar series" + anchors.fill: parent + theme: Chart.ChartThemeLight + legend: Chart.LegendBottom + + BarSeries { + barCategories: [ "2008", "2009", "2010", "2011", "2012" ] + // data implementation missing + } + } +} diff --git a/demos/qmlchart/qml/qmlchart/main.qml b/demos/qmlchart/qml/qmlchart/main.qml index 0db7f73..fe4efbe 100644 --- a/demos/qmlchart/qml/qmlchart/main.qml +++ b/demos/qmlchart/qml/qmlchart/main.qml @@ -40,7 +40,7 @@ Rectangle { Loader { id: loader anchors.fill: parent - source: "View" + (__viewNumber % 4 + 1) + ".qml"; + source: "View" + (__viewNumber % 5 + 1) + ".qml"; } MouseArea { diff --git a/demos/qmlchart/resources.qrc b/demos/qmlchart/resources.qrc index 82eb434..44c623e 100644 --- a/demos/qmlchart/resources.qrc +++ b/demos/qmlchart/resources.qrc @@ -6,5 +6,6 @@ qml/qmlchart/View2.qml qml/qmlchart/View3.qml qml/qmlchart/View4.qml + qml/qmlchart/View5.qml diff --git a/examples/barchart/main.cpp b/examples/barchart/main.cpp index f4e2624..a1013bb 100644 --- a/examples/barchart/main.cpp +++ b/examples/barchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QBarSeries* series = new QBarSeries(categories); + QBarSeries* series = new QBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/percentbarchart/main.cpp b/examples/percentbarchart/main.cpp index 383bdda..c72e751 100644 --- a/examples/percentbarchart/main.cpp +++ b/examples/percentbarchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QPercentBarSeries* series = new QPercentBarSeries(categories); + QPercentBarSeries* series = new QPercentBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/stackedbarchart/main.cpp b/examples/stackedbarchart/main.cpp index 987f2f9..289171a 100644 --- a/examples/stackedbarchart/main.cpp +++ b/examples/stackedbarchart/main.cpp @@ -51,7 +51,8 @@ int main(int argc, char *argv[]) //![2] //![3] - QStackedBarSeries* series = new QStackedBarSeries(categories); + QStackedBarSeries* series = new QStackedBarSeries(); + series->setCategories(categories); series->appendBarSet(set0); series->appendBarSet(set1); series->appendBarSet(set2); diff --git a/examples/stackedbarchartdrilldown/drilldownseries.cpp b/examples/stackedbarchartdrilldown/drilldownseries.cpp index 7d3b174..f23413e 100644 --- a/examples/stackedbarchartdrilldown/drilldownseries.cpp +++ b/examples/stackedbarchartdrilldown/drilldownseries.cpp @@ -23,8 +23,9 @@ QTCOMMERCIALCHART_USE_NAMESPACE DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) - : QStackedBarSeries(categories, parent) + : QStackedBarSeries(parent) { + setCategories(categories); } void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) diff --git a/qmlplugin/declarativeareaseries.cpp b/qmlplugin/declarativeareaseries.cpp index 68edbcd..86ca0c3 100644 --- a/qmlplugin/declarativeareaseries.cpp +++ b/qmlplugin/declarativeareaseries.cpp @@ -30,11 +30,6 @@ DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : { } -QAbstractSeries *DeclarativeAreaSeries::series() -{ - return this; -} - QDeclarativeListProperty DeclarativeAreaSeries::points() { return QDeclarativeListProperty(this, 0, &DeclarativeAreaSeries::appendPoints); diff --git a/qmlplugin/declarativeareaseries.h b/qmlplugin/declarativeareaseries.h index a9428f4..f2a41ab 100644 --- a/qmlplugin/declarativeareaseries.h +++ b/qmlplugin/declarativeareaseries.h @@ -37,7 +37,6 @@ public: explicit DeclarativeAreaSeries(QObject *parent = 0); public: - QAbstractSeries *series(); QDeclarativeListProperty points(); QDeclarativeListProperty lowerPoints(); diff --git a/qmlplugin/declarativebarseries.cpp b/qmlplugin/declarativebarseries.cpp index b68adc9..31ecdd5 100644 --- a/qmlplugin/declarativebarseries.cpp +++ b/qmlplugin/declarativebarseries.cpp @@ -50,7 +50,9 @@ void DeclarativeBarSeries::setBarCategories(QStringList categories) QChart *chart = qobject_cast(declarativeChart->m_chart); Q_ASSERT(chart); - m_series = new QBarSeries(m_categories); +// m_series = new QBarSeries(m_categories); + m_series = new QBarSeries(); + m_series->setCategories(m_categories); // TODO: use data from model QBarSet *set0 = new QBarSet("Bub"); diff --git a/qmlplugin/declarativechart.cpp b/qmlplugin/declarativechart.cpp index c58a8ee..e5d5d9c 100644 --- a/qmlplugin/declarativechart.cpp +++ b/qmlplugin/declarativechart.cpp @@ -19,6 +19,7 @@ ****************************************************************************/ #include "declarativechart.h" +#include "declarativepieseries.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -36,6 +37,26 @@ DeclarativeChart::~DeclarativeChart() delete m_chart; } +void DeclarativeChart::childEvent(QChildEvent *event) +{ + if (event->type() == QEvent::ChildAdded) { + if (qobject_cast(event->child())) { + m_chart->addSeries(qobject_cast(event->child())); + } + } +} + +void DeclarativeChart::componentComplete() +{ + foreach(QObject *child, children()) { + if (qobject_cast(child)) { + m_chart->addSeries(qobject_cast(child)); + } + } + + QDeclarativeItem::componentComplete(); +} + void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_UNUSED(oldGeometry) diff --git a/qmlplugin/declarativechart.h b/qmlplugin/declarativechart.h index 9229056..9e6b656 100644 --- a/qmlplugin/declarativechart.h +++ b/qmlplugin/declarativechart.h @@ -53,6 +53,8 @@ public: ~DeclarativeChart(); public: // From QDeclarativeItem/QGraphicsItem + void childEvent(QChildEvent *event); + void componentComplete(); void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); diff --git a/qmlplugin/declarativelineseries.cpp b/qmlplugin/declarativelineseries.cpp index 9c5934c..dd57245 100644 --- a/qmlplugin/declarativelineseries.cpp +++ b/qmlplugin/declarativelineseries.cpp @@ -30,11 +30,6 @@ DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : { } -QAbstractSeries *DeclarativeLineSeries::series() -{ - return this; -} - QDeclarativeListProperty DeclarativeLineSeries::points() { return QDeclarativeListProperty(this, 0, &DeclarativeXySeries::appendPoints); diff --git a/qmlplugin/declarativelineseries.h b/qmlplugin/declarativelineseries.h index 2b50631..2849c84 100644 --- a/qmlplugin/declarativelineseries.h +++ b/qmlplugin/declarativelineseries.h @@ -37,7 +37,6 @@ public: explicit DeclarativeLineSeries(QObject *parent = 0); public: - QAbstractSeries *series(); QDeclarativeListProperty points(); }; diff --git a/qmlplugin/declarativepieseries.cpp b/qmlplugin/declarativepieseries.cpp index 493b56e..f5f31bf 100644 --- a/qmlplugin/declarativepieseries.cpp +++ b/qmlplugin/declarativepieseries.cpp @@ -25,25 +25,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : - QPieSeries(parent), - m_chart(0) + QPieSeries(parent) { } -void DeclarativePieSeries::classBegin() -{ -} - -void DeclarativePieSeries::componentComplete() -{ - DeclarativeChart *declarativeChart = qobject_cast(parent()); - if (declarativeChart) { - QChart *chart = qobject_cast(declarativeChart->m_chart); - Q_ASSERT(chart); - chart->addSeries(this); - } -} - QDeclarativeListProperty DeclarativePieSeries::slices() { return QDeclarativeListProperty(this, 0, &DeclarativePieSeries::appendSlice); diff --git a/qmlplugin/declarativepieseries.h b/qmlplugin/declarativepieseries.h index 131104a..bc13132 100644 --- a/qmlplugin/declarativepieseries.h +++ b/qmlplugin/declarativepieseries.h @@ -24,32 +24,24 @@ #include "qchartglobal.h" #include "qpieslice.h" #include "qpieseries.h" -#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE class QChart; -class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus +class DeclarativePieSeries : public QPieSeries { Q_OBJECT - Q_INTERFACES(QDeclarativeParserStatus) Q_PROPERTY(QDeclarativeListProperty slices READ slices) public: explicit DeclarativePieSeries(QObject *parent = 0); QDeclarativeListProperty slices(); -public: // from QDeclarativeParserStatus - void classBegin(); - void componentComplete(); - public Q_SLOTS: static void appendSlice(QDeclarativeListProperty *list, QPieSlice *element); - -private: - QChart *m_chart; }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/qmlplugin/declarativescatterseries.cpp b/qmlplugin/declarativescatterseries.cpp index 0376631..936fa66 100644 --- a/qmlplugin/declarativescatterseries.cpp +++ b/qmlplugin/declarativescatterseries.cpp @@ -30,11 +30,6 @@ DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : { } -QAbstractSeries *DeclarativeScatterSeries::series() -{ - return this; -} - QDeclarativeListProperty DeclarativeScatterSeries::points() { return QDeclarativeListProperty(this, 0, &DeclarativeXySeries::appendPoints); diff --git a/qmlplugin/declarativescatterseries.h b/qmlplugin/declarativescatterseries.h index 7471052..ba6ffa7 100644 --- a/qmlplugin/declarativescatterseries.h +++ b/qmlplugin/declarativescatterseries.h @@ -37,7 +37,6 @@ public: explicit DeclarativeScatterSeries(QObject *parent = 0); public: - QAbstractSeries *series(); QDeclarativeListProperty points(); }; diff --git a/qmlplugin/declarativesplineseries.cpp b/qmlplugin/declarativesplineseries.cpp index 41648f2..c6753c0 100644 --- a/qmlplugin/declarativesplineseries.cpp +++ b/qmlplugin/declarativesplineseries.cpp @@ -29,11 +29,6 @@ DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : { } -QAbstractSeries *DeclarativeSplineSeries::series() -{ - return this; -} - QDeclarativeListProperty DeclarativeSplineSeries::points() { return QDeclarativeListProperty(this, 0, &DeclarativeXySeries::appendPoints); diff --git a/qmlplugin/declarativesplineseries.h b/qmlplugin/declarativesplineseries.h index 344ff27..a3bfc1a 100644 --- a/qmlplugin/declarativesplineseries.h +++ b/qmlplugin/declarativesplineseries.h @@ -37,7 +37,6 @@ public: explicit DeclarativeSplineSeries(QObject *parent = 0); public: - QAbstractSeries *series(); QDeclarativeListProperty points(); }; diff --git a/qmlplugin/declarativexyseries.cpp b/qmlplugin/declarativexyseries.cpp index 09651cd..f673102 100644 --- a/qmlplugin/declarativexyseries.cpp +++ b/qmlplugin/declarativexyseries.cpp @@ -33,22 +33,6 @@ DeclarativeXySeries::~DeclarativeXySeries() { } -void DeclarativeXySeries::classBegin() -{ -} - -void DeclarativeXySeries::componentComplete() -{ - QAbstractSeries *thisObj = reinterpret_cast(series()); - DeclarativeChart *declarativeChart = qobject_cast(thisObj->parent()); - - if (declarativeChart) { - QChart *chart = qobject_cast(declarativeChart->m_chart); - Q_ASSERT(chart); - chart->addSeries(thisObj); - } -} - void DeclarativeXySeries::appendPoints(QDeclarativeListProperty *list, DeclarativeXyPoint *element) { diff --git a/qmlplugin/declarativexyseries.h b/qmlplugin/declarativexyseries.h index b9174e2..7372140 100644 --- a/qmlplugin/declarativexyseries.h +++ b/qmlplugin/declarativexyseries.h @@ -23,7 +23,6 @@ #include "qchartglobal.h" #include "declarativexypoint.h" -#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -31,7 +30,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QChart; class QAbstractSeries; -class DeclarativeXySeries : public QDeclarativeParserStatus +class DeclarativeXySeries { Q_INTERFACES(QDeclarativeParserStatus) @@ -39,12 +38,7 @@ public: explicit DeclarativeXySeries(); ~DeclarativeXySeries(); -public: // from QDeclarativeParserStatus - virtual void classBegin(); - virtual void componentComplete(); - public: - virtual QAbstractSeries *series() = 0; virtual QDeclarativeListProperty points() = 0; public Q_SLOTS: diff --git a/src/barchart/qbarseries.cpp b/src/barchart/qbarseries.cpp index 08aecbb..b5709ab 100644 --- a/src/barchart/qbarseries.cpp +++ b/src/barchart/qbarseries.cpp @@ -67,8 +67,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. QBarSeries is QObject which is a child of a \a parent. */ -QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : - QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) +QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : + QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) { } @@ -96,57 +96,90 @@ QAbstractSeries::SeriesType QBarSeries::type() const return QAbstractSeries::SeriesTypeBar; } +void QBarSeries::setCategories(QBarCategories categories) +{ + Q_D(QBarSeries); + d->setCategories(categories); + emit d->categoriesUpdated(); +} + /*! Adds a set of bars to series. Takes ownership of \a set. */ -void QBarSeries::appendBarSet(QBarSet *set) +bool QBarSeries::appendBarSet(QBarSet *set) { Q_D(QBarSeries); + if ((d->m_barSets.contains(set)) || (set == 0)) { + // Fail if set is already in list or set is null. + return false; + } d->m_barSets.append(set); QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); emit d->restructuredBars(); + return true; } /*! Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. */ -void QBarSeries::removeBarSet(QBarSet *set) +bool QBarSeries::removeBarSet(QBarSet *set) { Q_D(QBarSeries); - if (d->m_barSets.contains(set)) { - d->m_barSets.removeOne(set); - QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); - emit d->restructuredBars(); + if (!d->m_barSets.contains(set)) { + // Fail if set is not in list + return false; } + d->m_barSets.removeOne(set); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); + emit d->restructuredBars(); + return true; } /*! Adds a list of barsets to series. Takes ownership of \a sets. */ -void QBarSeries::appendBarSets(QList sets) +bool QBarSeries::appendBarSets(QList sets) { Q_D(QBarSeries); foreach (QBarSet* set, sets) { + if ((set == 0) || (d->m_barSets.contains(set))) { + // Fail if any of the sets is null or is already appended. + return false; + } + if (sets.count(set) != 1) { + // Also fail if same set is more than once in given list. + return false; + } + } + + foreach (QBarSet* set, sets) { d->m_barSets.append(set); QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); } emit d->restructuredBars(); + return true; } /*! Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. */ -void QBarSeries::removeBarSets(QList sets) +bool QBarSeries::removeBarSets(QList sets) { Q_D(QBarSeries); + bool setsRemoved = false; foreach (QBarSet* set, sets) { if (d->m_barSets.contains(set)) { d->m_barSets.removeOne(set); QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); + setsRemoved = true; } } - emit d->restructuredBars(); + + if (setsRemoved) { + emit d->restructuredBars(); + } + return setsRemoved; } /*! @@ -227,15 +260,21 @@ void QBarSeries::setLabelsVisible(bool visible) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : +QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) : QAbstractSeriesPrivate(q), - m_categories(categories), +// m_categories(categories), m_mapCategories(-1), m_mapBarBottom(-1), m_mapBarTop(-1) { } +void QBarSeriesPrivate::setCategories(QBarCategories categories) +{ + m_categories = categories; +} + + QBarSet* QBarSeriesPrivate::barsetAt(int index) { return m_barSets.at(index); diff --git a/src/barchart/qbarseries.h b/src/barchart/qbarseries.h index 9d79229..2f7a6f1 100644 --- a/src/barchart/qbarseries.h +++ b/src/barchart/qbarseries.h @@ -39,15 +39,16 @@ class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries { Q_OBJECT public: - explicit QBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); virtual ~QBarSeries(); QAbstractSeries::SeriesType type() const; + void setCategories(QBarCategories categories); - void appendBarSet(QBarSet *set); // Takes ownership of set - void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set - void appendBarSets(QList sets); - void removeBarSets(QList sets); + bool appendBarSet(QBarSet *set); // Takes ownership of set + bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set + bool appendBarSets(QList sets); + bool removeBarSets(QList sets); int barsetCount() const; int categoryCount() const; QList barSets() const; diff --git a/src/barchart/qbarseries_p.h b/src/barchart/qbarseries_p.h index 29e5574..ca75df8 100644 --- a/src/barchart/qbarseries_p.h +++ b/src/barchart/qbarseries_p.h @@ -15,7 +15,8 @@ class QBarSeriesPrivate : public QAbstractSeriesPrivate { Q_OBJECT public: - QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); + QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *parent); + void setCategories(QBarCategories categories); void scaleDomain(Domain& domain); Chart* createGraphics(ChartPresenter* presenter); diff --git a/src/barchart/qpercentbarseries.cpp b/src/barchart/qpercentbarseries.cpp index 9277f30..6889b2b 100644 --- a/src/barchart/qpercentbarseries.cpp +++ b/src/barchart/qpercentbarseries.cpp @@ -53,8 +53,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. QPercentBarSeries is QObject which is a child of a \a parent. */ -QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent) - : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent) +QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent) + : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent) { } @@ -65,7 +65,7 @@ QAbstractSeries::SeriesType QPercentBarSeries::type() const /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QBarCategories categories, QPercentBarSeries *q) : QBarSeriesPrivate(categories,q) +QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(/*QBarCategories categories,*/ QPercentBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) { } diff --git a/src/barchart/qpercentbarseries.h b/src/barchart/qpercentbarseries.h index e8141ec..ba12f97 100644 --- a/src/barchart/qpercentbarseries.h +++ b/src/barchart/qpercentbarseries.h @@ -32,8 +32,9 @@ class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries { Q_OBJECT public: - explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); QAbstractSeries::SeriesType type() const; + private: Q_DECLARE_PRIVATE(QPercentBarSeries) Q_DISABLE_COPY(QPercentBarSeries) diff --git a/src/barchart/qpercentbarseries_p.h b/src/barchart/qpercentbarseries_p.h index b296c91..d7494a9 100644 --- a/src/barchart/qpercentbarseries_p.h +++ b/src/barchart/qpercentbarseries_p.h @@ -39,7 +39,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QPercentBarSeriesPrivate: public QBarSeriesPrivate { public: - QPercentBarSeriesPrivate(QBarCategories categories,QPercentBarSeries* q); + QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q); void scaleDomain(Domain& domain); Chart* createGraphics(ChartPresenter* presenter); diff --git a/src/barchart/qstackedbarseries.cpp b/src/barchart/qstackedbarseries.cpp index 3ef6dfe..12f7c62 100644 --- a/src/barchart/qstackedbarseries.cpp +++ b/src/barchart/qstackedbarseries.cpp @@ -52,8 +52,8 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. QStackedBarSeries is QObject which is a child of a \a parent. */ -QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent) - : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent) +QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent) + : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent) { } @@ -64,7 +64,7 @@ QAbstractSeries::SeriesType QStackedBarSeries::type() const /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QStackedBarSeries *q) : QBarSeriesPrivate(categories,q) +QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(/*QBarCategories categories,*/ QStackedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) { } diff --git a/src/barchart/qstackedbarseries.h b/src/barchart/qstackedbarseries.h index 5e0f234..8833d9f 100644 --- a/src/barchart/qstackedbarseries.h +++ b/src/barchart/qstackedbarseries.h @@ -32,8 +32,9 @@ class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries { Q_OBJECT public: - explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0); + explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); QAbstractSeries::SeriesType type() const; + private: Q_DECLARE_PRIVATE(QStackedBarSeries) Q_DISABLE_COPY(QStackedBarSeries) diff --git a/src/barchart/qstackedbarseries_p.h b/src/barchart/qstackedbarseries_p.h index 0ff4011..632de86 100644 --- a/src/barchart/qstackedbarseries_p.h +++ b/src/barchart/qstackedbarseries_p.h @@ -39,7 +39,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QStackedBarSeriesPrivate: public QBarSeriesPrivate { public: - QStackedBarSeriesPrivate(QBarCategories categories,QStackedBarSeries* q); + QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q); Chart* createGraphics(ChartPresenter* presenter); void scaleDomain(Domain& domain); diff --git a/test/auto/auto.pri b/test/auto/auto.pri index a1a846f..0a7c3ea 100644 --- a/test/auto/auto.pri +++ b/test/auto/auto.pri @@ -4,3 +4,6 @@ CONFIG += qtestlib !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") + +INCLUDEPATH += ../inc +HEADERS += ../inc/tst_definitions.h diff --git a/test/auto/auto.pro b/test/auto/auto.pro index 8121e34..63a6c58 100644 --- a/test/auto/auto.pro +++ b/test/auto/auto.pro @@ -3,7 +3,7 @@ } TEMPLATE = subdirs -SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries +SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qpieslice qpieseries test_private:{ SUBDIRS += chartdataset domain diff --git a/test/auto/chartdataset/tst_chartdataset.cpp b/test/auto/chartdataset/tst_chartdataset.cpp index 0876c86..a585d87 100644 --- a/test/auto/chartdataset/tst_chartdataset.cpp +++ b/test/auto/chartdataset/tst_chartdataset.cpp @@ -23,6 +23,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -151,10 +152,10 @@ void tst_ChartDataSet::addSeries() m_dataset->addSeries(series1,axis1); m_dataset->addSeries(series2,axis2); - QCOMPARE(spy0.count(), axisCount); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 3); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), axisCount); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 3); + TRY_COMPARE(spy3.count(), 0); if(axis0==0) axis0 = m_dataset->axisY(); if(axis1==0) axis1 = m_dataset->axisY(); @@ -193,10 +194,10 @@ void tst_ChartDataSet::removeSeries() m_dataset->removeSeries(series1); m_dataset->removeSeries(series2); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), axisCount); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 3); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), axisCount); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 3); } void tst_ChartDataSet::removeAllSeries_data() @@ -225,10 +226,10 @@ void tst_ChartDataSet::removeAllSeries() m_dataset->removeAllSeries(); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 4); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 3); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 4); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 3); } @@ -296,10 +297,10 @@ void tst_ChartDataSet::seriesCount() QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); QCOMPARE(m_dataset->seriesCount(series0->type()),3); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); } void tst_ChartDataSet::seriesIndex_data() @@ -333,10 +334,10 @@ void tst_ChartDataSet::seriesIndex() QCOMPARE(m_dataset->seriesIndex(series1),1); QCOMPARE(m_dataset->seriesIndex(series2),2); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); m_dataset->removeSeries(series0); m_dataset->removeSeries(series1); @@ -414,10 +415,10 @@ void tst_ChartDataSet::domain() QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); + TRY_COMPARE(spy3.count(), 0); } void tst_ChartDataSet::zoomInDomain_data() @@ -450,9 +451,9 @@ void tst_ChartDataSet::zoomInDomain() m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } void tst_ChartDataSet::zoomOutDomain_data() @@ -486,9 +487,9 @@ void tst_ChartDataSet::zoomOutDomain() m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } void tst_ChartDataSet::scrollDomain_data() @@ -522,9 +523,9 @@ void tst_ChartDataSet::scrollDomain() m_dataset->scrollDomain(10,10,QSize(1000,1000)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } QTEST_MAIN(tst_ChartDataSet) diff --git a/test/auto/domain/tst_domain.cpp b/test/auto/domain/tst_domain.cpp index dcf5352..c1ec2eb 100644 --- a/test/auto/domain/tst_domain.cpp +++ b/test/auto/domain/tst_domain.cpp @@ -21,6 +21,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -132,9 +133,9 @@ void tst_Domain::handleAxisRangeXChanged() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } @@ -168,9 +169,9 @@ void tst_Domain::handleAxisRangeYChanged() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } void tst_Domain::isEmpty_data() @@ -226,9 +227,9 @@ void tst_Domain::maxX() domain.setMaxX(maxX2); QCOMPARE(domain.maxX(), maxX2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), count); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), count); + TRY_COMPARE(spy2.count(), 0); } @@ -259,9 +260,9 @@ void tst_Domain::maxY() domain.setMaxY(maxY2); QCOMPARE(domain.maxY(), maxY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), count); } void tst_Domain::minX_data() @@ -291,9 +292,9 @@ void tst_Domain::minX() domain.setMinX(minX2); QCOMPARE(domain.minX(), minX2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), count); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), count); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::minY_data() @@ -323,9 +324,9 @@ void tst_Domain::minY() domain.setMinY(minY2); QCOMPARE(domain.minY(), minY2); - QCOMPARE(spy0.count(), count); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), count); + TRY_COMPARE(spy0.count(), count); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), count); } void tst_Domain::operatorEquals_data() @@ -371,9 +372,9 @@ void tst_Domain::operatorEquals() QCOMPARE(*domain1==*domain2, equals); QCOMPARE(*domain1!=*domain2, notEquals); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::setRange_data() @@ -407,9 +408,9 @@ void tst_Domain::setRange() QCOMPARE(domain.minY(), minY); QCOMPARE(domain.maxY(), maxY); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); } @@ -443,9 +444,9 @@ void tst_Domain::setRangeX() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::setRangeY_data() @@ -478,9 +479,9 @@ void tst_Domain::setRangeY() QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } void tst_Domain::spanX_data() @@ -508,9 +509,9 @@ void tst_Domain::spanX() QCOMPARE(domain.spanX(), spanX); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::spanY_data() @@ -538,9 +539,9 @@ void tst_Domain::spanY() QCOMPARE(domain.spanY(), spanY); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 0); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 0); } void tst_Domain::zoom_data() @@ -593,10 +594,9 @@ void tst_Domain::zoom() QCOMPARE(domain == domain1, true); domain.zoomOut(rect0, size0); QCOMPARE(domain == domain0, true); - QCOMPARE(spy0.count(), 6); - QCOMPARE(spy1.count(), 6); - QCOMPARE(spy2.count(), 6); - + TRY_COMPARE(spy0.count(), 6); + TRY_COMPARE(spy1.count(), 6); + TRY_COMPARE(spy2.count(), 6); } void tst_Domain::move_data() @@ -631,9 +631,9 @@ void tst_Domain::move() result.setRange(dx, size.width() + dx, dy, size.height() + dy); QCOMPARE(domain == result, true); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), dx!=0?1:0); - QCOMPARE(spy2.count(), dy!=0?1:0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); + TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); } void tst_Domain::handleAxisXChanged_data() @@ -671,9 +671,9 @@ void tst_Domain::handleAxisXChanged() QCOMPARE(resultMin, domain.minX()); QCOMPARE(resultMax, domain.maxX()); QCOMPARE(resultTickCount, domain.tickXCount()); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 0); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 0); } @@ -702,9 +702,9 @@ void tst_Domain::handleAxisYChanged() QCOMPARE(resultMin, domain.minY()); QCOMPARE(resultMax, domain.maxY()); QCOMPARE(resultTickCount, domain.tickYCount()); - QCOMPARE(spy0.count(), 1); - QCOMPARE(spy1.count(), 0); - QCOMPARE(spy2.count(), 1); + TRY_COMPARE(spy0.count(), 1); + TRY_COMPARE(spy1.count(), 0); + TRY_COMPARE(spy2.count(), 1); } QTEST_MAIN(tst_Domain) diff --git a/test/auto/inc/tst_definitions.h b/test/auto/inc/tst_definitions.h new file mode 100644 index 0000000..f30e9bb --- /dev/null +++ b/test/auto/inc/tst_definitions.h @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef TST_DEFINITIONS_H +#define TST_DEFINITIONS_H + +#include + +#define TRY_COMPARE(actual, expected) { \ + do { \ + const int timeout(1000); \ + const int waitStep(30); \ + /* always wait before comparing to catch possible extra signals */ \ + QTest::qWait(waitStep); \ + for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \ + QTest::qWait(waitStep); \ + QCOMPARE(actual, expected); \ + } while (0); \ +} + +#endif // TST_DEFINITIONS_H diff --git a/test/auto/qbarseries/tst_qbarseries.cpp b/test/auto/qbarseries/tst_qbarseries.cpp index d184e79..d4cab5a 100644 --- a/test/auto/qbarseries/tst_qbarseries.cpp +++ b/test/auto/qbarseries/tst_qbarseries.cpp @@ -39,6 +39,8 @@ private slots: void qbarseries(); void type_data(); void type(); + void setCategories_data(); + void setCategories(); void appendBarSet_data(); void appendBarSet(); void removeBarSet_data(); @@ -78,8 +80,10 @@ void tst_QBarSeries::cleanupTestCase() void tst_QBarSeries::init() { m_categories << "category0" << "category1" << "category2"; - m_barseries = new QBarSeries(m_categories); - m_barseries_with_sets = new QBarSeries(m_categories); + m_barseries = new QBarSeries(); + m_barseries->setCategories(m_categories); + m_barseries_with_sets = new QBarSeries(); + m_barseries_with_sets->setCategories(m_categories); for (int i=0; i<5; i++) { m_testSets.append(new QBarSet("testset")); @@ -113,8 +117,9 @@ void tst_QBarSeries::qbarseries_data() void tst_QBarSeries::qbarseries() { QFETCH(QBarCategories, categories); - QBarSeries *barseries = new QBarSeries(categories); + QBarSeries *barseries = new QBarSeries(); QVERIFY(barseries != 0); + barseries->setCategories(categories); QBarCategories verifyCategories = barseries->categories(); QVERIFY(verifyCategories.count() == categories.count()); @@ -133,6 +138,27 @@ void tst_QBarSeries::type() QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); } +void tst_QBarSeries::setCategories_data() +{ + QTest::addColumn ("categories"); + QBarCategories categories; + categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; + QTest::newRow("cat") << categories; +} + +void tst_QBarSeries::setCategories() +{ + QVERIFY(m_barseries->categories().count() == m_categories.count()); + + QFETCH(QBarCategories, categories); + m_barseries->setCategories(categories); + + QVERIFY(m_barseries->categories().count() == categories.count()); + for (int i=0; icategories().at(i).compare(categories.at(i)) == 0); + } +} + void tst_QBarSeries::appendBarSet_data() { } @@ -141,15 +167,32 @@ void tst_QBarSeries::appendBarSet() { QVERIFY(m_barseries->barsetCount() == 0); + bool ret = false; + + // Try adding barset QBarSet *barset = new QBarSet("testset"); - m_barseries->appendBarSet(barset); + ret = m_barseries->appendBarSet(barset); + QVERIFY(ret == true); QVERIFY(m_barseries->barsetCount() == 1); + // Try adding another set QBarSet *barset2 = new QBarSet("testset2"); - m_barseries->appendBarSet(barset2); + ret = m_barseries->appendBarSet(barset2); + + QVERIFY(ret == true); + QVERIFY(m_barseries->barsetCount() == 2); + // Try adding same set again + ret = m_barseries->appendBarSet(barset2); + QVERIFY(ret == false); QVERIFY(m_barseries->barsetCount() == 2); + + // Try adding null set + ret = m_barseries->appendBarSet(0); + QVERIFY(ret == false); + QVERIFY(m_barseries->barsetCount() == 2); + } void tst_QBarSeries::removeBarSet_data() @@ -161,10 +204,24 @@ void tst_QBarSeries::removeBarSet() int count = m_testSets.count(); QVERIFY(m_barseries_with_sets->barsetCount() == count); + // Try to remove null pointer (should not remove, should not crash) + bool ret = false; + ret = m_barseries_with_sets->removeBarSet(0); + QVERIFY(ret == false); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + + // Try to remove invalid pointer (should not remove, should not crash) + ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); + QVERIFY(ret == false); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + // remove some sets - m_barseries_with_sets->removeBarSet(m_testSets.at(2)); - m_barseries_with_sets->removeBarSet(m_testSets.at(3)); - m_barseries_with_sets->removeBarSet(m_testSets.at(4)); + ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); + QVERIFY(ret == true); + ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); + QVERIFY(ret == true); + ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); + QVERIFY(ret == true); QVERIFY(m_barseries_with_sets->barsetCount() == 2); @@ -173,11 +230,13 @@ void tst_QBarSeries::removeBarSet() QVERIFY(verifysets.at(0) == m_testSets.at(0)); QVERIFY(verifysets.at(1) == m_testSets.at(1)); - // Try removing all sets again + // Try removing all sets again (should be ok, even if some sets have already been removed) + ret = false; for (int i=0; iremoveBarSet(m_testSets.at(i)); + ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); } + QVERIFY(ret == true); QVERIFY(m_barseries_with_sets->barsetCount() == 0); } @@ -196,7 +255,37 @@ void tst_QBarSeries::appendBarSets() sets.append(new QBarSet("testset")); } - m_barseries->appendBarSets(sets); + // Append new sets (should succeed, count should match the count of sets) + bool ret = false; + ret = m_barseries->appendBarSets(sets); + QVERIFY(ret == true); + QVERIFY(m_barseries->barsetCount() == count); + + // Append same sets again (should fail, count should remain same) + ret = m_barseries->appendBarSets(sets); + QVERIFY(ret == false); + QVERIFY(m_barseries->barsetCount() == count); + + // Try append empty list (should succeed, but count should remain same) + QList invalidList; + ret = m_barseries->appendBarSets(invalidList); + QVERIFY(ret == true); + QVERIFY(m_barseries->barsetCount() == count); + + // Try append list with one new and one existing set (should fail, count remains same) + invalidList.append(new QBarSet("ok set")); + invalidList.append(sets.at(0)); + ret = m_barseries->appendBarSets(invalidList); + QVERIFY(ret == false); + QVERIFY(m_barseries->barsetCount() == count); + + // Try append list with null pointers (should fail, count remains same) + QList invalidList2; + invalidList2.append(0); + invalidList2.append(0); + invalidList2.append(0); + ret = m_barseries->appendBarSets(invalidList2); + QVERIFY(ret == false); QVERIFY(m_barseries->barsetCount() == count); } @@ -210,21 +299,36 @@ void tst_QBarSeries::removeBarSets() int count = m_testSets.count(); QVERIFY(m_barseries_with_sets->barsetCount() == count); - // Try removing empty list of sets - QList empty; - m_barseries_with_sets->removeBarSets(empty); + // Try removing empty list of sets (should return false, since no barsets were removed) + bool ret = false; + QList invalidList; + ret = m_barseries_with_sets->removeBarSets(invalidList); + QVERIFY(ret == false); QVERIFY(m_barseries_with_sets->barsetCount() == count); - // remove all sets - m_barseries_with_sets->removeBarSets(m_testSets); + // Add some null pointers to list + invalidList.append(0); + invalidList.append(0); + invalidList.append(0); + + // Try removing null pointers from list (should return false, should not crash, should not remove anything) + ret = m_barseries_with_sets->removeBarSets(invalidList); + QVERIFY(ret == false); + QVERIFY(m_barseries_with_sets->barsetCount() == count); + + // remove all sets (should return true, since sets were removed) + ret = m_barseries_with_sets->removeBarSets(m_testSets); + QVERIFY(ret == true); QVERIFY(m_barseries_with_sets->barsetCount() == 0); - // Try removing empty list again - m_barseries_with_sets->removeBarSets(empty); + // Try removing invalid list again (should return false, since no barsets were removed) + ret = m_barseries_with_sets->removeBarSets(invalidList); + QVERIFY(ret == false); QVERIFY(m_barseries_with_sets->barsetCount() == 0); - // remove all sets again - m_barseries_with_sets->removeBarSets(m_testSets); + // remove all sets again (should return false, since barsets were already removed) + ret = m_barseries_with_sets->removeBarSets(m_testSets); + QVERIFY(ret == false); QVERIFY(m_barseries_with_sets->barsetCount() == 0); } @@ -289,25 +393,31 @@ void tst_QBarSeries::setLabelsVisible_data() void tst_QBarSeries::setLabelsVisible() { + // labels should be invisible by default foreach (QBarSet* s, m_testSets) { QVERIFY(s->labelsVisible() == false); } + // turn labels to visible m_barseries_with_sets->setLabelsVisible(true); foreach (QBarSet* s, m_testSets) { QVERIFY(s->labelsVisible() == true); } + // turn labels to invisible m_barseries_with_sets->setLabelsVisible(false); foreach (QBarSet* s, m_testSets) { QVERIFY(s->labelsVisible() == false); } + + // without parameter, should turn labels to visible + m_barseries_with_sets->setLabelsVisible(); + foreach (QBarSet* s, m_testSets) { + QVERIFY(s->labelsVisible() == true); + } } /* - -void setLabelsVisible(bool visible = true); - bool setModel(QAbstractItemModel *model); void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); void setModelMappingRange(int first, int count = -1); diff --git a/test/auto/qchart/tst_qchart.cpp b/test/auto/qchart/tst_qchart.cpp index fe5ca33..f16fe49 100644 --- a/test/auto/qchart/tst_qchart.cpp +++ b/test/auto/qchart/tst_qchart.cpp @@ -164,9 +164,16 @@ void tst_QChart::addSeries_data() QAbstractSeries* series2 = new QScatterSeries(this); QAbstractSeries* series3 = new QSplineSeries(this); QAbstractSeries* series4 = new QPieSeries(this); - QAbstractSeries* series5 = new QBarSeries(QBarCategories(),this); - QAbstractSeries* series6 = new QPercentBarSeries(QBarCategories(),this); - QAbstractSeries* series7 = new QStackedBarSeries(QBarCategories(),this); + QAbstractSeries* series5 = new QBarSeries(this); + QAbstractSeries* series6 = new QPercentBarSeries(this); + QAbstractSeries* series7 = new QStackedBarSeries(this); + + QBarSeries* s5 = static_cast (series5); + s5->setCategories(QBarCategories()); + QPercentBarSeries* s6 = static_cast (series6); + s6->setCategories(QBarCategories()); + QStackedBarSeries* s7 = static_cast (series7); + s7->setCategories(QBarCategories()); QAxis* axis = new QAxis(this); @@ -550,17 +557,27 @@ void tst_QChart::zoomOut() m_chart->zoomIn(); - QVERIFY(minXaxisX()->min()); - QVERIFY(maxX>m_chart->axisX()->max()); - QVERIFY(minYaxisY()->min()); - QVERIFY(maxY>m_chart->axisY()->max()); + QVERIFY(minX < m_chart->axisX()->min()); + QVERIFY(maxX > m_chart->axisX()->max()); + QVERIFY(minY < m_chart->axisY()->min()); + QVERIFY(maxY > m_chart->axisY()->max()); m_chart->zoomOut(); - QVERIFY(minX==m_chart->axisX()->min()); - QVERIFY(maxX==m_chart->axisX()->max()); - QVERIFY(minY==m_chart->axisY()->min()); - QVERIFY(maxY==m_chart->axisY()->max()); + // min x may be a zero value + if (qFuzzyIsNull(minX)) + QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); + else + QCOMPARE(minX, m_chart->axisX()->min()); + + // min y may be a zero value + if (qFuzzyIsNull(minY)) + QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); + else + QCOMPARE(minY, m_chart->axisY()->min()); + + QVERIFY(maxX == m_chart->axisX()->max()); + QVERIFY(maxY == m_chart->axisY()->max()); } QTEST_MAIN(tst_QChart) diff --git a/test/auto/qchartview/tst_qchartview.cpp b/test/auto/qchartview/tst_qchartview.cpp index 7d58e31..6390b69 100644 --- a/test/auto/qchartview/tst_qchartview.cpp +++ b/test/auto/qchartview/tst_qchartview.cpp @@ -22,6 +22,7 @@ #include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -153,8 +154,8 @@ void tst_QChartView::rubberBand() QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); - QCOMPARE(spy0.count(), Xcount); - QCOMPARE(spy1.count(), Ycount); + TRY_COMPARE(spy0.count(), Xcount); + TRY_COMPARE(spy1.count(), Ycount); //this is hack since view does not get events otherwise m_view->setMouseTracking(false); diff --git a/test/auto/qlineseries/tst_qlineseries.cpp b/test/auto/qlineseries/tst_qlineseries.cpp index 6469142..306dbd1 100644 --- a/test/auto/qlineseries/tst_qlineseries.cpp +++ b/test/auto/qlineseries/tst_qlineseries.cpp @@ -22,6 +22,7 @@ #include #include #include +#include Q_DECLARE_METATYPE(QList) @@ -173,10 +174,8 @@ void tst_QLineSeries::append_raw() { QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); - QTest::qWait(200); m_series->append(points); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); } @@ -240,7 +239,7 @@ void tst_QLineSeries::count_raw() for(int i=0 ; i< count; ++i) m_series->append(i,i); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->count(), count); } @@ -262,7 +261,7 @@ void tst_QLineSeries::oper() } QCOMPARE(series.points(), points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); } @@ -283,7 +282,7 @@ void tst_QLineSeries::pen() QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); series.setPen(pen); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(series.pen(), pen); m_chart->addSeries(&series); @@ -312,7 +311,7 @@ void tst_QLineSeries::pointsVisible_raw() QFETCH(bool, pointsVisible); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->setPointsVisible(pointsVisible); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->pointsVisible(), pointsVisible); } @@ -326,17 +325,13 @@ void tst_QLineSeries::remove_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); foreach(const QPointF& point,points) - { m_series->remove(point); - QTest::qWait(200); - } - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points().count(), 0); } @@ -375,12 +370,10 @@ void tst_QLineSeries::removeAll_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); - QTest::qWait(200); m_series->removeAll(); - QTest::qWait(200); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points().count(), 0); } @@ -418,15 +411,11 @@ void tst_QLineSeries::replace_raw() QFETCH(QList, points); QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); m_series->append(points); - QCOMPARE(spy0.count(), 0); + TRY_COMPARE(spy0.count(), 0); QCOMPARE(m_series->points(), points); - QTest::qWait(200); foreach(const QPointF& point,points) - { - m_series->replace(point.x(),point.y(),point.x(),0); - QTest::qWait(200); - } + m_series->replace(point.x(),point.y(),point.x(),0); QList newPoints = m_series->points(); diff --git a/test/auto/qpercentbarseries/qpercentbarseries.pro b/test/auto/qpercentbarseries/qpercentbarseries.pro new file mode 100644 index 0000000..64f9b4b --- /dev/null +++ b/test/auto/qpercentbarseries/qpercentbarseries.pro @@ -0,0 +1,6 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +SOURCES += tst_qpercentbarseries.cpp + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp b/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp new file mode 100644 index 0000000..6fc0b64 --- /dev/null +++ b/test/auto/qpercentbarseries/tst_qpercentbarseries.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_QPercentBarSeries : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void qpercentbarseries_data(); + void qpercentbarseries(); + void type_data(); + void type(); + +private: + QPercentBarSeries* m_barseries; +}; + +void tst_QPercentBarSeries::initTestCase() +{ +} + +void tst_QPercentBarSeries::cleanupTestCase() +{ +} + +void tst_QPercentBarSeries::init() +{ + m_barseries = new QPercentBarSeries(); +} + +void tst_QPercentBarSeries::cleanup() +{ + delete m_barseries; + m_barseries = 0; +} + +void tst_QPercentBarSeries::qpercentbarseries_data() +{ +} + +void tst_QPercentBarSeries::qpercentbarseries() +{ + QPercentBarSeries *barseries = new QPercentBarSeries(); + QVERIFY(barseries != 0); +} + +void tst_QPercentBarSeries::type_data() +{ + +} + +void tst_QPercentBarSeries::type() +{ + QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); +} + + +/* +bool setModel(QAbstractItemModel *model); +void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); +void setModelMappingRange(int first, int count = -1); +*/ +QTEST_MAIN(tst_QPercentBarSeries) + +#include "tst_qpercentbarseries.moc" + diff --git a/test/auto/qpieseries/tst_qpieseries.cpp b/test/auto/qpieseries/tst_qpieseries.cpp index 27835a0..ad6486d 100644 --- a/test/auto/qpieseries/tst_qpieseries.cpp +++ b/test/auto/qpieseries/tst_qpieseries.cpp @@ -19,11 +19,16 @@ ****************************************************************************/ #include +#include +#include #include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE +Q_DECLARE_METATYPE(QPieSlice*) + class tst_qpieseries : public QObject { Q_OBJECT @@ -39,13 +44,12 @@ private slots: void append(); void insert(); void remove(); - //void calculatedValues(); - //void themes(); - //void clickedSignal(); - //void hoverSignal(); + void calculatedValues(); + void clickedSignal(); + void hoverSignal(); private: - + void verifyCalculatedData(const QPieSeries &series, bool *ok); private: @@ -53,6 +57,7 @@ private: void tst_qpieseries::initTestCase() { + qRegisterMetaType("QPieSlice*"); } void tst_qpieseries::cleanupTestCase() @@ -76,12 +81,12 @@ void tst_qpieseries::construction() QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); QVERIFY(s.count() == 0); QVERIFY(s.isEmpty()); - QVERIFY(qFuzzyIsNull(s.sum())); - QVERIFY(qFuzzyCompare(s.horizontalPosition(), 0.5)); - QVERIFY(qFuzzyCompare(s.verticalPosition(), 0.5)); - QVERIFY(qFuzzyCompare(s.pieSize(), 0.7)); - QVERIFY(qFuzzyIsNull(s.pieStartAngle())); - QVERIFY(qFuzzyCompare(s.pieEndAngle(), 360)); + QCOMPARE(s.sum(), 0.0); + QCOMPARE(s.horizontalPosition(), 0.5); + QCOMPARE(s.verticalPosition(), 0.5); + QCOMPARE(s.pieSize(), 0.7); + QCOMPARE(s.pieStartAngle(), 0.0); + QCOMPARE(s.pieEndAngle(), 360.0); } void tst_qpieseries::append() @@ -116,14 +121,14 @@ void tst_qpieseries::append() // append with params QPieSlice *slice5 = s.append(5, "slice 5"); QVERIFY(slice5 != 0); - QVERIFY(qFuzzyCompare(slice5->value(), 5.0)); + QCOMPARE(slice5->value(), 5.0); QCOMPARE(slice5->label(), QString("slice 5")); QCOMPARE(s.count(), 5); // check slices QVERIFY(!s.isEmpty()); for (int i=0; ivalue(), (qreal) i+1)); + QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); } } @@ -153,7 +158,7 @@ void tst_qpieseries::insert() // check slices for (int i=0; ivalue(), (qreal) i+1)); + QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); } } @@ -187,32 +192,135 @@ void tst_qpieseries::remove() QCOMPARE(s.count(), 0); // check that slices were actually destroyed - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); - QCOMPARE(spy3.count(), 1); + TRY_COMPARE(spy1.count(), 1); + TRY_COMPARE(spy2.count(), 1); + TRY_COMPARE(spy3.count(), 1); } -/* void tst_qpieseries::calculatedValues() { + bool ok; + QPieSeries s; + + // add a slice + QPieSlice *slice1 = s.append(1, "slice 1"); + verifyCalculatedData(s, &ok); + if (!ok) + return; + // add some more slices + QList list; + list << new QPieSlice(2, "slice 2"); + list << new QPieSlice(3, "slice 3"); + s.append(list); + verifyCalculatedData(s, &ok); + if (!ok) + return; + + // remove a slice + s.remove(slice1); + verifyCalculatedData(s, &ok); + if (!ok) + return; + + // insert a slice + s.insert(0, new QPieSlice(1, "Slice 4")); + verifyCalculatedData(s, &ok); + if (!ok) + return; + + // clear all + s.clear(); + verifyCalculatedData(s, &ok); } -void tst_qpieseries::themes() +void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) { + *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); + QCOMPARE(slice->endAngle(), startAngle + sliceSpan); + QCOMPARE(slice->percentage(), ratio); + startAngle += sliceSpan; + } + + if (!series.isEmpty()) + QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); + *ok = true; } + void tst_qpieseries::clickedSignal() { - + // create a pie series + QPieSeries *series = new QPieSeries(); + series->setPieSize(1.0); + QPieSlice *s1 = series->append(1, "slice 1"); + series->append(2, "slice 2"); + series->append(3, "slice 3"); + QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); + + // add series to the chart + QChartView view(new QChart()); + view.resize(200, 200); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + + // simulate clicks + // pie rectangle: QRectF(60,60 121x121) + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(clickSpy1.count(), 1); + QCOMPARE(qvariant_cast(clickSpy1.at(0).at(0)), s1); } void tst_qpieseries::hoverSignal() { - + // create a pie series + QPieSeries *series = new QPieSeries(); + series->setPieSize(1.0); + QPieSlice *s1 = series->append(1, "slice 1"); + series->append(2, "slice 2"); + series->append(3, "slice 3"); + + // add series to the chart + QChartView view(new QChart()); + view.resize(200, 200); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + + // first move to right top corner + QTest::mouseMove(view.viewport(), QPoint(200, 0)); + + // move inside the slice + // pie rectangle: QRectF(60,60 121x121) + QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); + QTest::mouseMove(view.viewport(), QPoint(139, 85)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(hoverSpy.count(), 1); + QCOMPARE(qvariant_cast(hoverSpy.at(0).at(0)), s1); + QCOMPARE(qvariant_cast(hoverSpy.at(0).at(1)), true); + + // move outside the slice + QTest::mouseMove(view.viewport(), QPoint(200, 0)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(hoverSpy.count(), 2); + QCOMPARE(qvariant_cast(hoverSpy.at(1).at(0)), s1); + QCOMPARE(qvariant_cast(hoverSpy.at(1).at(1)), false); } -*/ QTEST_MAIN(tst_qpieseries) diff --git a/test/auto/qpieslice/tst_qpieslice.cpp b/test/auto/qpieslice/tst_qpieslice.cpp index cd92d85..31464eb 100644 --- a/test/auto/qpieslice/tst_qpieslice.cpp +++ b/test/auto/qpieslice/tst_qpieslice.cpp @@ -19,7 +19,11 @@ ****************************************************************************/ #include +#include +#include +#include #include +#include QTCOMMERCIALCHART_USE_NAMESPACE @@ -36,6 +40,9 @@ public slots: private slots: void construction(); void changedSignals(); + void customize(); + void mouseClick(); + void mouseHover(); private: @@ -66,7 +73,7 @@ void tst_qpieslice::construction() { // no params QPieSlice slice1; - QVERIFY(qFuzzyIsNull(slice1.value())); + QCOMPARE(slice1.value(), 0.0); QVERIFY(slice1.label().isEmpty()); QVERIFY(!slice1.isLabelVisible()); QVERIFY(!slice1.isExploded()); @@ -74,15 +81,15 @@ void tst_qpieslice::construction() QCOMPARE(slice1.brush(), QBrush()); QCOMPARE(slice1.labelPen(), QPen()); QCOMPARE(slice1.labelFont(), QFont()); - QVERIFY(qFuzzyCompare(slice1.labelArmLengthFactor(), 0.15)); // default value - QVERIFY(qFuzzyCompare(slice1.explodeDistanceFactor(), 0.15)); // default value - QVERIFY(qFuzzyIsNull(slice1.percentage())); - QVERIFY(qFuzzyIsNull(slice1.startAngle())); - QVERIFY(qFuzzyIsNull(slice1.endAngle())); + QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value + QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value + QCOMPARE(slice1.percentage(), 0.0); + QCOMPARE(slice1.startAngle(), 0.0); + QCOMPARE(slice1.endAngle(), 0.0); // value and label params QPieSlice slice2(1.0, "foobar"); - QVERIFY(qFuzzyCompare(slice2.value(), 1.0)); + QCOMPARE(slice2.value(), 1.0); QCOMPARE(slice2.label(), QString("foobar")); QVERIFY(!slice2.isLabelVisible()); QVERIFY(!slice2.isExploded()); @@ -90,11 +97,11 @@ void tst_qpieslice::construction() QCOMPARE(slice2.brush(), QBrush()); QCOMPARE(slice2.labelPen(), QPen()); QCOMPARE(slice2.labelFont(), QFont()); - QVERIFY(qFuzzyCompare(slice2.labelArmLengthFactor(), 0.15)); // default value - QVERIFY(qFuzzyCompare(slice2.explodeDistanceFactor(), 0.15)); // default value - QVERIFY(qFuzzyIsNull(slice2.percentage())); - QVERIFY(qFuzzyIsNull(slice2.startAngle())); - QVERIFY(qFuzzyIsNull(slice2.endAngle())); + QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value + QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value + QCOMPARE(slice2.percentage(), 0.0); + QCOMPARE(slice2.startAngle(), 0.0); + QCOMPARE(slice2.endAngle(), 0.0); } void tst_qpieslice::changedSignals() @@ -122,7 +129,139 @@ void tst_qpieslice::changedSignals() slice.setLabelArmLengthFactor(0.1); slice.setExplodeDistanceFactor(0.1); slice.setExplodeDistanceFactor(0.1); - QCOMPARE(spy.count(), 10); + TRY_COMPARE(spy.count(), 10); +} + +void tst_qpieslice::customize() +{ + // create a pie series + QPieSeries *series = new QPieSeries(); + QPieSlice *s1 = series->append(1, "slice 1"); + QPieSlice *s2 = series->append(2, "slice 2"); + series->append(3, "slice 3"); + + // customize a slice + QPen p1(Qt::red); + s1->setPen(p1); + QBrush b1(Qt::red); + s1->setBrush(b1); + s1->setLabelPen(p1); + QFont f1("Consolas"); + s1->setLabelFont(f1); + + // add series to the chart + QChartView view(new QChart()); + view.resize(200, 200); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + //QTest::qWait(1000); + + // check that customizations persist + QCOMPARE(s1->pen(), p1); + QCOMPARE(s1->brush(), b1); + QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelFont(), f1); + + // remove a slice + series->remove(s2); + QCOMPARE(s1->pen(), p1); + QCOMPARE(s1->brush(), b1); + QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelFont(), f1); + + // add a slice + series->append(4, "slice 4"); + QCOMPARE(s1->pen(), p1); + QCOMPARE(s1->brush(), b1); + QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelFont(), f1); + + // insert a slice + series->insert(0, new QPieSlice(5, "slice 5")); + QCOMPARE(s1->pen(), p1); + QCOMPARE(s1->brush(), b1); + QCOMPARE(s1->labelPen(), p1); + QCOMPARE(s1->labelFont(), f1); + + // change theme + // theme will overwrite customizations + view.chart()->setTheme(QChart::ChartThemeHighContrast); + QVERIFY(s1->pen() != p1); + QVERIFY(s1->brush() != b1); + QVERIFY(s1->labelPen() != p1); + QVERIFY(s1->labelFont() != f1); +} + +void tst_qpieslice::mouseClick() +{ + // create a pie series + QPieSeries *series = new QPieSeries(); + series->setPieSize(1.0); + QPieSlice *s1 = series->append(1, "slice 1"); + QPieSlice *s2 = series->append(2, "slice 2"); + QPieSlice *s3 = series->append(3, "slice 3"); + QSignalSpy clickSpy1(s1, SIGNAL(clicked())); + QSignalSpy clickSpy2(s2, SIGNAL(clicked())); + QSignalSpy clickSpy3(s3, SIGNAL(clicked())); + + // add series to the chart + QChartView view(new QChart()); + view.resize(200, 200); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + + // simulate clicks + // pie rectangle: QRectF(60,60 121x121) + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(clickSpy1.count(), 1); + QCOMPARE(clickSpy2.count(), 1); + QCOMPARE(clickSpy3.count(), 1); +} + +void tst_qpieslice::mouseHover() +{ + // create a pie series + QPieSeries *series = new QPieSeries(); + series->setPieSize(1.0); + QPieSlice *s1 = series->append(1, "slice 1"); + series->append(2, "slice 2"); + series->append(3, "slice 3"); + + // add series to the chart + QChartView view(new QChart()); + view.resize(200, 200); + view.chart()->addSeries(series); + view.show(); + QTest::qWaitForWindowShown(&view); + + // first move to right top corner + QTest::mouseMove(view.viewport(), QPoint(200, 0)); + + // move inside slice rectangle but NOT the actual slice + // pie rectangle: QRectF(60,60 121x121) + QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); + QTest::mouseMove(view.viewport(), QPoint(170, 70)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(hoverSpy.count(), 0); + + // move inside the slice + QTest::mouseMove(view.viewport(), QPoint(139, 85)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(hoverSpy.count(), 1); + QCOMPARE(qvariant_cast(hoverSpy.at(0).at(0)), true); + + // move outside the slice + QTest::mouseMove(view.viewport(), QPoint(200, 0)); + QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); + QCOMPARE(hoverSpy.count(), 2); + QCOMPARE(qvariant_cast(hoverSpy.at(1).at(0)), false); } QTEST_MAIN(tst_qpieslice) diff --git a/test/auto/qstackedbarseries/qstackedbarseries.pro b/test/auto/qstackedbarseries/qstackedbarseries.pro new file mode 100644 index 0000000..a3d9c51 --- /dev/null +++ b/test/auto/qstackedbarseries/qstackedbarseries.pro @@ -0,0 +1,6 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} +SOURCES += tst_qstackedbarseries.cpp + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp b/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp new file mode 100644 index 0000000..a4ff457 --- /dev/null +++ b/test/auto/qstackedbarseries/tst_qstackedbarseries.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_QStackedBarSeries : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void qstackedbarseries_data(); + void qstackedbarseries(); + void type_data(); + void type(); + +private: + QStackedBarSeries* m_barseries; +}; + +void tst_QStackedBarSeries::initTestCase() +{ +} + +void tst_QStackedBarSeries::cleanupTestCase() +{ +} + +void tst_QStackedBarSeries::init() +{ + m_barseries = new QStackedBarSeries(); +} + +void tst_QStackedBarSeries::cleanup() +{ + delete m_barseries; + m_barseries = 0; +} + +void tst_QStackedBarSeries::qstackedbarseries_data() +{ +} + +void tst_QStackedBarSeries::qstackedbarseries() +{ + QStackedBarSeries *barseries = new QStackedBarSeries(); + QVERIFY(barseries != 0); +} + +void tst_QStackedBarSeries::type_data() +{ + +} + +void tst_QStackedBarSeries::type() +{ + QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); +} + +/* +bool setModel(QAbstractItemModel *model); +void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); +void setModelMappingRange(int first, int count = -1); +*/ +QTEST_MAIN(tst_QStackedBarSeries) + +#include "tst_qstackedbarseries.moc" + diff --git a/test/chartwidgettest/mainwidget.cpp b/test/chartwidgettest/mainwidget.cpp index 4e136b2..f9c7099 100644 --- a/test/chartwidgettest/mainwidget.cpp +++ b/test/chartwidgettest/mainwidget.cpp @@ -272,12 +272,16 @@ void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS foreach(QString label, labels) category << label; QBarSeries* series = 0; - if (seriesName == "Bar") - series = new QBarSeries(category, this); - else if (seriesName == "Stacked bar") - series = new QStackedBarSeries(category, this); - else - series = new QPercentBarSeries(category, this); + if (seriesName == "Bar") { + series = new QBarSeries(this); + series->setCategories(category); + } else if (seriesName == "Stacked bar") { + series = new QStackedBarSeries(this); + series->setCategories(category); + } else { + series = new QPercentBarSeries(this); + series->setCategories(category); + } for (int j(0); j < data.count(); j++) { QList column = data.at(j); diff --git a/test/gdpbarchart/widget.cpp b/test/gdpbarchart/widget.cpp index dfd6673..0cd68ba 100644 --- a/test/gdpbarchart/widget.cpp +++ b/test/gdpbarchart/widget.cpp @@ -140,8 +140,9 @@ void Widget::refreshChart() QStringList category; for (int i = 0; i < selectedCountriesStrings.size(); i++) category << selectedCountriesStrings[i]; - QBarSeries* series0 = new QBarSeries(category); - series0 = new QBarSeries(category); + QBarSeries* series0 = new QBarSeries(); + series0->setCategories(category); +// series0 = new QBarSeries(category); // prepare the selected counries SQL query QString countriesQuery = "country IN ("; diff --git a/test/tablemodelchart/tablewidget.cpp b/test/tablemodelchart/tablewidget.cpp index af81e48..0821ca3 100644 --- a/test/tablemodelchart/tablewidget.cpp +++ b/test/tablemodelchart/tablewidget.cpp @@ -370,7 +370,8 @@ void TableWidget::updateChartType(bool toggle) { m_chart->setAnimationOptions(QChart::SeriesAnimations); - QBarSeries* barSeries = new QBarSeries(QStringList()); + QBarSeries* barSeries = new QBarSeries(); + barSeries->setCategories(QStringList()); barSeries->setModel(m_model); // barSeries->setModelMappingRange(2, 5); barSeries->setModelMapping(5, 2, 4, Qt::Vertical);