##// END OF EJS Templates
Qt5: declarative fix part4...
Marek Rosa -
r2055:b660f2141c18
parent child
Show More
@@ -1,49 +1,48
1 1 !include(config.pri) {
2 2 error('Missing config.pri')
3 3 }
4 4
5 5 TEMPLATE = subdirs
6 SUBDIRS = src plugins demos examples
7 # tests
6 SUBDIRS = src plugins demos examples tests
8 7
9 8 development_build: message('Development build')
10 9
11 10 CONFIG += ordered
12 11 QMAKE_CXXFLAGS += -g -Wall
13 12 unix:QMAKE_DISTCLEAN += -r build bin include lib doc/html
14 13 win32:QMAKE_DISTCLEAN += /Q /s build bin include lib doc\\html
15 14
16 15 # install feature file
17 16 feature.path = $$[QT_INSTALL_DATA]/mkspecs/features
18 17 feature.files = $$PWD/features/qtcommercialchart.prf
19 18 INSTALLS += feature
20 19
21 20 docs.target = docs
22 21 win32:{
23 22 docs.commands = qdoc3 $$CHART_BUILD_DOC_DIR\\qcharts.qdocconf
24 23 }else{
25 24 docs.commands = qdoc3 $$CHART_BUILD_DOC_DIR/qcharts.qdocconf
26 25 }
27 26 docs.depends = FORCE
28 27 QMAKE_EXTRA_TARGETS += docs
29 28
30 29 unix:coverage:{
31 30 QMAKE_DISTCLEAN += -r ./coverage
32 31 QMAKE_CLEAN += build/*.gcda build/*.gcno
33 32 QMAKE_EXTRA_TARGETS += buildcoverage runcoverage gencoverage
34 33
35 34 buildcoverage.target = build_coverage
36 35 buildcoverage.depends = all
37 36 buildcoverage.commands = mkdir -p ./coverage; \
38 37 make -C src prepare_coverage;
39 38
40 39 runcoverage.target = run_coverage
41 40 runcoverage.depends = buildcoverage
42 41 runcoverage.commands = for f in `ls ./bin/tst_*` ; do echo "processing \$\$f test..."; \$\$f >> unit.log; done ; exit 0;
43 42
44 43 gencoverage.target = gen_coverage
45 44 gencoverage.depends = runcoverage
46 45 gencoverage.commands = make -C src gen_coverage; \
47 46 genhtml -o ./coverage ./coverage/coverage.info --prefix $$PWD
48 47 }
49 48
@@ -1,18 +1,18
1 1 !include( ../tests.pri ) {
2 2 error( "Couldn't find the tests.pri file!" )
3 3 }
4 4
5 5 greaterThan(QT_MAJOR_VERSION, 4) {
6 QT += testlib
6 QT += testlib widgets
7 7 } else {
8 8 CONFIG += qtestlib
9 9 }
10 10 !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_")
11 11
12 12 INCLUDEPATH += ../inc
13 13 HEADERS += ../inc/tst_definitions.h
14 14
15 15 OBJECTS_DIR = $$CHART_BUILD_DIR/tests/auto/$$TARGET
16 16 MOC_DIR = $$CHART_BUILD_DIR/tests/auto/$$TARGET
17 17 UI_DIR = $$CHART_BUILD_DIR/tests/auto/$$TARGET
18 18 RCC_DIR = $$CHART_BUILD_DIR/tests/auto/$$TARGET
@@ -1,644 +1,648
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 21 #include <QtTest/QtTest>
22 22
23 23 class tst_ChartDataSet: public QObject {
24 24
25 25 Q_OBJECT
26 26
27 27 private Q_SLOTS:
28 28 void skip();
29 29
30 30 };
31 31
32 32 void tst_ChartDataSet::skip()
33 33 {
34 #ifdef QT5_QUICK_1
35 QSKIP("This test requires the debug version of library");
36 #else
34 37 QSKIP("This test requires the debug version of library", SkipAll);
38 #endif
35 39 }
36 40
37 41 QTEST_MAIN(tst_ChartDataSet)
38 42 #include "tst_chartdataset.moc"
39 43
40 44 #else
41 45
42 46 #include <QtTest/QtTest>
43 47 #include <qabstractaxis.h>
44 48 #include <qvalueaxis.h>
45 49 #include <qbarcategoryaxis.h>
46 50 #include <qlineseries.h>
47 51 #include <qareaseries.h>
48 52 #include <qscatterseries.h>
49 53 #include <qsplineseries.h>
50 54 #include <qpieseries.h>
51 55 #include <qbarseries.h>
52 56 #include <qpercentbarseries.h>
53 57 #include <qstackedbarseries.h>
54 58 #include <private/chartdataset_p.h>
55 59 #include <private/domain_p.h>
56 60 #include <tst_definitions.h>
57 61
58 62 QTCOMMERCIALCHART_USE_NAMESPACE
59 63
60 64 Q_DECLARE_METATYPE(Domain *)
61 65 Q_DECLARE_METATYPE(QAbstractAxis *)
62 66 Q_DECLARE_METATYPE(QAbstractSeries *)
63 67 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
64 68 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
65 69 Q_DECLARE_METATYPE(QLineSeries *)
66 70
67 71 class tst_ChartDataSet: public QObject {
68 72
69 73 Q_OBJECT
70 74
71 75 public Q_SLOTS:
72 76 void initTestCase();
73 77 void cleanupTestCase();
74 78 void init();
75 79 void cleanup();
76 80
77 81 private Q_SLOTS:
78 82 void chartdataset_data();
79 83 void chartdataset();
80 84 void addSeries_data();
81 85 void addSeries();
82 86 void setAxisX_data();
83 87 void setAxisX();
84 88 void setAxisY_data();
85 89 void setAxisY();
86 90 void removeSeries_data();
87 91 void removeSeries();
88 92 void removeAllSeries_data();
89 93 void removeAllSeries();
90 94 void seriesCount_data();
91 95 void seriesCount();
92 96 void seriesIndex_data();
93 97 void seriesIndex();
94 98 void domain_data();
95 99 void domain();
96 100 void zoomInDomain_data();
97 101 void zoomInDomain();
98 102 void zoomOutDomain_data();
99 103 void zoomOutDomain();
100 104 void scrollDomain_data();
101 105 void scrollDomain();
102 106
103 107 private:
104 108 ChartDataSet* m_dataset;
105 109 };
106 110
107 111 void tst_ChartDataSet::initTestCase()
108 112 {
109 113 qRegisterMetaType<Domain*>();
110 114 qRegisterMetaType<QAbstractAxis*>();
111 115 qRegisterMetaType<QAbstractSeries*>();
112 116 }
113 117
114 118 void tst_ChartDataSet::cleanupTestCase()
115 119 {
116 120 }
117 121
118 122 void tst_ChartDataSet::init()
119 123 {
120 124 m_dataset = new ChartDataSet();
121 125 }
122 126
123 127
124 128 void tst_ChartDataSet::cleanup()
125 129 {
126 130 QList<QAbstractSeries*> series = m_dataset->series();
127 131 foreach(QAbstractSeries* serie, series)
128 132 {
129 133 m_dataset->removeSeries(serie);
130 134 }
131 135 }
132 136
133 137 void tst_ChartDataSet::chartdataset_data()
134 138 {
135 139 }
136 140
137 141 void tst_ChartDataSet::chartdataset()
138 142 {
139 143 QVERIFY(m_dataset->axisX(0) == 0);
140 144 QVERIFY(m_dataset->axisY(0) == 0);
141 145 QLineSeries* series = new QLineSeries(this);
142 146 QCOMPARE(m_dataset->seriesIndex(series),-1);
143 147 QVERIFY(m_dataset->domain(series) == 0);
144 148 QVERIFY(m_dataset->axisX(series) == 0);
145 149 QVERIFY(m_dataset->axisY(series) == 0);
146 150 m_dataset->createDefaultAxes();
147 151 }
148 152
149 153
150 154 void tst_ChartDataSet::addSeries_data()
151 155 {
152 156 QTest::addColumn<QAbstractSeries*>("series");
153 157
154 158 QAbstractSeries* line = new QLineSeries(this);
155 159 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
156 160 QAbstractSeries* scatter = new QScatterSeries(this);
157 161 QAbstractSeries* spline = new QSplineSeries(this);
158 162 QAbstractSeries* pie = new QPieSeries(this);
159 163 QAbstractSeries* bar = new QBarSeries(this);
160 164 QAbstractSeries* percent = new QPercentBarSeries(this);
161 165 QAbstractSeries* stacked = new QStackedBarSeries(this);
162 166
163 167 QTest::newRow("line") << line;
164 168 QTest::newRow("area") << area;
165 169 QTest::newRow("scatter") << scatter;
166 170 QTest::newRow("spline") << spline;
167 171 QTest::newRow("pie") << pie;
168 172 QTest::newRow("bar") << bar;
169 173 QTest::newRow("percent") << percent;
170 174 QTest::newRow("stacked") << stacked;
171 175 }
172 176
173 177 void tst_ChartDataSet::addSeries()
174 178 {
175 179
176 180 QFETCH(QAbstractSeries*, series);
177 181
178 182 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
179 183 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
180 184 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
181 185 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
182 186
183 187 m_dataset->addSeries(series);
184 188 m_dataset->createDefaultAxes();
185 189 if(series->type()==QAbstractSeries::SeriesTypePie){
186 190 TRY_COMPARE(spy0.count(), 0);
187 191 }else{
188 192 TRY_COMPARE(spy0.count(), 2);
189 193 }
190 194 TRY_COMPARE(spy1.count(), 0);
191 195 TRY_COMPARE(spy2.count(), 1);
192 196 TRY_COMPARE(spy3.count(), 0);
193 197 }
194 198
195 199
196 200 void tst_ChartDataSet::setAxisX_data()
197 201 {
198 202 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
199 203 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
200 204 QTest::addColumn<int>("axisCount");
201 205
202 206 QAbstractSeries* line = new QLineSeries(this);
203 207 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
204 208 QAbstractSeries* scatter = new QScatterSeries(this);
205 209 QAbstractSeries* spline = new QSplineSeries(this);
206 210 /*QAbstractSeries* pie = */new QPieSeries(this);
207 211 /*QAbstractSeries* bar = */new QBarSeries(this);
208 212 /*QAbstractSeries* percent = */new QPercentBarSeries(this);
209 213 /*QAbstractSeries* stacked = */new QStackedBarSeries(this);
210 214
211 215 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
212 216 << (QList<QAbstractSeries*>() << line << spline << scatter)
213 217 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this) << new QValueAxis(this)) << 3;
214 218
215 219 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
216 220 << (QList<QAbstractAxis*>() << new QValueAxis(this)) << 1;
217 221
218 222 QList<QAbstractAxis*> axes0;
219 223 axes0 << new QValueAxis(this) << new QValueAxis(this);
220 224 axes0 << axes0.last();
221 225 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
222 226 << (QList<QAbstractSeries*>() << line << spline << scatter)
223 227 << axes0 << 2;
224 228 //TODO: add more test cases
225 229 }
226 230
227 231 void tst_ChartDataSet::setAxisX()
228 232 {
229 233 QFETCH(QList<QAbstractSeries*>, seriesList);
230 234 QFETCH(QList<QAbstractAxis*>, axisList);
231 235 QFETCH(int, axisCount);
232 236
233 237 Q_ASSERT(seriesList.count() == axisList.count());
234 238
235 239 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
236 240 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
237 241 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
238 242 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
239 243
240 244 foreach(QAbstractSeries* series, seriesList){
241 245 m_dataset->addSeries(series);
242 246 }
243 247
244 248 TRY_COMPARE(spy0.count(), 0);
245 249 TRY_COMPARE(spy1.count(), 0);
246 250 TRY_COMPARE(spy2.count(), seriesList.count());
247 251 TRY_COMPARE(spy3.count(), 0);
248 252
249 253 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
250 254 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
251 255 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
252 256 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
253 257
254 258 for(int i=0 ; i < seriesList.count(); i++){
255 259 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Horizontal);
256 260 }
257 261
258 262 TRY_COMPARE(spy4.count(), axisCount);
259 263 TRY_COMPARE(spy5.count(), 0);
260 264 TRY_COMPARE(spy6.count(), 0);
261 265 TRY_COMPARE(spy7.count(), 0);
262 266
263 267 for(int i=0 ; i < seriesList.count(); i++){
264 268 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
265 269 }
266 270 }
267 271
268 272 void tst_ChartDataSet::setAxisY_data()
269 273 {
270 274 setAxisX_data();
271 275 }
272 276
273 277 void tst_ChartDataSet::setAxisY()
274 278 {
275 279 QFETCH(QList<QAbstractSeries*>, seriesList);
276 280 QFETCH(QList<QAbstractAxis*>, axisList);
277 281 QFETCH(int, axisCount);
278 282
279 283 Q_ASSERT(seriesList.count() == axisList.count());
280 284
281 285 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
282 286 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
283 287 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
284 288 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
285 289
286 290 foreach(QAbstractSeries* series, seriesList){
287 291 m_dataset->addSeries(series);
288 292 }
289 293
290 294 TRY_COMPARE(spy0.count(), 0);
291 295 TRY_COMPARE(spy1.count(), 0);
292 296 TRY_COMPARE(spy2.count(), seriesList.count());
293 297 TRY_COMPARE(spy3.count(), 0);
294 298
295 299 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
296 300 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
297 301 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
298 302 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
299 303
300 304 for(int i=0 ; i < seriesList.count(); i++){
301 305 m_dataset->setAxis(seriesList.at(i),axisList.at(i),Qt::Vertical);
302 306 }
303 307
304 308 TRY_COMPARE(spy4.count(), axisCount);
305 309 TRY_COMPARE(spy5.count(), 0);
306 310 TRY_COMPARE(spy6.count(), 0);
307 311 TRY_COMPARE(spy7.count(), 0);
308 312
309 313 for(int i=0 ; i < seriesList.count(); i++){
310 314 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
311 315 }
312 316 }
313 317
314 318 void tst_ChartDataSet::removeSeries_data()
315 319 {
316 320 addSeries_data();
317 321 }
318 322
319 323 void tst_ChartDataSet::removeSeries()
320 324 {
321 325 QFETCH(QAbstractSeries*, series);
322 326
323 327 m_dataset->addSeries(series);
324 328 m_dataset->createDefaultAxes();
325 329
326 330 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
327 331 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
328 332 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
329 333 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
330 334
331 335 m_dataset->removeSeries(series);
332 336
333 337 TRY_COMPARE(spy0.count(), 0);
334 338 if (series->type() == QAbstractSeries::SeriesTypePie) {
335 339 TRY_COMPARE(spy1.count(), 0);
336 340 }
337 341 else {
338 342 TRY_COMPARE(spy1.count(), 2);
339 343 }
340 344 TRY_COMPARE(spy2.count(), 0);
341 345 TRY_COMPARE(spy3.count(), 1);
342 346 }
343 347
344 348 void tst_ChartDataSet::removeAllSeries_data()
345 349 {
346 350 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
347 351 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
348 352 QTest::addColumn<int>("axisCount");
349 353
350 354 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
351 355 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
352 356 << new QScatterSeries(this))
353 357 << (QList<QAbstractAxis*>() << new QValueAxis(this) << new QValueAxis(this)
354 358 << new QValueAxis(this)) << 3;
355 359 //TODO:
356 360 }
357 361
358 362 void tst_ChartDataSet::removeAllSeries()
359 363 {
360 364 QFETCH(QList<QAbstractSeries*>, seriesList);
361 365 QFETCH(QList<QAbstractAxis*>, axisList);
362 366 QFETCH(int, axisCount);
363 367
364 368 foreach(QAbstractSeries* series, seriesList) {
365 369 m_dataset->addSeries(series);
366 370 }
367 371
368 372 for (int i = 0; i < seriesList.count(); i++) {
369 373 m_dataset->setAxis(seriesList.at(i), axisList.at(i),Qt::Horizontal);
370 374 }
371 375
372 376 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
373 377 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
374 378 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
375 379 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
376 380
377 381 m_dataset->removeAllSeries();
378 382
379 383 TRY_COMPARE(spy0.count(), 0);
380 384 TRY_COMPARE(spy1.count(), axisCount);
381 385 TRY_COMPARE(spy2.count(), 0);
382 386 TRY_COMPARE(spy3.count(), seriesList.count());
383 387 }
384 388
385 389
386 390 void tst_ChartDataSet::seriesCount_data()
387 391 {
388 392 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
389 393 QTest::addColumn<int>("seriesCount");
390 394
391 395 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
392 396 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
393 397 }
394 398
395 399 void tst_ChartDataSet::seriesCount()
396 400 {
397 401 QFETCH(QList<QAbstractSeries*>, seriesList);
398 402 QFETCH(int, seriesCount);
399 403
400 404 foreach(QAbstractSeries* series, seriesList){
401 405 m_dataset->addSeries(series);
402 406 }
403 407
404 408 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
405 409 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
406 410 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
407 411 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
408 412
409 413 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
410 414 TRY_COMPARE(spy0.count(), 0);
411 415 TRY_COMPARE(spy1.count(), 0);
412 416 TRY_COMPARE(spy2.count(), 0);
413 417 TRY_COMPARE(spy3.count(), 0);
414 418 }
415 419
416 420 void tst_ChartDataSet::seriesIndex_data()
417 421 {
418 422 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
419 423
420 424 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
421 425 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
422 426 }
423 427
424 428 void tst_ChartDataSet::seriesIndex()
425 429 {
426 430
427 431 QFETCH(QList<QAbstractSeries*>, seriesList);
428 432
429 433 foreach(QAbstractSeries* series, seriesList) {
430 434 m_dataset->addSeries(series);
431 435 }
432 436
433 437 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
434 438 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
435 439 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
436 440 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
437 441
438 442 for (int i = 0; i < seriesList.count(); i++) {
439 443 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 444 }
441 445
442 446 TRY_COMPARE(spy0.count(), 0);
443 447 TRY_COMPARE(spy1.count(), 0);
444 448 TRY_COMPARE(spy2.count(), 0);
445 449 TRY_COMPARE(spy3.count(), 0);
446 450
447 451 foreach(QAbstractSeries* series, seriesList) {
448 452 m_dataset->removeSeries(series);
449 453 }
450 454
451 455 for (int i = 0; i < seriesList.count(); i++) {
452 456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
453 457 }
454 458
455 459 foreach(QAbstractSeries* series, seriesList) {
456 460 m_dataset->addSeries(series);
457 461 }
458 462
459 463 for (int i = 0; i < seriesList.count(); i++) {
460 464 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
461 465 }
462 466
463 467 m_dataset->removeSeries(seriesList.at(1));
464 468
465 469 for (int i = 0; i < seriesList.count(); i++) {
466 470 if (i != 1)
467 471 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
468 472 else
469 473 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
470 474 }
471 475
472 476 m_dataset->addSeries(seriesList.at(1));
473 477
474 478 for (int i = 0; i < seriesList.count(); i++) {
475 479 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
476 480 }
477 481
478 482 m_dataset->removeSeries(seriesList.at(2));
479 483
480 484 for (int i = 0; i < seriesList.count(); i++) {
481 485 if (i != 2)
482 486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
483 487 else
484 488 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
485 489 }
486 490
487 491 m_dataset->removeSeries(seriesList.at(0));
488 492
489 493 for (int i = 0; i < seriesList.count(); i++) {
490 494 if (i != 2 && i != 0)
491 495 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
492 496 else
493 497 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
494 498 }
495 499
496 500 m_dataset->addSeries(seriesList.at(2));
497 501 m_dataset->addSeries(seriesList.at(0));
498 502
499 503 for (int i = 0; i < seriesList.count(); i++) {
500 504 if (i == 2)
501 505 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
502 506 else if (i == 0)
503 507 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
504 508 else
505 509 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
506 510 }
507 511
508 512 }
509 513
510 514 void tst_ChartDataSet::domain_data()
511 515 {
512 516 addSeries_data();
513 517 }
514 518
515 519 void tst_ChartDataSet::domain()
516 520 {
517 521 QFETCH(QAbstractSeries*, series);
518 522
519 523 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
520 524 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
521 525 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
522 526 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
523 527
524 528 m_dataset->addSeries(series);
525 529 QVERIFY(m_dataset->domain(series));
526 530
527 531
528 532 TRY_COMPARE(spy0.count(), 0);
529 533 TRY_COMPARE(spy1.count(), 0);
530 534 TRY_COMPARE(spy2.count(), 1);
531 535
532 536 QList<QVariant> arguments = spy2.takeFirst();
533 537 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
534 538 QVERIFY(m_dataset->domain(series) == domain);
535 539
536 540 TRY_COMPARE(spy3.count(), 0);
537 541
538 542 }
539 543
540 544 void tst_ChartDataSet::zoomInDomain_data()
541 545 {
542 546 QTest::addColumn<bool >("sameAxis");
543 547 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
544 548 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
545 549 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
546 550 }
547 551
548 552 void tst_ChartDataSet::zoomInDomain()
549 553 {
550 554 QFETCH(bool, sameAxis);
551 555 QFETCH(QList<QAbstractSeries*>, seriesList);
552 556
553 557 foreach(QAbstractSeries* series, seriesList) {
554 558 m_dataset->addSeries(series);
555 559 }
556 560
557 561 if(sameAxis) m_dataset->createDefaultAxes();
558 562
559 563 QList<QSignalSpy*> spyList;
560 564
561 565 foreach(QAbstractSeries* series, seriesList) {
562 566 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(updated()));
563 567 }
564 568
565 569 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
566 570
567 571 foreach(QSignalSpy* spy, spyList) {
568 572 TRY_COMPARE(spy->count(), 1);
569 573 }
570 574
571 575 qDeleteAll(spyList);
572 576 }
573 577
574 578
575 579
576 580 void tst_ChartDataSet::zoomOutDomain_data()
577 581 {
578 582 zoomInDomain_data();
579 583 }
580 584
581 585 void tst_ChartDataSet::zoomOutDomain()
582 586 {
583 587 QFETCH(bool, sameAxis);
584 588 QFETCH(QList<QAbstractSeries*>, seriesList);
585 589
586 590 foreach(QAbstractSeries* series, seriesList) {
587 591 m_dataset->addSeries(series);
588 592 }
589 593
590 594 if (sameAxis)
591 595 m_dataset->createDefaultAxes();
592 596
593 597 QList<QSignalSpy*> spyList;
594 598
595 599 foreach(QAbstractSeries* series, seriesList) {
596 600 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(updated()));
597 601 }
598 602
599 603 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
600 604
601 605 foreach(QSignalSpy* spy, spyList) {
602 606 TRY_COMPARE(spy->count(), 1);
603 607 }
604 608
605 609 qDeleteAll (spyList);
606 610 }
607 611
608 612 void tst_ChartDataSet::scrollDomain_data()
609 613 {
610 614 zoomInDomain_data();
611 615 }
612 616
613 617 void tst_ChartDataSet::scrollDomain()
614 618 {
615 619 QFETCH(bool, sameAxis);
616 620 QFETCH(QList<QAbstractSeries*>, seriesList);
617 621
618 622 foreach(QAbstractSeries* series, seriesList) {
619 623 m_dataset->addSeries(series);
620 624 }
621 625
622 626 if (sameAxis)
623 627 m_dataset->createDefaultAxes();
624 628
625 629 QList<QSignalSpy*> spyList;
626 630
627 631 foreach(QAbstractSeries* series, seriesList) {
628 632 spyList
629 633 << new QSignalSpy(m_dataset->domain(series),
630 634 SIGNAL(updated()));
631 635 }
632 636
633 637 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
634 638
635 639 foreach(QSignalSpy* spy, spyList) {
636 640 TRY_COMPARE(spy->count(), 1);
637 641 }
638 642
639 643 qDeleteAll(spyList);
640 644 }
641 645
642 646 QTEST_MAIN(tst_ChartDataSet)
643 647 #include "tst_chartdataset.moc"
644 648 #endif
@@ -1,703 +1,707
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21 21
22 22 #include <QtTest/QtTest>
23 23
24 24 class tst_Domain: public QObject {
25 25
26 26 Q_OBJECT
27 27
28 28 private Q_SLOTS:
29 29 void skip();
30 30
31 31 };
32 32
33 33 void tst_Domain::skip()
34 34 {
35 #ifdef QT5_QUICK_1
36 QSKIP("This test requires the debug version of library");
37 #else
35 38 QSKIP("This test requires the debug version of library", SkipAll);
39 #endif
36 40 }
37 41
38 42 QTEST_MAIN(tst_Domain)
39 43 #include "tst_domain.moc"
40 44
41 45 #else
42 46
43 47 #include <QtTest/QtTest>
44 48 #include <private/domain_p.h>
45 49 #include <private/qabstractaxis_p.h>
46 50 #include <tst_definitions.h>
47 51
48 52 QTCOMMERCIALCHART_USE_NAMESPACE
49 53
50 54 Q_DECLARE_METATYPE(Domain*)
51 55 Q_DECLARE_METATYPE(QSizeF)
52 56
53 57
54 58 class AxisMock: public QAbstractAxisPrivate
55 59 {
56 60 Q_OBJECT
57 61 public:
58 62 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
59 63 ChartAxis* createGraphics(ChartPresenter* presenter)
60 64 {
61 65 Q_UNUSED(presenter);
62 66 return 0;
63 67 };
64 68 void intializeDomain(Domain* domain)
65 69 {
66 70 Q_UNUSED(domain);
67 71 };
68 72 void setMin(const QVariant &min)
69 73 {
70 74 Q_UNUSED(min);
71 75 }
72 76 qreal min() { return m_min;}
73 77 void setMax(const QVariant &max)
74 78 {
75 79 Q_UNUSED(max);
76 80 }
77 81 qreal max() { return m_max; }
78 82 void setRange(const QVariant &min, const QVariant &max)
79 83 {
80 84 Q_UNUSED(min);
81 85 Q_UNUSED(max);
82 86 };
83 87
84 88 int count () const { return m_count; }
85 89
86 90 void handleDomainUpdated(){};
87 91 public:
88 92 int m_count;
89 93 qreal m_min;
90 94 qreal m_max;
91 95 };
92 96
93 97 class tst_Domain: public QObject
94 98 {
95 99 Q_OBJECT
96 100
97 101 public Q_SLOTS:
98 102 void initTestCase();
99 103 void cleanupTestCase();
100 104 void init();
101 105 void cleanup();
102 106
103 107 private Q_SLOTS:
104 108 void domain();
105 109 void handleAxisUpdatedX_data();
106 110 void handleAxisUpdatedX();
107 111 void handleAxisUpdatedY_data();
108 112 void handleAxisUpdatedY();
109 113 void isEmpty_data();
110 114 void isEmpty();
111 115 void maxX_data();
112 116 void maxX();
113 117 void maxY_data();
114 118 void maxY();
115 119 void minX_data();
116 120 void minX();
117 121 void minY_data();
118 122 void minY();
119 123 void operatorEquals_data();
120 124 void operatorEquals();
121 125 void setRange_data();
122 126 void setRange();
123 127 void setRangeX_data();
124 128 void setRangeX();
125 129 void setRangeY_data();
126 130 void setRangeY();
127 131 void spanX_data();
128 132 void spanX();
129 133 void spanY_data();
130 134 void spanY();
131 135 void zoom_data();
132 136 void zoom();
133 137 void move_data();
134 138 void move();
135 139 };
136 140
137 141 void tst_Domain::initTestCase()
138 142 {
139 143 }
140 144
141 145 void tst_Domain::cleanupTestCase()
142 146 {
143 147 }
144 148
145 149 void tst_Domain::init()
146 150 {
147 151 }
148 152
149 153 void tst_Domain::cleanup()
150 154 {
151 155 }
152 156
153 157 void tst_Domain::domain()
154 158 {
155 159 Domain domain;
156 160
157 161 QCOMPARE(domain.isEmpty(), true);
158 162 QCOMPARE(domain.maxX(), 0.0);
159 163 QCOMPARE(domain.maxY(), 0.0);
160 164 QCOMPARE(domain.minX(), 0.0);
161 165 QCOMPARE(domain.minY(), 0.0);
162 166 }
163 167
164 168 void tst_Domain::handleAxisUpdatedX_data()
165 169 {
166 170 QTest::addColumn<qreal>("min");
167 171 QTest::addColumn<qreal>("max");
168 172 QTest::newRow("-1 1") << -1.0 << 1.0;
169 173 QTest::newRow("0 1") << 0.0 << 1.0;
170 174 QTest::newRow("-1 0") << -1.0 << 0.0;
171 175 }
172 176
173 177 void tst_Domain::handleAxisUpdatedX()
174 178 {
175 179 QFETCH(qreal, min);
176 180 QFETCH(qreal, max);
177 181
178 182 Domain domain;
179 183
180 184 QSignalSpy spy0(&domain, SIGNAL(updated()));
181 185 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
182 186 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
183 187
184 188 AxisMock axis(Qt::Horizontal);
185 189 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
186 190 axis.m_min=min;
187 191 axis.m_max=max;
188 192 axis.emitUpdated();
189 193
190 194 QVERIFY(qFuzzyIsNull(domain.minX() - min));
191 195 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
192 196
193 197 QList<QVariant> arg1 = spy1.first();
194 198 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
195 199 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
196 200
197 201 TRY_COMPARE(spy0.count(), 1);
198 202 TRY_COMPARE(spy1.count(), 1);
199 203 TRY_COMPARE(spy2.count(), 0);
200 204
201 205 }
202 206
203 207 void tst_Domain::handleAxisUpdatedY_data()
204 208 {
205 209 QTest::addColumn<qreal>("min");
206 210 QTest::addColumn<qreal>("max");
207 211 QTest::newRow("-1 1") << -1.0 << 1.0;
208 212 QTest::newRow("0 1") << 0.0 << 1.0;
209 213 QTest::newRow("-1 0") << -1.0 << 0.0;
210 214 }
211 215
212 216 void tst_Domain::handleAxisUpdatedY()
213 217 {
214 218 QFETCH(qreal, min);
215 219 QFETCH(qreal, max);
216 220
217 221 Domain domain;
218 222
219 223 QSignalSpy spy0(&domain, SIGNAL(updated()));
220 224 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
221 225 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
222 226
223 227 AxisMock axis(Qt::Vertical);
224 228 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
225 229 axis.m_min = min;
226 230 axis.m_max = max;
227 231 axis.emitUpdated();
228 232
229 233 QVERIFY(qFuzzyIsNull(domain.minY() - min));
230 234 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
231 235
232 236 QList<QVariant> arg1 = spy2.first();
233 237 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
234 238 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
235 239
236 240 TRY_COMPARE(spy0.count(), 1);
237 241 TRY_COMPARE(spy1.count(), 0);
238 242 TRY_COMPARE(spy2.count(), 1);
239 243 }
240 244
241 245 void tst_Domain::isEmpty_data()
242 246 {
243 247 QTest::addColumn<qreal>("minX");
244 248 QTest::addColumn<qreal>("maxX");
245 249 QTest::addColumn<qreal>("minY");
246 250 QTest::addColumn<qreal>("maxY");
247 251 QTest::addColumn<bool>("isEmpty");
248 252 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
249 253 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
250 254 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
251 255 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
252 256 }
253 257
254 258 void tst_Domain::isEmpty()
255 259 {
256 260 QFETCH(qreal, minX);
257 261 QFETCH(qreal, maxX);
258 262 QFETCH(qreal, minY);
259 263 QFETCH(qreal, maxY);
260 264 QFETCH(bool, isEmpty);
261 265
262 266 Domain domain;
263 267 domain.setRange(minX, maxX, minY, maxY);
264 268 QCOMPARE(domain.isEmpty(), isEmpty);
265 269 }
266 270
267 271 void tst_Domain::maxX_data()
268 272 {
269 273 QTest::addColumn<qreal>("maxX1");
270 274 QTest::addColumn<qreal>("maxX2");
271 275 QTest::addColumn<int>("count");
272 276 QTest::newRow("1") << 0.0 << 1.0 << 1;
273 277 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
274 278 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
275 279 }
276 280
277 281 void tst_Domain::maxX()
278 282 {
279 283 QFETCH(qreal, maxX1);
280 284 QFETCH(qreal, maxX2);
281 285 QFETCH(int, count);
282 286
283 287 Domain domain;
284 288
285 289 QSignalSpy spy0(&domain, SIGNAL(updated()));
286 290 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
287 291 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
288 292
289 293 domain.setMaxX(maxX1);
290 294 QCOMPARE(domain.maxX(), maxX1);
291 295 domain.setMaxX(maxX2);
292 296 QCOMPARE(domain.maxX(), maxX2);
293 297
294 298 TRY_COMPARE(spy0.count(), count);
295 299 TRY_COMPARE(spy1.count(), count);
296 300 TRY_COMPARE(spy2.count(), 0);
297 301
298 302 }
299 303
300 304 void tst_Domain::maxY_data()
301 305 {
302 306 QTest::addColumn<qreal>("maxY1");
303 307 QTest::addColumn<qreal>("maxY2");
304 308 QTest::addColumn<int>("count");
305 309 QTest::newRow("1") << 0.0 << 1.0 << 1;
306 310 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
307 311 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
308 312 }
309 313
310 314 void tst_Domain::maxY()
311 315 {
312 316 QFETCH(qreal, maxY1);
313 317 QFETCH(qreal, maxY2);
314 318 QFETCH(int, count);
315 319
316 320 Domain domain;
317 321
318 322 QSignalSpy spy0(&domain, SIGNAL(updated()));
319 323 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
320 324 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
321 325
322 326 domain.setMaxY(maxY1);
323 327 QCOMPARE(domain.maxY(), maxY1);
324 328 domain.setMaxY(maxY2);
325 329 QCOMPARE(domain.maxY(), maxY2);
326 330
327 331 TRY_COMPARE(spy0.count(), count);
328 332 TRY_COMPARE(spy1.count(), 0);
329 333 TRY_COMPARE(spy2.count(), count);
330 334 }
331 335
332 336 void tst_Domain::minX_data()
333 337 {
334 338 QTest::addColumn<qreal>("minX1");
335 339 QTest::addColumn<qreal>("minX2");
336 340 QTest::addColumn<int>("count");
337 341 QTest::newRow("1") << 0.0 << 1.0 << 1;
338 342 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
339 343 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
340 344 }
341 345
342 346 void tst_Domain::minX()
343 347 {
344 348 QFETCH(qreal, minX1);
345 349 QFETCH(qreal, minX2);
346 350 QFETCH(int, count);
347 351
348 352 Domain domain;
349 353
350 354 QSignalSpy spy0(&domain, SIGNAL(updated()));
351 355 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
352 356 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
353 357
354 358 domain.setMinX(minX1);
355 359 QCOMPARE(domain.minX(), minX1);
356 360 domain.setMinX(minX2);
357 361 QCOMPARE(domain.minX(), minX2);
358 362
359 363 TRY_COMPARE(spy0.count(), count);
360 364 TRY_COMPARE(spy1.count(), count);
361 365 TRY_COMPARE(spy2.count(), 0);
362 366 }
363 367
364 368 void tst_Domain::minY_data()
365 369 {
366 370 QTest::addColumn<qreal>("minY1");
367 371 QTest::addColumn<qreal>("minY2");
368 372 QTest::addColumn<int>("count");
369 373 QTest::newRow("1") << 0.0 << 1.0 << 1;
370 374 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
371 375 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
372 376 }
373 377
374 378 void tst_Domain::minY()
375 379 {
376 380 QFETCH(qreal, minY1);
377 381 QFETCH(qreal, minY2);
378 382 QFETCH(int, count);
379 383
380 384 Domain domain;
381 385
382 386 QSignalSpy spy0(&domain, SIGNAL(updated()));
383 387 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
384 388 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
385 389
386 390 domain.setMinY(minY1);
387 391 QCOMPARE(domain.minY(), minY1);
388 392 domain.setMinY(minY2);
389 393 QCOMPARE(domain.minY(), minY2);
390 394
391 395 TRY_COMPARE(spy0.count(), count);
392 396 TRY_COMPARE(spy1.count(), 0);
393 397 TRY_COMPARE(spy2.count(), count);
394 398 }
395 399
396 400 void tst_Domain::operatorEquals_data()
397 401 {
398 402
399 403 QTest::addColumn<Domain*>("domain1");
400 404 QTest::addColumn<Domain*>("domain2");
401 405 QTest::addColumn<bool>("equals");
402 406 QTest::addColumn<bool>("notEquals");
403 407 Domain* a;
404 408 Domain* b;
405 409 a = new Domain();
406 410 a->setRange(0, 100, 0, 100);
407 411 b = new Domain();
408 412 b->setRange(0, 100, 0, 100);
409 413 QTest::newRow("equals") << a << b << true << false;
410 414 a = new Domain();
411 415 a->setRange(0, 100, 0, 100);
412 416 b = new Domain();
413 417 b->setRange(0, 100, 0, 1);
414 418 QTest::newRow("equals") << a << b << false << true;
415 419 a = new Domain();
416 420 a->setRange(0, 100, 0, 100);
417 421 b = new Domain();
418 422 b->setRange(0, 1, 0, 100);
419 423 QTest::newRow("equals") << a << b << false << true;
420 424
421 425 }
422 426
423 427 void tst_Domain::operatorEquals()
424 428 {
425 429 QFETCH(Domain*, domain1);
426 430 QFETCH(Domain*, domain2);
427 431 QFETCH(bool, equals);
428 432 QFETCH(bool, notEquals);
429 433
430 434 Domain domain;
431 435
432 436 QSignalSpy spy0(&domain, SIGNAL(updated()));
433 437 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
434 438 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
435 439
436 440 QCOMPARE(*domain1==*domain2, equals);
437 441 QCOMPARE(*domain1!=*domain2, notEquals);
438 442
439 443 TRY_COMPARE(spy0.count(), 0);
440 444 TRY_COMPARE(spy1.count(), 0);
441 445 TRY_COMPARE(spy2.count(), 0);
442 446 }
443 447
444 448 void tst_Domain::setRange_data()
445 449 {
446 450 QTest::addColumn<qreal>("minX");
447 451 QTest::addColumn<qreal>("maxX");
448 452 QTest::addColumn<qreal>("minY");
449 453 QTest::addColumn<qreal>("maxY");
450 454 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
451 455 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
452 456 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
453 457 }
454 458
455 459 void tst_Domain::setRange()
456 460 {
457 461 QFETCH(qreal, minX);
458 462 QFETCH(qreal, maxX);
459 463 QFETCH(qreal, minY);
460 464 QFETCH(qreal, maxY);
461 465
462 466 Domain domain;
463 467
464 468 QSignalSpy spy0(&domain, SIGNAL(updated()));
465 469 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
466 470 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
467 471
468 472 domain.setRange(minX, maxX, minY, maxY);
469 473
470 474 QCOMPARE(domain.minX(), minX);
471 475 QCOMPARE(domain.maxX(), maxX);
472 476 QCOMPARE(domain.minY(), minY);
473 477 QCOMPARE(domain.maxY(), maxY);
474 478
475 479 TRY_COMPARE(spy0.count(), 1);
476 480 TRY_COMPARE(spy1.count(), 1);
477 481 TRY_COMPARE(spy2.count(), 1);
478 482
479 483 }
480 484
481 485 void tst_Domain::setRangeX_data()
482 486 {
483 487 QTest::addColumn<qreal>("min");
484 488 QTest::addColumn<qreal>("max");
485 489 QTest::newRow("-1 1") << -1.0 << 1.0;
486 490 QTest::newRow("0 1") << 0.0 << 1.0;
487 491 QTest::newRow("-1 0") << -1.0 << 0.0;
488 492 }
489 493
490 494 void tst_Domain::setRangeX()
491 495 {
492 496 QFETCH(qreal, min);
493 497 QFETCH(qreal, max);
494 498
495 499 Domain domain;
496 500
497 501 QSignalSpy spy0(&domain, SIGNAL(updated()));
498 502 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
499 503 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
500 504
501 505 domain.setRangeX(min, max);
502 506
503 507 QVERIFY(qFuzzyIsNull(domain.minX() - min));
504 508 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
505 509
506 510 QList<QVariant> arg1 = spy1.first();
507 511 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
508 512 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
509 513
510 514 TRY_COMPARE(spy0.count(), 1);
511 515 TRY_COMPARE(spy1.count(), 1);
512 516 TRY_COMPARE(spy2.count(), 0);
513 517 }
514 518
515 519 void tst_Domain::setRangeY_data()
516 520 {
517 521 QTest::addColumn<qreal>("min");
518 522 QTest::addColumn<qreal>("max");
519 523 QTest::newRow("-1 1") << -1.0 << 1.0;
520 524 QTest::newRow("0 1") << 0.0 << 1.0;
521 525 QTest::newRow("-1 0") << -1.0 << 0.0;
522 526 }
523 527
524 528 void tst_Domain::setRangeY()
525 529 {
526 530 QFETCH(qreal, min);
527 531 QFETCH(qreal, max);
528 532
529 533 Domain domain;
530 534
531 535 QSignalSpy spy0(&domain, SIGNAL(updated()));
532 536 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
533 537 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
534 538
535 539 domain.setRangeY(min, max);
536 540
537 541 QVERIFY(qFuzzyIsNull(domain.minY() - min));
538 542 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
539 543
540 544 QList<QVariant> arg1 = spy2.first();
541 545 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
542 546 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
543 547
544 548 TRY_COMPARE(spy0.count(), 1);
545 549 TRY_COMPARE(spy1.count(), 0);
546 550 TRY_COMPARE(spy2.count(), 1);
547 551 }
548 552
549 553 void tst_Domain::spanX_data()
550 554 {
551 555 QTest::addColumn<qreal>("minX");
552 556 QTest::addColumn<qreal>("maxX");
553 557 QTest::addColumn<qreal>("spanX");
554 558 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
555 559 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
556 560 }
557 561
558 562 void tst_Domain::spanX()
559 563 {
560 564 QFETCH(qreal, minX);
561 565 QFETCH(qreal, maxX);
562 566 QFETCH(qreal, spanX);
563 567
564 568 Domain domain;
565 569
566 570 domain.setRangeX(minX, maxX);
567 571
568 572 QSignalSpy spy0(&domain, SIGNAL(updated()));
569 573 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
570 574 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
571 575
572 576 QCOMPARE(domain.spanX(), spanX);
573 577
574 578 TRY_COMPARE(spy0.count(), 0);
575 579 TRY_COMPARE(spy1.count(), 0);
576 580 TRY_COMPARE(spy2.count(), 0);
577 581 }
578 582
579 583 void tst_Domain::spanY_data()
580 584 {
581 585 QTest::addColumn<qreal>("minY");
582 586 QTest::addColumn<qreal>("maxY");
583 587 QTest::addColumn<qreal>("spanY");
584 588 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
585 589 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
586 590 }
587 591
588 592 void tst_Domain::spanY()
589 593 {
590 594 QFETCH(qreal, minY);
591 595 QFETCH(qreal, maxY);
592 596 QFETCH(qreal, spanY);
593 597
594 598 Domain domain;
595 599
596 600 domain.setRangeY(minY, maxY);
597 601
598 602 QSignalSpy spy0(&domain, SIGNAL(updated()));
599 603 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
600 604 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
601 605
602 606 QCOMPARE(domain.spanY(), spanY);
603 607
604 608 TRY_COMPARE(spy0.count(), 0);
605 609 TRY_COMPARE(spy1.count(), 0);
606 610 TRY_COMPARE(spy2.count(), 0);
607 611 }
608 612
609 613 void tst_Domain::zoom_data()
610 614 {
611 615 QTest::addColumn<QRectF>("rect0");
612 616 QTest::addColumn<QSizeF>("size0");
613 617 QTest::addColumn<QRectF>("rect1");
614 618 QTest::addColumn<QSizeF>("size1");
615 619 QTest::addColumn<QRectF>("rect2");
616 620 QTest::addColumn<QSizeF>("size2");
617 621 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
618 622 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
619 623 << QSizeF(1000, 1000);
620 624 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
621 625 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
622 626 << QSizeF(1000, 1000);
623 627 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
624 628 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
625 629 }
626 630
627 631 void tst_Domain::zoom()
628 632 {
629 633 QFETCH(QRectF, rect0);
630 634 QFETCH(QSizeF, size0);
631 635 QFETCH(QRectF, rect1);
632 636 QFETCH(QSizeF, size1);
633 637 QFETCH(QRectF, rect2);
634 638 QFETCH(QSizeF, size2);
635 639
636 640 Domain domain;
637 641
638 642 domain.setRange(0, 1000, 0, 1000);
639 643
640 644 QSignalSpy spy0(&domain, SIGNAL(updated()));
641 645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
642 646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
643 647
644 648 Domain domain0;
645 649 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
646 650 domain.zoomIn(rect0, size0);
647 651 Domain domain1;
648 652 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
649 653 domain.zoomIn(rect1, size1);
650 654 Domain domain2;
651 655 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
652 656 domain.zoomIn(rect2, size2);
653 657 domain.zoomOut(rect2, size2);
654 658 QCOMPARE(domain == domain2, true);
655 659 domain.zoomOut(rect1, size1);
656 660 QCOMPARE(domain == domain1, true);
657 661 domain.zoomOut(rect0, size0);
658 662 QCOMPARE(domain == domain0, true);
659 663 TRY_COMPARE(spy0.count(), 6);
660 664 TRY_COMPARE(spy1.count(), 6);
661 665 TRY_COMPARE(spy2.count(), 6);
662 666 }
663 667
664 668 void tst_Domain::move_data()
665 669 {
666 670 QTest::addColumn<int>("dx");
667 671 QTest::addColumn<int>("dy");
668 672 QTest::addColumn<QSizeF>("size");
669 673 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
670 674 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
671 675 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
672 676 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
673 677 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
674 678 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
675 679 }
676 680
677 681 void tst_Domain::move()
678 682 {
679 683 QFETCH(int, dx);
680 684 QFETCH(int, dy);
681 685 QFETCH(QSizeF, size);
682 686 Domain domain;
683 687
684 688 domain.setRange(0, size.width(), 0, size.height());
685 689
686 690 QSignalSpy spy0(&domain, SIGNAL(updated()));
687 691 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
688 692 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
689 693
690 694 domain.move(dx, dy, size);
691 695
692 696 Domain result;
693 697 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
694 698
695 699 QCOMPARE(domain == result, true);
696 700 TRY_COMPARE(spy0.count(), 1);
697 701 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
698 702 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
699 703 }
700 704
701 705 QTEST_MAIN(tst_Domain)
702 706 #include "tst_domain.moc"
703 707 #endif
@@ -1,847 +1,863
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "tst_qabstractaxis.h"
22 22
23 23 Q_DECLARE_METATYPE(QPen)
24 24 Q_DECLARE_METATYPE(Qt::Orientation)
25 25
26 26 void tst_QAbstractAxis::initTestCase()
27 27 {
28 28 }
29 29
30 30 void tst_QAbstractAxis::cleanupTestCase()
31 31 {
32 32 }
33 33
34 34 void tst_QAbstractAxis::init(QAbstractAxis* axis, QAbstractSeries* series)
35 35 {
36 36 m_axis = axis;
37 37 m_series = series;
38 38 m_view = new QChartView(new QChart());
39 39 m_chart = m_view->chart();
40 40 }
41 41
42 42 void tst_QAbstractAxis::cleanup()
43 43 {
44 44 delete m_view;
45 45 m_view = 0;
46 46 m_chart = 0;
47 47 m_axis = 0;
48 48 }
49 49
50 50 void tst_QAbstractAxis::qabstractaxis()
51 51 {
52 52 QCOMPARE(m_axis->linePen(), QPen());
53 53 //TODO QCOMPARE(m_axis->axisPenColor(), QColor());
54 54 QCOMPARE(m_axis->gridLinePen(), QPen());
55 55 QCOMPARE(m_axis->isLineVisible(), true);
56 56 QCOMPARE(m_axis->isGridLineVisible(), true);
57 57 QCOMPARE(m_axis->isVisible(), false);
58 58 QCOMPARE(m_axis->labelsAngle(), 0);
59 59 QCOMPARE(m_axis->labelsBrush(), QBrush());
60 60 //TODO QCOMPARE(m_axis->labelsColor(), QColor());
61 61 QCOMPARE(m_axis->labelsFont(), QFont());
62 62 QCOMPARE(m_axis->labelsPen(), QPen());
63 63 QCOMPARE(m_axis->labelsVisible(), true);
64 64 QCOMPARE(m_axis->orientation(), Qt::Orientation(0));
65 65 m_axis->setLineVisible(false);
66 66 m_axis->setLinePen(QPen());
67 67 m_axis->setLinePenColor(QColor());
68 68 m_axis->setGridLinePen(QPen());
69 69 m_axis->setGridLineVisible(false);
70 70 m_axis->setLabelsAngle(-1);
71 71 m_axis->setLabelsBrush(QBrush());
72 72 m_axis->setLabelsColor(QColor());
73 73 m_axis->setLabelsFont(QFont());
74 74 m_axis->setLabelsPen(QPen());
75 75 m_axis->setLabelsVisible(false);
76 76 m_axis->setMax(QVariant());
77 77 m_axis->setMin(QVariant());
78 78 m_axis->setRange(QVariant(), QVariant());
79 79 m_axis->setShadesBorderColor(QColor());
80 80 m_axis->setShadesBrush(QBrush());
81 81 m_axis->setShadesColor(QColor());
82 82 m_axis->setShadesPen(QPen());
83 83 m_axis->setShadesVisible(false);
84 84 m_axis->setVisible(false);
85 85 //TODO QCOMPARE(m_axis->shadesBorderColor(), QColor());
86 86 //TODO QCOMPARE(m_axis->shadesBrush(), QBrush());
87 87 //TODO QCOMPARE(m_axis->shadesColor(), QColor());
88 88 QCOMPARE(m_axis->shadesPen(), QPen());
89 89 QCOMPARE(m_axis->shadesVisible(), false);
90 90 m_axis->show();
91 91 m_axis->hide();
92 92 }
93 93
94 94 void tst_QAbstractAxis::axisPen_data()
95 95 {
96 96 QTest::addColumn<QPen>("axisPen");
97 97 QTest::newRow("null") << QPen();
98 98 QTest::newRow("blue") << QPen(Qt::blue);
99 99 QTest::newRow("black") << QPen(Qt::black);
100 100 QTest::newRow("red") << QPen(Qt::red);
101 101 }
102 102
103 103 void tst_QAbstractAxis::axisPen()
104 104 {
105 105 QFETCH(QPen, axisPen);
106 106
107 107 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
108 108 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
109 109 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
110 110 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
111 111 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
112 112 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
113 113 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
114 114 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
115 115 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
116 116
117 117 m_axis->setLinePen(axisPen);
118 118 QCOMPARE(m_axis->linePen(), axisPen);
119 119
120 120 QCOMPARE(spy0.count(), 0);
121 121 QCOMPARE(spy1.count(), 0);
122 122 QCOMPARE(spy2.count(), 0);
123 123 QCOMPARE(spy3.count(), 0);
124 124 QCOMPARE(spy4.count(), 0);
125 125 QCOMPARE(spy5.count(), 0);
126 126 QCOMPARE(spy6.count(), 0);
127 127 QCOMPARE(spy7.count(), 0);
128 128 QCOMPARE(spy8.count(), 0);
129 129
130 130 m_chart->setAxisX(m_axis, m_series);
131 131 m_view->show();
132 132 QTest::qWaitForWindowShown(m_view);
133 133 //TODO QCOMPARE(m_axis->axisPen(), axisPen);
134 134 }
135 135
136 136 void tst_QAbstractAxis::axisPenColor_data()
137 137 {
138 138 }
139 139
140 140 void tst_QAbstractAxis::axisPenColor()
141 141 {
142 #ifdef QT5_QUICK_1
143 QSKIP("Test is not implemented. This is depreciated function");
144 #else
142 145 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
146 #endif
143 147 }
144 148
145 149 void tst_QAbstractAxis::gridLinePen_data()
146 150 {
147 151
148 152 QTest::addColumn<QPen>("gridLinePen");
149 153 QTest::newRow("null") << QPen();
150 154 QTest::newRow("blue") << QPen(Qt::blue);
151 155 QTest::newRow("black") << QPen(Qt::black);
152 156 QTest::newRow("red") << QPen(Qt::red);
153 157
154 158 }
155 159
156 160 void tst_QAbstractAxis::gridLinePen()
157 161 {
158 162 QFETCH(QPen, gridLinePen);
159 163
160 164 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
161 165 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
162 166 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
163 167 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
164 168 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
165 169 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
166 170 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
167 171 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
168 172 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
169 173
170 174 m_axis->setGridLinePen(gridLinePen);
171 175 QCOMPARE(m_axis->gridLinePen(), gridLinePen);
172 176
173 177 QCOMPARE(spy0.count(), 0);
174 178 QCOMPARE(spy1.count(), 0);
175 179 QCOMPARE(spy2.count(), 0);
176 180 QCOMPARE(spy3.count(), 0);
177 181 QCOMPARE(spy4.count(), 0);
178 182 QCOMPARE(spy5.count(), 0);
179 183 QCOMPARE(spy6.count(), 0);
180 184 QCOMPARE(spy7.count(), 0);
181 185 QCOMPARE(spy8.count(), 0);
182 186
183 187 m_chart->setAxisX(m_axis, m_series);
184 188 m_view->show();
185 189 QTest::qWaitForWindowShown(m_view);
186 190 //TODO QCOMPARE(m_axis->gridLinePen(), gridLinePen);
187 191 }
188 192
189 193 void tst_QAbstractAxis::lineVisible_data()
190 194 {
191 195 QTest::addColumn<bool>("lineVisible");
192 196 QTest::newRow("true") << true;
193 197 QTest::newRow("false") << false;
194 198 }
195 199
196 200 void tst_QAbstractAxis::lineVisible()
197 201 {
198 202 QFETCH(bool, lineVisible);
199 203
200 204 m_axis->setLineVisible(!lineVisible);
201 205
202 206 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
203 207 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
204 208 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
205 209 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
206 210 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
207 211 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
208 212 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
209 213 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
210 214 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
211 215
212 216 m_axis->setLineVisible(lineVisible);
213 217 QCOMPARE(m_axis->isLineVisible(), lineVisible);
214 218
215 219 QCOMPARE(spy0.count(), 1);
216 220 QCOMPARE(spy1.count(), 0);
217 221 QCOMPARE(spy2.count(), 0);
218 222 QCOMPARE(spy3.count(), 0);
219 223 QCOMPARE(spy4.count(), 0);
220 224 QCOMPARE(spy5.count(), 0);
221 225 QCOMPARE(spy6.count(), 0);
222 226 QCOMPARE(spy7.count(), 0);
223 227 QCOMPARE(spy8.count(), 0);
224 228
225 229 m_chart->setAxisX(m_axis, m_series);
226 230 m_view->show();
227 231 QTest::qWaitForWindowShown(m_view);
228 232 QCOMPARE(m_axis->isLineVisible(), lineVisible);
229 233 }
230 234
231 235 void tst_QAbstractAxis::gridLineVisible_data()
232 236 {
233 237 QTest::addColumn<bool>("gridLineVisible");
234 238 QTest::newRow("true") << true;
235 239 QTest::newRow("false") << false;
236 240 }
237 241
238 242 void tst_QAbstractAxis::gridLineVisible()
239 243 {
240 244 QFETCH(bool, gridLineVisible);
241 245
242 246 m_axis->setGridLineVisible(!gridLineVisible);
243 247
244 248 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
245 249 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
246 250 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
247 251 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
248 252 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
249 253 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
250 254 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
251 255 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
252 256 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
253 257
254 258 m_axis->setGridLineVisible(gridLineVisible);
255 259 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
256 260
257 261 QCOMPARE(spy0.count(), 0);
258 262 QCOMPARE(spy1.count(), 0);
259 263 QCOMPARE(spy2.count(), 1);
260 264 QCOMPARE(spy3.count(), 0);
261 265 QCOMPARE(spy4.count(), 0);
262 266 QCOMPARE(spy5.count(), 0);
263 267 QCOMPARE(spy6.count(), 0);
264 268 QCOMPARE(spy7.count(), 0);
265 269 QCOMPARE(spy8.count(), 0);
266 270
267 271 m_chart->setAxisX(m_axis, m_series);
268 272 m_view->show();
269 273 QTest::qWaitForWindowShown(m_view);
270 274 QCOMPARE(m_axis->isGridLineVisible(), gridLineVisible);
271 275
272 276 }
273 277
274 278 void tst_QAbstractAxis::visible_data()
275 279 {
276 280 QTest::addColumn<bool>("visible");
277 281 QTest::newRow("true") << true;
278 282 QTest::newRow("false") << false;
279 283 }
280 284
281 285 void tst_QAbstractAxis::visible()
282 286 {
283 287 QFETCH(bool, visible);
284 288
285 289 m_axis->setVisible(!visible);
286 290
287 291 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
288 292 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
289 293 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
290 294 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
291 295 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
292 296 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
293 297 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
294 298 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
295 299 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
296 300
297 301 m_axis->setVisible(visible);
298 302 QCOMPARE(m_axis->isVisible(), visible);
299 303
300 304 QCOMPARE(spy0.count(), 0);
301 305 QCOMPARE(spy1.count(), 0);
302 306 QCOMPARE(spy2.count(), 0);
303 307 QCOMPARE(spy3.count(), 0);
304 308 QCOMPARE(spy4.count(), 0);
305 309 QCOMPARE(spy5.count(), 0);
306 310 QCOMPARE(spy6.count(), 0);
307 311 QCOMPARE(spy7.count(), 0);
308 312 QCOMPARE(spy8.count(), 1);
309 313
310 314 m_chart->setAxisX(m_axis, m_series);
311 315 m_view->show();
312 316 QTest::qWaitForWindowShown(m_view);
313 317 QCOMPARE(m_axis->isVisible(), true);
314 318 }
315 319
316 320 void tst_QAbstractAxis::labelsAngle_data()
317 321 {
318 322 QTest::addColumn<int>("labelsAngle");
319 323 QTest::newRow("0") << 0;
320 324 QTest::newRow("45") << 45;
321 325 QTest::newRow("90") << 90;
322 326 }
323 327
324 328 void tst_QAbstractAxis::labelsAngle()
325 329 {
326 330 QFETCH(int, labelsAngle);
327 331
328 332 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
329 333 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
330 334 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
331 335 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
332 336 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
333 337 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
334 338 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
335 339 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
336 340 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
337 341
338 342 m_axis->setLabelsAngle(labelsAngle);
339 343 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
340 344
341 345 QCOMPARE(spy0.count(), 0);
342 346 QCOMPARE(spy1.count(), 0);
343 347 QCOMPARE(spy2.count(), 0);
344 348 QCOMPARE(spy3.count(), 0);
345 349 QCOMPARE(spy4.count(), 0);
346 350 QCOMPARE(spy5.count(), 0);
347 351 QCOMPARE(spy6.count(), 0);
348 352 QCOMPARE(spy7.count(), 0);
349 353 QCOMPARE(spy8.count(), 0);
350 354
351 355 m_chart->setAxisX(m_axis, m_series);
352 356 m_view->show();
353 357 QTest::qWaitForWindowShown(m_view);
354 358 QCOMPARE(m_axis->labelsAngle(), labelsAngle);
355 359 }
356 360
357 361 void tst_QAbstractAxis::labelsBrush_data()
358 362 {
359 363 QTest::addColumn<QBrush>("labelsBrush");
360 364 QTest::newRow("null") << QBrush();
361 365 QTest::newRow("blue") << QBrush(Qt::blue);
362 366 QTest::newRow("black") << QBrush(Qt::black);
363 367
364 368 }
365 369
366 370 void tst_QAbstractAxis::labelsBrush()
367 371 {
368 372
369 373 QFETCH(QBrush, labelsBrush);
370 374
371 375 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
372 376 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
373 377 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
374 378 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
375 379 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
376 380 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
377 381 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
378 382 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
379 383 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
380 384
381 385 m_axis->setLabelsBrush(labelsBrush);
382 386 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
383 387
384 388 QCOMPARE(spy0.count(), 0);
385 389 QCOMPARE(spy1.count(), 0);
386 390 QCOMPARE(spy2.count(), 0);
387 391 QCOMPARE(spy3.count(), 0);
388 392 QCOMPARE(spy4.count(), 0);
389 393 QCOMPARE(spy5.count(), 0);
390 394 //TODO QCOMPARE(spy6.count(), 0);
391 395 QCOMPARE(spy7.count(), 0);
392 396 QCOMPARE(spy8.count(), 0);
393 397
394 398 m_view->show();
395 399 QTest::qWaitForWindowShown(m_view);
396 400 QCOMPARE(m_axis->labelsBrush(), labelsBrush);
397 401
398 402 }
399 403
400 404 void tst_QAbstractAxis::labelsColor_data()
401 405 {
402 406
403 407 }
404 408
405 409 void tst_QAbstractAxis::labelsColor()
406 410 {
411 #ifdef QT5_QUICK_1
412 QSKIP("Test is not implemented. This is depreciated function");
413 #else
407 414 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
415 #endif
408 416 }
409 417
410 418 void tst_QAbstractAxis::labelsFont_data()
411 419 {
412 420 QTest::addColumn<QFont>("labelsFont");
413 421 QTest::newRow("null") << QFont();
414 422 QTest::newRow("serif") << QFont("SansSerif");
415 423 }
416 424
417 425 void tst_QAbstractAxis::labelsFont()
418 426 {
419 427
420 428 QFETCH(QFont, labelsFont);
421 429
422 430 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
423 431 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
424 432 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
425 433 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
426 434 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
427 435 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
428 436 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
429 437 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
430 438 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
431 439
432 440 m_axis->setLabelsFont(labelsFont);
433 441 QCOMPARE(m_axis->labelsFont(), labelsFont);
434 442
435 443 QCOMPARE(spy0.count(), 0);
436 444 QCOMPARE(spy1.count(), 0);
437 445 QCOMPARE(spy2.count(), 0);
438 446 QCOMPARE(spy3.count(), 0);
439 447 QCOMPARE(spy4.count(), 0);
440 448 QCOMPARE(spy5.count(), 0);
441 449 QCOMPARE(spy6.count(), 0);
442 450 QCOMPARE(spy7.count(), 0);
443 451 QCOMPARE(spy8.count(), 0);
444 452
445 453 m_view->show();
446 454 QTest::qWaitForWindowShown(m_view);
447 455 QCOMPARE(m_axis->labelsFont(), labelsFont);
448 456
449 457 }
450 458
451 459 void tst_QAbstractAxis::labelsPen_data()
452 460 {
453 461 QTest::addColumn<QPen>("labelsPen");
454 462 QTest::newRow("null") << QPen();
455 463 QTest::newRow("blue") << QPen(Qt::blue);
456 464 QTest::newRow("black") << QPen(Qt::black);
457 465 QTest::newRow("red") << QPen(Qt::red);
458 466 }
459 467
460 468 void tst_QAbstractAxis::labelsPen()
461 469 {
462 470 QFETCH(QPen, labelsPen);
463 471
464 472 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
465 473 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
466 474 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
467 475 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
468 476 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
469 477 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
470 478 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
471 479 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
472 480 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
473 481
474 482 m_axis->setLabelsPen(labelsPen);
475 483 QCOMPARE(m_axis->labelsPen(), labelsPen);
476 484
477 485 QCOMPARE(spy0.count(), 0);
478 486 QCOMPARE(spy1.count(), 0);
479 487 QCOMPARE(spy2.count(), 0);
480 488 QCOMPARE(spy3.count(), 0);
481 489 QCOMPARE(spy4.count(), 0);
482 490 QCOMPARE(spy5.count(), 0);
483 491 QCOMPARE(spy6.count(), 0);
484 492 QCOMPARE(spy7.count(), 0);
485 493 QCOMPARE(spy8.count(), 0);
486 494
487 495 m_chart->setAxisX(m_axis, m_series);
488 496 m_view->show();
489 497 QTest::qWaitForWindowShown(m_view);
490 498 //TODO QCOMPARE(m_axis->labelsPen(), labelsPen);
491 499 }
492 500
493 501 void tst_QAbstractAxis::labelsVisible_data()
494 502 {
495 503 QTest::addColumn<bool>("labelsVisible");
496 504 QTest::newRow("true") << true;
497 505 QTest::newRow("false") << false;
498 506 }
499 507
500 508 void tst_QAbstractAxis::labelsVisible()
501 509 {
502 510 QFETCH(bool, labelsVisible);
503 511
504 512 m_axis->setLabelsVisible(!labelsVisible);
505 513
506 514 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
507 515 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
508 516 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
509 517 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
510 518 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
511 519 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
512 520 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
513 521 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
514 522 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
515 523
516 524 m_axis->setLabelsVisible(labelsVisible);
517 525 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
518 526
519 527 QCOMPARE(spy0.count(), 0);
520 528 QCOMPARE(spy1.count(), 0);
521 529 QCOMPARE(spy2.count(), 0);
522 530 QCOMPARE(spy3.count(), 0);
523 531 QCOMPARE(spy4.count(), 1);
524 532 QCOMPARE(spy5.count(), 0);
525 533 QCOMPARE(spy6.count(), 0);
526 534 QCOMPARE(spy7.count(), 0);
527 535 QCOMPARE(spy8.count(), 0);
528 536
529 537 m_chart->setAxisX(m_axis, m_series);
530 538 m_view->show();
531 539 QTest::qWaitForWindowShown(m_view);
532 540 QCOMPARE(m_axis->labelsVisible(), labelsVisible);
533 541 }
534 542
535 543 void tst_QAbstractAxis::orientation_data()
536 544 {
537 545 QTest::addColumn<Qt::Orientation>("orientation");
538 546 QTest::newRow("Vertical") << Qt::Vertical;
539 547 QTest::newRow("Horizontal") << Qt::Horizontal;
540 548 }
541 549
542 550 void tst_QAbstractAxis::orientation()
543 551 {
544 552 QFETCH(Qt::Orientation, orientation);
545 553
546 554 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
547 555 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
548 556 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
549 557 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
550 558 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
551 559 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
552 560 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
553 561 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
554 562 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
555 563
556 564 if(orientation==Qt::Vertical){
557 565 m_chart->setAxisY(m_axis,m_series);
558 566 }else{
559 567 m_chart->setAxisX(m_axis,m_series);
560 568 }
561 569 QCOMPARE(m_axis->orientation(), orientation);
562 570
563 571 QCOMPARE(spy0.count(), 0);
564 572 QCOMPARE(spy1.count(), 0);
565 573 QCOMPARE(spy2.count(), 0);
566 574 QCOMPARE(spy3.count(), 0);
567 575 QCOMPARE(spy4.count(), 0);
568 576 QCOMPARE(spy5.count(), 0);
569 577 QCOMPARE(spy6.count(), 0);
570 578 QCOMPARE(spy7.count(), 0);
571 579 QCOMPARE(spy8.count(), 1);
572 580
573 581 m_view->show();
574 582 QTest::qWaitForWindowShown(m_view);
575 583 QCOMPARE(m_axis->orientation(), orientation);
576 584 }
577 585
578 586 void tst_QAbstractAxis::setMax_data()
579 587 {
580 588 //just check if it does not crash
581 589 QTest::addColumn<QVariant>("max");
582 590 QTest::newRow("something") << QVariant("something");
583 591 QTest::newRow("1.0") << QVariant(1.0);
584 592 }
585 593
586 594 void tst_QAbstractAxis::setMax()
587 595 {
588 596 QFETCH(QVariant, max);
589 597 m_axis->setMax(max);
590 598 }
591 599
592 600 void tst_QAbstractAxis::setMin_data()
593 601 {
594 602 //just check if it does not crash
595 603 QTest::addColumn<QVariant>("min");
596 604 QTest::newRow("something") << QVariant("something");
597 605 QTest::newRow("1.0") << QVariant(1.0);
598 606 }
599 607
600 608 // public void setMin(QVariant const& min)
601 609 void tst_QAbstractAxis::setMin()
602 610 {
603 611 QFETCH(QVariant, min);
604 612 m_axis->setMin(min);
605 613 }
606 614
607 615 void tst_QAbstractAxis::setRange_data()
608 616 {
609 617 //just check if it does not crash
610 618 QTest::addColumn<QVariant>("min");
611 619 QTest::addColumn<QVariant>("max");
612 620 QTest::newRow("something") << QVariant("something0") << QVariant("something1");
613 621 QTest::newRow("-1 1") << QVariant(-1.0) << QVariant(1.0);
614 622 }
615 623
616 624 // public void setRange(QVariant const& min, QVariant const& max)
617 625 void tst_QAbstractAxis::setRange()
618 626 {
619 627
620 628 QFETCH(QVariant, min);
621 629 QFETCH(QVariant, max);
622 630 m_axis->setRange(min,max);
623 631 }
624 632
625 633 void tst_QAbstractAxis::shadesBorderColor_data()
626 634 {
627 635
628 636 }
629 637
630 638 void tst_QAbstractAxis::shadesBorderColor()
631 639 {
640 #ifdef QT5_QUICK_1
641 QSKIP("Test is not implemented. This is depreciated function");
642 #else
632 643 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
644 #endif
633 645 }
634 646
635 647 void tst_QAbstractAxis::shadesBrush_data()
636 648 {
637 649 QTest::addColumn<QBrush>("shadesBrush");
638 650 QTest::newRow("null") << QBrush();
639 651 QTest::newRow("blue") << QBrush(Qt::blue);
640 652 QTest::newRow("black") << QBrush(Qt::black);
641 653 }
642 654
643 655 void tst_QAbstractAxis::shadesBrush()
644 656 {
645 657 QFETCH(QBrush, shadesBrush);
646 658
647 659 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
648 660 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
649 661 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
650 662 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
651 663 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
652 664 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
653 665 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
654 666 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
655 667 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
656 668
657 669 m_axis->setShadesBrush(shadesBrush);
658 670 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
659 671
660 672 QCOMPARE(spy0.count(), 0);
661 673 QCOMPARE(spy1.count(), 0);
662 674 QCOMPARE(spy2.count(), 0);
663 675 QCOMPARE(spy3.count(), 0);
664 676 QCOMPARE(spy4.count(), 0);
665 677 QCOMPARE(spy5.count(), 0);
666 678 //TODO QCOMPARE(spy6.count(), 0);
667 679 QCOMPARE(spy7.count(), 0);
668 680 QCOMPARE(spy8.count(), 0);
669 681
670 682 m_view->show();
671 683 QTest::qWaitForWindowShown(m_view);
672 684 QCOMPARE(m_axis->shadesBrush(), shadesBrush);
673 685 }
674 686
675 687 void tst_QAbstractAxis::shadesColor_data()
676 688 {
677 689 }
678 690
679 691 // public QColor shadesColor() const
680 692 void tst_QAbstractAxis::shadesColor()
681 693 {
694 #ifdef QT5_QUICK_1
695 QSKIP("Test is not implemented. This is depreciated function");
696 #else
682 697 QSKIP("Test is not implemented. This is depreciated function", SkipAll);
698 #endif
683 699 }
684 700
685 701 void tst_QAbstractAxis::shadesPen_data()
686 702 {
687 703 QTest::addColumn<QPen>("shadesPen");
688 704 QTest::newRow("null") << QPen();
689 705 QTest::newRow("blue") << QPen(Qt::blue);
690 706 QTest::newRow("black") << QPen(Qt::black);
691 707 QTest::newRow("red") << QPen(Qt::red);
692 708 }
693 709
694 710 void tst_QAbstractAxis::shadesPen()
695 711 {
696 712 QFETCH(QPen, shadesPen);
697 713
698 714 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
699 715 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
700 716 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
701 717 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
702 718 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
703 719 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
704 720 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
705 721 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
706 722 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
707 723
708 724 m_axis->setShadesPen(shadesPen);
709 725 QCOMPARE(m_axis->shadesPen(), shadesPen);
710 726
711 727 QCOMPARE(spy0.count(), 0);
712 728 QCOMPARE(spy1.count(), 0);
713 729 QCOMPARE(spy2.count(), 0);
714 730 QCOMPARE(spy3.count(), 0);
715 731 QCOMPARE(spy4.count(), 0);
716 732 QCOMPARE(spy5.count(), 0);
717 733 QCOMPARE(spy6.count(), 0);
718 734 QCOMPARE(spy7.count(), 0);
719 735 QCOMPARE(spy8.count(), 0);
720 736
721 737 m_chart->setAxisX(m_axis, m_series);
722 738 m_view->show();
723 739 QTest::qWaitForWindowShown(m_view);
724 740 QCOMPARE(m_axis->shadesPen(), shadesPen);
725 741 }
726 742
727 743 void tst_QAbstractAxis::shadesVisible_data()
728 744 {
729 745 QTest::addColumn<bool>("shadesVisible");
730 746 QTest::newRow("true") << true;
731 747 QTest::newRow("false") << false;
732 748 }
733 749
734 750 void tst_QAbstractAxis::shadesVisible()
735 751 {
736 752 QFETCH(bool, shadesVisible);
737 753
738 754 m_axis->setShadesVisible(!shadesVisible);
739 755
740 756 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
741 757 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
742 758 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
743 759 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
744 760 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
745 761 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
746 762 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
747 763 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
748 764 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
749 765
750 766 m_axis->setShadesVisible(shadesVisible);
751 767 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
752 768
753 769 QCOMPARE(spy0.count(), 0);
754 770 QCOMPARE(spy1.count(), 0);
755 771 QCOMPARE(spy2.count(), 0);
756 772 QCOMPARE(spy3.count(), 0);
757 773 QCOMPARE(spy4.count(), 0);
758 774 QCOMPARE(spy5.count(), 0);
759 775 QCOMPARE(spy6.count(), 0);
760 776 QCOMPARE(spy7.count(), 1);
761 777 QCOMPARE(spy8.count(), 0);
762 778
763 779 m_chart->setAxisX(m_axis, m_series);
764 780 m_view->show();
765 781 QTest::qWaitForWindowShown(m_view);
766 782 QCOMPARE(m_axis->shadesVisible(), shadesVisible);
767 783 }
768 784
769 785 void tst_QAbstractAxis::show_data()
770 786 {
771 787
772 788 }
773 789
774 790 void tst_QAbstractAxis::show()
775 791 {
776 792 m_axis->hide();
777 793 QCOMPARE(m_axis->isVisible(), false);
778 794
779 795 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
780 796 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
781 797 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
782 798 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
783 799 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
784 800 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
785 801 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
786 802 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
787 803 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
788 804
789 805 m_axis->show();
790 806
791 807 QCOMPARE(spy0.count(), 0);
792 808 QCOMPARE(spy1.count(), 0);
793 809 QCOMPARE(spy2.count(), 0);
794 810 QCOMPARE(spy3.count(), 0);
795 811 QCOMPARE(spy4.count(), 0);
796 812 QCOMPARE(spy5.count(), 0);
797 813 QCOMPARE(spy6.count(), 0);
798 814 QCOMPARE(spy7.count(), 0);
799 815 QCOMPARE(spy8.count(), 1);
800 816 QCOMPARE(m_axis->isVisible(), true);
801 817 }
802 818
803 819 void tst_QAbstractAxis::hide_data()
804 820 {
805 821
806 822 }
807 823
808 824 void tst_QAbstractAxis::hide()
809 825 {
810 826 m_axis->show();
811 827 QCOMPARE(m_axis->isVisible(),true);
812 828
813 829 QSignalSpy spy0(m_axis, SIGNAL(lineVisibleChanged(bool)));
814 830 QSignalSpy spy1(m_axis, SIGNAL(colorChanged(QColor)));
815 831 QSignalSpy spy2(m_axis, SIGNAL(gridVisibleChanged(bool)));
816 832 QSignalSpy spy3(m_axis, SIGNAL(labelsColorChanged(QColor)));
817 833 QSignalSpy spy4(m_axis, SIGNAL(labelsVisibleChanged(bool)));
818 834 QSignalSpy spy5(m_axis, SIGNAL(shadesBorderColorChanged(QColor)));
819 835 QSignalSpy spy6(m_axis, SIGNAL(shadesColorChanged(QColor)));
820 836 QSignalSpy spy7(m_axis, SIGNAL(shadesVisibleChanged(bool)));
821 837 QSignalSpy spy8(m_axis, SIGNAL(visibleChanged(bool)));
822 838
823 839 m_axis->hide();
824 840
825 841 QCOMPARE(spy0.count(), 0);
826 842 QCOMPARE(spy1.count(), 0);
827 843 QCOMPARE(spy2.count(), 0);
828 844 QCOMPARE(spy3.count(), 0);
829 845 QCOMPARE(spy4.count(), 0);
830 846 QCOMPARE(spy5.count(), 0);
831 847 QCOMPARE(spy6.count(), 0);
832 848 QCOMPARE(spy7.count(), 0);
833 849 QCOMPARE(spy8.count(), 1);
834 850 QCOMPARE(m_axis->isVisible(),false);
835 851 }
836 852
837 853
838 854
839 855
840 856
841 857
842 858
843 859
844 860
845 861
846 862
847 863
@@ -1,35 +1,35
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QDeclarativeEngine>
23 23 #include "qmlapplicationviewer.h"
24 24
25 25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 26 {
27 27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29 29
30 viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
30 // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 31 viewer->setSource(QUrl("qrc:/qml/qmlchartaxis/main.qml"));
32 32 viewer->showExpanded();
33 33
34 34 return app->exec();
35 35 }
@@ -1,200 +1,206
1 1 // checksum 0x78c version 0x60010
2 2 /*
3 3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 4 QmlApplicationViewer is a convenience class containing mobile device specific
5 5 code such as screen orientation handling. Also QML paths and debugging are
6 6 handled here.
7 7 It is recommended not to modify this file, since newer versions of Qt Creator
8 8 may offer an updated version of it.
9 9 */
10 10
11 11 #include "qmlapplicationviewer.h"
12 12
13 13 #include <QtCore/QDir>
14 14 #include <QtCore/QFileInfo>
15 #include <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
15 #ifdef QT5_QUICK_1
16 #include <QtQuick1/QDeclarativeComponent>
17 #include <QtQuick1/QDeclarativeEngine>
18 #include <QtQuick1/QDeclarativeContext>
19 #else
20 #include <QtDeclarative/QDeclarativeComponent>
21 #include <QtDeclarative/QDeclarativeEngine>
22 #include <QtDeclarative/QDeclarativeContext>
23 #endif
18 24 #include <QApplication>
19 25
20 26 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21 27
22 28 #ifdef HARMATTAN_BOOSTER
23 29 #include <MDeclarativeCache>
24 30 #endif
25 31
26 32 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27 33
28 34 #include <qt_private/qdeclarativedebughelper_p.h>
29 35
30 36 #if !defined(NO_JSDEBUGGER)
31 37 #include <jsdebuggeragent.h>
32 38 #endif
33 39 #if !defined(NO_QMLOBSERVER)
34 40 #include <qdeclarativeviewobserver.h>
35 41 #endif
36 42
37 43 // Enable debugging before any QDeclarativeEngine is created
38 44 struct QmlJsDebuggingEnabler
39 45 {
40 46 QmlJsDebuggingEnabler()
41 47 {
42 48 QDeclarativeDebugHelper::enableDebugging();
43 49 }
44 50 };
45 51
46 52 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 53 static QmlJsDebuggingEnabler enableDebuggingHelper;
48 54
49 55 #endif // QMLJSDEBUGGER
50 56
51 57 class QmlApplicationViewerPrivate
52 58 {
53 59 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
54 60
55 61 QString mainQmlFile;
56 62 QDeclarativeView *view;
57 63 friend class QmlApplicationViewer;
58 64 QString adjustPath(const QString &path);
59 65 };
60 66
61 67 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 68 {
63 69 #ifdef Q_OS_UNIX
64 70 #ifdef Q_OS_MAC
65 71 if (!QDir::isAbsolutePath(path))
66 72 return QCoreApplication::applicationDirPath()
67 73 + QLatin1String("/../Resources/") + path;
68 74 #else
69 75 QString pathInInstallDir;
70 76 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 77 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
72 78
73 79 if (QFileInfo(pathInInstallDir).exists())
74 80 return pathInInstallDir;
75 81 #endif
76 82 #endif
77 83 return path;
78 84 }
79 85
80 86 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 87 : QDeclarativeView(parent)
82 88 , d(new QmlApplicationViewerPrivate(this))
83 89 {
84 90 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 91 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 92 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 93 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 94 #if !defined(NO_JSDEBUGGER)
89 95 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
90 96 #endif
91 97 #if !defined(NO_QMLOBSERVER)
92 98 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
93 99 #endif
94 100 #endif
95 101 }
96 102
97 103 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 104 : QDeclarativeView(parent)
99 105 , d(new QmlApplicationViewerPrivate(view))
100 106 {
101 107 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 108 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 109 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 110 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 111 #if !defined(NO_JSDEBUGGER)
106 112 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
107 113 #endif
108 114 #if !defined(NO_QMLOBSERVER)
109 115 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
110 116 #endif
111 117 #endif
112 118 }
113 119
114 120 QmlApplicationViewer::~QmlApplicationViewer()
115 121 {
116 122 delete d;
117 123 }
118 124
119 125 QmlApplicationViewer *QmlApplicationViewer::create()
120 126 {
121 127 #ifdef HARMATTAN_BOOSTER
122 128 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
123 129 #else
124 130 return new QmlApplicationViewer();
125 131 #endif
126 132 }
127 133
128 134 void QmlApplicationViewer::setMainQmlFile(const QString &file)
129 135 {
130 136 d->mainQmlFile = d->adjustPath(file);
131 137 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
132 138 }
133 139
134 140 void QmlApplicationViewer::addImportPath(const QString &path)
135 141 {
136 142 d->view->engine()->addImportPath(d->adjustPath(path));
137 143 }
138 144
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
140 {
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
147 return;
148 }
149 }
150 #endif // Q_OS_SYMBIAN
151
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
158 break;
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
161 break;
162 default:
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
165 break;
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
169 break;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
172 break;
173 default:
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
176 break;
177 #endif // QT_VERSION < 0x040702
178 };
179 setAttribute(attribute, true);
180 }
145 //void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
146 //{
147 //#if defined(Q_OS_SYMBIAN)
148 // // If the version of Qt on the device is < 4.7.2, that attribute won't work
149 // if (orientation != ScreenOrientationAuto) {
150 // const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
151 // if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
152 // qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
153 // return;
154 // }
155 // }
156 //#endif // Q_OS_SYMBIAN
157
158 // Qt::WidgetAttribute attribute;
159 // switch (orientation) {
160 //#if QT_VERSION < 0x040702
161 // // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
162 // case ScreenOrientationLockPortrait:
163 // attribute = static_cast<Qt::WidgetAttribute>(128);
164 // break;
165 // case ScreenOrientationLockLandscape:
166 // attribute = static_cast<Qt::WidgetAttribute>(129);
167 // break;
168 // default:
169 // case ScreenOrientationAuto:
170 // attribute = static_cast<Qt::WidgetAttribute>(130);
171 // break;
172 //#else // QT_VERSION < 0x040702
173 // case ScreenOrientationLockPortrait:
174 // attribute = Qt::WA_LockPortraitOrientation;
175 // break;
176 // case ScreenOrientationLockLandscape:
177 // attribute = Qt::WA_LockLandscapeOrientation;
178 // break;
179 // default:
180 // case ScreenOrientationAuto:
181 // attribute = Qt::WA_AutoOrientation;
182 // break;
183 //#endif // QT_VERSION < 0x040702
184 // };
185 // setAttribute(attribute, true);
186 //}
181 187
182 188 void QmlApplicationViewer::showExpanded()
183 189 {
184 190 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 191 d->view->showFullScreen();
186 192 #elif defined(Q_WS_MAEMO_5)
187 193 d->view->showMaximized();
188 194 #else
189 195 d->view->show();
190 196 #endif
191 197 }
192 198
193 199 QApplication *createApplication(int &argc, char **argv)
194 200 {
195 201 #ifdef HARMATTAN_BOOSTER
196 202 return MDeclarativeCache::qApplication(argc, argv);
197 203 #else
198 204 return new QApplication(argc, argv);
199 205 #endif
200 206 }
@@ -1,47 +1,51
1 1 // checksum 0x82ed version 0x60010
2 2 /*
3 3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 4 QmlApplicationViewer is a convenience class containing mobile device specific
5 5 code such as screen orientation handling. Also QML paths and debugging are
6 6 handled here.
7 7 It is recommended not to modify this file, since newer versions of Qt Creator
8 8 may offer an updated version of it.
9 9 */
10 10
11 11 #ifndef QMLAPPLICATIONVIEWER_H
12 12 #define QMLAPPLICATIONVIEWER_H
13 13
14 #include <QtDeclarative/QDeclarativeView>
14 #ifdef QT5_QUICK_1
15 #include <QtQuick1/QDeclarativeView>
16 #else
17 #include <QtDeclarative/QDeclarativeView>
18 #endif
15 19
16 20 class QmlApplicationViewer : public QDeclarativeView
17 21 {
18 22 Q_OBJECT
19 23
20 24 public:
21 25 enum ScreenOrientation {
22 26 ScreenOrientationLockPortrait,
23 27 ScreenOrientationLockLandscape,
24 28 ScreenOrientationAuto
25 29 };
26 30
27 31 explicit QmlApplicationViewer(QWidget *parent = 0);
28 32 virtual ~QmlApplicationViewer();
29 33
30 34 static QmlApplicationViewer *create();
31 35
32 36 void setMainQmlFile(const QString &file);
33 37 void addImportPath(const QString &path);
34 38
35 39 // Note that this will only have an effect on Symbian and Fremantle.
36 void setOrientation(ScreenOrientation orientation);
40 // void setOrientation(ScreenOrientation orientation);
37 41
38 42 void showExpanded();
39 43
40 44 private:
41 45 explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
42 46 class QmlApplicationViewerPrivate *d;
43 47 };
44 48
45 49 QApplication *createApplication(int &argc, char **argv);
46 50
47 51 #endif // QMLAPPLICATIONVIEWER_H
@@ -1,36 +1,36
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QDeclarativeEngine>
23 23 #include "qmlapplicationviewer.h"
24 24
25 25 Q_DECL_EXPORT int main(int argc, char *argv[])
26 26 {
27 27 QScopedPointer<QApplication> app(createApplication(argc, argv));
28 28 QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
29 29
30 viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
30 // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
31 31 viewer->setSource(QUrl("qrc:/qml/qmlchartproperties/loader.qml"));
32 32 viewer->setRenderHint(QPainter::Antialiasing, true);
33 33 viewer->showExpanded();
34 34
35 35 return app->exec();
36 36 }
@@ -1,200 +1,206
1 1 // checksum 0x78c version 0x60010
2 2 /*
3 3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 4 QmlApplicationViewer is a convenience class containing mobile device specific
5 5 code such as screen orientation handling. Also QML paths and debugging are
6 6 handled here.
7 7 It is recommended not to modify this file, since newer versions of Qt Creator
8 8 may offer an updated version of it.
9 9 */
10 10
11 11 #include "qmlapplicationviewer.h"
12 12
13 13 #include <QtCore/QDir>
14 14 #include <QtCore/QFileInfo>
15 #include <QtDeclarative/QDeclarativeComponent>
16 #include <QtDeclarative/QDeclarativeEngine>
17 #include <QtDeclarative/QDeclarativeContext>
15 #ifdef QT5_QUICK_1
16 #include <QtQuick1/QDeclarativeComponent>
17 #include <QtQuick1/QDeclarativeEngine>
18 #include <QtQuick1/QDeclarativeContext>
19 #else
20 #include <QtDeclarative/QDeclarativeComponent>
21 #include <QtDeclarative/QDeclarativeEngine>
22 #include <QtDeclarative/QDeclarativeContext>
23 #endif
18 24 #include <QApplication>
19 25
20 26 #include <qplatformdefs.h> // MEEGO_EDITION_HARMATTAN
21 27
22 28 #ifdef HARMATTAN_BOOSTER
23 29 #include <MDeclarativeCache>
24 30 #endif
25 31
26 32 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
27 33
28 34 #include <qt_private/qdeclarativedebughelper_p.h>
29 35
30 36 #if !defined(NO_JSDEBUGGER)
31 37 #include <jsdebuggeragent.h>
32 38 #endif
33 39 #if !defined(NO_QMLOBSERVER)
34 40 #include <qdeclarativeviewobserver.h>
35 41 #endif
36 42
37 43 // Enable debugging before any QDeclarativeEngine is created
38 44 struct QmlJsDebuggingEnabler
39 45 {
40 46 QmlJsDebuggingEnabler()
41 47 {
42 48 QDeclarativeDebugHelper::enableDebugging();
43 49 }
44 50 };
45 51
46 52 // Execute code in constructor before first QDeclarativeEngine is instantiated
47 53 static QmlJsDebuggingEnabler enableDebuggingHelper;
48 54
49 55 #endif // QMLJSDEBUGGER
50 56
51 57 class QmlApplicationViewerPrivate
52 58 {
53 59 QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {}
54 60
55 61 QString mainQmlFile;
56 62 QDeclarativeView *view;
57 63 friend class QmlApplicationViewer;
58 64 QString adjustPath(const QString &path);
59 65 };
60 66
61 67 QString QmlApplicationViewerPrivate::adjustPath(const QString &path)
62 68 {
63 69 #ifdef Q_OS_UNIX
64 70 #ifdef Q_OS_MAC
65 71 if (!QDir::isAbsolutePath(path))
66 72 return QCoreApplication::applicationDirPath()
67 73 + QLatin1String("/../Resources/") + path;
68 74 #else
69 75 QString pathInInstallDir;
70 76 const QString applicationDirPath = QCoreApplication::applicationDirPath();
71 77 pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path);
72 78
73 79 if (QFileInfo(pathInInstallDir).exists())
74 80 return pathInInstallDir;
75 81 #endif
76 82 #endif
77 83 return path;
78 84 }
79 85
80 86 QmlApplicationViewer::QmlApplicationViewer(QWidget *parent)
81 87 : QDeclarativeView(parent)
82 88 , d(new QmlApplicationViewerPrivate(this))
83 89 {
84 90 connect(engine(), SIGNAL(quit()), SLOT(close()));
85 91 setResizeMode(QDeclarativeView::SizeRootObjectToView);
86 92 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
87 93 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
88 94 #if !defined(NO_JSDEBUGGER)
89 95 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
90 96 #endif
91 97 #if !defined(NO_QMLOBSERVER)
92 98 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
93 99 #endif
94 100 #endif
95 101 }
96 102
97 103 QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent)
98 104 : QDeclarativeView(parent)
99 105 , d(new QmlApplicationViewerPrivate(view))
100 106 {
101 107 connect(view->engine(), SIGNAL(quit()), view, SLOT(close()));
102 108 view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
103 109 // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in
104 110 #if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800
105 111 #if !defined(NO_JSDEBUGGER)
106 112 new QmlJSDebugger::JSDebuggerAgent(d->view->engine());
107 113 #endif
108 114 #if !defined(NO_QMLOBSERVER)
109 115 new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view);
110 116 #endif
111 117 #endif
112 118 }
113 119
114 120 QmlApplicationViewer::~QmlApplicationViewer()
115 121 {
116 122 delete d;
117 123 }
118 124
119 125 QmlApplicationViewer *QmlApplicationViewer::create()
120 126 {
121 127 #ifdef HARMATTAN_BOOSTER
122 128 return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0);
123 129 #else
124 130 return new QmlApplicationViewer();
125 131 #endif
126 132 }
127 133
128 134 void QmlApplicationViewer::setMainQmlFile(const QString &file)
129 135 {
130 136 d->mainQmlFile = d->adjustPath(file);
131 137 d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile));
132 138 }
133 139
134 140 void QmlApplicationViewer::addImportPath(const QString &path)
135 141 {
136 142 d->view->engine()->addImportPath(d->adjustPath(path));
137 143 }
138 144
139 void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
140 {
141 #if defined(Q_OS_SYMBIAN)
142 // If the version of Qt on the device is < 4.7.2, that attribute won't work
143 if (orientation != ScreenOrientationAuto) {
144 const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
145 if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
146 qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
147 return;
148 }
149 }
150 #endif // Q_OS_SYMBIAN
151
152 Qt::WidgetAttribute attribute;
153 switch (orientation) {
154 #if QT_VERSION < 0x040702
155 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
156 case ScreenOrientationLockPortrait:
157 attribute = static_cast<Qt::WidgetAttribute>(128);
158 break;
159 case ScreenOrientationLockLandscape:
160 attribute = static_cast<Qt::WidgetAttribute>(129);
161 break;
162 default:
163 case ScreenOrientationAuto:
164 attribute = static_cast<Qt::WidgetAttribute>(130);
165 break;
166 #else // QT_VERSION < 0x040702
167 case ScreenOrientationLockPortrait:
168 attribute = Qt::WA_LockPortraitOrientation;
169 break;
170 case ScreenOrientationLockLandscape:
171 attribute = Qt::WA_LockLandscapeOrientation;
172 break;
173 default:
174 case ScreenOrientationAuto:
175 attribute = Qt::WA_AutoOrientation;
176 break;
177 #endif // QT_VERSION < 0x040702
178 };
179 setAttribute(attribute, true);
180 }
145 //void QmlApplicationViewer::setOrientation(ScreenOrientation orientation)
146 //{
147 //#if defined(Q_OS_SYMBIAN)
148 // // If the version of Qt on the device is < 4.7.2, that attribute won't work
149 // if (orientation != ScreenOrientationAuto) {
150 // const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
151 // if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
152 // qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
153 // return;
154 // }
155 // }
156 //#endif // Q_OS_SYMBIAN
157
158 // Qt::WidgetAttribute attribute;
159 // switch (orientation) {
160 //#if QT_VERSION < 0x040702
161 // // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
162 // case ScreenOrientationLockPortrait:
163 // attribute = static_cast<Qt::WidgetAttribute>(128);
164 // break;
165 // case ScreenOrientationLockLandscape:
166 // attribute = static_cast<Qt::WidgetAttribute>(129);
167 // break;
168 // default:
169 // case ScreenOrientationAuto:
170 // attribute = static_cast<Qt::WidgetAttribute>(130);
171 // break;
172 //#else // QT_VERSION < 0x040702
173 // case ScreenOrientationLockPortrait:
174 // attribute = Qt::WA_LockPortraitOrientation;
175 // break;
176 // case ScreenOrientationLockLandscape:
177 // attribute = Qt::WA_LockLandscapeOrientation;
178 // break;
179 // default:
180 // case ScreenOrientationAuto:
181 // attribute = Qt::WA_AutoOrientation;
182 // break;
183 //#endif // QT_VERSION < 0x040702
184 // };
185 // setAttribute(attribute, true);
186 //}
181 187
182 188 void QmlApplicationViewer::showExpanded()
183 189 {
184 190 #if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR)
185 191 d->view->showFullScreen();
186 192 #elif defined(Q_WS_MAEMO_5)
187 193 d->view->showMaximized();
188 194 #else
189 195 d->view->show();
190 196 #endif
191 197 }
192 198
193 199 QApplication *createApplication(int &argc, char **argv)
194 200 {
195 201 #ifdef HARMATTAN_BOOSTER
196 202 return MDeclarativeCache::qApplication(argc, argv);
197 203 #else
198 204 return new QApplication(argc, argv);
199 205 #endif
200 206 }
@@ -1,47 +1,51
1 1 // checksum 0x82ed version 0x60010
2 2 /*
3 3 This file was generated by the Qt Quick Application wizard of Qt Creator.
4 4 QmlApplicationViewer is a convenience class containing mobile device specific
5 5 code such as screen orientation handling. Also QML paths and debugging are
6 6 handled here.
7 7 It is recommended not to modify this file, since newer versions of Qt Creator
8 8 may offer an updated version of it.
9 9 */
10 10
11 11 #ifndef QMLAPPLICATIONVIEWER_H
12 12 #define QMLAPPLICATIONVIEWER_H
13 13
14 #include <QtDeclarative/QDeclarativeView>
14 #ifdef QT5_QUICK_1
15 #include <QtQuick1/QDeclarativeView>
16 #else
17 #include <QtDeclarative/QDeclarativeView>
18 #endif
15 19
16 20 class QmlApplicationViewer : public QDeclarativeView
17 21 {
18 22 Q_OBJECT
19 23
20 24 public:
21 25 enum ScreenOrientation {
22 26 ScreenOrientationLockPortrait,
23 27 ScreenOrientationLockLandscape,
24 28 ScreenOrientationAuto
25 29 };
26 30
27 31 explicit QmlApplicationViewer(QWidget *parent = 0);
28 32 virtual ~QmlApplicationViewer();
29 33
30 34 static QmlApplicationViewer *create();
31 35
32 36 void setMainQmlFile(const QString &file);
33 37 void addImportPath(const QString &path);
34 38
35 39 // Note that this will only have an effect on Symbian and Fremantle.
36 void setOrientation(ScreenOrientation orientation);
40 // void setOrientation(ScreenOrientation orientation);
37 41
38 42 void showExpanded();
39 43
40 44 private:
41 45 explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent);
42 46 class QmlApplicationViewerPrivate *d;
43 47 };
44 48
45 49 QApplication *createApplication(int &argc, char **argv);
46 50
47 51 #endif // QMLAPPLICATIONVIEWER_H
General Comments 0
You need to be logged in to leave comments. Login now