@@ -0,0 +1,38 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | import QtQuick 1.0 | |
|
22 | import QtCommercial.Chart 1.0 | |
|
23 | ||
|
24 | Rectangle { | |
|
25 | anchors.fill: parent | |
|
26 | ||
|
27 | Chart { | |
|
28 | title: "Bar series" | |
|
29 | anchors.fill: parent | |
|
30 | theme: Chart.ChartThemeLight | |
|
31 | legend: Chart.LegendBottom | |
|
32 | ||
|
33 | BarSeries { | |
|
34 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
35 | // data implementation missing | |
|
36 | } | |
|
37 | } | |
|
38 | } |
@@ -0,0 +1,38 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #ifndef TST_DEFINITIONS_H | |
|
22 | #define TST_DEFINITIONS_H | |
|
23 | ||
|
24 | #include <QtTest/QtTest> | |
|
25 | ||
|
26 | #define TRY_COMPARE(actual, expected) { \ | |
|
27 | do { \ | |
|
28 | const int timeout(1000); \ | |
|
29 | const int waitStep(30); \ | |
|
30 | /* always wait before comparing to catch possible extra signals */ \ | |
|
31 | QTest::qWait(waitStep); \ | |
|
32 | for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \ | |
|
33 | QTest::qWait(waitStep); \ | |
|
34 | QCOMPARE(actual, expected); \ | |
|
35 | } while (0); \ | |
|
36 | } | |
|
37 | ||
|
38 | #endif // TST_DEFINITIONS_H |
@@ -0,0 +1,6 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | SOURCES += tst_qpercentbarseries.cpp | |
|
5 | ||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,95 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QtTest/QtTest> | |
|
22 | #include <qpercentbarseries.h> | |
|
23 | #include <qbarset.h> | |
|
24 | ||
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
26 | ||
|
27 | class tst_QPercentBarSeries : public QObject | |
|
28 | { | |
|
29 | Q_OBJECT | |
|
30 | ||
|
31 | public slots: | |
|
32 | void initTestCase(); | |
|
33 | void cleanupTestCase(); | |
|
34 | void init(); | |
|
35 | void cleanup(); | |
|
36 | ||
|
37 | private slots: | |
|
38 | void qpercentbarseries_data(); | |
|
39 | void qpercentbarseries(); | |
|
40 | void type_data(); | |
|
41 | void type(); | |
|
42 | ||
|
43 | private: | |
|
44 | QPercentBarSeries* m_barseries; | |
|
45 | }; | |
|
46 | ||
|
47 | void tst_QPercentBarSeries::initTestCase() | |
|
48 | { | |
|
49 | } | |
|
50 | ||
|
51 | void tst_QPercentBarSeries::cleanupTestCase() | |
|
52 | { | |
|
53 | } | |
|
54 | ||
|
55 | void tst_QPercentBarSeries::init() | |
|
56 | { | |
|
57 | m_barseries = new QPercentBarSeries(); | |
|
58 | } | |
|
59 | ||
|
60 | void tst_QPercentBarSeries::cleanup() | |
|
61 | { | |
|
62 | delete m_barseries; | |
|
63 | m_barseries = 0; | |
|
64 | } | |
|
65 | ||
|
66 | void tst_QPercentBarSeries::qpercentbarseries_data() | |
|
67 | { | |
|
68 | } | |
|
69 | ||
|
70 | void tst_QPercentBarSeries::qpercentbarseries() | |
|
71 | { | |
|
72 | QPercentBarSeries *barseries = new QPercentBarSeries(); | |
|
73 | QVERIFY(barseries != 0); | |
|
74 | } | |
|
75 | ||
|
76 | void tst_QPercentBarSeries::type_data() | |
|
77 | { | |
|
78 | ||
|
79 | } | |
|
80 | ||
|
81 | void tst_QPercentBarSeries::type() | |
|
82 | { | |
|
83 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); | |
|
84 | } | |
|
85 | ||
|
86 | ||
|
87 | /* | |
|
88 | bool setModel(QAbstractItemModel *model); | |
|
89 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
|
90 | void setModelMappingRange(int first, int count = -1); | |
|
91 | */ | |
|
92 | QTEST_MAIN(tst_QPercentBarSeries) | |
|
93 | ||
|
94 | #include "tst_qpercentbarseries.moc" | |
|
95 |
@@ -0,0 +1,6 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | SOURCES += tst_qstackedbarseries.cpp | |
|
5 | ||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,94 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include <QtTest/QtTest> | |
|
22 | #include <qstackedbarseries.h> | |
|
23 | #include <qbarset.h> | |
|
24 | ||
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
26 | ||
|
27 | class tst_QStackedBarSeries : public QObject | |
|
28 | { | |
|
29 | Q_OBJECT | |
|
30 | ||
|
31 | public slots: | |
|
32 | void initTestCase(); | |
|
33 | void cleanupTestCase(); | |
|
34 | void init(); | |
|
35 | void cleanup(); | |
|
36 | ||
|
37 | private slots: | |
|
38 | void qstackedbarseries_data(); | |
|
39 | void qstackedbarseries(); | |
|
40 | void type_data(); | |
|
41 | void type(); | |
|
42 | ||
|
43 | private: | |
|
44 | QStackedBarSeries* m_barseries; | |
|
45 | }; | |
|
46 | ||
|
47 | void tst_QStackedBarSeries::initTestCase() | |
|
48 | { | |
|
49 | } | |
|
50 | ||
|
51 | void tst_QStackedBarSeries::cleanupTestCase() | |
|
52 | { | |
|
53 | } | |
|
54 | ||
|
55 | void tst_QStackedBarSeries::init() | |
|
56 | { | |
|
57 | m_barseries = new QStackedBarSeries(); | |
|
58 | } | |
|
59 | ||
|
60 | void tst_QStackedBarSeries::cleanup() | |
|
61 | { | |
|
62 | delete m_barseries; | |
|
63 | m_barseries = 0; | |
|
64 | } | |
|
65 | ||
|
66 | void tst_QStackedBarSeries::qstackedbarseries_data() | |
|
67 | { | |
|
68 | } | |
|
69 | ||
|
70 | void tst_QStackedBarSeries::qstackedbarseries() | |
|
71 | { | |
|
72 | QStackedBarSeries *barseries = new QStackedBarSeries(); | |
|
73 | QVERIFY(barseries != 0); | |
|
74 | } | |
|
75 | ||
|
76 | void tst_QStackedBarSeries::type_data() | |
|
77 | { | |
|
78 | ||
|
79 | } | |
|
80 | ||
|
81 | void tst_QStackedBarSeries::type() | |
|
82 | { | |
|
83 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); | |
|
84 | } | |
|
85 | ||
|
86 | /* | |
|
87 | bool setModel(QAbstractItemModel *model); | |
|
88 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
|
89 | void setModelMappingRange(int first, int count = -1); | |
|
90 | */ | |
|
91 | QTEST_MAIN(tst_QStackedBarSeries) | |
|
92 | ||
|
93 | #include "tst_qstackedbarseries.moc" | |
|
94 |
@@ -9,7 +9,6 examples/*/*/*[.]app | |||
|
9 | 9 | !examples/tutorials/* |
|
10 | 10 | !examples/tutorials/*/* |
|
11 | 11 | !examples/ja_JP/*/* |
|
12 | demos/*/* | |
|
13 | 12 | !demos/spectrum/* |
|
14 | 13 | demos/spectrum/bin |
|
15 | 14 | !demos/*/*[.]* |
@@ -216,7 +216,8 QChart* ThemeWidget::createBarChart(int valueCount) const | |||
|
216 | 216 | for (int i(0); i < valueCount; i++) |
|
217 | 217 | categories << QString::number(i); |
|
218 | 218 | |
|
219 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
|
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
|
220 | series->setCategories(categories); | |
|
220 | 221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | 222 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
222 | 223 | foreach (Data data, m_dataTable[i]) |
@@ -31,9 +31,9 Rectangle { | |||
|
31 | 31 | legend: Chart.LegendBottom |
|
32 | 32 | |
|
33 | 33 | PieSeries { |
|
34 |
horizontalPosition: 0. |
|
|
35 |
verticalPosition: 0. |
|
|
36 |
size: 0. |
|
|
34 | horizontalPosition: 0.5 | |
|
35 | verticalPosition: 0.5 | |
|
36 | size: 0.7 | |
|
37 | 37 | slices: [ |
|
38 | 38 | PieSlice { label: "Volkswagen"; value: 13.5 }, |
|
39 | 39 | PieSlice { label: "Toyota"; value: 10.9 }, |
@@ -43,10 +43,5 Rectangle { | |||
|
43 | 43 | PieSlice { label: "Others"; value: 52.0 } |
|
44 | 44 | ] |
|
45 | 45 | } |
|
46 | ||
|
47 | BarSeries { | |
|
48 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
49 | // data implementation missing | |
|
50 | } | |
|
51 | 46 | } |
|
52 | 47 | } |
@@ -31,20 +31,20 Rectangle { | |||
|
31 | 31 | legend: Chart.LegendTop |
|
32 | 32 | |
|
33 | 33 | AreaSeries { |
|
34 |
name: " |
|
|
34 | name: "Swedish" | |
|
35 | 35 | points: [ |
|
36 |
XyPoint { x: 0; y: |
|
|
37 |
XyPoint { x: 1; y: |
|
|
38 |
XyPoint { x: 2; y: |
|
|
39 |
XyPoint { x: 3; y: |
|
|
40 |
XyPoint { x: 4; y: |
|
|
36 | XyPoint { x: 0; y: 1 }, | |
|
37 | XyPoint { x: 1; y: 1 }, | |
|
38 | XyPoint { x: 2; y: 3 }, | |
|
39 | XyPoint { x: 3; y: 3 }, | |
|
40 | XyPoint { x: 4; y: 2 }, | |
|
41 | 41 | XyPoint { x: 5; y: 0 }, |
|
42 |
XyPoint { x: 6; y: |
|
|
43 |
XyPoint { x: 7; y: |
|
|
44 |
XyPoint { x: 8; y: |
|
|
45 |
XyPoint { x: 9; y: |
|
|
46 |
XyPoint { x: 10; y: |
|
|
47 |
XyPoint { x: 11; y: |
|
|
42 | XyPoint { x: 6; y: 2 }, | |
|
43 | XyPoint { x: 7; y: 1 }, | |
|
44 | XyPoint { x: 8; y: 2 }, | |
|
45 | XyPoint { x: 9; y: 1 }, | |
|
46 | XyPoint { x: 10; y: 3 }, | |
|
47 | XyPoint { x: 11; y: 3 } | |
|
48 | 48 | ] |
|
49 | 49 | lowerPoints: [ |
|
50 | 50 | XyPoint { x: 0; y: 0 }, |
@@ -95,20 +95,20 Rectangle { | |||
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | AreaSeries { |
|
98 |
name: " |
|
|
98 | name: "Finnish" | |
|
99 | 99 | points: [ |
|
100 |
XyPoint { x: 0; y: |
|
|
101 |
XyPoint { x: 1; y: |
|
|
102 |
XyPoint { x: 2; y: |
|
|
103 |
XyPoint { x: 3; y: |
|
|
104 |
XyPoint { x: 4; y: |
|
|
100 | XyPoint { x: 0; y: 0 }, | |
|
101 | XyPoint { x: 1; y: 0 }, | |
|
102 | XyPoint { x: 2; y: 0 }, | |
|
103 | XyPoint { x: 3; y: 0 }, | |
|
104 | XyPoint { x: 4; y: 0 }, | |
|
105 | 105 | XyPoint { x: 5; y: 0 }, |
|
106 |
XyPoint { x: 6; y: |
|
|
107 |
XyPoint { x: 7; y: |
|
|
108 |
XyPoint { x: 8; y: |
|
|
109 |
XyPoint { x: 9; y: |
|
|
110 |
XyPoint { x: 10; y: |
|
|
111 |
XyPoint { x: 11; y: |
|
|
106 | XyPoint { x: 6; y: 1 }, | |
|
107 | XyPoint { x: 7; y: 0 }, | |
|
108 | XyPoint { x: 8; y: 0 }, | |
|
109 | XyPoint { x: 9; y: 0 }, | |
|
110 | XyPoint { x: 10; y: 0 }, | |
|
111 | XyPoint { x: 11; y: 1 } | |
|
112 | 112 | ] |
|
113 | 113 | lowerPoints: [ |
|
114 | 114 | XyPoint { x: 0; y: 0 }, |
@@ -40,7 +40,7 Rectangle { | |||
|
40 | 40 | Loader { |
|
41 | 41 | id: loader |
|
42 | 42 | anchors.fill: parent |
|
43 |
source: "View" + (__viewNumber % |
|
|
43 | source: "View" + (__viewNumber % 5 + 1) + ".qml"; | |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | MouseArea { |
@@ -6,5 +6,6 | |||
|
6 | 6 | <file>qml/qmlchart/View2.qml</file> |
|
7 | 7 | <file>qml/qmlchart/View3.qml</file> |
|
8 | 8 | <file>qml/qmlchart/View4.qml</file> |
|
9 | <file>qml/qmlchart/View5.qml</file> | |
|
9 | 10 | </qresource> |
|
10 | 11 | </RCC> |
@@ -51,7 +51,8 int main(int argc, char *argv[]) | |||
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QBarSeries* series = new QBarSeries( |
|
|
54 | QBarSeries* series = new QBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
@@ -51,7 +51,8 int main(int argc, char *argv[]) | |||
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QPercentBarSeries* series = new QPercentBarSeries( |
|
|
54 | QPercentBarSeries* series = new QPercentBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
@@ -51,7 +51,8 int main(int argc, char *argv[]) | |||
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
|
54 | QStackedBarSeries* series = new QStackedBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
@@ -23,8 +23,9 | |||
|
23 | 23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) |
|
26 |
: QStackedBarSeries( |
|
|
26 | : QStackedBarSeries(parent) | |
|
27 | 27 | { |
|
28 | setCategories(categories); | |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
@@ -30,11 +30,6 DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : | |||
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | QAbstractSeries *DeclarativeAreaSeries::series() | |
|
34 | { | |
|
35 | return this; | |
|
36 | } | |
|
37 | ||
|
38 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints); |
@@ -37,7 +37,6 public: | |||
|
37 | 37 | explicit DeclarativeAreaSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints(); |
|
43 | 42 |
@@ -50,7 +50,9 void DeclarativeBarSeries::setBarCategories(QStringList categories) | |||
|
50 | 50 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
51 | 51 | Q_ASSERT(chart); |
|
52 | 52 | |
|
53 | m_series = new QBarSeries(m_categories); | |
|
53 | // m_series = new QBarSeries(m_categories); | |
|
54 | m_series = new QBarSeries(); | |
|
55 | m_series->setCategories(m_categories); | |
|
54 | 56 | |
|
55 | 57 | // TODO: use data from model |
|
56 | 58 | QBarSet *set0 = new QBarSet("Bub"); |
@@ -19,6 +19,7 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativechart.h" |
|
22 | #include "declarativepieseries.h" | |
|
22 | 23 | #include <QPainter> |
|
23 | 24 | |
|
24 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -36,6 +37,26 DeclarativeChart::~DeclarativeChart() | |||
|
36 | 37 | delete m_chart; |
|
37 | 38 | } |
|
38 | 39 | |
|
40 | void DeclarativeChart::childEvent(QChildEvent *event) | |
|
41 | { | |
|
42 | if (event->type() == QEvent::ChildAdded) { | |
|
43 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
|
44 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
|
45 | } | |
|
46 | } | |
|
47 | } | |
|
48 | ||
|
49 | void DeclarativeChart::componentComplete() | |
|
50 | { | |
|
51 | foreach(QObject *child, children()) { | |
|
52 | if (qobject_cast<QAbstractSeries *>(child)) { | |
|
53 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
|
54 | } | |
|
55 | } | |
|
56 | ||
|
57 | QDeclarativeItem::componentComplete(); | |
|
58 | } | |
|
59 | ||
|
39 | 60 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
40 | 61 | { |
|
41 | 62 | Q_UNUSED(oldGeometry) |
@@ -53,6 +53,8 public: | |||
|
53 | 53 | ~DeclarativeChart(); |
|
54 | 54 | |
|
55 | 55 | public: // From QDeclarativeItem/QGraphicsItem |
|
56 | void childEvent(QChildEvent *event); | |
|
57 | void componentComplete(); | |
|
56 | 58 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
57 | 59 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
58 | 60 |
@@ -30,11 +30,6 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : | |||
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | QAbstractSeries *DeclarativeLineSeries::series() | |
|
34 | { | |
|
35 | return this; | |
|
36 | } | |
|
37 | ||
|
38 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
@@ -37,7 +37,6 public: | |||
|
37 | 37 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 |
@@ -25,25 +25,10 | |||
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
28 |
QPieSeries(parent) |
|
|
29 | m_chart(0) | |
|
28 | QPieSeries(parent) | |
|
30 | 29 | { |
|
31 | 30 | } |
|
32 | 31 | |
|
33 | void DeclarativePieSeries::classBegin() | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | void DeclarativePieSeries::componentComplete() | |
|
38 | { | |
|
39 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
|
40 | if (declarativeChart) { | |
|
41 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
|
42 | Q_ASSERT(chart); | |
|
43 | chart->addSeries(this); | |
|
44 | } | |
|
45 | } | |
|
46 | ||
|
47 | 32 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices() |
|
48 | 33 | { |
|
49 | 34 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice); |
@@ -24,32 +24,24 | |||
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qpieslice.h" |
|
26 | 26 | #include "qpieseries.h" |
|
27 |
#include <QDeclarative |
|
|
27 | #include <QDeclarativeListProperty> | |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QChart; |
|
32 | 32 | |
|
33 |
class DeclarativePieSeries : public QPieSeries |
|
|
33 | class DeclarativePieSeries : public QPieSeries | |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | Q_INTERFACES(QDeclarativeParserStatus) | |
|
37 | 36 | Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices) |
|
38 | 37 | |
|
39 | 38 | public: |
|
40 | 39 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
41 | 40 | QDeclarativeListProperty<QPieSlice> slices(); |
|
42 | 41 | |
|
43 | public: // from QDeclarativeParserStatus | |
|
44 | void classBegin(); | |
|
45 | void componentComplete(); | |
|
46 | ||
|
47 | 42 | public Q_SLOTS: |
|
48 | 43 | static void appendSlice(QDeclarativeListProperty<QPieSlice> *list, |
|
49 | 44 | QPieSlice *element); |
|
50 | ||
|
51 | private: | |
|
52 | QChart *m_chart; | |
|
53 | 45 | }; |
|
54 | 46 | |
|
55 | 47 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -30,11 +30,6 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : | |||
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | QAbstractSeries *DeclarativeScatterSeries::series() | |
|
34 | { | |
|
35 | return this; | |
|
36 | } | |
|
37 | ||
|
38 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
@@ -37,7 +37,6 public: | |||
|
37 | 37 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 |
@@ -29,11 +29,6 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : | |||
|
29 | 29 | { |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | QAbstractSeries *DeclarativeSplineSeries::series() | |
|
33 | { | |
|
34 | return this; | |
|
35 | } | |
|
36 | ||
|
37 | 32 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points() |
|
38 | 33 | { |
|
39 | 34 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
@@ -37,7 +37,6 public: | |||
|
37 | 37 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 |
@@ -33,22 +33,6 DeclarativeXySeries::~DeclarativeXySeries() | |||
|
33 | 33 | { |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | void DeclarativeXySeries::classBegin() | |
|
37 | { | |
|
38 | } | |
|
39 | ||
|
40 | void DeclarativeXySeries::componentComplete() | |
|
41 | { | |
|
42 | QAbstractSeries *thisObj = reinterpret_cast<QAbstractSeries *>(series()); | |
|
43 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent()); | |
|
44 | ||
|
45 | if (declarativeChart) { | |
|
46 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
|
47 | Q_ASSERT(chart); | |
|
48 | chart->addSeries(thisObj); | |
|
49 | } | |
|
50 | } | |
|
51 | ||
|
52 | 36 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
53 | 37 | DeclarativeXyPoint *element) |
|
54 | 38 | { |
@@ -23,7 +23,6 | |||
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "declarativexypoint.h" |
|
26 | #include <QDeclarativeParserStatus> | |
|
27 | 26 | #include <QDeclarativeListProperty> |
|
28 | 27 | |
|
29 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -31,7 +30,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
31 | 30 | class QChart; |
|
32 | 31 | class QAbstractSeries; |
|
33 | 32 | |
|
34 | class DeclarativeXySeries : public QDeclarativeParserStatus | |
|
33 | class DeclarativeXySeries | |
|
35 | 34 | { |
|
36 | 35 | Q_INTERFACES(QDeclarativeParserStatus) |
|
37 | 36 | |
@@ -39,12 +38,7 public: | |||
|
39 | 38 | explicit DeclarativeXySeries(); |
|
40 | 39 | ~DeclarativeXySeries(); |
|
41 | 40 | |
|
42 | public: // from QDeclarativeParserStatus | |
|
43 | virtual void classBegin(); | |
|
44 | virtual void componentComplete(); | |
|
45 | ||
|
46 | 41 | public: |
|
47 | virtual QAbstractSeries *series() = 0; | |
|
48 | 42 | virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0; |
|
49 | 43 | |
|
50 | 44 | public Q_SLOTS: |
@@ -67,8 +67,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
67 | 67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
68 | 68 | QBarSeries is QObject which is a child of a \a parent. |
|
69 | 69 | */ |
|
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : | |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) | |
|
70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : | |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) | |
|
72 | 72 | { |
|
73 | 73 | } |
|
74 | 74 | |
@@ -96,57 +96,90 QAbstractSeries::SeriesType QBarSeries::type() const | |||
|
96 | 96 | return QAbstractSeries::SeriesTypeBar; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | void QBarSeries::setCategories(QBarCategories categories) | |
|
100 | { | |
|
101 | Q_D(QBarSeries); | |
|
102 | d->setCategories(categories); | |
|
103 | emit d->categoriesUpdated(); | |
|
104 | } | |
|
105 | ||
|
99 | 106 | /*! |
|
100 | 107 | Adds a set of bars to series. Takes ownership of \a set. |
|
101 | 108 | */ |
|
102 |
|
|
|
109 | bool QBarSeries::appendBarSet(QBarSet *set) | |
|
103 | 110 | { |
|
104 | 111 | Q_D(QBarSeries); |
|
112 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |
|
113 | // Fail if set is already in list or set is null. | |
|
114 | return false; | |
|
115 | } | |
|
105 | 116 | d->m_barSets.append(set); |
|
106 | 117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
107 | 118 | emit d->restructuredBars(); |
|
119 | return true; | |
|
108 | 120 | } |
|
109 | 121 | |
|
110 | 122 | /*! |
|
111 | 123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
112 | 124 | */ |
|
113 |
|
|
|
125 | bool QBarSeries::removeBarSet(QBarSet *set) | |
|
114 | 126 | { |
|
115 | 127 | Q_D(QBarSeries); |
|
116 | if (d->m_barSets.contains(set)) { | |
|
117 | d->m_barSets.removeOne(set); | |
|
118 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
|
119 | emit d->restructuredBars(); | |
|
128 | if (!d->m_barSets.contains(set)) { | |
|
129 | // Fail if set is not in list | |
|
130 | return false; | |
|
120 | 131 | } |
|
132 | d->m_barSets.removeOne(set); | |
|
133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
|
134 | emit d->restructuredBars(); | |
|
135 | return true; | |
|
121 | 136 | } |
|
122 | 137 | |
|
123 | 138 | /*! |
|
124 | 139 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
125 | 140 | */ |
|
126 |
|
|
|
141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
|
127 | 142 | { |
|
128 | 143 | Q_D(QBarSeries); |
|
129 | 144 | foreach (QBarSet* set, sets) { |
|
145 | if ((set == 0) || (d->m_barSets.contains(set))) { | |
|
146 | // Fail if any of the sets is null or is already appended. | |
|
147 | return false; | |
|
148 | } | |
|
149 | if (sets.count(set) != 1) { | |
|
150 | // Also fail if same set is more than once in given list. | |
|
151 | return false; | |
|
152 | } | |
|
153 | } | |
|
154 | ||
|
155 | foreach (QBarSet* set, sets) { | |
|
130 | 156 | d->m_barSets.append(set); |
|
131 | 157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
132 | 158 | } |
|
133 | 159 | emit d->restructuredBars(); |
|
160 | return true; | |
|
134 | 161 | } |
|
135 | 162 | |
|
136 | 163 | /*! |
|
137 | 164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
138 | 165 | */ |
|
139 |
|
|
|
166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
|
140 | 167 | { |
|
141 | 168 | Q_D(QBarSeries); |
|
142 | 169 | |
|
170 | bool setsRemoved = false; | |
|
143 | 171 | foreach (QBarSet* set, sets) { |
|
144 | 172 | if (d->m_barSets.contains(set)) { |
|
145 | 173 | d->m_barSets.removeOne(set); |
|
146 | 174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
175 | setsRemoved = true; | |
|
147 | 176 | } |
|
148 | 177 | } |
|
149 | emit d->restructuredBars(); | |
|
178 | ||
|
179 | if (setsRemoved) { | |
|
180 | emit d->restructuredBars(); | |
|
181 | } | |
|
182 | return setsRemoved; | |
|
150 | 183 | } |
|
151 | 184 | |
|
152 | 185 | /*! |
@@ -227,15 +260,21 void QBarSeries::setLabelsVisible(bool visible) | |||
|
227 | 260 | |
|
228 | 261 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
229 | 262 | |
|
230 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : | |
|
263 | QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) : | |
|
231 | 264 | QAbstractSeriesPrivate(q), |
|
232 | m_categories(categories), | |
|
265 | // m_categories(categories), | |
|
233 | 266 | m_mapCategories(-1), |
|
234 | 267 | m_mapBarBottom(-1), |
|
235 | 268 | m_mapBarTop(-1) |
|
236 | 269 | { |
|
237 | 270 | } |
|
238 | 271 | |
|
272 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |
|
273 | { | |
|
274 | m_categories = categories; | |
|
275 | } | |
|
276 | ||
|
277 | ||
|
239 | 278 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
240 | 279 | { |
|
241 | 280 | return m_barSets.at(index); |
@@ -39,15 +39,16 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |||
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | public: |
|
42 | explicit QBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
42 | explicit QBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
43 | 43 | virtual ~QBarSeries(); |
|
44 | 44 | |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | void setCategories(QBarCategories categories); | |
|
46 | 47 | |
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
48 | bool appendBarSet(QBarSet *set); // Takes ownership of set | |
|
49 | bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
|
50 | bool appendBarSets(QList<QBarSet* > sets); | |
|
51 | bool removeBarSets(QList<QBarSet* > sets); | |
|
51 | 52 | int barsetCount() const; |
|
52 | 53 | int categoryCount() const; |
|
53 | 54 | QList<QBarSet*> barSets() const; |
@@ -15,7 +15,8 class QBarSeriesPrivate : public QAbstractSeriesPrivate | |||
|
15 | 15 | { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | public: |
|
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); | |
|
18 | QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *parent); | |
|
19 | void setCategories(QBarCategories categories); | |
|
19 | 20 | |
|
20 | 21 | void scaleDomain(Domain& domain); |
|
21 | 22 | Chart* createGraphics(ChartPresenter* presenter); |
@@ -53,8 +53,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
53 | 53 | Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. |
|
54 | 54 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
55 | 55 | */ |
|
56 | QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent) | |
|
57 | : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent) | |
|
56 | QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
|
57 | : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent) | |
|
58 | 58 | { |
|
59 | 59 | } |
|
60 | 60 | |
@@ -65,7 +65,7 QAbstractSeries::SeriesType QPercentBarSeries::type() const | |||
|
65 | 65 | |
|
66 | 66 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
67 | 67 | |
|
68 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QBarCategories categories, QPercentBarSeries *q) : QBarSeriesPrivate(categories,q) | |
|
68 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(/*QBarCategories categories,*/ QPercentBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |
|
69 | 69 | { |
|
70 | 70 | |
|
71 | 71 | } |
@@ -32,8 +32,9 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |||
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | public: |
|
35 | explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
35 | explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
36 | 36 | QAbstractSeries::SeriesType type() const; |
|
37 | ||
|
37 | 38 | private: |
|
38 | 39 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
39 | 40 | Q_DISABLE_COPY(QPercentBarSeries) |
@@ -39,7 +39,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
39 | 39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | QPercentBarSeriesPrivate(QBarCategories categories,QPercentBarSeries* q); | |
|
42 | QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q); | |
|
43 | 43 | void scaleDomain(Domain& domain); |
|
44 | 44 | Chart* createGraphics(ChartPresenter* presenter); |
|
45 | 45 |
@@ -52,8 +52,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
52 | 52 | Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | 53 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
54 | 54 | */ |
|
55 | QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent) | |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent) | |
|
55 | QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent) | |
|
57 | 57 | { |
|
58 | 58 | } |
|
59 | 59 | |
@@ -64,7 +64,7 QAbstractSeries::SeriesType QStackedBarSeries::type() const | |||
|
64 | 64 | |
|
65 | 65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 | 66 | |
|
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QStackedBarSeries *q) : QBarSeriesPrivate(categories,q) | |
|
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(/*QBarCategories categories,*/ QStackedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |
|
68 | 68 | { |
|
69 | 69 | |
|
70 | 70 | } |
@@ -32,8 +32,9 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |||
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | public: |
|
35 | explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
35 | explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
36 | 36 | QAbstractSeries::SeriesType type() const; |
|
37 | ||
|
37 | 38 | private: |
|
38 | 39 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
39 | 40 | Q_DISABLE_COPY(QStackedBarSeries) |
@@ -39,7 +39,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
39 | 39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | QStackedBarSeriesPrivate(QBarCategories categories,QStackedBarSeries* q); | |
|
42 | QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q); | |
|
43 | 43 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | 44 | void scaleDomain(Domain& domain); |
|
45 | 45 |
@@ -4,3 +4,6 | |||
|
4 | 4 | |
|
5 | 5 | CONFIG += qtestlib |
|
6 | 6 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") |
|
7 | ||
|
8 | INCLUDEPATH += ../inc | |
|
9 | HEADERS += ../inc/tst_definitions.h |
@@ -3,7 +3,7 | |||
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries | |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qpieslice qpieseries | |
|
7 | 7 | |
|
8 | 8 | test_private:{ |
|
9 | 9 | SUBDIRS += chartdataset domain |
@@ -23,6 +23,7 | |||
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <private/chartdataset_p.h> |
|
25 | 25 | #include <private/domain_p.h> |
|
26 | #include <tst_definitions.h> | |
|
26 | 27 | |
|
27 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 29 | |
@@ -151,10 +152,10 void tst_ChartDataSet::addSeries() | |||
|
151 | 152 | m_dataset->addSeries(series1,axis1); |
|
152 | 153 | m_dataset->addSeries(series2,axis2); |
|
153 | 154 | |
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
155 | TRY_COMPARE(spy0.count(), axisCount); | |
|
156 | TRY_COMPARE(spy1.count(), 0); | |
|
157 | TRY_COMPARE(spy2.count(), 3); | |
|
158 | TRY_COMPARE(spy3.count(), 0); | |
|
158 | 159 | |
|
159 | 160 | if(axis0==0) axis0 = m_dataset->axisY(); |
|
160 | 161 | if(axis1==0) axis1 = m_dataset->axisY(); |
@@ -193,10 +194,10 void tst_ChartDataSet::removeSeries() | |||
|
193 | 194 | m_dataset->removeSeries(series1); |
|
194 | 195 | m_dataset->removeSeries(series2); |
|
195 | 196 | |
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
197 | TRY_COMPARE(spy0.count(), 0); | |
|
198 | TRY_COMPARE(spy1.count(), axisCount); | |
|
199 | TRY_COMPARE(spy2.count(), 0); | |
|
200 | TRY_COMPARE(spy3.count(), 3); | |
|
200 | 201 | } |
|
201 | 202 | |
|
202 | 203 | void tst_ChartDataSet::removeAllSeries_data() |
@@ -225,10 +226,10 void tst_ChartDataSet::removeAllSeries() | |||
|
225 | 226 | |
|
226 | 227 | m_dataset->removeAllSeries(); |
|
227 | 228 | |
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
229 | TRY_COMPARE(spy0.count(), 0); | |
|
230 | TRY_COMPARE(spy1.count(), 4); | |
|
231 | TRY_COMPARE(spy2.count(), 0); | |
|
232 | TRY_COMPARE(spy3.count(), 3); | |
|
232 | 233 | } |
|
233 | 234 | |
|
234 | 235 | |
@@ -296,10 +297,10 void tst_ChartDataSet::seriesCount() | |||
|
296 | 297 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
297 | 298 | |
|
298 | 299 | QCOMPARE(m_dataset->seriesCount(series0->type()),3); |
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
300 | TRY_COMPARE(spy0.count(), 0); | |
|
301 | TRY_COMPARE(spy1.count(), 0); | |
|
302 | TRY_COMPARE(spy2.count(), 0); | |
|
303 | TRY_COMPARE(spy3.count(), 0); | |
|
303 | 304 | } |
|
304 | 305 | |
|
305 | 306 | void tst_ChartDataSet::seriesIndex_data() |
@@ -333,10 +334,10 void tst_ChartDataSet::seriesIndex() | |||
|
333 | 334 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
334 | 335 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
335 | 336 | |
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
337 | TRY_COMPARE(spy0.count(), 0); | |
|
338 | TRY_COMPARE(spy1.count(), 0); | |
|
339 | TRY_COMPARE(spy2.count(), 0); | |
|
340 | TRY_COMPARE(spy3.count(), 0); | |
|
340 | 341 | |
|
341 | 342 | m_dataset->removeSeries(series0); |
|
342 | 343 | m_dataset->removeSeries(series1); |
@@ -414,10 +415,10 void tst_ChartDataSet::domain() | |||
|
414 | 415 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); |
|
415 | 416 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); |
|
416 | 417 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); |
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
418 | TRY_COMPARE(spy0.count(), 0); | |
|
419 | TRY_COMPARE(spy1.count(), 0); | |
|
420 | TRY_COMPARE(spy2.count(), 0); | |
|
421 | TRY_COMPARE(spy3.count(), 0); | |
|
421 | 422 | } |
|
422 | 423 | |
|
423 | 424 | void tst_ChartDataSet::zoomInDomain_data() |
@@ -450,9 +451,9 void tst_ChartDataSet::zoomInDomain() | |||
|
450 | 451 | |
|
451 | 452 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
452 | 453 | |
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
|
454 | TRY_COMPARE(spy0.count(), 1); | |
|
455 | TRY_COMPARE(spy1.count(), 1); | |
|
456 | TRY_COMPARE(spy2.count(), 1); | |
|
456 | 457 | } |
|
457 | 458 | |
|
458 | 459 | void tst_ChartDataSet::zoomOutDomain_data() |
@@ -486,9 +487,9 void tst_ChartDataSet::zoomOutDomain() | |||
|
486 | 487 | |
|
487 | 488 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
488 | 489 | |
|
489 |
|
|
|
490 |
|
|
|
491 |
|
|
|
490 | TRY_COMPARE(spy0.count(), 1); | |
|
491 | TRY_COMPARE(spy1.count(), 1); | |
|
492 | TRY_COMPARE(spy2.count(), 1); | |
|
492 | 493 | } |
|
493 | 494 | |
|
494 | 495 | void tst_ChartDataSet::scrollDomain_data() |
@@ -522,9 +523,9 void tst_ChartDataSet::scrollDomain() | |||
|
522 | 523 | |
|
523 | 524 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
524 | 525 | |
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
|
526 | TRY_COMPARE(spy0.count(), 1); | |
|
527 | TRY_COMPARE(spy1.count(), 1); | |
|
528 | TRY_COMPARE(spy2.count(), 1); | |
|
528 | 529 | } |
|
529 | 530 | |
|
530 | 531 | QTEST_MAIN(tst_ChartDataSet) |
@@ -21,6 +21,7 | |||
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <private/domain_p.h> |
|
23 | 23 | #include <qaxis.h> |
|
24 | #include <tst_definitions.h> | |
|
24 | 25 | |
|
25 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 27 | |
@@ -132,9 +133,9 void tst_Domain::handleAxisRangeXChanged() | |||
|
132 | 133 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
133 | 134 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
134 | 135 | |
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
136 | TRY_COMPARE(spy0.count(), 1); | |
|
137 | TRY_COMPARE(spy1.count(), 1); | |
|
138 | TRY_COMPARE(spy2.count(), 0); | |
|
138 | 139 | |
|
139 | 140 | } |
|
140 | 141 | |
@@ -168,9 +169,9 void tst_Domain::handleAxisRangeYChanged() | |||
|
168 | 169 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
169 | 170 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
170 | 171 | |
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
172 | TRY_COMPARE(spy0.count(), 1); | |
|
173 | TRY_COMPARE(spy1.count(), 0); | |
|
174 | TRY_COMPARE(spy2.count(), 1); | |
|
174 | 175 | } |
|
175 | 176 | |
|
176 | 177 | void tst_Domain::isEmpty_data() |
@@ -226,9 +227,9 void tst_Domain::maxX() | |||
|
226 | 227 | domain.setMaxX(maxX2); |
|
227 | 228 | QCOMPARE(domain.maxX(), maxX2); |
|
228 | 229 | |
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
230 | TRY_COMPARE(spy0.count(), count); | |
|
231 | TRY_COMPARE(spy1.count(), count); | |
|
232 | TRY_COMPARE(spy2.count(), 0); | |
|
232 | 233 | |
|
233 | 234 | } |
|
234 | 235 | |
@@ -259,9 +260,9 void tst_Domain::maxY() | |||
|
259 | 260 | domain.setMaxY(maxY2); |
|
260 | 261 | QCOMPARE(domain.maxY(), maxY2); |
|
261 | 262 | |
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
263 | TRY_COMPARE(spy0.count(), count); | |
|
264 | TRY_COMPARE(spy1.count(), 0); | |
|
265 | TRY_COMPARE(spy2.count(), count); | |
|
265 | 266 | } |
|
266 | 267 | |
|
267 | 268 | void tst_Domain::minX_data() |
@@ -291,9 +292,9 void tst_Domain::minX() | |||
|
291 | 292 | domain.setMinX(minX2); |
|
292 | 293 | QCOMPARE(domain.minX(), minX2); |
|
293 | 294 | |
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
295 | TRY_COMPARE(spy0.count(), count); | |
|
296 | TRY_COMPARE(spy1.count(), count); | |
|
297 | TRY_COMPARE(spy2.count(), 0); | |
|
297 | 298 | } |
|
298 | 299 | |
|
299 | 300 | void tst_Domain::minY_data() |
@@ -323,9 +324,9 void tst_Domain::minY() | |||
|
323 | 324 | domain.setMinY(minY2); |
|
324 | 325 | QCOMPARE(domain.minY(), minY2); |
|
325 | 326 | |
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
327 | TRY_COMPARE(spy0.count(), count); | |
|
328 | TRY_COMPARE(spy1.count(), 0); | |
|
329 | TRY_COMPARE(spy2.count(), count); | |
|
329 | 330 | } |
|
330 | 331 | |
|
331 | 332 | void tst_Domain::operatorEquals_data() |
@@ -371,9 +372,9 void tst_Domain::operatorEquals() | |||
|
371 | 372 | QCOMPARE(*domain1==*domain2, equals); |
|
372 | 373 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
373 | 374 | |
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
375 | TRY_COMPARE(spy0.count(), 0); | |
|
376 | TRY_COMPARE(spy1.count(), 0); | |
|
377 | TRY_COMPARE(spy2.count(), 0); | |
|
377 | 378 | } |
|
378 | 379 | |
|
379 | 380 | void tst_Domain::setRange_data() |
@@ -407,9 +408,9 void tst_Domain::setRange() | |||
|
407 | 408 | QCOMPARE(domain.minY(), minY); |
|
408 | 409 | QCOMPARE(domain.maxY(), maxY); |
|
409 | 410 | |
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
411 | TRY_COMPARE(spy0.count(), 1); | |
|
412 | TRY_COMPARE(spy1.count(), 1); | |
|
413 | TRY_COMPARE(spy2.count(), 1); | |
|
413 | 414 | |
|
414 | 415 | } |
|
415 | 416 | |
@@ -443,9 +444,9 void tst_Domain::setRangeX() | |||
|
443 | 444 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
444 | 445 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
445 | 446 | |
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
|
447 | TRY_COMPARE(spy0.count(), 1); | |
|
448 | TRY_COMPARE(spy1.count(), 1); | |
|
449 | TRY_COMPARE(spy2.count(), 0); | |
|
449 | 450 | } |
|
450 | 451 | |
|
451 | 452 | void tst_Domain::setRangeY_data() |
@@ -478,9 +479,9 void tst_Domain::setRangeY() | |||
|
478 | 479 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
479 | 480 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
480 | 481 | |
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
482 | TRY_COMPARE(spy0.count(), 1); | |
|
483 | TRY_COMPARE(spy1.count(), 0); | |
|
484 | TRY_COMPARE(spy2.count(), 1); | |
|
484 | 485 | } |
|
485 | 486 | |
|
486 | 487 | void tst_Domain::spanX_data() |
@@ -508,9 +509,9 void tst_Domain::spanX() | |||
|
508 | 509 | |
|
509 | 510 | QCOMPARE(domain.spanX(), spanX); |
|
510 | 511 | |
|
511 |
|
|
|
512 |
|
|
|
513 |
|
|
|
512 | TRY_COMPARE(spy0.count(), 0); | |
|
513 | TRY_COMPARE(spy1.count(), 0); | |
|
514 | TRY_COMPARE(spy2.count(), 0); | |
|
514 | 515 | } |
|
515 | 516 | |
|
516 | 517 | void tst_Domain::spanY_data() |
@@ -538,9 +539,9 void tst_Domain::spanY() | |||
|
538 | 539 | |
|
539 | 540 | QCOMPARE(domain.spanY(), spanY); |
|
540 | 541 | |
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
542 | TRY_COMPARE(spy0.count(), 0); | |
|
543 | TRY_COMPARE(spy1.count(), 0); | |
|
544 | TRY_COMPARE(spy2.count(), 0); | |
|
544 | 545 | } |
|
545 | 546 | |
|
546 | 547 | void tst_Domain::zoom_data() |
@@ -593,10 +594,9 void tst_Domain::zoom() | |||
|
593 | 594 | QCOMPARE(domain == domain1, true); |
|
594 | 595 | domain.zoomOut(rect0, size0); |
|
595 | 596 | QCOMPARE(domain == domain0, true); |
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
|
599 | ||
|
597 | TRY_COMPARE(spy0.count(), 6); | |
|
598 | TRY_COMPARE(spy1.count(), 6); | |
|
599 | TRY_COMPARE(spy2.count(), 6); | |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void tst_Domain::move_data() |
@@ -631,9 +631,9 void tst_Domain::move() | |||
|
631 | 631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
632 | 632 | |
|
633 | 633 | QCOMPARE(domain == result, true); |
|
634 |
|
|
|
635 |
|
|
|
636 |
|
|
|
634 | TRY_COMPARE(spy0.count(), 1); | |
|
635 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); | |
|
636 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); | |
|
637 | 637 | } |
|
638 | 638 | |
|
639 | 639 | void tst_Domain::handleAxisXChanged_data() |
@@ -671,9 +671,9 void tst_Domain::handleAxisXChanged() | |||
|
671 | 671 | QCOMPARE(resultMin, domain.minX()); |
|
672 | 672 | QCOMPARE(resultMax, domain.maxX()); |
|
673 | 673 | QCOMPARE(resultTickCount, domain.tickXCount()); |
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
674 | TRY_COMPARE(spy0.count(), 1); | |
|
675 | TRY_COMPARE(spy1.count(), 1); | |
|
676 | TRY_COMPARE(spy2.count(), 0); | |
|
677 | 677 | |
|
678 | 678 | } |
|
679 | 679 | |
@@ -702,9 +702,9 void tst_Domain::handleAxisYChanged() | |||
|
702 | 702 | QCOMPARE(resultMin, domain.minY()); |
|
703 | 703 | QCOMPARE(resultMax, domain.maxY()); |
|
704 | 704 | QCOMPARE(resultTickCount, domain.tickYCount()); |
|
705 |
|
|
|
706 |
|
|
|
707 |
|
|
|
705 | TRY_COMPARE(spy0.count(), 1); | |
|
706 | TRY_COMPARE(spy1.count(), 0); | |
|
707 | TRY_COMPARE(spy2.count(), 1); | |
|
708 | 708 | } |
|
709 | 709 | |
|
710 | 710 | QTEST_MAIN(tst_Domain) |
@@ -39,6 +39,8 private slots: | |||
|
39 | 39 | void qbarseries(); |
|
40 | 40 | void type_data(); |
|
41 | 41 | void type(); |
|
42 | void setCategories_data(); | |
|
43 | void setCategories(); | |
|
42 | 44 | void appendBarSet_data(); |
|
43 | 45 | void appendBarSet(); |
|
44 | 46 | void removeBarSet_data(); |
@@ -78,8 +80,10 void tst_QBarSeries::cleanupTestCase() | |||
|
78 | 80 | void tst_QBarSeries::init() |
|
79 | 81 | { |
|
80 | 82 | m_categories << "category0" << "category1" << "category2"; |
|
81 |
m_barseries = new QBarSeries( |
|
|
82 |
m_barseries |
|
|
83 | m_barseries = new QBarSeries(); | |
|
84 | m_barseries->setCategories(m_categories); | |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
|
86 | m_barseries_with_sets->setCategories(m_categories); | |
|
83 | 87 | |
|
84 | 88 | for (int i=0; i<5; i++) { |
|
85 | 89 | m_testSets.append(new QBarSet("testset")); |
@@ -113,8 +117,9 void tst_QBarSeries::qbarseries_data() | |||
|
113 | 117 | void tst_QBarSeries::qbarseries() |
|
114 | 118 | { |
|
115 | 119 | QFETCH(QBarCategories, categories); |
|
116 |
QBarSeries *barseries = new QBarSeries( |
|
|
120 | QBarSeries *barseries = new QBarSeries(); | |
|
117 | 121 | QVERIFY(barseries != 0); |
|
122 | barseries->setCategories(categories); | |
|
118 | 123 | QBarCategories verifyCategories = barseries->categories(); |
|
119 | 124 | |
|
120 | 125 | QVERIFY(verifyCategories.count() == categories.count()); |
@@ -133,6 +138,27 void tst_QBarSeries::type() | |||
|
133 | 138 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
134 | 139 | } |
|
135 | 140 | |
|
141 | void tst_QBarSeries::setCategories_data() | |
|
142 | { | |
|
143 | QTest::addColumn<QBarCategories> ("categories"); | |
|
144 | QBarCategories categories; | |
|
145 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; | |
|
146 | QTest::newRow("cat") << categories; | |
|
147 | } | |
|
148 | ||
|
149 | void tst_QBarSeries::setCategories() | |
|
150 | { | |
|
151 | QVERIFY(m_barseries->categories().count() == m_categories.count()); | |
|
152 | ||
|
153 | QFETCH(QBarCategories, categories); | |
|
154 | m_barseries->setCategories(categories); | |
|
155 | ||
|
156 | QVERIFY(m_barseries->categories().count() == categories.count()); | |
|
157 | for (int i=0; i<categories.count(); i++) { | |
|
158 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); | |
|
159 | } | |
|
160 | } | |
|
161 | ||
|
136 | 162 | void tst_QBarSeries::appendBarSet_data() |
|
137 | 163 | { |
|
138 | 164 | } |
@@ -141,15 +167,32 void tst_QBarSeries::appendBarSet() | |||
|
141 | 167 | { |
|
142 | 168 | QVERIFY(m_barseries->barsetCount() == 0); |
|
143 | 169 | |
|
170 | bool ret = false; | |
|
171 | ||
|
172 | // Try adding barset | |
|
144 | 173 | QBarSet *barset = new QBarSet("testset"); |
|
145 | m_barseries->appendBarSet(barset); | |
|
174 | ret = m_barseries->appendBarSet(barset); | |
|
146 | 175 | |
|
176 | QVERIFY(ret == true); | |
|
147 | 177 | QVERIFY(m_barseries->barsetCount() == 1); |
|
148 | 178 | |
|
179 | // Try adding another set | |
|
149 | 180 | QBarSet *barset2 = new QBarSet("testset2"); |
|
150 | m_barseries->appendBarSet(barset2); | |
|
181 | ret = m_barseries->appendBarSet(barset2); | |
|
182 | ||
|
183 | QVERIFY(ret == true); | |
|
184 | QVERIFY(m_barseries->barsetCount() == 2); | |
|
151 | 185 | |
|
186 | // Try adding same set again | |
|
187 | ret = m_barseries->appendBarSet(barset2); | |
|
188 | QVERIFY(ret == false); | |
|
152 | 189 | QVERIFY(m_barseries->barsetCount() == 2); |
|
190 | ||
|
191 | // Try adding null set | |
|
192 | ret = m_barseries->appendBarSet(0); | |
|
193 | QVERIFY(ret == false); | |
|
194 | QVERIFY(m_barseries->barsetCount() == 2); | |
|
195 | ||
|
153 | 196 | } |
|
154 | 197 | |
|
155 | 198 | void tst_QBarSeries::removeBarSet_data() |
@@ -161,10 +204,24 void tst_QBarSeries::removeBarSet() | |||
|
161 | 204 | int count = m_testSets.count(); |
|
162 | 205 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
163 | 206 | |
|
207 | // Try to remove null pointer (should not remove, should not crash) | |
|
208 | bool ret = false; | |
|
209 | ret = m_barseries_with_sets->removeBarSet(0); | |
|
210 | QVERIFY(ret == false); | |
|
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
212 | ||
|
213 | // Try to remove invalid pointer (should not remove, should not crash) | |
|
214 | ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); | |
|
215 | QVERIFY(ret == false); | |
|
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
217 | ||
|
164 | 218 | // remove some sets |
|
165 | m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
|
166 | m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
|
167 |
m_barseries_with_sets->removeBarSet(m_testSets.at( |
|
|
219 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
|
220 | QVERIFY(ret == true); | |
|
221 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
|
222 | QVERIFY(ret == true); | |
|
223 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); | |
|
224 | QVERIFY(ret == true); | |
|
168 | 225 | |
|
169 | 226 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
170 | 227 | |
@@ -173,11 +230,13 void tst_QBarSeries::removeBarSet() | |||
|
173 | 230 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
174 | 231 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
175 | 232 | |
|
176 | // Try removing all sets again | |
|
233 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
|
234 | ret = false; | |
|
177 | 235 | for (int i=0; i<count; i++) { |
|
178 | m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
|
236 | ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
|
179 | 237 | } |
|
180 | 238 | |
|
239 | QVERIFY(ret == true); | |
|
181 | 240 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
182 | 241 | } |
|
183 | 242 | |
@@ -196,7 +255,37 void tst_QBarSeries::appendBarSets() | |||
|
196 | 255 | sets.append(new QBarSet("testset")); |
|
197 | 256 | } |
|
198 | 257 | |
|
199 | m_barseries->appendBarSets(sets); | |
|
258 | // Append new sets (should succeed, count should match the count of sets) | |
|
259 | bool ret = false; | |
|
260 | ret = m_barseries->appendBarSets(sets); | |
|
261 | QVERIFY(ret == true); | |
|
262 | QVERIFY(m_barseries->barsetCount() == count); | |
|
263 | ||
|
264 | // Append same sets again (should fail, count should remain same) | |
|
265 | ret = m_barseries->appendBarSets(sets); | |
|
266 | QVERIFY(ret == false); | |
|
267 | QVERIFY(m_barseries->barsetCount() == count); | |
|
268 | ||
|
269 | // Try append empty list (should succeed, but count should remain same) | |
|
270 | QList<QBarSet*> invalidList; | |
|
271 | ret = m_barseries->appendBarSets(invalidList); | |
|
272 | QVERIFY(ret == true); | |
|
273 | QVERIFY(m_barseries->barsetCount() == count); | |
|
274 | ||
|
275 | // Try append list with one new and one existing set (should fail, count remains same) | |
|
276 | invalidList.append(new QBarSet("ok set")); | |
|
277 | invalidList.append(sets.at(0)); | |
|
278 | ret = m_barseries->appendBarSets(invalidList); | |
|
279 | QVERIFY(ret == false); | |
|
280 | QVERIFY(m_barseries->barsetCount() == count); | |
|
281 | ||
|
282 | // Try append list with null pointers (should fail, count remains same) | |
|
283 | QList<QBarSet*> invalidList2; | |
|
284 | invalidList2.append(0); | |
|
285 | invalidList2.append(0); | |
|
286 | invalidList2.append(0); | |
|
287 | ret = m_barseries->appendBarSets(invalidList2); | |
|
288 | QVERIFY(ret == false); | |
|
200 | 289 | QVERIFY(m_barseries->barsetCount() == count); |
|
201 | 290 | } |
|
202 | 291 | |
@@ -210,21 +299,36 void tst_QBarSeries::removeBarSets() | |||
|
210 | 299 | int count = m_testSets.count(); |
|
211 | 300 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
212 | 301 | |
|
213 | // Try removing empty list of sets | |
|
214 | QList<QBarSet*> empty; | |
|
215 | m_barseries_with_sets->removeBarSets(empty); | |
|
302 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
|
303 | bool ret = false; | |
|
304 | QList<QBarSet*> invalidList; | |
|
305 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
306 | QVERIFY(ret == false); | |
|
216 | 307 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
217 | 308 | |
|
218 | // remove all sets | |
|
219 | m_barseries_with_sets->removeBarSets(m_testSets); | |
|
309 | // Add some null pointers to list | |
|
310 | invalidList.append(0); | |
|
311 | invalidList.append(0); | |
|
312 | invalidList.append(0); | |
|
313 | ||
|
314 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |
|
315 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
316 | QVERIFY(ret == false); | |
|
317 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
318 | ||
|
319 | // remove all sets (should return true, since sets were removed) | |
|
320 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
|
321 | QVERIFY(ret == true); | |
|
220 | 322 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
221 | 323 | |
|
222 | // Try removing empty list again | |
|
223 |
m_barseries_with_sets->removeBarSets( |
|
|
324 | // Try removing invalid list again (should return false, since no barsets were removed) | |
|
325 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
326 | QVERIFY(ret == false); | |
|
224 | 327 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
225 | 328 | |
|
226 | // remove all sets again | |
|
227 | m_barseries_with_sets->removeBarSets(m_testSets); | |
|
329 | // remove all sets again (should return false, since barsets were already removed) | |
|
330 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
|
331 | QVERIFY(ret == false); | |
|
228 | 332 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
229 | 333 | } |
|
230 | 334 | |
@@ -289,25 +393,31 void tst_QBarSeries::setLabelsVisible_data() | |||
|
289 | 393 | |
|
290 | 394 | void tst_QBarSeries::setLabelsVisible() |
|
291 | 395 | { |
|
396 | // labels should be invisible by default | |
|
292 | 397 | foreach (QBarSet* s, m_testSets) { |
|
293 | 398 | QVERIFY(s->labelsVisible() == false); |
|
294 | 399 | } |
|
295 | 400 | |
|
401 | // turn labels to visible | |
|
296 | 402 | m_barseries_with_sets->setLabelsVisible(true); |
|
297 | 403 | foreach (QBarSet* s, m_testSets) { |
|
298 | 404 | QVERIFY(s->labelsVisible() == true); |
|
299 | 405 | } |
|
300 | 406 | |
|
407 | // turn labels to invisible | |
|
301 | 408 | m_barseries_with_sets->setLabelsVisible(false); |
|
302 | 409 | foreach (QBarSet* s, m_testSets) { |
|
303 | 410 | QVERIFY(s->labelsVisible() == false); |
|
304 | 411 | } |
|
412 | ||
|
413 | // without parameter, should turn labels to visible | |
|
414 | m_barseries_with_sets->setLabelsVisible(); | |
|
415 | foreach (QBarSet* s, m_testSets) { | |
|
416 | QVERIFY(s->labelsVisible() == true); | |
|
417 | } | |
|
305 | 418 | } |
|
306 | 419 | |
|
307 | 420 | /* |
|
308 | ||
|
309 | void setLabelsVisible(bool visible = true); | |
|
310 | ||
|
311 | 421 | bool setModel(QAbstractItemModel *model); |
|
312 | 422 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
313 | 423 | void setModelMappingRange(int first, int count = -1); |
@@ -164,9 +164,16 void tst_QChart::addSeries_data() | |||
|
164 | 164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
165 | 165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
166 | 166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
167 |
QAbstractSeries* series5 = new QBarSeries( |
|
|
168 |
QAbstractSeries* series6 = new QPercentBarSeries( |
|
|
169 |
QAbstractSeries* series7 = new QStackedBarSeries( |
|
|
167 | QAbstractSeries* series5 = new QBarSeries(this); | |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
|
170 | ||
|
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); | |
|
172 | s5->setCategories(QBarCategories()); | |
|
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); | |
|
174 | s6->setCategories(QBarCategories()); | |
|
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); | |
|
176 | s7->setCategories(QBarCategories()); | |
|
170 | 177 | |
|
171 | 178 | QAxis* axis = new QAxis(this); |
|
172 | 179 | |
@@ -550,17 +557,27 void tst_QChart::zoomOut() | |||
|
550 | 557 | |
|
551 | 558 | m_chart->zoomIn(); |
|
552 | 559 | |
|
553 | QVERIFY(minX<m_chart->axisX()->min()); | |
|
554 | QVERIFY(maxX>m_chart->axisX()->max()); | |
|
555 | QVERIFY(minY<m_chart->axisY()->min()); | |
|
556 | QVERIFY(maxY>m_chart->axisY()->max()); | |
|
560 | QVERIFY(minX < m_chart->axisX()->min()); | |
|
561 | QVERIFY(maxX > m_chart->axisX()->max()); | |
|
562 | QVERIFY(minY < m_chart->axisY()->min()); | |
|
563 | QVERIFY(maxY > m_chart->axisY()->max()); | |
|
557 | 564 | |
|
558 | 565 | m_chart->zoomOut(); |
|
559 | 566 | |
|
560 | QVERIFY(minX==m_chart->axisX()->min()); | |
|
561 | QVERIFY(maxX==m_chart->axisX()->max()); | |
|
562 |
QVERIFY( |
|
|
563 | QVERIFY(maxY==m_chart->axisY()->max()); | |
|
567 | // min x may be a zero value | |
|
568 | if (qFuzzyIsNull(minX)) | |
|
569 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
|
570 | else | |
|
571 | QCOMPARE(minX, m_chart->axisX()->min()); | |
|
572 | ||
|
573 | // min y may be a zero value | |
|
574 | if (qFuzzyIsNull(minY)) | |
|
575 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
|
576 | else | |
|
577 | QCOMPARE(minY, m_chart->axisY()->min()); | |
|
578 | ||
|
579 | QVERIFY(maxX == m_chart->axisX()->max()); | |
|
580 | QVERIFY(maxY == m_chart->axisY()->max()); | |
|
564 | 581 | } |
|
565 | 582 | |
|
566 | 583 | QTEST_MAIN(tst_QChart) |
@@ -22,6 +22,7 | |||
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <cmath> |
|
25 | #include <tst_definitions.h> | |
|
25 | 26 | |
|
26 | 27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 28 | |
@@ -153,8 +154,8 void tst_QChartView::rubberBand() | |||
|
153 | 154 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
154 | 155 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
155 | 156 | |
|
156 |
|
|
|
157 |
|
|
|
157 | TRY_COMPARE(spy0.count(), Xcount); | |
|
158 | TRY_COMPARE(spy1.count(), Ycount); | |
|
158 | 159 | |
|
159 | 160 | //this is hack since view does not get events otherwise |
|
160 | 161 | m_view->setMouseTracking(false); |
@@ -22,6 +22,7 | |||
|
22 | 22 | #include <qlineseries.h> |
|
23 | 23 | #include <qchartview.h> |
|
24 | 24 | #include <QStandardItemModel> |
|
25 | #include <tst_definitions.h> | |
|
25 | 26 | |
|
26 | 27 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
27 | 28 | |
@@ -173,10 +174,8 void tst_QLineSeries::append_raw() | |||
|
173 | 174 | { |
|
174 | 175 | QFETCH(QList<QPointF>, points); |
|
175 | 176 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
176 | QTest::qWait(200); | |
|
177 | 177 | m_series->append(points); |
|
178 | QTest::qWait(200); | |
|
179 | QCOMPARE(spy0.count(), 0); | |
|
178 | TRY_COMPARE(spy0.count(), 0); | |
|
180 | 179 | QCOMPARE(m_series->points(), points); |
|
181 | 180 | } |
|
182 | 181 | |
@@ -240,7 +239,7 void tst_QLineSeries::count_raw() | |||
|
240 | 239 | for(int i=0 ; i< count; ++i) |
|
241 | 240 | m_series->append(i,i); |
|
242 | 241 | |
|
243 |
|
|
|
242 | TRY_COMPARE(spy0.count(), 0); | |
|
244 | 243 | QCOMPARE(m_series->count(), count); |
|
245 | 244 | } |
|
246 | 245 | |
@@ -262,7 +261,7 void tst_QLineSeries::oper() | |||
|
262 | 261 | } |
|
263 | 262 | |
|
264 | 263 | QCOMPARE(series.points(), points); |
|
265 |
|
|
|
264 | TRY_COMPARE(spy0.count(), 0); | |
|
266 | 265 | } |
|
267 | 266 | |
|
268 | 267 | |
@@ -283,7 +282,7 void tst_QLineSeries::pen() | |||
|
283 | 282 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); |
|
284 | 283 | series.setPen(pen); |
|
285 | 284 | |
|
286 |
|
|
|
285 | TRY_COMPARE(spy0.count(), 0); | |
|
287 | 286 | QCOMPARE(series.pen(), pen); |
|
288 | 287 | |
|
289 | 288 | m_chart->addSeries(&series); |
@@ -312,7 +311,7 void tst_QLineSeries::pointsVisible_raw() | |||
|
312 | 311 | QFETCH(bool, pointsVisible); |
|
313 | 312 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
314 | 313 | m_series->setPointsVisible(pointsVisible); |
|
315 |
|
|
|
314 | TRY_COMPARE(spy0.count(), 0); | |
|
316 | 315 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
317 | 316 | } |
|
318 | 317 | |
@@ -326,17 +325,13 void tst_QLineSeries::remove_raw() | |||
|
326 | 325 | QFETCH(QList<QPointF>, points); |
|
327 | 326 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
328 | 327 | m_series->append(points); |
|
329 | QTest::qWait(200); | |
|
330 | QCOMPARE(spy0.count(), 0); | |
|
328 | TRY_COMPARE(spy0.count(), 0); | |
|
331 | 329 | QCOMPARE(m_series->points(), points); |
|
332 | 330 | |
|
333 | 331 | foreach(const QPointF& point,points) |
|
334 | { | |
|
335 | 332 | m_series->remove(point); |
|
336 | QTest::qWait(200); | |
|
337 | } | |
|
338 | 333 | |
|
339 |
|
|
|
334 | TRY_COMPARE(spy0.count(), 0); | |
|
340 | 335 | QCOMPARE(m_series->points().count(), 0); |
|
341 | 336 | } |
|
342 | 337 | |
@@ -375,12 +370,10 void tst_QLineSeries::removeAll_raw() | |||
|
375 | 370 | QFETCH(QList<QPointF>, points); |
|
376 | 371 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
377 | 372 | m_series->append(points); |
|
378 |
|
|
|
373 | TRY_COMPARE(spy0.count(), 0); | |
|
379 | 374 | QCOMPARE(m_series->points(), points); |
|
380 | QTest::qWait(200); | |
|
381 | 375 | m_series->removeAll(); |
|
382 | QTest::qWait(200); | |
|
383 | QCOMPARE(spy0.count(), 0); | |
|
376 | TRY_COMPARE(spy0.count(), 0); | |
|
384 | 377 | QCOMPARE(m_series->points().count(), 0); |
|
385 | 378 | } |
|
386 | 379 | |
@@ -418,15 +411,11 void tst_QLineSeries::replace_raw() | |||
|
418 | 411 | QFETCH(QList<QPointF>, points); |
|
419 | 412 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
420 | 413 | m_series->append(points); |
|
421 |
|
|
|
414 | TRY_COMPARE(spy0.count(), 0); | |
|
422 | 415 | QCOMPARE(m_series->points(), points); |
|
423 | QTest::qWait(200); | |
|
424 | 416 | |
|
425 | 417 | foreach(const QPointF& point,points) |
|
426 | { | |
|
427 | m_series->replace(point.x(),point.y(),point.x(),0); | |
|
428 | QTest::qWait(200); | |
|
429 | } | |
|
418 | m_series->replace(point.x(),point.y(),point.x(),0); | |
|
430 | 419 | |
|
431 | 420 | QList<QPointF> newPoints = m_series->points(); |
|
432 | 421 |
@@ -19,11 +19,16 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | #include <qchartview.h> | |
|
23 | #include <qchart.h> | |
|
22 | 24 | #include <qpieseries.h> |
|
23 | 25 | #include <qpieslice.h> |
|
26 | #include <tst_definitions.h> | |
|
24 | 27 | |
|
25 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 29 | |
|
30 | Q_DECLARE_METATYPE(QPieSlice*) | |
|
31 | ||
|
27 | 32 | class tst_qpieseries : public QObject |
|
28 | 33 | { |
|
29 | 34 | Q_OBJECT |
@@ -39,13 +44,12 private slots: | |||
|
39 | 44 | void append(); |
|
40 | 45 | void insert(); |
|
41 | 46 | void remove(); |
|
42 |
|
|
|
43 | //void themes(); | |
|
44 |
|
|
|
45 | //void hoverSignal(); | |
|
47 | void calculatedValues(); | |
|
48 | void clickedSignal(); | |
|
49 | void hoverSignal(); | |
|
46 | 50 | |
|
47 | 51 | private: |
|
48 | ||
|
52 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
|
49 | 53 | |
|
50 | 54 | private: |
|
51 | 55 | |
@@ -53,6 +57,7 private: | |||
|
53 | 57 | |
|
54 | 58 | void tst_qpieseries::initTestCase() |
|
55 | 59 | { |
|
60 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
|
56 | 61 | } |
|
57 | 62 | |
|
58 | 63 | void tst_qpieseries::cleanupTestCase() |
@@ -76,12 +81,12 void tst_qpieseries::construction() | |||
|
76 | 81 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); |
|
77 | 82 | QVERIFY(s.count() == 0); |
|
78 | 83 | QVERIFY(s.isEmpty()); |
|
79 | QVERIFY(qFuzzyIsNull(s.sum())); | |
|
80 |
Q |
|
|
81 |
Q |
|
|
82 |
Q |
|
|
83 |
Q |
|
|
84 |
Q |
|
|
84 | QCOMPARE(s.sum(), 0.0); | |
|
85 | QCOMPARE(s.horizontalPosition(), 0.5); | |
|
86 | QCOMPARE(s.verticalPosition(), 0.5); | |
|
87 | QCOMPARE(s.pieSize(), 0.7); | |
|
88 | QCOMPARE(s.pieStartAngle(), 0.0); | |
|
89 | QCOMPARE(s.pieEndAngle(), 360.0); | |
|
85 | 90 | } |
|
86 | 91 | |
|
87 | 92 | void tst_qpieseries::append() |
@@ -116,14 +121,14 void tst_qpieseries::append() | |||
|
116 | 121 | // append with params |
|
117 | 122 | QPieSlice *slice5 = s.append(5, "slice 5"); |
|
118 | 123 | QVERIFY(slice5 != 0); |
|
119 |
Q |
|
|
124 | QCOMPARE(slice5->value(), 5.0); | |
|
120 | 125 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
121 | 126 | QCOMPARE(s.count(), 5); |
|
122 | 127 | |
|
123 | 128 | // check slices |
|
124 | 129 | QVERIFY(!s.isEmpty()); |
|
125 | 130 | for (int i=0; i<s.count(); i++) { |
|
126 |
Q |
|
|
131 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
|
127 | 132 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
128 | 133 | } |
|
129 | 134 | } |
@@ -153,7 +158,7 void tst_qpieseries::insert() | |||
|
153 | 158 | |
|
154 | 159 | // check slices |
|
155 | 160 | for (int i=0; i<s.count(); i++) { |
|
156 |
Q |
|
|
161 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
|
157 | 162 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
158 | 163 | } |
|
159 | 164 | } |
@@ -187,32 +192,135 void tst_qpieseries::remove() | |||
|
187 | 192 | QCOMPARE(s.count(), 0); |
|
188 | 193 | |
|
189 | 194 | // check that slices were actually destroyed |
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
195 | TRY_COMPARE(spy1.count(), 1); | |
|
196 | TRY_COMPARE(spy2.count(), 1); | |
|
197 | TRY_COMPARE(spy3.count(), 1); | |
|
193 | 198 | } |
|
194 | 199 | |
|
195 | /* | |
|
196 | 200 | void tst_qpieseries::calculatedValues() |
|
197 | 201 | { |
|
202 | bool ok; | |
|
203 | QPieSeries s; | |
|
204 | ||
|
205 | // add a slice | |
|
206 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
|
207 | verifyCalculatedData(s, &ok); | |
|
208 | if (!ok) | |
|
209 | return; | |
|
198 | 210 | |
|
211 | // add some more slices | |
|
212 | QList<QPieSlice *> list; | |
|
213 | list << new QPieSlice(2, "slice 2"); | |
|
214 | list << new QPieSlice(3, "slice 3"); | |
|
215 | s.append(list); | |
|
216 | verifyCalculatedData(s, &ok); | |
|
217 | if (!ok) | |
|
218 | return; | |
|
219 | ||
|
220 | // remove a slice | |
|
221 | s.remove(slice1); | |
|
222 | verifyCalculatedData(s, &ok); | |
|
223 | if (!ok) | |
|
224 | return; | |
|
225 | ||
|
226 | // insert a slice | |
|
227 | s.insert(0, new QPieSlice(1, "Slice 4")); | |
|
228 | verifyCalculatedData(s, &ok); | |
|
229 | if (!ok) | |
|
230 | return; | |
|
231 | ||
|
232 | // clear all | |
|
233 | s.clear(); | |
|
234 | verifyCalculatedData(s, &ok); | |
|
199 | 235 | } |
|
200 | 236 | |
|
201 | void tst_qpieseries::themes() | |
|
237 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
|
202 | 238 | { |
|
239 | *ok = false; | |
|
240 | ||
|
241 | qreal sum = 0; | |
|
242 | foreach (const QPieSlice *slice, series.slices()) | |
|
243 | sum += slice->value(); | |
|
244 | QCOMPARE(series.sum(), sum); | |
|
245 | ||
|
246 | qreal startAngle = series.pieStartAngle(); | |
|
247 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
|
248 | foreach (const QPieSlice *slice, series.slices()) { | |
|
249 | qreal ratio = slice->value() / sum; | |
|
250 | qreal sliceSpan = pieAngleSpan * ratio; | |
|
251 | QCOMPARE(slice->startAngle(), startAngle); | |
|
252 | QCOMPARE(slice->endAngle(), startAngle + sliceSpan); | |
|
253 | QCOMPARE(slice->percentage(), ratio); | |
|
254 | startAngle += sliceSpan; | |
|
255 | } | |
|
256 | ||
|
257 | if (!series.isEmpty()) | |
|
258 | QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); | |
|
203 | 259 | |
|
260 | *ok = true; | |
|
204 | 261 | } |
|
205 | 262 | |
|
263 | ||
|
206 | 264 | void tst_qpieseries::clickedSignal() |
|
207 | 265 | { |
|
208 | ||
|
266 | // create a pie series | |
|
267 | QPieSeries *series = new QPieSeries(); | |
|
268 | series->setPieSize(1.0); | |
|
269 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
270 | series->append(2, "slice 2"); | |
|
271 | series->append(3, "slice 3"); | |
|
272 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); | |
|
273 | ||
|
274 | // add series to the chart | |
|
275 | QChartView view(new QChart()); | |
|
276 | view.resize(200, 200); | |
|
277 | view.chart()->addSeries(series); | |
|
278 | view.show(); | |
|
279 | QTest::qWaitForWindowShown(&view); | |
|
280 | ||
|
281 | // simulate clicks | |
|
282 | // pie rectangle: QRectF(60,60 121x121) | |
|
283 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
|
284 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
285 | QCOMPARE(clickSpy1.count(), 1); | |
|
286 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy1.at(0).at(0)), s1); | |
|
209 | 287 | } |
|
210 | 288 | |
|
211 | 289 | void tst_qpieseries::hoverSignal() |
|
212 | 290 | { |
|
213 | ||
|
291 | // create a pie series | |
|
292 | QPieSeries *series = new QPieSeries(); | |
|
293 | series->setPieSize(1.0); | |
|
294 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
295 | series->append(2, "slice 2"); | |
|
296 | series->append(3, "slice 3"); | |
|
297 | ||
|
298 | // add series to the chart | |
|
299 | QChartView view(new QChart()); | |
|
300 | view.resize(200, 200); | |
|
301 | view.chart()->addSeries(series); | |
|
302 | view.show(); | |
|
303 | QTest::qWaitForWindowShown(&view); | |
|
304 | ||
|
305 | // first move to right top corner | |
|
306 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
307 | ||
|
308 | // move inside the slice | |
|
309 | // pie rectangle: QRectF(60,60 121x121) | |
|
310 | QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); | |
|
311 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
|
312 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
313 | QCOMPARE(hoverSpy.count(), 1); | |
|
314 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |
|
315 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |
|
316 | ||
|
317 | // move outside the slice | |
|
318 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
319 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
320 | QCOMPARE(hoverSpy.count(), 2); | |
|
321 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |
|
322 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |
|
214 | 323 | } |
|
215 | */ | |
|
216 | 324 | |
|
217 | 325 | QTEST_MAIN(tst_qpieseries) |
|
218 | 326 |
@@ -19,7 +19,11 | |||
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | #include <tst_definitions.h> | |
|
23 | #include <qchartview.h> | |
|
24 | #include <qchart.h> | |
|
22 | 25 | #include <qpieslice.h> |
|
26 | #include <qpieseries.h> | |
|
23 | 27 | |
|
24 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | 29 | |
@@ -36,6 +40,9 public slots: | |||
|
36 | 40 | private slots: |
|
37 | 41 | void construction(); |
|
38 | 42 | void changedSignals(); |
|
43 | void customize(); | |
|
44 | void mouseClick(); | |
|
45 | void mouseHover(); | |
|
39 | 46 | |
|
40 | 47 | private: |
|
41 | 48 | |
@@ -66,7 +73,7 void tst_qpieslice::construction() | |||
|
66 | 73 | { |
|
67 | 74 | // no params |
|
68 | 75 | QPieSlice slice1; |
|
69 |
Q |
|
|
76 | QCOMPARE(slice1.value(), 0.0); | |
|
70 | 77 | QVERIFY(slice1.label().isEmpty()); |
|
71 | 78 | QVERIFY(!slice1.isLabelVisible()); |
|
72 | 79 | QVERIFY(!slice1.isExploded()); |
@@ -74,15 +81,15 void tst_qpieslice::construction() | |||
|
74 | 81 | QCOMPARE(slice1.brush(), QBrush()); |
|
75 | 82 | QCOMPARE(slice1.labelPen(), QPen()); |
|
76 | 83 | QCOMPARE(slice1.labelFont(), QFont()); |
|
77 |
Q |
|
|
78 |
Q |
|
|
79 |
Q |
|
|
80 |
Q |
|
|
81 |
Q |
|
|
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value | |
|
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value | |
|
86 | QCOMPARE(slice1.percentage(), 0.0); | |
|
87 | QCOMPARE(slice1.startAngle(), 0.0); | |
|
88 | QCOMPARE(slice1.endAngle(), 0.0); | |
|
82 | 89 | |
|
83 | 90 | // value and label params |
|
84 | 91 | QPieSlice slice2(1.0, "foobar"); |
|
85 |
Q |
|
|
92 | QCOMPARE(slice2.value(), 1.0); | |
|
86 | 93 | QCOMPARE(slice2.label(), QString("foobar")); |
|
87 | 94 | QVERIFY(!slice2.isLabelVisible()); |
|
88 | 95 | QVERIFY(!slice2.isExploded()); |
@@ -90,11 +97,11 void tst_qpieslice::construction() | |||
|
90 | 97 | QCOMPARE(slice2.brush(), QBrush()); |
|
91 | 98 | QCOMPARE(slice2.labelPen(), QPen()); |
|
92 | 99 | QCOMPARE(slice2.labelFont(), QFont()); |
|
93 |
Q |
|
|
94 |
Q |
|
|
95 |
Q |
|
|
96 |
Q |
|
|
97 |
Q |
|
|
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value | |
|
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value | |
|
102 | QCOMPARE(slice2.percentage(), 0.0); | |
|
103 | QCOMPARE(slice2.startAngle(), 0.0); | |
|
104 | QCOMPARE(slice2.endAngle(), 0.0); | |
|
98 | 105 | } |
|
99 | 106 | |
|
100 | 107 | void tst_qpieslice::changedSignals() |
@@ -122,7 +129,139 void tst_qpieslice::changedSignals() | |||
|
122 | 129 | slice.setLabelArmLengthFactor(0.1); |
|
123 | 130 | slice.setExplodeDistanceFactor(0.1); |
|
124 | 131 | slice.setExplodeDistanceFactor(0.1); |
|
125 |
|
|
|
132 | TRY_COMPARE(spy.count(), 10); | |
|
133 | } | |
|
134 | ||
|
135 | void tst_qpieslice::customize() | |
|
136 | { | |
|
137 | // create a pie series | |
|
138 | QPieSeries *series = new QPieSeries(); | |
|
139 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
140 | QPieSlice *s2 = series->append(2, "slice 2"); | |
|
141 | series->append(3, "slice 3"); | |
|
142 | ||
|
143 | // customize a slice | |
|
144 | QPen p1(Qt::red); | |
|
145 | s1->setPen(p1); | |
|
146 | QBrush b1(Qt::red); | |
|
147 | s1->setBrush(b1); | |
|
148 | s1->setLabelPen(p1); | |
|
149 | QFont f1("Consolas"); | |
|
150 | s1->setLabelFont(f1); | |
|
151 | ||
|
152 | // add series to the chart | |
|
153 | QChartView view(new QChart()); | |
|
154 | view.resize(200, 200); | |
|
155 | view.chart()->addSeries(series); | |
|
156 | view.show(); | |
|
157 | QTest::qWaitForWindowShown(&view); | |
|
158 | //QTest::qWait(1000); | |
|
159 | ||
|
160 | // check that customizations persist | |
|
161 | QCOMPARE(s1->pen(), p1); | |
|
162 | QCOMPARE(s1->brush(), b1); | |
|
163 | QCOMPARE(s1->labelPen(), p1); | |
|
164 | QCOMPARE(s1->labelFont(), f1); | |
|
165 | ||
|
166 | // remove a slice | |
|
167 | series->remove(s2); | |
|
168 | QCOMPARE(s1->pen(), p1); | |
|
169 | QCOMPARE(s1->brush(), b1); | |
|
170 | QCOMPARE(s1->labelPen(), p1); | |
|
171 | QCOMPARE(s1->labelFont(), f1); | |
|
172 | ||
|
173 | // add a slice | |
|
174 | series->append(4, "slice 4"); | |
|
175 | QCOMPARE(s1->pen(), p1); | |
|
176 | QCOMPARE(s1->brush(), b1); | |
|
177 | QCOMPARE(s1->labelPen(), p1); | |
|
178 | QCOMPARE(s1->labelFont(), f1); | |
|
179 | ||
|
180 | // insert a slice | |
|
181 | series->insert(0, new QPieSlice(5, "slice 5")); | |
|
182 | QCOMPARE(s1->pen(), p1); | |
|
183 | QCOMPARE(s1->brush(), b1); | |
|
184 | QCOMPARE(s1->labelPen(), p1); | |
|
185 | QCOMPARE(s1->labelFont(), f1); | |
|
186 | ||
|
187 | // change theme | |
|
188 | // theme will overwrite customizations | |
|
189 | view.chart()->setTheme(QChart::ChartThemeHighContrast); | |
|
190 | QVERIFY(s1->pen() != p1); | |
|
191 | QVERIFY(s1->brush() != b1); | |
|
192 | QVERIFY(s1->labelPen() != p1); | |
|
193 | QVERIFY(s1->labelFont() != f1); | |
|
194 | } | |
|
195 | ||
|
196 | void tst_qpieslice::mouseClick() | |
|
197 | { | |
|
198 | // create a pie series | |
|
199 | QPieSeries *series = new QPieSeries(); | |
|
200 | series->setPieSize(1.0); | |
|
201 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
202 | QPieSlice *s2 = series->append(2, "slice 2"); | |
|
203 | QPieSlice *s3 = series->append(3, "slice 3"); | |
|
204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); | |
|
205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); | |
|
206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); | |
|
207 | ||
|
208 | // add series to the chart | |
|
209 | QChartView view(new QChart()); | |
|
210 | view.resize(200, 200); | |
|
211 | view.chart()->addSeries(series); | |
|
212 | view.show(); | |
|
213 | QTest::qWaitForWindowShown(&view); | |
|
214 | ||
|
215 | // simulate clicks | |
|
216 | // pie rectangle: QRectF(60,60 121x121) | |
|
217 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
|
218 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 | |
|
219 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 | |
|
220 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice | |
|
221 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice | |
|
222 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
223 | QCOMPARE(clickSpy1.count(), 1); | |
|
224 | QCOMPARE(clickSpy2.count(), 1); | |
|
225 | QCOMPARE(clickSpy3.count(), 1); | |
|
226 | } | |
|
227 | ||
|
228 | void tst_qpieslice::mouseHover() | |
|
229 | { | |
|
230 | // create a pie series | |
|
231 | QPieSeries *series = new QPieSeries(); | |
|
232 | series->setPieSize(1.0); | |
|
233 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
234 | series->append(2, "slice 2"); | |
|
235 | series->append(3, "slice 3"); | |
|
236 | ||
|
237 | // add series to the chart | |
|
238 | QChartView view(new QChart()); | |
|
239 | view.resize(200, 200); | |
|
240 | view.chart()->addSeries(series); | |
|
241 | view.show(); | |
|
242 | QTest::qWaitForWindowShown(&view); | |
|
243 | ||
|
244 | // first move to right top corner | |
|
245 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
246 | ||
|
247 | // move inside slice rectangle but NOT the actual slice | |
|
248 | // pie rectangle: QRectF(60,60 121x121) | |
|
249 | QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); | |
|
250 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); | |
|
251 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
252 | QCOMPARE(hoverSpy.count(), 0); | |
|
253 | ||
|
254 | // move inside the slice | |
|
255 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
|
256 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
257 | QCOMPARE(hoverSpy.count(), 1); | |
|
258 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); | |
|
259 | ||
|
260 | // move outside the slice | |
|
261 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
262 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
263 | QCOMPARE(hoverSpy.count(), 2); | |
|
264 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); | |
|
126 | 265 | } |
|
127 | 266 | |
|
128 | 267 | QTEST_MAIN(tst_qpieslice) |
@@ -272,12 +272,16 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||
|
272 | 272 | foreach(QString label, labels) |
|
273 | 273 | category << label; |
|
274 | 274 | QBarSeries* series = 0; |
|
275 | if (seriesName == "Bar") | |
|
276 |
series = new QBarSeries( |
|
|
277 | else if (seriesName == "Stacked bar") | |
|
278 | series = new QStackedBarSeries(category, this); | |
|
279 | else | |
|
280 |
series |
|
|
275 | if (seriesName == "Bar") { | |
|
276 | series = new QBarSeries(this); | |
|
277 | series->setCategories(category); | |
|
278 | } else if (seriesName == "Stacked bar") { | |
|
279 | series = new QStackedBarSeries(this); | |
|
280 | series->setCategories(category); | |
|
281 | } else { | |
|
282 | series = new QPercentBarSeries(this); | |
|
283 | series->setCategories(category); | |
|
284 | } | |
|
281 | 285 | |
|
282 | 286 | for (int j(0); j < data.count(); j++) { |
|
283 | 287 | QList<qreal> column = data.at(j); |
@@ -140,8 +140,9 void Widget::refreshChart() | |||
|
140 | 140 | QStringList category; |
|
141 | 141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
142 | 142 | category << selectedCountriesStrings[i]; |
|
143 |
QBarSeries* series0 = new QBarSeries( |
|
|
144 |
series0 |
|
|
143 | QBarSeries* series0 = new QBarSeries(); | |
|
144 | series0->setCategories(category); | |
|
145 | // series0 = new QBarSeries(category); | |
|
145 | 146 | |
|
146 | 147 | // prepare the selected counries SQL query |
|
147 | 148 | QString countriesQuery = "country IN ("; |
@@ -370,7 +370,8 void TableWidget::updateChartType(bool toggle) | |||
|
370 | 370 | { |
|
371 | 371 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
372 | 372 | |
|
373 |
QBarSeries* barSeries = new QBarSeries( |
|
|
373 | QBarSeries* barSeries = new QBarSeries(); | |
|
374 | barSeries->setCategories(QStringList()); | |
|
374 | 375 | barSeries->setModel(m_model); |
|
375 | 376 | // barSeries->setModelMappingRange(2, 5); |
|
376 | 377 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
General Comments 0
You need to be logged in to leave comments.
Login now