@@ -1,406 +1,393 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #ifndef BUILD_PRIVATE_UNIT_TESTS |
|
20 | #ifndef BUILD_PRIVATE_UNIT_TESTS | |
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 |
|
22 | |||
23 | class tst_ChartDataSet: public QObject { |
|
23 | class tst_ChartDataSet: public QObject { | |
24 |
|
24 | |||
25 | Q_OBJECT |
|
25 | Q_OBJECT | |
26 |
|
26 | |||
27 | private Q_SLOTS: |
|
27 | private Q_SLOTS: | |
28 | void skip(); |
|
28 | void skip(); | |
29 |
|
29 | |||
30 | }; |
|
30 | }; | |
31 |
|
31 | |||
32 | void tst_ChartDataSet::skip() |
|
32 | void tst_ChartDataSet::skip() | |
33 | { |
|
33 | { | |
34 | QSKIP("This test requires the debug version of library"); |
|
34 | QSKIP("This test requires the debug version of library"); | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | QTEST_MAIN(tst_ChartDataSet) |
|
37 | QTEST_MAIN(tst_ChartDataSet) | |
38 | #include "tst_chartdataset.moc" |
|
38 | #include "tst_chartdataset.moc" | |
39 |
|
39 | |||
40 | #else |
|
40 | #else | |
41 |
|
41 | |||
42 | #include <QtTest/QtTest> |
|
42 | #include <QtTest/QtTest> | |
43 | #include <QtCharts/QAbstractAxis> |
|
43 | #include <QtCharts/QAbstractAxis> | |
44 | #include <QtCharts/QValueAxis> |
|
44 | #include <QtCharts/QValueAxis> | |
45 | #include <QtCharts/QBarCategoryAxis> |
|
45 | #include <QtCharts/QBarCategoryAxis> | |
46 | #include <QtCharts/QCategoryAxis> |
|
46 | #include <QtCharts/QCategoryAxis> | |
47 | #ifndef QT_ON_ARM |
|
47 | #ifndef QT_ON_ARM | |
48 | #include <QtCharts/QDateTimeAxis> |
|
48 | #include <QtCharts/QDateTimeAxis> | |
49 | #endif |
|
49 | #endif | |
50 | #include <QtCharts/QLineSeries> |
|
50 | #include <QtCharts/QLineSeries> | |
51 | #include <QtCharts/QAreaSeries> |
|
51 | #include <QtCharts/QAreaSeries> | |
52 | #include <QtCharts/QScatterSeries> |
|
52 | #include <QtCharts/QScatterSeries> | |
53 | #include <QtCharts/QSplineSeries> |
|
53 | #include <QtCharts/QSplineSeries> | |
54 | #include <QtCharts/QPieSeries> |
|
54 | #include <QtCharts/QPieSeries> | |
55 | #include <QtCharts/QBarSeries> |
|
55 | #include <QtCharts/QBarSeries> | |
56 | #include <QtCharts/QPercentBarSeries> |
|
56 | #include <QtCharts/QPercentBarSeries> | |
57 | #include <QtCharts/QStackedBarSeries> |
|
57 | #include <QtCharts/QStackedBarSeries> | |
58 | #include <private/chartdataset_p.h> |
|
58 | #include <private/chartdataset_p.h> | |
59 | #include <private/abstractdomain_p.h> |
|
59 | #include <private/abstractdomain_p.h> | |
60 | #include <tst_definitions.h> |
|
60 | #include <tst_definitions.h> | |
61 |
|
61 | |||
62 | QT_CHARTS_USE_NAMESPACE |
|
62 | QT_CHARTS_USE_NAMESPACE | |
63 |
|
63 | |||
64 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
64 | Q_DECLARE_METATYPE(AbstractDomain *) | |
65 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
65 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
66 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
66 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
67 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
67 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
68 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
68 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
69 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
69 | Q_DECLARE_METATYPE(Qt::Alignment) | |
70 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
70 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) | |
71 | Q_DECLARE_METATYPE(QLineSeries *) |
|
71 | Q_DECLARE_METATYPE(QLineSeries *) | |
72 |
|
72 | |||
73 | class tst_ChartDataSet: public QObject { |
|
73 | class tst_ChartDataSet: public QObject { | |
74 |
|
74 | |||
75 | Q_OBJECT |
|
75 | Q_OBJECT | |
76 | public: |
|
76 | public: | |
77 | tst_ChartDataSet():m_dataset(0){}; |
|
77 | tst_ChartDataSet():m_dataset(0){}; | |
78 |
|
78 | |||
79 | public Q_SLOTS: |
|
79 | public Q_SLOTS: | |
80 | void initTestCase(); |
|
80 | void initTestCase(); | |
81 | void cleanupTestCase(); |
|
81 | void cleanupTestCase(); | |
82 | void init(); |
|
82 | void init(); | |
83 | void cleanup(); |
|
83 | void cleanup(); | |
84 |
|
84 | |||
85 | private Q_SLOTS: |
|
85 | private Q_SLOTS: | |
86 | void chartdataset_data(); |
|
86 | void chartdataset_data(); | |
87 | void chartdataset(); |
|
87 | void chartdataset(); | |
88 | void addSeries_data(); |
|
88 | void addSeries_data(); | |
89 | void addSeries(); |
|
89 | void addSeries(); | |
90 | void removeSeries_data(); |
|
90 | void removeSeries_data(); | |
91 | void removeSeries(); |
|
91 | void removeSeries(); | |
92 | void addAxis_data(); |
|
92 | void addAxis_data(); | |
93 | void addAxis(); |
|
93 | void addAxis(); | |
94 | void removeAxis_data(); |
|
94 | void removeAxis_data(); | |
95 | void removeAxis(); |
|
95 | void removeAxis(); | |
96 | void attachAxis_data(); |
|
96 | void attachAxis_data(); | |
97 | void attachAxis(); |
|
97 | void attachAxis(); | |
98 | void detachAxis_data(); |
|
98 | void detachAxis_data(); | |
99 | void detachAxis(); |
|
99 | void detachAxis(); | |
100 |
|
100 | |||
101 | private: |
|
101 | private: | |
102 | ChartDataSet* m_dataset; |
|
102 | ChartDataSet* m_dataset; | |
103 | }; |
|
103 | }; | |
104 |
|
104 | |||
105 | void tst_ChartDataSet::initTestCase() |
|
105 | void tst_ChartDataSet::initTestCase() | |
106 | { |
|
106 | { | |
107 | qRegisterMetaType<AbstractDomain*>(); |
|
107 | qRegisterMetaType<AbstractDomain*>(); | |
108 | qRegisterMetaType<QAbstractAxis*>(); |
|
108 | qRegisterMetaType<QAbstractAxis*>(); | |
109 | qRegisterMetaType<QAbstractSeries*>(); |
|
109 | qRegisterMetaType<QAbstractSeries*>(); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void tst_ChartDataSet::cleanupTestCase() |
|
112 | void tst_ChartDataSet::cleanupTestCase() | |
113 | { |
|
113 | { | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void tst_ChartDataSet::init() |
|
116 | void tst_ChartDataSet::init() | |
117 | { |
|
117 | { | |
118 | Q_ASSERT(!m_dataset); |
|
118 | Q_ASSERT(!m_dataset); | |
119 | m_dataset = new ChartDataSet(0); |
|
119 | m_dataset = new ChartDataSet(0); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | void tst_ChartDataSet::cleanup() |
|
123 | void tst_ChartDataSet::cleanup() | |
124 | { |
|
124 | { | |
125 | delete m_dataset; |
|
125 | delete m_dataset; | |
126 | m_dataset=0; |
|
126 | m_dataset=0; | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void tst_ChartDataSet::chartdataset_data() |
|
129 | void tst_ChartDataSet::chartdataset_data() | |
130 | { |
|
130 | { | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void tst_ChartDataSet::chartdataset() |
|
133 | void tst_ChartDataSet::chartdataset() | |
134 | { |
|
134 | { | |
135 | QVERIFY(m_dataset->axes().isEmpty()); |
|
135 | QVERIFY(m_dataset->axes().isEmpty()); | |
136 | QVERIFY(m_dataset->series().isEmpty()); |
|
136 | QVERIFY(m_dataset->series().isEmpty()); | |
137 | m_dataset->createDefaultAxes(); |
|
137 | m_dataset->createDefaultAxes(); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | void tst_ChartDataSet::addSeries_data() |
|
141 | void tst_ChartDataSet::addSeries_data() | |
142 | { |
|
142 | { | |
143 | QTest::addColumn<QAbstractSeries*>("series"); |
|
143 | QTest::addColumn<QAbstractSeries*>("series"); | |
144 |
|
144 | |||
145 | QAbstractSeries* line = new QLineSeries(this); |
|
145 | QAbstractSeries* line = new QLineSeries(this); | |
146 | QTest::newRow("line") << line; |
|
146 | QTest::newRow("line") << line; | |
147 |
|
147 | |||
148 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
148 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); | |
149 | QTest::newRow("area") << area; |
|
149 | QTest::newRow("area") << area; | |
150 |
|
150 | |||
151 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
151 | QAbstractSeries* scatter = new QScatterSeries(this); | |
152 | QTest::newRow("scatter") << scatter; |
|
152 | QTest::newRow("scatter") << scatter; | |
153 |
|
153 | |||
154 | QAbstractSeries* spline = new QSplineSeries(this); |
|
154 | QAbstractSeries* spline = new QSplineSeries(this); | |
155 | QTest::newRow("spline") << spline; |
|
155 | QTest::newRow("spline") << spline; | |
156 |
|
156 | |||
157 | QAbstractSeries* pie = new QPieSeries(this); |
|
157 | QAbstractSeries* pie = new QPieSeries(this); | |
158 | QTest::newRow("pie") << pie; |
|
158 | QTest::newRow("pie") << pie; | |
159 |
|
159 | |||
160 | QAbstractSeries* bar = new QBarSeries(this); |
|
160 | QAbstractSeries* bar = new QBarSeries(this); | |
161 | QTest::newRow("bar") << bar; |
|
161 | QTest::newRow("bar") << bar; | |
162 |
|
162 | |||
163 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
163 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
164 | QTest::newRow("percent") << percent; |
|
164 | QTest::newRow("percent") << percent; | |
165 |
|
165 | |||
166 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
166 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
167 | QTest::newRow("stacked") << stacked; |
|
167 | QTest::newRow("stacked") << stacked; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void tst_ChartDataSet::addSeries() |
|
170 | void tst_ChartDataSet::addSeries() | |
171 | { |
|
171 | { | |
172 | QFETCH(QAbstractSeries*, series); |
|
172 | QFETCH(QAbstractSeries*, series); | |
173 | QVERIFY(m_dataset->series().isEmpty()); |
|
173 | QVERIFY(m_dataset->series().isEmpty()); | |
174 |
|
174 | |||
175 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
175 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
176 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
176 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
177 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
177 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
178 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
178 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
179 |
|
179 | |||
180 | m_dataset->addSeries(series); |
|
180 | m_dataset->addSeries(series); | |
181 |
|
181 | |||
182 | QCOMPARE(m_dataset->series().count(),1); |
|
182 | QCOMPARE(m_dataset->series().count(),1); | |
183 | TRY_COMPARE(spy0.count(), 0); |
|
183 | TRY_COMPARE(spy0.count(), 0); | |
184 | TRY_COMPARE(spy1.count(), 0); |
|
184 | TRY_COMPARE(spy1.count(), 0); | |
185 | TRY_COMPARE(spy2.count(), 1); |
|
185 | TRY_COMPARE(spy2.count(), 1); | |
186 | TRY_COMPARE(spy3.count(), 0); |
|
186 | TRY_COMPARE(spy3.count(), 0); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void tst_ChartDataSet::removeSeries_data() |
|
189 | void tst_ChartDataSet::removeSeries_data() | |
190 | { |
|
190 | { | |
191 | addSeries_data(); |
|
191 | addSeries_data(); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | void tst_ChartDataSet::removeSeries() |
|
194 | void tst_ChartDataSet::removeSeries() | |
195 | { |
|
195 | { | |
196 | QFETCH(QAbstractSeries*, series); |
|
196 | QFETCH(QAbstractSeries*, series); | |
197 | QVERIFY(m_dataset->series().isEmpty()); |
|
197 | QVERIFY(m_dataset->series().isEmpty()); | |
198 | m_dataset->addSeries(series); |
|
198 | m_dataset->addSeries(series); | |
199 |
|
199 | |||
200 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
200 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
201 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
201 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
202 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
202 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
203 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
203 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
204 |
|
204 | |||
205 | m_dataset->removeSeries(series); |
|
205 | m_dataset->removeSeries(series); | |
206 |
|
206 | |||
207 | QCOMPARE(m_dataset->series().count(),0); |
|
207 | QCOMPARE(m_dataset->series().count(),0); | |
208 | TRY_COMPARE(spy0.count(), 0); |
|
208 | TRY_COMPARE(spy0.count(), 0); | |
209 | TRY_COMPARE(spy1.count(), 0); |
|
209 | TRY_COMPARE(spy1.count(), 0); | |
210 | TRY_COMPARE(spy2.count(), 0); |
|
210 | TRY_COMPARE(spy2.count(), 0); | |
211 | TRY_COMPARE(spy3.count(), 1); |
|
211 | TRY_COMPARE(spy3.count(), 1); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void tst_ChartDataSet::addAxis_data() |
|
214 | void tst_ChartDataSet::addAxis_data() | |
215 | { |
|
215 | { | |
216 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
216 | QTest::addColumn<QAbstractAxis*>("axis"); | |
217 | QAbstractAxis* value = new QValueAxis(this); |
|
217 | QAbstractAxis* value = new QValueAxis(this); | |
218 | QAbstractAxis* category = new QCategoryAxis(this); |
|
218 | QAbstractAxis* category = new QCategoryAxis(this); | |
219 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
219 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
220 | #ifndef Q_WS_QWS |
|
220 | #ifndef Q_WS_QWS | |
221 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
221 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
222 | #endif |
|
222 | #endif | |
223 |
|
223 | |||
224 | QTest::newRow("value") << value; |
|
224 | QTest::newRow("value") << value; | |
225 | QTest::newRow("category") << category; |
|
225 | QTest::newRow("category") << category; | |
226 | QTest::newRow("barcategory") << barcategory; |
|
226 | QTest::newRow("barcategory") << barcategory; | |
227 | #ifndef Q_WS_QWS |
|
227 | #ifndef Q_WS_QWS | |
228 | QTest::newRow("datetime") << datetime; |
|
228 | QTest::newRow("datetime") << datetime; | |
229 | #endif |
|
229 | #endif | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | void tst_ChartDataSet::addAxis() |
|
232 | void tst_ChartDataSet::addAxis() | |
233 | { |
|
233 | { | |
234 | QFETCH(QAbstractAxis*, axis); |
|
234 | QFETCH(QAbstractAxis*, axis); | |
235 | QVERIFY(m_dataset->axes().isEmpty()); |
|
235 | QVERIFY(m_dataset->axes().isEmpty()); | |
236 |
|
236 | |||
237 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
237 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
238 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
238 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
239 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
239 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
240 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
240 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
241 |
|
241 | |||
242 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
242 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
243 |
|
243 | |||
244 | QCOMPARE(m_dataset->axes().count(),1); |
|
244 | QCOMPARE(m_dataset->axes().count(),1); | |
245 | TRY_COMPARE(spy0.count(), 1); |
|
245 | TRY_COMPARE(spy0.count(), 1); | |
246 | TRY_COMPARE(spy1.count(), 0); |
|
246 | TRY_COMPARE(spy1.count(), 0); | |
247 | TRY_COMPARE(spy2.count(), 0); |
|
247 | TRY_COMPARE(spy2.count(), 0); | |
248 | TRY_COMPARE(spy3.count(), 0); |
|
248 | TRY_COMPARE(spy3.count(), 0); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void tst_ChartDataSet::removeAxis_data() |
|
251 | void tst_ChartDataSet::removeAxis_data() | |
252 | { |
|
252 | { | |
253 | addAxis_data(); |
|
253 | addAxis_data(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | void tst_ChartDataSet::removeAxis() |
|
256 | void tst_ChartDataSet::removeAxis() | |
257 | { |
|
257 | { | |
258 | QFETCH(QAbstractAxis*, axis); |
|
258 | QFETCH(QAbstractAxis*, axis); | |
259 | QVERIFY(m_dataset->series().isEmpty()); |
|
259 | QVERIFY(m_dataset->series().isEmpty()); | |
260 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
260 | m_dataset->addAxis(axis,Qt::AlignBottom); | |
261 |
|
261 | |||
262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
266 |
|
266 | |||
267 | m_dataset->removeAxis(axis); |
|
267 | m_dataset->removeAxis(axis); | |
268 |
|
268 | |||
269 | QCOMPARE(m_dataset->axes().count(),0); |
|
269 | QCOMPARE(m_dataset->axes().count(),0); | |
270 | QCOMPARE(m_dataset->series().count(),0); |
|
270 | QCOMPARE(m_dataset->series().count(),0); | |
271 | TRY_COMPARE(spy0.count(), 0); |
|
271 | TRY_COMPARE(spy0.count(), 0); | |
272 | TRY_COMPARE(spy1.count(), 1); |
|
272 | TRY_COMPARE(spy1.count(), 1); | |
273 | TRY_COMPARE(spy2.count(), 0); |
|
273 | TRY_COMPARE(spy2.count(), 0); | |
274 | TRY_COMPARE(spy3.count(), 0); |
|
274 | TRY_COMPARE(spy3.count(), 0); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void tst_ChartDataSet::attachAxis_data() |
|
277 | void tst_ChartDataSet::attachAxis_data() | |
278 | { |
|
278 | { | |
279 |
|
279 | |||
280 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
280 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
281 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
281 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
282 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
282 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); | |
283 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
283 | QTest::addColumn<QAbstractSeries*>("attachSeries"); | |
284 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
284 | QTest::addColumn<QAbstractAxis*>("attachAxis"); | |
285 | QTest::addColumn<bool>("success"); |
|
285 | QTest::addColumn<bool>("success"); | |
286 |
|
286 | |||
287 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
|||
288 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
|||
289 | QAbstractSeries* spline = new QSplineSeries(this); |
|
|||
290 | QAbstractSeries* pie = new QPieSeries(this); |
|
|||
291 | QAbstractSeries* bar = new QBarSeries(this); |
|
|||
292 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
|||
293 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
|||
294 |
|
||||
295 | QAbstractAxis* category = new QCategoryAxis(this); |
|
|||
296 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
|||
297 | #ifndef Q_WS_QWS |
|
|||
298 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
|||
299 | #endif |
|
|||
300 | { |
|
287 | { | |
301 | QList<QAbstractSeries*> series; |
|
288 | QList<QAbstractSeries*> series; | |
302 | QList<QAbstractAxis*> axes; |
|
289 | QList<QAbstractAxis*> axes; | |
303 | QList<Qt::Alignment> alignment; |
|
290 | QList<Qt::Alignment> alignment; | |
304 | QAbstractSeries* line = new QLineSeries(this); |
|
291 | QAbstractSeries* line = new QLineSeries(this); | |
305 | QAbstractAxis* value1 = new QValueAxis(this); |
|
292 | QAbstractAxis* value1 = new QValueAxis(this); | |
306 | QAbstractAxis* value2 = new QValueAxis(this); |
|
293 | QAbstractAxis* value2 = new QValueAxis(this); | |
307 | series << line << 0; |
|
294 | series << line << 0; | |
308 | axes << value1 << value2; |
|
295 | axes << value1 << value2; | |
309 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
296 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
310 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
297 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; | |
311 | } |
|
298 | } | |
312 |
|
299 | |||
313 | { |
|
300 | { | |
314 | QList<QAbstractSeries*> series; |
|
301 | QList<QAbstractSeries*> series; | |
315 | QList<QAbstractAxis*> axes; |
|
302 | QList<QAbstractAxis*> axes; | |
316 | QList<Qt::Alignment> alignment; |
|
303 | QList<Qt::Alignment> alignment; | |
317 | QAbstractSeries* line = new QLineSeries(this); |
|
304 | QAbstractSeries* line = new QLineSeries(this); | |
318 | QAbstractAxis* value1 = new QValueAxis(this); |
|
305 | QAbstractAxis* value1 = new QValueAxis(this); | |
319 | QAbstractAxis* value2 = new QValueAxis(this); |
|
306 | QAbstractAxis* value2 = new QValueAxis(this); | |
320 | series << 0 << line; |
|
307 | series << 0 << line; | |
321 | axes << value1 << value2; |
|
308 | axes << value1 << value2; | |
322 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
309 | alignment << Qt::AlignBottom << Qt::AlignLeft; | |
323 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
310 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; | |
324 | } |
|
311 | } | |
325 |
|
312 | |||
326 | } |
|
313 | } | |
327 |
|
314 | |||
328 | void tst_ChartDataSet::attachAxis() |
|
315 | void tst_ChartDataSet::attachAxis() | |
329 | { |
|
316 | { | |
330 | QFETCH(QList<QAbstractSeries*>, series); |
|
317 | QFETCH(QList<QAbstractSeries*>, series); | |
331 | QFETCH(QList<QAbstractAxis*>, axis); |
|
318 | QFETCH(QList<QAbstractAxis*>, axis); | |
332 | QFETCH(QList<Qt::Alignment>, alignment); |
|
319 | QFETCH(QList<Qt::Alignment>, alignment); | |
333 | QFETCH(QAbstractSeries*, attachSeries); |
|
320 | QFETCH(QAbstractSeries*, attachSeries); | |
334 | QFETCH(QAbstractAxis*, attachAxis); |
|
321 | QFETCH(QAbstractAxis*, attachAxis); | |
335 | QFETCH(bool, success); |
|
322 | QFETCH(bool, success); | |
336 |
|
323 | |||
337 | Q_ASSERT(series.count() == axis.count()); |
|
324 | Q_ASSERT(series.count() == axis.count()); | |
338 | Q_ASSERT(series.count() == alignment.count()); |
|
325 | Q_ASSERT(series.count() == alignment.count()); | |
339 |
|
326 | |||
340 | QVERIFY(m_dataset->series().isEmpty()); |
|
327 | QVERIFY(m_dataset->series().isEmpty()); | |
341 | QVERIFY(m_dataset->axes().isEmpty()); |
|
328 | QVERIFY(m_dataset->axes().isEmpty()); | |
342 |
|
329 | |||
343 | for(int i = 0 ; i < series.count() ; i++){ |
|
330 | for(int i = 0 ; i < series.count() ; i++){ | |
344 | if(series[i]) m_dataset->addSeries(series[i]); |
|
331 | if(series[i]) m_dataset->addSeries(series[i]); | |
345 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
332 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); | |
346 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
333 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
347 | } |
|
334 | } | |
348 |
|
335 | |||
349 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
336 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
350 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
337 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
351 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
338 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
352 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
339 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
353 |
|
340 | |||
354 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
341 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); | |
355 |
|
342 | |||
356 | } |
|
343 | } | |
357 |
|
344 | |||
358 | void tst_ChartDataSet::detachAxis_data() |
|
345 | void tst_ChartDataSet::detachAxis_data() | |
359 | { |
|
346 | { | |
360 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
347 | QTest::addColumn<QList<QAbstractSeries*> >("series"); | |
361 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
348 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); | |
362 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
349 | QTest::addColumn<QAbstractSeries*>("detachSeries"); | |
363 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
350 | QTest::addColumn<QAbstractAxis*>("detachAxis"); | |
364 | QTest::addColumn<bool>("success"); |
|
351 | QTest::addColumn<bool>("success"); | |
365 |
|
352 | |||
366 | { |
|
353 | { | |
367 | QList<QAbstractSeries*> series; |
|
354 | QList<QAbstractSeries*> series; | |
368 | QList<QAbstractAxis*> axes; |
|
355 | QList<QAbstractAxis*> axes; | |
369 | QAbstractSeries* line = new QLineSeries(this); |
|
356 | QAbstractSeries* line = new QLineSeries(this); | |
370 | QAbstractAxis* value = new QValueAxis(this); |
|
357 | QAbstractAxis* value = new QValueAxis(this); | |
371 | series << line; |
|
358 | series << line; | |
372 | axes << value; |
|
359 | axes << value; | |
373 | QTest::newRow("first") << series << axes << line << value << true; |
|
360 | QTest::newRow("first") << series << axes << line << value << true; | |
374 | } |
|
361 | } | |
375 | } |
|
362 | } | |
376 |
|
363 | |||
377 | void tst_ChartDataSet::detachAxis() |
|
364 | void tst_ChartDataSet::detachAxis() | |
378 | { |
|
365 | { | |
379 | QFETCH(QList<QAbstractSeries*>, series); |
|
366 | QFETCH(QList<QAbstractSeries*>, series); | |
380 | QFETCH(QList<QAbstractAxis*>, axis); |
|
367 | QFETCH(QList<QAbstractAxis*>, axis); | |
381 | QFETCH(QAbstractSeries*, detachSeries); |
|
368 | QFETCH(QAbstractSeries*, detachSeries); | |
382 | QFETCH(QAbstractAxis*, detachAxis); |
|
369 | QFETCH(QAbstractAxis*, detachAxis); | |
383 | QFETCH(bool, success); |
|
370 | QFETCH(bool, success); | |
384 |
|
371 | |||
385 | Q_ASSERT(series.count() == axis.count()); |
|
372 | Q_ASSERT(series.count() == axis.count()); | |
386 |
|
373 | |||
387 | QVERIFY(m_dataset->series().isEmpty()); |
|
374 | QVERIFY(m_dataset->series().isEmpty()); | |
388 | QVERIFY(m_dataset->axes().isEmpty()); |
|
375 | QVERIFY(m_dataset->axes().isEmpty()); | |
389 |
|
376 | |||
390 | for(int i = 0; i < series.count(); i++) { |
|
377 | for(int i = 0; i < series.count(); i++) { | |
391 | if(series[i]) m_dataset->addSeries(series[i]); |
|
378 | if(series[i]) m_dataset->addSeries(series[i]); | |
392 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
379 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); | |
393 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
380 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); | |
394 | } |
|
381 | } | |
395 |
|
382 | |||
396 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
383 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); | |
397 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
384 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
398 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
385 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); | |
399 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
386 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
400 |
|
387 | |||
401 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
388 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); | |
402 | } |
|
389 | } | |
403 |
|
390 | |||
404 | QTEST_MAIN(tst_ChartDataSet) |
|
391 | QTEST_MAIN(tst_ChartDataSet) | |
405 | #include "tst_chartdataset.moc" |
|
392 | #include "tst_chartdataset.moc" | |
406 | #endif |
|
393 | #endif |
@@ -1,89 +1,90 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2014 Digia Plc |
|
3 | ** Copyright (C) 2014 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
7 | ** This file is part of the Qt Enterprise Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | #ifndef CHARTS_H |
|
22 | #ifndef CHARTS_H | |
23 | #define CHARTS_H |
|
23 | #define CHARTS_H | |
24 | #include "model.h" |
|
24 | #include "model.h" | |
25 | #include <QtCore/QList> |
|
25 | #include <QtCore/QList> | |
26 | #include <QtCore/QString> |
|
26 | #include <QtCore/QString> | |
|
27 | #include <QtCore/QSharedPointer> | |||
27 | #include <QtCharts/QChartGlobal> |
|
28 | #include <QtCharts/QChartGlobal> | |
28 |
|
29 | |||
29 | QT_CHARTS_BEGIN_NAMESPACE |
|
30 | QT_CHARTS_BEGIN_NAMESPACE | |
30 | class QChart; |
|
31 | class QChart; | |
31 | QT_CHARTS_END_NAMESPACE |
|
32 | QT_CHARTS_END_NAMESPACE | |
32 |
|
33 | |||
33 | QT_CHARTS_USE_NAMESPACE |
|
34 | QT_CHARTS_USE_NAMESPACE | |
34 |
|
35 | |||
35 | class Chart |
|
36 | class Chart | |
36 | { |
|
37 | { | |
37 | public: |
|
38 | public: | |
38 | virtual ~Chart() {}; |
|
39 | virtual ~Chart() {}; | |
39 | virtual QChart *createChart(const DataTable &table) = 0; |
|
40 | virtual QChart *createChart(const DataTable &table) = 0; | |
40 | virtual QString name() = 0; |
|
41 | virtual QString name() = 0; | |
41 | virtual QString category() = 0; |
|
42 | virtual QString category() = 0; | |
42 | virtual QString subCategory() = 0; |
|
43 | virtual QString subCategory() = 0; | |
43 |
|
44 | |||
44 | }; |
|
45 | }; | |
45 |
|
46 | |||
46 | namespace Charts |
|
47 | namespace Charts | |
47 | { |
|
48 | { | |
48 |
|
49 | |||
49 | typedef QList<Chart *> ChartList; |
|
50 | typedef QList<Chart *> ChartList; | |
50 |
|
51 | |||
51 | inline ChartList &chartList() |
|
52 | inline ChartList &chartList() | |
52 | { |
|
53 | { | |
53 | static ChartList list; |
|
54 | static ChartList list; | |
54 | return list; |
|
55 | return list; | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | inline bool findChart(Chart *chart) |
|
58 | inline bool findChart(Chart *chart) | |
58 | { |
|
59 | { | |
59 | ChartList &list = chartList(); |
|
60 | ChartList &list = chartList(); | |
60 | if (list.contains(chart)) |
|
61 | if (list.contains(chart)) | |
61 | return true; |
|
62 | return true; | |
62 |
|
63 | |||
63 | foreach (Chart *item, list) { |
|
64 | foreach (Chart *item, list) { | |
64 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) |
|
65 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) | |
65 | return true; |
|
66 | return true; | |
66 | } |
|
67 | } | |
67 | return false; |
|
68 | return false; | |
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | inline void addChart(Chart *chart) |
|
71 | inline void addChart(Chart *chart) | |
71 | { |
|
72 | { | |
72 | ChartList &list = chartList(); |
|
73 | ChartList &list = chartList(); | |
73 | if (!findChart(chart)) |
|
74 | if (!findChart(chart)) | |
74 | list.append(chart); |
|
75 | list.append(chart); | |
75 | } |
|
76 | } | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | template <class T> |
|
79 | template <class T> | |
79 | class ChartWrapper |
|
80 | class ChartWrapper | |
80 | { |
|
81 | { | |
81 | public: |
|
82 | public: | |
82 | QSharedPointer<T> chart; |
|
83 | QSharedPointer<T> chart; | |
83 | ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } |
|
84 | ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } | |
84 | }; |
|
85 | }; | |
85 |
|
86 | |||
86 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; |
|
87 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; | |
87 | #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; |
|
88 | #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; | |
88 |
|
89 | |||
89 | #endif |
|
90 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now