@@ -0,0 +1,38 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | import QtQuick 1.0 | |||
|
22 | import QtCommercial.Chart 1.0 | |||
|
23 | ||||
|
24 | Rectangle { | |||
|
25 | anchors.fill: parent | |||
|
26 | ||||
|
27 | Chart { | |||
|
28 | title: "Bar series" | |||
|
29 | anchors.fill: parent | |||
|
30 | theme: Chart.ChartThemeLight | |||
|
31 | legend: Chart.LegendBottom | |||
|
32 | ||||
|
33 | BarSeries { | |||
|
34 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |||
|
35 | // data implementation missing | |||
|
36 | } | |||
|
37 | } | |||
|
38 | } |
@@ -0,0 +1,38 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef TST_DEFINITIONS_H | |||
|
22 | #define TST_DEFINITIONS_H | |||
|
23 | ||||
|
24 | #include <QtTest/QtTest> | |||
|
25 | ||||
|
26 | #define TRY_COMPARE(actual, expected) { \ | |||
|
27 | do { \ | |||
|
28 | const int timeout(1000); \ | |||
|
29 | const int waitStep(30); \ | |||
|
30 | /* always wait before comparing to catch possible extra signals */ \ | |||
|
31 | QTest::qWait(waitStep); \ | |||
|
32 | for (int time(0); (actual != expected) && (time < timeout); time += waitStep) \ | |||
|
33 | QTest::qWait(waitStep); \ | |||
|
34 | QCOMPARE(actual, expected); \ | |||
|
35 | } while (0); \ | |||
|
36 | } | |||
|
37 | ||||
|
38 | #endif // TST_DEFINITIONS_H |
@@ -0,0 +1,6 | |||||
|
1 | !include( ../auto.pri ) { | |||
|
2 | error( "Couldn't find the auto.pri file!" ) | |||
|
3 | } | |||
|
4 | SOURCES += tst_qpercentbarseries.cpp | |||
|
5 | ||||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,95 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include <QtTest/QtTest> | |||
|
22 | #include <qpercentbarseries.h> | |||
|
23 | #include <qbarset.h> | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
26 | ||||
|
27 | class tst_QPercentBarSeries : public QObject | |||
|
28 | { | |||
|
29 | Q_OBJECT | |||
|
30 | ||||
|
31 | public slots: | |||
|
32 | void initTestCase(); | |||
|
33 | void cleanupTestCase(); | |||
|
34 | void init(); | |||
|
35 | void cleanup(); | |||
|
36 | ||||
|
37 | private slots: | |||
|
38 | void qpercentbarseries_data(); | |||
|
39 | void qpercentbarseries(); | |||
|
40 | void type_data(); | |||
|
41 | void type(); | |||
|
42 | ||||
|
43 | private: | |||
|
44 | QPercentBarSeries* m_barseries; | |||
|
45 | }; | |||
|
46 | ||||
|
47 | void tst_QPercentBarSeries::initTestCase() | |||
|
48 | { | |||
|
49 | } | |||
|
50 | ||||
|
51 | void tst_QPercentBarSeries::cleanupTestCase() | |||
|
52 | { | |||
|
53 | } | |||
|
54 | ||||
|
55 | void tst_QPercentBarSeries::init() | |||
|
56 | { | |||
|
57 | m_barseries = new QPercentBarSeries(); | |||
|
58 | } | |||
|
59 | ||||
|
60 | void tst_QPercentBarSeries::cleanup() | |||
|
61 | { | |||
|
62 | delete m_barseries; | |||
|
63 | m_barseries = 0; | |||
|
64 | } | |||
|
65 | ||||
|
66 | void tst_QPercentBarSeries::qpercentbarseries_data() | |||
|
67 | { | |||
|
68 | } | |||
|
69 | ||||
|
70 | void tst_QPercentBarSeries::qpercentbarseries() | |||
|
71 | { | |||
|
72 | QPercentBarSeries *barseries = new QPercentBarSeries(); | |||
|
73 | QVERIFY(barseries != 0); | |||
|
74 | } | |||
|
75 | ||||
|
76 | void tst_QPercentBarSeries::type_data() | |||
|
77 | { | |||
|
78 | ||||
|
79 | } | |||
|
80 | ||||
|
81 | void tst_QPercentBarSeries::type() | |||
|
82 | { | |||
|
83 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); | |||
|
84 | } | |||
|
85 | ||||
|
86 | ||||
|
87 | /* | |||
|
88 | bool setModel(QAbstractItemModel *model); | |||
|
89 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |||
|
90 | void setModelMappingRange(int first, int count = -1); | |||
|
91 | */ | |||
|
92 | QTEST_MAIN(tst_QPercentBarSeries) | |||
|
93 | ||||
|
94 | #include "tst_qpercentbarseries.moc" | |||
|
95 |
@@ -0,0 +1,6 | |||||
|
1 | !include( ../auto.pri ) { | |||
|
2 | error( "Couldn't find the auto.pri file!" ) | |||
|
3 | } | |||
|
4 | SOURCES += tst_qstackedbarseries.cpp | |||
|
5 | ||||
|
6 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,94 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include <QtTest/QtTest> | |||
|
22 | #include <qstackedbarseries.h> | |||
|
23 | #include <qbarset.h> | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
26 | ||||
|
27 | class tst_QStackedBarSeries : public QObject | |||
|
28 | { | |||
|
29 | Q_OBJECT | |||
|
30 | ||||
|
31 | public slots: | |||
|
32 | void initTestCase(); | |||
|
33 | void cleanupTestCase(); | |||
|
34 | void init(); | |||
|
35 | void cleanup(); | |||
|
36 | ||||
|
37 | private slots: | |||
|
38 | void qstackedbarseries_data(); | |||
|
39 | void qstackedbarseries(); | |||
|
40 | void type_data(); | |||
|
41 | void type(); | |||
|
42 | ||||
|
43 | private: | |||
|
44 | QStackedBarSeries* m_barseries; | |||
|
45 | }; | |||
|
46 | ||||
|
47 | void tst_QStackedBarSeries::initTestCase() | |||
|
48 | { | |||
|
49 | } | |||
|
50 | ||||
|
51 | void tst_QStackedBarSeries::cleanupTestCase() | |||
|
52 | { | |||
|
53 | } | |||
|
54 | ||||
|
55 | void tst_QStackedBarSeries::init() | |||
|
56 | { | |||
|
57 | m_barseries = new QStackedBarSeries(); | |||
|
58 | } | |||
|
59 | ||||
|
60 | void tst_QStackedBarSeries::cleanup() | |||
|
61 | { | |||
|
62 | delete m_barseries; | |||
|
63 | m_barseries = 0; | |||
|
64 | } | |||
|
65 | ||||
|
66 | void tst_QStackedBarSeries::qstackedbarseries_data() | |||
|
67 | { | |||
|
68 | } | |||
|
69 | ||||
|
70 | void tst_QStackedBarSeries::qstackedbarseries() | |||
|
71 | { | |||
|
72 | QStackedBarSeries *barseries = new QStackedBarSeries(); | |||
|
73 | QVERIFY(barseries != 0); | |||
|
74 | } | |||
|
75 | ||||
|
76 | void tst_QStackedBarSeries::type_data() | |||
|
77 | { | |||
|
78 | ||||
|
79 | } | |||
|
80 | ||||
|
81 | void tst_QStackedBarSeries::type() | |||
|
82 | { | |||
|
83 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); | |||
|
84 | } | |||
|
85 | ||||
|
86 | /* | |||
|
87 | bool setModel(QAbstractItemModel *model); | |||
|
88 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |||
|
89 | void setModelMappingRange(int first, int count = -1); | |||
|
90 | */ | |||
|
91 | QTEST_MAIN(tst_QStackedBarSeries) | |||
|
92 | ||||
|
93 | #include "tst_qstackedbarseries.moc" | |||
|
94 |
@@ -1,270 +1,269 | |||||
1 | # This file is used to ignore files which are generated in the Qt build system |
|
1 | # This file is used to ignore files which are generated in the Qt build system | |
2 | # ---------------------------------------------------------------------------- |
|
2 | # ---------------------------------------------------------------------------- | |
3 |
|
3 | |||
4 | examples/*/*/* |
|
4 | examples/*/*/* | |
5 | !examples/*/*/*[.]* |
|
5 | !examples/*/*/*[.]* | |
6 | !examples/*/*/README |
|
6 | !examples/*/*/README | |
7 | examples/*/*/*[.]app |
|
7 | examples/*/*/*[.]app | |
8 | !examples/declarative/* |
|
8 | !examples/declarative/* | |
9 | !examples/tutorials/* |
|
9 | !examples/tutorials/* | |
10 | !examples/tutorials/*/* |
|
10 | !examples/tutorials/*/* | |
11 | !examples/ja_JP/*/* |
|
11 | !examples/ja_JP/*/* | |
12 | demos/*/* |
|
|||
13 | !demos/spectrum/* |
|
12 | !demos/spectrum/* | |
14 | demos/spectrum/bin |
|
13 | demos/spectrum/bin | |
15 | !demos/*/*[.]* |
|
14 | !demos/*/*[.]* | |
16 | demos/*/*[.]app |
|
15 | demos/*/*[.]app | |
17 | !demos/declarative/* |
|
16 | !demos/declarative/* | |
18 | config.tests/*/*/* |
|
17 | config.tests/*/*/* | |
19 | !config.tests/*/*/*[.]* |
|
18 | !config.tests/*/*/*[.]* | |
20 | config.tests/*/*/*[.]app |
|
19 | config.tests/*/*/*[.]app | |
21 |
|
20 | |||
22 | callgrind.out.* |
|
21 | callgrind.out.* | |
23 | pcviewer.cfg |
|
22 | pcviewer.cfg | |
24 | *~ |
|
23 | *~ | |
25 | *.a |
|
24 | *.a | |
26 | *.la |
|
25 | *.la | |
27 | *.core |
|
26 | *.core | |
28 | *.moc |
|
27 | *.moc | |
29 | *.o |
|
28 | *.o | |
30 | *.obj |
|
29 | *.obj | |
31 | *.orig |
|
30 | *.orig | |
32 | *.swp |
|
31 | *.swp | |
33 | *.rej |
|
32 | *.rej | |
34 | *.so |
|
33 | *.so | |
35 | *.pbxuser |
|
34 | *.pbxuser | |
36 | *.mode1 |
|
35 | *.mode1 | |
37 | *.mode1v3 |
|
36 | *.mode1v3 | |
38 | *_pch.h.cpp |
|
37 | *_pch.h.cpp | |
39 | *_resource.rc |
|
38 | *_resource.rc | |
40 | .#* |
|
39 | .#* | |
41 | *.*# |
|
40 | *.*# | |
42 | core |
|
41 | core | |
43 | .qmake.cache |
|
42 | .qmake.cache | |
44 | .qmake.vars |
|
43 | .qmake.vars | |
45 | *.prl |
|
44 | *.prl | |
46 | tags |
|
45 | tags | |
47 | .DS_Store |
|
46 | .DS_Store | |
48 | *.debug |
|
47 | *.debug | |
49 | Makefile* |
|
48 | Makefile* | |
50 | !qmake/Makefile.win32* |
|
49 | !qmake/Makefile.win32* | |
51 | !qmake/Makefile.unix |
|
50 | !qmake/Makefile.unix | |
52 | *.prl |
|
51 | *.prl | |
53 | *.app |
|
52 | *.app | |
54 | *.pro.user* |
|
53 | *.pro.user* | |
55 | *.qmlproject.user* |
|
54 | *.qmlproject.user* | |
56 | *.gcov |
|
55 | *.gcov | |
57 | bin/Qt*.dll |
|
56 | bin/Qt*.dll | |
58 | bin/assistant* |
|
57 | bin/assistant* | |
59 | bin/designer* |
|
58 | bin/designer* | |
60 | bin/dumpcpp* |
|
59 | bin/dumpcpp* | |
61 | bin/idc* |
|
60 | bin/idc* | |
62 | bin/linguist* |
|
61 | bin/linguist* | |
63 | bin/lrelease* |
|
62 | bin/lrelease* | |
64 | bin/lupdate* |
|
63 | bin/lupdate* | |
65 | bin/lconvert* |
|
64 | bin/lconvert* | |
66 | bin/moc* |
|
65 | bin/moc* | |
67 | bin/makeqpf* |
|
66 | bin/makeqpf* | |
68 | bin/pixeltool* |
|
67 | bin/pixeltool* | |
69 | bin/qmake* |
|
68 | bin/qmake* | |
70 | bin/qdoc3* |
|
69 | bin/qdoc3* | |
71 | bin/qt3to4* |
|
70 | bin/qt3to4* | |
72 | bin/qtdemo* |
|
71 | bin/qtdemo* | |
73 | bin/qttracereplay* |
|
72 | bin/qttracereplay* | |
74 | bin/rcc* |
|
73 | bin/rcc* | |
75 | bin/uic* |
|
74 | bin/uic* | |
76 | bin/patternist* |
|
75 | bin/patternist* | |
77 | bin/phonon* |
|
76 | bin/phonon* | |
78 | bin/qcollectiongenerator* |
|
77 | bin/qcollectiongenerator* | |
79 | bin/qdbus* |
|
78 | bin/qdbus* | |
80 | bin/qhelpconverter* |
|
79 | bin/qhelpconverter* | |
81 | bin/qhelpgenerator* |
|
80 | bin/qhelpgenerator* | |
82 | bin/qtconfig* |
|
81 | bin/qtconfig* | |
83 | bin/xmlpatterns* |
|
82 | bin/xmlpatterns* | |
84 | bin/cetest* |
|
83 | bin/cetest* | |
85 | bin/collectiongenerator |
|
84 | bin/collectiongenerator | |
86 | bin/helpconverter |
|
85 | bin/helpconverter | |
87 | bin/helpgenerator |
|
86 | bin/helpgenerator | |
88 | bin/kmap2qmap* |
|
87 | bin/kmap2qmap* | |
89 | bin/qlalr* |
|
88 | bin/qlalr* | |
90 | bin/qmlconv* |
|
89 | bin/qmlconv* | |
91 | bin/qmldebugger* |
|
90 | bin/qmldebugger* | |
92 | bin/qml* |
|
91 | bin/qml* | |
93 | bin/qttracereplay* |
|
92 | bin/qttracereplay* | |
94 | configure.cache |
|
93 | configure.cache | |
95 | config.status |
|
94 | config.status | |
96 | mkspecs/default |
|
95 | mkspecs/default | |
97 | mkspecs/qconfig.pri |
|
96 | mkspecs/qconfig.pri | |
98 | moc_*.cpp |
|
97 | moc_*.cpp | |
99 | qmake/qmake.exe |
|
98 | qmake/qmake.exe | |
100 | qmake/Makefile.bak |
|
99 | qmake/Makefile.bak | |
101 | src/corelib/global/qconfig.cpp |
|
100 | src/corelib/global/qconfig.cpp | |
102 | src/corelib/global/qconfig.h |
|
101 | src/corelib/global/qconfig.h | |
103 | src/corelib/global/qconfig.h.qmake |
|
102 | src/corelib/global/qconfig.h.qmake | |
104 | src/tools/uic/qclass_lib_map.h |
|
103 | src/tools/uic/qclass_lib_map.h | |
105 | ui_*.h |
|
104 | ui_*.h | |
106 | tests/auto/qprocess/test*/*.exe |
|
105 | tests/auto/qprocess/test*/*.exe | |
107 | tests/auto/qtcpsocket/stressTest/*.exe |
|
106 | tests/auto/qtcpsocket/stressTest/*.exe | |
108 | tests/auto/qprocess/fileWriterProcess/*.exe |
|
107 | tests/auto/qprocess/fileWriterProcess/*.exe | |
109 | tests/auto/qmake/testdata/quotedfilenames/*.exe |
|
108 | tests/auto/qmake/testdata/quotedfilenames/*.exe | |
110 | tests/auto/compilerwarnings/*.exe |
|
109 | tests/auto/compilerwarnings/*.exe | |
111 | tests/auto/qmake/testdata/quotedfilenames/test.cpp |
|
110 | tests/auto/qmake/testdata/quotedfilenames/test.cpp | |
112 | tests/auto/qprocess/fileWriterProcess.txt |
|
111 | tests/auto/qprocess/fileWriterProcess.txt | |
113 | .com.apple.timemachine.supported |
|
112 | .com.apple.timemachine.supported | |
114 | tests/auto/qlibrary/libmylib.so* |
|
113 | tests/auto/qlibrary/libmylib.so* | |
115 | tests/auto/qresourceengine/runtime_resource.rcc |
|
114 | tests/auto/qresourceengine/runtime_resource.rcc | |
116 | tools/qtestlib/chart/chart* |
|
115 | tools/qtestlib/chart/chart* | |
117 | tools/qtestlib/updater/updater* |
|
116 | tools/qtestlib/updater/updater* | |
118 | tools/activeqt/testcon/testcon.tlb |
|
117 | tools/activeqt/testcon/testcon.tlb | |
119 | translations/*.qm |
|
118 | translations/*.qm | |
120 | translations/*_untranslated.ts |
|
119 | translations/*_untranslated.ts | |
121 | qrc_*.cpp |
|
120 | qrc_*.cpp | |
122 |
|
121 | |||
123 | # Test generated files |
|
122 | # Test generated files | |
124 | QObject.log |
|
123 | QObject.log | |
125 | tst_* |
|
124 | tst_* | |
126 | !tst_*.* |
|
125 | !tst_*.* | |
127 | tst_*.log |
|
126 | tst_*.log | |
128 | tst_*.debug |
|
127 | tst_*.debug | |
129 | tst_*~ |
|
128 | tst_*~ | |
130 |
|
129 | |||
131 | # xemacs temporary files |
|
130 | # xemacs temporary files | |
132 | *.flc |
|
131 | *.flc | |
133 |
|
132 | |||
134 | # Vim temporary files |
|
133 | # Vim temporary files | |
135 | .*.swp |
|
134 | .*.swp | |
136 |
|
135 | |||
137 | # Visual Studio generated files |
|
136 | # Visual Studio generated files | |
138 | *.ib_pdb_index |
|
137 | *.ib_pdb_index | |
139 | *.idb |
|
138 | *.idb | |
140 | *.ilk |
|
139 | *.ilk | |
141 | *.pdb |
|
140 | *.pdb | |
142 | *.sln |
|
141 | *.sln | |
143 | *.suo |
|
142 | *.suo | |
144 | *.vcproj |
|
143 | *.vcproj | |
145 | *vcproj.*.*.user |
|
144 | *vcproj.*.*.user | |
146 | *.ncb |
|
145 | *.ncb | |
147 | *.vcxproj |
|
146 | *.vcxproj | |
148 | *.vcxproj.filters |
|
147 | *.vcxproj.filters | |
149 | *.vcxproj.user |
|
148 | *.vcxproj.user | |
150 |
|
149 | |||
151 | # MinGW generated files |
|
150 | # MinGW generated files | |
152 | *.Debug |
|
151 | *.Debug | |
153 | *.Release |
|
152 | *.Release | |
154 |
|
153 | |||
155 | # WebKit temp files |
|
154 | # WebKit temp files | |
156 | src/3rdparty/webkit/WebCore/mocinclude.tmp |
|
155 | src/3rdparty/webkit/WebCore/mocinclude.tmp | |
157 | src/3rdparty/webkit/includes.txt |
|
156 | src/3rdparty/webkit/includes.txt | |
158 | src/3rdparty/webkit/includes2.txt |
|
157 | src/3rdparty/webkit/includes2.txt | |
159 |
|
158 | |||
160 | # Symlinks generated by configure |
|
159 | # Symlinks generated by configure | |
161 | tools/qvfb/qvfbhdr.h |
|
160 | tools/qvfb/qvfbhdr.h | |
162 | tools/qvfb/qlock_p.h |
|
161 | tools/qvfb/qlock_p.h | |
163 | tools/qvfb/qlock.cpp |
|
162 | tools/qvfb/qlock.cpp | |
164 | tools/qvfb/qwssignalhandler.cpp |
|
163 | tools/qvfb/qwssignalhandler.cpp | |
165 | tools/qvfb/qwssignalhandler_p.h |
|
164 | tools/qvfb/qwssignalhandler_p.h | |
166 | .DS_Store |
|
165 | .DS_Store | |
167 | .pch |
|
166 | .pch | |
168 | .rcc |
|
167 | .rcc | |
169 | *.app |
|
168 | *.app | |
170 | config.status |
|
169 | config.status | |
171 | config.tests/unix/cups/cups |
|
170 | config.tests/unix/cups/cups | |
172 | config.tests/unix/getaddrinfo/getaddrinfo |
|
171 | config.tests/unix/getaddrinfo/getaddrinfo | |
173 | config.tests/unix/getifaddrs/getifaddrs |
|
172 | config.tests/unix/getifaddrs/getifaddrs | |
174 | config.tests/unix/iconv/iconv |
|
173 | config.tests/unix/iconv/iconv | |
175 | config.tests/unix/ipv6/ipv6 |
|
174 | config.tests/unix/ipv6/ipv6 | |
176 | config.tests/unix/ipv6ifname/ipv6ifname |
|
175 | config.tests/unix/ipv6ifname/ipv6ifname | |
177 | config.tests/unix/largefile/largefile |
|
176 | config.tests/unix/largefile/largefile | |
178 | config.tests/unix/nis/nis |
|
177 | config.tests/unix/nis/nis | |
179 | config.tests/unix/odbc/odbc |
|
178 | config.tests/unix/odbc/odbc | |
180 | config.tests/unix/openssl/openssl |
|
179 | config.tests/unix/openssl/openssl | |
181 | config.tests/unix/stl/stl |
|
180 | config.tests/unix/stl/stl | |
182 | config.tests/unix/zlib/zlib |
|
181 | config.tests/unix/zlib/zlib | |
183 | config.tests/unix/3dnow/3dnow |
|
182 | config.tests/unix/3dnow/3dnow | |
184 | config.tests/unix/mmx/mmx |
|
183 | config.tests/unix/mmx/mmx | |
185 | config.tests/unix/sse/sse |
|
184 | config.tests/unix/sse/sse | |
186 | config.tests/unix/sse2/sse2 |
|
185 | config.tests/unix/sse2/sse2 | |
187 |
|
186 | |||
188 |
|
187 | |||
189 |
|
188 | |||
190 | # Directories to ignore |
|
189 | # Directories to ignore | |
191 | # --------------------- |
|
190 | # --------------------- | |
192 |
|
191 | |||
193 | debug |
|
192 | debug | |
194 | examples/tools/plugandpaint/plugins |
|
193 | examples/tools/plugandpaint/plugins | |
195 | include/* |
|
194 | include/* | |
196 | include/*/* |
|
195 | include/*/* | |
197 | lib/* |
|
196 | lib/* | |
198 | !lib/fonts |
|
197 | !lib/fonts | |
199 | !lib/README |
|
198 | !lib/README | |
200 | plugins/*/* |
|
199 | plugins/*/* | |
201 | release |
|
200 | release | |
202 | tmp |
|
201 | tmp | |
203 | doc-build |
|
202 | doc-build | |
204 | doc/html/* |
|
203 | doc/html/* | |
205 | tools/qdoc3/doc/html/* |
|
204 | tools/qdoc3/doc/html/* | |
206 | doc/qch |
|
205 | doc/qch | |
207 | doc-build |
|
206 | doc-build | |
208 | .rcc |
|
207 | .rcc | |
209 | .pch |
|
208 | .pch | |
210 | .metadata |
|
209 | .metadata | |
211 | build/* |
|
210 | build/* | |
212 | bin/* |
|
211 | bin/* | |
213 | coverage/* |
|
212 | coverage/* | |
214 |
|
213 | |||
215 | # Symbian build system generated files |
|
214 | # Symbian build system generated files | |
216 | # --------------------- |
|
215 | # --------------------- | |
217 |
|
216 | |||
218 | ABLD.BAT |
|
217 | ABLD.BAT | |
219 | bld.inf* |
|
218 | bld.inf* | |
220 | *.mmp |
|
219 | *.mmp | |
221 | *.mk |
|
220 | *.mk | |
222 | *.rss |
|
221 | *.rss | |
223 | *.loc |
|
222 | *.loc | |
224 | !s60main.rss |
|
223 | !s60main.rss | |
225 | *.pkg |
|
224 | *.pkg | |
226 | plugin_commonu.def |
|
225 | plugin_commonu.def | |
227 | *.qtplugin |
|
226 | *.qtplugin | |
228 | *.sis |
|
227 | *.sis | |
229 | *.sisx |
|
228 | *.sisx | |
230 | *.lst |
|
229 | *.lst | |
231 | *.exe |
|
230 | *.exe | |
232 | *.mif |
|
231 | *.mif | |
233 | *.rsc |
|
232 | *.rsc | |
234 | *.sym |
|
233 | *.sym | |
235 | *.lib |
|
234 | *.lib | |
236 |
|
235 | |||
237 | # runonphone crash dumps |
|
236 | # runonphone crash dumps | |
238 | d_exc_*.txt |
|
237 | d_exc_*.txt | |
239 | d_exc_*.stk |
|
238 | d_exc_*.stk | |
240 |
|
239 | |||
241 | # Generated by abldfast.bat from devtools. |
|
240 | # Generated by abldfast.bat from devtools. | |
242 | .abldsteps.* |
|
241 | .abldsteps.* | |
243 |
|
242 | |||
244 | # Carbide project files |
|
243 | # Carbide project files | |
245 | # --------------------- |
|
244 | # --------------------- | |
246 | .project |
|
245 | .project | |
247 | .cproject |
|
246 | .cproject | |
248 | .make.cache |
|
247 | .make.cache | |
249 | *.d |
|
248 | *.d | |
250 |
|
249 | |||
251 | # OSX build files |
|
250 | # OSX build files | |
252 | *.xcodeproj |
|
251 | *.xcodeproj | |
253 | Info.plist |
|
252 | Info.plist | |
254 |
|
253 | |||
255 | qtc-debugging-helper |
|
254 | qtc-debugging-helper | |
256 | qtc-qmldump |
|
255 | qtc-qmldump | |
257 | qtc-qmldbg |
|
256 | qtc-qmldbg | |
258 |
|
257 | |||
259 | .pc/ |
|
258 | .pc/ | |
260 |
|
259 | |||
261 | # INTEGRITY generated files |
|
260 | # INTEGRITY generated files | |
262 | *.gpj |
|
261 | *.gpj | |
263 | *.int |
|
262 | *.int | |
264 | *.ael |
|
263 | *.ael | |
265 | *.dla |
|
264 | *.dla | |
266 | *.dnm |
|
265 | *.dnm | |
267 | *.dep |
|
266 | *.dep | |
268 | *.map |
|
267 | *.map | |
269 | work |
|
268 | work | |
270 |
|
269 |
@@ -1,375 +1,376 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "themewidget.h" |
|
21 | #include "themewidget.h" | |
22 |
|
22 | |||
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPieSeries> |
|
24 | #include <QPieSeries> | |
25 | #include <QPieSlice> |
|
25 | #include <QPieSlice> | |
26 | #include <QBarSeries> |
|
26 | #include <QBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QStackedBarSeries> |
|
28 | #include <QStackedBarSeries> | |
29 | #include <QBarSet> |
|
29 | #include <QBarSet> | |
30 | #include <QLineSeries> |
|
30 | #include <QLineSeries> | |
31 | #include <QSplineSeries> |
|
31 | #include <QSplineSeries> | |
32 | #include <QScatterSeries> |
|
32 | #include <QScatterSeries> | |
33 | #include <QAreaSeries> |
|
33 | #include <QAreaSeries> | |
34 | #include <QLegend> |
|
34 | #include <QLegend> | |
35 | #include <QGridLayout> |
|
35 | #include <QGridLayout> | |
36 | #include <QFormLayout> |
|
36 | #include <QFormLayout> | |
37 | #include <QComboBox> |
|
37 | #include <QComboBox> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QCheckBox> |
|
39 | #include <QCheckBox> | |
40 | #include <QGroupBox> |
|
40 | #include <QGroupBox> | |
41 | #include <QLabel> |
|
41 | #include <QLabel> | |
42 | #include <QTime> |
|
42 | #include <QTime> | |
43 |
|
43 | |||
44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
44 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
45 | QWidget(parent), |
|
45 | QWidget(parent), | |
46 | m_listCount(3), |
|
46 | m_listCount(3), | |
47 | m_valueMax(10), |
|
47 | m_valueMax(10), | |
48 | m_valueCount(7), |
|
48 | m_valueCount(7), | |
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
50 | m_themeComboBox(createThemeBox()), |
|
50 | m_themeComboBox(createThemeBox()), | |
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
52 | m_animatedComboBox(createAnimationBox()), |
|
52 | m_animatedComboBox(createAnimationBox()), | |
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 | { |
|
54 | { | |
55 | connectSignals(); |
|
55 | connectSignals(); | |
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
60 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
62 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
63 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
63 | settingsLayout->addWidget(new QLabel("Legend:")); | |
64 | settingsLayout->addWidget(m_legendComboBox); |
|
64 | settingsLayout->addWidget(m_legendComboBox); | |
65 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
65 | settingsLayout->addWidget(m_antialiasCheckBox); | |
66 | settingsLayout->addStretch(); |
|
66 | settingsLayout->addStretch(); | |
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
68 |
|
68 | |||
69 | //create charts |
|
69 | //create charts | |
70 |
|
70 | |||
71 | QChartView *chartView; |
|
71 | QChartView *chartView; | |
72 |
|
72 | |||
73 | chartView = new QChartView(createAreaChart()); |
|
73 | chartView = new QChartView(createAreaChart()); | |
74 | baseLayout->addWidget(chartView, 1, 0); |
|
74 | baseLayout->addWidget(chartView, 1, 0); | |
75 | m_charts << chartView; |
|
75 | m_charts << chartView; | |
76 |
|
76 | |||
77 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
77 | chartView = new QChartView(createBarChart(m_valueCount)); | |
78 | baseLayout->addWidget(chartView, 1, 1); |
|
78 | baseLayout->addWidget(chartView, 1, 1); | |
79 | m_charts << chartView; |
|
79 | m_charts << chartView; | |
80 |
|
80 | |||
81 | chartView = new QChartView(createLineChart()); |
|
81 | chartView = new QChartView(createLineChart()); | |
82 | baseLayout->addWidget(chartView, 1, 2); |
|
82 | baseLayout->addWidget(chartView, 1, 2); | |
83 | m_charts << chartView; |
|
83 | m_charts << chartView; | |
84 |
|
84 | |||
85 | chartView = new QChartView(createPieChart()); |
|
85 | chartView = new QChartView(createPieChart()); | |
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
87 | baseLayout->addWidget(chartView, 2, 0); |
|
87 | baseLayout->addWidget(chartView, 2, 0); | |
88 | m_charts << chartView; |
|
88 | m_charts << chartView; | |
89 |
|
89 | |||
90 | chartView = new QChartView(createSplineChart()); |
|
90 | chartView = new QChartView(createSplineChart()); | |
91 | baseLayout->addWidget(chartView, 2, 1); |
|
91 | baseLayout->addWidget(chartView, 2, 1); | |
92 | m_charts << chartView; |
|
92 | m_charts << chartView; | |
93 |
|
93 | |||
94 | chartView = new QChartView(createScatterChart()); |
|
94 | chartView = new QChartView(createScatterChart()); | |
95 | baseLayout->addWidget(chartView, 2, 2); |
|
95 | baseLayout->addWidget(chartView, 2, 2); | |
96 | m_charts << chartView; |
|
96 | m_charts << chartView; | |
97 |
|
97 | |||
98 | setLayout(baseLayout); |
|
98 | setLayout(baseLayout); | |
99 |
|
99 | |||
100 | // Set defaults |
|
100 | // Set defaults | |
101 | m_antialiasCheckBox->setChecked(true); |
|
101 | m_antialiasCheckBox->setChecked(true); | |
102 | updateUI(); |
|
102 | updateUI(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | ThemeWidget::~ThemeWidget() |
|
105 | ThemeWidget::~ThemeWidget() | |
106 | { |
|
106 | { | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ThemeWidget::connectSignals() |
|
109 | void ThemeWidget::connectSignals() | |
110 | { |
|
110 | { | |
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
118 | { |
|
118 | { | |
119 | DataTable dataTable; |
|
119 | DataTable dataTable; | |
120 |
|
120 | |||
121 | // set seed for random stuff |
|
121 | // set seed for random stuff | |
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
123 |
|
123 | |||
124 | // generate random data |
|
124 | // generate random data | |
125 | for (int i(0); i < listCount; i++) { |
|
125 | for (int i(0); i < listCount; i++) { | |
126 | DataList dataList; |
|
126 | DataList dataList; | |
127 | qreal yValue(0); |
|
127 | qreal yValue(0); | |
128 | for (int j(0); j < valueCount; j++) { |
|
128 | for (int j(0); j < valueCount; j++) { | |
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
131 | yValue); |
|
131 | yValue); | |
132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
133 | dataList << Data(value, label); |
|
133 | dataList << Data(value, label); | |
134 | } |
|
134 | } | |
135 | dataTable << dataList; |
|
135 | dataTable << dataList; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | return dataTable; |
|
138 | return dataTable; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | QComboBox* ThemeWidget::createThemeBox() const |
|
141 | QComboBox* ThemeWidget::createThemeBox() const | |
142 | { |
|
142 | { | |
143 | // settings layout |
|
143 | // settings layout | |
144 | QComboBox* themeComboBox = new QComboBox(); |
|
144 | QComboBox* themeComboBox = new QComboBox(); | |
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
152 | return themeComboBox; |
|
152 | return themeComboBox; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | QComboBox* ThemeWidget::createAnimationBox() const |
|
155 | QComboBox* ThemeWidget::createAnimationBox() const | |
156 | { |
|
156 | { | |
157 | // settings layout |
|
157 | // settings layout | |
158 | QComboBox* animationComboBox = new QComboBox(); |
|
158 | QComboBox* animationComboBox = new QComboBox(); | |
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
163 | return animationComboBox; |
|
163 | return animationComboBox; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QComboBox* ThemeWidget::createLegendBox() const |
|
166 | QComboBox* ThemeWidget::createLegendBox() const | |
167 | { |
|
167 | { | |
168 | QComboBox* legendComboBox = new QComboBox(); |
|
168 | QComboBox* legendComboBox = new QComboBox(); | |
169 | legendComboBox->addItem("No Legend ", 0); |
|
169 | legendComboBox->addItem("No Legend ", 0); | |
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
174 | return legendComboBox; |
|
174 | return legendComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | QChart *chart = new QChart(); |
|
179 | QChart *chart = new QChart(); | |
180 | chart->axisX()->setNiceNumbersEnabled(true); |
|
180 | chart->axisX()->setNiceNumbersEnabled(true); | |
181 | chart->axisY()->setNiceNumbersEnabled(true); |
|
181 | chart->axisY()->setNiceNumbersEnabled(true); | |
182 | chart->setTitle("Area chart"); |
|
182 | chart->setTitle("Area chart"); | |
183 |
|
183 | |||
184 | // The lower series initialized to zero values |
|
184 | // The lower series initialized to zero values | |
185 | QLineSeries *lowerSeries = 0; |
|
185 | QLineSeries *lowerSeries = 0; | |
186 | QString name("Series "); |
|
186 | QString name("Series "); | |
187 | int nameIndex = 0; |
|
187 | int nameIndex = 0; | |
188 | for (int i(0); i < m_dataTable.count(); i++) { |
|
188 | for (int i(0); i < m_dataTable.count(); i++) { | |
189 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
189 | QLineSeries *upperSeries = new QLineSeries(chart); | |
190 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
190 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
191 | Data data = m_dataTable[i].at(j); |
|
191 | Data data = m_dataTable[i].at(j); | |
192 | if (lowerSeries){ |
|
192 | if (lowerSeries){ | |
193 | const QList<QPointF>& points = lowerSeries->points(); |
|
193 | const QList<QPointF>& points = lowerSeries->points(); | |
194 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
194 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
195 | }else |
|
195 | }else | |
196 | upperSeries->append(QPointF(j, data.first.y())); |
|
196 | upperSeries->append(QPointF(j, data.first.y())); | |
197 | } |
|
197 | } | |
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
199 | area->setName(name + QString::number(nameIndex)); |
|
199 | area->setName(name + QString::number(nameIndex)); | |
200 | nameIndex++; |
|
200 | nameIndex++; | |
201 | chart->addSeries(area); |
|
201 | chart->addSeries(area); | |
202 | lowerSeries = upperSeries; |
|
202 | lowerSeries = upperSeries; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | return chart; |
|
205 | return chart; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
208 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
209 | { |
|
209 | { | |
210 | QChart* chart = new QChart(); |
|
210 | QChart* chart = new QChart(); | |
211 | chart->axisX()->setNiceNumbersEnabled(true); |
|
211 | chart->axisX()->setNiceNumbersEnabled(true); | |
212 | chart->axisY()->setNiceNumbersEnabled(true); |
|
212 | chart->axisY()->setNiceNumbersEnabled(true); | |
213 | chart->setTitle("Bar chart"); |
|
213 | chart->setTitle("Bar chart"); | |
214 |
|
214 | |||
215 | QBarCategories categories; |
|
215 | QBarCategories categories; | |
216 | for (int i(0); i < valueCount; i++) |
|
216 | for (int i(0); i < valueCount; i++) | |
217 | categories << QString::number(i); |
|
217 | categories << QString::number(i); | |
218 |
|
218 | |||
219 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
|
220 | series->setCategories(categories); | |||
220 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | for (int i(0); i < m_dataTable.count(); i++) { | |
221 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
222 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
222 | foreach (Data data, m_dataTable[i]) |
|
223 | foreach (Data data, m_dataTable[i]) | |
223 | *set << data.first.y(); |
|
224 | *set << data.first.y(); | |
224 | series->appendBarSet(set); |
|
225 | series->appendBarSet(set); | |
225 | } |
|
226 | } | |
226 | chart->addSeries(series); |
|
227 | chart->addSeries(series); | |
227 |
|
228 | |||
228 | return chart; |
|
229 | return chart; | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | QChart* ThemeWidget::createLineChart() const |
|
232 | QChart* ThemeWidget::createLineChart() const | |
232 | { |
|
233 | { | |
233 | QChart* chart = new QChart(); |
|
234 | QChart* chart = new QChart(); | |
234 | chart->axisX()->setNiceNumbersEnabled(true); |
|
235 | chart->axisX()->setNiceNumbersEnabled(true); | |
235 | chart->axisY()->setNiceNumbersEnabled(true); |
|
236 | chart->axisY()->setNiceNumbersEnabled(true); | |
236 | chart->setTitle("Line chart"); |
|
237 | chart->setTitle("Line chart"); | |
237 |
|
238 | |||
238 | QString name("Series "); |
|
239 | QString name("Series "); | |
239 | int nameIndex = 0; |
|
240 | int nameIndex = 0; | |
240 | foreach (DataList list, m_dataTable) { |
|
241 | foreach (DataList list, m_dataTable) { | |
241 | QLineSeries *series = new QLineSeries(chart); |
|
242 | QLineSeries *series = new QLineSeries(chart); | |
242 | foreach (Data data, list) |
|
243 | foreach (Data data, list) | |
243 | series->append(data.first); |
|
244 | series->append(data.first); | |
244 | series->setName(name + QString::number(nameIndex)); |
|
245 | series->setName(name + QString::number(nameIndex)); | |
245 | nameIndex++; |
|
246 | nameIndex++; | |
246 | chart->addSeries(series); |
|
247 | chart->addSeries(series); | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | return chart; |
|
250 | return chart; | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
252 | QChart* ThemeWidget::createPieChart() const |
|
253 | QChart* ThemeWidget::createPieChart() const | |
253 | { |
|
254 | { | |
254 | QChart* chart = new QChart(); |
|
255 | QChart* chart = new QChart(); | |
255 | chart->setTitle("Pie chart"); |
|
256 | chart->setTitle("Pie chart"); | |
256 |
|
257 | |||
257 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
258 | qreal pieSize = 1.0 / m_dataTable.count(); | |
258 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
259 | for (int i = 0; i < m_dataTable.count(); i++) { | |
259 | QPieSeries *series = new QPieSeries(chart); |
|
260 | QPieSeries *series = new QPieSeries(chart); | |
260 | foreach (Data data, m_dataTable[i]) { |
|
261 | foreach (Data data, m_dataTable[i]) { | |
261 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
262 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
262 | if (data == m_dataTable[i].first()) { |
|
263 | if (data == m_dataTable[i].first()) { | |
263 | slice->setLabelVisible(); |
|
264 | slice->setLabelVisible(); | |
264 | slice->setExploded(); |
|
265 | slice->setExploded(); | |
265 | } |
|
266 | } | |
266 | } |
|
267 | } | |
267 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
268 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
268 | series->setPieSize(pieSize); |
|
269 | series->setPieSize(pieSize); | |
269 | series->setHorizontalPosition(hPos); |
|
270 | series->setHorizontalPosition(hPos); | |
270 | series->setVerticalPosition(0.5); |
|
271 | series->setVerticalPosition(0.5); | |
271 | chart->addSeries(series); |
|
272 | chart->addSeries(series); | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | return chart; |
|
275 | return chart; | |
275 | } |
|
276 | } | |
276 |
|
277 | |||
277 | QChart* ThemeWidget::createSplineChart() const |
|
278 | QChart* ThemeWidget::createSplineChart() const | |
278 | { // spine chart |
|
279 | { // spine chart | |
279 | QChart* chart = new QChart(); |
|
280 | QChart* chart = new QChart(); | |
280 | chart->axisX()->setNiceNumbersEnabled(true); |
|
281 | chart->axisX()->setNiceNumbersEnabled(true); | |
281 | chart->axisY()->setNiceNumbersEnabled(true); |
|
282 | chart->axisY()->setNiceNumbersEnabled(true); | |
282 | chart->setTitle("Spline chart"); |
|
283 | chart->setTitle("Spline chart"); | |
283 | QString name("Series "); |
|
284 | QString name("Series "); | |
284 | int nameIndex = 0; |
|
285 | int nameIndex = 0; | |
285 | foreach (DataList list, m_dataTable) { |
|
286 | foreach (DataList list, m_dataTable) { | |
286 | QSplineSeries *series = new QSplineSeries(chart); |
|
287 | QSplineSeries *series = new QSplineSeries(chart); | |
287 | foreach (Data data, list) |
|
288 | foreach (Data data, list) | |
288 | series->append(data.first); |
|
289 | series->append(data.first); | |
289 | series->setName(name + QString::number(nameIndex)); |
|
290 | series->setName(name + QString::number(nameIndex)); | |
290 | nameIndex++; |
|
291 | nameIndex++; | |
291 | chart->addSeries(series); |
|
292 | chart->addSeries(series); | |
292 | } |
|
293 | } | |
293 | return chart; |
|
294 | return chart; | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | QChart* ThemeWidget::createScatterChart() const |
|
297 | QChart* ThemeWidget::createScatterChart() const | |
297 | { // scatter chart |
|
298 | { // scatter chart | |
298 | QChart* chart = new QChart(); |
|
299 | QChart* chart = new QChart(); | |
299 | chart->axisX()->setNiceNumbersEnabled(true); |
|
300 | chart->axisX()->setNiceNumbersEnabled(true); | |
300 | chart->axisY()->setNiceNumbersEnabled(true); |
|
301 | chart->axisY()->setNiceNumbersEnabled(true); | |
301 | chart->setTitle("Scatter chart"); |
|
302 | chart->setTitle("Scatter chart"); | |
302 | QString name("Series "); |
|
303 | QString name("Series "); | |
303 | int nameIndex = 0; |
|
304 | int nameIndex = 0; | |
304 | foreach (DataList list, m_dataTable) { |
|
305 | foreach (DataList list, m_dataTable) { | |
305 | QScatterSeries *series = new QScatterSeries(chart); |
|
306 | QScatterSeries *series = new QScatterSeries(chart); | |
306 | foreach (Data data, list) |
|
307 | foreach (Data data, list) | |
307 | series->append(data.first); |
|
308 | series->append(data.first); | |
308 | series->setName(name + QString::number(nameIndex)); |
|
309 | series->setName(name + QString::number(nameIndex)); | |
309 | nameIndex++; |
|
310 | nameIndex++; | |
310 | chart->addSeries(series); |
|
311 | chart->addSeries(series); | |
311 | } |
|
312 | } | |
312 | return chart; |
|
313 | return chart; | |
313 | } |
|
314 | } | |
314 |
|
315 | |||
315 | void ThemeWidget::updateUI() |
|
316 | void ThemeWidget::updateUI() | |
316 | { |
|
317 | { | |
317 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
318 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
318 |
|
319 | |||
319 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
320 | if (m_charts.at(0)->chart()->theme() != theme) { | |
320 | foreach (QChartView *chartView, m_charts) |
|
321 | foreach (QChartView *chartView, m_charts) | |
321 | chartView->chart()->setTheme(theme); |
|
322 | chartView->chart()->setTheme(theme); | |
322 |
|
323 | |||
323 | QPalette pal = window()->palette(); |
|
324 | QPalette pal = window()->palette(); | |
324 | if (theme == QChart::ChartThemeLight) { |
|
325 | if (theme == QChart::ChartThemeLight) { | |
325 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
326 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
326 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
327 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
327 | } else if (theme == QChart::ChartThemeDark) { |
|
328 | } else if (theme == QChart::ChartThemeDark) { | |
328 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
329 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
329 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
330 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
330 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
331 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
331 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
332 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
332 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
333 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
333 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
334 | } else if (theme == QChart::ChartThemeBrownSand) { | |
334 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
335 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
335 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
336 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
337 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
337 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
338 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
338 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
339 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
339 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
340 | } else if (theme == QChart::ChartThemeHighContrast) { | |
340 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
341 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
341 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
342 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
342 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
343 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
343 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
344 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
344 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
345 | } else { |
|
346 | } else { | |
346 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
347 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
347 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
348 | } |
|
349 | } | |
349 | window()->setPalette(pal); |
|
350 | window()->setPalette(pal); | |
350 | } |
|
351 | } | |
351 |
|
352 | |||
352 | bool checked = m_antialiasCheckBox->isChecked(); |
|
353 | bool checked = m_antialiasCheckBox->isChecked(); | |
353 | foreach (QChartView *chart, m_charts) |
|
354 | foreach (QChartView *chart, m_charts) | |
354 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
355 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
355 |
|
356 | |||
356 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
357 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
357 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
358 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
358 | foreach (QChartView *chartView, m_charts) |
|
359 | foreach (QChartView *chartView, m_charts) | |
359 | chartView->chart()->setAnimationOptions(options); |
|
360 | chartView->chart()->setAnimationOptions(options); | |
360 | } |
|
361 | } | |
361 |
|
362 | |||
362 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
363 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
363 |
|
364 | |||
364 | if (!alignment) { |
|
365 | if (!alignment) { | |
365 | foreach (QChartView *chartView, m_charts) { |
|
366 | foreach (QChartView *chartView, m_charts) { | |
366 | chartView->chart()->legend()->hide(); |
|
367 | chartView->chart()->legend()->hide(); | |
367 | } |
|
368 | } | |
368 | } else { |
|
369 | } else { | |
369 | foreach (QChartView *chartView, m_charts) { |
|
370 | foreach (QChartView *chartView, m_charts) { | |
370 | chartView->chart()->legend()->setAlignment(alignment); |
|
371 | chartView->chart()->legend()->setAlignment(alignment); | |
371 | chartView->chart()->legend()->show(); |
|
372 | chartView->chart()->legend()->show(); | |
372 | } |
|
373 | } | |
373 | } |
|
374 | } | |
374 | } |
|
375 | } | |
375 |
|
376 |
@@ -1,52 +1,47 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Rectangle { |
|
24 | Rectangle { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 |
|
26 | |||
27 | Chart { |
|
27 | Chart { | |
28 | title: "Car brand shares in Finland" |
|
28 | title: "Car brand shares in Finland" | |
29 | anchors.fill: parent |
|
29 | anchors.fill: parent | |
30 | theme: Chart.ChartThemeLight |
|
30 | theme: Chart.ChartThemeLight | |
31 | legend: Chart.LegendBottom |
|
31 | legend: Chart.LegendBottom | |
32 |
|
32 | |||
33 | PieSeries { |
|
33 | PieSeries { | |
34 |
horizontalPosition: 0. |
|
34 | horizontalPosition: 0.5 | |
35 |
verticalPosition: 0. |
|
35 | verticalPosition: 0.5 | |
36 |
size: 0. |
|
36 | size: 0.7 | |
37 | slices: [ |
|
37 | slices: [ | |
38 | PieSlice { label: "Volkswagen"; value: 13.5 }, |
|
38 | PieSlice { label: "Volkswagen"; value: 13.5 }, | |
39 | PieSlice { label: "Toyota"; value: 10.9 }, |
|
39 | PieSlice { label: "Toyota"; value: 10.9 }, | |
40 | PieSlice { label: "Ford"; value: 8.6 }, |
|
40 | PieSlice { label: "Ford"; value: 8.6 }, | |
41 | PieSlice { label: "Skoda"; value: 8.2 }, |
|
41 | PieSlice { label: "Skoda"; value: 8.2 }, | |
42 | PieSlice { label: "Volvo"; value: 6.8 }, |
|
42 | PieSlice { label: "Volvo"; value: 6.8 }, | |
43 | PieSlice { label: "Others"; value: 52.0 } |
|
43 | PieSlice { label: "Others"; value: 52.0 } | |
44 | ] |
|
44 | ] | |
45 | } |
|
45 | } | |
46 |
|
||||
47 | BarSeries { |
|
|||
48 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] |
|
|||
49 | // data implementation missing |
|
|||
50 | } |
|
|||
51 | } |
|
46 | } | |
52 | } |
|
47 | } |
@@ -1,129 +1,129 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Rectangle { |
|
24 | Rectangle { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 |
|
26 | |||
27 | Chart { |
|
27 | Chart { | |
28 | title: "NHL All-Star Team Players" |
|
28 | title: "NHL All-Star Team Players" | |
29 | anchors.fill: parent |
|
29 | anchors.fill: parent | |
30 | theme: Chart.ChartThemeHighContrast |
|
30 | theme: Chart.ChartThemeHighContrast | |
31 | legend: Chart.LegendTop |
|
31 | legend: Chart.LegendTop | |
32 |
|
32 | |||
33 | AreaSeries { |
|
33 | AreaSeries { | |
34 |
name: " |
|
34 | name: "Swedish" | |
35 | points: [ |
|
35 | points: [ | |
36 |
XyPoint { x: 0; y: |
|
36 | XyPoint { x: 0; y: 1 }, | |
37 |
XyPoint { x: 1; y: |
|
37 | XyPoint { x: 1; y: 1 }, | |
38 |
XyPoint { x: 2; y: |
|
38 | XyPoint { x: 2; y: 3 }, | |
39 |
XyPoint { x: 3; y: |
|
39 | XyPoint { x: 3; y: 3 }, | |
40 |
XyPoint { x: 4; y: |
|
40 | XyPoint { x: 4; y: 2 }, | |
41 | XyPoint { x: 5; y: 0 }, |
|
41 | XyPoint { x: 5; y: 0 }, | |
42 |
XyPoint { x: 6; y: |
|
42 | XyPoint { x: 6; y: 2 }, | |
43 |
XyPoint { x: 7; y: |
|
43 | XyPoint { x: 7; y: 1 }, | |
44 |
XyPoint { x: 8; y: |
|
44 | XyPoint { x: 8; y: 2 }, | |
45 |
XyPoint { x: 9; y: |
|
45 | XyPoint { x: 9; y: 1 }, | |
46 |
XyPoint { x: 10; y: |
|
46 | XyPoint { x: 10; y: 3 }, | |
47 |
XyPoint { x: 11; y: |
|
47 | XyPoint { x: 11; y: 3 } | |
48 | ] |
|
48 | ] | |
49 | lowerPoints: [ |
|
49 | lowerPoints: [ | |
50 | XyPoint { x: 0; y: 0 }, |
|
50 | XyPoint { x: 0; y: 0 }, | |
51 | XyPoint { x: 1; y: 0 }, |
|
51 | XyPoint { x: 1; y: 0 }, | |
52 | XyPoint { x: 2; y: 0 }, |
|
52 | XyPoint { x: 2; y: 0 }, | |
53 | XyPoint { x: 3; y: 0 }, |
|
53 | XyPoint { x: 3; y: 0 }, | |
54 | XyPoint { x: 4; y: 0 }, |
|
54 | XyPoint { x: 4; y: 0 }, | |
55 | XyPoint { x: 5; y: 0 }, |
|
55 | XyPoint { x: 5; y: 0 }, | |
56 | XyPoint { x: 6; y: 0 }, |
|
56 | XyPoint { x: 6; y: 0 }, | |
57 | XyPoint { x: 7; y: 0 }, |
|
57 | XyPoint { x: 7; y: 0 }, | |
58 | XyPoint { x: 8; y: 0 }, |
|
58 | XyPoint { x: 8; y: 0 }, | |
59 | XyPoint { x: 9; y: 0 }, |
|
59 | XyPoint { x: 9; y: 0 }, | |
60 | XyPoint { x: 10; y: 0 }, |
|
60 | XyPoint { x: 10; y: 0 }, | |
61 | XyPoint { x: 11; y: 0 } |
|
61 | XyPoint { x: 11; y: 0 } | |
62 | ] |
|
62 | ] | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | AreaSeries { |
|
65 | AreaSeries { | |
66 | name: "Russian" |
|
66 | name: "Russian" | |
67 | points: [ |
|
67 | points: [ | |
68 | XyPoint { x: 0; y: 1 }, |
|
68 | XyPoint { x: 0; y: 1 }, | |
69 | XyPoint { x: 1; y: 1 }, |
|
69 | XyPoint { x: 1; y: 1 }, | |
70 | XyPoint { x: 2; y: 1 }, |
|
70 | XyPoint { x: 2; y: 1 }, | |
71 | XyPoint { x: 3; y: 1 }, |
|
71 | XyPoint { x: 3; y: 1 }, | |
72 | XyPoint { x: 4; y: 1 }, |
|
72 | XyPoint { x: 4; y: 1 }, | |
73 | XyPoint { x: 5; y: 0 }, |
|
73 | XyPoint { x: 5; y: 0 }, | |
74 | XyPoint { x: 6; y: 1 }, |
|
74 | XyPoint { x: 6; y: 1 }, | |
75 | XyPoint { x: 7; y: 1 }, |
|
75 | XyPoint { x: 7; y: 1 }, | |
76 | XyPoint { x: 8; y: 4 }, |
|
76 | XyPoint { x: 8; y: 4 }, | |
77 | XyPoint { x: 9; y: 3 }, |
|
77 | XyPoint { x: 9; y: 3 }, | |
78 | XyPoint { x: 10; y: 2 }, |
|
78 | XyPoint { x: 10; y: 2 }, | |
79 | XyPoint { x: 11; y: 1 } |
|
79 | XyPoint { x: 11; y: 1 } | |
80 | ] |
|
80 | ] | |
81 | lowerPoints: [ |
|
81 | lowerPoints: [ | |
82 | XyPoint { x: 0; y: 0 }, |
|
82 | XyPoint { x: 0; y: 0 }, | |
83 | XyPoint { x: 1; y: 0 }, |
|
83 | XyPoint { x: 1; y: 0 }, | |
84 | XyPoint { x: 2; y: 0 }, |
|
84 | XyPoint { x: 2; y: 0 }, | |
85 | XyPoint { x: 3; y: 0 }, |
|
85 | XyPoint { x: 3; y: 0 }, | |
86 | XyPoint { x: 4; y: 0 }, |
|
86 | XyPoint { x: 4; y: 0 }, | |
87 | XyPoint { x: 5; y: 0 }, |
|
87 | XyPoint { x: 5; y: 0 }, | |
88 | XyPoint { x: 6; y: 0 }, |
|
88 | XyPoint { x: 6; y: 0 }, | |
89 | XyPoint { x: 7; y: 0 }, |
|
89 | XyPoint { x: 7; y: 0 }, | |
90 | XyPoint { x: 8; y: 0 }, |
|
90 | XyPoint { x: 8; y: 0 }, | |
91 | XyPoint { x: 9; y: 0 }, |
|
91 | XyPoint { x: 9; y: 0 }, | |
92 | XyPoint { x: 10; y: 0 }, |
|
92 | XyPoint { x: 10; y: 0 }, | |
93 | XyPoint { x: 11; y: 0 } |
|
93 | XyPoint { x: 11; y: 0 } | |
94 | ] |
|
94 | ] | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | AreaSeries { |
|
97 | AreaSeries { | |
98 |
name: " |
|
98 | name: "Finnish" | |
99 | points: [ |
|
99 | points: [ | |
100 |
XyPoint { x: 0; y: |
|
100 | XyPoint { x: 0; y: 0 }, | |
101 |
XyPoint { x: 1; y: |
|
101 | XyPoint { x: 1; y: 0 }, | |
102 |
XyPoint { x: 2; y: |
|
102 | XyPoint { x: 2; y: 0 }, | |
103 |
XyPoint { x: 3; y: |
|
103 | XyPoint { x: 3; y: 0 }, | |
104 |
XyPoint { x: 4; y: |
|
104 | XyPoint { x: 4; y: 0 }, | |
105 | XyPoint { x: 5; y: 0 }, |
|
105 | XyPoint { x: 5; y: 0 }, | |
106 |
XyPoint { x: 6; y: |
|
106 | XyPoint { x: 6; y: 1 }, | |
107 |
XyPoint { x: 7; y: |
|
107 | XyPoint { x: 7; y: 0 }, | |
108 |
XyPoint { x: 8; y: |
|
108 | XyPoint { x: 8; y: 0 }, | |
109 |
XyPoint { x: 9; y: |
|
109 | XyPoint { x: 9; y: 0 }, | |
110 |
XyPoint { x: 10; y: |
|
110 | XyPoint { x: 10; y: 0 }, | |
111 |
XyPoint { x: 11; y: |
|
111 | XyPoint { x: 11; y: 1 } | |
112 | ] |
|
112 | ] | |
113 | lowerPoints: [ |
|
113 | lowerPoints: [ | |
114 | XyPoint { x: 0; y: 0 }, |
|
114 | XyPoint { x: 0; y: 0 }, | |
115 | XyPoint { x: 1; y: 0 }, |
|
115 | XyPoint { x: 1; y: 0 }, | |
116 | XyPoint { x: 2; y: 0 }, |
|
116 | XyPoint { x: 2; y: 0 }, | |
117 | XyPoint { x: 3; y: 0 }, |
|
117 | XyPoint { x: 3; y: 0 }, | |
118 | XyPoint { x: 4; y: 0 }, |
|
118 | XyPoint { x: 4; y: 0 }, | |
119 | XyPoint { x: 5; y: 0 }, |
|
119 | XyPoint { x: 5; y: 0 }, | |
120 | XyPoint { x: 6; y: 0 }, |
|
120 | XyPoint { x: 6; y: 0 }, | |
121 | XyPoint { x: 7; y: 0 }, |
|
121 | XyPoint { x: 7; y: 0 }, | |
122 | XyPoint { x: 8; y: 0 }, |
|
122 | XyPoint { x: 8; y: 0 }, | |
123 | XyPoint { x: 9; y: 0 }, |
|
123 | XyPoint { x: 9; y: 0 }, | |
124 | XyPoint { x: 10; y: 0 }, |
|
124 | XyPoint { x: 10; y: 0 }, | |
125 | XyPoint { x: 11; y: 0 } |
|
125 | XyPoint { x: 11; y: 0 } | |
126 | ] |
|
126 | ] | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 | } |
|
129 | } |
@@ -1,53 +1,53 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Rectangle { |
|
24 | Rectangle { | |
25 | width: parent.width |
|
25 | width: parent.width | |
26 | height: parent.height |
|
26 | height: parent.height | |
27 | property int __viewNumber: 0 |
|
27 | property int __viewNumber: 0 | |
28 |
|
28 | |||
29 | Timer { |
|
29 | Timer { | |
30 | id: timer |
|
30 | id: timer | |
31 | running: true |
|
31 | running: true | |
32 | repeat: true |
|
32 | repeat: true | |
33 | interval: 5000 |
|
33 | interval: 5000 | |
34 | triggeredOnStart: false |
|
34 | triggeredOnStart: false | |
35 | onTriggered: { |
|
35 | onTriggered: { | |
36 | __viewNumber++; |
|
36 | __viewNumber++; | |
37 | } |
|
37 | } | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | Loader { |
|
40 | Loader { | |
41 | id: loader |
|
41 | id: loader | |
42 | anchors.fill: parent |
|
42 | anchors.fill: parent | |
43 |
source: "View" + (__viewNumber % |
|
43 | source: "View" + (__viewNumber % 5 + 1) + ".qml"; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | MouseArea { |
|
46 | MouseArea { | |
47 | anchors.fill: parent |
|
47 | anchors.fill: parent | |
48 | onClicked: { |
|
48 | onClicked: { | |
49 | timer.restart(); |
|
49 | timer.restart(); | |
50 | __viewNumber++; |
|
50 | __viewNumber++; | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } |
@@ -1,10 +1,11 | |||||
1 | <RCC> |
|
1 | <RCC> | |
2 | <qresource prefix="/"> |
|
2 | <qresource prefix="/"> | |
3 | <file>qml/qmlchart/loader.qml</file> |
|
3 | <file>qml/qmlchart/loader.qml</file> | |
4 | <file>qml/qmlchart/main.qml</file> |
|
4 | <file>qml/qmlchart/main.qml</file> | |
5 | <file>qml/qmlchart/View1.qml</file> |
|
5 | <file>qml/qmlchart/View1.qml</file> | |
6 | <file>qml/qmlchart/View2.qml</file> |
|
6 | <file>qml/qmlchart/View2.qml</file> | |
7 | <file>qml/qmlchart/View3.qml</file> |
|
7 | <file>qml/qmlchart/View3.qml</file> | |
8 | <file>qml/qmlchart/View4.qml</file> |
|
8 | <file>qml/qmlchart/View4.qml</file> | |
|
9 | <file>qml/qmlchart/View5.qml</file> | |||
9 | </qresource> |
|
10 | </qresource> | |
10 | </RCC> |
|
11 | </RCC> |
@@ -1,87 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSeries> |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 |
QBarSeries* series = new QBarSeries( |
|
54 | QBarSeries* series = new QBarSeries(); | |
|
55 | series->setCategories(categories); | |||
55 | series->appendBarSet(set0); |
|
56 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
57 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
58 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
59 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
60 | series->appendBarSet(set4); | |
60 | //![3] |
|
61 | //![3] | |
61 |
|
62 | |||
62 | //![4] |
|
63 | //![4] | |
63 | QChart* chart = new QChart(); |
|
64 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
65 | chart->addSeries(series); | |
65 | chart->setTitle("Simple barchart example"); |
|
66 | chart->setTitle("Simple barchart example"); | |
66 | //![4] |
|
67 | //![4] | |
67 |
|
68 | |||
68 | //![5] |
|
69 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
70 | chart->legend()->setVisible(true); | |
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | chart->axisY()->setNiceNumbersEnabled(true); |
|
72 | chart->axisY()->setNiceNumbersEnabled(true); | |
72 | //![5] |
|
73 | //![5] | |
73 |
|
74 | |||
74 | //![6] |
|
75 | //![6] | |
75 | QChartView* chartView = new QChartView(chart); |
|
76 | QChartView* chartView = new QChartView(chart); | |
76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
77 | chartView->setRenderHint(QPainter::Antialiasing); | |
77 | //![6] |
|
78 | //![6] | |
78 |
|
79 | |||
79 | //![7] |
|
80 | //![7] | |
80 | QMainWindow window; |
|
81 | QMainWindow window; | |
81 | window.setCentralWidget(chartView); |
|
82 | window.setCentralWidget(chartView); | |
82 | window.resize(400, 300); |
|
83 | window.resize(400, 300); | |
83 | window.show(); |
|
84 | window.show(); | |
84 | //![7] |
|
85 | //![7] | |
85 |
|
86 | |||
86 | return a.exec(); |
|
87 | return a.exec(); | |
87 | } |
|
88 | } |
@@ -1,87 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPercentBarSeries> |
|
24 | #include <QPercentBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 |
QPercentBarSeries* series = new QPercentBarSeries( |
|
54 | QPercentBarSeries* series = new QPercentBarSeries(); | |
|
55 | series->setCategories(categories); | |||
55 | series->appendBarSet(set0); |
|
56 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
57 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
58 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
59 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
60 | series->appendBarSet(set4); | |
60 | //![3] |
|
61 | //![3] | |
61 |
|
62 | |||
62 | //![4] |
|
63 | //![4] | |
63 | QChart* chart = new QChart(); |
|
64 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
65 | chart->addSeries(series); | |
65 | chart->setTitle("Simple percentbarchart example"); |
|
66 | chart->setTitle("Simple percentbarchart example"); | |
66 | //![4] |
|
67 | //![4] | |
67 |
|
68 | |||
68 | //![5] |
|
69 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
70 | chart->legend()->setVisible(true); | |
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | //![5] |
|
72 | //![5] | |
72 |
|
73 | |||
73 | //![6] |
|
74 | //![6] | |
74 | QChartView* chartView = new QChartView(chart); |
|
75 | QChartView* chartView = new QChartView(chart); | |
75 | chartView->setRenderHint(QPainter::Antialiasing); |
|
76 | chartView->setRenderHint(QPainter::Antialiasing); | |
76 | //![6] |
|
77 | //![6] | |
77 |
|
78 | |||
78 | //![7] |
|
79 | //![7] | |
79 | QMainWindow window; |
|
80 | QMainWindow window; | |
80 | window.setCentralWidget(chartView); |
|
81 | window.setCentralWidget(chartView); | |
81 | window.resize(400, 300); |
|
82 | window.resize(400, 300); | |
82 | window.show(); |
|
83 | window.show(); | |
83 | //![7] |
|
84 | //![7] | |
84 |
|
85 | |||
85 | return a.exec(); |
|
86 | return a.exec(); | |
86 | } |
|
87 | } | |
87 |
|
88 |
@@ -1,88 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
35 | QBarCategories categories; | |
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
37 | //![1] |
|
37 | //![1] | |
38 |
|
38 | |||
39 | //![2] |
|
39 | //![2] | |
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
40 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
41 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
42 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
43 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
44 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
45 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 | //![2] |
|
51 | //![2] | |
52 |
|
52 | |||
53 | //![3] |
|
53 | //![3] | |
54 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
54 | QStackedBarSeries* series = new QStackedBarSeries(); | |
|
55 | series->setCategories(categories); | |||
55 | series->appendBarSet(set0); |
|
56 | series->appendBarSet(set0); | |
56 | series->appendBarSet(set1); |
|
57 | series->appendBarSet(set1); | |
57 | series->appendBarSet(set2); |
|
58 | series->appendBarSet(set2); | |
58 | series->appendBarSet(set3); |
|
59 | series->appendBarSet(set3); | |
59 | series->appendBarSet(set4); |
|
60 | series->appendBarSet(set4); | |
60 | //![3] |
|
61 | //![3] | |
61 |
|
62 | |||
62 | //![4] |
|
63 | //![4] | |
63 | QChart* chart = new QChart(); |
|
64 | QChart* chart = new QChart(); | |
64 | chart->addSeries(series); |
|
65 | chart->addSeries(series); | |
65 | chart->setTitle("Simple stackedbarchart example"); |
|
66 | chart->setTitle("Simple stackedbarchart example"); | |
66 | //![4] |
|
67 | //![4] | |
67 |
|
68 | |||
68 | //![5] |
|
69 | //![5] | |
69 | chart->legend()->setVisible(true); |
|
70 | chart->legend()->setVisible(true); | |
70 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
71 | chart->axisY()->setNiceNumbersEnabled(true); |
|
72 | chart->axisY()->setNiceNumbersEnabled(true); | |
72 | //![5] |
|
73 | //![5] | |
73 |
|
74 | |||
74 | //![6] |
|
75 | //![6] | |
75 | QChartView* chartView = new QChartView(chart); |
|
76 | QChartView* chartView = new QChartView(chart); | |
76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
77 | chartView->setRenderHint(QPainter::Antialiasing); | |
77 | //![6] |
|
78 | //![6] | |
78 |
|
79 | |||
79 | //![7] |
|
80 | //![7] | |
80 | QMainWindow window; |
|
81 | QMainWindow window; | |
81 | window.setCentralWidget(chartView); |
|
82 | window.setCentralWidget(chartView); | |
82 | window.resize(400, 300); |
|
83 | window.resize(400, 300); | |
83 | window.show(); |
|
84 | window.show(); | |
84 | //![7] |
|
85 | //![7] | |
85 |
|
86 | |||
86 | return a.exec(); |
|
87 | return a.exec(); | |
87 | } |
|
88 | } | |
88 |
|
89 |
@@ -1,40 +1,41 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "drilldownseries.h" |
|
21 | #include "drilldownseries.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) |
|
25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) | |
26 |
: QStackedBarSeries( |
|
26 | : QStackedBarSeries(parent) | |
27 | { |
|
27 | { | |
|
28 | setCategories(categories); | |||
28 | } |
|
29 | } | |
29 |
|
30 | |||
30 | void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
|
31 | void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) | |
31 | { |
|
32 | { | |
32 | mDrilldownSeries[category] = drilldownSeries; |
|
33 | mDrilldownSeries[category] = drilldownSeries; | |
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(QString category) |
|
36 | DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(QString category) | |
36 | { |
|
37 | { | |
37 | return mDrilldownSeries[category]; |
|
38 | return mDrilldownSeries[category]; | |
38 | } |
|
39 | } | |
39 |
|
40 | |||
40 | #include "moc_drilldownseries.cpp" |
|
41 | #include "moc_drilldownseries.cpp" |
@@ -1,70 +1,65 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativeareaseries.h" |
|
21 | #include "declarativeareaseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : |
|
28 | DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : | |
29 | QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) |
|
29 | QAreaSeries(new QLineSeries(parent), new QLineSeries(parent)) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QAbstractSeries *DeclarativeAreaSeries::series() |
|
|||
34 | { |
|
|||
35 | return this; |
|
|||
36 | } |
|
|||
37 |
|
||||
38 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points() |
|
33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points() | |
39 | { |
|
34 | { | |
40 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints); |
|
35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints); | |
41 | } |
|
36 | } | |
42 |
|
37 | |||
43 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints() |
|
38 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints() | |
44 | { |
|
39 | { | |
45 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints); |
|
40 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints); | |
46 | } |
|
41 | } | |
47 |
|
42 | |||
48 | void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
43 | void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
49 | DeclarativeXyPoint *element) |
|
44 | DeclarativeXyPoint *element) | |
50 | { |
|
45 | { | |
51 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); |
|
46 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); | |
52 | if (series) { |
|
47 | if (series) { | |
53 | QLineSeries *upper = series->upperSeries(); |
|
48 | QLineSeries *upper = series->upperSeries(); | |
54 | upper->append(element->x(), element->y()); |
|
49 | upper->append(element->x(), element->y()); | |
55 | } |
|
50 | } | |
56 | } |
|
51 | } | |
57 |
|
52 | |||
58 | void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
53 | void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
59 | DeclarativeXyPoint *element) |
|
54 | DeclarativeXyPoint *element) | |
60 | { |
|
55 | { | |
61 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); |
|
56 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); | |
62 | if (series) { |
|
57 | if (series) { | |
63 | QLineSeries *lower = series->lowerSeries(); |
|
58 | QLineSeries *lower = series->lowerSeries(); | |
64 | lower->append(element->x(), element->y()); |
|
59 | lower->append(element->x(), element->y()); | |
65 | } |
|
60 | } | |
66 | } |
|
61 | } | |
67 |
|
62 | |||
68 | #include "moc_declarativeareaseries.cpp" |
|
63 | #include "moc_declarativeareaseries.cpp" | |
69 |
|
64 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,52 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVEAREASERIES_H |
|
21 | #ifndef DECLARATIVEAREASERIES_H | |
22 | #define DECLARATIVEAREASERIES_H |
|
22 | #define DECLARATIVEAREASERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qareaseries.h" |
|
25 | #include "qareaseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries |
|
30 | class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
33 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) | |
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints) |
|
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeAreaSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeAreaSeries(QObject *parent = 0); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QAbstractSeries *series(); |
|
|||
41 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); | |
42 | QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints(); |
|
41 | QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints(); | |
43 |
|
42 | |||
44 | public Q_SLOTS: |
|
43 | public Q_SLOTS: | |
45 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
44 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
46 | DeclarativeXyPoint *element); |
|
45 | DeclarativeXyPoint *element); | |
47 | static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
46 | static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
48 | DeclarativeXyPoint *element); |
|
47 | DeclarativeXyPoint *element); | |
49 | }; |
|
48 | }; | |
50 |
|
49 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
52 |
|
51 | |||
53 | #endif // DECLARATIVEAREASERIES_H |
|
52 | #endif // DECLARATIVEAREASERIES_H |
@@ -1,79 +1,81 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qbarseries.h" |
|
24 | #include "qbarseries.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
29 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
30 | QDeclarativeItem(parent) |
|
30 | QDeclarativeItem(parent) | |
31 | { |
|
31 | { | |
32 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
32 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void DeclarativeBarSeries::componentComplete() |
|
35 | void DeclarativeBarSeries::componentComplete() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
|
39 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | |
40 | { |
|
40 | { | |
41 | m_categories = categories; |
|
41 | m_categories = categories; | |
42 |
|
42 | |||
43 | if (m_series) { |
|
43 | if (m_series) { | |
44 | delete m_series; |
|
44 | delete m_series; | |
45 | m_series = 0; |
|
45 | m_series = 0; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
48 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
49 | if (declarativeChart) { |
|
49 | if (declarativeChart) { | |
50 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
50 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
51 | Q_ASSERT(chart); |
|
51 | Q_ASSERT(chart); | |
52 |
|
52 | |||
53 | m_series = new QBarSeries(m_categories); |
|
53 | // m_series = new QBarSeries(m_categories); | |
|
54 | m_series = new QBarSeries(); | |||
|
55 | m_series->setCategories(m_categories); | |||
54 |
|
56 | |||
55 | // TODO: use data from model |
|
57 | // TODO: use data from model | |
56 | QBarSet *set0 = new QBarSet("Bub"); |
|
58 | QBarSet *set0 = new QBarSet("Bub"); | |
57 | QBarSet *set1 = new QBarSet("Bob"); |
|
59 | QBarSet *set1 = new QBarSet("Bob"); | |
58 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
60 | QBarSet *set2 = new QBarSet("Guybrush"); | |
59 |
|
61 | |||
60 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
62 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
61 | *set1 << 5 << 1 << 2 << 4 << 1 << 7; |
|
63 | *set1 << 5 << 1 << 2 << 4 << 1 << 7; | |
62 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
64 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
63 |
|
65 | |||
64 | m_series->appendBarSet(set0); |
|
66 | m_series->appendBarSet(set0); | |
65 | m_series->appendBarSet(set1); |
|
67 | m_series->appendBarSet(set1); | |
66 | m_series->appendBarSet(set2); |
|
68 | m_series->appendBarSet(set2); | |
67 |
|
69 | |||
68 | chart->addSeries(m_series); |
|
70 | chart->addSeries(m_series); | |
69 | } |
|
71 | } | |
70 | } |
|
72 | } | |
71 |
|
73 | |||
72 | QStringList DeclarativeBarSeries::barCategories() |
|
74 | QStringList DeclarativeBarSeries::barCategories() | |
73 | { |
|
75 | { | |
74 | return m_categories; |
|
76 | return m_categories; | |
75 | } |
|
77 | } | |
76 |
|
78 | |||
77 | #include "moc_declarativebarseries.cpp" |
|
79 | #include "moc_declarativebarseries.cpp" | |
78 |
|
80 | |||
79 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,114 +1,135 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
|
22 | #include "declarativepieseries.h" | |||
22 | #include <QPainter> |
|
23 | #include <QPainter> | |
23 |
|
24 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
26 | |||
26 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
27 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
27 | : QDeclarativeItem(parent), |
|
28 | : QDeclarativeItem(parent), | |
28 | m_chart(new QChart(this)), |
|
29 | m_chart(new QChart(this)), | |
29 | m_legend(LegendDisabled) |
|
30 | m_legend(LegendDisabled) | |
30 | { |
|
31 | { | |
31 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
32 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | DeclarativeChart::~DeclarativeChart() |
|
35 | DeclarativeChart::~DeclarativeChart() | |
35 | { |
|
36 | { | |
36 | delete m_chart; |
|
37 | delete m_chart; | |
37 | } |
|
38 | } | |
38 |
|
39 | |||
|
40 | void DeclarativeChart::childEvent(QChildEvent *event) | |||
|
41 | { | |||
|
42 | if (event->type() == QEvent::ChildAdded) { | |||
|
43 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |||
|
44 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |||
|
45 | } | |||
|
46 | } | |||
|
47 | } | |||
|
48 | ||||
|
49 | void DeclarativeChart::componentComplete() | |||
|
50 | { | |||
|
51 | foreach(QObject *child, children()) { | |||
|
52 | if (qobject_cast<QAbstractSeries *>(child)) { | |||
|
53 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |||
|
54 | } | |||
|
55 | } | |||
|
56 | ||||
|
57 | QDeclarativeItem::componentComplete(); | |||
|
58 | } | |||
|
59 | ||||
39 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
60 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
40 | { |
|
61 | { | |
41 | Q_UNUSED(oldGeometry) |
|
62 | Q_UNUSED(oldGeometry) | |
42 |
|
63 | |||
43 | if (newGeometry.isValid()) { |
|
64 | if (newGeometry.isValid()) { | |
44 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
65 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
45 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
66 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
46 | } |
|
67 | } | |
47 | } |
|
68 | } | |
48 | } |
|
69 | } | |
49 |
|
70 | |||
50 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
71 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
51 | { |
|
72 | { | |
52 | Q_UNUSED(option) |
|
73 | Q_UNUSED(option) | |
53 | Q_UNUSED(widget) |
|
74 | Q_UNUSED(widget) | |
54 |
|
75 | |||
55 | // TODO: optimized? |
|
76 | // TODO: optimized? | |
56 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
77 | painter->setRenderHint(QPainter::Antialiasing, true); | |
57 | } |
|
78 | } | |
58 |
|
79 | |||
59 | void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations) |
|
80 | void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations) | |
60 | { |
|
81 | { | |
61 | m_chart->setAnimationOptions(animations); |
|
82 | m_chart->setAnimationOptions(animations); | |
62 | } |
|
83 | } | |
63 |
|
84 | |||
64 | QChart::AnimationOption DeclarativeChart::animationOptions() |
|
85 | QChart::AnimationOption DeclarativeChart::animationOptions() | |
65 | { |
|
86 | { | |
66 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
87 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
67 | return QChart::AllAnimations; |
|
88 | return QChart::AllAnimations; | |
68 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
89 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
69 | return QChart::GridAxisAnimations; |
|
90 | return QChart::GridAxisAnimations; | |
70 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
91 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
71 | return QChart::SeriesAnimations; |
|
92 | return QChart::SeriesAnimations; | |
72 | else |
|
93 | else | |
73 | return QChart::NoAnimation; |
|
94 | return QChart::NoAnimation; | |
74 | } |
|
95 | } | |
75 |
|
96 | |||
76 | void DeclarativeChart::setLegend(ChartLegend legend) |
|
97 | void DeclarativeChart::setLegend(ChartLegend legend) | |
77 | { |
|
98 | { | |
78 | if (legend != m_legend) { |
|
99 | if (legend != m_legend) { | |
79 | m_legend = legend; |
|
100 | m_legend = legend; | |
80 | switch (m_legend) { |
|
101 | switch (m_legend) { | |
81 | case LegendDisabled: |
|
102 | case LegendDisabled: | |
82 | m_chart->legend()->setVisible(false); |
|
103 | m_chart->legend()->setVisible(false); | |
83 | break; |
|
104 | break; | |
84 | case LegendTop: |
|
105 | case LegendTop: | |
85 | m_chart->legend()->setVisible(true); |
|
106 | m_chart->legend()->setVisible(true); | |
86 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); |
|
107 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); | |
87 | break; |
|
108 | break; | |
88 | case LegendBottom: |
|
109 | case LegendBottom: | |
89 | m_chart->legend()->setVisible(true); |
|
110 | m_chart->legend()->setVisible(true); | |
90 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
111 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
91 | break; |
|
112 | break; | |
92 | case LegendLeft: |
|
113 | case LegendLeft: | |
93 | m_chart->legend()->setVisible(true); |
|
114 | m_chart->legend()->setVisible(true); | |
94 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); |
|
115 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); | |
95 | break; |
|
116 | break; | |
96 | case LegendRight: |
|
117 | case LegendRight: | |
97 | m_chart->legend()->setVisible(true); |
|
118 | m_chart->legend()->setVisible(true); | |
98 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); |
|
119 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); | |
99 | break; |
|
120 | break; | |
100 | default: |
|
121 | default: | |
101 | m_chart->legend()->setVisible(false); |
|
122 | m_chart->legend()->setVisible(false); | |
102 | break; |
|
123 | break; | |
103 | } |
|
124 | } | |
104 | } |
|
125 | } | |
105 | } |
|
126 | } | |
106 |
|
127 | |||
107 | DeclarativeChart::ChartLegend DeclarativeChart::legend() |
|
128 | DeclarativeChart::ChartLegend DeclarativeChart::legend() | |
108 | { |
|
129 | { | |
109 | return m_legend; |
|
130 | return m_legend; | |
110 | } |
|
131 | } | |
111 |
|
132 | |||
112 | #include "moc_declarativechart.cpp" |
|
133 | #include "moc_declarativechart.cpp" | |
113 |
|
134 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
135 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,80 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVECHART_H |
|
21 | #ifndef DECLARATIVECHART_H | |
22 | #define DECLARATIVECHART_H |
|
22 | #define DECLARATIVECHART_H | |
23 |
|
23 | |||
24 | #include <QtCore/QtGlobal> |
|
24 | #include <QtCore/QtGlobal> | |
25 | #include <QDeclarativeItem> |
|
25 | #include <QDeclarativeItem> | |
26 | #include <qchart.h> |
|
26 | #include <qchart.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | // TODO: Derive from QChart for easier definition of properties? |
|
30 | // TODO: Derive from QChart for easier definition of properties? | |
31 | class DeclarativeChart : public QDeclarativeItem |
|
31 | class DeclarativeChart : public QDeclarativeItem | |
32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead | |
33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
36 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) | |
37 | Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions) |
|
37 | Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions) | |
38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
38 | Q_PROPERTY(QString title READ title WRITE setTitle) | |
39 | Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend) |
|
39 | Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend) | |
40 | Q_ENUMS(ChartLegend) |
|
40 | Q_ENUMS(ChartLegend) | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | enum ChartLegend { |
|
43 | enum ChartLegend { | |
44 | LegendDisabled = 0, |
|
44 | LegendDisabled = 0, | |
45 | LegendTop, |
|
45 | LegendTop, | |
46 | LegendBottom, |
|
46 | LegendBottom, | |
47 | LegendLeft, |
|
47 | LegendLeft, | |
48 | LegendRight |
|
48 | LegendRight | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | public: |
|
51 | public: | |
52 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
52 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
53 | ~DeclarativeChart(); |
|
53 | ~DeclarativeChart(); | |
54 |
|
54 | |||
55 | public: // From QDeclarativeItem/QGraphicsItem |
|
55 | public: // From QDeclarativeItem/QGraphicsItem | |
|
56 | void childEvent(QChildEvent *event); | |||
|
57 | void componentComplete(); | |||
56 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
58 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
57 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
59 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
58 |
|
60 | |||
59 | public: |
|
61 | public: | |
60 | void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);} |
|
62 | void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);} | |
61 | QChart::ChartTheme theme() {return m_chart->theme();} |
|
63 | QChart::ChartTheme theme() {return m_chart->theme();} | |
62 | void setAnimationOptions(QChart::AnimationOption animations); |
|
64 | void setAnimationOptions(QChart::AnimationOption animations); | |
63 | QChart::AnimationOption animationOptions(); |
|
65 | QChart::AnimationOption animationOptions(); | |
64 | void setTitle(QString title) {m_chart->setTitle(title);} |
|
66 | void setTitle(QString title) {m_chart->setTitle(title);} | |
65 | QString title() { return m_chart->title();} |
|
67 | QString title() { return m_chart->title();} | |
66 | void setLegend(ChartLegend legend); |
|
68 | void setLegend(ChartLegend legend); | |
67 | ChartLegend legend(); |
|
69 | ChartLegend legend(); | |
68 |
|
70 | |||
69 | public: |
|
71 | public: | |
70 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
72 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
71 | // multi inheritance, so we now have a QChart as a member instead |
|
73 | // multi inheritance, so we now have a QChart as a member instead | |
72 | QChart *m_chart; |
|
74 | QChart *m_chart; | |
73 | ChartLegend m_legend; |
|
75 | ChartLegend m_legend; | |
74 | }; |
|
76 | }; | |
75 |
|
77 | |||
76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
77 |
|
79 | |||
78 | #endif // DECLARATIVECHART_H |
|
80 | #endif // DECLARATIVECHART_H |
@@ -1,45 +1,40 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativelineseries.h" |
|
21 | #include "declarativelineseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : |
|
28 | DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : | |
29 | QLineSeries(parent) |
|
29 | QLineSeries(parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QAbstractSeries *DeclarativeLineSeries::series() |
|
|||
34 | { |
|
|||
35 | return this; |
|
|||
36 | } |
|
|||
37 |
|
||||
38 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points() |
|
33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points() | |
39 | { |
|
34 | { | |
40 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); | |
41 | } |
|
36 | } | |
42 |
|
37 | |||
43 | #include "moc_declarativelineseries.cpp" |
|
38 | #include "moc_declarativelineseries.cpp" | |
44 |
|
39 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVELINESERIES_H |
|
21 | #ifndef DECLARATIVELINESERIES_H | |
22 | #define DECLARATIVELINESERIES_H |
|
22 | #define DECLARATIVELINESERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qlineseries.h" |
|
25 | #include "qlineseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries |
|
31 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeLineSeries(QObject *parent = 0); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QAbstractSeries *series(); |
|
|||
41 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); | |
42 | }; |
|
41 | }; | |
43 |
|
42 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
44 | |||
46 | #endif // DECLARATIVELINESERIES_H |
|
45 | #endif // DECLARATIVELINESERIES_H |
@@ -1,62 +1,47 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativepieseries.h" |
|
21 | #include "declarativepieseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
27 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | |
28 |
QPieSeries(parent) |
|
28 | QPieSeries(parent) | |
29 | m_chart(0) |
|
|||
30 | { |
|
29 | { | |
31 | } |
|
30 | } | |
32 |
|
31 | |||
33 | void DeclarativePieSeries::classBegin() |
|
|||
34 | { |
|
|||
35 | } |
|
|||
36 |
|
||||
37 | void DeclarativePieSeries::componentComplete() |
|
|||
38 | { |
|
|||
39 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
|||
40 | if (declarativeChart) { |
|
|||
41 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
|||
42 | Q_ASSERT(chart); |
|
|||
43 | chart->addSeries(this); |
|
|||
44 | } |
|
|||
45 | } |
|
|||
46 |
|
||||
47 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices() |
|
32 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices() | |
48 | { |
|
33 | { | |
49 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice); |
|
34 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice); | |
50 | } |
|
35 | } | |
51 |
|
36 | |||
52 | void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list, |
|
37 | void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list, | |
53 | QPieSlice *slice) |
|
38 | QPieSlice *slice) | |
54 | { |
|
39 | { | |
55 | DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object); |
|
40 | DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object); | |
56 | if (series) |
|
41 | if (series) | |
57 | series->append(slice->value(), slice->label()); |
|
42 | series->append(slice->value(), slice->label()); | |
58 | } |
|
43 | } | |
59 |
|
44 | |||
60 | #include "moc_declarativepieseries.cpp" |
|
45 | #include "moc_declarativepieseries.cpp" | |
61 |
|
46 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,49 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVEPIESERIES_H |
|
21 | #ifndef DECLARATIVEPIESERIES_H | |
22 | #define DECLARATIVEPIESERIES_H |
|
22 | #define DECLARATIVEPIESERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qpieslice.h" |
|
25 | #include "qpieslice.h" | |
26 | #include "qpieseries.h" |
|
26 | #include "qpieseries.h" | |
27 |
#include <QDeclarative |
|
27 | #include <QDeclarativeListProperty> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QChart; |
|
31 | class QChart; | |
32 |
|
32 | |||
33 |
class DeclarativePieSeries : public QPieSeries |
|
33 | class DeclarativePieSeries : public QPieSeries | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_INTERFACES(QDeclarativeParserStatus) |
|
|||
37 | Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices) |
|
36 | Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices) | |
38 |
|
37 | |||
39 | public: |
|
38 | public: | |
40 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
39 | explicit DeclarativePieSeries(QObject *parent = 0); | |
41 | QDeclarativeListProperty<QPieSlice> slices(); |
|
40 | QDeclarativeListProperty<QPieSlice> slices(); | |
42 |
|
41 | |||
43 | public: // from QDeclarativeParserStatus |
|
|||
44 | void classBegin(); |
|
|||
45 | void componentComplete(); |
|
|||
46 |
|
||||
47 | public Q_SLOTS: |
|
42 | public Q_SLOTS: | |
48 | static void appendSlice(QDeclarativeListProperty<QPieSlice> *list, |
|
43 | static void appendSlice(QDeclarativeListProperty<QPieSlice> *list, | |
49 | QPieSlice *element); |
|
44 | QPieSlice *element); | |
50 |
|
||||
51 | private: |
|
|||
52 | QChart *m_chart; |
|
|||
53 | }; |
|
45 | }; | |
54 |
|
46 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
48 | |||
57 | #endif // DECLARATIVEPIESERIES_H |
|
49 | #endif // DECLARATIVEPIESERIES_H |
@@ -1,45 +1,40 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativescatterseries.h" |
|
21 | #include "declarativescatterseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qscatterseries.h" |
|
24 | #include "qscatterseries.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : |
|
28 | DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : | |
29 | QScatterSeries(parent) |
|
29 | QScatterSeries(parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QAbstractSeries *DeclarativeScatterSeries::series() |
|
|||
34 | { |
|
|||
35 | return this; |
|
|||
36 | } |
|
|||
37 |
|
||||
38 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() |
|
33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() | |
39 | { |
|
34 | { | |
40 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); | |
41 | } |
|
36 | } | |
42 |
|
37 | |||
43 | #include "moc_declarativescatterseries.cpp" |
|
38 | #include "moc_declarativescatterseries.cpp" | |
44 |
|
39 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVESCATTERSERIES_H |
|
21 | #ifndef DECLARATIVESCATTERSERIES_H | |
22 | #define DECLARATIVESCATTERSERIES_H |
|
22 | #define DECLARATIVESCATTERSERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries |
|
31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeScatterSeries(QObject *parent = 0); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QAbstractSeries *series(); |
|
|||
41 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); | |
42 | }; |
|
41 | }; | |
43 |
|
42 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
44 | |||
46 | #endif // DECLARATIVESCATTERSERIES_H |
|
45 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -1,44 +1,39 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativesplineseries.h" |
|
21 | #include "declarativesplineseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : |
|
27 | DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : | |
28 | QSplineSeries(parent) |
|
28 | QSplineSeries(parent) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QAbstractSeries *DeclarativeSplineSeries::series() |
|
|||
33 | { |
|
|||
34 | return this; |
|
|||
35 | } |
|
|||
36 |
|
||||
37 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points() |
|
32 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points() | |
38 | { |
|
33 | { | |
39 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
34 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); | |
40 | } |
|
35 | } | |
41 |
|
36 | |||
42 | #include "moc_declarativesplineseries.cpp" |
|
37 | #include "moc_declarativesplineseries.cpp" | |
43 |
|
38 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVESPLINESERIES_H |
|
21 | #ifndef DECLARATIVESPLINESERIES_H | |
22 | #define DECLARATIVESPLINESERIES_H |
|
22 | #define DECLARATIVESPLINESERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qsplineseries.h" |
|
25 | #include "qsplineseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries |
|
31 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
37 | explicit DeclarativeSplineSeries(QObject *parent = 0); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QAbstractSeries *series(); |
|
|||
41 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); | |
42 | }; |
|
41 | }; | |
43 |
|
42 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
44 | |||
46 | #endif // DECLARATIVESPLINESERIES_H |
|
45 | #endif // DECLARATIVESPLINESERIES_H |
@@ -1,60 +1,44 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | //#include "DeclarativeXySeries.h" |
|
21 | //#include "DeclarativeXySeries.h" | |
22 | #include "declarativexyseries.h" |
|
22 | #include "declarativexyseries.h" | |
23 | #include "qxyseries.h" |
|
23 | #include "qxyseries.h" | |
24 | #include "declarativechart.h" |
|
24 | #include "declarativechart.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | DeclarativeXySeries::DeclarativeXySeries() |
|
28 | DeclarativeXySeries::DeclarativeXySeries() | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | DeclarativeXySeries::~DeclarativeXySeries() |
|
32 | DeclarativeXySeries::~DeclarativeXySeries() | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void DeclarativeXySeries::classBegin() |
|
|||
37 | { |
|
|||
38 | } |
|
|||
39 |
|
||||
40 | void DeclarativeXySeries::componentComplete() |
|
|||
41 | { |
|
|||
42 | QAbstractSeries *thisObj = reinterpret_cast<QAbstractSeries *>(series()); |
|
|||
43 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent()); |
|
|||
44 |
|
||||
45 | if (declarativeChart) { |
|
|||
46 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
|||
47 | Q_ASSERT(chart); |
|
|||
48 | chart->addSeries(thisObj); |
|
|||
49 | } |
|
|||
50 | } |
|
|||
51 |
|
||||
52 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
36 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
53 | DeclarativeXyPoint *element) |
|
37 | DeclarativeXyPoint *element) | |
54 | { |
|
38 | { | |
55 | QXYSeries *series = qobject_cast<QXYSeries *>(list->object); |
|
39 | QXYSeries *series = qobject_cast<QXYSeries *>(list->object); | |
56 | if (series) |
|
40 | if (series) | |
57 | series->append(element->x(), element->y()); |
|
41 | series->append(element->x(), element->y()); | |
58 | } |
|
42 | } | |
59 |
|
43 | |||
60 | QTCOMMERCIALCHART_END_NAMESPACE |
|
44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,51 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVE_XY_SERIES_H |
|
21 | #ifndef DECLARATIVE_XY_SERIES_H | |
22 | #define DECLARATIVE_XY_SERIES_H |
|
22 | #define DECLARATIVE_XY_SERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "declarativexypoint.h" |
|
25 | #include "declarativexypoint.h" | |
26 | #include <QDeclarativeParserStatus> |
|
|||
27 | #include <QDeclarativeListProperty> |
|
26 | #include <QDeclarativeListProperty> | |
28 |
|
27 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
29 | |||
31 | class QChart; |
|
30 | class QChart; | |
32 | class QAbstractSeries; |
|
31 | class QAbstractSeries; | |
33 |
|
32 | |||
34 | class DeclarativeXySeries : public QDeclarativeParserStatus |
|
33 | class DeclarativeXySeries | |
35 | { |
|
34 | { | |
36 | Q_INTERFACES(QDeclarativeParserStatus) |
|
35 | Q_INTERFACES(QDeclarativeParserStatus) | |
37 |
|
36 | |||
38 | public: |
|
37 | public: | |
39 | explicit DeclarativeXySeries(); |
|
38 | explicit DeclarativeXySeries(); | |
40 | ~DeclarativeXySeries(); |
|
39 | ~DeclarativeXySeries(); | |
41 |
|
40 | |||
42 | public: // from QDeclarativeParserStatus |
|
|||
43 | virtual void classBegin(); |
|
|||
44 | virtual void componentComplete(); |
|
|||
45 |
|
||||
46 | public: |
|
41 | public: | |
47 | virtual QAbstractSeries *series() = 0; |
|
|||
48 | virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0; |
|
42 | virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0; | |
49 |
|
43 | |||
50 | public Q_SLOTS: |
|
44 | public Q_SLOTS: | |
51 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
45 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
52 | DeclarativeXyPoint *element); |
|
46 | DeclarativeXyPoint *element); | |
53 | }; |
|
47 | }; | |
54 |
|
48 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
50 | |||
57 | #endif // DECLARATIVE_XY_SERIES_H |
|
51 | #endif // DECLARATIVE_XY_SERIES_H |
@@ -1,665 +1,704 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | #include <QAbstractItemModel> |
|
31 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
32 | #include <QModelIndex> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QBarSeries |
|
37 | \class QBarSeries | |
38 | \brief part of QtCommercial chart API. |
|
38 | \brief part of QtCommercial chart API. | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple | |
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
43 | by QStringList. |
|
43 | by QStringList. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) | |
53 |
|
53 | |||
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category | |
55 | contained by the series. |
|
55 | contained by the series. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
60 |
|
60 | |||
61 | The signal is emitted if mouse is hovered on top of series. |
|
61 | The signal is emitted if mouse is hovered on top of series. | |
62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
62 | Parameter \a barset is the pointer of barset, where hover happened. | |
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
68 | QBarSeries is QObject which is a child of a \a parent. |
|
68 | QBarSeries is QObject which is a child of a \a parent. | |
69 | */ |
|
69 | */ | |
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : |
|
70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : | |
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | Destructs barseries and owned barsets. |
|
76 | Destructs barseries and owned barsets. | |
77 | */ |
|
77 | */ | |
78 | QBarSeries::~QBarSeries() |
|
78 | QBarSeries::~QBarSeries() | |
79 | { |
|
79 | { | |
80 | // NOTE: d_ptr destroyed by QObject |
|
80 | // NOTE: d_ptr destroyed by QObject | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \internal |
|
84 | \internal | |
85 | */ |
|
85 | */ | |
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
87 | QAbstractSeries(d,parent) |
|
87 | QAbstractSeries(d,parent) | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Returns the type of series. Derived classes override this. |
|
92 | Returns the type of series. Derived classes override this. | |
93 | */ |
|
93 | */ | |
94 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
94 | QAbstractSeries::SeriesType QBarSeries::type() const | |
95 | { |
|
95 | { | |
96 | return QAbstractSeries::SeriesTypeBar; |
|
96 | return QAbstractSeries::SeriesTypeBar; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
|
99 | void QBarSeries::setCategories(QBarCategories categories) | |||
|
100 | { | |||
|
101 | Q_D(QBarSeries); | |||
|
102 | d->setCategories(categories); | |||
|
103 | emit d->categoriesUpdated(); | |||
|
104 | } | |||
|
105 | ||||
99 | /*! |
|
106 | /*! | |
100 | Adds a set of bars to series. Takes ownership of \a set. |
|
107 | Adds a set of bars to series. Takes ownership of \a set. | |
101 | */ |
|
108 | */ | |
102 |
|
|
109 | bool QBarSeries::appendBarSet(QBarSet *set) | |
103 | { |
|
110 | { | |
104 | Q_D(QBarSeries); |
|
111 | Q_D(QBarSeries); | |
|
112 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |||
|
113 | // Fail if set is already in list or set is null. | |||
|
114 | return false; | |||
|
115 | } | |||
105 | d->m_barSets.append(set); |
|
116 | d->m_barSets.append(set); | |
106 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
107 | emit d->restructuredBars(); |
|
118 | emit d->restructuredBars(); | |
|
119 | return true; | |||
108 | } |
|
120 | } | |
109 |
|
121 | |||
110 | /*! |
|
122 | /*! | |
111 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
112 | */ |
|
124 | */ | |
113 |
|
|
125 | bool QBarSeries::removeBarSet(QBarSet *set) | |
114 | { |
|
126 | { | |
115 | Q_D(QBarSeries); |
|
127 | Q_D(QBarSeries); | |
116 | if (d->m_barSets.contains(set)) { |
|
128 | if (!d->m_barSets.contains(set)) { | |
117 | d->m_barSets.removeOne(set); |
|
129 | // Fail if set is not in list | |
118 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
130 | return false; | |
119 | emit d->restructuredBars(); |
|
|||
120 | } |
|
131 | } | |
|
132 | d->m_barSets.removeOne(set); | |||
|
133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |||
|
134 | emit d->restructuredBars(); | |||
|
135 | return true; | |||
121 | } |
|
136 | } | |
122 |
|
137 | |||
123 | /*! |
|
138 | /*! | |
124 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
139 | Adds a list of barsets to series. Takes ownership of \a sets. | |
125 | */ |
|
140 | */ | |
126 |
|
|
141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
127 | { |
|
142 | { | |
128 | Q_D(QBarSeries); |
|
143 | Q_D(QBarSeries); | |
129 | foreach (QBarSet* set, sets) { |
|
144 | foreach (QBarSet* set, sets) { | |
|
145 | if ((set == 0) || (d->m_barSets.contains(set))) { | |||
|
146 | // Fail if any of the sets is null or is already appended. | |||
|
147 | return false; | |||
|
148 | } | |||
|
149 | if (sets.count(set) != 1) { | |||
|
150 | // Also fail if same set is more than once in given list. | |||
|
151 | return false; | |||
|
152 | } | |||
|
153 | } | |||
|
154 | ||||
|
155 | foreach (QBarSet* set, sets) { | |||
130 | d->m_barSets.append(set); |
|
156 | d->m_barSets.append(set); | |
131 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
132 | } |
|
158 | } | |
133 | emit d->restructuredBars(); |
|
159 | emit d->restructuredBars(); | |
|
160 | return true; | |||
134 | } |
|
161 | } | |
135 |
|
162 | |||
136 | /*! |
|
163 | /*! | |
137 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
138 | */ |
|
165 | */ | |
139 |
|
|
166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
140 | { |
|
167 | { | |
141 | Q_D(QBarSeries); |
|
168 | Q_D(QBarSeries); | |
142 |
|
169 | |||
|
170 | bool setsRemoved = false; | |||
143 | foreach (QBarSet* set, sets) { |
|
171 | foreach (QBarSet* set, sets) { | |
144 | if (d->m_barSets.contains(set)) { |
|
172 | if (d->m_barSets.contains(set)) { | |
145 | d->m_barSets.removeOne(set); |
|
173 | d->m_barSets.removeOne(set); | |
146 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
|
175 | setsRemoved = true; | |||
147 | } |
|
176 | } | |
148 | } |
|
177 | } | |
149 | emit d->restructuredBars(); |
|
178 | ||
|
179 | if (setsRemoved) { | |||
|
180 | emit d->restructuredBars(); | |||
|
181 | } | |||
|
182 | return setsRemoved; | |||
150 | } |
|
183 | } | |
151 |
|
184 | |||
152 | /*! |
|
185 | /*! | |
153 | Returns number of sets in series. |
|
186 | Returns number of sets in series. | |
154 | */ |
|
187 | */ | |
155 | int QBarSeries::barsetCount() const |
|
188 | int QBarSeries::barsetCount() const | |
156 | { |
|
189 | { | |
157 | Q_D(const QBarSeries); |
|
190 | Q_D(const QBarSeries); | |
158 | return d->m_barSets.count(); |
|
191 | return d->m_barSets.count(); | |
159 | } |
|
192 | } | |
160 |
|
193 | |||
161 | /*! |
|
194 | /*! | |
162 | Returns number of categories in series |
|
195 | Returns number of categories in series | |
163 | */ |
|
196 | */ | |
164 | int QBarSeries::categoryCount() const |
|
197 | int QBarSeries::categoryCount() const | |
165 | { |
|
198 | { | |
166 | Q_D(const QBarSeries); |
|
199 | Q_D(const QBarSeries); | |
167 | return d->m_categories.count(); |
|
200 | return d->m_categories.count(); | |
168 | } |
|
201 | } | |
169 |
|
202 | |||
170 | /*! |
|
203 | /*! | |
171 | Returns a list of sets in series. Keeps ownership of sets. |
|
204 | Returns a list of sets in series. Keeps ownership of sets. | |
172 | */ |
|
205 | */ | |
173 | QList<QBarSet*> QBarSeries::barSets() const |
|
206 | QList<QBarSet*> QBarSeries::barSets() const | |
174 | { |
|
207 | { | |
175 | Q_D(const QBarSeries); |
|
208 | Q_D(const QBarSeries); | |
176 | return d->m_barSets; |
|
209 | return d->m_barSets; | |
177 | } |
|
210 | } | |
178 |
|
211 | |||
179 | /*! |
|
212 | /*! | |
180 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
213 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
181 | Sets the \a model to be used as a data source |
|
214 | Sets the \a model to be used as a data source | |
182 | */ |
|
215 | */ | |
183 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
216 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
184 | { |
|
217 | { | |
185 | Q_D(QBarSeries); |
|
218 | Q_D(QBarSeries); | |
186 | return d->setModel(model); |
|
219 | return d->setModel(model); | |
187 | } |
|
220 | } | |
188 |
|
221 | |||
189 | /*! |
|
222 | /*! | |
190 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
223 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
191 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
224 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
192 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
225 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
193 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
226 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
194 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
227 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
195 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
228 | The \a orientation parameter specifies whether the data is in columns or in rows. | |
196 | */ |
|
229 | */ | |
197 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
230 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
198 | { |
|
231 | { | |
199 | Q_D(QBarSeries); |
|
232 | Q_D(QBarSeries); | |
200 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
233 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
201 | } |
|
234 | } | |
202 |
|
235 | |||
203 | void QBarSeries::setModelMappingRange(int first, int count) |
|
236 | void QBarSeries::setModelMappingRange(int first, int count) | |
204 | { |
|
237 | { | |
205 | Q_D(QBarSeries); |
|
238 | Q_D(QBarSeries); | |
206 | d->setModelMappingRange(first, count); |
|
239 | d->setModelMappingRange(first, count); | |
207 | } |
|
240 | } | |
208 |
|
241 | |||
209 | /*! |
|
242 | /*! | |
210 | Returns the bar categories of the series. |
|
243 | Returns the bar categories of the series. | |
211 | */ |
|
244 | */ | |
212 | QBarCategories QBarSeries::categories() const |
|
245 | QBarCategories QBarSeries::categories() const | |
213 | { |
|
246 | { | |
214 | Q_D(const QBarSeries); |
|
247 | Q_D(const QBarSeries); | |
215 | return d->m_categories; |
|
248 | return d->m_categories; | |
216 | } |
|
249 | } | |
217 |
|
250 | |||
218 | /*! |
|
251 | /*! | |
219 | Sets the visibility of labels in series to \a visible |
|
252 | Sets the visibility of labels in series to \a visible | |
220 | */ |
|
253 | */ | |
221 | void QBarSeries::setLabelsVisible(bool visible) |
|
254 | void QBarSeries::setLabelsVisible(bool visible) | |
222 | { |
|
255 | { | |
223 | foreach (QBarSet* s, barSets()) { |
|
256 | foreach (QBarSet* s, barSets()) { | |
224 | s->setLabelsVisible(visible); |
|
257 | s->setLabelsVisible(visible); | |
225 | } |
|
258 | } | |
226 | } |
|
259 | } | |
227 |
|
260 | |||
228 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
229 |
|
262 | |||
230 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : |
|
263 | QBarSeriesPrivate::QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *q) : | |
231 | QAbstractSeriesPrivate(q), |
|
264 | QAbstractSeriesPrivate(q), | |
232 | m_categories(categories), |
|
265 | // m_categories(categories), | |
233 | m_mapCategories(-1), |
|
266 | m_mapCategories(-1), | |
234 | m_mapBarBottom(-1), |
|
267 | m_mapBarBottom(-1), | |
235 | m_mapBarTop(-1) |
|
268 | m_mapBarTop(-1) | |
236 | { |
|
269 | { | |
237 | } |
|
270 | } | |
238 |
|
271 | |||
|
272 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |||
|
273 | { | |||
|
274 | m_categories = categories; | |||
|
275 | } | |||
|
276 | ||||
|
277 | ||||
239 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
278 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
240 | { |
|
279 | { | |
241 | return m_barSets.at(index); |
|
280 | return m_barSets.at(index); | |
242 | } |
|
281 | } | |
243 |
|
282 | |||
244 | QString QBarSeriesPrivate::categoryName(int category) |
|
283 | QString QBarSeriesPrivate::categoryName(int category) | |
245 | { |
|
284 | { | |
246 | return m_categories.at(category); |
|
285 | return m_categories.at(category); | |
247 | } |
|
286 | } | |
248 |
|
287 | |||
249 | qreal QBarSeriesPrivate::min() |
|
288 | qreal QBarSeriesPrivate::min() | |
250 | { |
|
289 | { | |
251 | if (m_barSets.count() <= 0) { |
|
290 | if (m_barSets.count() <= 0) { | |
252 | return 0; |
|
291 | return 0; | |
253 | } |
|
292 | } | |
254 | qreal min = INT_MAX; |
|
293 | qreal min = INT_MAX; | |
255 |
|
294 | |||
256 | for (int i = 0; i < m_barSets.count(); i++) { |
|
295 | for (int i = 0; i < m_barSets.count(); i++) { | |
257 | int categoryCount = m_barSets.at(i)->count(); |
|
296 | int categoryCount = m_barSets.at(i)->count(); | |
258 | for (int j = 0; j < categoryCount; j++) { |
|
297 | for (int j = 0; j < categoryCount; j++) { | |
259 | qreal temp = m_barSets.at(i)->at(j); |
|
298 | qreal temp = m_barSets.at(i)->at(j); | |
260 | if (temp < min) |
|
299 | if (temp < min) | |
261 | min = temp; |
|
300 | min = temp; | |
262 | } |
|
301 | } | |
263 | } |
|
302 | } | |
264 | return min; |
|
303 | return min; | |
265 | } |
|
304 | } | |
266 |
|
305 | |||
267 | qreal QBarSeriesPrivate::max() |
|
306 | qreal QBarSeriesPrivate::max() | |
268 | { |
|
307 | { | |
269 | if (m_barSets.count() <= 0) { |
|
308 | if (m_barSets.count() <= 0) { | |
270 | return 0; |
|
309 | return 0; | |
271 | } |
|
310 | } | |
272 | qreal max = INT_MIN; |
|
311 | qreal max = INT_MIN; | |
273 |
|
312 | |||
274 | for (int i = 0; i < m_barSets.count(); i++) { |
|
313 | for (int i = 0; i < m_barSets.count(); i++) { | |
275 | int categoryCount = m_barSets.at(i)->count(); |
|
314 | int categoryCount = m_barSets.at(i)->count(); | |
276 | for (int j = 0; j < categoryCount; j++) { |
|
315 | for (int j = 0; j < categoryCount; j++) { | |
277 | qreal temp = m_barSets.at(i)->at(j); |
|
316 | qreal temp = m_barSets.at(i)->at(j); | |
278 | if (temp > max) |
|
317 | if (temp > max) | |
279 | max = temp; |
|
318 | max = temp; | |
280 | } |
|
319 | } | |
281 | } |
|
320 | } | |
282 |
|
321 | |||
283 | return max; |
|
322 | return max; | |
284 | } |
|
323 | } | |
285 |
|
324 | |||
286 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
325 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
287 | { |
|
326 | { | |
288 | if ((set < 0) || (set >= m_barSets.count())) { |
|
327 | if ((set < 0) || (set >= m_barSets.count())) { | |
289 | // No set, no value. |
|
328 | // No set, no value. | |
290 | return 0; |
|
329 | return 0; | |
291 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
330 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
292 | // No category, no value. |
|
331 | // No category, no value. | |
293 | return 0; |
|
332 | return 0; | |
294 | } |
|
333 | } | |
295 |
|
334 | |||
296 | return m_barSets.at(set)->at(category); |
|
335 | return m_barSets.at(set)->at(category); | |
297 | } |
|
336 | } | |
298 |
|
337 | |||
299 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
338 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
300 | { |
|
339 | { | |
301 | if ((set < 0) || (set >= m_barSets.count())) { |
|
340 | if ((set < 0) || (set >= m_barSets.count())) { | |
302 | // No set, no value. |
|
341 | // No set, no value. | |
303 | return 0; |
|
342 | return 0; | |
304 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
343 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
305 | // No category, no value. |
|
344 | // No category, no value. | |
306 | return 0; |
|
345 | return 0; | |
307 | } |
|
346 | } | |
308 |
|
347 | |||
309 | qreal value = m_barSets.at(set)->at(category); |
|
348 | qreal value = m_barSets.at(set)->at(category); | |
310 | qreal sum = categorySum(category); |
|
349 | qreal sum = categorySum(category); | |
311 | if ( qFuzzyIsNull(sum) ) { |
|
350 | if ( qFuzzyIsNull(sum) ) { | |
312 | return 0; |
|
351 | return 0; | |
313 | } |
|
352 | } | |
314 |
|
353 | |||
315 | return value / sum; |
|
354 | return value / sum; | |
316 | } |
|
355 | } | |
317 |
|
356 | |||
318 | qreal QBarSeriesPrivate::categorySum(int category) |
|
357 | qreal QBarSeriesPrivate::categorySum(int category) | |
319 | { |
|
358 | { | |
320 | qreal sum(0); |
|
359 | qreal sum(0); | |
321 | int count = m_barSets.count(); // Count sets |
|
360 | int count = m_barSets.count(); // Count sets | |
322 | for (int set = 0; set < count; set++) { |
|
361 | for (int set = 0; set < count; set++) { | |
323 | if (category < m_barSets.at(set)->count()) |
|
362 | if (category < m_barSets.at(set)->count()) | |
324 | sum += m_barSets.at(set)->at(category); |
|
363 | sum += m_barSets.at(set)->at(category); | |
325 | } |
|
364 | } | |
326 | return sum; |
|
365 | return sum; | |
327 | } |
|
366 | } | |
328 |
|
367 | |||
329 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
368 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
330 | { |
|
369 | { | |
331 | qreal sum(0); |
|
370 | qreal sum(0); | |
332 | int count = m_barSets.count(); // Count sets |
|
371 | int count = m_barSets.count(); // Count sets | |
333 | for (int set = 0; set < count; set++) { |
|
372 | for (int set = 0; set < count; set++) { | |
334 | if (category < m_barSets.at(set)->count()) |
|
373 | if (category < m_barSets.at(set)->count()) | |
335 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
374 | sum += qAbs(m_barSets.at(set)->at(category)); | |
336 | } |
|
375 | } | |
337 | return sum; |
|
376 | return sum; | |
338 | } |
|
377 | } | |
339 |
|
378 | |||
340 | qreal QBarSeriesPrivate::maxCategorySum() |
|
379 | qreal QBarSeriesPrivate::maxCategorySum() | |
341 | { |
|
380 | { | |
342 | qreal max = INT_MIN; |
|
381 | qreal max = INT_MIN; | |
343 | int count = m_categories.count(); |
|
382 | int count = m_categories.count(); | |
344 | for (int i = 0; i < count; i++) { |
|
383 | for (int i = 0; i < count; i++) { | |
345 | qreal sum = categorySum(i); |
|
384 | qreal sum = categorySum(i); | |
346 | if (sum > max) |
|
385 | if (sum > max) | |
347 | max = sum; |
|
386 | max = sum; | |
348 | } |
|
387 | } | |
349 | return max; |
|
388 | return max; | |
350 | } |
|
389 | } | |
351 |
|
390 | |||
352 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
391 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
353 | { |
|
392 | { | |
354 | // disconnect signals from old model |
|
393 | // disconnect signals from old model | |
355 | if(m_model) |
|
394 | if(m_model) | |
356 | { |
|
395 | { | |
357 | disconnect(m_model, 0, this, 0); |
|
396 | disconnect(m_model, 0, this, 0); | |
358 | m_mapCategories = -1; |
|
397 | m_mapCategories = -1; | |
359 | m_mapBarBottom = -1; |
|
398 | m_mapBarBottom = -1; | |
360 | m_mapBarTop = -1; |
|
399 | m_mapBarTop = -1; | |
361 | m_mapOrientation = Qt::Vertical; |
|
400 | m_mapOrientation = Qt::Vertical; | |
362 | } |
|
401 | } | |
363 |
|
402 | |||
364 | // set new model |
|
403 | // set new model | |
365 | if(model) |
|
404 | if(model) | |
366 | { |
|
405 | { | |
367 | m_model = model; |
|
406 | m_model = model; | |
368 | return true; |
|
407 | return true; | |
369 | } |
|
408 | } | |
370 | else |
|
409 | else | |
371 | { |
|
410 | { | |
372 | m_model = 0; |
|
411 | m_model = 0; | |
373 | return false; |
|
412 | return false; | |
374 | } |
|
413 | } | |
375 | } |
|
414 | } | |
376 |
|
415 | |||
377 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
416 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
378 | { |
|
417 | { | |
379 | Q_Q(QBarSeries); |
|
418 | Q_Q(QBarSeries); | |
380 |
|
419 | |||
381 | if (m_model == 0) |
|
420 | if (m_model == 0) | |
382 | return; |
|
421 | return; | |
383 |
|
422 | |||
384 | m_mapCategories = categories; |
|
423 | m_mapCategories = categories; | |
385 | m_mapBarBottom = bottomBoundry; |
|
424 | m_mapBarBottom = bottomBoundry; | |
386 | m_mapBarTop = topBoundry; |
|
425 | m_mapBarTop = topBoundry; | |
387 | m_mapOrientation = orientation; |
|
426 | m_mapOrientation = orientation; | |
388 |
|
427 | |||
389 | // connect the signals |
|
428 | // connect the signals | |
390 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
429 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
391 | if (m_mapOrientation == Qt::Vertical) { |
|
430 | if (m_mapOrientation == Qt::Vertical) { | |
392 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
431 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
393 | connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
432 | connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
394 | } else { |
|
433 | } else { | |
395 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
434 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
396 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
435 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
397 | } |
|
436 | } | |
398 |
|
437 | |||
399 | // create the initial bars |
|
438 | // create the initial bars | |
400 | m_categories.clear(); |
|
439 | m_categories.clear(); | |
401 | if (m_mapOrientation == Qt::Vertical) { |
|
440 | if (m_mapOrientation == Qt::Vertical) { | |
402 | int rowCount = 0; |
|
441 | int rowCount = 0; | |
403 | if(m_mapCount == -1) |
|
442 | if(m_mapCount == -1) | |
404 | rowCount = m_model->rowCount() - m_mapFirst; |
|
443 | rowCount = m_model->rowCount() - m_mapFirst; | |
405 | else |
|
444 | else | |
406 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
445 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
407 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
446 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
408 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
447 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
409 | } |
|
448 | } | |
410 |
|
449 | |||
411 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
450 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
412 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
451 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
413 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
452 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
414 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
453 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
415 | q->appendBarSet(barSet); |
|
454 | q->appendBarSet(barSet); | |
416 | } |
|
455 | } | |
417 | } else { |
|
456 | } else { | |
418 | int columnCount = 0; |
|
457 | int columnCount = 0; | |
419 | if(m_mapCount == -1) |
|
458 | if(m_mapCount == -1) | |
420 | columnCount = m_model->columnCount() - m_mapFirst; |
|
459 | columnCount = m_model->columnCount() - m_mapFirst; | |
421 | else |
|
460 | else | |
422 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
461 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
423 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
462 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
424 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
463 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
425 | } |
|
464 | } | |
426 |
|
465 | |||
427 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
466 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
428 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
467 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
429 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
468 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
430 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
469 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
431 | q->appendBarSet(barSet); |
|
470 | q->appendBarSet(barSet); | |
432 | } |
|
471 | } | |
433 | } |
|
472 | } | |
434 | } |
|
473 | } | |
435 |
|
474 | |||
436 | void QBarSeriesPrivate::setModelMappingRange(int first, int count) |
|
475 | void QBarSeriesPrivate::setModelMappingRange(int first, int count) | |
437 | { |
|
476 | { | |
438 | m_mapFirst = first; |
|
477 | m_mapFirst = first; | |
439 | m_mapCount = count; |
|
478 | m_mapCount = count; | |
440 | } |
|
479 | } | |
441 |
|
480 | |||
442 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
481 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
443 | { |
|
482 | { | |
444 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
483 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
445 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
484 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
446 | if (m_mapOrientation == Qt::Vertical) |
|
485 | if (m_mapOrientation == Qt::Vertical) | |
447 | { |
|
486 | { | |
448 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
487 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
449 | if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { |
|
488 | if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { | |
450 | if (column >= m_mapBarBottom && column <= m_mapBarTop) |
|
489 | if (column >= m_mapBarBottom && column <= m_mapBarTop) | |
451 | barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
490 | barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
452 | // if (column == m_mapCategories);// TODO: |
|
491 | // if (column == m_mapCategories);// TODO: | |
453 | } |
|
492 | } | |
454 | } |
|
493 | } | |
455 | else |
|
494 | else | |
456 | { |
|
495 | { | |
457 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
496 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
458 | if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { |
|
497 | if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { | |
459 | if (row >= m_mapBarBottom && row <= m_mapBarTop) |
|
498 | if (row >= m_mapBarBottom && row <= m_mapBarTop) | |
460 | barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
499 | barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
461 | // if (row == m_mapCategories);// TODO: |
|
500 | // if (row == m_mapCategories);// TODO: | |
462 | } |
|
501 | } | |
463 | } |
|
502 | } | |
464 | } |
|
503 | } | |
465 | } |
|
504 | } | |
466 | } |
|
505 | } | |
467 |
|
506 | |||
468 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
507 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
469 | { |
|
508 | { | |
470 | Q_UNUSED(parent); |
|
509 | Q_UNUSED(parent); | |
471 | Q_UNUSED(start); |
|
510 | Q_UNUSED(start); | |
472 | Q_UNUSED(end); |
|
511 | Q_UNUSED(end); | |
473 | initializeDataFromModel(); |
|
512 | initializeDataFromModel(); | |
474 | // // series uses model as a data sourceupda |
|
513 | // // series uses model as a data sourceupda | |
475 | // int addedCount = end - start + 1; |
|
514 | // int addedCount = end - start + 1; | |
476 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { |
|
515 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { | |
477 | // return; |
|
516 | // return; | |
478 | // } else { |
|
517 | // } else { | |
479 |
|
518 | |||
480 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { |
|
519 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { | |
481 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); |
|
520 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); | |
482 | // // adding items to unlimited map |
|
521 | // // adding items to unlimited map | |
483 | // if (m_mapCount == -1 && start >= m_mapFirst) { |
|
522 | // if (m_mapCount == -1 && start >= m_mapFirst) { | |
484 | // for (int i = start; i <= end; i++) { |
|
523 | // for (int i = start; i <= end; i++) { | |
485 | // if (bar == m_mapBarBottom) |
|
524 | // if (bar == m_mapBarBottom) | |
486 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
525 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
487 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
526 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
488 | // } |
|
527 | // } | |
489 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { |
|
528 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { | |
490 | // // not all newly added items |
|
529 | // // not all newly added items | |
491 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
530 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
492 | // if (bar == m_mapBarBottom) |
|
531 | // if (bar == m_mapBarBottom) | |
493 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
532 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
494 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
533 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
495 | // } |
|
534 | // } | |
496 | // } |
|
535 | // } | |
497 |
|
536 | |||
498 | // // adding items to limited map |
|
537 | // // adding items to limited map | |
499 | // else if (start >= m_mapFirst) { |
|
538 | // else if (start >= m_mapFirst) { | |
500 | // // remove the items that will no longer fit into the map |
|
539 | // // remove the items that will no longer fit into the map | |
501 | // // int toRemove = addedCount - (count - points().size()); |
|
540 | // // int toRemove = addedCount - (count - points().size()); | |
502 | // for (int i = start; i <= end; i++) { |
|
541 | // for (int i = start; i <= end; i++) { | |
503 | // if (bar == m_mapBarBottom) |
|
542 | // if (bar == m_mapBarBottom) | |
504 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
543 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
505 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
544 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
506 | // } |
|
545 | // } | |
507 | // if (m_barSets.size() > m_mapCount) |
|
546 | // if (m_barSets.size() > m_mapCount) | |
508 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
547 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
509 | // if (bar == m_mapBarBottom) |
|
548 | // if (bar == m_mapBarBottom) | |
510 | // removeCategory(i); |
|
549 | // removeCategory(i); | |
511 | // barSet->remove(i); |
|
550 | // barSet->remove(i); | |
512 | // } |
|
551 | // } | |
513 | // } else { |
|
552 | // } else { | |
514 | // // |
|
553 | // // | |
515 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
554 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { | |
516 | // if (bar == m_mapBarBottom) |
|
555 | // if (bar == m_mapBarBottom) | |
517 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
556 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); | |
518 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
557 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); | |
519 | // } |
|
558 | // } | |
520 | // if (m_barSets.size() > m_mapCount) |
|
559 | // if (m_barSets.size() > m_mapCount) | |
521 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
560 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { | |
522 | // if (bar == m_mapBarBottom) |
|
561 | // if (bar == m_mapBarBottom) | |
523 | // removeCategory(i); |
|
562 | // removeCategory(i); | |
524 | // barSet->remove(i); |
|
563 | // barSet->remove(i); | |
525 | // } |
|
564 | // } | |
526 | // } |
|
565 | // } | |
527 | // } |
|
566 | // } | |
528 | // emit restructuredBars(); |
|
567 | // emit restructuredBars(); | |
529 | // emit barsetChanged(); |
|
568 | // emit barsetChanged(); | |
530 | // emit categoriesUpdated(); |
|
569 | // emit categoriesUpdated(); | |
531 | // } |
|
570 | // } | |
532 | } |
|
571 | } | |
533 |
|
572 | |||
534 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
573 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
535 | { |
|
574 | { | |
536 | Q_UNUSED(parent); |
|
575 | Q_UNUSED(parent); | |
537 | Q_UNUSED(start); |
|
576 | Q_UNUSED(start); | |
538 | Q_UNUSED(end); |
|
577 | Q_UNUSED(end); | |
539 | initializeDataFromModel(); |
|
578 | initializeDataFromModel(); | |
540 | } |
|
579 | } | |
541 |
|
580 | |||
542 | void QBarSeriesPrivate::initializeDataFromModel() |
|
581 | void QBarSeriesPrivate::initializeDataFromModel() | |
543 | { |
|
582 | { | |
544 | Q_Q(QBarSeries); |
|
583 | Q_Q(QBarSeries); | |
545 |
|
584 | |||
546 | if (m_model == 0) |
|
585 | if (m_model == 0) | |
547 | return; |
|
586 | return; | |
548 |
|
587 | |||
549 | // connect the signals |
|
588 | // connect the signals | |
550 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
589 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
551 | // if (m_mapOrientation == Qt::Vertical) { |
|
590 | // if (m_mapOrientation == Qt::Vertical) { | |
552 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
591 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
553 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
592 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
554 | // } else { |
|
593 | // } else { | |
555 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
594 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
556 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
595 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
557 | // } |
|
596 | // } | |
558 |
|
597 | |||
559 | // create the initial bars |
|
598 | // create the initial bars | |
560 | m_categories.clear(); |
|
599 | m_categories.clear(); | |
561 | m_barSets.clear(); |
|
600 | m_barSets.clear(); | |
562 | // emit restructuredBars(); |
|
601 | // emit restructuredBars(); | |
563 | if (m_mapOrientation == Qt::Vertical) { |
|
602 | if (m_mapOrientation == Qt::Vertical) { | |
564 | int rowCount = 0; |
|
603 | int rowCount = 0; | |
565 | if(m_mapCount == -1) |
|
604 | if(m_mapCount == -1) | |
566 | rowCount = m_model->rowCount() - m_mapFirst; |
|
605 | rowCount = m_model->rowCount() - m_mapFirst; | |
567 | else |
|
606 | else | |
568 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
607 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); | |
569 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
608 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { | |
570 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
609 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
571 | } |
|
610 | } | |
572 |
|
611 | |||
573 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
612 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
574 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
613 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
575 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
614 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) | |
576 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
615 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
577 | q->appendBarSet(barSet); |
|
616 | q->appendBarSet(barSet); | |
578 | } |
|
617 | } | |
579 | } else { |
|
618 | } else { | |
580 | int columnCount = 0; |
|
619 | int columnCount = 0; | |
581 | if(m_mapCount == -1) |
|
620 | if(m_mapCount == -1) | |
582 | columnCount = m_model->columnCount() - m_mapFirst; |
|
621 | columnCount = m_model->columnCount() - m_mapFirst; | |
583 | else |
|
622 | else | |
584 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
623 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); | |
585 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
624 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { | |
586 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
625 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
587 | } |
|
626 | } | |
588 |
|
627 | |||
589 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
628 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
590 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
629 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
591 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
630 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) | |
592 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
631 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
593 | q->appendBarSet(barSet); |
|
632 | q->appendBarSet(barSet); | |
594 | } |
|
633 | } | |
595 | } |
|
634 | } | |
596 | emit restructuredBars(); |
|
635 | emit restructuredBars(); | |
597 | // emit updatedBars(); |
|
636 | // emit updatedBars(); | |
598 | } |
|
637 | } | |
599 |
|
638 | |||
600 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
639 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
601 | { |
|
640 | { | |
602 | m_categories.insert(index, category); |
|
641 | m_categories.insert(index, category); | |
603 | emit categoriesUpdated(); |
|
642 | emit categoriesUpdated(); | |
604 | } |
|
643 | } | |
605 |
|
644 | |||
606 | void QBarSeriesPrivate::removeCategory(int index) |
|
645 | void QBarSeriesPrivate::removeCategory(int index) | |
607 | { |
|
646 | { | |
608 | m_categories.removeAt(index); |
|
647 | m_categories.removeAt(index); | |
609 | emit categoriesUpdated(); |
|
648 | emit categoriesUpdated(); | |
610 | } |
|
649 | } | |
611 |
|
650 | |||
612 | void QBarSeriesPrivate::barsetChanged() |
|
651 | void QBarSeriesPrivate::barsetChanged() | |
613 | { |
|
652 | { | |
614 | emit updatedBars(); |
|
653 | emit updatedBars(); | |
615 | } |
|
654 | } | |
616 |
|
655 | |||
617 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
656 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
618 | { |
|
657 | { | |
619 | qreal minX(domain.minX()); |
|
658 | qreal minX(domain.minX()); | |
620 | qreal minY(domain.minY()); |
|
659 | qreal minY(domain.minY()); | |
621 | qreal maxX(domain.maxX()); |
|
660 | qreal maxX(domain.maxX()); | |
622 | qreal maxY(domain.maxY()); |
|
661 | qreal maxY(domain.maxY()); | |
623 | int tickXCount(domain.tickXCount()); |
|
662 | int tickXCount(domain.tickXCount()); | |
624 | int tickYCount(domain.tickYCount()); |
|
663 | int tickYCount(domain.tickYCount()); | |
625 |
|
664 | |||
626 | qreal x = m_categories.count(); |
|
665 | qreal x = m_categories.count(); | |
627 | qreal y = max(); |
|
666 | qreal y = max(); | |
628 | minX = qMin(minX, x); |
|
667 | minX = qMin(minX, x); | |
629 | minY = qMin(minY, y); |
|
668 | minY = qMin(minY, y); | |
630 | maxX = qMax(maxX, x); |
|
669 | maxX = qMax(maxX, x); | |
631 | maxY = qMax(maxY, y); |
|
670 | maxY = qMax(maxY, y); | |
632 | tickXCount = x+1; |
|
671 | tickXCount = x+1; | |
633 |
|
672 | |||
634 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
673 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
635 | } |
|
674 | } | |
636 |
|
675 | |||
637 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
676 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
638 | { |
|
677 | { | |
639 | Q_Q(QBarSeries); |
|
678 | Q_Q(QBarSeries); | |
640 |
|
679 | |||
641 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
680 | BarChartItem* bar = new BarChartItem(q,presenter); | |
642 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
681 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
643 | presenter->animator()->addAnimation(bar); |
|
682 | presenter->animator()->addAnimation(bar); | |
644 | } |
|
683 | } | |
645 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
684 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
646 | return bar; |
|
685 | return bar; | |
647 |
|
686 | |||
648 | } |
|
687 | } | |
649 |
|
688 | |||
650 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
689 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
651 | { |
|
690 | { | |
652 | Q_Q(QBarSeries); |
|
691 | Q_Q(QBarSeries); | |
653 | QList<LegendMarker*> markers; |
|
692 | QList<LegendMarker*> markers; | |
654 | foreach(QBarSet* set, q->barSets()) { |
|
693 | foreach(QBarSet* set, q->barSets()) { | |
655 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
694 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
656 | markers << marker; |
|
695 | markers << marker; | |
657 | } |
|
696 | } | |
658 |
|
697 | |||
659 | return markers; |
|
698 | return markers; | |
660 | } |
|
699 | } | |
661 |
|
700 | |||
662 | #include "moc_qbarseries.cpp" |
|
701 | #include "moc_qbarseries.cpp" | |
663 | #include "moc_qbarseries_p.cpp" |
|
702 | #include "moc_qbarseries_p.cpp" | |
664 |
|
703 | |||
665 | QTCOMMERCIALCHART_END_NAMESPACE |
|
704 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,79 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | typedef QStringList QBarCategories; |
|
31 | typedef QStringList QBarCategories; | |
32 |
|
32 | |||
33 | class QBarSet; |
|
33 | class QBarSet; | |
34 | class BarCategory; |
|
34 | class BarCategory; | |
35 | class QBarSeriesPrivate; |
|
35 | class QBarSeriesPrivate; | |
36 |
|
36 | |||
37 | // Container for series |
|
37 | // Container for series | |
38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | explicit QBarSeries(QBarCategories categories, QObject *parent = 0); |
|
42 | explicit QBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
43 | virtual ~QBarSeries(); |
|
43 | virtual ~QBarSeries(); | |
44 |
|
44 | |||
45 | QAbstractSeries::SeriesType type() const; |
|
45 | QAbstractSeries::SeriesType type() const; | |
|
46 | void setCategories(QBarCategories categories); | |||
46 |
|
47 | |||
47 |
|
|
48 | bool appendBarSet(QBarSet *set); // Takes ownership of set | |
48 |
|
|
49 | bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
49 |
|
|
50 | bool appendBarSets(QList<QBarSet* > sets); | |
50 |
|
|
51 | bool removeBarSets(QList<QBarSet* > sets); | |
51 | int barsetCount() const; |
|
52 | int barsetCount() const; | |
52 | int categoryCount() const; |
|
53 | int categoryCount() const; | |
53 | QList<QBarSet*> barSets() const; |
|
54 | QList<QBarSet*> barSets() const; | |
54 | QBarCategories categories() const; |
|
55 | QBarCategories categories() const; | |
55 |
|
56 | |||
56 | void setLabelsVisible(bool visible = true); |
|
57 | void setLabelsVisible(bool visible = true); | |
57 |
|
58 | |||
58 | bool setModel(QAbstractItemModel *model); |
|
59 | bool setModel(QAbstractItemModel *model); | |
59 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
60 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
60 | void setModelMappingRange(int first, int count = -1); |
|
61 | void setModelMappingRange(int first, int count = -1); | |
61 |
|
62 | |||
62 | protected: |
|
63 | protected: | |
63 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
64 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
64 |
|
65 | |||
65 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
66 | void clicked(QBarSet *barset, QString category); |
|
67 | void clicked(QBarSet *barset, QString category); | |
67 | void hovered(QBarSet* barset, bool status); |
|
68 | void hovered(QBarSet* barset, bool status); | |
68 |
|
69 | |||
69 | protected: |
|
70 | protected: | |
70 | Q_DECLARE_PRIVATE(QBarSeries) |
|
71 | Q_DECLARE_PRIVATE(QBarSeries) | |
71 | friend class BarChartItem; |
|
72 | friend class BarChartItem; | |
72 | friend class PercentBarChartItem; |
|
73 | friend class PercentBarChartItem; | |
73 | friend class StackedBarChartItem; |
|
74 | friend class StackedBarChartItem; | |
74 | }; |
|
75 | }; | |
75 |
|
76 | |||
76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE | |
77 |
|
78 | |||
78 | #endif // BARSERIES_H |
|
79 | #endif // BARSERIES_H |
@@ -1,68 +1,69 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qabstractseries_p.h" |
|
5 | #include "qabstractseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QAbstractSeries> |
|
7 | #include <QAbstractSeries> | |
8 |
|
8 | |||
9 | class QModelIndex; |
|
9 | class QModelIndex; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); |
|
18 | QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *parent); | |
|
19 | void setCategories(QBarCategories categories); | |||
19 |
|
20 | |||
20 | void scaleDomain(Domain& domain); |
|
21 | void scaleDomain(Domain& domain); | |
21 | Chart* createGraphics(ChartPresenter* presenter); |
|
22 | Chart* createGraphics(ChartPresenter* presenter); | |
22 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
23 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
23 |
|
24 | |||
24 | bool setModel(QAbstractItemModel *model); |
|
25 | bool setModel(QAbstractItemModel *model); | |
25 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
26 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
26 | void setModelMappingRange(int first, int count = -1); |
|
27 | void setModelMappingRange(int first, int count = -1); | |
27 |
|
28 | |||
28 | void insertCategory(int index, const QString category); |
|
29 | void insertCategory(int index, const QString category); | |
29 | void removeCategory(int index); |
|
30 | void removeCategory(int index); | |
30 |
|
31 | |||
31 | QBarSet* barsetAt(int index); |
|
32 | QBarSet* barsetAt(int index); | |
32 | QString categoryName(int category); |
|
33 | QString categoryName(int category); | |
33 | qreal min(); |
|
34 | qreal min(); | |
34 | qreal max(); |
|
35 | qreal max(); | |
35 | qreal valueAt(int set, int category); |
|
36 | qreal valueAt(int set, int category); | |
36 | qreal percentageAt(int set, int category); |
|
37 | qreal percentageAt(int set, int category); | |
37 | qreal categorySum(int category); |
|
38 | qreal categorySum(int category); | |
38 | qreal absoluteCategorySum(int category); |
|
39 | qreal absoluteCategorySum(int category); | |
39 | qreal maxCategorySum(); |
|
40 | qreal maxCategorySum(); | |
40 |
|
41 | |||
41 | Q_SIGNALS: |
|
42 | Q_SIGNALS: | |
42 | void clicked(QBarSet *barset, QString category); |
|
43 | void clicked(QBarSet *barset, QString category); | |
43 | void updatedBars(); |
|
44 | void updatedBars(); | |
44 | void restructuredBars(); |
|
45 | void restructuredBars(); | |
45 | void categoriesUpdated(); |
|
46 | void categoriesUpdated(); | |
46 |
|
47 | |||
47 | private Q_SLOTS: |
|
48 | private Q_SLOTS: | |
48 | // slots for updating bars when data in model changes |
|
49 | // slots for updating bars when data in model changes | |
49 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
50 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
51 | void modelDataAdded(QModelIndex parent, int start, int end); | |
51 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
52 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
52 | void initializeDataFromModel(); |
|
53 | void initializeDataFromModel(); | |
53 | void barsetChanged(); |
|
54 | void barsetChanged(); | |
54 |
|
55 | |||
55 | protected: |
|
56 | protected: | |
56 | QList<QBarSet *> m_barSets; |
|
57 | QList<QBarSet *> m_barSets; | |
57 | QBarCategories m_categories; |
|
58 | QBarCategories m_categories; | |
58 |
|
59 | |||
59 | int m_mapCategories; |
|
60 | int m_mapCategories; | |
60 | int m_mapBarBottom; |
|
61 | int m_mapBarBottom; | |
61 | int m_mapBarTop; |
|
62 | int m_mapBarTop; | |
62 | private: |
|
63 | private: | |
63 | Q_DECLARE_PUBLIC(QBarSeries) |
|
64 | Q_DECLARE_PUBLIC(QBarSeries) | |
64 | }; |
|
65 | }; | |
65 |
|
66 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
67 |
|
68 | |||
68 | #endif // QBARSERIESPRIVATE_P_H |
|
69 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,109 +1,109 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QPercentBarSeries |
|
32 | \class QPercentBarSeries | |
33 | \brief part of QtCommercial chart API. |
|
33 | \brief part of QtCommercial chart API. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage |
|
36 | QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage | |
37 | of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets. |
|
37 | of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets. | |
38 | QBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
38 | QBarSeries groups the data from sets to categories, which are defined by QStringList. | |
39 |
|
39 | |||
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
41 | \image examples_percentbarchart.png |
|
41 | \image examples_percentbarchart.png | |
42 |
|
42 | |||
43 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
43 | \sa QBarSet, QStackedBarSeries, QBarSeries | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \fn virtual QSeriesType QPercentBarSeries::type() const |
|
47 | \fn virtual QSeriesType QPercentBarSeries::type() const | |
48 | \brief Returns type of series. |
|
48 | \brief Returns type of series. | |
49 | \sa QAbstractSeries, QSeriesType |
|
49 | \sa QAbstractSeries, QSeriesType | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. | |
54 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
54 | QPercentBarSeries is QObject which is a child of a \a parent. | |
55 | */ |
|
55 | */ | |
56 | QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent) |
|
56 | QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
57 | : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent) |
|
57 | : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent) | |
58 | { |
|
58 | { | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
61 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
62 | { |
|
62 | { | |
63 | return QAbstractSeries::SeriesTypePercentBar; |
|
63 | return QAbstractSeries::SeriesTypePercentBar; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
67 |
|
67 | |||
68 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QBarCategories categories, QPercentBarSeries *q) : QBarSeriesPrivate(categories,q) |
|
68 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(/*QBarCategories categories,*/ QPercentBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |
69 | { |
|
69 | { | |
70 |
|
70 | |||
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
73 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
74 | { |
|
74 | { | |
75 | Q_Q(QPercentBarSeries); |
|
75 | Q_Q(QPercentBarSeries); | |
76 | qreal minX(domain.minX()); |
|
76 | qreal minX(domain.minX()); | |
77 | qreal minY(domain.minY()); |
|
77 | qreal minY(domain.minY()); | |
78 | qreal maxX(domain.maxX()); |
|
78 | qreal maxX(domain.maxX()); | |
79 | qreal maxY(domain.maxY()); |
|
79 | qreal maxY(domain.maxY()); | |
80 | int tickXCount(domain.tickXCount()); |
|
80 | int tickXCount(domain.tickXCount()); | |
81 | int tickYCount(domain.tickYCount()); |
|
81 | int tickYCount(domain.tickYCount()); | |
82 |
|
82 | |||
83 | qreal x = q->categoryCount(); |
|
83 | qreal x = q->categoryCount(); | |
84 | minX = qMin(minX, x); |
|
84 | minX = qMin(minX, x); | |
85 | maxX = qMax(maxX, x); |
|
85 | maxX = qMax(maxX, x); | |
86 | minY = 0; |
|
86 | minY = 0; | |
87 | maxY = 100; |
|
87 | maxY = 100; | |
88 | tickXCount = x+1; |
|
88 | tickXCount = x+1; | |
89 |
|
89 | |||
90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
94 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
95 | { |
|
95 | { | |
96 | Q_Q(QPercentBarSeries); |
|
96 | Q_Q(QPercentBarSeries); | |
97 |
|
97 | |||
98 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
98 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
100 | presenter->animator()->addAnimation(bar); |
|
100 | presenter->animator()->addAnimation(bar); | |
101 | } |
|
101 | } | |
102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
103 | return bar; |
|
103 | return bar; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | #include "moc_qpercentbarseries.cpp" |
|
106 | #include "moc_qpercentbarseries.cpp" | |
107 |
|
107 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE | |
109 |
|
109 |
@@ -1,44 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef PERCENTBARSERIES_H |
|
21 | #ifndef PERCENTBARSERIES_H | |
22 | #define PERCENTBARSERIES_H |
|
22 | #define PERCENTBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QPercentBarSeriesPrivate; |
|
29 | class QPercentBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0); |
|
35 | explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
|
37 | ||||
37 | private: |
|
38 | private: | |
38 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QPercentBarSeries) | |
39 | Q_DISABLE_COPY(QPercentBarSeries) |
|
40 | Q_DISABLE_COPY(QPercentBarSeries) | |
40 | }; |
|
41 | }; | |
41 |
|
42 | |||
42 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
43 |
|
44 | |||
44 | #endif // PERCENTBARSERIES_H |
|
45 | #endif // PERCENTBARSERIES_H |
@@ -1,52 +1,52 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QPERCENTBARSERIES_P_H |
|
30 | #ifndef QPERCENTBARSERIES_P_H | |
31 | #define QPERCENTBARSERIES_P_H |
|
31 | #define QPERCENTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate |
|
39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QPercentBarSeriesPrivate(QBarCategories categories,QPercentBarSeries* q); |
|
42 | QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
44 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | Chart* createGraphics(ChartPresenter* presenter); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QPercentBarSeries) | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif |
|
52 | #endif |
@@ -1,108 +1,108 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QStackedBarSeries |
|
31 | \class QStackedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QStackedBarSeries represents a series of data shown as bars. All bars in same category are |
|
35 | QStackedBarSeries represents a series of data shown as bars. All bars in same category are | |
36 | stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets. |
|
36 | stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets. | |
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
38 |
|
38 | |||
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
40 | \image examples_stackedbarchart.png |
|
40 | \image examples_stackedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QStackedBarSeries::type() const |
|
46 | \fn virtual QSeriesType QStackedBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QSeriesType |
|
48 | \sa QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. |
|
52 | Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. | |
53 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
53 | QStackedBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 | QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent) |
|
55 | QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
56 | : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent) |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypeStackedBar; |
|
62 | return QAbstractSeries::SeriesTypeStackedBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QBarCategories categories, QStackedBarSeries *q) : QBarSeriesPrivate(categories,q) |
|
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(/*QBarCategories categories,*/ QStackedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
75 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
76 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
77 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
78 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
79 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
80 |
|
80 | |||
81 | qreal x = m_categories.count(); |
|
81 | qreal x = m_categories.count(); | |
82 | qreal y = maxCategorySum(); |
|
82 | qreal y = maxCategorySum(); | |
83 | minX = qMin(minX, x); |
|
83 | minX = qMin(minX, x); | |
84 | minY = qMin(minY, y); |
|
84 | minY = qMin(minY, y); | |
85 | maxX = qMax(maxX, x); |
|
85 | maxX = qMax(maxX, x); | |
86 | maxY = qMax(maxY, y); |
|
86 | maxY = qMax(maxY, y); | |
87 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
88 |
|
88 | |||
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 |
|
92 | |||
93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
94 | { |
|
94 | { | |
95 | Q_Q(QStackedBarSeries); |
|
95 | Q_Q(QStackedBarSeries); | |
96 |
|
96 | |||
97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
99 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
100 | } |
|
100 | } | |
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
102 | return bar; |
|
102 | return bar; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | #include "moc_qstackedbarseries.cpp" |
|
105 | #include "moc_qstackedbarseries.cpp" | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
108 |
@@ -1,44 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef STACKEDBARSERIES_H |
|
21 | #ifndef STACKEDBARSERIES_H | |
22 | #define STACKEDBARSERIES_H |
|
22 | #define STACKEDBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QStackedBarSeriesPrivate; |
|
29 | class QStackedBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0); |
|
35 | explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
|
37 | ||||
37 | private: |
|
38 | private: | |
38 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QStackedBarSeries) | |
39 | Q_DISABLE_COPY(QStackedBarSeries) |
|
40 | Q_DISABLE_COPY(QStackedBarSeries) | |
40 | }; |
|
41 | }; | |
41 |
|
42 | |||
42 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
43 |
|
44 | |||
44 | #endif // STACKEDBARSERIES_H |
|
45 | #endif // STACKEDBARSERIES_H |
@@ -1,52 +1,52 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QSTACKEDBARSERIES_P_H |
|
30 | #ifndef QSTACKEDBARSERIES_P_H | |
31 | #define QSTACKEDBARSERIES_P_H |
|
31 | #define QSTACKEDBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate |
|
39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QStackedBarSeriesPrivate(QBarCategories categories,QStackedBarSeries* q); |
|
42 | QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif |
|
52 | #endif |
@@ -1,6 +1,9 | |||||
1 | !include( ../test.pri ) { |
|
1 | !include( ../test.pri ) { | |
2 | error( "Couldn't find the test.pri file!" ) |
|
2 | error( "Couldn't find the test.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | CONFIG += qtestlib |
|
5 | CONFIG += qtestlib | |
6 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") |
|
6 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") | |
|
7 | ||||
|
8 | INCLUDEPATH += ../inc | |||
|
9 | HEADERS += ../inc/tst_definitions.h |
@@ -1,10 +1,10 | |||||
1 | !include( ../test.pri ) { |
|
1 | !include( ../test.pri ) { | |
2 | error( "Couldn't find the test.pri file!" ) |
|
2 | error( "Couldn't find the test.pri file!" ) | |
3 | } |
|
3 | } | |
4 |
|
4 | |||
5 | TEMPLATE = subdirs |
|
5 | TEMPLATE = subdirs | |
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qpieslice qpieseries | |
7 |
|
7 | |||
8 | test_private:{ |
|
8 | test_private:{ | |
9 | SUBDIRS += chartdataset domain |
|
9 | SUBDIRS += chartdataset domain | |
10 | } |
|
10 | } |
@@ -1,532 +1,533 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qaxis.h> |
|
22 | #include <qaxis.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <private/chartdataset_p.h> |
|
24 | #include <private/chartdataset_p.h> | |
25 | #include <private/domain_p.h> |
|
25 | #include <private/domain_p.h> | |
|
26 | #include <tst_definitions.h> | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
29 | |||
29 | Q_DECLARE_METATYPE(Domain *) |
|
30 | Q_DECLARE_METATYPE(Domain *) | |
30 | Q_DECLARE_METATYPE(QAxis *) |
|
31 | Q_DECLARE_METATYPE(QAxis *) | |
31 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
32 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
32 | Q_DECLARE_METATYPE(QLineSeries *) |
|
33 | Q_DECLARE_METATYPE(QLineSeries *) | |
33 |
|
34 | |||
34 | class tst_ChartDataSet: public QObject { |
|
35 | class tst_ChartDataSet: public QObject { | |
35 |
|
36 | |||
36 | Q_OBJECT |
|
37 | Q_OBJECT | |
37 |
|
38 | |||
38 | public Q_SLOTS: |
|
39 | public Q_SLOTS: | |
39 | void initTestCase(); |
|
40 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
41 | void cleanupTestCase(); | |
41 | void init(); |
|
42 | void init(); | |
42 | void cleanup(); |
|
43 | void cleanup(); | |
43 |
|
44 | |||
44 | private Q_SLOTS: |
|
45 | private Q_SLOTS: | |
45 | void chartdataset_data(); |
|
46 | void chartdataset_data(); | |
46 | void chartdataset(); |
|
47 | void chartdataset(); | |
47 | void addSeries_data(); |
|
48 | void addSeries_data(); | |
48 | void addSeries(); |
|
49 | void addSeries(); | |
49 | void removeSeries_data(); |
|
50 | void removeSeries_data(); | |
50 | void removeSeries(); |
|
51 | void removeSeries(); | |
51 | void removeAllSeries_data(); |
|
52 | void removeAllSeries_data(); | |
52 | void removeAllSeries(); |
|
53 | void removeAllSeries(); | |
53 | void axisY_data(); |
|
54 | void axisY_data(); | |
54 | void axisY(); |
|
55 | void axisY(); | |
55 | void seriesCount_data(); |
|
56 | void seriesCount_data(); | |
56 | void seriesCount(); |
|
57 | void seriesCount(); | |
57 | void seriesIndex_data(); |
|
58 | void seriesIndex_data(); | |
58 | void seriesIndex(); |
|
59 | void seriesIndex(); | |
59 | void domain_data(); |
|
60 | void domain_data(); | |
60 | void domain(); |
|
61 | void domain(); | |
61 | void zoomInDomain_data(); |
|
62 | void zoomInDomain_data(); | |
62 | void zoomInDomain(); |
|
63 | void zoomInDomain(); | |
63 | void zoomOutDomain_data(); |
|
64 | void zoomOutDomain_data(); | |
64 | void zoomOutDomain(); |
|
65 | void zoomOutDomain(); | |
65 | void scrollDomain_data(); |
|
66 | void scrollDomain_data(); | |
66 | void scrollDomain(); |
|
67 | void scrollDomain(); | |
67 | private: |
|
68 | private: | |
68 | ChartDataSet* m_dataset; |
|
69 | ChartDataSet* m_dataset; | |
69 | }; |
|
70 | }; | |
70 |
|
71 | |||
71 | void tst_ChartDataSet::initTestCase() |
|
72 | void tst_ChartDataSet::initTestCase() | |
72 | { |
|
73 | { | |
73 | qRegisterMetaType<Domain*>(); |
|
74 | qRegisterMetaType<Domain*>(); | |
74 | qRegisterMetaType<QAxis*>(); |
|
75 | qRegisterMetaType<QAxis*>(); | |
75 | qRegisterMetaType<QAbstractSeries*>(); |
|
76 | qRegisterMetaType<QAbstractSeries*>(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void tst_ChartDataSet::cleanupTestCase() |
|
79 | void tst_ChartDataSet::cleanupTestCase() | |
79 | { |
|
80 | { | |
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | void tst_ChartDataSet::init() |
|
83 | void tst_ChartDataSet::init() | |
83 | { |
|
84 | { | |
84 | m_dataset = new ChartDataSet(); |
|
85 | m_dataset = new ChartDataSet(); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 |
|
88 | |||
88 | void tst_ChartDataSet::cleanup() |
|
89 | void tst_ChartDataSet::cleanup() | |
89 | { |
|
90 | { | |
90 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
91 | QList<QAbstractSeries*> series = m_dataset->series(); | |
91 | foreach(QAbstractSeries* serie, series) |
|
92 | foreach(QAbstractSeries* serie, series) | |
92 | { |
|
93 | { | |
93 | m_dataset->removeSeries(serie); |
|
94 | m_dataset->removeSeries(serie); | |
94 | } |
|
95 | } | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | void tst_ChartDataSet::chartdataset_data() |
|
98 | void tst_ChartDataSet::chartdataset_data() | |
98 | { |
|
99 | { | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | void tst_ChartDataSet::chartdataset() |
|
102 | void tst_ChartDataSet::chartdataset() | |
102 | { |
|
103 | { | |
103 | QVERIFY2(m_dataset->axisX(), "Missing axisX."); |
|
104 | QVERIFY2(m_dataset->axisX(), "Missing axisX."); | |
104 | QVERIFY2(m_dataset->axisY(), "Missing axisY."); |
|
105 | QVERIFY2(m_dataset->axisY(), "Missing axisY."); | |
105 | //check if not dangling pointer |
|
106 | //check if not dangling pointer | |
106 | m_dataset->axisX()->objectName(); |
|
107 | m_dataset->axisX()->objectName(); | |
107 | m_dataset->axisY()->objectName(); |
|
108 | m_dataset->axisY()->objectName(); | |
108 | QLineSeries* series = new QLineSeries(this); |
|
109 | QLineSeries* series = new QLineSeries(this); | |
109 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
110 | QCOMPARE(m_dataset->seriesIndex(series),-1); | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | void tst_ChartDataSet::addSeries_data() |
|
113 | void tst_ChartDataSet::addSeries_data() | |
113 | { |
|
114 | { | |
114 | QTest::addColumn<QLineSeries*>("series0"); |
|
115 | QTest::addColumn<QLineSeries*>("series0"); | |
115 | QTest::addColumn<QAxis*>("axis0"); |
|
116 | QTest::addColumn<QAxis*>("axis0"); | |
116 | QTest::addColumn<QLineSeries*>("series1"); |
|
117 | QTest::addColumn<QLineSeries*>("series1"); | |
117 | QTest::addColumn<QAxis*>("axis1"); |
|
118 | QTest::addColumn<QAxis*>("axis1"); | |
118 | QTest::addColumn<QLineSeries*>("series2"); |
|
119 | QTest::addColumn<QLineSeries*>("series2"); | |
119 | QTest::addColumn<QAxis*>("axis2"); |
|
120 | QTest::addColumn<QAxis*>("axis2"); | |
120 | QTest::addColumn<int>("axisCount"); |
|
121 | QTest::addColumn<int>("axisCount"); | |
121 |
|
122 | |||
122 | QLineSeries* series0 = new QLineSeries(this); |
|
123 | QLineSeries* series0 = new QLineSeries(this); | |
123 | QLineSeries* series1 = new QLineSeries(this); |
|
124 | QLineSeries* series1 = new QLineSeries(this); | |
124 | QLineSeries* series2 = new QLineSeries(this); |
|
125 | QLineSeries* series2 = new QLineSeries(this); | |
125 |
|
126 | |||
126 | QAxis* axis0 = new QAxis(this); |
|
127 | QAxis* axis0 = new QAxis(this); | |
127 | QAxis* axis1 = new QAxis(this); |
|
128 | QAxis* axis1 = new QAxis(this); | |
128 | QAxis* axis2 = new QAxis(this); |
|
129 | QAxis* axis2 = new QAxis(this); | |
129 |
|
130 | |||
130 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QAxis*)0 << series1 << (QAxis*)0 << series2 << (QAxis*)0 << 2; |
|
131 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QAxis*)0 << series1 << (QAxis*)0 << series2 << (QAxis*)0 << 2; | |
131 | QTest::newRow("default axis Y: series0, axis0: series1,series2") << series0 << (QAxis*)0 << series1 << axis0 << series2 << axis0 << 3; |
|
132 | QTest::newRow("default axis Y: series0, axis0: series1,series2") << series0 << (QAxis*)0 << series1 << axis0 << series2 << axis0 << 3; | |
132 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; |
|
133 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; | |
133 | } |
|
134 | } | |
134 |
|
135 | |||
135 | void tst_ChartDataSet::addSeries() |
|
136 | void tst_ChartDataSet::addSeries() | |
136 | { |
|
137 | { | |
137 | QFETCH(QLineSeries*, series0); |
|
138 | QFETCH(QLineSeries*, series0); | |
138 | QFETCH(QAxis*, axis0); |
|
139 | QFETCH(QAxis*, axis0); | |
139 | QFETCH(QLineSeries*, series1); |
|
140 | QFETCH(QLineSeries*, series1); | |
140 | QFETCH(QAxis*, axis1); |
|
141 | QFETCH(QAxis*, axis1); | |
141 | QFETCH(QLineSeries*, series2); |
|
142 | QFETCH(QLineSeries*, series2); | |
142 | QFETCH(QAxis*, axis2); |
|
143 | QFETCH(QAxis*, axis2); | |
143 | QFETCH(int, axisCount); |
|
144 | QFETCH(int, axisCount); | |
144 |
|
145 | |||
145 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); |
|
146 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); | |
146 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); |
|
147 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); | |
147 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
148 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
148 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
149 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
149 |
|
150 | |||
150 | m_dataset->addSeries(series0,axis0); |
|
151 | m_dataset->addSeries(series0,axis0); | |
151 | m_dataset->addSeries(series1,axis1); |
|
152 | m_dataset->addSeries(series1,axis1); | |
152 | m_dataset->addSeries(series2,axis2); |
|
153 | m_dataset->addSeries(series2,axis2); | |
153 |
|
154 | |||
154 |
|
|
155 | TRY_COMPARE(spy0.count(), axisCount); | |
155 |
|
|
156 | TRY_COMPARE(spy1.count(), 0); | |
156 |
|
|
157 | TRY_COMPARE(spy2.count(), 3); | |
157 |
|
|
158 | TRY_COMPARE(spy3.count(), 0); | |
158 |
|
159 | |||
159 | if(axis0==0) axis0 = m_dataset->axisY(); |
|
160 | if(axis0==0) axis0 = m_dataset->axisY(); | |
160 | if(axis1==0) axis1 = m_dataset->axisY(); |
|
161 | if(axis1==0) axis1 = m_dataset->axisY(); | |
161 | if(axis2==0) axis2 = m_dataset->axisY(); |
|
162 | if(axis2==0) axis2 = m_dataset->axisY(); | |
162 |
|
163 | |||
163 | QVERIFY(axis0 == m_dataset->removeSeries(series0)); |
|
164 | QVERIFY(axis0 == m_dataset->removeSeries(series0)); | |
164 | QVERIFY(axis1 == m_dataset->removeSeries(series1)); |
|
165 | QVERIFY(axis1 == m_dataset->removeSeries(series1)); | |
165 | QVERIFY(axis2 == m_dataset->removeSeries(series2)); |
|
166 | QVERIFY(axis2 == m_dataset->removeSeries(series2)); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | void tst_ChartDataSet::removeSeries_data() |
|
169 | void tst_ChartDataSet::removeSeries_data() | |
169 | { |
|
170 | { | |
170 | addSeries_data(); |
|
171 | addSeries_data(); | |
171 | } |
|
172 | } | |
172 |
|
173 | |||
173 | void tst_ChartDataSet::removeSeries() |
|
174 | void tst_ChartDataSet::removeSeries() | |
174 | { |
|
175 | { | |
175 | QFETCH(QLineSeries*, series0); |
|
176 | QFETCH(QLineSeries*, series0); | |
176 | QFETCH(QAxis*, axis0); |
|
177 | QFETCH(QAxis*, axis0); | |
177 | QFETCH(QLineSeries*, series1); |
|
178 | QFETCH(QLineSeries*, series1); | |
178 | QFETCH(QAxis*, axis1); |
|
179 | QFETCH(QAxis*, axis1); | |
179 | QFETCH(QLineSeries*, series2); |
|
180 | QFETCH(QLineSeries*, series2); | |
180 | QFETCH(QAxis*, axis2); |
|
181 | QFETCH(QAxis*, axis2); | |
181 | QFETCH(int, axisCount); |
|
182 | QFETCH(int, axisCount); | |
182 |
|
183 | |||
183 | m_dataset->addSeries(series0,axis0); |
|
184 | m_dataset->addSeries(series0,axis0); | |
184 | m_dataset->addSeries(series1,axis1); |
|
185 | m_dataset->addSeries(series1,axis1); | |
185 | m_dataset->addSeries(series2,axis2); |
|
186 | m_dataset->addSeries(series2,axis2); | |
186 |
|
187 | |||
187 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
188 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); | |
188 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
189 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); | |
189 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
190 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
190 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
191 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
191 |
|
192 | |||
192 | m_dataset->removeSeries(series0); |
|
193 | m_dataset->removeSeries(series0); | |
193 | m_dataset->removeSeries(series1); |
|
194 | m_dataset->removeSeries(series1); | |
194 | m_dataset->removeSeries(series2); |
|
195 | m_dataset->removeSeries(series2); | |
195 |
|
196 | |||
196 |
|
|
197 | TRY_COMPARE(spy0.count(), 0); | |
197 |
|
|
198 | TRY_COMPARE(spy1.count(), axisCount); | |
198 |
|
|
199 | TRY_COMPARE(spy2.count(), 0); | |
199 |
|
|
200 | TRY_COMPARE(spy3.count(), 3); | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | void tst_ChartDataSet::removeAllSeries_data() |
|
203 | void tst_ChartDataSet::removeAllSeries_data() | |
203 | { |
|
204 | { | |
204 |
|
205 | |||
205 | } |
|
206 | } | |
206 |
|
207 | |||
207 | void tst_ChartDataSet::removeAllSeries() |
|
208 | void tst_ChartDataSet::removeAllSeries() | |
208 | { |
|
209 | { | |
209 | QLineSeries* series0 = new QLineSeries(this); |
|
210 | QLineSeries* series0 = new QLineSeries(this); | |
210 | QLineSeries* series1 = new QLineSeries(this); |
|
211 | QLineSeries* series1 = new QLineSeries(this); | |
211 | QLineSeries* series2 = new QLineSeries(this); |
|
212 | QLineSeries* series2 = new QLineSeries(this); | |
212 |
|
213 | |||
213 | QAxis* axis0 = new QAxis(this); |
|
214 | QAxis* axis0 = new QAxis(this); | |
214 | QAxis* axis1 = new QAxis(this); |
|
215 | QAxis* axis1 = new QAxis(this); | |
215 | QAxis* axis2 = new QAxis(this); |
|
216 | QAxis* axis2 = new QAxis(this); | |
216 |
|
217 | |||
217 | m_dataset->addSeries(series0, axis0); |
|
218 | m_dataset->addSeries(series0, axis0); | |
218 | m_dataset->addSeries(series1, axis1); |
|
219 | m_dataset->addSeries(series1, axis1); | |
219 | m_dataset->addSeries(series2, axis2); |
|
220 | m_dataset->addSeries(series2, axis2); | |
220 |
|
221 | |||
221 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
222 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); | |
222 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
223 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); | |
223 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
224 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
224 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
225 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
225 |
|
226 | |||
226 | m_dataset->removeAllSeries(); |
|
227 | m_dataset->removeAllSeries(); | |
227 |
|
228 | |||
228 |
|
|
229 | TRY_COMPARE(spy0.count(), 0); | |
229 |
|
|
230 | TRY_COMPARE(spy1.count(), 4); | |
230 |
|
|
231 | TRY_COMPARE(spy2.count(), 0); | |
231 |
|
|
232 | TRY_COMPARE(spy3.count(), 3); | |
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 |
|
235 | |||
235 | void tst_ChartDataSet::axisY_data() |
|
236 | void tst_ChartDataSet::axisY_data() | |
236 | { |
|
237 | { | |
237 | QTest::addColumn<QAxis*>("axis0"); |
|
238 | QTest::addColumn<QAxis*>("axis0"); | |
238 | QTest::addColumn<QAxis*>("axis1"); |
|
239 | QTest::addColumn<QAxis*>("axis1"); | |
239 | QTest::addColumn<QAxis*>("axis2"); |
|
240 | QTest::addColumn<QAxis*>("axis2"); | |
240 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
241 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
241 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
242 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
242 | } |
|
243 | } | |
243 |
|
244 | |||
244 | void tst_ChartDataSet::axisY() |
|
245 | void tst_ChartDataSet::axisY() | |
245 | { |
|
246 | { | |
246 | QFETCH(QAxis*, axis0); |
|
247 | QFETCH(QAxis*, axis0); | |
247 | QFETCH(QAxis*, axis1); |
|
248 | QFETCH(QAxis*, axis1); | |
248 | QFETCH(QAxis*, axis2); |
|
249 | QFETCH(QAxis*, axis2); | |
249 |
|
250 | |||
250 | QAxis* defaultAxisY = m_dataset->axisY(); |
|
251 | QAxis* defaultAxisY = m_dataset->axisY(); | |
251 |
|
252 | |||
252 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
253 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
253 |
|
254 | |||
254 | QLineSeries* series0 = new QLineSeries(); |
|
255 | QLineSeries* series0 = new QLineSeries(); | |
255 | m_dataset->addSeries(series0,axis0); |
|
256 | m_dataset->addSeries(series0,axis0); | |
256 |
|
257 | |||
257 | QLineSeries* series1 = new QLineSeries(); |
|
258 | QLineSeries* series1 = new QLineSeries(); | |
258 | m_dataset->addSeries(series1,axis1); |
|
259 | m_dataset->addSeries(series1,axis1); | |
259 |
|
260 | |||
260 | QLineSeries* series2 = new QLineSeries(); |
|
261 | QLineSeries* series2 = new QLineSeries(); | |
261 | m_dataset->addSeries(series2,axis2); |
|
262 | m_dataset->addSeries(series2,axis2); | |
262 |
|
263 | |||
263 | if(!axis0) axis0=defaultAxisY ; |
|
264 | if(!axis0) axis0=defaultAxisY ; | |
264 | if(!axis1) axis1=defaultAxisY ; |
|
265 | if(!axis1) axis1=defaultAxisY ; | |
265 | if(!axis2) axis2=defaultAxisY ; |
|
266 | if(!axis2) axis2=defaultAxisY ; | |
266 |
|
267 | |||
267 | QVERIFY(m_dataset->axisY(series0) == axis0); |
|
268 | QVERIFY(m_dataset->axisY(series0) == axis0); | |
268 | QVERIFY(m_dataset->axisY(series1) == axis1); |
|
269 | QVERIFY(m_dataset->axisY(series1) == axis1); | |
269 | QVERIFY(m_dataset->axisY(series2) == axis2); |
|
270 | QVERIFY(m_dataset->axisY(series2) == axis2); | |
270 |
|
271 | |||
271 | } |
|
272 | } | |
272 |
|
273 | |||
273 | void tst_ChartDataSet::seriesCount_data() |
|
274 | void tst_ChartDataSet::seriesCount_data() | |
274 | { |
|
275 | { | |
275 | addSeries_data(); |
|
276 | addSeries_data(); | |
276 | } |
|
277 | } | |
277 |
|
278 | |||
278 | void tst_ChartDataSet::seriesCount() |
|
279 | void tst_ChartDataSet::seriesCount() | |
279 | { |
|
280 | { | |
280 | QFETCH(QLineSeries*, series0); |
|
281 | QFETCH(QLineSeries*, series0); | |
281 | QFETCH(QAxis*, axis0); |
|
282 | QFETCH(QAxis*, axis0); | |
282 | QFETCH(QLineSeries*, series1); |
|
283 | QFETCH(QLineSeries*, series1); | |
283 | QFETCH(QAxis*, axis1); |
|
284 | QFETCH(QAxis*, axis1); | |
284 | QFETCH(QLineSeries*, series2); |
|
285 | QFETCH(QLineSeries*, series2); | |
285 | QFETCH(QAxis*, axis2); |
|
286 | QFETCH(QAxis*, axis2); | |
286 | QFETCH(int, axisCount); |
|
287 | QFETCH(int, axisCount); | |
287 | Q_UNUSED(axisCount); |
|
288 | Q_UNUSED(axisCount); | |
288 |
|
289 | |||
289 | m_dataset->addSeries(series0, axis0); |
|
290 | m_dataset->addSeries(series0, axis0); | |
290 | m_dataset->addSeries(series1, axis1); |
|
291 | m_dataset->addSeries(series1, axis1); | |
291 | m_dataset->addSeries(series2, axis2); |
|
292 | m_dataset->addSeries(series2, axis2); | |
292 |
|
293 | |||
293 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
294 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); | |
294 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
295 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); | |
295 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
296 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
296 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
297 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
297 |
|
298 | |||
298 | QCOMPARE(m_dataset->seriesCount(series0->type()),3); |
|
299 | QCOMPARE(m_dataset->seriesCount(series0->type()),3); | |
299 |
|
|
300 | TRY_COMPARE(spy0.count(), 0); | |
300 |
|
|
301 | TRY_COMPARE(spy1.count(), 0); | |
301 |
|
|
302 | TRY_COMPARE(spy2.count(), 0); | |
302 |
|
|
303 | TRY_COMPARE(spy3.count(), 0); | |
303 | } |
|
304 | } | |
304 |
|
305 | |||
305 | void tst_ChartDataSet::seriesIndex_data() |
|
306 | void tst_ChartDataSet::seriesIndex_data() | |
306 | { |
|
307 | { | |
307 | addSeries_data(); |
|
308 | addSeries_data(); | |
308 | } |
|
309 | } | |
309 |
|
310 | |||
310 | void tst_ChartDataSet::seriesIndex() |
|
311 | void tst_ChartDataSet::seriesIndex() | |
311 | { |
|
312 | { | |
312 | //TODO: rewrite this series_index_data to match better |
|
313 | //TODO: rewrite this series_index_data to match better | |
313 |
|
314 | |||
314 | QFETCH(QLineSeries*, series0); |
|
315 | QFETCH(QLineSeries*, series0); | |
315 | QFETCH(QAxis*, axis0); |
|
316 | QFETCH(QAxis*, axis0); | |
316 | QFETCH(QLineSeries*, series1); |
|
317 | QFETCH(QLineSeries*, series1); | |
317 | QFETCH(QAxis*, axis1); |
|
318 | QFETCH(QAxis*, axis1); | |
318 | QFETCH(QLineSeries*, series2); |
|
319 | QFETCH(QLineSeries*, series2); | |
319 | QFETCH(QAxis*, axis2); |
|
320 | QFETCH(QAxis*, axis2); | |
320 | QFETCH(int, axisCount); |
|
321 | QFETCH(int, axisCount); | |
321 | Q_UNUSED(axisCount); |
|
322 | Q_UNUSED(axisCount); | |
322 |
|
323 | |||
323 | m_dataset->addSeries(series0, axis0); |
|
324 | m_dataset->addSeries(series0, axis0); | |
324 | m_dataset->addSeries(series1, axis1); |
|
325 | m_dataset->addSeries(series1, axis1); | |
325 | m_dataset->addSeries(series2, axis2); |
|
326 | m_dataset->addSeries(series2, axis2); | |
326 |
|
327 | |||
327 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); |
|
328 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); | |
328 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); |
|
329 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); | |
329 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
330 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); | |
330 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
331 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
331 |
|
332 | |||
332 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
333 | QCOMPARE(m_dataset->seriesIndex(series0),0); | |
333 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
334 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
334 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
335 | QCOMPARE(m_dataset->seriesIndex(series2),2); | |
335 |
|
336 | |||
336 |
|
|
337 | TRY_COMPARE(spy0.count(), 0); | |
337 |
|
|
338 | TRY_COMPARE(spy1.count(), 0); | |
338 |
|
|
339 | TRY_COMPARE(spy2.count(), 0); | |
339 |
|
|
340 | TRY_COMPARE(spy3.count(), 0); | |
340 |
|
341 | |||
341 | m_dataset->removeSeries(series0); |
|
342 | m_dataset->removeSeries(series0); | |
342 | m_dataset->removeSeries(series1); |
|
343 | m_dataset->removeSeries(series1); | |
343 | m_dataset->removeSeries(series2); |
|
344 | m_dataset->removeSeries(series2); | |
344 |
|
345 | |||
345 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
346 | QCOMPARE(m_dataset->seriesIndex(series0),-1); | |
346 | QCOMPARE(m_dataset->seriesIndex(series1),-1); |
|
347 | QCOMPARE(m_dataset->seriesIndex(series1),-1); | |
347 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
348 | QCOMPARE(m_dataset->seriesIndex(series2),-1); | |
348 |
|
349 | |||
349 | m_dataset->addSeries(series0, axis0); |
|
350 | m_dataset->addSeries(series0, axis0); | |
350 | m_dataset->addSeries(series1, axis1); |
|
351 | m_dataset->addSeries(series1, axis1); | |
351 | m_dataset->addSeries(series2, axis2); |
|
352 | m_dataset->addSeries(series2, axis2); | |
352 |
|
353 | |||
353 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
354 | QCOMPARE(m_dataset->seriesIndex(series0),0); | |
354 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
355 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
355 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
356 | QCOMPARE(m_dataset->seriesIndex(series2),2); | |
356 |
|
357 | |||
357 | m_dataset->removeSeries(series1); |
|
358 | m_dataset->removeSeries(series1); | |
358 |
|
359 | |||
359 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
360 | QCOMPARE(m_dataset->seriesIndex(series0),0); | |
360 | QCOMPARE(m_dataset->seriesIndex(series1),-1); |
|
361 | QCOMPARE(m_dataset->seriesIndex(series1),-1); | |
361 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
362 | QCOMPARE(m_dataset->seriesIndex(series2),2); | |
362 |
|
363 | |||
363 | m_dataset->addSeries(series1, axis1); |
|
364 | m_dataset->addSeries(series1, axis1); | |
364 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
365 | QCOMPARE(m_dataset->seriesIndex(series0),0); | |
365 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
366 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
366 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
367 | QCOMPARE(m_dataset->seriesIndex(series2),2); | |
367 |
|
368 | |||
368 | m_dataset->removeSeries(series2); |
|
369 | m_dataset->removeSeries(series2); | |
369 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
370 | QCOMPARE(m_dataset->seriesIndex(series0),0); | |
370 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
371 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
371 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
372 | QCOMPARE(m_dataset->seriesIndex(series2),-1); | |
372 |
|
373 | |||
373 | m_dataset->removeSeries(series0); |
|
374 | m_dataset->removeSeries(series0); | |
374 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
375 | QCOMPARE(m_dataset->seriesIndex(series0),-1); | |
375 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
376 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
376 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
377 | QCOMPARE(m_dataset->seriesIndex(series2),-1); | |
377 |
|
378 | |||
378 | m_dataset->addSeries(series2); |
|
379 | m_dataset->addSeries(series2); | |
379 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
380 | QCOMPARE(m_dataset->seriesIndex(series0),-1); | |
380 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
381 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
381 | QCOMPARE(m_dataset->seriesIndex(series2),0); |
|
382 | QCOMPARE(m_dataset->seriesIndex(series2),0); | |
382 |
|
383 | |||
383 | m_dataset->addSeries(series0); |
|
384 | m_dataset->addSeries(series0); | |
384 | QCOMPARE(m_dataset->seriesIndex(series0),2); |
|
385 | QCOMPARE(m_dataset->seriesIndex(series0),2); | |
385 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
386 | QCOMPARE(m_dataset->seriesIndex(series1),1); | |
386 | QCOMPARE(m_dataset->seriesIndex(series2),0); |
|
387 | QCOMPARE(m_dataset->seriesIndex(series2),0); | |
387 | } |
|
388 | } | |
388 |
|
389 | |||
389 | void tst_ChartDataSet::domain_data() |
|
390 | void tst_ChartDataSet::domain_data() | |
390 | { |
|
391 | { | |
391 | addSeries_data(); |
|
392 | addSeries_data(); | |
392 | } |
|
393 | } | |
393 |
|
394 | |||
394 | void tst_ChartDataSet::domain() |
|
395 | void tst_ChartDataSet::domain() | |
395 | { |
|
396 | { | |
396 | QFETCH(QLineSeries*, series0); |
|
397 | QFETCH(QLineSeries*, series0); | |
397 | QFETCH(QAxis*, axis0); |
|
398 | QFETCH(QAxis*, axis0); | |
398 | QFETCH(QLineSeries*, series1); |
|
399 | QFETCH(QLineSeries*, series1); | |
399 | QFETCH(QAxis*, axis1); |
|
400 | QFETCH(QAxis*, axis1); | |
400 | QFETCH(QLineSeries*, series2); |
|
401 | QFETCH(QLineSeries*, series2); | |
401 | QFETCH(QAxis*, axis2); |
|
402 | QFETCH(QAxis*, axis2); | |
402 | QFETCH(int, axisCount); |
|
403 | QFETCH(int, axisCount); | |
403 | Q_UNUSED(axisCount); |
|
404 | Q_UNUSED(axisCount); | |
404 |
|
405 | |||
405 | m_dataset->addSeries(series0, axis0); |
|
406 | m_dataset->addSeries(series0, axis0); | |
406 | m_dataset->addSeries(series1, axis1); |
|
407 | m_dataset->addSeries(series1, axis1); | |
407 | m_dataset->addSeries(series2, axis2); |
|
408 | m_dataset->addSeries(series2, axis2); | |
408 |
|
409 | |||
409 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
410 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); | |
410 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
411 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); | |
411 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
412 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
412 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
413 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
413 |
|
414 | |||
414 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); |
|
415 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); | |
415 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); |
|
416 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); | |
416 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); |
|
417 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); | |
417 |
|
|
418 | TRY_COMPARE(spy0.count(), 0); | |
418 |
|
|
419 | TRY_COMPARE(spy1.count(), 0); | |
419 |
|
|
420 | TRY_COMPARE(spy2.count(), 0); | |
420 |
|
|
421 | TRY_COMPARE(spy3.count(), 0); | |
421 | } |
|
422 | } | |
422 |
|
423 | |||
423 | void tst_ChartDataSet::zoomInDomain_data() |
|
424 | void tst_ChartDataSet::zoomInDomain_data() | |
424 | { |
|
425 | { | |
425 | addSeries_data(); |
|
426 | addSeries_data(); | |
426 | } |
|
427 | } | |
427 |
|
428 | |||
428 | void tst_ChartDataSet::zoomInDomain() |
|
429 | void tst_ChartDataSet::zoomInDomain() | |
429 | { |
|
430 | { | |
430 | QFETCH(QLineSeries*, series0); |
|
431 | QFETCH(QLineSeries*, series0); | |
431 | QFETCH(QAxis*, axis0); |
|
432 | QFETCH(QAxis*, axis0); | |
432 | QFETCH(QLineSeries*, series1); |
|
433 | QFETCH(QLineSeries*, series1); | |
433 | QFETCH(QAxis*, axis1); |
|
434 | QFETCH(QAxis*, axis1); | |
434 | QFETCH(QLineSeries*, series2); |
|
435 | QFETCH(QLineSeries*, series2); | |
435 | QFETCH(QAxis*, axis2); |
|
436 | QFETCH(QAxis*, axis2); | |
436 | QFETCH(int, axisCount); |
|
437 | QFETCH(int, axisCount); | |
437 | Q_UNUSED(axisCount); |
|
438 | Q_UNUSED(axisCount); | |
438 |
|
439 | |||
439 | m_dataset->addSeries(series0, axis0); |
|
440 | m_dataset->addSeries(series0, axis0); | |
440 | m_dataset->addSeries(series1, axis1); |
|
441 | m_dataset->addSeries(series1, axis1); | |
441 | m_dataset->addSeries(series2, axis2); |
|
442 | m_dataset->addSeries(series2, axis2); | |
442 |
|
443 | |||
443 | Domain* domain0 = m_dataset->domain(series0); |
|
444 | Domain* domain0 = m_dataset->domain(series0); | |
444 | Domain* domain1 = m_dataset->domain(series1); |
|
445 | Domain* domain1 = m_dataset->domain(series1); | |
445 | Domain* domain2 = m_dataset->domain(series2); |
|
446 | Domain* domain2 = m_dataset->domain(series2); | |
446 |
|
447 | |||
447 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
448 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
448 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
449 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
449 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
450 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
450 |
|
451 | |||
451 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
452 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
452 |
|
453 | |||
453 |
|
|
454 | TRY_COMPARE(spy0.count(), 1); | |
454 |
|
|
455 | TRY_COMPARE(spy1.count(), 1); | |
455 |
|
|
456 | TRY_COMPARE(spy2.count(), 1); | |
456 | } |
|
457 | } | |
457 |
|
458 | |||
458 | void tst_ChartDataSet::zoomOutDomain_data() |
|
459 | void tst_ChartDataSet::zoomOutDomain_data() | |
459 | { |
|
460 | { | |
460 | addSeries_data(); |
|
461 | addSeries_data(); | |
461 | } |
|
462 | } | |
462 |
|
463 | |||
463 | void tst_ChartDataSet::zoomOutDomain() |
|
464 | void tst_ChartDataSet::zoomOutDomain() | |
464 | { |
|
465 | { | |
465 | QFETCH(QLineSeries*, series0); |
|
466 | QFETCH(QLineSeries*, series0); | |
466 | QFETCH(QAxis*, axis0); |
|
467 | QFETCH(QAxis*, axis0); | |
467 | QFETCH(QLineSeries*, series1); |
|
468 | QFETCH(QLineSeries*, series1); | |
468 | QFETCH(QAxis*, axis1); |
|
469 | QFETCH(QAxis*, axis1); | |
469 | QFETCH(QLineSeries*, series2); |
|
470 | QFETCH(QLineSeries*, series2); | |
470 | QFETCH(QAxis*, axis2); |
|
471 | QFETCH(QAxis*, axis2); | |
471 | QFETCH(int, axisCount); |
|
472 | QFETCH(int, axisCount); | |
472 |
|
473 | |||
473 | Q_UNUSED(axisCount); |
|
474 | Q_UNUSED(axisCount); | |
474 |
|
475 | |||
475 | m_dataset->addSeries(series0, axis0); |
|
476 | m_dataset->addSeries(series0, axis0); | |
476 | m_dataset->addSeries(series1, axis1); |
|
477 | m_dataset->addSeries(series1, axis1); | |
477 | m_dataset->addSeries(series2, axis2); |
|
478 | m_dataset->addSeries(series2, axis2); | |
478 |
|
479 | |||
479 | Domain* domain0 = m_dataset->domain(series0); |
|
480 | Domain* domain0 = m_dataset->domain(series0); | |
480 | Domain* domain1 = m_dataset->domain(series1); |
|
481 | Domain* domain1 = m_dataset->domain(series1); | |
481 | Domain* domain2 = m_dataset->domain(series2); |
|
482 | Domain* domain2 = m_dataset->domain(series2); | |
482 |
|
483 | |||
483 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
484 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
484 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
485 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
485 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
486 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
486 |
|
487 | |||
487 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
488 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
488 |
|
489 | |||
489 |
|
|
490 | TRY_COMPARE(spy0.count(), 1); | |
490 |
|
|
491 | TRY_COMPARE(spy1.count(), 1); | |
491 |
|
|
492 | TRY_COMPARE(spy2.count(), 1); | |
492 | } |
|
493 | } | |
493 |
|
494 | |||
494 | void tst_ChartDataSet::scrollDomain_data() |
|
495 | void tst_ChartDataSet::scrollDomain_data() | |
495 | { |
|
496 | { | |
496 | addSeries_data(); |
|
497 | addSeries_data(); | |
497 | } |
|
498 | } | |
498 |
|
499 | |||
499 | void tst_ChartDataSet::scrollDomain() |
|
500 | void tst_ChartDataSet::scrollDomain() | |
500 | { |
|
501 | { | |
501 | QFETCH(QLineSeries*, series0); |
|
502 | QFETCH(QLineSeries*, series0); | |
502 | QFETCH(QAxis*, axis0); |
|
503 | QFETCH(QAxis*, axis0); | |
503 | QFETCH(QLineSeries*, series1); |
|
504 | QFETCH(QLineSeries*, series1); | |
504 | QFETCH(QAxis*, axis1); |
|
505 | QFETCH(QAxis*, axis1); | |
505 | QFETCH(QLineSeries*, series2); |
|
506 | QFETCH(QLineSeries*, series2); | |
506 | QFETCH(QAxis*, axis2); |
|
507 | QFETCH(QAxis*, axis2); | |
507 | QFETCH(int, axisCount); |
|
508 | QFETCH(int, axisCount); | |
508 |
|
509 | |||
509 | Q_UNUSED(axisCount); |
|
510 | Q_UNUSED(axisCount); | |
510 |
|
511 | |||
511 | m_dataset->addSeries(series0, axis0); |
|
512 | m_dataset->addSeries(series0, axis0); | |
512 | m_dataset->addSeries(series1, axis1); |
|
513 | m_dataset->addSeries(series1, axis1); | |
513 | m_dataset->addSeries(series2, axis2); |
|
514 | m_dataset->addSeries(series2, axis2); | |
514 |
|
515 | |||
515 | Domain* domain0 = m_dataset->domain(series0); |
|
516 | Domain* domain0 = m_dataset->domain(series0); | |
516 | Domain* domain1 = m_dataset->domain(series1); |
|
517 | Domain* domain1 = m_dataset->domain(series1); | |
517 | Domain* domain2 = m_dataset->domain(series2); |
|
518 | Domain* domain2 = m_dataset->domain(series2); | |
518 |
|
519 | |||
519 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
520 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
520 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
521 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
521 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
522 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
522 |
|
523 | |||
523 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
524 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); | |
524 |
|
525 | |||
525 |
|
|
526 | TRY_COMPARE(spy0.count(), 1); | |
526 |
|
|
527 | TRY_COMPARE(spy1.count(), 1); | |
527 |
|
|
528 | TRY_COMPARE(spy2.count(), 1); | |
528 | } |
|
529 | } | |
529 |
|
530 | |||
530 | QTEST_MAIN(tst_ChartDataSet) |
|
531 | QTEST_MAIN(tst_ChartDataSet) | |
531 | #include "tst_chartdataset.moc" |
|
532 | #include "tst_chartdataset.moc" | |
532 |
|
533 |
@@ -1,712 +1,712 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <private/domain_p.h> |
|
22 | #include <private/domain_p.h> | |
23 | #include <qaxis.h> |
|
23 | #include <qaxis.h> | |
|
24 | #include <tst_definitions.h> | |||
24 |
|
25 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
27 | |||
27 | Q_DECLARE_METATYPE(Domain*) |
|
28 | Q_DECLARE_METATYPE(Domain*) | |
28 | Q_DECLARE_METATYPE(QSizeF) |
|
29 | Q_DECLARE_METATYPE(QSizeF) | |
29 |
|
30 | |||
30 | class tst_Domain: public QObject |
|
31 | class tst_Domain: public QObject | |
31 | { |
|
32 | { | |
32 | Q_OBJECT |
|
33 | Q_OBJECT | |
33 |
|
34 | |||
34 | public Q_SLOTS: |
|
35 | public Q_SLOTS: | |
35 | void initTestCase(); |
|
36 | void initTestCase(); | |
36 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
37 | void init(); |
|
38 | void init(); | |
38 | void cleanup(); |
|
39 | void cleanup(); | |
39 |
|
40 | |||
40 | private Q_SLOTS: |
|
41 | private Q_SLOTS: | |
41 | void domain(); |
|
42 | void domain(); | |
42 | void handleAxisRangeXChanged_data(); |
|
43 | void handleAxisRangeXChanged_data(); | |
43 | void handleAxisRangeXChanged(); |
|
44 | void handleAxisRangeXChanged(); | |
44 | void handleAxisRangeYChanged_data(); |
|
45 | void handleAxisRangeYChanged_data(); | |
45 | void handleAxisRangeYChanged(); |
|
46 | void handleAxisRangeYChanged(); | |
46 | void isEmpty_data(); |
|
47 | void isEmpty_data(); | |
47 | void isEmpty(); |
|
48 | void isEmpty(); | |
48 | void maxX_data(); |
|
49 | void maxX_data(); | |
49 | void maxX(); |
|
50 | void maxX(); | |
50 | void maxY_data(); |
|
51 | void maxY_data(); | |
51 | void maxY(); |
|
52 | void maxY(); | |
52 | void minX_data(); |
|
53 | void minX_data(); | |
53 | void minX(); |
|
54 | void minX(); | |
54 | void minY_data(); |
|
55 | void minY_data(); | |
55 | void minY(); |
|
56 | void minY(); | |
56 | void operatorEquals_data(); |
|
57 | void operatorEquals_data(); | |
57 | void operatorEquals(); |
|
58 | void operatorEquals(); | |
58 | void setRange_data(); |
|
59 | void setRange_data(); | |
59 | void setRange(); |
|
60 | void setRange(); | |
60 | void setRangeX_data(); |
|
61 | void setRangeX_data(); | |
61 | void setRangeX(); |
|
62 | void setRangeX(); | |
62 | void setRangeY_data(); |
|
63 | void setRangeY_data(); | |
63 | void setRangeY(); |
|
64 | void setRangeY(); | |
64 | void spanX_data(); |
|
65 | void spanX_data(); | |
65 | void spanX(); |
|
66 | void spanX(); | |
66 | void spanY_data(); |
|
67 | void spanY_data(); | |
67 | void spanY(); |
|
68 | void spanY(); | |
68 | void zoom_data(); |
|
69 | void zoom_data(); | |
69 | void zoom(); |
|
70 | void zoom(); | |
70 | void move_data(); |
|
71 | void move_data(); | |
71 | void move(); |
|
72 | void move(); | |
72 | void handleAxisXChanged_data(); |
|
73 | void handleAxisXChanged_data(); | |
73 | void handleAxisXChanged(); |
|
74 | void handleAxisXChanged(); | |
74 | void handleAxisYChanged_data(); |
|
75 | void handleAxisYChanged_data(); | |
75 | void handleAxisYChanged(); |
|
76 | void handleAxisYChanged(); | |
76 | }; |
|
77 | }; | |
77 |
|
78 | |||
78 | void tst_Domain::initTestCase() |
|
79 | void tst_Domain::initTestCase() | |
79 | { |
|
80 | { | |
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | void tst_Domain::cleanupTestCase() |
|
83 | void tst_Domain::cleanupTestCase() | |
83 | { |
|
84 | { | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | void tst_Domain::init() |
|
87 | void tst_Domain::init() | |
87 | { |
|
88 | { | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | void tst_Domain::cleanup() |
|
91 | void tst_Domain::cleanup() | |
91 | { |
|
92 | { | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | void tst_Domain::domain() |
|
95 | void tst_Domain::domain() | |
95 | { |
|
96 | { | |
96 | Domain domain; |
|
97 | Domain domain; | |
97 |
|
98 | |||
98 | QCOMPARE(domain.isEmpty(), true); |
|
99 | QCOMPARE(domain.isEmpty(), true); | |
99 | QCOMPARE(domain.maxX(), 0.0); |
|
100 | QCOMPARE(domain.maxX(), 0.0); | |
100 | QCOMPARE(domain.maxY(), 0.0); |
|
101 | QCOMPARE(domain.maxY(), 0.0); | |
101 | QCOMPARE(domain.minX(), 0.0); |
|
102 | QCOMPARE(domain.minX(), 0.0); | |
102 | QCOMPARE(domain.minY(), 0.0); |
|
103 | QCOMPARE(domain.minY(), 0.0); | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | void tst_Domain::handleAxisRangeXChanged_data() |
|
106 | void tst_Domain::handleAxisRangeXChanged_data() | |
106 | { |
|
107 | { | |
107 | QTest::addColumn<qreal>("min"); |
|
108 | QTest::addColumn<qreal>("min"); | |
108 | QTest::addColumn<qreal>("max"); |
|
109 | QTest::addColumn<qreal>("max"); | |
109 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
110 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
110 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
111 | QTest::newRow("0 1") << 0.0 << 1.0; | |
111 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
112 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | void tst_Domain::handleAxisRangeXChanged() |
|
115 | void tst_Domain::handleAxisRangeXChanged() | |
115 | { |
|
116 | { | |
116 | QFETCH(qreal, min); |
|
117 | QFETCH(qreal, min); | |
117 | QFETCH(qreal, max); |
|
118 | QFETCH(qreal, max); | |
118 |
|
119 | |||
119 | Domain domain; |
|
120 | Domain domain; | |
120 |
|
121 | |||
121 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
122 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
122 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
123 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
123 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
124 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
124 |
|
125 | |||
125 | domain.handleAxisXChanged(min, max); |
|
126 | domain.handleAxisXChanged(min, max); | |
126 |
|
127 | |||
127 | QList<QVariant> arg0 = spy0.first(); |
|
128 | QList<QVariant> arg0 = spy0.first(); | |
128 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
129 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); | |
129 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
130 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); | |
130 |
|
131 | |||
131 | QList<QVariant> arg1 = spy1.first(); |
|
132 | QList<QVariant> arg1 = spy1.first(); | |
132 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
133 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
133 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
134 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
134 |
|
135 | |||
135 |
|
|
136 | TRY_COMPARE(spy0.count(), 1); | |
136 |
|
|
137 | TRY_COMPARE(spy1.count(), 1); | |
137 |
|
|
138 | TRY_COMPARE(spy2.count(), 0); | |
138 |
|
139 | |||
139 | } |
|
140 | } | |
140 |
|
141 | |||
141 | void tst_Domain::handleAxisRangeYChanged_data() |
|
142 | void tst_Domain::handleAxisRangeYChanged_data() | |
142 | { |
|
143 | { | |
143 | QTest::addColumn<qreal>("min"); |
|
144 | QTest::addColumn<qreal>("min"); | |
144 | QTest::addColumn<qreal>("max"); |
|
145 | QTest::addColumn<qreal>("max"); | |
145 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
146 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
146 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
147 | QTest::newRow("0 1") << 0.0 << 1.0; | |
147 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
148 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
148 | } |
|
149 | } | |
149 |
|
150 | |||
150 | void tst_Domain::handleAxisRangeYChanged() |
|
151 | void tst_Domain::handleAxisRangeYChanged() | |
151 | { |
|
152 | { | |
152 | QFETCH(qreal, min); |
|
153 | QFETCH(qreal, min); | |
153 | QFETCH(qreal, max); |
|
154 | QFETCH(qreal, max); | |
154 |
|
155 | |||
155 | Domain domain; |
|
156 | Domain domain; | |
156 |
|
157 | |||
157 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
158 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
158 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
159 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
159 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
160 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
160 |
|
161 | |||
161 | domain.handleAxisYChanged(min, max, 5); |
|
162 | domain.handleAxisYChanged(min, max, 5); | |
162 |
|
163 | |||
163 | QList<QVariant> arg0 = spy0.first(); |
|
164 | QList<QVariant> arg0 = spy0.first(); | |
164 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
165 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); | |
165 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
166 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); | |
166 |
|
167 | |||
167 | QList<QVariant> arg1 = spy2.first(); |
|
168 | QList<QVariant> arg1 = spy2.first(); | |
168 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
169 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
169 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
170 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
170 |
|
171 | |||
171 |
|
|
172 | TRY_COMPARE(spy0.count(), 1); | |
172 |
|
|
173 | TRY_COMPARE(spy1.count(), 0); | |
173 |
|
|
174 | TRY_COMPARE(spy2.count(), 1); | |
174 | } |
|
175 | } | |
175 |
|
176 | |||
176 | void tst_Domain::isEmpty_data() |
|
177 | void tst_Domain::isEmpty_data() | |
177 | { |
|
178 | { | |
178 | QTest::addColumn<qreal>("minX"); |
|
179 | QTest::addColumn<qreal>("minX"); | |
179 | QTest::addColumn<qreal>("maxX"); |
|
180 | QTest::addColumn<qreal>("maxX"); | |
180 | QTest::addColumn<qreal>("minY"); |
|
181 | QTest::addColumn<qreal>("minY"); | |
181 | QTest::addColumn<qreal>("maxY"); |
|
182 | QTest::addColumn<qreal>("maxY"); | |
182 | QTest::addColumn<bool>("isEmpty"); |
|
183 | QTest::addColumn<bool>("isEmpty"); | |
183 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
184 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; | |
184 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
185 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |
185 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
186 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |
186 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
187 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | void tst_Domain::isEmpty() |
|
190 | void tst_Domain::isEmpty() | |
190 | { |
|
191 | { | |
191 | QFETCH(qreal, minX); |
|
192 | QFETCH(qreal, minX); | |
192 | QFETCH(qreal, maxX); |
|
193 | QFETCH(qreal, maxX); | |
193 | QFETCH(qreal, minY); |
|
194 | QFETCH(qreal, minY); | |
194 | QFETCH(qreal, maxY); |
|
195 | QFETCH(qreal, maxY); | |
195 | QFETCH(bool, isEmpty); |
|
196 | QFETCH(bool, isEmpty); | |
196 |
|
197 | |||
197 | Domain domain; |
|
198 | Domain domain; | |
198 | domain.setRange(minX, maxX, minY, maxY); |
|
199 | domain.setRange(minX, maxX, minY, maxY); | |
199 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
200 | QCOMPARE(domain.isEmpty(), isEmpty); | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | void tst_Domain::maxX_data() |
|
203 | void tst_Domain::maxX_data() | |
203 | { |
|
204 | { | |
204 | QTest::addColumn<qreal>("maxX1"); |
|
205 | QTest::addColumn<qreal>("maxX1"); | |
205 | QTest::addColumn<qreal>("maxX2"); |
|
206 | QTest::addColumn<qreal>("maxX2"); | |
206 | QTest::addColumn<int>("count"); |
|
207 | QTest::addColumn<int>("count"); | |
207 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
208 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
208 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
209 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
209 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
210 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
210 | } |
|
211 | } | |
211 |
|
212 | |||
212 | void tst_Domain::maxX() |
|
213 | void tst_Domain::maxX() | |
213 | { |
|
214 | { | |
214 | QFETCH(qreal, maxX1); |
|
215 | QFETCH(qreal, maxX1); | |
215 | QFETCH(qreal, maxX2); |
|
216 | QFETCH(qreal, maxX2); | |
216 | QFETCH(int, count); |
|
217 | QFETCH(int, count); | |
217 |
|
218 | |||
218 | Domain domain; |
|
219 | Domain domain; | |
219 |
|
220 | |||
220 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
221 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
221 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
222 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
222 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
223 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
223 |
|
224 | |||
224 | domain.setMaxX(maxX1); |
|
225 | domain.setMaxX(maxX1); | |
225 | QCOMPARE(domain.maxX(), maxX1); |
|
226 | QCOMPARE(domain.maxX(), maxX1); | |
226 | domain.setMaxX(maxX2); |
|
227 | domain.setMaxX(maxX2); | |
227 | QCOMPARE(domain.maxX(), maxX2); |
|
228 | QCOMPARE(domain.maxX(), maxX2); | |
228 |
|
229 | |||
229 |
|
|
230 | TRY_COMPARE(spy0.count(), count); | |
230 |
|
|
231 | TRY_COMPARE(spy1.count(), count); | |
231 |
|
|
232 | TRY_COMPARE(spy2.count(), 0); | |
232 |
|
233 | |||
233 | } |
|
234 | } | |
234 |
|
235 | |||
235 | void tst_Domain::maxY_data() |
|
236 | void tst_Domain::maxY_data() | |
236 | { |
|
237 | { | |
237 | QTest::addColumn<qreal>("maxY1"); |
|
238 | QTest::addColumn<qreal>("maxY1"); | |
238 | QTest::addColumn<qreal>("maxY2"); |
|
239 | QTest::addColumn<qreal>("maxY2"); | |
239 | QTest::addColumn<int>("count"); |
|
240 | QTest::addColumn<int>("count"); | |
240 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
241 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
241 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
242 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
242 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
243 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
243 | } |
|
244 | } | |
244 |
|
245 | |||
245 | void tst_Domain::maxY() |
|
246 | void tst_Domain::maxY() | |
246 | { |
|
247 | { | |
247 | QFETCH(qreal, maxY1); |
|
248 | QFETCH(qreal, maxY1); | |
248 | QFETCH(qreal, maxY2); |
|
249 | QFETCH(qreal, maxY2); | |
249 | QFETCH(int, count); |
|
250 | QFETCH(int, count); | |
250 |
|
251 | |||
251 | Domain domain; |
|
252 | Domain domain; | |
252 |
|
253 | |||
253 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
254 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
254 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
255 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
255 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
256 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
256 |
|
257 | |||
257 | domain.setMaxY(maxY1); |
|
258 | domain.setMaxY(maxY1); | |
258 | QCOMPARE(domain.maxY(), maxY1); |
|
259 | QCOMPARE(domain.maxY(), maxY1); | |
259 | domain.setMaxY(maxY2); |
|
260 | domain.setMaxY(maxY2); | |
260 | QCOMPARE(domain.maxY(), maxY2); |
|
261 | QCOMPARE(domain.maxY(), maxY2); | |
261 |
|
262 | |||
262 |
|
|
263 | TRY_COMPARE(spy0.count(), count); | |
263 |
|
|
264 | TRY_COMPARE(spy1.count(), 0); | |
264 |
|
|
265 | TRY_COMPARE(spy2.count(), count); | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | void tst_Domain::minX_data() |
|
268 | void tst_Domain::minX_data() | |
268 | { |
|
269 | { | |
269 | QTest::addColumn<qreal>("minX1"); |
|
270 | QTest::addColumn<qreal>("minX1"); | |
270 | QTest::addColumn<qreal>("minX2"); |
|
271 | QTest::addColumn<qreal>("minX2"); | |
271 | QTest::addColumn<int>("count"); |
|
272 | QTest::addColumn<int>("count"); | |
272 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
273 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
273 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
274 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
274 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
275 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
275 | } |
|
276 | } | |
276 |
|
277 | |||
277 | void tst_Domain::minX() |
|
278 | void tst_Domain::minX() | |
278 | { |
|
279 | { | |
279 | QFETCH(qreal, minX1); |
|
280 | QFETCH(qreal, minX1); | |
280 | QFETCH(qreal, minX2); |
|
281 | QFETCH(qreal, minX2); | |
281 | QFETCH(int, count); |
|
282 | QFETCH(int, count); | |
282 |
|
283 | |||
283 | Domain domain; |
|
284 | Domain domain; | |
284 |
|
285 | |||
285 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
286 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
286 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
287 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
287 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
288 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
288 |
|
289 | |||
289 | domain.setMinX(minX1); |
|
290 | domain.setMinX(minX1); | |
290 | QCOMPARE(domain.minX(), minX1); |
|
291 | QCOMPARE(domain.minX(), minX1); | |
291 | domain.setMinX(minX2); |
|
292 | domain.setMinX(minX2); | |
292 | QCOMPARE(domain.minX(), minX2); |
|
293 | QCOMPARE(domain.minX(), minX2); | |
293 |
|
294 | |||
294 |
|
|
295 | TRY_COMPARE(spy0.count(), count); | |
295 |
|
|
296 | TRY_COMPARE(spy1.count(), count); | |
296 |
|
|
297 | TRY_COMPARE(spy2.count(), 0); | |
297 | } |
|
298 | } | |
298 |
|
299 | |||
299 | void tst_Domain::minY_data() |
|
300 | void tst_Domain::minY_data() | |
300 | { |
|
301 | { | |
301 | QTest::addColumn<qreal>("minY1"); |
|
302 | QTest::addColumn<qreal>("minY1"); | |
302 | QTest::addColumn<qreal>("minY2"); |
|
303 | QTest::addColumn<qreal>("minY2"); | |
303 | QTest::addColumn<int>("count"); |
|
304 | QTest::addColumn<int>("count"); | |
304 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
305 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |
305 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
306 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |
306 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
307 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |
307 | } |
|
308 | } | |
308 |
|
309 | |||
309 | void tst_Domain::minY() |
|
310 | void tst_Domain::minY() | |
310 | { |
|
311 | { | |
311 | QFETCH(qreal, minY1); |
|
312 | QFETCH(qreal, minY1); | |
312 | QFETCH(qreal, minY2); |
|
313 | QFETCH(qreal, minY2); | |
313 | QFETCH(int, count); |
|
314 | QFETCH(int, count); | |
314 |
|
315 | |||
315 | Domain domain; |
|
316 | Domain domain; | |
316 |
|
317 | |||
317 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
318 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
318 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
319 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
319 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
320 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
320 |
|
321 | |||
321 | domain.setMinY(minY1); |
|
322 | domain.setMinY(minY1); | |
322 | QCOMPARE(domain.minY(), minY1); |
|
323 | QCOMPARE(domain.minY(), minY1); | |
323 | domain.setMinY(minY2); |
|
324 | domain.setMinY(minY2); | |
324 | QCOMPARE(domain.minY(), minY2); |
|
325 | QCOMPARE(domain.minY(), minY2); | |
325 |
|
326 | |||
326 |
|
|
327 | TRY_COMPARE(spy0.count(), count); | |
327 |
|
|
328 | TRY_COMPARE(spy1.count(), 0); | |
328 |
|
|
329 | TRY_COMPARE(spy2.count(), count); | |
329 | } |
|
330 | } | |
330 |
|
331 | |||
331 | void tst_Domain::operatorEquals_data() |
|
332 | void tst_Domain::operatorEquals_data() | |
332 | { |
|
333 | { | |
333 |
|
334 | |||
334 | QTest::addColumn<Domain*>("domain1"); |
|
335 | QTest::addColumn<Domain*>("domain1"); | |
335 | QTest::addColumn<Domain*>("domain2"); |
|
336 | QTest::addColumn<Domain*>("domain2"); | |
336 | QTest::addColumn<bool>("equals"); |
|
337 | QTest::addColumn<bool>("equals"); | |
337 | QTest::addColumn<bool>("notEquals"); |
|
338 | QTest::addColumn<bool>("notEquals"); | |
338 | Domain* a; |
|
339 | Domain* a; | |
339 | Domain* b; |
|
340 | Domain* b; | |
340 | a = new Domain(); |
|
341 | a = new Domain(); | |
341 | a->setRange(0, 100, 0, 100); |
|
342 | a->setRange(0, 100, 0, 100); | |
342 | b = new Domain(); |
|
343 | b = new Domain(); | |
343 | b->setRange(0, 100, 0, 100); |
|
344 | b->setRange(0, 100, 0, 100); | |
344 | QTest::newRow("equals") << a << b << true << false; |
|
345 | QTest::newRow("equals") << a << b << true << false; | |
345 | a = new Domain(); |
|
346 | a = new Domain(); | |
346 | a->setRange(0, 100, 0, 100); |
|
347 | a->setRange(0, 100, 0, 100); | |
347 | b = new Domain(); |
|
348 | b = new Domain(); | |
348 | b->setRange(0, 100, 0, 1); |
|
349 | b->setRange(0, 100, 0, 1); | |
349 | QTest::newRow("equals") << a << b << false << true; |
|
350 | QTest::newRow("equals") << a << b << false << true; | |
350 | a = new Domain(); |
|
351 | a = new Domain(); | |
351 | a->setRange(0, 100, 0, 100); |
|
352 | a->setRange(0, 100, 0, 100); | |
352 | b = new Domain(); |
|
353 | b = new Domain(); | |
353 | b->setRange(0, 1, 0, 100); |
|
354 | b->setRange(0, 1, 0, 100); | |
354 | QTest::newRow("equals") << a << b << false << true; |
|
355 | QTest::newRow("equals") << a << b << false << true; | |
355 |
|
356 | |||
356 | } |
|
357 | } | |
357 |
|
358 | |||
358 | void tst_Domain::operatorEquals() |
|
359 | void tst_Domain::operatorEquals() | |
359 | { |
|
360 | { | |
360 | QFETCH(Domain*, domain1); |
|
361 | QFETCH(Domain*, domain1); | |
361 | QFETCH(Domain*, domain2); |
|
362 | QFETCH(Domain*, domain2); | |
362 | QFETCH(bool, equals); |
|
363 | QFETCH(bool, equals); | |
363 | QFETCH(bool, notEquals); |
|
364 | QFETCH(bool, notEquals); | |
364 |
|
365 | |||
365 | Domain domain; |
|
366 | Domain domain; | |
366 |
|
367 | |||
367 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
368 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
368 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
369 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
369 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
370 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
370 |
|
371 | |||
371 | QCOMPARE(*domain1==*domain2, equals); |
|
372 | QCOMPARE(*domain1==*domain2, equals); | |
372 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
373 | QCOMPARE(*domain1!=*domain2, notEquals); | |
373 |
|
374 | |||
374 |
|
|
375 | TRY_COMPARE(spy0.count(), 0); | |
375 |
|
|
376 | TRY_COMPARE(spy1.count(), 0); | |
376 |
|
|
377 | TRY_COMPARE(spy2.count(), 0); | |
377 | } |
|
378 | } | |
378 |
|
379 | |||
379 | void tst_Domain::setRange_data() |
|
380 | void tst_Domain::setRange_data() | |
380 | { |
|
381 | { | |
381 | QTest::addColumn<qreal>("minX"); |
|
382 | QTest::addColumn<qreal>("minX"); | |
382 | QTest::addColumn<qreal>("maxX"); |
|
383 | QTest::addColumn<qreal>("maxX"); | |
383 | QTest::addColumn<qreal>("minY"); |
|
384 | QTest::addColumn<qreal>("minY"); | |
384 | QTest::addColumn<qreal>("maxY"); |
|
385 | QTest::addColumn<qreal>("maxY"); | |
385 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
386 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; | |
386 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
387 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; | |
387 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
388 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; | |
388 | } |
|
389 | } | |
389 |
|
390 | |||
390 | void tst_Domain::setRange() |
|
391 | void tst_Domain::setRange() | |
391 | { |
|
392 | { | |
392 | QFETCH(qreal, minX); |
|
393 | QFETCH(qreal, minX); | |
393 | QFETCH(qreal, maxX); |
|
394 | QFETCH(qreal, maxX); | |
394 | QFETCH(qreal, minY); |
|
395 | QFETCH(qreal, minY); | |
395 | QFETCH(qreal, maxY); |
|
396 | QFETCH(qreal, maxY); | |
396 |
|
397 | |||
397 | Domain domain; |
|
398 | Domain domain; | |
398 |
|
399 | |||
399 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
400 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
400 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
401 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
401 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
402 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
402 |
|
403 | |||
403 | domain.setRange(minX, maxX, minY, maxY); |
|
404 | domain.setRange(minX, maxX, minY, maxY); | |
404 |
|
405 | |||
405 | QCOMPARE(domain.minX(), minX); |
|
406 | QCOMPARE(domain.minX(), minX); | |
406 | QCOMPARE(domain.maxX(), maxX); |
|
407 | QCOMPARE(domain.maxX(), maxX); | |
407 | QCOMPARE(domain.minY(), minY); |
|
408 | QCOMPARE(domain.minY(), minY); | |
408 | QCOMPARE(domain.maxY(), maxY); |
|
409 | QCOMPARE(domain.maxY(), maxY); | |
409 |
|
410 | |||
410 |
|
|
411 | TRY_COMPARE(spy0.count(), 1); | |
411 |
|
|
412 | TRY_COMPARE(spy1.count(), 1); | |
412 |
|
|
413 | TRY_COMPARE(spy2.count(), 1); | |
413 |
|
414 | |||
414 | } |
|
415 | } | |
415 |
|
416 | |||
416 | void tst_Domain::setRangeX_data() |
|
417 | void tst_Domain::setRangeX_data() | |
417 | { |
|
418 | { | |
418 | QTest::addColumn<qreal>("min"); |
|
419 | QTest::addColumn<qreal>("min"); | |
419 | QTest::addColumn<qreal>("max"); |
|
420 | QTest::addColumn<qreal>("max"); | |
420 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
421 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
421 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
422 | QTest::newRow("0 1") << 0.0 << 1.0; | |
422 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
423 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
423 | } |
|
424 | } | |
424 |
|
425 | |||
425 | void tst_Domain::setRangeX() |
|
426 | void tst_Domain::setRangeX() | |
426 | { |
|
427 | { | |
427 | QFETCH(qreal, min); |
|
428 | QFETCH(qreal, min); | |
428 | QFETCH(qreal, max); |
|
429 | QFETCH(qreal, max); | |
429 |
|
430 | |||
430 | Domain domain; |
|
431 | Domain domain; | |
431 |
|
432 | |||
432 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
433 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
433 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
434 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
434 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
435 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
435 |
|
436 | |||
436 | domain.setRangeX(min, max); |
|
437 | domain.setRangeX(min, max); | |
437 |
|
438 | |||
438 | QList<QVariant> arg0 = spy0.first(); |
|
439 | QList<QVariant> arg0 = spy0.first(); | |
439 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
440 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); | |
440 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
441 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); | |
441 |
|
442 | |||
442 | QList<QVariant> arg1 = spy1.first(); |
|
443 | QList<QVariant> arg1 = spy1.first(); | |
443 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
444 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
444 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
445 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
445 |
|
446 | |||
446 |
|
|
447 | TRY_COMPARE(spy0.count(), 1); | |
447 |
|
|
448 | TRY_COMPARE(spy1.count(), 1); | |
448 |
|
|
449 | TRY_COMPARE(spy2.count(), 0); | |
449 | } |
|
450 | } | |
450 |
|
451 | |||
451 | void tst_Domain::setRangeY_data() |
|
452 | void tst_Domain::setRangeY_data() | |
452 | { |
|
453 | { | |
453 | QTest::addColumn<qreal>("min"); |
|
454 | QTest::addColumn<qreal>("min"); | |
454 | QTest::addColumn<qreal>("max"); |
|
455 | QTest::addColumn<qreal>("max"); | |
455 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
456 | QTest::newRow("-1 1") << -1.0 << 1.0; | |
456 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
457 | QTest::newRow("0 1") << 0.0 << 1.0; | |
457 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
458 | QTest::newRow("-1 0") << -1.0 << 0.0; | |
458 | } |
|
459 | } | |
459 |
|
460 | |||
460 | void tst_Domain::setRangeY() |
|
461 | void tst_Domain::setRangeY() | |
461 | { |
|
462 | { | |
462 | QFETCH(qreal, min); |
|
463 | QFETCH(qreal, min); | |
463 | QFETCH(qreal, max); |
|
464 | QFETCH(qreal, max); | |
464 |
|
465 | |||
465 | Domain domain; |
|
466 | Domain domain; | |
466 |
|
467 | |||
467 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
468 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
468 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
469 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
469 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
470 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
470 |
|
471 | |||
471 | domain.setRangeY(min, max); |
|
472 | domain.setRangeY(min, max); | |
472 |
|
473 | |||
473 | QList<QVariant> arg0 = spy0.first(); |
|
474 | QList<QVariant> arg0 = spy0.first(); | |
474 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
475 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); | |
475 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
476 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); | |
476 |
|
477 | |||
477 | QList<QVariant> arg1 = spy2.first(); |
|
478 | QList<QVariant> arg1 = spy2.first(); | |
478 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
479 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); | |
479 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
480 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); | |
480 |
|
481 | |||
481 |
|
|
482 | TRY_COMPARE(spy0.count(), 1); | |
482 |
|
|
483 | TRY_COMPARE(spy1.count(), 0); | |
483 |
|
|
484 | TRY_COMPARE(spy2.count(), 1); | |
484 | } |
|
485 | } | |
485 |
|
486 | |||
486 | void tst_Domain::spanX_data() |
|
487 | void tst_Domain::spanX_data() | |
487 | { |
|
488 | { | |
488 | QTest::addColumn<qreal>("minX"); |
|
489 | QTest::addColumn<qreal>("minX"); | |
489 | QTest::addColumn<qreal>("maxX"); |
|
490 | QTest::addColumn<qreal>("maxX"); | |
490 | QTest::addColumn<qreal>("spanX"); |
|
491 | QTest::addColumn<qreal>("spanX"); | |
491 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
492 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |
492 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
493 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |
493 | } |
|
494 | } | |
494 |
|
495 | |||
495 | void tst_Domain::spanX() |
|
496 | void tst_Domain::spanX() | |
496 | { |
|
497 | { | |
497 | QFETCH(qreal, minX); |
|
498 | QFETCH(qreal, minX); | |
498 | QFETCH(qreal, maxX); |
|
499 | QFETCH(qreal, maxX); | |
499 | QFETCH(qreal, spanX); |
|
500 | QFETCH(qreal, spanX); | |
500 |
|
501 | |||
501 | Domain domain; |
|
502 | Domain domain; | |
502 |
|
503 | |||
503 | domain.setRangeX(minX, maxX); |
|
504 | domain.setRangeX(minX, maxX); | |
504 |
|
505 | |||
505 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
506 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
506 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
507 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
507 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
508 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
508 |
|
509 | |||
509 | QCOMPARE(domain.spanX(), spanX); |
|
510 | QCOMPARE(domain.spanX(), spanX); | |
510 |
|
511 | |||
511 |
|
|
512 | TRY_COMPARE(spy0.count(), 0); | |
512 |
|
|
513 | TRY_COMPARE(spy1.count(), 0); | |
513 |
|
|
514 | TRY_COMPARE(spy2.count(), 0); | |
514 | } |
|
515 | } | |
515 |
|
516 | |||
516 | void tst_Domain::spanY_data() |
|
517 | void tst_Domain::spanY_data() | |
517 | { |
|
518 | { | |
518 | QTest::addColumn<qreal>("minY"); |
|
519 | QTest::addColumn<qreal>("minY"); | |
519 | QTest::addColumn<qreal>("maxY"); |
|
520 | QTest::addColumn<qreal>("maxY"); | |
520 | QTest::addColumn<qreal>("spanY"); |
|
521 | QTest::addColumn<qreal>("spanY"); | |
521 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
522 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |
522 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
523 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |
523 | } |
|
524 | } | |
524 |
|
525 | |||
525 | void tst_Domain::spanY() |
|
526 | void tst_Domain::spanY() | |
526 | { |
|
527 | { | |
527 | QFETCH(qreal, minY); |
|
528 | QFETCH(qreal, minY); | |
528 | QFETCH(qreal, maxY); |
|
529 | QFETCH(qreal, maxY); | |
529 | QFETCH(qreal, spanY); |
|
530 | QFETCH(qreal, spanY); | |
530 |
|
531 | |||
531 | Domain domain; |
|
532 | Domain domain; | |
532 |
|
533 | |||
533 | domain.setRangeY(minY, maxY); |
|
534 | domain.setRangeY(minY, maxY); | |
534 |
|
535 | |||
535 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
536 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
536 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
537 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
537 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
538 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
538 |
|
539 | |||
539 | QCOMPARE(domain.spanY(), spanY); |
|
540 | QCOMPARE(domain.spanY(), spanY); | |
540 |
|
541 | |||
541 |
|
|
542 | TRY_COMPARE(spy0.count(), 0); | |
542 |
|
|
543 | TRY_COMPARE(spy1.count(), 0); | |
543 |
|
|
544 | TRY_COMPARE(spy2.count(), 0); | |
544 | } |
|
545 | } | |
545 |
|
546 | |||
546 | void tst_Domain::zoom_data() |
|
547 | void tst_Domain::zoom_data() | |
547 | { |
|
548 | { | |
548 | QTest::addColumn<QRectF>("rect0"); |
|
549 | QTest::addColumn<QRectF>("rect0"); | |
549 | QTest::addColumn<QSizeF>("size0"); |
|
550 | QTest::addColumn<QSizeF>("size0"); | |
550 | QTest::addColumn<QRectF>("rect1"); |
|
551 | QTest::addColumn<QRectF>("rect1"); | |
551 | QTest::addColumn<QSizeF>("size1"); |
|
552 | QTest::addColumn<QSizeF>("size1"); | |
552 | QTest::addColumn<QRectF>("rect2"); |
|
553 | QTest::addColumn<QRectF>("rect2"); | |
553 | QTest::addColumn<QSizeF>("size2"); |
|
554 | QTest::addColumn<QSizeF>("size2"); | |
554 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
555 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) | |
555 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
556 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) | |
556 | << QSizeF(1000, 1000); |
|
557 | << QSizeF(1000, 1000); | |
557 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
558 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) | |
558 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
559 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) | |
559 | << QSizeF(1000, 1000); |
|
560 | << QSizeF(1000, 1000); | |
560 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
561 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) | |
561 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
562 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); | |
562 | } |
|
563 | } | |
563 |
|
564 | |||
564 | void tst_Domain::zoom() |
|
565 | void tst_Domain::zoom() | |
565 | { |
|
566 | { | |
566 | QFETCH(QRectF, rect0); |
|
567 | QFETCH(QRectF, rect0); | |
567 | QFETCH(QSizeF, size0); |
|
568 | QFETCH(QSizeF, size0); | |
568 | QFETCH(QRectF, rect1); |
|
569 | QFETCH(QRectF, rect1); | |
569 | QFETCH(QSizeF, size1); |
|
570 | QFETCH(QSizeF, size1); | |
570 | QFETCH(QRectF, rect2); |
|
571 | QFETCH(QRectF, rect2); | |
571 | QFETCH(QSizeF, size2); |
|
572 | QFETCH(QSizeF, size2); | |
572 |
|
573 | |||
573 | Domain domain; |
|
574 | Domain domain; | |
574 |
|
575 | |||
575 | domain.setRange(0, 1000, 0, 1000); |
|
576 | domain.setRange(0, 1000, 0, 1000); | |
576 |
|
577 | |||
577 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
578 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
578 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
579 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
579 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
580 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
580 |
|
581 | |||
581 | Domain domain0; |
|
582 | Domain domain0; | |
582 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
583 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
583 | domain.zoomIn(rect0, size0); |
|
584 | domain.zoomIn(rect0, size0); | |
584 | Domain domain1; |
|
585 | Domain domain1; | |
585 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
586 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
586 | domain.zoomIn(rect1, size1); |
|
587 | domain.zoomIn(rect1, size1); | |
587 | Domain domain2; |
|
588 | Domain domain2; | |
588 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
589 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); | |
589 | domain.zoomIn(rect2, size2); |
|
590 | domain.zoomIn(rect2, size2); | |
590 | domain.zoomOut(rect2, size2); |
|
591 | domain.zoomOut(rect2, size2); | |
591 | QCOMPARE(domain == domain2, true); |
|
592 | QCOMPARE(domain == domain2, true); | |
592 | domain.zoomOut(rect1, size1); |
|
593 | domain.zoomOut(rect1, size1); | |
593 | QCOMPARE(domain == domain1, true); |
|
594 | QCOMPARE(domain == domain1, true); | |
594 | domain.zoomOut(rect0, size0); |
|
595 | domain.zoomOut(rect0, size0); | |
595 | QCOMPARE(domain == domain0, true); |
|
596 | QCOMPARE(domain == domain0, true); | |
596 |
|
|
597 | TRY_COMPARE(spy0.count(), 6); | |
597 |
|
|
598 | TRY_COMPARE(spy1.count(), 6); | |
598 |
|
|
599 | TRY_COMPARE(spy2.count(), 6); | |
599 |
|
||||
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void tst_Domain::move_data() |
|
602 | void tst_Domain::move_data() | |
603 | { |
|
603 | { | |
604 | QTest::addColumn<int>("dx"); |
|
604 | QTest::addColumn<int>("dx"); | |
605 | QTest::addColumn<int>("dy"); |
|
605 | QTest::addColumn<int>("dy"); | |
606 | QTest::addColumn<QSizeF>("size"); |
|
606 | QTest::addColumn<QSizeF>("size"); | |
607 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
607 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); | |
608 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); |
|
608 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); | |
609 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
609 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); | |
610 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); |
|
610 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); | |
611 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
611 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); | |
612 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
612 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); | |
613 | } |
|
613 | } | |
614 |
|
614 | |||
615 | void tst_Domain::move() |
|
615 | void tst_Domain::move() | |
616 | { |
|
616 | { | |
617 | QFETCH(int, dx); |
|
617 | QFETCH(int, dx); | |
618 | QFETCH(int, dy); |
|
618 | QFETCH(int, dy); | |
619 | QFETCH(QSizeF, size); |
|
619 | QFETCH(QSizeF, size); | |
620 | Domain domain; |
|
620 | Domain domain; | |
621 |
|
621 | |||
622 | domain.setRange(0, size.width(), 0, size.height()); |
|
622 | domain.setRange(0, size.width(), 0, size.height()); | |
623 |
|
623 | |||
624 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
624 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
625 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
625 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
626 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
626 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
627 |
|
627 | |||
628 | domain.move(dx, dy, size); |
|
628 | domain.move(dx, dy, size); | |
629 |
|
629 | |||
630 | Domain result; |
|
630 | Domain result; | |
631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); | |
632 |
|
632 | |||
633 | QCOMPARE(domain == result, true); |
|
633 | QCOMPARE(domain == result, true); | |
634 |
|
|
634 | TRY_COMPARE(spy0.count(), 1); | |
635 |
|
|
635 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); | |
636 |
|
|
636 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | void tst_Domain::handleAxisXChanged_data() |
|
639 | void tst_Domain::handleAxisXChanged_data() | |
640 | { |
|
640 | { | |
641 | QTest::addColumn<qreal>("min"); |
|
641 | QTest::addColumn<qreal>("min"); | |
642 | QTest::addColumn<qreal>("max"); |
|
642 | QTest::addColumn<qreal>("max"); | |
643 | QTest::addColumn<int>("tickCount"); |
|
643 | QTest::addColumn<int>("tickCount"); | |
644 | QTest::addColumn<bool>("niceNumbers"); |
|
644 | QTest::addColumn<bool>("niceNumbers"); | |
645 | QTest::addColumn<qreal>("resultMin"); |
|
645 | QTest::addColumn<qreal>("resultMin"); | |
646 | QTest::addColumn<qreal>("resultMax"); |
|
646 | QTest::addColumn<qreal>("resultMax"); | |
647 | QTest::addColumn<int>("resultTickCount"); |
|
647 | QTest::addColumn<int>("resultTickCount"); | |
648 | QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; |
|
648 | QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; | |
649 | QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; |
|
649 | QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; | |
650 | QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; |
|
650 | QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; | |
651 | QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; |
|
651 | QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | void tst_Domain::handleAxisXChanged() |
|
654 | void tst_Domain::handleAxisXChanged() | |
655 | { |
|
655 | { | |
656 | QFETCH(qreal, min); |
|
656 | QFETCH(qreal, min); | |
657 | QFETCH(qreal, max); |
|
657 | QFETCH(qreal, max); | |
658 | QFETCH(int, tickCount); |
|
658 | QFETCH(int, tickCount); | |
659 | QFETCH(bool, niceNumbers); |
|
659 | QFETCH(bool, niceNumbers); | |
660 | QFETCH(qreal, resultMin); |
|
660 | QFETCH(qreal, resultMin); | |
661 | QFETCH(qreal, resultMax); |
|
661 | QFETCH(qreal, resultMax); | |
662 | QFETCH(int, resultTickCount); |
|
662 | QFETCH(int, resultTickCount); | |
663 |
|
663 | |||
664 | Domain domain; |
|
664 | Domain domain; | |
665 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
665 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
666 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
666 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
667 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
667 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
668 |
|
668 | |||
669 | domain.handleAxisXChanged(min, max, tickCount, niceNumbers); |
|
669 | domain.handleAxisXChanged(min, max, tickCount, niceNumbers); | |
670 |
|
670 | |||
671 | QCOMPARE(resultMin, domain.minX()); |
|
671 | QCOMPARE(resultMin, domain.minX()); | |
672 | QCOMPARE(resultMax, domain.maxX()); |
|
672 | QCOMPARE(resultMax, domain.maxX()); | |
673 | QCOMPARE(resultTickCount, domain.tickXCount()); |
|
673 | QCOMPARE(resultTickCount, domain.tickXCount()); | |
674 |
|
|
674 | TRY_COMPARE(spy0.count(), 1); | |
675 |
|
|
675 | TRY_COMPARE(spy1.count(), 1); | |
676 |
|
|
676 | TRY_COMPARE(spy2.count(), 0); | |
677 |
|
677 | |||
678 | } |
|
678 | } | |
679 |
|
679 | |||
680 | void tst_Domain::handleAxisYChanged_data() |
|
680 | void tst_Domain::handleAxisYChanged_data() | |
681 | { |
|
681 | { | |
682 | handleAxisXChanged_data(); |
|
682 | handleAxisXChanged_data(); | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | void tst_Domain::handleAxisYChanged() |
|
685 | void tst_Domain::handleAxisYChanged() | |
686 | { |
|
686 | { | |
687 | QFETCH(qreal, min); |
|
687 | QFETCH(qreal, min); | |
688 | QFETCH(qreal, max); |
|
688 | QFETCH(qreal, max); | |
689 | QFETCH(int, tickCount); |
|
689 | QFETCH(int, tickCount); | |
690 | QFETCH(bool, niceNumbers); |
|
690 | QFETCH(bool, niceNumbers); | |
691 | QFETCH(qreal, resultMin); |
|
691 | QFETCH(qreal, resultMin); | |
692 | QFETCH(qreal, resultMax); |
|
692 | QFETCH(qreal, resultMax); | |
693 | QFETCH(int, resultTickCount); |
|
693 | QFETCH(int, resultTickCount); | |
694 |
|
694 | |||
695 | Domain domain; |
|
695 | Domain domain; | |
696 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
696 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
697 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
697 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); | |
698 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
698 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); | |
699 |
|
699 | |||
700 | domain.handleAxisYChanged(min, max, tickCount, niceNumbers); |
|
700 | domain.handleAxisYChanged(min, max, tickCount, niceNumbers); | |
701 |
|
701 | |||
702 | QCOMPARE(resultMin, domain.minY()); |
|
702 | QCOMPARE(resultMin, domain.minY()); | |
703 | QCOMPARE(resultMax, domain.maxY()); |
|
703 | QCOMPARE(resultMax, domain.maxY()); | |
704 | QCOMPARE(resultTickCount, domain.tickYCount()); |
|
704 | QCOMPARE(resultTickCount, domain.tickYCount()); | |
705 |
|
|
705 | TRY_COMPARE(spy0.count(), 1); | |
706 |
|
|
706 | TRY_COMPARE(spy1.count(), 0); | |
707 |
|
|
707 | TRY_COMPARE(spy2.count(), 1); | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | QTEST_MAIN(tst_Domain) |
|
710 | QTEST_MAIN(tst_Domain) | |
711 | #include "tst_domain.moc" |
|
711 | #include "tst_domain.moc" | |
712 |
|
712 |
@@ -1,318 +1,428 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
26 | |||
27 | class tst_QBarSeries : public QObject |
|
27 | class tst_QBarSeries : public QObject | |
28 | { |
|
28 | { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 |
|
30 | |||
31 | public slots: |
|
31 | public slots: | |
32 | void initTestCase(); |
|
32 | void initTestCase(); | |
33 | void cleanupTestCase(); |
|
33 | void cleanupTestCase(); | |
34 | void init(); |
|
34 | void init(); | |
35 | void cleanup(); |
|
35 | void cleanup(); | |
36 |
|
36 | |||
37 | private slots: |
|
37 | private slots: | |
38 | void qbarseries_data(); |
|
38 | void qbarseries_data(); | |
39 | void qbarseries(); |
|
39 | void qbarseries(); | |
40 | void type_data(); |
|
40 | void type_data(); | |
41 | void type(); |
|
41 | void type(); | |
|
42 | void setCategories_data(); | |||
|
43 | void setCategories(); | |||
42 | void appendBarSet_data(); |
|
44 | void appendBarSet_data(); | |
43 | void appendBarSet(); |
|
45 | void appendBarSet(); | |
44 | void removeBarSet_data(); |
|
46 | void removeBarSet_data(); | |
45 | void removeBarSet(); |
|
47 | void removeBarSet(); | |
46 | void appendBarSets_data(); |
|
48 | void appendBarSets_data(); | |
47 | void appendBarSets(); |
|
49 | void appendBarSets(); | |
48 | void removeBarSets_data(); |
|
50 | void removeBarSets_data(); | |
49 | void removeBarSets(); |
|
51 | void removeBarSets(); | |
50 | void barsetCount_data(); |
|
52 | void barsetCount_data(); | |
51 | void barsetCount(); |
|
53 | void barsetCount(); | |
52 | void categoryCount_data(); |
|
54 | void categoryCount_data(); | |
53 | void categoryCount(); |
|
55 | void categoryCount(); | |
54 | void barSets_data(); |
|
56 | void barSets_data(); | |
55 | void barSets(); |
|
57 | void barSets(); | |
56 | void categories_data(); |
|
58 | void categories_data(); | |
57 | void categories(); |
|
59 | void categories(); | |
58 | void setLabelsVisible_data(); |
|
60 | void setLabelsVisible_data(); | |
59 | void setLabelsVisible(); |
|
61 | void setLabelsVisible(); | |
60 |
|
62 | |||
61 | private: |
|
63 | private: | |
62 | QBarSeries* m_barseries; |
|
64 | QBarSeries* m_barseries; | |
63 | QBarSeries* m_barseries_with_sets; |
|
65 | QBarSeries* m_barseries_with_sets; | |
64 |
|
66 | |||
65 | QList<QBarSet*> m_testSets; |
|
67 | QList<QBarSet*> m_testSets; | |
66 |
|
68 | |||
67 | QBarCategories m_categories; |
|
69 | QBarCategories m_categories; | |
68 | }; |
|
70 | }; | |
69 |
|
71 | |||
70 | void tst_QBarSeries::initTestCase() |
|
72 | void tst_QBarSeries::initTestCase() | |
71 | { |
|
73 | { | |
72 | } |
|
74 | } | |
73 |
|
75 | |||
74 | void tst_QBarSeries::cleanupTestCase() |
|
76 | void tst_QBarSeries::cleanupTestCase() | |
75 | { |
|
77 | { | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | void tst_QBarSeries::init() |
|
80 | void tst_QBarSeries::init() | |
79 | { |
|
81 | { | |
80 | m_categories << "category0" << "category1" << "category2"; |
|
82 | m_categories << "category0" << "category1" << "category2"; | |
81 |
m_barseries = new QBarSeries( |
|
83 | m_barseries = new QBarSeries(); | |
82 |
m_barseries |
|
84 | m_barseries->setCategories(m_categories); | |
|
85 | m_barseries_with_sets = new QBarSeries(); | |||
|
86 | m_barseries_with_sets->setCategories(m_categories); | |||
83 |
|
87 | |||
84 | for (int i=0; i<5; i++) { |
|
88 | for (int i=0; i<5; i++) { | |
85 | m_testSets.append(new QBarSet("testset")); |
|
89 | m_testSets.append(new QBarSet("testset")); | |
86 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); |
|
90 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); | |
87 | } |
|
91 | } | |
88 | } |
|
92 | } | |
89 |
|
93 | |||
90 | void tst_QBarSeries::cleanup() |
|
94 | void tst_QBarSeries::cleanup() | |
91 | { |
|
95 | { | |
92 | foreach(QBarSet* s, m_testSets) { |
|
96 | foreach(QBarSet* s, m_testSets) { | |
93 | m_barseries_with_sets->removeBarSet(s); |
|
97 | m_barseries_with_sets->removeBarSet(s); | |
94 | delete s; |
|
98 | delete s; | |
95 | } |
|
99 | } | |
96 | m_testSets.clear(); |
|
100 | m_testSets.clear(); | |
97 |
|
101 | |||
98 | delete m_barseries; |
|
102 | delete m_barseries; | |
99 | m_barseries = 0; |
|
103 | m_barseries = 0; | |
100 | delete m_barseries_with_sets; |
|
104 | delete m_barseries_with_sets; | |
101 | m_barseries_with_sets = 0; |
|
105 | m_barseries_with_sets = 0; | |
102 | m_categories.clear(); |
|
106 | m_categories.clear(); | |
103 | } |
|
107 | } | |
104 |
|
108 | |||
105 | void tst_QBarSeries::qbarseries_data() |
|
109 | void tst_QBarSeries::qbarseries_data() | |
106 | { |
|
110 | { | |
107 | QTest::addColumn<QBarCategories> ("categories"); |
|
111 | QTest::addColumn<QBarCategories> ("categories"); | |
108 | QBarCategories c; |
|
112 | QBarCategories c; | |
109 | c << "category0" << "category1" << "category2"; |
|
113 | c << "category0" << "category1" << "category2"; | |
110 | QTest::newRow("categories") << c; |
|
114 | QTest::newRow("categories") << c; | |
111 | } |
|
115 | } | |
112 |
|
116 | |||
113 | void tst_QBarSeries::qbarseries() |
|
117 | void tst_QBarSeries::qbarseries() | |
114 | { |
|
118 | { | |
115 | QFETCH(QBarCategories, categories); |
|
119 | QFETCH(QBarCategories, categories); | |
116 |
QBarSeries *barseries = new QBarSeries( |
|
120 | QBarSeries *barseries = new QBarSeries(); | |
117 | QVERIFY(barseries != 0); |
|
121 | QVERIFY(barseries != 0); | |
|
122 | barseries->setCategories(categories); | |||
118 | QBarCategories verifyCategories = barseries->categories(); |
|
123 | QBarCategories verifyCategories = barseries->categories(); | |
119 |
|
124 | |||
120 | QVERIFY(verifyCategories.count() == categories.count()); |
|
125 | QVERIFY(verifyCategories.count() == categories.count()); | |
121 | for (int i=0; i<categories.count(); i++) { |
|
126 | for (int i=0; i<categories.count(); i++) { | |
122 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
127 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); | |
123 | } |
|
128 | } | |
124 | } |
|
129 | } | |
125 |
|
130 | |||
126 | void tst_QBarSeries::type_data() |
|
131 | void tst_QBarSeries::type_data() | |
127 | { |
|
132 | { | |
128 |
|
133 | |||
129 | } |
|
134 | } | |
130 |
|
135 | |||
131 | void tst_QBarSeries::type() |
|
136 | void tst_QBarSeries::type() | |
132 | { |
|
137 | { | |
133 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
138 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
134 | } |
|
139 | } | |
135 |
|
140 | |||
|
141 | void tst_QBarSeries::setCategories_data() | |||
|
142 | { | |||
|
143 | QTest::addColumn<QBarCategories> ("categories"); | |||
|
144 | QBarCategories categories; | |||
|
145 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; | |||
|
146 | QTest::newRow("cat") << categories; | |||
|
147 | } | |||
|
148 | ||||
|
149 | void tst_QBarSeries::setCategories() | |||
|
150 | { | |||
|
151 | QVERIFY(m_barseries->categories().count() == m_categories.count()); | |||
|
152 | ||||
|
153 | QFETCH(QBarCategories, categories); | |||
|
154 | m_barseries->setCategories(categories); | |||
|
155 | ||||
|
156 | QVERIFY(m_barseries->categories().count() == categories.count()); | |||
|
157 | for (int i=0; i<categories.count(); i++) { | |||
|
158 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); | |||
|
159 | } | |||
|
160 | } | |||
|
161 | ||||
136 | void tst_QBarSeries::appendBarSet_data() |
|
162 | void tst_QBarSeries::appendBarSet_data() | |
137 | { |
|
163 | { | |
138 | } |
|
164 | } | |
139 |
|
165 | |||
140 | void tst_QBarSeries::appendBarSet() |
|
166 | void tst_QBarSeries::appendBarSet() | |
141 | { |
|
167 | { | |
142 | QVERIFY(m_barseries->barsetCount() == 0); |
|
168 | QVERIFY(m_barseries->barsetCount() == 0); | |
143 |
|
169 | |||
|
170 | bool ret = false; | |||
|
171 | ||||
|
172 | // Try adding barset | |||
144 | QBarSet *barset = new QBarSet("testset"); |
|
173 | QBarSet *barset = new QBarSet("testset"); | |
145 | m_barseries->appendBarSet(barset); |
|
174 | ret = m_barseries->appendBarSet(barset); | |
146 |
|
175 | |||
|
176 | QVERIFY(ret == true); | |||
147 | QVERIFY(m_barseries->barsetCount() == 1); |
|
177 | QVERIFY(m_barseries->barsetCount() == 1); | |
148 |
|
178 | |||
|
179 | // Try adding another set | |||
149 | QBarSet *barset2 = new QBarSet("testset2"); |
|
180 | QBarSet *barset2 = new QBarSet("testset2"); | |
150 | m_barseries->appendBarSet(barset2); |
|
181 | ret = m_barseries->appendBarSet(barset2); | |
|
182 | ||||
|
183 | QVERIFY(ret == true); | |||
|
184 | QVERIFY(m_barseries->barsetCount() == 2); | |||
151 |
|
185 | |||
|
186 | // Try adding same set again | |||
|
187 | ret = m_barseries->appendBarSet(barset2); | |||
|
188 | QVERIFY(ret == false); | |||
152 | QVERIFY(m_barseries->barsetCount() == 2); |
|
189 | QVERIFY(m_barseries->barsetCount() == 2); | |
|
190 | ||||
|
191 | // Try adding null set | |||
|
192 | ret = m_barseries->appendBarSet(0); | |||
|
193 | QVERIFY(ret == false); | |||
|
194 | QVERIFY(m_barseries->barsetCount() == 2); | |||
|
195 | ||||
153 | } |
|
196 | } | |
154 |
|
197 | |||
155 | void tst_QBarSeries::removeBarSet_data() |
|
198 | void tst_QBarSeries::removeBarSet_data() | |
156 | { |
|
199 | { | |
157 | } |
|
200 | } | |
158 |
|
201 | |||
159 | void tst_QBarSeries::removeBarSet() |
|
202 | void tst_QBarSeries::removeBarSet() | |
160 | { |
|
203 | { | |
161 | int count = m_testSets.count(); |
|
204 | int count = m_testSets.count(); | |
162 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
205 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
163 |
|
206 | |||
|
207 | // Try to remove null pointer (should not remove, should not crash) | |||
|
208 | bool ret = false; | |||
|
209 | ret = m_barseries_with_sets->removeBarSet(0); | |||
|
210 | QVERIFY(ret == false); | |||
|
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
212 | ||||
|
213 | // Try to remove invalid pointer (should not remove, should not crash) | |||
|
214 | ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); | |||
|
215 | QVERIFY(ret == false); | |||
|
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
217 | ||||
164 | // remove some sets |
|
218 | // remove some sets | |
165 | m_barseries_with_sets->removeBarSet(m_testSets.at(2)); |
|
219 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
166 | m_barseries_with_sets->removeBarSet(m_testSets.at(3)); |
|
220 | QVERIFY(ret == true); | |
167 |
m_barseries_with_sets->removeBarSet(m_testSets.at( |
|
221 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
|
222 | QVERIFY(ret == true); | |||
|
223 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); | |||
|
224 | QVERIFY(ret == true); | |||
168 |
|
225 | |||
169 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
226 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); | |
170 |
|
227 | |||
171 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
228 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
172 |
|
229 | |||
173 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
230 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
174 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
231 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
175 |
|
232 | |||
176 | // Try removing all sets again |
|
233 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
|
234 | ret = false; | |||
177 | for (int i=0; i<count; i++) { |
|
235 | for (int i=0; i<count; i++) { | |
178 | m_barseries_with_sets->removeBarSet(m_testSets.at(i)); |
|
236 | ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
179 | } |
|
237 | } | |
180 |
|
238 | |||
|
239 | QVERIFY(ret == true); | |||
181 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
240 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
182 | } |
|
241 | } | |
183 |
|
242 | |||
184 | void tst_QBarSeries::appendBarSets_data() |
|
243 | void tst_QBarSeries::appendBarSets_data() | |
185 | { |
|
244 | { | |
186 |
|
245 | |||
187 | } |
|
246 | } | |
188 |
|
247 | |||
189 | void tst_QBarSeries::appendBarSets() |
|
248 | void tst_QBarSeries::appendBarSets() | |
190 | { |
|
249 | { | |
191 | int count = 5; |
|
250 | int count = 5; | |
192 | QVERIFY(m_barseries->barsetCount() == 0); |
|
251 | QVERIFY(m_barseries->barsetCount() == 0); | |
193 |
|
252 | |||
194 | QList<QBarSet*> sets; |
|
253 | QList<QBarSet*> sets; | |
195 | for (int i=0; i<count; i++) { |
|
254 | for (int i=0; i<count; i++) { | |
196 | sets.append(new QBarSet("testset")); |
|
255 | sets.append(new QBarSet("testset")); | |
197 | } |
|
256 | } | |
198 |
|
257 | |||
199 | m_barseries->appendBarSets(sets); |
|
258 | // Append new sets (should succeed, count should match the count of sets) | |
|
259 | bool ret = false; | |||
|
260 | ret = m_barseries->appendBarSets(sets); | |||
|
261 | QVERIFY(ret == true); | |||
|
262 | QVERIFY(m_barseries->barsetCount() == count); | |||
|
263 | ||||
|
264 | // Append same sets again (should fail, count should remain same) | |||
|
265 | ret = m_barseries->appendBarSets(sets); | |||
|
266 | QVERIFY(ret == false); | |||
|
267 | QVERIFY(m_barseries->barsetCount() == count); | |||
|
268 | ||||
|
269 | // Try append empty list (should succeed, but count should remain same) | |||
|
270 | QList<QBarSet*> invalidList; | |||
|
271 | ret = m_barseries->appendBarSets(invalidList); | |||
|
272 | QVERIFY(ret == true); | |||
|
273 | QVERIFY(m_barseries->barsetCount() == count); | |||
|
274 | ||||
|
275 | // Try append list with one new and one existing set (should fail, count remains same) | |||
|
276 | invalidList.append(new QBarSet("ok set")); | |||
|
277 | invalidList.append(sets.at(0)); | |||
|
278 | ret = m_barseries->appendBarSets(invalidList); | |||
|
279 | QVERIFY(ret == false); | |||
|
280 | QVERIFY(m_barseries->barsetCount() == count); | |||
|
281 | ||||
|
282 | // Try append list with null pointers (should fail, count remains same) | |||
|
283 | QList<QBarSet*> invalidList2; | |||
|
284 | invalidList2.append(0); | |||
|
285 | invalidList2.append(0); | |||
|
286 | invalidList2.append(0); | |||
|
287 | ret = m_barseries->appendBarSets(invalidList2); | |||
|
288 | QVERIFY(ret == false); | |||
200 | QVERIFY(m_barseries->barsetCount() == count); |
|
289 | QVERIFY(m_barseries->barsetCount() == count); | |
201 | } |
|
290 | } | |
202 |
|
291 | |||
203 | void tst_QBarSeries::removeBarSets_data() |
|
292 | void tst_QBarSeries::removeBarSets_data() | |
204 | { |
|
293 | { | |
205 |
|
294 | |||
206 | } |
|
295 | } | |
207 |
|
296 | |||
208 | void tst_QBarSeries::removeBarSets() |
|
297 | void tst_QBarSeries::removeBarSets() | |
209 | { |
|
298 | { | |
210 | int count = m_testSets.count(); |
|
299 | int count = m_testSets.count(); | |
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
300 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
212 |
|
301 | |||
213 | // Try removing empty list of sets |
|
302 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
214 | QList<QBarSet*> empty; |
|
303 | bool ret = false; | |
215 | m_barseries_with_sets->removeBarSets(empty); |
|
304 | QList<QBarSet*> invalidList; | |
|
305 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |||
|
306 | QVERIFY(ret == false); | |||
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
307 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
217 |
|
308 | |||
218 | // remove all sets |
|
309 | // Add some null pointers to list | |
219 | m_barseries_with_sets->removeBarSets(m_testSets); |
|
310 | invalidList.append(0); | |
|
311 | invalidList.append(0); | |||
|
312 | invalidList.append(0); | |||
|
313 | ||||
|
314 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |||
|
315 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |||
|
316 | QVERIFY(ret == false); | |||
|
317 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |||
|
318 | ||||
|
319 | // remove all sets (should return true, since sets were removed) | |||
|
320 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |||
|
321 | QVERIFY(ret == true); | |||
220 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
322 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
221 |
|
323 | |||
222 | // Try removing empty list again |
|
324 | // Try removing invalid list again (should return false, since no barsets were removed) | |
223 |
m_barseries_with_sets->removeBarSets( |
|
325 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
326 | QVERIFY(ret == false); | |||
224 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
327 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
225 |
|
328 | |||
226 | // remove all sets again |
|
329 | // remove all sets again (should return false, since barsets were already removed) | |
227 | m_barseries_with_sets->removeBarSets(m_testSets); |
|
330 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
|
331 | QVERIFY(ret == false); | |||
228 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
332 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
229 | } |
|
333 | } | |
230 |
|
334 | |||
231 | void tst_QBarSeries::barsetCount_data() |
|
335 | void tst_QBarSeries::barsetCount_data() | |
232 | { |
|
336 | { | |
233 |
|
337 | |||
234 | } |
|
338 | } | |
235 |
|
339 | |||
236 | void tst_QBarSeries::barsetCount() |
|
340 | void tst_QBarSeries::barsetCount() | |
237 | { |
|
341 | { | |
238 | QVERIFY(m_barseries->barsetCount() == 0); |
|
342 | QVERIFY(m_barseries->barsetCount() == 0); | |
239 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); |
|
343 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); | |
240 | } |
|
344 | } | |
241 |
|
345 | |||
242 | void tst_QBarSeries::categoryCount_data() |
|
346 | void tst_QBarSeries::categoryCount_data() | |
243 | { |
|
347 | { | |
244 |
|
348 | |||
245 | } |
|
349 | } | |
246 |
|
350 | |||
247 | void tst_QBarSeries::categoryCount() |
|
351 | void tst_QBarSeries::categoryCount() | |
248 | { |
|
352 | { | |
249 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); |
|
353 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); | |
250 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); |
|
354 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); | |
251 | } |
|
355 | } | |
252 |
|
356 | |||
253 | void tst_QBarSeries::barSets_data() |
|
357 | void tst_QBarSeries::barSets_data() | |
254 | { |
|
358 | { | |
255 |
|
359 | |||
256 | } |
|
360 | } | |
257 |
|
361 | |||
258 | void tst_QBarSeries::barSets() |
|
362 | void tst_QBarSeries::barSets() | |
259 | { |
|
363 | { | |
260 | QVERIFY(m_barseries->barSets().count() == 0); |
|
364 | QVERIFY(m_barseries->barSets().count() == 0); | |
261 |
|
365 | |||
262 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
366 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
263 | QVERIFY(sets.count() == m_testSets.count()); |
|
367 | QVERIFY(sets.count() == m_testSets.count()); | |
264 |
|
368 | |||
265 | for (int i=0; i<m_testSets.count(); i++) { |
|
369 | for (int i=0; i<m_testSets.count(); i++) { | |
266 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
370 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
267 | } |
|
371 | } | |
268 | } |
|
372 | } | |
269 |
|
373 | |||
270 | void tst_QBarSeries::categories_data() |
|
374 | void tst_QBarSeries::categories_data() | |
271 | { |
|
375 | { | |
272 |
|
376 | |||
273 | } |
|
377 | } | |
274 |
|
378 | |||
275 | void tst_QBarSeries::categories() |
|
379 | void tst_QBarSeries::categories() | |
276 | { |
|
380 | { | |
277 | QBarCategories categories = m_barseries->categories(); |
|
381 | QBarCategories categories = m_barseries->categories(); | |
278 |
|
382 | |||
279 | QVERIFY(categories.count() == m_categories.count()); |
|
383 | QVERIFY(categories.count() == m_categories.count()); | |
280 | for (int i=0; i<m_categories.count(); i++) { |
|
384 | for (int i=0; i<m_categories.count(); i++) { | |
281 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); |
|
385 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); | |
282 | } |
|
386 | } | |
283 | } |
|
387 | } | |
284 |
|
388 | |||
285 | void tst_QBarSeries::setLabelsVisible_data() |
|
389 | void tst_QBarSeries::setLabelsVisible_data() | |
286 | { |
|
390 | { | |
287 |
|
391 | |||
288 | } |
|
392 | } | |
289 |
|
393 | |||
290 | void tst_QBarSeries::setLabelsVisible() |
|
394 | void tst_QBarSeries::setLabelsVisible() | |
291 | { |
|
395 | { | |
|
396 | // labels should be invisible by default | |||
292 | foreach (QBarSet* s, m_testSets) { |
|
397 | foreach (QBarSet* s, m_testSets) { | |
293 | QVERIFY(s->labelsVisible() == false); |
|
398 | QVERIFY(s->labelsVisible() == false); | |
294 | } |
|
399 | } | |
295 |
|
400 | |||
|
401 | // turn labels to visible | |||
296 | m_barseries_with_sets->setLabelsVisible(true); |
|
402 | m_barseries_with_sets->setLabelsVisible(true); | |
297 | foreach (QBarSet* s, m_testSets) { |
|
403 | foreach (QBarSet* s, m_testSets) { | |
298 | QVERIFY(s->labelsVisible() == true); |
|
404 | QVERIFY(s->labelsVisible() == true); | |
299 | } |
|
405 | } | |
300 |
|
406 | |||
|
407 | // turn labels to invisible | |||
301 | m_barseries_with_sets->setLabelsVisible(false); |
|
408 | m_barseries_with_sets->setLabelsVisible(false); | |
302 | foreach (QBarSet* s, m_testSets) { |
|
409 | foreach (QBarSet* s, m_testSets) { | |
303 | QVERIFY(s->labelsVisible() == false); |
|
410 | QVERIFY(s->labelsVisible() == false); | |
304 | } |
|
411 | } | |
|
412 | ||||
|
413 | // without parameter, should turn labels to visible | |||
|
414 | m_barseries_with_sets->setLabelsVisible(); | |||
|
415 | foreach (QBarSet* s, m_testSets) { | |||
|
416 | QVERIFY(s->labelsVisible() == true); | |||
|
417 | } | |||
305 | } |
|
418 | } | |
306 |
|
419 | |||
307 | /* |
|
420 | /* | |
308 |
|
||||
309 | void setLabelsVisible(bool visible = true); |
|
|||
310 |
|
||||
311 | bool setModel(QAbstractItemModel *model); |
|
421 | bool setModel(QAbstractItemModel *model); | |
312 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
422 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
313 | void setModelMappingRange(int first, int count = -1); |
|
423 | void setModelMappingRange(int first, int count = -1); | |
314 | */ |
|
424 | */ | |
315 | QTEST_MAIN(tst_QBarSeries) |
|
425 | QTEST_MAIN(tst_QBarSeries) | |
316 |
|
426 | |||
317 | #include "tst_qbarseries.moc" |
|
427 | #include "tst_qbarseries.moc" | |
318 |
|
428 |
@@ -1,568 +1,585 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
4 | #include <qareaseries.h> |
|
4 | #include <qareaseries.h> | |
5 | #include <qscatterseries.h> |
|
5 | #include <qscatterseries.h> | |
6 | #include <qsplineseries.h> |
|
6 | #include <qsplineseries.h> | |
7 | #include <qpieseries.h> |
|
7 | #include <qpieseries.h> | |
8 | #include <qbarseries.h> |
|
8 | #include <qbarseries.h> | |
9 | #include <qpercentbarseries.h> |
|
9 | #include <qpercentbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | Q_DECLARE_METATYPE(QAxis *) |
|
14 | Q_DECLARE_METATYPE(QAxis *) | |
15 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
15 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
17 | Q_DECLARE_METATYPE(QBrush) |
|
17 | Q_DECLARE_METATYPE(QBrush) | |
18 | Q_DECLARE_METATYPE(QPen) |
|
18 | Q_DECLARE_METATYPE(QPen) | |
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
20 |
|
20 | |||
21 | class tst_QChart : public QObject |
|
21 | class tst_QChart : public QObject | |
22 | { |
|
22 | { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 |
|
24 | |||
25 | public slots: |
|
25 | public slots: | |
26 | void initTestCase(); |
|
26 | void initTestCase(); | |
27 | void cleanupTestCase(); |
|
27 | void cleanupTestCase(); | |
28 | void init(); |
|
28 | void init(); | |
29 | void cleanup(); |
|
29 | void cleanup(); | |
30 |
|
30 | |||
31 | private slots: |
|
31 | private slots: | |
32 | void qchart_data(); |
|
32 | void qchart_data(); | |
33 | void qchart(); |
|
33 | void qchart(); | |
34 |
|
34 | |||
35 | void addSeries_data(); |
|
35 | void addSeries_data(); | |
36 | void addSeries(); |
|
36 | void addSeries(); | |
37 | void animationOptions_data(); |
|
37 | void animationOptions_data(); | |
38 | void animationOptions(); |
|
38 | void animationOptions(); | |
39 | void axisX_data(); |
|
39 | void axisX_data(); | |
40 | void axisX(); |
|
40 | void axisX(); | |
41 | void axisY_data(); |
|
41 | void axisY_data(); | |
42 | void axisY(); |
|
42 | void axisY(); | |
43 | void backgroundBrush_data(); |
|
43 | void backgroundBrush_data(); | |
44 | void backgroundBrush(); |
|
44 | void backgroundBrush(); | |
45 | void backgroundPen_data(); |
|
45 | void backgroundPen_data(); | |
46 | void backgroundPen(); |
|
46 | void backgroundPen(); | |
47 | void isBackgroundVisible_data(); |
|
47 | void isBackgroundVisible_data(); | |
48 | void isBackgroundVisible(); |
|
48 | void isBackgroundVisible(); | |
49 | void legend_data(); |
|
49 | void legend_data(); | |
50 | void legend(); |
|
50 | void legend(); | |
51 | void margins_data(); |
|
51 | void margins_data(); | |
52 | void margins(); |
|
52 | void margins(); | |
53 | void removeAllSeries_data(); |
|
53 | void removeAllSeries_data(); | |
54 | void removeAllSeries(); |
|
54 | void removeAllSeries(); | |
55 | void removeSeries_data(); |
|
55 | void removeSeries_data(); | |
56 | void removeSeries(); |
|
56 | void removeSeries(); | |
57 | void scrollDown_data(); |
|
57 | void scrollDown_data(); | |
58 | void scrollDown(); |
|
58 | void scrollDown(); | |
59 | void scrollLeft_data(); |
|
59 | void scrollLeft_data(); | |
60 | void scrollLeft(); |
|
60 | void scrollLeft(); | |
61 | void scrollRight_data(); |
|
61 | void scrollRight_data(); | |
62 | void scrollRight(); |
|
62 | void scrollRight(); | |
63 | void scrollUp_data(); |
|
63 | void scrollUp_data(); | |
64 | void scrollUp(); |
|
64 | void scrollUp(); | |
65 | void theme_data(); |
|
65 | void theme_data(); | |
66 | void theme(); |
|
66 | void theme(); | |
67 | void title_data(); |
|
67 | void title_data(); | |
68 | void title(); |
|
68 | void title(); | |
69 | void titleBrush_data(); |
|
69 | void titleBrush_data(); | |
70 | void titleBrush(); |
|
70 | void titleBrush(); | |
71 | void titleFont_data(); |
|
71 | void titleFont_data(); | |
72 | void titleFont(); |
|
72 | void titleFont(); | |
73 | void zoomIn_data(); |
|
73 | void zoomIn_data(); | |
74 | void zoomIn(); |
|
74 | void zoomIn(); | |
75 | void zoomOut_data(); |
|
75 | void zoomOut_data(); | |
76 | void zoomOut(); |
|
76 | void zoomOut(); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void createTestData(); |
|
79 | void createTestData(); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | QChartView* m_view; |
|
82 | QChartView* m_view; | |
83 | QChart* m_chart; |
|
83 | QChart* m_chart; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_QChart::initTestCase() |
|
86 | void tst_QChart::initTestCase() | |
87 | { |
|
87 | { | |
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void tst_QChart::cleanupTestCase() |
|
91 | void tst_QChart::cleanupTestCase() | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_QChart::init() |
|
96 | void tst_QChart::init() | |
97 | { |
|
97 | { | |
98 | m_view = new QChartView(new QChart()); |
|
98 | m_view = new QChartView(new QChart()); | |
99 | m_chart = m_view->chart(); |
|
99 | m_chart = m_view->chart(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void tst_QChart::createTestData() |
|
102 | void tst_QChart::createTestData() | |
103 | { |
|
103 | { | |
104 | QLineSeries* series0 = new QLineSeries(this); |
|
104 | QLineSeries* series0 = new QLineSeries(this); | |
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
106 | m_chart->addSeries(series0); |
|
106 | m_chart->addSeries(series0); | |
107 | m_view->show(); |
|
107 | m_view->show(); | |
108 | QTest::qWaitForWindowShown(m_view); |
|
108 | QTest::qWaitForWindowShown(m_view); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QChart::cleanup() |
|
111 | void tst_QChart::cleanup() | |
112 | { |
|
112 | { | |
113 | delete m_view; |
|
113 | delete m_view; | |
114 | m_view = 0; |
|
114 | m_view = 0; | |
115 | m_chart = 0; |
|
115 | m_chart = 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QChart::qchart_data() |
|
118 | void tst_QChart::qchart_data() | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QChart::qchart() |
|
122 | void tst_QChart::qchart() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_chart); |
|
124 | QVERIFY(m_chart); | |
125 | QVERIFY(m_chart->legend()); |
|
125 | QVERIFY(m_chart->legend()); | |
126 | QVERIFY(!m_chart->legend()->isVisible()); |
|
126 | QVERIFY(!m_chart->legend()->isVisible()); | |
127 |
|
127 | |||
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
129 | QVERIFY(m_chart->axisX()); |
|
129 | QVERIFY(m_chart->axisX()); | |
130 | QVERIFY(m_chart->axisY()); |
|
130 | QVERIFY(m_chart->axisY()); | |
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
134 |
|
134 | |||
135 | QVERIFY(m_chart->margins().top()>0); |
|
135 | QVERIFY(m_chart->margins().top()>0); | |
136 | QVERIFY(m_chart->margins().left()>0); |
|
136 | QVERIFY(m_chart->margins().left()>0); | |
137 | QVERIFY(m_chart->margins().right()>0); |
|
137 | QVERIFY(m_chart->margins().right()>0); | |
138 | QVERIFY(m_chart->margins().bottom()>0); |
|
138 | QVERIFY(m_chart->margins().bottom()>0); | |
139 |
|
139 | |||
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
141 | QCOMPARE(m_chart->title(), QString()); |
|
141 | QCOMPARE(m_chart->title(), QString()); | |
142 |
|
142 | |||
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
144 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
144 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
145 |
|
145 | |||
146 | m_chart->removeAllSeries(); |
|
146 | m_chart->removeAllSeries(); | |
147 | m_chart->scrollDown(); |
|
147 | m_chart->scrollDown(); | |
148 | m_chart->scrollLeft(); |
|
148 | m_chart->scrollLeft(); | |
149 | m_chart->scrollRight(); |
|
149 | m_chart->scrollRight(); | |
150 | m_chart->scrollUp(); |
|
150 | m_chart->scrollUp(); | |
151 |
|
151 | |||
152 | m_chart->zoomIn(); |
|
152 | m_chart->zoomIn(); | |
153 | m_chart->zoomIn(QRectF()); |
|
153 | m_chart->zoomIn(QRectF()); | |
154 | m_chart->zoomOut(); |
|
154 | m_chart->zoomOut(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void tst_QChart::addSeries_data() |
|
157 | void tst_QChart::addSeries_data() | |
158 | { |
|
158 | { | |
159 | QTest::addColumn<QAbstractSeries *>("series"); |
|
159 | QTest::addColumn<QAbstractSeries *>("series"); | |
160 | QTest::addColumn<QAxis *>("axis"); |
|
160 | QTest::addColumn<QAxis *>("axis"); | |
161 |
|
161 | |||
162 | QAbstractSeries* series0 = new QLineSeries(this); |
|
162 | QAbstractSeries* series0 = new QLineSeries(this); | |
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
164 | QAbstractSeries* series2 = new QScatterSeries(this); | |
165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
165 | QAbstractSeries* series3 = new QSplineSeries(this); | |
166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
166 | QAbstractSeries* series4 = new QPieSeries(this); | |
167 |
QAbstractSeries* series5 = new QBarSeries( |
|
167 | QAbstractSeries* series5 = new QBarSeries(this); | |
168 |
QAbstractSeries* series6 = new QPercentBarSeries( |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
169 |
QAbstractSeries* series7 = new QStackedBarSeries( |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
|
170 | ||||
|
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); | |||
|
172 | s5->setCategories(QBarCategories()); | |||
|
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); | |||
|
174 | s6->setCategories(QBarCategories()); | |||
|
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); | |||
|
176 | s7->setCategories(QBarCategories()); | |||
170 |
|
177 | |||
171 | QAxis* axis = new QAxis(this); |
|
178 | QAxis* axis = new QAxis(this); | |
172 |
|
179 | |||
173 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; |
|
180 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; | |
174 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
181 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
175 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; |
|
182 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; | |
176 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
183 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
177 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; |
|
184 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; | |
178 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
185 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
179 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; |
|
186 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; | |
180 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
187 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
181 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; |
|
188 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; | |
182 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
189 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
183 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; |
|
190 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; | |
184 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
191 | QTest::newRow("axis: barSeries") << series5 << axis; | |
185 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; |
|
192 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; | |
186 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
193 | QTest::newRow("axis: barSeries") << series6 << axis; | |
187 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; |
|
194 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; | |
188 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
195 | QTest::newRow("axis: barSeries") << series7 << axis; | |
189 |
|
196 | |||
190 | } |
|
197 | } | |
191 |
|
198 | |||
192 | void tst_QChart::addSeries() |
|
199 | void tst_QChart::addSeries() | |
193 | { |
|
200 | { | |
194 | QFETCH(QAbstractSeries *, series); |
|
201 | QFETCH(QAbstractSeries *, series); | |
195 | QFETCH(QAxis *, axis); |
|
202 | QFETCH(QAxis *, axis); | |
196 | m_view->show(); |
|
203 | m_view->show(); | |
197 | QTest::qWaitForWindowShown(m_view); |
|
204 | QTest::qWaitForWindowShown(m_view); | |
198 | if(!axis) axis = m_chart->axisY(); |
|
205 | if(!axis) axis = m_chart->axisY(); | |
199 | m_chart->addSeries(series,axis); |
|
206 | m_chart->addSeries(series,axis); | |
200 | QCOMPARE(m_chart->axisY(series),axis); |
|
207 | QCOMPARE(m_chart->axisY(series),axis); | |
201 | m_chart->removeSeries(series); |
|
208 | m_chart->removeSeries(series); | |
202 |
|
209 | |||
203 | } |
|
210 | } | |
204 |
|
211 | |||
205 | void tst_QChart::animationOptions_data() |
|
212 | void tst_QChart::animationOptions_data() | |
206 | { |
|
213 | { | |
207 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
214 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
208 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
215 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
209 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
216 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
210 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
217 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
211 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
218 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
212 | } |
|
219 | } | |
213 |
|
220 | |||
214 | void tst_QChart::animationOptions() |
|
221 | void tst_QChart::animationOptions() | |
215 | { |
|
222 | { | |
216 | createTestData(); |
|
223 | createTestData(); | |
217 | QFETCH(QChart::AnimationOption, animationOptions); |
|
224 | QFETCH(QChart::AnimationOption, animationOptions); | |
218 | m_chart->setAnimationOptions(animationOptions); |
|
225 | m_chart->setAnimationOptions(animationOptions); | |
219 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
226 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
220 | } |
|
227 | } | |
221 |
|
228 | |||
222 | void tst_QChart::axisX_data() |
|
229 | void tst_QChart::axisX_data() | |
223 | { |
|
230 | { | |
224 |
|
231 | |||
225 | } |
|
232 | } | |
226 |
|
233 | |||
227 | void tst_QChart::axisX() |
|
234 | void tst_QChart::axisX() | |
228 | { |
|
235 | { | |
229 | QVERIFY(m_chart->axisX()); |
|
236 | QVERIFY(m_chart->axisX()); | |
230 | QAxis* axis = m_chart->axisX(); |
|
237 | QAxis* axis = m_chart->axisX(); | |
231 | createTestData(); |
|
238 | createTestData(); | |
232 | //it should be the same axis |
|
239 | //it should be the same axis | |
233 | QCOMPARE(axis,m_chart->axisX()); |
|
240 | QCOMPARE(axis,m_chart->axisX()); | |
234 | } |
|
241 | } | |
235 |
|
242 | |||
236 | void tst_QChart::axisY_data() |
|
243 | void tst_QChart::axisY_data() | |
237 | { |
|
244 | { | |
238 | QTest::addColumn<QAxis*>("axis0"); |
|
245 | QTest::addColumn<QAxis*>("axis0"); | |
239 | QTest::addColumn<QAxis*>("axis1"); |
|
246 | QTest::addColumn<QAxis*>("axis1"); | |
240 | QTest::addColumn<QAxis*>("axis2"); |
|
247 | QTest::addColumn<QAxis*>("axis2"); | |
241 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
248 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
242 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
249 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
243 | } |
|
250 | } | |
244 |
|
251 | |||
245 |
|
252 | |||
246 | void tst_QChart::axisY() |
|
253 | void tst_QChart::axisY() | |
247 | { |
|
254 | { | |
248 | QFETCH(QAxis*, axis0); |
|
255 | QFETCH(QAxis*, axis0); | |
249 | QFETCH(QAxis*, axis1); |
|
256 | QFETCH(QAxis*, axis1); | |
250 | QFETCH(QAxis*, axis2); |
|
257 | QFETCH(QAxis*, axis2); | |
251 |
|
258 | |||
252 | QAxis* defaultAxisY = m_chart->axisY(); |
|
259 | QAxis* defaultAxisY = m_chart->axisY(); | |
253 |
|
260 | |||
254 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
261 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
255 |
|
262 | |||
256 | QLineSeries* series0 = new QLineSeries(); |
|
263 | QLineSeries* series0 = new QLineSeries(); | |
257 | m_chart->addSeries(series0, axis0); |
|
264 | m_chart->addSeries(series0, axis0); | |
258 |
|
265 | |||
259 | QLineSeries* series1 = new QLineSeries(); |
|
266 | QLineSeries* series1 = new QLineSeries(); | |
260 | m_chart->addSeries(series1, axis1); |
|
267 | m_chart->addSeries(series1, axis1); | |
261 |
|
268 | |||
262 | QLineSeries* series2 = new QLineSeries(); |
|
269 | QLineSeries* series2 = new QLineSeries(); | |
263 | m_chart->addSeries(series2, axis2); |
|
270 | m_chart->addSeries(series2, axis2); | |
264 |
|
271 | |||
265 | if (!axis0) |
|
272 | if (!axis0) | |
266 | axis0 = defaultAxisY; |
|
273 | axis0 = defaultAxisY; | |
267 | if (!axis1) |
|
274 | if (!axis1) | |
268 | axis1 = defaultAxisY; |
|
275 | axis1 = defaultAxisY; | |
269 | if (!axis2) |
|
276 | if (!axis2) | |
270 | axis2 = defaultAxisY; |
|
277 | axis2 = defaultAxisY; | |
271 |
|
278 | |||
272 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
279 | QVERIFY(m_chart->axisY(series0) == axis0); | |
273 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
280 | QVERIFY(m_chart->axisY(series1) == axis1); | |
274 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
281 | QVERIFY(m_chart->axisY(series2) == axis2); | |
275 | } |
|
282 | } | |
276 |
|
283 | |||
277 | void tst_QChart::backgroundBrush_data() |
|
284 | void tst_QChart::backgroundBrush_data() | |
278 | { |
|
285 | { | |
279 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
286 | QTest::addColumn<QBrush>("backgroundBrush"); | |
280 | QTest::newRow("null") << QBrush(); |
|
287 | QTest::newRow("null") << QBrush(); | |
281 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
288 | QTest::newRow("blue") << QBrush(Qt::blue); | |
282 | QTest::newRow("white") << QBrush(Qt::white); |
|
289 | QTest::newRow("white") << QBrush(Qt::white); | |
283 | QTest::newRow("black") << QBrush(Qt::black); |
|
290 | QTest::newRow("black") << QBrush(Qt::black); | |
284 | } |
|
291 | } | |
285 |
|
292 | |||
286 | void tst_QChart::backgroundBrush() |
|
293 | void tst_QChart::backgroundBrush() | |
287 | { |
|
294 | { | |
288 | QFETCH(QBrush, backgroundBrush); |
|
295 | QFETCH(QBrush, backgroundBrush); | |
289 | m_chart->setBackgroundBrush(backgroundBrush); |
|
296 | m_chart->setBackgroundBrush(backgroundBrush); | |
290 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
297 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
291 | } |
|
298 | } | |
292 |
|
299 | |||
293 | void tst_QChart::backgroundPen_data() |
|
300 | void tst_QChart::backgroundPen_data() | |
294 | { |
|
301 | { | |
295 | QTest::addColumn<QPen>("backgroundPen"); |
|
302 | QTest::addColumn<QPen>("backgroundPen"); | |
296 | QTest::newRow("null") << QPen(); |
|
303 | QTest::newRow("null") << QPen(); | |
297 | QTest::newRow("blue") << QPen(Qt::blue); |
|
304 | QTest::newRow("blue") << QPen(Qt::blue); | |
298 | QTest::newRow("white") << QPen(Qt::white); |
|
305 | QTest::newRow("white") << QPen(Qt::white); | |
299 | QTest::newRow("black") << QPen(Qt::black); |
|
306 | QTest::newRow("black") << QPen(Qt::black); | |
300 | } |
|
307 | } | |
301 |
|
308 | |||
302 |
|
309 | |||
303 | void tst_QChart::backgroundPen() |
|
310 | void tst_QChart::backgroundPen() | |
304 | { |
|
311 | { | |
305 | QFETCH(QPen, backgroundPen); |
|
312 | QFETCH(QPen, backgroundPen); | |
306 | m_chart->setBackgroundPen(backgroundPen); |
|
313 | m_chart->setBackgroundPen(backgroundPen); | |
307 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
314 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
308 | } |
|
315 | } | |
309 |
|
316 | |||
310 | void tst_QChart::isBackgroundVisible_data() |
|
317 | void tst_QChart::isBackgroundVisible_data() | |
311 | { |
|
318 | { | |
312 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
319 | QTest::addColumn<bool>("isBackgroundVisible"); | |
313 | QTest::newRow("true") << true; |
|
320 | QTest::newRow("true") << true; | |
314 | QTest::newRow("false") << false; |
|
321 | QTest::newRow("false") << false; | |
315 | } |
|
322 | } | |
316 |
|
323 | |||
317 | void tst_QChart::isBackgroundVisible() |
|
324 | void tst_QChart::isBackgroundVisible() | |
318 | { |
|
325 | { | |
319 | QFETCH(bool, isBackgroundVisible); |
|
326 | QFETCH(bool, isBackgroundVisible); | |
320 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
327 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
321 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
328 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
322 | } |
|
329 | } | |
323 |
|
330 | |||
324 | void tst_QChart::legend_data() |
|
331 | void tst_QChart::legend_data() | |
325 | { |
|
332 | { | |
326 |
|
333 | |||
327 | } |
|
334 | } | |
328 |
|
335 | |||
329 | void tst_QChart::legend() |
|
336 | void tst_QChart::legend() | |
330 | { |
|
337 | { | |
331 | QVERIFY(m_chart->legend()); |
|
338 | QVERIFY(m_chart->legend()); | |
332 | } |
|
339 | } | |
333 |
|
340 | |||
334 | void tst_QChart::margins_data() |
|
341 | void tst_QChart::margins_data() | |
335 | { |
|
342 | { | |
336 |
|
343 | |||
337 | } |
|
344 | } | |
338 |
|
345 | |||
339 | void tst_QChart::margins() |
|
346 | void tst_QChart::margins() | |
340 | { |
|
347 | { | |
341 | createTestData(); |
|
348 | createTestData(); | |
342 | QRectF rect = m_chart->geometry(); |
|
349 | QRectF rect = m_chart->geometry(); | |
343 |
|
350 | |||
344 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
351 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
345 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
352 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
346 | } |
|
353 | } | |
347 |
|
354 | |||
348 | void tst_QChart::removeAllSeries_data() |
|
355 | void tst_QChart::removeAllSeries_data() | |
349 | { |
|
356 | { | |
350 |
|
357 | |||
351 | } |
|
358 | } | |
352 |
|
359 | |||
353 | void tst_QChart::removeAllSeries() |
|
360 | void tst_QChart::removeAllSeries() | |
354 | { |
|
361 | { | |
355 | QLineSeries* series0 = new QLineSeries(this); |
|
362 | QLineSeries* series0 = new QLineSeries(this); | |
356 | QLineSeries* series1 = new QLineSeries(this); |
|
363 | QLineSeries* series1 = new QLineSeries(this); | |
357 | QLineSeries* series2 = new QLineSeries(this); |
|
364 | QLineSeries* series2 = new QLineSeries(this); | |
358 |
|
365 | |||
359 | m_chart->addSeries(series0); |
|
366 | m_chart->addSeries(series0); | |
360 | m_chart->addSeries(series1); |
|
367 | m_chart->addSeries(series1); | |
361 | m_chart->addSeries(series2); |
|
368 | m_chart->addSeries(series2); | |
362 | m_view->show(); |
|
369 | m_view->show(); | |
363 | QTest::qWaitForWindowShown(m_view); |
|
370 | QTest::qWaitForWindowShown(m_view); | |
364 |
|
371 | |||
365 | QVERIFY(m_chart->axisY(series0)!=0); |
|
372 | QVERIFY(m_chart->axisY(series0)!=0); | |
366 | QVERIFY(m_chart->axisY(series1)!=0); |
|
373 | QVERIFY(m_chart->axisY(series1)!=0); | |
367 | QVERIFY(m_chart->axisY(series2)!=0); |
|
374 | QVERIFY(m_chart->axisY(series2)!=0); | |
368 |
|
375 | |||
369 | m_chart->removeAllSeries(); |
|
376 | m_chart->removeAllSeries(); | |
370 |
|
377 | |||
371 | QVERIFY(m_chart->axisY(series0)==0); |
|
378 | QVERIFY(m_chart->axisY(series0)==0); | |
372 | QVERIFY(m_chart->axisY(series1)==0); |
|
379 | QVERIFY(m_chart->axisY(series1)==0); | |
373 | QVERIFY(m_chart->axisY(series2)==0); |
|
380 | QVERIFY(m_chart->axisY(series2)==0); | |
374 | } |
|
381 | } | |
375 |
|
382 | |||
376 | void tst_QChart::removeSeries_data() |
|
383 | void tst_QChart::removeSeries_data() | |
377 | { |
|
384 | { | |
378 | addSeries_data(); |
|
385 | addSeries_data(); | |
379 | } |
|
386 | } | |
380 |
|
387 | |||
381 | void tst_QChart::removeSeries() |
|
388 | void tst_QChart::removeSeries() | |
382 | { |
|
389 | { | |
383 | QFETCH(QAbstractSeries *, series); |
|
390 | QFETCH(QAbstractSeries *, series); | |
384 | QFETCH(QAxis *, axis); |
|
391 | QFETCH(QAxis *, axis); | |
385 | m_view->show(); |
|
392 | m_view->show(); | |
386 | QTest::qWaitForWindowShown(m_view); |
|
393 | QTest::qWaitForWindowShown(m_view); | |
387 | if(!axis) axis = m_chart->axisY(); |
|
394 | if(!axis) axis = m_chart->axisY(); | |
388 | m_chart->addSeries(series,axis); |
|
395 | m_chart->addSeries(series,axis); | |
389 | QCOMPARE(m_chart->axisY(series),axis); |
|
396 | QCOMPARE(m_chart->axisY(series),axis); | |
390 | m_chart->removeSeries(series); |
|
397 | m_chart->removeSeries(series); | |
391 | QVERIFY(m_chart->axisY(series)==0); |
|
398 | QVERIFY(m_chart->axisY(series)==0); | |
392 | } |
|
399 | } | |
393 |
|
400 | |||
394 | void tst_QChart::scrollDown_data() |
|
401 | void tst_QChart::scrollDown_data() | |
395 | { |
|
402 | { | |
396 |
|
403 | |||
397 | } |
|
404 | } | |
398 |
|
405 | |||
399 | void tst_QChart::scrollDown() |
|
406 | void tst_QChart::scrollDown() | |
400 | { |
|
407 | { | |
401 | createTestData(); |
|
408 | createTestData(); | |
402 | qreal min = m_chart->axisY()->min(); |
|
409 | qreal min = m_chart->axisY()->min(); | |
403 | m_chart->scrollDown(); |
|
410 | m_chart->scrollDown(); | |
404 | QVERIFY(m_chart->axisY()->min()<min); |
|
411 | QVERIFY(m_chart->axisY()->min()<min); | |
405 | } |
|
412 | } | |
406 |
|
413 | |||
407 | void tst_QChart::scrollLeft_data() |
|
414 | void tst_QChart::scrollLeft_data() | |
408 | { |
|
415 | { | |
409 |
|
416 | |||
410 | } |
|
417 | } | |
411 |
|
418 | |||
412 | void tst_QChart::scrollLeft() |
|
419 | void tst_QChart::scrollLeft() | |
413 | { |
|
420 | { | |
414 | createTestData(); |
|
421 | createTestData(); | |
415 | qreal min = m_chart->axisX()->min(); |
|
422 | qreal min = m_chart->axisX()->min(); | |
416 | m_chart->scrollLeft(); |
|
423 | m_chart->scrollLeft(); | |
417 | QVERIFY(m_chart->axisX()->min()<min); |
|
424 | QVERIFY(m_chart->axisX()->min()<min); | |
418 | } |
|
425 | } | |
419 |
|
426 | |||
420 | void tst_QChart::scrollRight_data() |
|
427 | void tst_QChart::scrollRight_data() | |
421 | { |
|
428 | { | |
422 |
|
429 | |||
423 | } |
|
430 | } | |
424 |
|
431 | |||
425 | void tst_QChart::scrollRight() |
|
432 | void tst_QChart::scrollRight() | |
426 | { |
|
433 | { | |
427 | createTestData(); |
|
434 | createTestData(); | |
428 | qreal min = m_chart->axisX()->min(); |
|
435 | qreal min = m_chart->axisX()->min(); | |
429 | m_chart->scrollRight(); |
|
436 | m_chart->scrollRight(); | |
430 | QVERIFY(m_chart->axisX()->min()>min); |
|
437 | QVERIFY(m_chart->axisX()->min()>min); | |
431 | } |
|
438 | } | |
432 |
|
439 | |||
433 | void tst_QChart::scrollUp_data() |
|
440 | void tst_QChart::scrollUp_data() | |
434 | { |
|
441 | { | |
435 |
|
442 | |||
436 | } |
|
443 | } | |
437 |
|
444 | |||
438 | void tst_QChart::scrollUp() |
|
445 | void tst_QChart::scrollUp() | |
439 | { |
|
446 | { | |
440 | createTestData(); |
|
447 | createTestData(); | |
441 | qreal min = m_chart->axisY()->min(); |
|
448 | qreal min = m_chart->axisY()->min(); | |
442 | m_chart->scrollUp(); |
|
449 | m_chart->scrollUp(); | |
443 | QVERIFY(m_chart->axisY()->min()>min); |
|
450 | QVERIFY(m_chart->axisY()->min()>min); | |
444 | } |
|
451 | } | |
445 |
|
452 | |||
446 | void tst_QChart::theme_data() |
|
453 | void tst_QChart::theme_data() | |
447 | { |
|
454 | { | |
448 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
455 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
449 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
456 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
450 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
457 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
451 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
458 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
452 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
459 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
453 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
460 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
454 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
461 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
455 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
462 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
456 | } |
|
463 | } | |
457 |
|
464 | |||
458 | void tst_QChart::theme() |
|
465 | void tst_QChart::theme() | |
459 | { |
|
466 | { | |
460 | QFETCH(QChart::ChartTheme, theme); |
|
467 | QFETCH(QChart::ChartTheme, theme); | |
461 | createTestData(); |
|
468 | createTestData(); | |
462 | m_chart->setTheme(theme); |
|
469 | m_chart->setTheme(theme); | |
463 | QVERIFY(m_chart->theme()==theme); |
|
470 | QVERIFY(m_chart->theme()==theme); | |
464 | } |
|
471 | } | |
465 |
|
472 | |||
466 | void tst_QChart::title_data() |
|
473 | void tst_QChart::title_data() | |
467 | { |
|
474 | { | |
468 | QTest::addColumn<QString>("title"); |
|
475 | QTest::addColumn<QString>("title"); | |
469 | QTest::newRow("null") << QString(); |
|
476 | QTest::newRow("null") << QString(); | |
470 | QTest::newRow("foo") << QString("foo"); |
|
477 | QTest::newRow("foo") << QString("foo"); | |
471 | } |
|
478 | } | |
472 |
|
479 | |||
473 | void tst_QChart::title() |
|
480 | void tst_QChart::title() | |
474 | { |
|
481 | { | |
475 | QFETCH(QString, title); |
|
482 | QFETCH(QString, title); | |
476 | m_chart->setTitle(title); |
|
483 | m_chart->setTitle(title); | |
477 | QCOMPARE(m_chart->title(), title); |
|
484 | QCOMPARE(m_chart->title(), title); | |
478 | } |
|
485 | } | |
479 |
|
486 | |||
480 | void tst_QChart::titleBrush_data() |
|
487 | void tst_QChart::titleBrush_data() | |
481 | { |
|
488 | { | |
482 | QTest::addColumn<QBrush>("titleBrush"); |
|
489 | QTest::addColumn<QBrush>("titleBrush"); | |
483 | QTest::newRow("null") << QBrush(); |
|
490 | QTest::newRow("null") << QBrush(); | |
484 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
491 | QTest::newRow("blue") << QBrush(Qt::blue); | |
485 | QTest::newRow("white") << QBrush(Qt::white); |
|
492 | QTest::newRow("white") << QBrush(Qt::white); | |
486 | QTest::newRow("black") << QBrush(Qt::black); |
|
493 | QTest::newRow("black") << QBrush(Qt::black); | |
487 | } |
|
494 | } | |
488 |
|
495 | |||
489 | void tst_QChart::titleBrush() |
|
496 | void tst_QChart::titleBrush() | |
490 | { |
|
497 | { | |
491 | QFETCH(QBrush, titleBrush); |
|
498 | QFETCH(QBrush, titleBrush); | |
492 | m_chart->setTitleBrush(titleBrush); |
|
499 | m_chart->setTitleBrush(titleBrush); | |
493 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
500 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
494 | } |
|
501 | } | |
495 |
|
502 | |||
496 | void tst_QChart::titleFont_data() |
|
503 | void tst_QChart::titleFont_data() | |
497 | { |
|
504 | { | |
498 | QTest::addColumn<QFont>("titleFont"); |
|
505 | QTest::addColumn<QFont>("titleFont"); | |
499 | QTest::newRow("null") << QFont(); |
|
506 | QTest::newRow("null") << QFont(); | |
500 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
507 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
501 | } |
|
508 | } | |
502 |
|
509 | |||
503 | void tst_QChart::titleFont() |
|
510 | void tst_QChart::titleFont() | |
504 | { |
|
511 | { | |
505 | QFETCH(QFont, titleFont); |
|
512 | QFETCH(QFont, titleFont); | |
506 | m_chart->setTitleFont(titleFont); |
|
513 | m_chart->setTitleFont(titleFont); | |
507 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
514 | QCOMPARE(m_chart->titleFont(), titleFont); | |
508 | } |
|
515 | } | |
509 |
|
516 | |||
510 | void tst_QChart::zoomIn_data() |
|
517 | void tst_QChart::zoomIn_data() | |
511 | { |
|
518 | { | |
512 | QTest::addColumn<QRectF>("rect"); |
|
519 | QTest::addColumn<QRectF>("rect"); | |
513 | QTest::newRow("null") << QRectF(); |
|
520 | QTest::newRow("null") << QRectF(); | |
514 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
521 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
515 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
522 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
516 | } |
|
523 | } | |
517 |
|
524 | |||
518 |
|
525 | |||
519 | void tst_QChart::zoomIn() |
|
526 | void tst_QChart::zoomIn() | |
520 | { |
|
527 | { | |
521 | QFETCH(QRectF, rect); |
|
528 | QFETCH(QRectF, rect); | |
522 | createTestData(); |
|
529 | createTestData(); | |
523 | QRectF marigns = m_chart->margins(); |
|
530 | QRectF marigns = m_chart->margins(); | |
524 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
531 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
525 | qreal minX = m_chart->axisX()->min(); |
|
532 | qreal minX = m_chart->axisX()->min(); | |
526 | qreal minY = m_chart->axisY()->min(); |
|
533 | qreal minY = m_chart->axisY()->min(); | |
527 | qreal maxX = m_chart->axisX()->max(); |
|
534 | qreal maxX = m_chart->axisX()->max(); | |
528 | qreal maxY = m_chart->axisY()->max(); |
|
535 | qreal maxY = m_chart->axisY()->max(); | |
529 | m_chart->zoomIn(rect); |
|
536 | m_chart->zoomIn(rect); | |
530 | if(rect.isValid()){ |
|
537 | if(rect.isValid()){ | |
531 | QVERIFY(minX<m_chart->axisX()->min()); |
|
538 | QVERIFY(minX<m_chart->axisX()->min()); | |
532 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
539 | QVERIFY(maxX>m_chart->axisX()->max()); | |
533 | QVERIFY(minY<m_chart->axisY()->min()); |
|
540 | QVERIFY(minY<m_chart->axisY()->min()); | |
534 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
541 | QVERIFY(maxY>m_chart->axisY()->max()); | |
535 | } |
|
542 | } | |
536 | } |
|
543 | } | |
537 |
|
544 | |||
538 | void tst_QChart::zoomOut_data() |
|
545 | void tst_QChart::zoomOut_data() | |
539 | { |
|
546 | { | |
540 |
|
547 | |||
541 | } |
|
548 | } | |
542 |
|
549 | |||
543 | void tst_QChart::zoomOut() |
|
550 | void tst_QChart::zoomOut() | |
544 | { |
|
551 | { | |
545 | createTestData(); |
|
552 | createTestData(); | |
546 | qreal minX = m_chart->axisX()->min(); |
|
553 | qreal minX = m_chart->axisX()->min(); | |
547 | qreal minY = m_chart->axisY()->min(); |
|
554 | qreal minY = m_chart->axisY()->min(); | |
548 | qreal maxX = m_chart->axisX()->max(); |
|
555 | qreal maxX = m_chart->axisX()->max(); | |
549 | qreal maxY = m_chart->axisY()->max(); |
|
556 | qreal maxY = m_chart->axisY()->max(); | |
550 |
|
557 | |||
551 | m_chart->zoomIn(); |
|
558 | m_chart->zoomIn(); | |
552 |
|
559 | |||
553 | QVERIFY(minX<m_chart->axisX()->min()); |
|
560 | QVERIFY(minX < m_chart->axisX()->min()); | |
554 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
561 | QVERIFY(maxX > m_chart->axisX()->max()); | |
555 | QVERIFY(minY<m_chart->axisY()->min()); |
|
562 | QVERIFY(minY < m_chart->axisY()->min()); | |
556 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
563 | QVERIFY(maxY > m_chart->axisY()->max()); | |
557 |
|
564 | |||
558 | m_chart->zoomOut(); |
|
565 | m_chart->zoomOut(); | |
559 |
|
566 | |||
560 | QVERIFY(minX==m_chart->axisX()->min()); |
|
567 | // min x may be a zero value | |
561 | QVERIFY(maxX==m_chart->axisX()->max()); |
|
568 | if (qFuzzyIsNull(minX)) | |
562 |
QVERIFY( |
|
569 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
563 | QVERIFY(maxY==m_chart->axisY()->max()); |
|
570 | else | |
|
571 | QCOMPARE(minX, m_chart->axisX()->min()); | |||
|
572 | ||||
|
573 | // min y may be a zero value | |||
|
574 | if (qFuzzyIsNull(minY)) | |||
|
575 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |||
|
576 | else | |||
|
577 | QCOMPARE(minY, m_chart->axisY()->min()); | |||
|
578 | ||||
|
579 | QVERIFY(maxX == m_chart->axisX()->max()); | |||
|
580 | QVERIFY(maxY == m_chart->axisY()->max()); | |||
564 | } |
|
581 | } | |
565 |
|
582 | |||
566 | QTEST_MAIN(tst_QChart) |
|
583 | QTEST_MAIN(tst_QChart) | |
567 | #include "tst_qchart.moc" |
|
584 | #include "tst_qchart.moc" | |
568 |
|
585 |
@@ -1,170 +1,171 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <cmath> |
|
24 | #include <cmath> | |
|
25 | #include <tst_definitions.h> | |||
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
28 | |||
28 |
|
29 | |||
29 | Q_DECLARE_METATYPE(QChart*) |
|
30 | Q_DECLARE_METATYPE(QChart*) | |
30 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) | |
31 | Q_DECLARE_METATYPE(Qt::Key) |
|
32 | Q_DECLARE_METATYPE(Qt::Key) | |
32 |
|
33 | |||
33 | class tst_QChartView : public QObject |
|
34 | class tst_QChartView : public QObject | |
34 | { |
|
35 | { | |
35 | Q_OBJECT |
|
36 | Q_OBJECT | |
36 |
|
37 | |||
37 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
38 | void initTestCase(); |
|
39 | void initTestCase(); | |
39 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
40 | void init(); |
|
41 | void init(); | |
41 | void cleanup(); |
|
42 | void cleanup(); | |
42 |
|
43 | |||
43 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
44 | void qchartview_data(); |
|
45 | void qchartview_data(); | |
45 | void qchartview(); |
|
46 | void qchartview(); | |
46 | void chart_data(); |
|
47 | void chart_data(); | |
47 | void chart(); |
|
48 | void chart(); | |
48 | void rubberBand_data(); |
|
49 | void rubberBand_data(); | |
49 | void rubberBand(); |
|
50 | void rubberBand(); | |
50 |
|
51 | |||
51 | private: |
|
52 | private: | |
52 | QChartView* m_view; |
|
53 | QChartView* m_view; | |
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | void tst_QChartView::initTestCase() |
|
56 | void tst_QChartView::initTestCase() | |
56 | { |
|
57 | { | |
57 | //test tracks mouse, give a while to user to relese it |
|
58 | //test tracks mouse, give a while to user to relese it | |
58 | QTest::qWait(1000); |
|
59 | QTest::qWait(1000); | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | void tst_QChartView::cleanupTestCase() |
|
62 | void tst_QChartView::cleanupTestCase() | |
62 | { |
|
63 | { | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | void tst_QChartView::init() |
|
66 | void tst_QChartView::init() | |
66 | { |
|
67 | { | |
67 | m_view = new QChartView(new QChart()); |
|
68 | m_view = new QChartView(new QChart()); | |
68 | m_view->chart()->legend()->setVisible(false); |
|
69 | m_view->chart()->legend()->setVisible(false); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | void tst_QChartView::cleanup() |
|
72 | void tst_QChartView::cleanup() | |
72 | { |
|
73 | { | |
73 | delete m_view; |
|
74 | delete m_view; | |
74 | m_view =0; |
|
75 | m_view =0; | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | void tst_QChartView::qchartview_data() |
|
78 | void tst_QChartView::qchartview_data() | |
78 | { |
|
79 | { | |
79 |
|
80 | |||
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | void tst_QChartView::qchartview() |
|
83 | void tst_QChartView::qchartview() | |
83 | { |
|
84 | { | |
84 | QVERIFY(m_view->chart()); |
|
85 | QVERIFY(m_view->chart()); | |
85 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
86 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
86 | m_view->show(); |
|
87 | m_view->show(); | |
87 | QTest::qWaitForWindowShown(m_view); |
|
88 | QTest::qWaitForWindowShown(m_view); | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | void tst_QChartView::chart_data() |
|
91 | void tst_QChartView::chart_data() | |
91 | { |
|
92 | { | |
92 |
|
93 | |||
93 | QTest::addColumn<QChart*>("chart"); |
|
94 | QTest::addColumn<QChart*>("chart"); | |
94 | QTest::newRow("qchart") << new QChart(); |
|
95 | QTest::newRow("qchart") << new QChart(); | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | void tst_QChartView::chart() |
|
98 | void tst_QChartView::chart() | |
98 | { |
|
99 | { | |
99 | QFETCH(QChart*, chart); |
|
100 | QFETCH(QChart*, chart); | |
100 | QChartView* view = new QChartView(chart); |
|
101 | QChartView* view = new QChartView(chart); | |
101 | QCOMPARE(view->chart(), chart); |
|
102 | QCOMPARE(view->chart(), chart); | |
102 | delete view; |
|
103 | delete view; | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | void tst_QChartView::rubberBand_data() |
|
106 | void tst_QChartView::rubberBand_data() | |
106 | { |
|
107 | { | |
107 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
108 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
108 | QTest::addColumn<int>("Xcount"); |
|
109 | QTest::addColumn<int>("Xcount"); | |
109 | QTest::addColumn<int>("Ycount"); |
|
110 | QTest::addColumn<int>("Ycount"); | |
110 |
|
111 | |||
111 | QTest::addColumn<int>("minX"); |
|
112 | QTest::addColumn<int>("minX"); | |
112 | QTest::addColumn<int>("maxX"); |
|
113 | QTest::addColumn<int>("maxX"); | |
113 | QTest::addColumn<int>("minY"); |
|
114 | QTest::addColumn<int>("minY"); | |
114 | QTest::addColumn<int>("maxY"); |
|
115 | QTest::addColumn<int>("maxY"); | |
115 |
|
116 | |||
116 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
117 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; | |
117 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
118 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; | |
118 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
119 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; | |
119 | } |
|
120 | } | |
120 |
|
121 | |||
121 | void tst_QChartView::rubberBand() |
|
122 | void tst_QChartView::rubberBand() | |
122 | { |
|
123 | { | |
123 | QFETCH(QChartView::RubberBands, rubberBand); |
|
124 | QFETCH(QChartView::RubberBands, rubberBand); | |
124 | QFETCH(int, Xcount); |
|
125 | QFETCH(int, Xcount); | |
125 | QFETCH(int, Ycount); |
|
126 | QFETCH(int, Ycount); | |
126 | QFETCH(int, minX); |
|
127 | QFETCH(int, minX); | |
127 | QFETCH(int, maxX); |
|
128 | QFETCH(int, maxX); | |
128 | QFETCH(int, minY); |
|
129 | QFETCH(int, minY); | |
129 | QFETCH(int, maxY); |
|
130 | QFETCH(int, maxY); | |
130 |
|
131 | |||
131 | m_view->setRubberBand(rubberBand); |
|
132 | m_view->setRubberBand(rubberBand); | |
132 | QRectF padding = m_view->chart()->margins(); |
|
133 | QRectF padding = m_view->chart()->margins(); | |
133 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
134 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
134 |
|
135 | |||
135 | QLineSeries* line = new QLineSeries(); |
|
136 | QLineSeries* line = new QLineSeries(); | |
136 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
137 | *line << QPointF(0, 0) << QPointF(200, 200); | |
137 |
|
138 | |||
138 | m_view->chart()->addSeries(line); |
|
139 | m_view->chart()->addSeries(line); | |
139 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
140 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); | |
140 | m_view->show(); |
|
141 | m_view->show(); | |
141 |
|
142 | |||
142 | //this is hack since view does not get events otherwise |
|
143 | //this is hack since view does not get events otherwise | |
143 | m_view->setMouseTracking(true); |
|
144 | m_view->setMouseTracking(true); | |
144 |
|
145 | |||
145 | QAxis* axisY = m_view->chart()->axisY(); |
|
146 | QAxis* axisY = m_view->chart()->axisY(); | |
146 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
147 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); | |
147 | QAxis* axisX = m_view->chart()->axisX(); |
|
148 | QAxis* axisX = m_view->chart()->axisX(); | |
148 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
149 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); | |
149 |
|
150 | |||
150 | QTest::qWaitForWindowShown(m_view); |
|
151 | QTest::qWaitForWindowShown(m_view); | |
151 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
152 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); | |
152 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
153 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); | |
153 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
154 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); | |
154 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
155 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); | |
155 |
|
156 | |||
156 |
|
|
157 | TRY_COMPARE(spy0.count(), Xcount); | |
157 |
|
|
158 | TRY_COMPARE(spy1.count(), Ycount); | |
158 |
|
159 | |||
159 | //this is hack since view does not get events otherwise |
|
160 | //this is hack since view does not get events otherwise | |
160 | m_view->setMouseTracking(false); |
|
161 | m_view->setMouseTracking(false); | |
161 |
|
162 | |||
162 | QVERIFY(axisX->min() - minX < 1); |
|
163 | QVERIFY(axisX->min() - minX < 1); | |
163 | QVERIFY(axisX->max() - maxX < 1); |
|
164 | QVERIFY(axisX->max() - maxX < 1); | |
164 | QVERIFY(axisY->min() - minY < 1); |
|
165 | QVERIFY(axisY->min() - minY < 1); | |
165 | QVERIFY(axisY->max() - maxY < 1); |
|
166 | QVERIFY(axisY->max() - maxY < 1); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | QTEST_MAIN(tst_QChartView) |
|
169 | QTEST_MAIN(tst_QChartView) | |
169 | #include "tst_qchartview.moc" |
|
170 | #include "tst_qchartview.moc" | |
170 |
|
171 |
@@ -1,636 +1,625 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qlineseries.h> |
|
22 | #include <qlineseries.h> | |
23 | #include <qchartview.h> |
|
23 | #include <qchartview.h> | |
24 | #include <QStandardItemModel> |
|
24 | #include <QStandardItemModel> | |
|
25 | #include <tst_definitions.h> | |||
25 |
|
26 | |||
26 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
27 | Q_DECLARE_METATYPE(QList<QPointF>) | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
30 | |||
30 | class tst_QLineSeries : public QObject |
|
31 | class tst_QLineSeries : public QObject | |
31 | { |
|
32 | { | |
32 | Q_OBJECT |
|
33 | Q_OBJECT | |
33 |
|
34 | |||
34 | public slots: |
|
35 | public slots: | |
35 | void initTestCase(); |
|
36 | void initTestCase(); | |
36 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
37 | void init(); |
|
38 | void init(); | |
38 | void cleanup(); |
|
39 | void cleanup(); | |
39 |
|
40 | |||
40 | private slots: |
|
41 | private slots: | |
41 | void qlineseries_data(); |
|
42 | void qlineseries_data(); | |
42 | void qlineseries(); |
|
43 | void qlineseries(); | |
43 | void append_raw_data(); |
|
44 | void append_raw_data(); | |
44 | void append_raw(); |
|
45 | void append_raw(); | |
45 | void append_chart_data(); |
|
46 | void append_chart_data(); | |
46 | void append_chart(); |
|
47 | void append_chart(); | |
47 | void append_chart_animation_data(); |
|
48 | void append_chart_animation_data(); | |
48 | void append_chart_animation(); |
|
49 | void append_chart_animation(); | |
49 | void chart_append_data(); |
|
50 | void chart_append_data(); | |
50 | void chart_append(); |
|
51 | void chart_append(); | |
51 | void count_raw_data(); |
|
52 | void count_raw_data(); | |
52 | void count_raw(); |
|
53 | void count_raw(); | |
53 | void oper_data(); |
|
54 | void oper_data(); | |
54 | void oper(); |
|
55 | void oper(); | |
55 | void pen_data(); |
|
56 | void pen_data(); | |
56 | void pen(); |
|
57 | void pen(); | |
57 | void pointsVisible_raw_data(); |
|
58 | void pointsVisible_raw_data(); | |
58 | void pointsVisible_raw(); |
|
59 | void pointsVisible_raw(); | |
59 | void remove_raw_data(); |
|
60 | void remove_raw_data(); | |
60 | void remove_raw(); |
|
61 | void remove_raw(); | |
61 | void remove_chart_data(); |
|
62 | void remove_chart_data(); | |
62 | void remove_chart(); |
|
63 | void remove_chart(); | |
63 | void remove_chart_animation_data(); |
|
64 | void remove_chart_animation_data(); | |
64 | void remove_chart_animation(); |
|
65 | void remove_chart_animation(); | |
65 | void removeAll_raw_data(); |
|
66 | void removeAll_raw_data(); | |
66 | void removeAll_raw(); |
|
67 | void removeAll_raw(); | |
67 | void removeAll_chart_data(); |
|
68 | void removeAll_chart_data(); | |
68 | void removeAll_chart(); |
|
69 | void removeAll_chart(); | |
69 | void removeAll_chart_animation_data(); |
|
70 | void removeAll_chart_animation_data(); | |
70 | void removeAll_chart_animation(); |
|
71 | void removeAll_chart_animation(); | |
71 | void replace_raw_data(); |
|
72 | void replace_raw_data(); | |
72 | void replace_raw(); |
|
73 | void replace_raw(); | |
73 | void replace_chart_data(); |
|
74 | void replace_chart_data(); | |
74 | void replace_chart(); |
|
75 | void replace_chart(); | |
75 | void replace_chart_animation_data(); |
|
76 | void replace_chart_animation_data(); | |
76 | void replace_chart_animation(); |
|
77 | void replace_chart_animation(); | |
77 | void setModel_data(); |
|
78 | void setModel_data(); | |
78 | void setModel(); |
|
79 | void setModel(); | |
79 | void setModelMapping_data(); |
|
80 | void setModelMapping_data(); | |
80 | void setModelMapping(); |
|
81 | void setModelMapping(); | |
81 | void setModelMappingRange_data(); |
|
82 | void setModelMappingRange_data(); | |
82 | void setModelMappingRange(); |
|
83 | void setModelMappingRange(); | |
83 | void modelUpdated(); |
|
84 | void modelUpdated(); | |
84 | void modelUpdatedCustomMapping(); |
|
85 | void modelUpdatedCustomMapping(); | |
85 | private: |
|
86 | private: | |
86 | void append_data(); |
|
87 | void append_data(); | |
87 | void count_data(); |
|
88 | void count_data(); | |
88 | void pointsVisible_data(); |
|
89 | void pointsVisible_data(); | |
89 |
|
90 | |||
90 | private: |
|
91 | private: | |
91 | QChartView* m_view; |
|
92 | QChartView* m_view; | |
92 | QChart* m_chart; |
|
93 | QChart* m_chart; | |
93 | QLineSeries* m_series; |
|
94 | QLineSeries* m_series; | |
94 | }; |
|
95 | }; | |
95 |
|
96 | |||
96 | void tst_QLineSeries::initTestCase() |
|
97 | void tst_QLineSeries::initTestCase() | |
97 | { |
|
98 | { | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void tst_QLineSeries::cleanupTestCase() |
|
101 | void tst_QLineSeries::cleanupTestCase() | |
101 | { |
|
102 | { | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | void tst_QLineSeries::init() |
|
105 | void tst_QLineSeries::init() | |
105 | { |
|
106 | { | |
106 | m_view = new QChartView(new QChart()); |
|
107 | m_view = new QChartView(new QChart()); | |
107 | m_chart = m_view->chart(); |
|
108 | m_chart = m_view->chart(); | |
108 | m_series = new QLineSeries(); |
|
109 | m_series = new QLineSeries(); | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | void tst_QLineSeries::cleanup() |
|
112 | void tst_QLineSeries::cleanup() | |
112 | { |
|
113 | { | |
113 | delete m_series; |
|
114 | delete m_series; | |
114 | delete m_view; |
|
115 | delete m_view; | |
115 | m_view = 0; |
|
116 | m_view = 0; | |
116 | m_chart = 0; |
|
117 | m_chart = 0; | |
117 | m_series = 0; |
|
118 | m_series = 0; | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | void tst_QLineSeries::qlineseries_data() |
|
121 | void tst_QLineSeries::qlineseries_data() | |
121 | { |
|
122 | { | |
122 |
|
123 | |||
123 | } |
|
124 | } | |
124 |
|
125 | |||
125 | void tst_QLineSeries::qlineseries() |
|
126 | void tst_QLineSeries::qlineseries() | |
126 | { |
|
127 | { | |
127 | QLineSeries series; |
|
128 | QLineSeries series; | |
128 |
|
129 | |||
129 | QCOMPARE(series.count(),0); |
|
130 | QCOMPARE(series.count(),0); | |
130 | QCOMPARE(series.brush(), QBrush()); |
|
131 | QCOMPARE(series.brush(), QBrush()); | |
131 | QCOMPARE(series.points(), QList<QPointF>()); |
|
132 | QCOMPARE(series.points(), QList<QPointF>()); | |
132 | QCOMPARE(series.pen(), QPen()); |
|
133 | QCOMPARE(series.pen(), QPen()); | |
133 | QCOMPARE(series.pointsVisible(), false); |
|
134 | QCOMPARE(series.pointsVisible(), false); | |
134 |
|
135 | |||
135 | series.append(QList<QPointF>()); |
|
136 | series.append(QList<QPointF>()); | |
136 | series.append(0.0,0.0); |
|
137 | series.append(0.0,0.0); | |
137 | series.append(QPointF()); |
|
138 | series.append(QPointF()); | |
138 |
|
139 | |||
139 | series.remove(0.0,0.0); |
|
140 | series.remove(0.0,0.0); | |
140 | series.remove(QPointF()); |
|
141 | series.remove(QPointF()); | |
141 | series.removeAll(); |
|
142 | series.removeAll(); | |
142 |
|
143 | |||
143 | series.replace(QPointF(),QPointF()); |
|
144 | series.replace(QPointF(),QPointF()); | |
144 | series.replace(0,0,0,0); |
|
145 | series.replace(0,0,0,0); | |
145 | series.setBrush(QBrush()); |
|
146 | series.setBrush(QBrush()); | |
146 |
|
147 | |||
147 | QCOMPARE(series.setModel((QAbstractItemModel*)0), false); |
|
148 | QCOMPARE(series.setModel((QAbstractItemModel*)0), false); | |
148 |
|
149 | |||
149 | series.setModelMapping(-1, -1, Qt::Orientation(0)); |
|
150 | series.setModelMapping(-1, -1, Qt::Orientation(0)); | |
150 |
|
151 | |||
151 | series.setPen(QPen()); |
|
152 | series.setPen(QPen()); | |
152 | series.setPointsVisible(false); |
|
153 | series.setPointsVisible(false); | |
153 |
|
154 | |||
154 | m_chart->addSeries(&series); |
|
155 | m_chart->addSeries(&series); | |
155 | m_view->show(); |
|
156 | m_view->show(); | |
156 | QTest::qWaitForWindowShown(m_view); |
|
157 | QTest::qWaitForWindowShown(m_view); | |
157 | } |
|
158 | } | |
158 |
|
159 | |||
159 | void tst_QLineSeries::append_data() |
|
160 | void tst_QLineSeries::append_data() | |
160 | { |
|
161 | { | |
161 | QTest::addColumn< QList<QPointF> >("points"); |
|
162 | QTest::addColumn< QList<QPointF> >("points"); | |
162 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); |
|
163 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); | |
163 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); |
|
164 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); | |
164 | } |
|
165 | } | |
165 |
|
166 | |||
166 |
|
167 | |||
167 | void tst_QLineSeries::append_raw_data() |
|
168 | void tst_QLineSeries::append_raw_data() | |
168 | { |
|
169 | { | |
169 | append_data(); |
|
170 | append_data(); | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 | void tst_QLineSeries::append_raw() |
|
173 | void tst_QLineSeries::append_raw() | |
173 | { |
|
174 | { | |
174 | QFETCH(QList<QPointF>, points); |
|
175 | QFETCH(QList<QPointF>, points); | |
175 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
176 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
176 | QTest::qWait(200); |
|
|||
177 | m_series->append(points); |
|
177 | m_series->append(points); | |
178 | QTest::qWait(200); |
|
178 | TRY_COMPARE(spy0.count(), 0); | |
179 | QCOMPARE(spy0.count(), 0); |
|
|||
180 | QCOMPARE(m_series->points(), points); |
|
179 | QCOMPARE(m_series->points(), points); | |
181 | } |
|
180 | } | |
182 |
|
181 | |||
183 | void tst_QLineSeries::chart_append_data() |
|
182 | void tst_QLineSeries::chart_append_data() | |
184 | { |
|
183 | { | |
185 | append_data(); |
|
184 | append_data(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | void tst_QLineSeries::chart_append() |
|
187 | void tst_QLineSeries::chart_append() | |
189 | { |
|
188 | { | |
190 | append_raw(); |
|
189 | append_raw(); | |
191 | m_chart->addSeries(m_series); |
|
190 | m_chart->addSeries(m_series); | |
192 | m_view->show(); |
|
191 | m_view->show(); | |
193 | QTest::qWaitForWindowShown(m_view); |
|
192 | QTest::qWaitForWindowShown(m_view); | |
194 | } |
|
193 | } | |
195 |
|
194 | |||
196 | void tst_QLineSeries::append_chart_data() |
|
195 | void tst_QLineSeries::append_chart_data() | |
197 | { |
|
196 | { | |
198 | append_data(); |
|
197 | append_data(); | |
199 | } |
|
198 | } | |
200 |
|
199 | |||
201 | void tst_QLineSeries::append_chart() |
|
200 | void tst_QLineSeries::append_chart() | |
202 | { |
|
201 | { | |
203 | m_view->show(); |
|
202 | m_view->show(); | |
204 | m_chart->addSeries(m_series); |
|
203 | m_chart->addSeries(m_series); | |
205 | QTest::qWaitForWindowShown(m_view); |
|
204 | QTest::qWaitForWindowShown(m_view); | |
206 | append_raw(); |
|
205 | append_raw(); | |
207 |
|
206 | |||
208 | } |
|
207 | } | |
209 |
|
208 | |||
210 | void tst_QLineSeries::append_chart_animation_data() |
|
209 | void tst_QLineSeries::append_chart_animation_data() | |
211 | { |
|
210 | { | |
212 | append_data(); |
|
211 | append_data(); | |
213 | } |
|
212 | } | |
214 |
|
213 | |||
215 | void tst_QLineSeries::append_chart_animation() |
|
214 | void tst_QLineSeries::append_chart_animation() | |
216 | { |
|
215 | { | |
217 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
216 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
218 | append_chart(); |
|
217 | append_chart(); | |
219 | } |
|
218 | } | |
220 |
|
219 | |||
221 | void tst_QLineSeries::count_data() |
|
220 | void tst_QLineSeries::count_data() | |
222 | { |
|
221 | { | |
223 | QTest::addColumn<int>("count"); |
|
222 | QTest::addColumn<int>("count"); | |
224 | QTest::newRow("0") << 0; |
|
223 | QTest::newRow("0") << 0; | |
225 | QTest::newRow("5") << 5; |
|
224 | QTest::newRow("5") << 5; | |
226 | QTest::newRow("10") << 5; |
|
225 | QTest::newRow("10") << 5; | |
227 | } |
|
226 | } | |
228 |
|
227 | |||
229 | void tst_QLineSeries::count_raw_data() |
|
228 | void tst_QLineSeries::count_raw_data() | |
230 | { |
|
229 | { | |
231 | count_data(); |
|
230 | count_data(); | |
232 | } |
|
231 | } | |
233 |
|
232 | |||
234 | void tst_QLineSeries::count_raw() |
|
233 | void tst_QLineSeries::count_raw() | |
235 | { |
|
234 | { | |
236 | QFETCH(int, count); |
|
235 | QFETCH(int, count); | |
237 |
|
236 | |||
238 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
237 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
239 |
|
238 | |||
240 | for(int i=0 ; i< count; ++i) |
|
239 | for(int i=0 ; i< count; ++i) | |
241 | m_series->append(i,i); |
|
240 | m_series->append(i,i); | |
242 |
|
241 | |||
243 |
|
|
242 | TRY_COMPARE(spy0.count(), 0); | |
244 | QCOMPARE(m_series->count(), count); |
|
243 | QCOMPARE(m_series->count(), count); | |
245 | } |
|
244 | } | |
246 |
|
245 | |||
247 | void tst_QLineSeries::oper_data() |
|
246 | void tst_QLineSeries::oper_data() | |
248 | { |
|
247 | { | |
249 | append_data(); |
|
248 | append_data(); | |
250 | } |
|
249 | } | |
251 |
|
250 | |||
252 | void tst_QLineSeries::oper() |
|
251 | void tst_QLineSeries::oper() | |
253 | { |
|
252 | { | |
254 | QFETCH(QList<QPointF>, points); |
|
253 | QFETCH(QList<QPointF>, points); | |
255 | QLineSeries series; |
|
254 | QLineSeries series; | |
256 |
|
255 | |||
257 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); |
|
256 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | |
258 |
|
257 | |||
259 | foreach(const QPointF& point,points) |
|
258 | foreach(const QPointF& point,points) | |
260 | { |
|
259 | { | |
261 | series<<point; |
|
260 | series<<point; | |
262 | } |
|
261 | } | |
263 |
|
262 | |||
264 | QCOMPARE(series.points(), points); |
|
263 | QCOMPARE(series.points(), points); | |
265 |
|
|
264 | TRY_COMPARE(spy0.count(), 0); | |
266 | } |
|
265 | } | |
267 |
|
266 | |||
268 |
|
267 | |||
269 | void tst_QLineSeries::pen_data() |
|
268 | void tst_QLineSeries::pen_data() | |
270 | { |
|
269 | { | |
271 | QTest::addColumn<QPen>("pen"); |
|
270 | QTest::addColumn<QPen>("pen"); | |
272 | QTest::newRow("null") << QPen(); |
|
271 | QTest::newRow("null") << QPen(); | |
273 | QTest::newRow("blue") << QPen(Qt::blue); |
|
272 | QTest::newRow("blue") << QPen(Qt::blue); | |
274 | QTest::newRow("black") << QPen(Qt::black); |
|
273 | QTest::newRow("black") << QPen(Qt::black); | |
275 | QTest::newRow("red") << QPen(Qt::red); |
|
274 | QTest::newRow("red") << QPen(Qt::red); | |
276 | } |
|
275 | } | |
277 |
|
276 | |||
278 | void tst_QLineSeries::pen() |
|
277 | void tst_QLineSeries::pen() | |
279 | { |
|
278 | { | |
280 | QFETCH(QPen, pen); |
|
279 | QFETCH(QPen, pen); | |
281 | QLineSeries series; |
|
280 | QLineSeries series; | |
282 |
|
281 | |||
283 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); |
|
282 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | |
284 | series.setPen(pen); |
|
283 | series.setPen(pen); | |
285 |
|
284 | |||
286 |
|
|
285 | TRY_COMPARE(spy0.count(), 0); | |
287 | QCOMPARE(series.pen(), pen); |
|
286 | QCOMPARE(series.pen(), pen); | |
288 |
|
287 | |||
289 | m_chart->addSeries(&series); |
|
288 | m_chart->addSeries(&series); | |
290 |
|
289 | |||
291 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); |
|
290 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); | |
292 |
|
291 | |||
293 | m_chart->setTheme(QChart::ChartThemeDark); |
|
292 | m_chart->setTheme(QChart::ChartThemeDark); | |
294 |
|
293 | |||
295 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); |
|
294 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); | |
296 | } |
|
295 | } | |
297 |
|
296 | |||
298 | void tst_QLineSeries::pointsVisible_data() |
|
297 | void tst_QLineSeries::pointsVisible_data() | |
299 | { |
|
298 | { | |
300 | QTest::addColumn<bool>("pointsVisible"); |
|
299 | QTest::addColumn<bool>("pointsVisible"); | |
301 | QTest::newRow("true") << true; |
|
300 | QTest::newRow("true") << true; | |
302 | QTest::newRow("false") << false; |
|
301 | QTest::newRow("false") << false; | |
303 | } |
|
302 | } | |
304 |
|
303 | |||
305 | void tst_QLineSeries::pointsVisible_raw_data() |
|
304 | void tst_QLineSeries::pointsVisible_raw_data() | |
306 | { |
|
305 | { | |
307 | pointsVisible_data(); |
|
306 | pointsVisible_data(); | |
308 | } |
|
307 | } | |
309 |
|
308 | |||
310 | void tst_QLineSeries::pointsVisible_raw() |
|
309 | void tst_QLineSeries::pointsVisible_raw() | |
311 | { |
|
310 | { | |
312 | QFETCH(bool, pointsVisible); |
|
311 | QFETCH(bool, pointsVisible); | |
313 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
312 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
314 | m_series->setPointsVisible(pointsVisible); |
|
313 | m_series->setPointsVisible(pointsVisible); | |
315 |
|
|
314 | TRY_COMPARE(spy0.count(), 0); | |
316 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
315 | QCOMPARE(m_series->pointsVisible(), pointsVisible); | |
317 | } |
|
316 | } | |
318 |
|
317 | |||
319 | void tst_QLineSeries::remove_raw_data() |
|
318 | void tst_QLineSeries::remove_raw_data() | |
320 | { |
|
319 | { | |
321 | append_data(); |
|
320 | append_data(); | |
322 | } |
|
321 | } | |
323 |
|
322 | |||
324 | void tst_QLineSeries::remove_raw() |
|
323 | void tst_QLineSeries::remove_raw() | |
325 | { |
|
324 | { | |
326 | QFETCH(QList<QPointF>, points); |
|
325 | QFETCH(QList<QPointF>, points); | |
327 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
326 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
328 | m_series->append(points); |
|
327 | m_series->append(points); | |
329 | QTest::qWait(200); |
|
328 | TRY_COMPARE(spy0.count(), 0); | |
330 | QCOMPARE(spy0.count(), 0); |
|
|||
331 | QCOMPARE(m_series->points(), points); |
|
329 | QCOMPARE(m_series->points(), points); | |
332 |
|
330 | |||
333 | foreach(const QPointF& point,points) |
|
331 | foreach(const QPointF& point,points) | |
334 | { |
|
|||
335 | m_series->remove(point); |
|
332 | m_series->remove(point); | |
336 | QTest::qWait(200); |
|
|||
337 | } |
|
|||
338 |
|
333 | |||
339 |
|
|
334 | TRY_COMPARE(spy0.count(), 0); | |
340 | QCOMPARE(m_series->points().count(), 0); |
|
335 | QCOMPARE(m_series->points().count(), 0); | |
341 | } |
|
336 | } | |
342 |
|
337 | |||
343 | void tst_QLineSeries::remove_chart_data() |
|
338 | void tst_QLineSeries::remove_chart_data() | |
344 | { |
|
339 | { | |
345 | append_data(); |
|
340 | append_data(); | |
346 | } |
|
341 | } | |
347 |
|
342 | |||
348 | void tst_QLineSeries::remove_chart() |
|
343 | void tst_QLineSeries::remove_chart() | |
349 | { |
|
344 | { | |
350 | m_view->show(); |
|
345 | m_view->show(); | |
351 | m_chart->addSeries(m_series); |
|
346 | m_chart->addSeries(m_series); | |
352 | QTest::qWaitForWindowShown(m_view); |
|
347 | QTest::qWaitForWindowShown(m_view); | |
353 | remove_raw(); |
|
348 | remove_raw(); | |
354 | } |
|
349 | } | |
355 |
|
350 | |||
356 | void tst_QLineSeries::remove_chart_animation_data() |
|
351 | void tst_QLineSeries::remove_chart_animation_data() | |
357 | { |
|
352 | { | |
358 | append_data(); |
|
353 | append_data(); | |
359 | } |
|
354 | } | |
360 |
|
355 | |||
361 | void tst_QLineSeries::remove_chart_animation() |
|
356 | void tst_QLineSeries::remove_chart_animation() | |
362 | { |
|
357 | { | |
363 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
358 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
364 | remove_chart(); |
|
359 | remove_chart(); | |
365 | } |
|
360 | } | |
366 |
|
361 | |||
367 |
|
362 | |||
368 | void tst_QLineSeries::removeAll_raw_data() |
|
363 | void tst_QLineSeries::removeAll_raw_data() | |
369 | { |
|
364 | { | |
370 | append_data(); |
|
365 | append_data(); | |
371 | } |
|
366 | } | |
372 |
|
367 | |||
373 | void tst_QLineSeries::removeAll_raw() |
|
368 | void tst_QLineSeries::removeAll_raw() | |
374 | { |
|
369 | { | |
375 | QFETCH(QList<QPointF>, points); |
|
370 | QFETCH(QList<QPointF>, points); | |
376 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
371 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
377 | m_series->append(points); |
|
372 | m_series->append(points); | |
378 |
|
|
373 | TRY_COMPARE(spy0.count(), 0); | |
379 | QCOMPARE(m_series->points(), points); |
|
374 | QCOMPARE(m_series->points(), points); | |
380 | QTest::qWait(200); |
|
|||
381 | m_series->removeAll(); |
|
375 | m_series->removeAll(); | |
382 | QTest::qWait(200); |
|
376 | TRY_COMPARE(spy0.count(), 0); | |
383 | QCOMPARE(spy0.count(), 0); |
|
|||
384 | QCOMPARE(m_series->points().count(), 0); |
|
377 | QCOMPARE(m_series->points().count(), 0); | |
385 | } |
|
378 | } | |
386 |
|
379 | |||
387 | void tst_QLineSeries::removeAll_chart_data() |
|
380 | void tst_QLineSeries::removeAll_chart_data() | |
388 | { |
|
381 | { | |
389 | append_data(); |
|
382 | append_data(); | |
390 | } |
|
383 | } | |
391 |
|
384 | |||
392 | void tst_QLineSeries::removeAll_chart() |
|
385 | void tst_QLineSeries::removeAll_chart() | |
393 | { |
|
386 | { | |
394 | m_view->show(); |
|
387 | m_view->show(); | |
395 | m_chart->addSeries(m_series); |
|
388 | m_chart->addSeries(m_series); | |
396 | QTest::qWaitForWindowShown(m_view); |
|
389 | QTest::qWaitForWindowShown(m_view); | |
397 | removeAll_raw(); |
|
390 | removeAll_raw(); | |
398 | } |
|
391 | } | |
399 |
|
392 | |||
400 | void tst_QLineSeries::removeAll_chart_animation_data() |
|
393 | void tst_QLineSeries::removeAll_chart_animation_data() | |
401 | { |
|
394 | { | |
402 | append_data(); |
|
395 | append_data(); | |
403 | } |
|
396 | } | |
404 |
|
397 | |||
405 | void tst_QLineSeries::removeAll_chart_animation() |
|
398 | void tst_QLineSeries::removeAll_chart_animation() | |
406 | { |
|
399 | { | |
407 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
400 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
408 | removeAll_chart(); |
|
401 | removeAll_chart(); | |
409 | } |
|
402 | } | |
410 |
|
403 | |||
411 | void tst_QLineSeries::replace_raw_data() |
|
404 | void tst_QLineSeries::replace_raw_data() | |
412 | { |
|
405 | { | |
413 | append_data(); |
|
406 | append_data(); | |
414 | } |
|
407 | } | |
415 |
|
408 | |||
416 | void tst_QLineSeries::replace_raw() |
|
409 | void tst_QLineSeries::replace_raw() | |
417 | { |
|
410 | { | |
418 | QFETCH(QList<QPointF>, points); |
|
411 | QFETCH(QList<QPointF>, points); | |
419 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
412 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
420 | m_series->append(points); |
|
413 | m_series->append(points); | |
421 |
|
|
414 | TRY_COMPARE(spy0.count(), 0); | |
422 | QCOMPARE(m_series->points(), points); |
|
415 | QCOMPARE(m_series->points(), points); | |
423 | QTest::qWait(200); |
|
|||
424 |
|
416 | |||
425 | foreach(const QPointF& point,points) |
|
417 | foreach(const QPointF& point,points) | |
426 | { |
|
418 | m_series->replace(point.x(),point.y(),point.x(),0); | |
427 | m_series->replace(point.x(),point.y(),point.x(),0); |
|
|||
428 | QTest::qWait(200); |
|
|||
429 | } |
|
|||
430 |
|
419 | |||
431 | QList<QPointF> newPoints = m_series->points(); |
|
420 | QList<QPointF> newPoints = m_series->points(); | |
432 |
|
421 | |||
433 | QCOMPARE(newPoints.count(), points.count()); |
|
422 | QCOMPARE(newPoints.count(), points.count()); | |
434 |
|
423 | |||
435 | for(int i =0 ; i<points.count() ; ++i) { |
|
424 | for(int i =0 ; i<points.count() ; ++i) { | |
436 | QCOMPARE(points[i].x(), newPoints[i].x()); |
|
425 | QCOMPARE(points[i].x(), newPoints[i].x()); | |
437 | QCOMPARE(newPoints[i].y(), 0.0); |
|
426 | QCOMPARE(newPoints[i].y(), 0.0); | |
438 | } |
|
427 | } | |
439 | } |
|
428 | } | |
440 |
|
429 | |||
441 |
|
430 | |||
442 | void tst_QLineSeries::replace_chart_data() |
|
431 | void tst_QLineSeries::replace_chart_data() | |
443 | { |
|
432 | { | |
444 | append_data(); |
|
433 | append_data(); | |
445 | } |
|
434 | } | |
446 |
|
435 | |||
447 | void tst_QLineSeries::replace_chart() |
|
436 | void tst_QLineSeries::replace_chart() | |
448 | { |
|
437 | { | |
449 | m_view->show(); |
|
438 | m_view->show(); | |
450 | m_chart->addSeries(m_series); |
|
439 | m_chart->addSeries(m_series); | |
451 | QTest::qWaitForWindowShown(m_view); |
|
440 | QTest::qWaitForWindowShown(m_view); | |
452 | replace_raw(); |
|
441 | replace_raw(); | |
453 | } |
|
442 | } | |
454 |
|
443 | |||
455 | void tst_QLineSeries::replace_chart_animation_data() |
|
444 | void tst_QLineSeries::replace_chart_animation_data() | |
456 | { |
|
445 | { | |
457 | append_data(); |
|
446 | append_data(); | |
458 | } |
|
447 | } | |
459 |
|
448 | |||
460 | void tst_QLineSeries::replace_chart_animation() |
|
449 | void tst_QLineSeries::replace_chart_animation() | |
461 | { |
|
450 | { | |
462 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
451 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
463 | replace_chart(); |
|
452 | replace_chart(); | |
464 | } |
|
453 | } | |
465 |
|
454 | |||
466 | void tst_QLineSeries::setModel_data() |
|
455 | void tst_QLineSeries::setModel_data() | |
467 | { |
|
456 | { | |
468 |
|
457 | |||
469 | } |
|
458 | } | |
470 |
|
459 | |||
471 | void tst_QLineSeries::setModel() |
|
460 | void tst_QLineSeries::setModel() | |
472 | { |
|
461 | { | |
473 | QLineSeries series; |
|
462 | QLineSeries series; | |
474 | series.setModel(0); |
|
463 | series.setModel(0); | |
475 | QVERIFY2(series.model() == 0, "Model should be unset"); |
|
464 | QVERIFY2(series.model() == 0, "Model should be unset"); | |
476 |
|
465 | |||
477 | QStandardItemModel *stdModel = new QStandardItemModel(); |
|
466 | QStandardItemModel *stdModel = new QStandardItemModel(); | |
478 | series.setModel(stdModel); |
|
467 | series.setModel(stdModel); | |
479 | QVERIFY2((series.model()) == stdModel, "Model should be stdModel"); |
|
468 | QVERIFY2((series.model()) == stdModel, "Model should be stdModel"); | |
480 |
|
469 | |||
481 | // unset the model |
|
470 | // unset the model | |
482 | series.setModel(0); |
|
471 | series.setModel(0); | |
483 | QVERIFY2(series.model() == 0, "Model should be unset"); |
|
472 | QVERIFY2(series.model() == 0, "Model should be unset"); | |
484 |
|
473 | |||
485 | } |
|
474 | } | |
486 |
|
475 | |||
487 | Q_DECLARE_METATYPE(Qt::Orientation) |
|
476 | Q_DECLARE_METATYPE(Qt::Orientation) | |
488 | void tst_QLineSeries::setModelMapping_data() |
|
477 | void tst_QLineSeries::setModelMapping_data() | |
489 | { |
|
478 | { | |
490 | QTest::addColumn<int>("modelX"); |
|
479 | QTest::addColumn<int>("modelX"); | |
491 | QTest::addColumn<int>("modelY"); |
|
480 | QTest::addColumn<int>("modelY"); | |
492 | QTest::addColumn<Qt::Orientation>("orientation"); |
|
481 | QTest::addColumn<Qt::Orientation>("orientation"); | |
493 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; |
|
482 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; | |
494 | QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; |
|
483 | QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; | |
495 | QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; |
|
484 | QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; | |
496 |
|
485 | |||
497 | QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; |
|
486 | QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; | |
498 | QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; |
|
487 | QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; | |
499 | QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; |
|
488 | QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; | |
500 | } |
|
489 | } | |
501 |
|
490 | |||
502 | void tst_QLineSeries::setModelMapping() |
|
491 | void tst_QLineSeries::setModelMapping() | |
503 | { |
|
492 | { | |
504 | QFETCH(int, modelX); |
|
493 | QFETCH(int, modelX); | |
505 | QFETCH(int, modelY); |
|
494 | QFETCH(int, modelY); | |
506 | QFETCH(Qt::Orientation, orientation); |
|
495 | QFETCH(Qt::Orientation, orientation); | |
507 |
|
496 | |||
508 | QLineSeries series; |
|
497 | QLineSeries series; | |
509 |
|
498 | |||
510 | // model has not been set so setting mapping should do nothing |
|
499 | // model has not been set so setting mapping should do nothing | |
511 | series.setModelMapping(modelX, modelY, orientation); |
|
500 | series.setModelMapping(modelX, modelY, orientation); | |
512 | QCOMPARE(series.mapX(), -1); |
|
501 | QCOMPARE(series.mapX(), -1); | |
513 | QCOMPARE(series.mapY(), -1); |
|
502 | QCOMPARE(series.mapY(), -1); | |
514 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); |
|
503 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | |
515 |
|
504 | |||
516 | // now let us set the model |
|
505 | // now let us set the model | |
517 | series.setModel(new QStandardItemModel()); |
|
506 | series.setModel(new QStandardItemModel()); | |
518 | series.setModelMapping(modelX, modelY, orientation); |
|
507 | series.setModelMapping(modelX, modelY, orientation); | |
519 | QCOMPARE(series.mapX(), modelX); |
|
508 | QCOMPARE(series.mapX(), modelX); | |
520 | QCOMPARE(series.mapY(), modelY); |
|
509 | QCOMPARE(series.mapY(), modelY); | |
521 | QVERIFY2(series.mapOrientation() == orientation, "not good"); |
|
510 | QVERIFY2(series.mapOrientation() == orientation, "not good"); | |
522 |
|
511 | |||
523 | // now let us remove the model, the values should go back to default ones. |
|
512 | // now let us remove the model, the values should go back to default ones. | |
524 | series.setModel(0); |
|
513 | series.setModel(0); | |
525 | QCOMPARE(series.mapX(), -1); |
|
514 | QCOMPARE(series.mapX(), -1); | |
526 | QCOMPARE(series.mapY(), -1); |
|
515 | QCOMPARE(series.mapY(), -1); | |
527 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); |
|
516 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | |
528 | } |
|
517 | } | |
529 |
|
518 | |||
530 | void tst_QLineSeries::setModelMappingRange_data() |
|
519 | void tst_QLineSeries::setModelMappingRange_data() | |
531 | { |
|
520 | { | |
532 | QTest::addColumn<int>("first"); |
|
521 | QTest::addColumn<int>("first"); | |
533 | QTest::addColumn<int>("count"); |
|
522 | QTest::addColumn<int>("count"); | |
534 | QTest::newRow("first: 0, count: unlimited") << 0 << -1; |
|
523 | QTest::newRow("first: 0, count: unlimited") << 0 << -1; | |
535 | QTest::newRow("first: 0, count: 5") << 0 << 5; |
|
524 | QTest::newRow("first: 0, count: 5") << 0 << 5; | |
536 | QTest::newRow("first: 3, count: unlimited") << 3 << -1; |
|
525 | QTest::newRow("first: 3, count: unlimited") << 3 << -1; | |
537 | QTest::newRow("first: 3, count: 5") << 3 << 5; |
|
526 | QTest::newRow("first: 3, count: 5") << 3 << 5; | |
538 | QTest::newRow("first: -3, count: 5") << -3 << 5; |
|
527 | QTest::newRow("first: -3, count: 5") << -3 << 5; | |
539 | QTest::newRow("first: 3, count: -5") << 3 << -5; |
|
528 | QTest::newRow("first: 3, count: -5") << 3 << -5; | |
540 | QTest::newRow("first: -3, count: -5") << 3 << -5; |
|
529 | QTest::newRow("first: -3, count: -5") << 3 << -5; | |
541 | QTest::newRow("first: -3, count: 0") << -3 << 0; |
|
530 | QTest::newRow("first: -3, count: 0") << -3 << 0; | |
542 | QTest::newRow("first: 0, count: -5") << 0 << -5; |
|
531 | QTest::newRow("first: 0, count: -5") << 0 << -5; | |
543 | QTest::newRow("first: 0, count: 0") << 0 << 0; |
|
532 | QTest::newRow("first: 0, count: 0") << 0 << 0; | |
544 | } |
|
533 | } | |
545 |
|
534 | |||
546 | void tst_QLineSeries::setModelMappingRange() |
|
535 | void tst_QLineSeries::setModelMappingRange() | |
547 | { |
|
536 | { | |
548 | QFETCH(int, first); |
|
537 | QFETCH(int, first); | |
549 | QFETCH(int, count); |
|
538 | QFETCH(int, count); | |
550 | QLineSeries series; |
|
539 | QLineSeries series; | |
551 |
|
540 | |||
552 | QStandardItemModel *model = new QStandardItemModel(0, 2); |
|
541 | QStandardItemModel *model = new QStandardItemModel(0, 2); | |
553 | series.setModel(model); |
|
542 | series.setModel(model); | |
554 | series.setModelMapping(0, 1); |
|
543 | series.setModelMapping(0, 1); | |
555 | series.setModelMappingRange(first, count); |
|
544 | series.setModelMappingRange(first, count); | |
556 |
|
545 | |||
557 | QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0 |
|
546 | QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0 | |
558 | QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0 |
|
547 | QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0 | |
559 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); |
|
548 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | |
560 |
|
549 | |||
561 | for (int row = 0; row < 3; ++row) { |
|
550 | for (int row = 0; row < 3; ++row) { | |
562 | for (int column = 0; column < 2; column++) { |
|
551 | for (int column = 0; column < 2; column++) { | |
563 | QStandardItem *item = new QStandardItem(row * column); |
|
552 | QStandardItem *item = new QStandardItem(row * column); | |
564 | model->setItem(row, column, item); |
|
553 | model->setItem(row, column, item); | |
565 | } |
|
554 | } | |
566 | } |
|
555 | } | |
567 | if (qMax(count, -1) != -1) |
|
556 | if (qMax(count, -1) != -1) | |
568 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0"); |
|
557 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0"); | |
569 | else |
|
558 | else | |
570 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); |
|
559 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | |
571 |
|
560 | |||
572 | // let's add few more rows to the model |
|
561 | // let's add few more rows to the model | |
573 | for (int row = 0; row < 10; ++row) { |
|
562 | for (int row = 0; row < 10; ++row) { | |
574 | QList<QStandardItem *> newRow; |
|
563 | QList<QStandardItem *> newRow; | |
575 | for (int column = 0; column < 2; column++) { |
|
564 | for (int column = 0; column < 2; column++) { | |
576 | newRow.append(new QStandardItem(row * column)); |
|
565 | newRow.append(new QStandardItem(row * column)); | |
577 | } |
|
566 | } | |
578 | model->appendRow(newRow); |
|
567 | model->appendRow(newRow); | |
579 | } |
|
568 | } | |
580 | if (qMax(count, -1) != -1) |
|
569 | if (qMax(count, -1) != -1) | |
581 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0"); |
|
570 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0"); | |
582 | else |
|
571 | else | |
583 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); |
|
572 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | |
584 |
|
573 | |||
585 | // unset the model, values should be default |
|
574 | // unset the model, values should be default | |
586 | series.setModel(0); |
|
575 | series.setModel(0); | |
587 | QCOMPARE(series.mapFirst(), 0); |
|
576 | QCOMPARE(series.mapFirst(), 0); | |
588 | QCOMPARE(series.mapCount(), -1); |
|
577 | QCOMPARE(series.mapCount(), -1); | |
589 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); |
|
578 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | |
590 | } |
|
579 | } | |
591 |
|
580 | |||
592 | void tst_QLineSeries::modelUpdated() |
|
581 | void tst_QLineSeries::modelUpdated() | |
593 | { |
|
582 | { | |
594 | QStandardItemModel *model = new QStandardItemModel; |
|
583 | QStandardItemModel *model = new QStandardItemModel; | |
595 | for (int row = 0; row < 10; ++row) { |
|
584 | for (int row = 0; row < 10; ++row) { | |
596 | QList<QStandardItem *> newRow; |
|
585 | QList<QStandardItem *> newRow; | |
597 | for (int column = 0; column < 2; column++) { |
|
586 | for (int column = 0; column < 2; column++) { | |
598 | newRow.append(new QStandardItem(row * column)); |
|
587 | newRow.append(new QStandardItem(row * column)); | |
599 | } |
|
588 | } | |
600 | model->appendRow(newRow); |
|
589 | model->appendRow(newRow); | |
601 | } |
|
590 | } | |
602 |
|
591 | |||
603 | QLineSeries series; |
|
592 | QLineSeries series; | |
604 | series.setModel(model); |
|
593 | series.setModel(model); | |
605 | series.setModelMapping(0, 1); |
|
594 | series.setModelMapping(0, 1); | |
606 |
|
595 | |||
607 | model->setData(model->index(3, 1), 34); |
|
596 | model->setData(model->index(3, 1), 34); | |
608 | // check that the update data is correctly taken from the model |
|
597 | // check that the update data is correctly taken from the model | |
609 | QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34)); |
|
598 | QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34)); | |
610 | } |
|
599 | } | |
611 |
|
600 | |||
612 | void tst_QLineSeries::modelUpdatedCustomMapping() |
|
601 | void tst_QLineSeries::modelUpdatedCustomMapping() | |
613 | { |
|
602 | { | |
614 |
|
603 | |||
615 | QStandardItemModel *model = new QStandardItemModel; |
|
604 | QStandardItemModel *model = new QStandardItemModel; | |
616 | for (int row = 0; row < 10; ++row) { |
|
605 | for (int row = 0; row < 10; ++row) { | |
617 | QList<QStandardItem *> newRow; |
|
606 | QList<QStandardItem *> newRow; | |
618 | for (int column = 0; column < 2; column++) { |
|
607 | for (int column = 0; column < 2; column++) { | |
619 | newRow.append(new QStandardItem(row * column)); |
|
608 | newRow.append(new QStandardItem(row * column)); | |
620 | } |
|
609 | } | |
621 | model->appendRow(newRow); |
|
610 | model->appendRow(newRow); | |
622 | } |
|
611 | } | |
623 |
|
612 | |||
624 | QLineSeries series; |
|
613 | QLineSeries series; | |
625 | series.setModel(model); |
|
614 | series.setModel(model); | |
626 | series.setModelMapping(0, 1); |
|
615 | series.setModelMapping(0, 1); | |
627 | series.setModelMappingRange(3, 4); |
|
616 | series.setModelMappingRange(3, 4); | |
628 |
|
617 | |||
629 | model->setData(model->index(3, 1), 34); |
|
618 | model->setData(model->index(3, 1), 34); | |
630 | QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34)); |
|
619 | QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34)); | |
631 | } |
|
620 | } | |
632 |
|
621 | |||
633 | QTEST_MAIN(tst_QLineSeries) |
|
622 | QTEST_MAIN(tst_QLineSeries) | |
634 |
|
623 | |||
635 | #include "tst_qlineseries.moc" |
|
624 | #include "tst_qlineseries.moc" | |
636 |
|
625 |
@@ -1,220 +1,328 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
|
22 | #include <qchartview.h> | |||
|
23 | #include <qchart.h> | |||
22 | #include <qpieseries.h> |
|
24 | #include <qpieseries.h> | |
23 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
|
26 | #include <tst_definitions.h> | |||
24 |
|
27 | |||
25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
26 |
|
29 | |||
|
30 | Q_DECLARE_METATYPE(QPieSlice*) | |||
|
31 | ||||
27 | class tst_qpieseries : public QObject |
|
32 | class tst_qpieseries : public QObject | |
28 | { |
|
33 | { | |
29 | Q_OBJECT |
|
34 | Q_OBJECT | |
30 |
|
35 | |||
31 | public slots: |
|
36 | public slots: | |
32 | void initTestCase(); |
|
37 | void initTestCase(); | |
33 | void cleanupTestCase(); |
|
38 | void cleanupTestCase(); | |
34 | void init(); |
|
39 | void init(); | |
35 | void cleanup(); |
|
40 | void cleanup(); | |
36 |
|
41 | |||
37 | private slots: |
|
42 | private slots: | |
38 | void construction(); |
|
43 | void construction(); | |
39 | void append(); |
|
44 | void append(); | |
40 | void insert(); |
|
45 | void insert(); | |
41 | void remove(); |
|
46 | void remove(); | |
42 |
|
|
47 | void calculatedValues(); | |
43 | //void themes(); |
|
48 | void clickedSignal(); | |
44 |
|
|
49 | void hoverSignal(); | |
45 | //void hoverSignal(); |
|
|||
46 |
|
50 | |||
47 | private: |
|
51 | private: | |
48 |
|
52 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | ||
49 |
|
53 | |||
50 | private: |
|
54 | private: | |
51 |
|
55 | |||
52 | }; |
|
56 | }; | |
53 |
|
57 | |||
54 | void tst_qpieseries::initTestCase() |
|
58 | void tst_qpieseries::initTestCase() | |
55 | { |
|
59 | { | |
|
60 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |||
56 | } |
|
61 | } | |
57 |
|
62 | |||
58 | void tst_qpieseries::cleanupTestCase() |
|
63 | void tst_qpieseries::cleanupTestCase() | |
59 | { |
|
64 | { | |
60 | } |
|
65 | } | |
61 |
|
66 | |||
62 | void tst_qpieseries::init() |
|
67 | void tst_qpieseries::init() | |
63 | { |
|
68 | { | |
64 |
|
69 | |||
65 | } |
|
70 | } | |
66 |
|
71 | |||
67 | void tst_qpieseries::cleanup() |
|
72 | void tst_qpieseries::cleanup() | |
68 | { |
|
73 | { | |
69 |
|
74 | |||
70 | } |
|
75 | } | |
71 |
|
76 | |||
72 | void tst_qpieseries::construction() |
|
77 | void tst_qpieseries::construction() | |
73 | { |
|
78 | { | |
74 | // verify default values |
|
79 | // verify default values | |
75 | QPieSeries s; |
|
80 | QPieSeries s; | |
76 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); |
|
81 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); | |
77 | QVERIFY(s.count() == 0); |
|
82 | QVERIFY(s.count() == 0); | |
78 | QVERIFY(s.isEmpty()); |
|
83 | QVERIFY(s.isEmpty()); | |
79 | QVERIFY(qFuzzyIsNull(s.sum())); |
|
84 | QCOMPARE(s.sum(), 0.0); | |
80 |
Q |
|
85 | QCOMPARE(s.horizontalPosition(), 0.5); | |
81 |
Q |
|
86 | QCOMPARE(s.verticalPosition(), 0.5); | |
82 |
Q |
|
87 | QCOMPARE(s.pieSize(), 0.7); | |
83 |
Q |
|
88 | QCOMPARE(s.pieStartAngle(), 0.0); | |
84 |
Q |
|
89 | QCOMPARE(s.pieEndAngle(), 360.0); | |
85 | } |
|
90 | } | |
86 |
|
91 | |||
87 | void tst_qpieseries::append() |
|
92 | void tst_qpieseries::append() | |
88 | { |
|
93 | { | |
89 | QPieSeries s; |
|
94 | QPieSeries s; | |
90 |
|
95 | |||
91 | // append pointer |
|
96 | // append pointer | |
92 | QPieSlice *slice1 = 0; |
|
97 | QPieSlice *slice1 = 0; | |
93 | QVERIFY(!s.append(slice1)); |
|
98 | QVERIFY(!s.append(slice1)); | |
94 | slice1 = new QPieSlice(1, "slice 1"); |
|
99 | slice1 = new QPieSlice(1, "slice 1"); | |
95 | QVERIFY(s.append(slice1)); |
|
100 | QVERIFY(s.append(slice1)); | |
96 | QVERIFY(!s.append(slice1)); |
|
101 | QVERIFY(!s.append(slice1)); | |
97 | QCOMPARE(s.count(), 1); |
|
102 | QCOMPARE(s.count(), 1); | |
98 |
|
103 | |||
99 | // append pointer list |
|
104 | // append pointer list | |
100 | QList<QPieSlice *> list; |
|
105 | QList<QPieSlice *> list; | |
101 | QVERIFY(!s.append(list)); |
|
106 | QVERIFY(!s.append(list)); | |
102 | list << (QPieSlice *) 0; |
|
107 | list << (QPieSlice *) 0; | |
103 | QVERIFY(!s.append(list)); |
|
108 | QVERIFY(!s.append(list)); | |
104 | list.clear(); |
|
109 | list.clear(); | |
105 | list << new QPieSlice(2, "slice 2"); |
|
110 | list << new QPieSlice(2, "slice 2"); | |
106 | list << new QPieSlice(3, "slice 3"); |
|
111 | list << new QPieSlice(3, "slice 3"); | |
107 | QVERIFY(s.append(list)); |
|
112 | QVERIFY(s.append(list)); | |
108 | QVERIFY(!s.append(list)); |
|
113 | QVERIFY(!s.append(list)); | |
109 | QCOMPARE(s.count(), 3); |
|
114 | QCOMPARE(s.count(), 3); | |
110 |
|
115 | |||
111 | // append operator |
|
116 | // append operator | |
112 | s << new QPieSlice(4, "slice 4"); |
|
117 | s << new QPieSlice(4, "slice 4"); | |
113 | s << slice1; // fails because already added |
|
118 | s << slice1; // fails because already added | |
114 | QCOMPARE(s.count(), 4); |
|
119 | QCOMPARE(s.count(), 4); | |
115 |
|
120 | |||
116 | // append with params |
|
121 | // append with params | |
117 | QPieSlice *slice5 = s.append(5, "slice 5"); |
|
122 | QPieSlice *slice5 = s.append(5, "slice 5"); | |
118 | QVERIFY(slice5 != 0); |
|
123 | QVERIFY(slice5 != 0); | |
119 |
Q |
|
124 | QCOMPARE(slice5->value(), 5.0); | |
120 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
125 | QCOMPARE(slice5->label(), QString("slice 5")); | |
121 | QCOMPARE(s.count(), 5); |
|
126 | QCOMPARE(s.count(), 5); | |
122 |
|
127 | |||
123 | // check slices |
|
128 | // check slices | |
124 | QVERIFY(!s.isEmpty()); |
|
129 | QVERIFY(!s.isEmpty()); | |
125 | for (int i=0; i<s.count(); i++) { |
|
130 | for (int i=0; i<s.count(); i++) { | |
126 |
Q |
|
131 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
127 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
132 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
128 | } |
|
133 | } | |
129 | } |
|
134 | } | |
130 |
|
135 | |||
131 | void tst_qpieseries::insert() |
|
136 | void tst_qpieseries::insert() | |
132 | { |
|
137 | { | |
133 | QPieSeries s; |
|
138 | QPieSeries s; | |
134 |
|
139 | |||
135 | // insert one slice |
|
140 | // insert one slice | |
136 | QPieSlice *slice1 = 0; |
|
141 | QPieSlice *slice1 = 0; | |
137 | QVERIFY(!s.insert(0, slice1)); |
|
142 | QVERIFY(!s.insert(0, slice1)); | |
138 | slice1 = new QPieSlice(1, "slice 1"); |
|
143 | slice1 = new QPieSlice(1, "slice 1"); | |
139 | QVERIFY(!s.insert(-1, slice1)); |
|
144 | QVERIFY(!s.insert(-1, slice1)); | |
140 | QVERIFY(!s.insert(5, slice1)); |
|
145 | QVERIFY(!s.insert(5, slice1)); | |
141 | QVERIFY(s.insert(0, slice1)); |
|
146 | QVERIFY(s.insert(0, slice1)); | |
142 | QVERIFY(!s.insert(0, slice1)); |
|
147 | QVERIFY(!s.insert(0, slice1)); | |
143 | QCOMPARE(s.count(), 1); |
|
148 | QCOMPARE(s.count(), 1); | |
144 |
|
149 | |||
145 | // add some more slices |
|
150 | // add some more slices | |
146 | s.append(2, "slice 2"); |
|
151 | s.append(2, "slice 2"); | |
147 | s.append(4, "slice 4"); |
|
152 | s.append(4, "slice 4"); | |
148 | QCOMPARE(s.count(), 3); |
|
153 | QCOMPARE(s.count(), 3); | |
149 |
|
154 | |||
150 | // insert between slices |
|
155 | // insert between slices | |
151 | s.insert(2, new QPieSlice(3, "slice 3")); |
|
156 | s.insert(2, new QPieSlice(3, "slice 3")); | |
152 | QCOMPARE(s.count(), 4); |
|
157 | QCOMPARE(s.count(), 4); | |
153 |
|
158 | |||
154 | // check slices |
|
159 | // check slices | |
155 | for (int i=0; i<s.count(); i++) { |
|
160 | for (int i=0; i<s.count(); i++) { | |
156 |
Q |
|
161 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
157 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
162 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
158 | } |
|
163 | } | |
159 | } |
|
164 | } | |
160 |
|
165 | |||
161 | void tst_qpieseries::remove() |
|
166 | void tst_qpieseries::remove() | |
162 | { |
|
167 | { | |
163 | QPieSeries s; |
|
168 | QPieSeries s; | |
164 |
|
169 | |||
165 | // add some slices |
|
170 | // add some slices | |
166 | QPieSlice *slice1 = s.append(1, "slice 1"); |
|
171 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
167 | QPieSlice *slice2 = s.append(2, "slice 2"); |
|
172 | QPieSlice *slice2 = s.append(2, "slice 2"); | |
168 | QPieSlice *slice3 = s.append(3, "slice 3"); |
|
173 | QPieSlice *slice3 = s.append(3, "slice 3"); | |
169 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
174 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
170 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
175 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
171 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
176 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
172 | QCOMPARE(s.count(), 3); |
|
177 | QCOMPARE(s.count(), 3); | |
173 |
|
178 | |||
174 | // null pointer remove |
|
179 | // null pointer remove | |
175 | QVERIFY(!s.remove(0)); |
|
180 | QVERIFY(!s.remove(0)); | |
176 |
|
181 | |||
177 | // remove first |
|
182 | // remove first | |
178 | QVERIFY(s.remove(slice1)); |
|
183 | QVERIFY(s.remove(slice1)); | |
179 | QVERIFY(!s.remove(slice1)); |
|
184 | QVERIFY(!s.remove(slice1)); | |
180 | QCOMPARE(s.count(), 2); |
|
185 | QCOMPARE(s.count(), 2); | |
181 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); |
|
186 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); | |
182 |
|
187 | |||
183 | // remove all |
|
188 | // remove all | |
184 | s.clear(); |
|
189 | s.clear(); | |
185 | QVERIFY(s.isEmpty()); |
|
190 | QVERIFY(s.isEmpty()); | |
186 | QVERIFY(s.slices().isEmpty()); |
|
191 | QVERIFY(s.slices().isEmpty()); | |
187 | QCOMPARE(s.count(), 0); |
|
192 | QCOMPARE(s.count(), 0); | |
188 |
|
193 | |||
189 | // check that slices were actually destroyed |
|
194 | // check that slices were actually destroyed | |
190 |
|
|
195 | TRY_COMPARE(spy1.count(), 1); | |
191 |
|
|
196 | TRY_COMPARE(spy2.count(), 1); | |
192 |
|
|
197 | TRY_COMPARE(spy3.count(), 1); | |
193 | } |
|
198 | } | |
194 |
|
199 | |||
195 | /* |
|
|||
196 | void tst_qpieseries::calculatedValues() |
|
200 | void tst_qpieseries::calculatedValues() | |
197 | { |
|
201 | { | |
|
202 | bool ok; | |||
|
203 | QPieSeries s; | |||
|
204 | ||||
|
205 | // add a slice | |||
|
206 | QPieSlice *slice1 = s.append(1, "slice 1"); | |||
|
207 | verifyCalculatedData(s, &ok); | |||
|
208 | if (!ok) | |||
|
209 | return; | |||
198 |
|
210 | |||
|
211 | // add some more slices | |||
|
212 | QList<QPieSlice *> list; | |||
|
213 | list << new QPieSlice(2, "slice 2"); | |||
|
214 | list << new QPieSlice(3, "slice 3"); | |||
|
215 | s.append(list); | |||
|
216 | verifyCalculatedData(s, &ok); | |||
|
217 | if (!ok) | |||
|
218 | return; | |||
|
219 | ||||
|
220 | // remove a slice | |||
|
221 | s.remove(slice1); | |||
|
222 | verifyCalculatedData(s, &ok); | |||
|
223 | if (!ok) | |||
|
224 | return; | |||
|
225 | ||||
|
226 | // insert a slice | |||
|
227 | s.insert(0, new QPieSlice(1, "Slice 4")); | |||
|
228 | verifyCalculatedData(s, &ok); | |||
|
229 | if (!ok) | |||
|
230 | return; | |||
|
231 | ||||
|
232 | // clear all | |||
|
233 | s.clear(); | |||
|
234 | verifyCalculatedData(s, &ok); | |||
199 | } |
|
235 | } | |
200 |
|
236 | |||
201 | void tst_qpieseries::themes() |
|
237 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
202 | { |
|
238 | { | |
|
239 | *ok = false; | |||
|
240 | ||||
|
241 | qreal sum = 0; | |||
|
242 | foreach (const QPieSlice *slice, series.slices()) | |||
|
243 | sum += slice->value(); | |||
|
244 | QCOMPARE(series.sum(), sum); | |||
|
245 | ||||
|
246 | qreal startAngle = series.pieStartAngle(); | |||
|
247 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |||
|
248 | foreach (const QPieSlice *slice, series.slices()) { | |||
|
249 | qreal ratio = slice->value() / sum; | |||
|
250 | qreal sliceSpan = pieAngleSpan * ratio; | |||
|
251 | QCOMPARE(slice->startAngle(), startAngle); | |||
|
252 | QCOMPARE(slice->endAngle(), startAngle + sliceSpan); | |||
|
253 | QCOMPARE(slice->percentage(), ratio); | |||
|
254 | startAngle += sliceSpan; | |||
|
255 | } | |||
|
256 | ||||
|
257 | if (!series.isEmpty()) | |||
|
258 | QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); | |||
203 |
|
259 | |||
|
260 | *ok = true; | |||
204 | } |
|
261 | } | |
205 |
|
262 | |||
|
263 | ||||
206 | void tst_qpieseries::clickedSignal() |
|
264 | void tst_qpieseries::clickedSignal() | |
207 | { |
|
265 | { | |
208 |
|
266 | // create a pie series | ||
|
267 | QPieSeries *series = new QPieSeries(); | |||
|
268 | series->setPieSize(1.0); | |||
|
269 | QPieSlice *s1 = series->append(1, "slice 1"); | |||
|
270 | series->append(2, "slice 2"); | |||
|
271 | series->append(3, "slice 3"); | |||
|
272 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); | |||
|
273 | ||||
|
274 | // add series to the chart | |||
|
275 | QChartView view(new QChart()); | |||
|
276 | view.resize(200, 200); | |||
|
277 | view.chart()->addSeries(series); | |||
|
278 | view.show(); | |||
|
279 | QTest::qWaitForWindowShown(&view); | |||
|
280 | ||||
|
281 | // simulate clicks | |||
|
282 | // pie rectangle: QRectF(60,60 121x121) | |||
|
283 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |||
|
284 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
285 | QCOMPARE(clickSpy1.count(), 1); | |||
|
286 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy1.at(0).at(0)), s1); | |||
209 | } |
|
287 | } | |
210 |
|
288 | |||
211 | void tst_qpieseries::hoverSignal() |
|
289 | void tst_qpieseries::hoverSignal() | |
212 | { |
|
290 | { | |
213 |
|
291 | // create a pie series | ||
|
292 | QPieSeries *series = new QPieSeries(); | |||
|
293 | series->setPieSize(1.0); | |||
|
294 | QPieSlice *s1 = series->append(1, "slice 1"); | |||
|
295 | series->append(2, "slice 2"); | |||
|
296 | series->append(3, "slice 3"); | |||
|
297 | ||||
|
298 | // add series to the chart | |||
|
299 | QChartView view(new QChart()); | |||
|
300 | view.resize(200, 200); | |||
|
301 | view.chart()->addSeries(series); | |||
|
302 | view.show(); | |||
|
303 | QTest::qWaitForWindowShown(&view); | |||
|
304 | ||||
|
305 | // first move to right top corner | |||
|
306 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |||
|
307 | ||||
|
308 | // move inside the slice | |||
|
309 | // pie rectangle: QRectF(60,60 121x121) | |||
|
310 | QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); | |||
|
311 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |||
|
312 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
313 | QCOMPARE(hoverSpy.count(), 1); | |||
|
314 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |||
|
315 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |||
|
316 | ||||
|
317 | // move outside the slice | |||
|
318 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |||
|
319 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
320 | QCOMPARE(hoverSpy.count(), 2); | |||
|
321 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |||
|
322 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |||
214 | } |
|
323 | } | |
215 | */ |
|
|||
216 |
|
324 | |||
217 | QTEST_MAIN(tst_qpieseries) |
|
325 | QTEST_MAIN(tst_qpieseries) | |
218 |
|
326 | |||
219 | #include "tst_qpieseries.moc" |
|
327 | #include "tst_qpieseries.moc" | |
220 |
|
328 |
@@ -1,131 +1,270 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
|
22 | #include <tst_definitions.h> | |||
|
23 | #include <qchartview.h> | |||
|
24 | #include <qchart.h> | |||
22 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
|
26 | #include <qpieseries.h> | |||
23 |
|
27 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
29 | |||
26 | class tst_qpieslice : public QObject |
|
30 | class tst_qpieslice : public QObject | |
27 | { |
|
31 | { | |
28 | Q_OBJECT |
|
32 | Q_OBJECT | |
29 |
|
33 | |||
30 | public slots: |
|
34 | public slots: | |
31 | void initTestCase(); |
|
35 | void initTestCase(); | |
32 | void cleanupTestCase(); |
|
36 | void cleanupTestCase(); | |
33 | void init(); |
|
37 | void init(); | |
34 | void cleanup(); |
|
38 | void cleanup(); | |
35 |
|
39 | |||
36 | private slots: |
|
40 | private slots: | |
37 | void construction(); |
|
41 | void construction(); | |
38 | void changedSignals(); |
|
42 | void changedSignals(); | |
|
43 | void customize(); | |||
|
44 | void mouseClick(); | |||
|
45 | void mouseHover(); | |||
39 |
|
46 | |||
40 | private: |
|
47 | private: | |
41 |
|
48 | |||
42 |
|
49 | |||
43 | private: |
|
50 | private: | |
44 |
|
51 | |||
45 | }; |
|
52 | }; | |
46 |
|
53 | |||
47 | void tst_qpieslice::initTestCase() |
|
54 | void tst_qpieslice::initTestCase() | |
48 | { |
|
55 | { | |
49 | } |
|
56 | } | |
50 |
|
57 | |||
51 | void tst_qpieslice::cleanupTestCase() |
|
58 | void tst_qpieslice::cleanupTestCase() | |
52 | { |
|
59 | { | |
53 | } |
|
60 | } | |
54 |
|
61 | |||
55 | void tst_qpieslice::init() |
|
62 | void tst_qpieslice::init() | |
56 | { |
|
63 | { | |
57 |
|
64 | |||
58 | } |
|
65 | } | |
59 |
|
66 | |||
60 | void tst_qpieslice::cleanup() |
|
67 | void tst_qpieslice::cleanup() | |
61 | { |
|
68 | { | |
62 |
|
69 | |||
63 | } |
|
70 | } | |
64 |
|
71 | |||
65 | void tst_qpieslice::construction() |
|
72 | void tst_qpieslice::construction() | |
66 | { |
|
73 | { | |
67 | // no params |
|
74 | // no params | |
68 | QPieSlice slice1; |
|
75 | QPieSlice slice1; | |
69 |
Q |
|
76 | QCOMPARE(slice1.value(), 0.0); | |
70 | QVERIFY(slice1.label().isEmpty()); |
|
77 | QVERIFY(slice1.label().isEmpty()); | |
71 | QVERIFY(!slice1.isLabelVisible()); |
|
78 | QVERIFY(!slice1.isLabelVisible()); | |
72 | QVERIFY(!slice1.isExploded()); |
|
79 | QVERIFY(!slice1.isExploded()); | |
73 | QCOMPARE(slice1.pen(), QPen()); |
|
80 | QCOMPARE(slice1.pen(), QPen()); | |
74 | QCOMPARE(slice1.brush(), QBrush()); |
|
81 | QCOMPARE(slice1.brush(), QBrush()); | |
75 | QCOMPARE(slice1.labelPen(), QPen()); |
|
82 | QCOMPARE(slice1.labelPen(), QPen()); | |
76 | QCOMPARE(slice1.labelFont(), QFont()); |
|
83 | QCOMPARE(slice1.labelFont(), QFont()); | |
77 |
Q |
|
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value | |
78 |
Q |
|
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value | |
79 |
Q |
|
86 | QCOMPARE(slice1.percentage(), 0.0); | |
80 |
Q |
|
87 | QCOMPARE(slice1.startAngle(), 0.0); | |
81 |
Q |
|
88 | QCOMPARE(slice1.endAngle(), 0.0); | |
82 |
|
89 | |||
83 | // value and label params |
|
90 | // value and label params | |
84 | QPieSlice slice2(1.0, "foobar"); |
|
91 | QPieSlice slice2(1.0, "foobar"); | |
85 |
Q |
|
92 | QCOMPARE(slice2.value(), 1.0); | |
86 | QCOMPARE(slice2.label(), QString("foobar")); |
|
93 | QCOMPARE(slice2.label(), QString("foobar")); | |
87 | QVERIFY(!slice2.isLabelVisible()); |
|
94 | QVERIFY(!slice2.isLabelVisible()); | |
88 | QVERIFY(!slice2.isExploded()); |
|
95 | QVERIFY(!slice2.isExploded()); | |
89 | QCOMPARE(slice2.pen(), QPen()); |
|
96 | QCOMPARE(slice2.pen(), QPen()); | |
90 | QCOMPARE(slice2.brush(), QBrush()); |
|
97 | QCOMPARE(slice2.brush(), QBrush()); | |
91 | QCOMPARE(slice2.labelPen(), QPen()); |
|
98 | QCOMPARE(slice2.labelPen(), QPen()); | |
92 | QCOMPARE(slice2.labelFont(), QFont()); |
|
99 | QCOMPARE(slice2.labelFont(), QFont()); | |
93 |
Q |
|
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value | |
94 |
Q |
|
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value | |
95 |
Q |
|
102 | QCOMPARE(slice2.percentage(), 0.0); | |
96 |
Q |
|
103 | QCOMPARE(slice2.startAngle(), 0.0); | |
97 |
Q |
|
104 | QCOMPARE(slice2.endAngle(), 0.0); | |
98 | } |
|
105 | } | |
99 |
|
106 | |||
100 | void tst_qpieslice::changedSignals() |
|
107 | void tst_qpieslice::changedSignals() | |
101 | { |
|
108 | { | |
102 | // set everything twice to see we do not get unnecessary signals |
|
109 | // set everything twice to see we do not get unnecessary signals | |
103 | QPieSlice slice; |
|
110 | QPieSlice slice; | |
104 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined |
|
111 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined | |
105 | slice.setValue(1); |
|
112 | slice.setValue(1); | |
106 | slice.setValue(1); |
|
113 | slice.setValue(1); | |
107 | slice.setLabel("foobar"); |
|
114 | slice.setLabel("foobar"); | |
108 | slice.setLabel("foobar"); |
|
115 | slice.setLabel("foobar"); | |
109 | slice.setLabelVisible(); |
|
116 | slice.setLabelVisible(); | |
110 | slice.setLabelVisible(); |
|
117 | slice.setLabelVisible(); | |
111 | slice.setExploded(); |
|
118 | slice.setExploded(); | |
112 | slice.setExploded(); |
|
119 | slice.setExploded(); | |
113 | slice.setPen(QPen(Qt::red)); |
|
120 | slice.setPen(QPen(Qt::red)); | |
114 | slice.setPen(QPen(Qt::red)); |
|
121 | slice.setPen(QPen(Qt::red)); | |
115 | slice.setBrush(QBrush(Qt::red)); |
|
122 | slice.setBrush(QBrush(Qt::red)); | |
116 | slice.setBrush(QBrush(Qt::red)); |
|
123 | slice.setBrush(QBrush(Qt::red)); | |
117 | slice.setLabelPen(QPen(Qt::green)); |
|
124 | slice.setLabelPen(QPen(Qt::green)); | |
118 | slice.setLabelPen(QPen(Qt::green)); |
|
125 | slice.setLabelPen(QPen(Qt::green)); | |
119 | slice.setLabelFont(QFont("Tahoma")); |
|
126 | slice.setLabelFont(QFont("Tahoma")); | |
120 | slice.setLabelFont(QFont("Tahoma")); |
|
127 | slice.setLabelFont(QFont("Tahoma")); | |
121 | slice.setLabelArmLengthFactor(0.1); |
|
128 | slice.setLabelArmLengthFactor(0.1); | |
122 | slice.setLabelArmLengthFactor(0.1); |
|
129 | slice.setLabelArmLengthFactor(0.1); | |
123 | slice.setExplodeDistanceFactor(0.1); |
|
130 | slice.setExplodeDistanceFactor(0.1); | |
124 | slice.setExplodeDistanceFactor(0.1); |
|
131 | slice.setExplodeDistanceFactor(0.1); | |
125 |
|
|
132 | TRY_COMPARE(spy.count(), 10); | |
|
133 | } | |||
|
134 | ||||
|
135 | void tst_qpieslice::customize() | |||
|
136 | { | |||
|
137 | // create a pie series | |||
|
138 | QPieSeries *series = new QPieSeries(); | |||
|
139 | QPieSlice *s1 = series->append(1, "slice 1"); | |||
|
140 | QPieSlice *s2 = series->append(2, "slice 2"); | |||
|
141 | series->append(3, "slice 3"); | |||
|
142 | ||||
|
143 | // customize a slice | |||
|
144 | QPen p1(Qt::red); | |||
|
145 | s1->setPen(p1); | |||
|
146 | QBrush b1(Qt::red); | |||
|
147 | s1->setBrush(b1); | |||
|
148 | s1->setLabelPen(p1); | |||
|
149 | QFont f1("Consolas"); | |||
|
150 | s1->setLabelFont(f1); | |||
|
151 | ||||
|
152 | // add series to the chart | |||
|
153 | QChartView view(new QChart()); | |||
|
154 | view.resize(200, 200); | |||
|
155 | view.chart()->addSeries(series); | |||
|
156 | view.show(); | |||
|
157 | QTest::qWaitForWindowShown(&view); | |||
|
158 | //QTest::qWait(1000); | |||
|
159 | ||||
|
160 | // check that customizations persist | |||
|
161 | QCOMPARE(s1->pen(), p1); | |||
|
162 | QCOMPARE(s1->brush(), b1); | |||
|
163 | QCOMPARE(s1->labelPen(), p1); | |||
|
164 | QCOMPARE(s1->labelFont(), f1); | |||
|
165 | ||||
|
166 | // remove a slice | |||
|
167 | series->remove(s2); | |||
|
168 | QCOMPARE(s1->pen(), p1); | |||
|
169 | QCOMPARE(s1->brush(), b1); | |||
|
170 | QCOMPARE(s1->labelPen(), p1); | |||
|
171 | QCOMPARE(s1->labelFont(), f1); | |||
|
172 | ||||
|
173 | // add a slice | |||
|
174 | series->append(4, "slice 4"); | |||
|
175 | QCOMPARE(s1->pen(), p1); | |||
|
176 | QCOMPARE(s1->brush(), b1); | |||
|
177 | QCOMPARE(s1->labelPen(), p1); | |||
|
178 | QCOMPARE(s1->labelFont(), f1); | |||
|
179 | ||||
|
180 | // insert a slice | |||
|
181 | series->insert(0, new QPieSlice(5, "slice 5")); | |||
|
182 | QCOMPARE(s1->pen(), p1); | |||
|
183 | QCOMPARE(s1->brush(), b1); | |||
|
184 | QCOMPARE(s1->labelPen(), p1); | |||
|
185 | QCOMPARE(s1->labelFont(), f1); | |||
|
186 | ||||
|
187 | // change theme | |||
|
188 | // theme will overwrite customizations | |||
|
189 | view.chart()->setTheme(QChart::ChartThemeHighContrast); | |||
|
190 | QVERIFY(s1->pen() != p1); | |||
|
191 | QVERIFY(s1->brush() != b1); | |||
|
192 | QVERIFY(s1->labelPen() != p1); | |||
|
193 | QVERIFY(s1->labelFont() != f1); | |||
|
194 | } | |||
|
195 | ||||
|
196 | void tst_qpieslice::mouseClick() | |||
|
197 | { | |||
|
198 | // create a pie series | |||
|
199 | QPieSeries *series = new QPieSeries(); | |||
|
200 | series->setPieSize(1.0); | |||
|
201 | QPieSlice *s1 = series->append(1, "slice 1"); | |||
|
202 | QPieSlice *s2 = series->append(2, "slice 2"); | |||
|
203 | QPieSlice *s3 = series->append(3, "slice 3"); | |||
|
204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); | |||
|
205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); | |||
|
206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); | |||
|
207 | ||||
|
208 | // add series to the chart | |||
|
209 | QChartView view(new QChart()); | |||
|
210 | view.resize(200, 200); | |||
|
211 | view.chart()->addSeries(series); | |||
|
212 | view.show(); | |||
|
213 | QTest::qWaitForWindowShown(&view); | |||
|
214 | ||||
|
215 | // simulate clicks | |||
|
216 | // pie rectangle: QRectF(60,60 121x121) | |||
|
217 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |||
|
218 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 | |||
|
219 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 | |||
|
220 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice | |||
|
221 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice | |||
|
222 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
223 | QCOMPARE(clickSpy1.count(), 1); | |||
|
224 | QCOMPARE(clickSpy2.count(), 1); | |||
|
225 | QCOMPARE(clickSpy3.count(), 1); | |||
|
226 | } | |||
|
227 | ||||
|
228 | void tst_qpieslice::mouseHover() | |||
|
229 | { | |||
|
230 | // create a pie series | |||
|
231 | QPieSeries *series = new QPieSeries(); | |||
|
232 | series->setPieSize(1.0); | |||
|
233 | QPieSlice *s1 = series->append(1, "slice 1"); | |||
|
234 | series->append(2, "slice 2"); | |||
|
235 | series->append(3, "slice 3"); | |||
|
236 | ||||
|
237 | // add series to the chart | |||
|
238 | QChartView view(new QChart()); | |||
|
239 | view.resize(200, 200); | |||
|
240 | view.chart()->addSeries(series); | |||
|
241 | view.show(); | |||
|
242 | QTest::qWaitForWindowShown(&view); | |||
|
243 | ||||
|
244 | // first move to right top corner | |||
|
245 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |||
|
246 | ||||
|
247 | // move inside slice rectangle but NOT the actual slice | |||
|
248 | // pie rectangle: QRectF(60,60 121x121) | |||
|
249 | QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); | |||
|
250 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); | |||
|
251 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
252 | QCOMPARE(hoverSpy.count(), 0); | |||
|
253 | ||||
|
254 | // move inside the slice | |||
|
255 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |||
|
256 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
257 | QCOMPARE(hoverSpy.count(), 1); | |||
|
258 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); | |||
|
259 | ||||
|
260 | // move outside the slice | |||
|
261 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |||
|
262 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |||
|
263 | QCOMPARE(hoverSpy.count(), 2); | |||
|
264 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); | |||
126 | } |
|
265 | } | |
127 |
|
266 | |||
128 | QTEST_MAIN(tst_qpieslice) |
|
267 | QTEST_MAIN(tst_qpieslice) | |
129 |
|
268 | |||
130 | #include "tst_qpieslice.moc" |
|
269 | #include "tst_qpieslice.moc" | |
131 |
|
270 |
@@ -1,345 +1,349 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qstackedbarseries.h> |
|
31 | #include <qstackedbarseries.h> | |
32 | #include <qpercentbarseries.h> |
|
32 | #include <qpercentbarseries.h> | |
33 | #include <QPushButton> |
|
33 | #include <QPushButton> | |
34 | #include <QComboBox> |
|
34 | #include <QComboBox> | |
35 | #include <QSpinBox> |
|
35 | #include <QSpinBox> | |
36 | #include <QCheckBox> |
|
36 | #include <QCheckBox> | |
37 | #include <QGridLayout> |
|
37 | #include <QGridLayout> | |
38 | #include <QHBoxLayout> |
|
38 | #include <QHBoxLayout> | |
39 | #include <QLabel> |
|
39 | #include <QLabel> | |
40 | #include <QSpacerItem> |
|
40 | #include <QSpacerItem> | |
41 | #include <QMessageBox> |
|
41 | #include <QMessageBox> | |
42 | #include <cmath> |
|
42 | #include <cmath> | |
43 | #include <QDebug> |
|
43 | #include <QDebug> | |
44 | #include <QStandardItemModel> |
|
44 | #include <QStandardItemModel> | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
47 | QTCOMMERCIALCHART_USE_NAMESPACE | |
48 |
|
48 | |||
49 | MainWidget::MainWidget(QWidget *parent) : |
|
49 | MainWidget::MainWidget(QWidget *parent) : | |
50 | QWidget(parent), |
|
50 | QWidget(parent), | |
51 | m_addSerieDialog(0), |
|
51 | m_addSerieDialog(0), | |
52 | m_chart(0) |
|
52 | m_chart(0) | |
53 | { |
|
53 | { | |
54 | m_chart = new QChart(); |
|
54 | m_chart = new QChart(); | |
55 |
|
55 | |||
56 | // Grid layout for the controls for configuring the chart widget |
|
56 | // Grid layout for the controls for configuring the chart widget | |
57 | QGridLayout *grid = new QGridLayout(); |
|
57 | QGridLayout *grid = new QGridLayout(); | |
58 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
58 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
59 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
59 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
60 | grid->addWidget(addSeriesButton, 0, 1); |
|
60 | grid->addWidget(addSeriesButton, 0, 1); | |
61 | initBackroundCombo(grid); |
|
61 | initBackroundCombo(grid); | |
62 | initScaleControls(grid); |
|
62 | initScaleControls(grid); | |
63 | initThemeCombo(grid); |
|
63 | initThemeCombo(grid); | |
64 | initCheckboxes(grid); |
|
64 | initCheckboxes(grid); | |
65 |
|
65 | |||
66 | // add row with empty label to make all the other rows static |
|
66 | // add row with empty label to make all the other rows static | |
67 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
67 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
68 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
68 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
69 |
|
69 | |||
70 | // Create chart view with the chart |
|
70 | // Create chart view with the chart | |
71 | m_chartView = new QChartView(m_chart, this); |
|
71 | m_chartView = new QChartView(m_chart, this); | |
72 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
72 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
73 |
|
73 | |||
74 | // Another grid layout as a main layout |
|
74 | // Another grid layout as a main layout | |
75 | QGridLayout *mainLayout = new QGridLayout(); |
|
75 | QGridLayout *mainLayout = new QGridLayout(); | |
76 | mainLayout->addLayout(grid, 0, 0); |
|
76 | mainLayout->addLayout(grid, 0, 0); | |
77 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
77 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
78 | setLayout(mainLayout); |
|
78 | setLayout(mainLayout); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | // Combo box for selecting the chart's background |
|
81 | // Combo box for selecting the chart's background | |
82 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
82 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
83 | { |
|
83 | { | |
84 | QComboBox *backgroundCombo = new QComboBox(this); |
|
84 | QComboBox *backgroundCombo = new QComboBox(this); | |
85 | backgroundCombo->addItem("Color"); |
|
85 | backgroundCombo->addItem("Color"); | |
86 | backgroundCombo->addItem("Gradient"); |
|
86 | backgroundCombo->addItem("Gradient"); | |
87 | backgroundCombo->addItem("Image"); |
|
87 | backgroundCombo->addItem("Image"); | |
88 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
88 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
89 | this, SLOT(backgroundChanged(int))); |
|
89 | this, SLOT(backgroundChanged(int))); | |
90 |
|
90 | |||
91 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
91 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
92 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
92 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | // Scale related controls (auto-scale vs. manual min-max values) |
|
95 | // Scale related controls (auto-scale vs. manual min-max values) | |
96 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
96 | void MainWidget::initScaleControls(QGridLayout *grid) | |
97 | { |
|
97 | { | |
98 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
98 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
99 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
99 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
100 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
100 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
101 | m_xMinSpin = new QSpinBox(); |
|
101 | m_xMinSpin = new QSpinBox(); | |
102 | m_xMinSpin->setMinimum(INT_MIN); |
|
102 | m_xMinSpin->setMinimum(INT_MIN); | |
103 | m_xMinSpin->setMaximum(INT_MAX); |
|
103 | m_xMinSpin->setMaximum(INT_MAX); | |
104 | m_xMinSpin->setValue(0); |
|
104 | m_xMinSpin->setValue(0); | |
105 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
105 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
106 | m_xMaxSpin = new QSpinBox(); |
|
106 | m_xMaxSpin = new QSpinBox(); | |
107 | m_xMaxSpin->setMinimum(INT_MIN); |
|
107 | m_xMaxSpin->setMinimum(INT_MIN); | |
108 | m_xMaxSpin->setMaximum(INT_MAX); |
|
108 | m_xMaxSpin->setMaximum(INT_MAX); | |
109 | m_xMaxSpin->setValue(10); |
|
109 | m_xMaxSpin->setValue(10); | |
110 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
110 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
111 | m_yMinSpin = new QSpinBox(); |
|
111 | m_yMinSpin = new QSpinBox(); | |
112 | m_yMinSpin->setMinimum(INT_MIN); |
|
112 | m_yMinSpin->setMinimum(INT_MIN); | |
113 | m_yMinSpin->setMaximum(INT_MAX); |
|
113 | m_yMinSpin->setMaximum(INT_MAX); | |
114 | m_yMinSpin->setValue(0); |
|
114 | m_yMinSpin->setValue(0); | |
115 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
115 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
116 | m_yMaxSpin = new QSpinBox(); |
|
116 | m_yMaxSpin = new QSpinBox(); | |
117 | m_yMaxSpin->setMinimum(INT_MIN); |
|
117 | m_yMaxSpin->setMinimum(INT_MIN); | |
118 | m_yMaxSpin->setMaximum(INT_MAX); |
|
118 | m_yMaxSpin->setMaximum(INT_MAX); | |
119 | m_yMaxSpin->setValue(10); |
|
119 | m_yMaxSpin->setValue(10); | |
120 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
120 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
121 |
|
121 | |||
122 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
122 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
123 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
123 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
124 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
124 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
125 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
125 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
126 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
126 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
127 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
127 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
128 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
128 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
129 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
129 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
130 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
130 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
131 |
|
131 | |||
132 | m_autoScaleCheck->setChecked(true); |
|
132 | m_autoScaleCheck->setChecked(true); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | // Combo box for selecting theme |
|
135 | // Combo box for selecting theme | |
136 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
136 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
137 | { |
|
137 | { | |
138 | QComboBox *chartTheme = new QComboBox(); |
|
138 | QComboBox *chartTheme = new QComboBox(); | |
139 | chartTheme->addItem("Default"); |
|
139 | chartTheme->addItem("Default"); | |
140 | chartTheme->addItem("Light"); |
|
140 | chartTheme->addItem("Light"); | |
141 | chartTheme->addItem("Blue Cerulean"); |
|
141 | chartTheme->addItem("Blue Cerulean"); | |
142 | chartTheme->addItem("Dark"); |
|
142 | chartTheme->addItem("Dark"); | |
143 | chartTheme->addItem("Brown Sand"); |
|
143 | chartTheme->addItem("Brown Sand"); | |
144 | chartTheme->addItem("Blue NCS"); |
|
144 | chartTheme->addItem("Blue NCS"); | |
145 | chartTheme->addItem("High Contrast"); |
|
145 | chartTheme->addItem("High Contrast"); | |
146 | chartTheme->addItem("Blue Icy"); |
|
146 | chartTheme->addItem("Blue Icy"); | |
147 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
147 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
148 | this, SLOT(changeChartTheme(int))); |
|
148 | this, SLOT(changeChartTheme(int))); | |
149 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
149 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
150 | grid->addWidget(chartTheme, 8, 1); |
|
150 | grid->addWidget(chartTheme, 8, 1); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | // Different check boxes for customizing chart |
|
153 | // Different check boxes for customizing chart | |
154 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
154 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
155 | { |
|
155 | { | |
156 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
156 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
157 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
157 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
158 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
158 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
159 | zoomCheckBox->setChecked(true); |
|
159 | zoomCheckBox->setChecked(true); | |
160 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
160 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
161 |
|
161 | |||
162 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
162 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
163 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
163 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
164 | aliasCheckBox->setChecked(false); |
|
164 | aliasCheckBox->setChecked(false); | |
165 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
165 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void MainWidget::antiAliasToggled(bool enabled) |
|
168 | void MainWidget::antiAliasToggled(bool enabled) | |
169 | { |
|
169 | { | |
170 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
170 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void MainWidget::addSeries() |
|
173 | void MainWidget::addSeries() | |
174 | { |
|
174 | { | |
175 | if (!m_addSerieDialog) { |
|
175 | if (!m_addSerieDialog) { | |
176 | m_addSerieDialog = new DataSerieDialog(this); |
|
176 | m_addSerieDialog = new DataSerieDialog(this); | |
177 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
177 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
178 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
178 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
179 | } |
|
179 | } | |
180 | m_addSerieDialog->exec(); |
|
180 | m_addSerieDialog->exec(); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
183 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
184 | { |
|
184 | { | |
185 | // TODO: dataCharacteristics |
|
185 | // TODO: dataCharacteristics | |
186 | QList<RealList> testData; |
|
186 | QList<RealList> testData; | |
187 | for (int j(0); j < columnCount; j++) { |
|
187 | for (int j(0); j < columnCount; j++) { | |
188 | QList <qreal> newColumn; |
|
188 | QList <qreal> newColumn; | |
189 | for (int i(0); i < rowCount; i++) { |
|
189 | for (int i(0); i < rowCount; i++) { | |
190 | if (dataCharacteristics == "Sin") { |
|
190 | if (dataCharacteristics == "Sin") { | |
191 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
191 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
192 | } else if (dataCharacteristics == "Sin + random") { |
|
192 | } else if (dataCharacteristics == "Sin + random") { | |
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
194 | } else if (dataCharacteristics == "Random") { |
|
194 | } else if (dataCharacteristics == "Random") { | |
195 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
195 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
196 | } else if (dataCharacteristics == "Linear") { |
|
196 | } else if (dataCharacteristics == "Linear") { | |
197 | //newColumn.append(i * (j + 1.0)); |
|
197 | //newColumn.append(i * (j + 1.0)); | |
198 | // TODO: temporary hack to make pie work; prevent zero values: |
|
198 | // TODO: temporary hack to make pie work; prevent zero values: | |
199 | newColumn.append(i * (j + 1.0) + 0.1); |
|
199 | newColumn.append(i * (j + 1.0) + 0.1); | |
200 | } else { // "constant" |
|
200 | } else { // "constant" | |
201 | newColumn.append((j + 1.0)); |
|
201 | newColumn.append((j + 1.0)); | |
202 | } |
|
202 | } | |
203 | } |
|
203 | } | |
204 | testData.append(newColumn); |
|
204 | testData.append(newColumn); | |
205 | } |
|
205 | } | |
206 | return testData; |
|
206 | return testData; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | QStringList MainWidget::generateLabels(int count) |
|
209 | QStringList MainWidget::generateLabels(int count) | |
210 | { |
|
210 | { | |
211 | QStringList result; |
|
211 | QStringList result; | |
212 | for (int i(0); i < count; i++) |
|
212 | for (int i(0); i < count; i++) | |
213 | result.append("label" + QString::number(i)); |
|
213 | result.append("label" + QString::number(i)); | |
214 | return result; |
|
214 | return result; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
217 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
218 | { |
|
218 | { | |
219 | qDebug() << "addSeries: " << seriesName |
|
219 | qDebug() << "addSeries: " << seriesName | |
220 | << " columnCount: " << columnCount |
|
220 | << " columnCount: " << columnCount | |
221 | << " rowCount: " << rowCount |
|
221 | << " rowCount: " << rowCount | |
222 | << " dataCharacteristics: " << dataCharacteristics |
|
222 | << " dataCharacteristics: " << dataCharacteristics | |
223 | << " labels enabled: " << labelsEnabled; |
|
223 | << " labels enabled: " << labelsEnabled; | |
224 | m_defaultSeriesName = seriesName; |
|
224 | m_defaultSeriesName = seriesName; | |
225 |
|
225 | |||
226 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
226 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
227 |
|
227 | |||
228 | // Line series and scatter series use similar data |
|
228 | // Line series and scatter series use similar data | |
229 | if (seriesName == "Line") { |
|
229 | if (seriesName == "Line") { | |
230 | for (int j(0); j < data.count(); j ++) { |
|
230 | for (int j(0); j < data.count(); j ++) { | |
231 | QList<qreal> column = data.at(j); |
|
231 | QList<qreal> column = data.at(j); | |
232 | QLineSeries *series = new QLineSeries(); |
|
232 | QLineSeries *series = new QLineSeries(); | |
233 | series->setName("line" + QString::number(j)); |
|
233 | series->setName("line" + QString::number(j)); | |
234 | for (int i(0); i < column.count(); i++) |
|
234 | for (int i(0); i < column.count(); i++) | |
235 | series->append(i, column.at(i)); |
|
235 | series->append(i, column.at(i)); | |
236 | m_chart->addSeries(series); |
|
236 | m_chart->addSeries(series); | |
237 | } |
|
237 | } | |
238 | } else if (seriesName == "Area") { |
|
238 | } else if (seriesName == "Area") { | |
239 | // TODO: lower series for the area? |
|
239 | // TODO: lower series for the area? | |
240 | for (int j(0); j < data.count(); j ++) { |
|
240 | for (int j(0); j < data.count(); j ++) { | |
241 | QList<qreal> column = data.at(j); |
|
241 | QList<qreal> column = data.at(j); | |
242 | QLineSeries *lineSeries = new QLineSeries(); |
|
242 | QLineSeries *lineSeries = new QLineSeries(); | |
243 | for (int i(0); i < column.count(); i++) |
|
243 | for (int i(0); i < column.count(); i++) | |
244 | lineSeries->append(i, column.at(i)); |
|
244 | lineSeries->append(i, column.at(i)); | |
245 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
245 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
246 | areaSeries->setName("area" + QString::number(j)); |
|
246 | areaSeries->setName("area" + QString::number(j)); | |
247 | m_chart->addSeries(areaSeries); |
|
247 | m_chart->addSeries(areaSeries); | |
248 | } |
|
248 | } | |
249 | } else if (seriesName == "Scatter") { |
|
249 | } else if (seriesName == "Scatter") { | |
250 | for (int j(0); j < data.count(); j++) { |
|
250 | for (int j(0); j < data.count(); j++) { | |
251 | QList<qreal> column = data.at(j); |
|
251 | QList<qreal> column = data.at(j); | |
252 | QScatterSeries *series = new QScatterSeries(); |
|
252 | QScatterSeries *series = new QScatterSeries(); | |
253 | series->setName("scatter" + QString::number(j)); |
|
253 | series->setName("scatter" + QString::number(j)); | |
254 | for (int i(0); i < column.count(); i++) |
|
254 | for (int i(0); i < column.count(); i++) | |
255 | series->append(i, column.at(i)); |
|
255 | series->append(i, column.at(i)); | |
256 | m_chart->addSeries(series); |
|
256 | m_chart->addSeries(series); | |
257 | } |
|
257 | } | |
258 | } else if (seriesName == "Pie") { |
|
258 | } else if (seriesName == "Pie") { | |
259 | QStringList labels = generateLabels(rowCount); |
|
259 | QStringList labels = generateLabels(rowCount); | |
260 | for (int j(0); j < data.count(); j++) { |
|
260 | for (int j(0); j < data.count(); j++) { | |
261 | QPieSeries *series = new QPieSeries(); |
|
261 | QPieSeries *series = new QPieSeries(); | |
262 | QList<qreal> column = data.at(j); |
|
262 | QList<qreal> column = data.at(j); | |
263 | for (int i(0); i < column.count(); i++) |
|
263 | for (int i(0); i < column.count(); i++) | |
264 | series->append(column.at(i), labels.at(i)); |
|
264 | series->append(column.at(i), labels.at(i)); | |
265 | m_chart->addSeries(series); |
|
265 | m_chart->addSeries(series); | |
266 | } |
|
266 | } | |
267 | } else if (seriesName == "Bar" |
|
267 | } else if (seriesName == "Bar" | |
268 | || seriesName == "Stacked bar" |
|
268 | || seriesName == "Stacked bar" | |
269 | || seriesName == "Percent bar") { |
|
269 | || seriesName == "Percent bar") { | |
270 | QStringList category; |
|
270 | QStringList category; | |
271 | QStringList labels = generateLabels(rowCount); |
|
271 | QStringList labels = generateLabels(rowCount); | |
272 | foreach(QString label, labels) |
|
272 | foreach(QString label, labels) | |
273 | category << label; |
|
273 | category << label; | |
274 | QBarSeries* series = 0; |
|
274 | QBarSeries* series = 0; | |
275 | if (seriesName == "Bar") |
|
275 | if (seriesName == "Bar") { | |
276 |
series = new QBarSeries( |
|
276 | series = new QBarSeries(this); | |
277 | else if (seriesName == "Stacked bar") |
|
277 | series->setCategories(category); | |
278 | series = new QStackedBarSeries(category, this); |
|
278 | } else if (seriesName == "Stacked bar") { | |
279 | else |
|
279 | series = new QStackedBarSeries(this); | |
280 |
series |
|
280 | series->setCategories(category); | |
|
281 | } else { | |||
|
282 | series = new QPercentBarSeries(this); | |||
|
283 | series->setCategories(category); | |||
|
284 | } | |||
281 |
|
285 | |||
282 | for (int j(0); j < data.count(); j++) { |
|
286 | for (int j(0); j < data.count(); j++) { | |
283 | QList<qreal> column = data.at(j); |
|
287 | QList<qreal> column = data.at(j); | |
284 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
288 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
285 | for (int i(0); i < column.count(); i++) |
|
289 | for (int i(0); i < column.count(); i++) | |
286 | *set << column.at(i); |
|
290 | *set << column.at(i); | |
287 | series->appendBarSet(set); |
|
291 | series->appendBarSet(set); | |
288 | } |
|
292 | } | |
289 |
|
293 | |||
290 | m_chart->addSeries(series); |
|
294 | m_chart->addSeries(series); | |
291 | } else if (seriesName == "Spline") { |
|
295 | } else if (seriesName == "Spline") { | |
292 | for (int j(0); j < data.count(); j ++) { |
|
296 | for (int j(0); j < data.count(); j ++) { | |
293 | QList<qreal> column = data.at(j); |
|
297 | QList<qreal> column = data.at(j); | |
294 | QSplineSeries *series = new QSplineSeries(); |
|
298 | QSplineSeries *series = new QSplineSeries(); | |
295 | for (int i(0); i < column.count(); i++) |
|
299 | for (int i(0); i < column.count(); i++) | |
296 | series->append(i, column.at(i)); |
|
300 | series->append(i, column.at(i)); | |
297 | m_chart->addSeries(series); |
|
301 | m_chart->addSeries(series); | |
298 | } |
|
302 | } | |
299 | } |
|
303 | } | |
300 | } |
|
304 | } | |
301 |
|
305 | |||
302 | void MainWidget::backgroundChanged(int itemIndex) |
|
306 | void MainWidget::backgroundChanged(int itemIndex) | |
303 | { |
|
307 | { | |
304 | qDebug() << "backgroundChanged: " << itemIndex; |
|
308 | qDebug() << "backgroundChanged: " << itemIndex; | |
305 | } |
|
309 | } | |
306 |
|
310 | |||
307 | void MainWidget::autoScaleChanged(int value) |
|
311 | void MainWidget::autoScaleChanged(int value) | |
308 | { |
|
312 | { | |
309 | if (value) { |
|
313 | if (value) { | |
310 | // TODO: enable auto scaling |
|
314 | // TODO: enable auto scaling | |
311 | } else { |
|
315 | } else { | |
312 | // TODO: set scaling manually (and disable auto scaling) |
|
316 | // TODO: set scaling manually (and disable auto scaling) | |
313 | } |
|
317 | } | |
314 |
|
318 | |||
315 | m_xMinSpin->setEnabled(!value); |
|
319 | m_xMinSpin->setEnabled(!value); | |
316 | m_xMaxSpin->setEnabled(!value); |
|
320 | m_xMaxSpin->setEnabled(!value); | |
317 | m_yMinSpin->setEnabled(!value); |
|
321 | m_yMinSpin->setEnabled(!value); | |
318 | m_yMaxSpin->setEnabled(!value); |
|
322 | m_yMaxSpin->setEnabled(!value); | |
319 | } |
|
323 | } | |
320 |
|
324 | |||
321 | void MainWidget::xMinChanged(int value) |
|
325 | void MainWidget::xMinChanged(int value) | |
322 | { |
|
326 | { | |
323 | qDebug() << "xMinChanged: " << value; |
|
327 | qDebug() << "xMinChanged: " << value; | |
324 | } |
|
328 | } | |
325 |
|
329 | |||
326 | void MainWidget::xMaxChanged(int value) |
|
330 | void MainWidget::xMaxChanged(int value) | |
327 | { |
|
331 | { | |
328 | qDebug() << "xMaxChanged: " << value; |
|
332 | qDebug() << "xMaxChanged: " << value; | |
329 | } |
|
333 | } | |
330 |
|
334 | |||
331 | void MainWidget::yMinChanged(int value) |
|
335 | void MainWidget::yMinChanged(int value) | |
332 | { |
|
336 | { | |
333 | qDebug() << "yMinChanged: " << value; |
|
337 | qDebug() << "yMinChanged: " << value; | |
334 | } |
|
338 | } | |
335 |
|
339 | |||
336 | void MainWidget::yMaxChanged(int value) |
|
340 | void MainWidget::yMaxChanged(int value) | |
337 | { |
|
341 | { | |
338 | qDebug() << "yMaxChanged: " << value; |
|
342 | qDebug() << "yMaxChanged: " << value; | |
339 | } |
|
343 | } | |
340 |
|
344 | |||
341 | void MainWidget::changeChartTheme(int themeIndex) |
|
345 | void MainWidget::changeChartTheme(int themeIndex) | |
342 | { |
|
346 | { | |
343 | qDebug() << "changeChartTheme: " << themeIndex; |
|
347 | qDebug() << "changeChartTheme: " << themeIndex; | |
344 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
348 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
345 | } |
|
349 | } |
@@ -1,244 +1,245 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "widget.h" |
|
21 | #include "widget.h" | |
22 |
|
22 | |||
23 | #include <QChart> |
|
23 | #include <QChart> | |
24 | #include <QScatterSeries> |
|
24 | #include <QScatterSeries> | |
25 | #include <QAxis> |
|
25 | #include <QAxis> | |
26 | #include <QBarSet> |
|
26 | #include <QBarSet> | |
27 | #include <QBarSeries> |
|
27 | #include <QBarSeries> | |
28 | #include <QLegend> |
|
28 | #include <QLegend> | |
29 |
|
29 | |||
30 | #include <QGridLayout> |
|
30 | #include <QGridLayout> | |
31 | #include <QPushButton> |
|
31 | #include <QPushButton> | |
32 | #include <QLabel> |
|
32 | #include <QLabel> | |
33 | #include <QListWidget> |
|
33 | #include <QListWidget> | |
34 | #include <QPrinter> |
|
34 | #include <QPrinter> | |
35 | #include <QPrintDialog> |
|
35 | #include <QPrintDialog> | |
36 | #include <QRadioButton> |
|
36 | #include <QRadioButton> | |
37 | #include <QStringList> |
|
37 | #include <QStringList> | |
38 | #include <QSqlQuery> |
|
38 | #include <QSqlQuery> | |
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
41 | QTCOMMERCIALCHART_USE_NAMESPACE | |
42 |
|
42 | |||
43 | Widget::Widget(QWidget *parent) |
|
43 | Widget::Widget(QWidget *parent) | |
44 | : QWidget(parent) |
|
44 | : QWidget(parent) | |
45 | { |
|
45 | { | |
46 | setGeometry(100, 100, 1000, 600); |
|
46 | setGeometry(100, 100, 1000, 600); | |
47 |
|
47 | |||
48 | // right panel layout |
|
48 | // right panel layout | |
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); |
|
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); | |
50 | barChartRadioButton->setChecked(true); |
|
50 | barChartRadioButton->setChecked(true); | |
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); |
|
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); | |
52 | scatterChartRadioButton->setChecked(false); |
|
52 | scatterChartRadioButton->setChecked(false); | |
53 | countrieslist = new QListWidget; |
|
53 | countrieslist = new QListWidget; | |
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); | |
55 |
|
55 | |||
56 | //list of years widget |
|
56 | //list of years widget | |
57 | yearslist = new QListWidget; |
|
57 | yearslist = new QListWidget; | |
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
59 | for (int i = 1990; i < 2011; i++) |
|
59 | for (int i = 1990; i < 2011; i++) | |
60 | yearslist->addItem(QString("%1").arg(i)); |
|
60 | yearslist->addItem(QString("%1").arg(i)); | |
61 |
|
61 | |||
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); | |
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); | |
64 |
|
64 | |||
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); |
|
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); | |
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); |
|
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); | |
67 |
|
67 | |||
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; | |
69 | rightPanelLayout->addWidget(barChartRadioButton); |
|
69 | rightPanelLayout->addWidget(barChartRadioButton); | |
70 | rightPanelLayout->addWidget(scatterChartRadioButton); |
|
70 | rightPanelLayout->addWidget(scatterChartRadioButton); | |
71 | rightPanelLayout->addWidget(countrieslist); |
|
71 | rightPanelLayout->addWidget(countrieslist); | |
72 | rightPanelLayout->addWidget(yearslist); |
|
72 | rightPanelLayout->addWidget(yearslist); | |
73 | rightPanelLayout->addWidget(refreshButton); |
|
73 | rightPanelLayout->addWidget(refreshButton); | |
74 | rightPanelLayout->addWidget(printButton); |
|
74 | rightPanelLayout->addWidget(printButton); | |
75 | rightPanelLayout->setStretch(0, 1); |
|
75 | rightPanelLayout->setStretch(0, 1); | |
76 | rightPanelLayout->setStretch(1, 0); |
|
76 | rightPanelLayout->setStretch(1, 0); | |
77 |
|
77 | |||
78 | QChart *chart = new QChart(); |
|
78 | QChart *chart = new QChart(); | |
79 | chart->setTitle("GDP by country"); |
|
79 | chart->setTitle("GDP by country"); | |
80 | chart->legend()->setVisible(true); |
|
80 | chart->legend()->setVisible(true); | |
81 |
|
81 | |||
82 | // main layout |
|
82 | // main layout | |
83 | chartView = new QChartView(chart); |
|
83 | chartView = new QChartView(chart); | |
84 | QGridLayout* mainLayout = new QGridLayout; |
|
84 | QGridLayout* mainLayout = new QGridLayout; | |
85 | mainLayout->addWidget(chartView, 0, 0); |
|
85 | mainLayout->addWidget(chartView, 0, 0); | |
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); | |
87 | mainLayout->setColumnStretch(0,1); |
|
87 | mainLayout->setColumnStretch(0,1); | |
88 | setLayout(mainLayout); |
|
88 | setLayout(mainLayout); | |
89 |
|
89 | |||
90 | // connect to the database |
|
90 | // connect to the database | |
91 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
91 | db = QSqlDatabase::addDatabase("QSQLITE"); | |
92 | db.setDatabaseName("gdpData"); |
|
92 | db.setDatabaseName("gdpData"); | |
93 | if(!db.open()) |
|
93 | if(!db.open()) | |
94 | { |
|
94 | { | |
95 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
95 | qDebug() << "could not open database. SQLite db file missing (?)"; | |
96 | return; |
|
96 | return; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | // get the list of all countires and regions. |
|
99 | // get the list of all countires and regions. | |
100 | QSqlQuery query; |
|
100 | QSqlQuery query; | |
101 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
101 | query.exec("SELECT DISTINCT country FROM gdp2"); | |
102 |
|
102 | |||
103 | // add the countries to the country filter |
|
103 | // add the countries to the country filter | |
104 | while (query.next()) { |
|
104 | while (query.next()) { | |
105 | countrieslist->addItem(query.value(0).toString()); |
|
105 | countrieslist->addItem(query.value(0).toString()); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | Widget::~Widget() |
|
109 | Widget::~Widget() | |
110 | { |
|
110 | { | |
111 | // |
|
111 | // | |
112 | db.close(); |
|
112 | db.close(); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | refreshes the chart |
|
116 | refreshes the chart | |
117 | */ |
|
117 | */ | |
118 | void Widget::refreshChart() |
|
118 | void Widget::refreshChart() | |
119 | { |
|
119 | { | |
120 | chartView->chart()->removeAllSeries(); |
|
120 | chartView->chart()->removeAllSeries(); | |
121 |
|
121 | |||
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. | |
123 | QStringList selectedCountriesStrings; |
|
123 | QStringList selectedCountriesStrings; | |
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); | |
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) | |
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); | |
127 | selectedCountriesStrings.sort(); |
|
127 | selectedCountriesStrings.sort(); | |
128 |
|
128 | |||
129 | QSqlQuery query; |
|
129 | QSqlQuery query; | |
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. |
|
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. | |
131 | QList<int> selectedYearsInts; |
|
131 | QList<int> selectedYearsInts; | |
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); | |
133 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
133 | for (int i = 0; i < selectedYearsItems.size(); i++) | |
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); | |
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); |
|
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); | |
136 |
|
136 | |||
137 | if (barChartRadioButton->isChecked()) |
|
137 | if (barChartRadioButton->isChecked()) | |
138 | { |
|
138 | { | |
139 | // use the sorted selected coutries list to initialize BarCategory |
|
139 | // use the sorted selected coutries list to initialize BarCategory | |
140 | QStringList category; |
|
140 | QStringList category; | |
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
142 | category << selectedCountriesStrings[i]; |
|
142 | category << selectedCountriesStrings[i]; | |
143 |
QBarSeries* series0 = new QBarSeries( |
|
143 | QBarSeries* series0 = new QBarSeries(); | |
144 |
series0 |
|
144 | series0->setCategories(category); | |
|
145 | // series0 = new QBarSeries(category); | |||
145 |
|
146 | |||
146 | // prepare the selected counries SQL query |
|
147 | // prepare the selected counries SQL query | |
147 | QString countriesQuery = "country IN ("; |
|
148 | QString countriesQuery = "country IN ("; | |
148 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
149 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
149 | { |
|
150 | { | |
150 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
151 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); | |
151 | if ( i < selectedCountriesStrings.size() - 1) |
|
152 | if ( i < selectedCountriesStrings.size() - 1) | |
152 | countriesQuery.append(","); |
|
153 | countriesQuery.append(","); | |
153 | else |
|
154 | else | |
154 | countriesQuery.append(")"); |
|
155 | countriesQuery.append(")"); | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | // perform a query for each selected year |
|
158 | // perform a query for each selected year | |
158 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
159 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
159 | { |
|
160 | { | |
160 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
161 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); | |
161 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); |
|
162 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); | |
162 |
|
163 | |||
163 | // while (query.next()) { |
|
164 | // while (query.next()) { | |
164 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
165 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); | |
165 | // } |
|
166 | // } | |
166 | query.first(); |
|
167 | query.first(); | |
167 |
|
168 | |||
168 | // the data for some of the coutries for some years might be missing. |
|
169 | // the data for some of the coutries for some years might be missing. | |
169 | // QBarChart needs bars to have same size |
|
170 | // QBarChart needs bars to have same size | |
170 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
171 | for (int k = 0; k < selectedCountriesStrings.size(); k++) | |
171 | { |
|
172 | { | |
172 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
173 | if (selectedCountriesStrings[k] == query.value(0).toString()) | |
173 | { |
|
174 | { | |
174 | *barSet << query.value(1).toReal(); |
|
175 | *barSet << query.value(1).toReal(); | |
175 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
176 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); | |
176 | query.next(); |
|
177 | query.next(); | |
177 | } |
|
178 | } | |
178 | else |
|
179 | else | |
179 | { |
|
180 | { | |
180 | // data missing, put 0 |
|
181 | // data missing, put 0 | |
181 | *barSet << 0.0f; |
|
182 | *barSet << 0.0f; | |
182 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
183 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); | |
183 | } |
|
184 | } | |
184 | } |
|
185 | } | |
185 | series0->appendBarSet(barSet); |
|
186 | series0->appendBarSet(barSet); | |
186 | } |
|
187 | } | |
187 | // add the serie to the chart |
|
188 | // add the serie to the chart | |
188 | chartView->chart()->addSeries(series0); |
|
189 | chartView->chart()->addSeries(series0); | |
189 | } |
|
190 | } | |
190 | else if (scatterChartRadioButton->isChecked()) |
|
191 | else if (scatterChartRadioButton->isChecked()) | |
191 | { |
|
192 | { | |
192 | QString yearsQuery = "year IN ("; |
|
193 | QString yearsQuery = "year IN ("; | |
193 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
194 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
194 | { |
|
195 | { | |
195 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); |
|
196 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); | |
196 | if ( i < selectedYearsInts.size() - 1) |
|
197 | if ( i < selectedYearsInts.size() - 1) | |
197 | yearsQuery.append(","); |
|
198 | yearsQuery.append(","); | |
198 | else |
|
199 | else | |
199 | yearsQuery.append(")"); |
|
200 | yearsQuery.append(")"); | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | // perform a query for each selected country |
|
203 | // perform a query for each selected country | |
203 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
204 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
204 | { |
|
205 | { | |
205 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); |
|
206 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); | |
206 | query.first(); |
|
207 | query.first(); | |
207 |
|
208 | |||
208 | QScatterSeries* series = new QScatterSeries; |
|
209 | QScatterSeries* series = new QScatterSeries; | |
209 | series->setName(selectedCountriesStrings[i]); |
|
210 | series->setName(selectedCountriesStrings[i]); | |
210 | // the data for some of the coutries for some years might be missing. |
|
211 | // the data for some of the coutries for some years might be missing. | |
211 | for (int k = 0; k < selectedYearsInts.size(); k++) |
|
212 | for (int k = 0; k < selectedYearsInts.size(); k++) | |
212 | { |
|
213 | { | |
213 | if (selectedYearsInts[k] == query.value(0).toInt()) |
|
214 | if (selectedYearsInts[k] == query.value(0).toInt()) | |
214 | { |
|
215 | { | |
215 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); |
|
216 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); | |
216 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); |
|
217 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); | |
217 | query.next(); |
|
218 | query.next(); | |
218 | } |
|
219 | } | |
219 | else |
|
220 | else | |
220 | { |
|
221 | { | |
221 | // data missing, put 0 |
|
222 | // data missing, put 0 | |
222 | *series << QPointF(selectedYearsInts[k] , 0.0f); |
|
223 | *series << QPointF(selectedYearsInts[k] , 0.0f); | |
223 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); |
|
224 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); | |
224 | } |
|
225 | } | |
225 | } |
|
226 | } | |
226 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); |
|
227 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); | |
227 | chartView->chart()->addSeries(series); |
|
228 | chartView->chart()->addSeries(series); | |
228 | } |
|
229 | } | |
229 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); |
|
230 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); | |
230 | } |
|
231 | } | |
231 | } |
|
232 | } | |
232 |
|
233 | |||
233 | void Widget::printChart() |
|
234 | void Widget::printChart() | |
234 | { |
|
235 | { | |
235 | QPrinter printer; |
|
236 | QPrinter printer; | |
236 | // QPrinter printer(QPrinter::HighResolution); |
|
237 | // QPrinter printer(QPrinter::HighResolution); | |
237 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
238 | printer.setOutputFormat(QPrinter::PdfFormat); | |
238 | printer.setOrientation(QPrinter::Landscape); |
|
239 | printer.setOrientation(QPrinter::Landscape); | |
239 | printer.setOutputFileName("print.pdf"); |
|
240 | printer.setOutputFileName("print.pdf"); | |
240 |
|
241 | |||
241 | QPainter painter; |
|
242 | QPainter painter; | |
242 | painter.begin(&printer); |
|
243 | painter.begin(&printer); | |
243 | chartView->render(&painter); |
|
244 | chartView->render(&painter); | |
244 | } |
|
245 | } |
@@ -1,411 +1,412 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QChart> |
|
24 | #include <QChart> | |
25 | #include <QStyledItemDelegate> |
|
25 | #include <QStyledItemDelegate> | |
26 | #include <QLineSeries> |
|
26 | #include <QLineSeries> | |
27 | #include <QSplineSeries> |
|
27 | #include <QSplineSeries> | |
28 | #include <QScatterSeries> |
|
28 | #include <QScatterSeries> | |
29 | #include "customtablemodel.h" |
|
29 | #include "customtablemodel.h" | |
30 | #include <QPieSeries> |
|
30 | #include <QPieSeries> | |
31 | #include <QPieSlice> |
|
31 | #include <QPieSlice> | |
32 | #include <QAreaSeries> |
|
32 | #include <QAreaSeries> | |
33 | #include <QBarSeries> |
|
33 | #include <QBarSeries> | |
34 | #include <QBarSet> |
|
34 | #include <QBarSet> | |
35 | #include <QPushButton> |
|
35 | #include <QPushButton> | |
36 | #include <QRadioButton> |
|
36 | #include <QRadioButton> | |
37 | #include <QLabel> |
|
37 | #include <QLabel> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QTime> |
|
39 | #include <QTime> | |
40 | #include <QHeaderView> |
|
40 | #include <QHeaderView> | |
41 |
|
41 | |||
42 | TableWidget::TableWidget(QWidget *parent) |
|
42 | TableWidget::TableWidget(QWidget *parent) | |
43 | : QWidget(parent) |
|
43 | : QWidget(parent) | |
44 | // specialPie(0) |
|
44 | // specialPie(0) | |
45 | { |
|
45 | { | |
46 | setGeometry(1900, 100, 1000, 600); |
|
46 | setGeometry(1900, 100, 1000, 600); | |
47 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
47 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
48 | // create simple model for storing data |
|
48 | // create simple model for storing data | |
49 | // user's table data model |
|
49 | // user's table data model | |
50 | m_model = new CustomTableModel; |
|
50 | m_model = new CustomTableModel; | |
51 | m_tableView = new QTableView; |
|
51 | m_tableView = new QTableView; | |
52 | m_tableView->setModel(m_model); |
|
52 | m_tableView->setModel(m_model); | |
53 | // m_tableView->setMinimumHeight(300); |
|
53 | // m_tableView->setMinimumHeight(300); | |
54 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
54 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
55 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
55 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
56 |
|
56 | |||
57 | m_chart = new QChart; |
|
57 | m_chart = new QChart; | |
58 | m_chart->legend()->setVisible(true); |
|
58 | m_chart->legend()->setVisible(true); | |
59 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
59 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
60 | m_chartView = new QChartView(m_chart); |
|
60 | m_chartView = new QChartView(m_chart); | |
61 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
61 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
62 | m_chartView->setMinimumSize(640, 480); |
|
62 | m_chartView->setMinimumSize(640, 480); | |
63 |
|
63 | |||
64 | // add, remove data buttons |
|
64 | // add, remove data buttons | |
65 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
65 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
66 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
66 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
67 |
|
67 | |||
68 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
68 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
69 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
69 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
70 |
|
70 | |||
71 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
71 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
72 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
72 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
73 |
|
73 | |||
74 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
74 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); | |
75 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
75 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); | |
76 |
|
76 | |||
77 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
77 | QPushButton* removeColumnButton = new QPushButton("Remove column"); | |
78 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
78 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); | |
79 |
|
79 | |||
80 | QPushButton* specialPieButton = new QPushButton("Test pie"); |
|
80 | QPushButton* specialPieButton = new QPushButton("Test pie"); | |
81 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
81 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
84 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
85 |
|
85 | |||
86 | // spin box for setting number of affected items (add, remove) |
|
86 | // spin box for setting number of affected items (add, remove) | |
87 | m_linesCountSpinBox = new QSpinBox; |
|
87 | m_linesCountSpinBox = new QSpinBox; | |
88 | m_linesCountSpinBox->setRange(1, 10); |
|
88 | m_linesCountSpinBox->setRange(1, 10); | |
89 | m_linesCountSpinBox->setValue(1); |
|
89 | m_linesCountSpinBox->setValue(1); | |
90 |
|
90 | |||
91 | // buttons layout |
|
91 | // buttons layout | |
92 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
92 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
93 | // buttonsLayout->addWidget(spinBoxLabel); |
|
93 | // buttonsLayout->addWidget(spinBoxLabel); | |
94 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
94 | // buttonsLayout->addWidget(m_linesCountSpinBox); | |
95 | // buttonsLayout->addWidget(addRowAboveButton); |
|
95 | // buttonsLayout->addWidget(addRowAboveButton); | |
96 | buttonsLayout->addWidget(addRowBelowButton); |
|
96 | buttonsLayout->addWidget(addRowBelowButton); | |
97 | buttonsLayout->addWidget(removeRowButton); |
|
97 | buttonsLayout->addWidget(removeRowButton); | |
98 | // buttonsLayout->addWidget(addColumnRightButton); |
|
98 | // buttonsLayout->addWidget(addColumnRightButton); | |
99 | // buttonsLayout->addWidget(removeColumnButton); |
|
99 | // buttonsLayout->addWidget(removeColumnButton); | |
100 | // buttonsLayout->addWidget(specialPieButton); |
|
100 | // buttonsLayout->addWidget(specialPieButton); | |
101 | buttonsLayout->addStretch(); |
|
101 | buttonsLayout->addStretch(); | |
102 |
|
102 | |||
103 | // chart type radio buttons |
|
103 | // chart type radio buttons | |
104 | m_lineRadioButton = new QRadioButton("Line"); |
|
104 | m_lineRadioButton = new QRadioButton("Line"); | |
105 | m_splineRadioButton = new QRadioButton("Spline"); |
|
105 | m_splineRadioButton = new QRadioButton("Spline"); | |
106 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
106 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
107 | m_pieRadioButton = new QRadioButton("Pie"); |
|
107 | m_pieRadioButton = new QRadioButton("Pie"); | |
108 | m_areaRadioButton = new QRadioButton("Area"); |
|
108 | m_areaRadioButton = new QRadioButton("Area"); | |
109 | m_barRadioButton = new QRadioButton("Bar"); |
|
109 | m_barRadioButton = new QRadioButton("Bar"); | |
110 |
|
110 | |||
111 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
111 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
112 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
112 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
113 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
113 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
114 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
114 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
115 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
115 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
116 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
116 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
117 | m_pieRadioButton->setChecked(true); |
|
117 | m_pieRadioButton->setChecked(true); | |
118 |
|
118 | |||
119 | // radio buttons layout |
|
119 | // radio buttons layout | |
120 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
120 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
121 | radioLayout->addWidget(m_lineRadioButton); |
|
121 | radioLayout->addWidget(m_lineRadioButton); | |
122 | // radioLayout->addWidget(m_splineRadioButton); |
|
122 | // radioLayout->addWidget(m_splineRadioButton); | |
123 | // radioLayout->addWidget(m_scatterRadioButton); |
|
123 | // radioLayout->addWidget(m_scatterRadioButton); | |
124 | radioLayout->addWidget(m_pieRadioButton); |
|
124 | radioLayout->addWidget(m_pieRadioButton); | |
125 | // radioLayout->addWidget(m_areaRadioButton); |
|
125 | // radioLayout->addWidget(m_areaRadioButton); | |
126 | radioLayout->addWidget(m_barRadioButton); |
|
126 | radioLayout->addWidget(m_barRadioButton); | |
127 | radioLayout->addStretch(); |
|
127 | radioLayout->addStretch(); | |
128 |
|
128 | |||
129 | // create main layout |
|
129 | // create main layout | |
130 | QGridLayout* mainLayout = new QGridLayout; |
|
130 | QGridLayout* mainLayout = new QGridLayout; | |
131 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
131 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
132 | // mainLayout->addLayout(radioLayout, 2, 1); |
|
132 | // mainLayout->addLayout(radioLayout, 2, 1); | |
133 | mainLayout->addWidget(m_tableView, 1, 0); |
|
133 | mainLayout->addWidget(m_tableView, 1, 0); | |
134 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
134 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
135 | setLayout(mainLayout); |
|
135 | setLayout(mainLayout); | |
136 | m_lineRadioButton->setFocus(); |
|
136 | m_lineRadioButton->setFocus(); | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | void TableWidget::addRowAbove() |
|
139 | void TableWidget::addRowAbove() | |
140 | { |
|
140 | { | |
141 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
141 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
142 |
|
142 | |||
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void TableWidget::addRowBelow() |
|
145 | void TableWidget::addRowBelow() | |
146 | { |
|
146 | { | |
147 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
147 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
148 |
|
148 | |||
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void TableWidget::removeRow() |
|
151 | void TableWidget::removeRow() | |
152 | { |
|
152 | { | |
153 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
153 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void TableWidget::addColumnRight() |
|
156 | void TableWidget::addColumnRight() | |
157 | { |
|
157 | { | |
158 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
158 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void TableWidget::removeColumn() |
|
161 | void TableWidget::removeColumn() | |
162 | { |
|
162 | { | |
163 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
163 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void TableWidget::updateChartType(bool toggle) |
|
166 | void TableWidget::updateChartType(bool toggle) | |
167 | { |
|
167 | { | |
168 | // this if is needed, so that the function is only called once. |
|
168 | // this if is needed, so that the function is only called once. | |
169 | // For the radioButton that was enabled. |
|
169 | // For the radioButton that was enabled. | |
170 | if (toggle) { |
|
170 | if (toggle) { | |
171 | // specialPie = 0; |
|
171 | // specialPie = 0; | |
172 | m_chart->removeAllSeries(); |
|
172 | m_chart->removeAllSeries(); | |
173 | m_chart->axisX()->setNiceNumbersEnabled(false); |
|
173 | m_chart->axisX()->setNiceNumbersEnabled(false); | |
174 | m_chart->axisY()->setNiceNumbersEnabled(false); |
|
174 | m_chart->axisY()->setNiceNumbersEnabled(false); | |
175 |
|
175 | |||
176 | // renable axes of the chart (pie hides them) |
|
176 | // renable axes of the chart (pie hides them) | |
177 | // x axis |
|
177 | // x axis | |
178 | QAxis *axis = m_chart->axisX(); |
|
178 | QAxis *axis = m_chart->axisX(); | |
179 | axis->setAxisVisible(true); |
|
179 | axis->setAxisVisible(true); | |
180 | axis->setGridLineVisible(true); |
|
180 | axis->setGridLineVisible(true); | |
181 | axis->setLabelsVisible(true); |
|
181 | axis->setLabelsVisible(true); | |
182 |
|
182 | |||
183 | // y axis |
|
183 | // y axis | |
184 | axis = m_chart->axisY(); |
|
184 | axis = m_chart->axisY(); | |
185 | axis->setAxisVisible(true); |
|
185 | axis->setAxisVisible(true); | |
186 | axis->setGridLineVisible(true); |
|
186 | axis->setGridLineVisible(true); | |
187 | axis->setLabelsVisible(true); |
|
187 | axis->setLabelsVisible(true); | |
188 |
|
188 | |||
189 | m_model->clearMapping(); |
|
189 | m_model->clearMapping(); | |
190 |
|
190 | |||
191 | QString seriesColorHex = "#000000"; |
|
191 | QString seriesColorHex = "#000000"; | |
192 | QPen pen; |
|
192 | QPen pen; | |
193 | pen.setWidth(2); |
|
193 | pen.setWidth(2); | |
194 |
|
194 | |||
195 | if (m_lineRadioButton->isChecked()) |
|
195 | if (m_lineRadioButton->isChecked()) | |
196 | { |
|
196 | { | |
197 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
197 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
198 |
|
198 | |||
199 | // series 1 |
|
199 | // series 1 | |
200 | m_series = new QLineSeries; |
|
200 | m_series = new QLineSeries; | |
201 | m_series->setModel(m_model); |
|
201 | m_series->setModel(m_model); | |
202 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
202 | m_series->setModelMapping(0,1, Qt::Vertical); | |
203 | m_series->setModelMappingRange(3, 4); |
|
203 | m_series->setModelMappingRange(3, 4); | |
204 | m_chart->addSeries(m_series); |
|
204 | m_chart->addSeries(m_series); | |
205 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
205 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
206 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
206 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
207 |
|
207 | |||
208 | // series 2 |
|
208 | // series 2 | |
209 | m_series = new QLineSeries; |
|
209 | m_series = new QLineSeries; | |
210 | m_series->setModel(m_model); |
|
210 | m_series->setModel(m_model); | |
211 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
211 | m_series->setModelMapping(2,3, Qt::Vertical); | |
212 | m_chart->addSeries(m_series); |
|
212 | m_chart->addSeries(m_series); | |
213 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
213 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
214 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
214 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
215 |
|
215 | |||
216 | // series 3 |
|
216 | // series 3 | |
217 | m_series = new QLineSeries; |
|
217 | m_series = new QLineSeries; | |
218 | m_series->setModel(m_model); |
|
218 | m_series->setModel(m_model); | |
219 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
219 | m_series->setModelMapping(4,5, Qt::Vertical); | |
220 | m_series->setModelMappingRange(2, -1); |
|
220 | m_series->setModelMappingRange(2, -1); | |
221 | m_chart->addSeries(m_series); |
|
221 | m_chart->addSeries(m_series); | |
222 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
222 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
223 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
223 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
224 | } |
|
224 | } | |
225 | else if (m_splineRadioButton->isChecked()) |
|
225 | else if (m_splineRadioButton->isChecked()) | |
226 | { |
|
226 | { | |
227 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
227 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
228 |
|
228 | |||
229 | // series 1 |
|
229 | // series 1 | |
230 | m_series = new QSplineSeries; |
|
230 | m_series = new QSplineSeries; | |
231 | m_series->setModel(m_model); |
|
231 | m_series->setModel(m_model); | |
232 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
232 | m_series->setModelMapping(0,1, Qt::Vertical); | |
233 | // m_series->setModelMappingRange(1, 4); |
|
233 | // m_series->setModelMappingRange(1, 4); | |
234 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
234 | // series->setModelMapping(0,1, Qt::Horizontal); | |
235 | m_chart->addSeries(m_series); |
|
235 | m_chart->addSeries(m_series); | |
236 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
236 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
237 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
237 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
238 |
|
238 | |||
239 | // series 2 |
|
239 | // series 2 | |
240 | m_series = new QSplineSeries; |
|
240 | m_series = new QSplineSeries; | |
241 | m_series->setModel(m_model); |
|
241 | m_series->setModel(m_model); | |
242 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
242 | m_series->setModelMapping(2,3, Qt::Vertical); | |
243 | m_series->setModelMappingRange(2, 4); |
|
243 | m_series->setModelMappingRange(2, 4); | |
244 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
244 | // series->setModelMapping(2,3, Qt::Horizontal); | |
245 | m_chart->addSeries(m_series); |
|
245 | m_chart->addSeries(m_series); | |
246 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
246 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
247 | m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
247 | m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
248 |
|
248 | |||
249 | // series 3 |
|
249 | // series 3 | |
250 | m_series = new QSplineSeries; |
|
250 | m_series = new QSplineSeries; | |
251 | m_series->setModel(m_model); |
|
251 | m_series->setModel(m_model); | |
252 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
252 | m_series->setModelMapping(4,5, Qt::Vertical); | |
253 | m_series->setModelMappingRange(2, -1); |
|
253 | m_series->setModelMappingRange(2, -1); | |
254 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
254 | // series->setModelMapping(4,5, Qt::Horizontal); | |
255 | m_chart->addSeries(m_series); |
|
255 | m_chart->addSeries(m_series); | |
256 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
256 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
257 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
257 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
258 | } |
|
258 | } | |
259 | else if (m_scatterRadioButton->isChecked()) |
|
259 | else if (m_scatterRadioButton->isChecked()) | |
260 | { |
|
260 | { | |
261 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
261 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
262 |
|
262 | |||
263 | // series 1 |
|
263 | // series 1 | |
264 | m_series = new QScatterSeries; |
|
264 | m_series = new QScatterSeries; | |
265 | m_series->setModel(m_model); |
|
265 | m_series->setModel(m_model); | |
266 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
266 | m_series->setModelMapping(0,1, Qt::Vertical); | |
267 | // m_series->setModelMappingRange(2, 0); |
|
267 | // m_series->setModelMappingRange(2, 0); | |
268 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
268 | // series->setModelMapping(0,1, Qt::Horizontal); | |
269 | m_chart->addSeries(m_series); |
|
269 | m_chart->addSeries(m_series); | |
270 |
|
270 | |||
271 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
271 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
272 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
272 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
273 |
|
273 | |||
274 | // series 2 |
|
274 | // series 2 | |
275 | m_series = new QScatterSeries; |
|
275 | m_series = new QScatterSeries; | |
276 | m_series->setModel(m_model); |
|
276 | m_series->setModel(m_model); | |
277 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
277 | m_series->setModelMapping(2,3, Qt::Vertical); | |
278 | // m_series->setModelMappingRange(1, 6); |
|
278 | // m_series->setModelMappingRange(1, 6); | |
279 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
279 | // series->setModelMapping(2,3, Qt::Horizontal); | |
280 | m_chart->addSeries(m_series); |
|
280 | m_chart->addSeries(m_series); | |
281 |
|
281 | |||
282 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
282 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
283 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
283 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
284 |
|
284 | |||
285 | // series 3 |
|
285 | // series 3 | |
286 | m_series = new QScatterSeries; |
|
286 | m_series = new QScatterSeries; | |
287 | m_series->setModel(m_model); |
|
287 | m_series->setModel(m_model); | |
288 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
288 | m_series->setModelMapping(4,5, Qt::Vertical); | |
289 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
289 | // series->setModelMapping(4,5, Qt::Horizontal); | |
290 | m_chart->addSeries(m_series); |
|
290 | m_chart->addSeries(m_series); | |
291 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
291 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
292 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
292 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
293 | } |
|
293 | } | |
294 | else if (m_pieRadioButton->isChecked()) |
|
294 | else if (m_pieRadioButton->isChecked()) | |
295 | { |
|
295 | { | |
296 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
296 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
297 |
|
297 | |||
298 | // pie 1 |
|
298 | // pie 1 | |
299 | QPieSeries* pieSeries = new QPieSeries; |
|
299 | QPieSeries* pieSeries = new QPieSeries; | |
300 | pieSeries->setModel(m_model); |
|
300 | pieSeries->setModel(m_model); | |
301 | pieSeries->setModelMappingRange(2, 5); |
|
301 | pieSeries->setModelMappingRange(2, 5); | |
302 | pieSeries->setModelMapping(1, 0, Qt::Vertical); |
|
302 | pieSeries->setModelMapping(1, 0, Qt::Vertical); | |
303 | pieSeries->setLabelsVisible(true); |
|
303 | pieSeries->setLabelsVisible(true); | |
304 | pieSeries->setPieSize(0.75); |
|
304 | pieSeries->setPieSize(0.75); | |
305 | // pieSeries->setHorizontalPosition(0.2); |
|
305 | // pieSeries->setHorizontalPosition(0.2); | |
306 | // pieSeries->setVerticalPosition(0.3); |
|
306 | // pieSeries->setVerticalPosition(0.3); | |
307 |
|
307 | |||
308 | m_chart->addSeries(pieSeries); |
|
308 | m_chart->addSeries(pieSeries); | |
309 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
309 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
310 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
310 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); | |
311 |
|
311 | |||
312 | // // pie 2 |
|
312 | // // pie 2 | |
313 | // pieSeries = new QPieSeries; |
|
313 | // pieSeries = new QPieSeries; | |
314 | // pieSeries->setModel(m_model); |
|
314 | // pieSeries->setModel(m_model); | |
315 |
|
315 | |||
316 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
316 | // pieSeries->setModelMapping(1,1, Qt::Vertical); | |
317 | // pieSeries->setModelMappingRange(2, -1); |
|
317 | // pieSeries->setModelMappingRange(2, -1); | |
318 | // pieSeries->setLabelsVisible(true); |
|
318 | // pieSeries->setLabelsVisible(true); | |
319 | // pieSeries->setPieSize(0.35); |
|
319 | // pieSeries->setPieSize(0.35); | |
320 | // pieSeries->setHorizontalPosition(0.8); |
|
320 | // pieSeries->setHorizontalPosition(0.8); | |
321 | // pieSeries->setVerticalPosition(0.3); |
|
321 | // pieSeries->setVerticalPosition(0.3); | |
322 | // m_chart->addSeries(pieSeries); |
|
322 | // m_chart->addSeries(pieSeries); | |
323 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
323 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
324 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
324 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); | |
325 |
|
325 | |||
326 | // // pie 3 |
|
326 | // // pie 3 | |
327 | // pieSeries = new QPieSeries; |
|
327 | // pieSeries = new QPieSeries; | |
328 | // pieSeries->setModel(m_model); |
|
328 | // pieSeries->setModel(m_model); | |
329 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
329 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
330 | // pieSeries->setLabelsVisible(true); |
|
330 | // pieSeries->setLabelsVisible(true); | |
331 | // pieSeries->setPieSize(0.35); |
|
331 | // pieSeries->setPieSize(0.35); | |
332 | // pieSeries->setHorizontalPosition(0.5); |
|
332 | // pieSeries->setHorizontalPosition(0.5); | |
333 | // pieSeries->setVerticalPosition(0.75); |
|
333 | // pieSeries->setVerticalPosition(0.75); | |
334 | // m_chart->addSeries(pieSeries); |
|
334 | // m_chart->addSeries(pieSeries); | |
335 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
335 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
336 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
336 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
337 |
|
337 | |||
338 | // // special pie |
|
338 | // // special pie | |
339 | // specialPie = new QPieSeries; |
|
339 | // specialPie = new QPieSeries; | |
340 | // specialPie->append(17, "1"); |
|
340 | // specialPie->append(17, "1"); | |
341 | // specialPie->append(45, "2"); |
|
341 | // specialPie->append(45, "2"); | |
342 | // specialPie->append(77, "3"); |
|
342 | // specialPie->append(77, "3"); | |
343 | // specialPie->append(37, "4"); |
|
343 | // specialPie->append(37, "4"); | |
344 | // specialPie->append(27, "5"); |
|
344 | // specialPie->append(27, "5"); | |
345 | // specialPie->append(47, "6"); |
|
345 | // specialPie->append(47, "6"); | |
346 | // specialPie->setPieSize(0.35); |
|
346 | // specialPie->setPieSize(0.35); | |
347 | // specialPie->setHorizontalPosition(0.8); |
|
347 | // specialPie->setHorizontalPosition(0.8); | |
348 | // specialPie->setVerticalPosition(0.75); |
|
348 | // specialPie->setVerticalPosition(0.75); | |
349 | // specialPie->setLabelsVisible(true); |
|
349 | // specialPie->setLabelsVisible(true); | |
350 | // m_chart->addSeries(specialPie); |
|
350 | // m_chart->addSeries(specialPie); | |
351 | } |
|
351 | } | |
352 | else if (m_areaRadioButton->isChecked()) |
|
352 | else if (m_areaRadioButton->isChecked()) | |
353 | { |
|
353 | { | |
354 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
354 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
355 |
|
355 | |||
356 | QLineSeries* upperLineSeries = new QLineSeries; |
|
356 | QLineSeries* upperLineSeries = new QLineSeries; | |
357 | upperLineSeries->setModel(m_model); |
|
357 | upperLineSeries->setModel(m_model); | |
358 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
358 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
359 | // upperLineSeries->setModelMappingRange(1, 5); |
|
359 | // upperLineSeries->setModelMappingRange(1, 5); | |
360 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
360 | QLineSeries* lowerLineSeries = new QLineSeries; | |
361 | lowerLineSeries->setModel(m_model); |
|
361 | lowerLineSeries->setModel(m_model); | |
362 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
362 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
363 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
363 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
364 | m_chart->addSeries(areaSeries); |
|
364 | m_chart->addSeries(areaSeries); | |
365 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
365 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
366 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
366 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
367 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
367 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
368 | } |
|
368 | } | |
369 | else if (m_barRadioButton->isChecked()) |
|
369 | else if (m_barRadioButton->isChecked()) | |
370 | { |
|
370 | { | |
371 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
371 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
372 |
|
372 | |||
373 |
QBarSeries* barSeries = new QBarSeries( |
|
373 | QBarSeries* barSeries = new QBarSeries(); | |
|
374 | barSeries->setCategories(QStringList()); | |||
374 | barSeries->setModel(m_model); |
|
375 | barSeries->setModel(m_model); | |
375 | // barSeries->setModelMappingRange(2, 5); |
|
376 | // barSeries->setModelMappingRange(2, 5); | |
376 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
377 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
377 | m_chart->addSeries(barSeries); |
|
378 | m_chart->addSeries(barSeries); | |
378 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
379 | QList<QBarSet*> barsets = barSeries->barSets(); | |
379 | for (int i = 0; i < barsets.count(); i++) { |
|
380 | for (int i = 0; i < barsets.count(); i++) { | |
380 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
381 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
381 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
382 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
382 | } |
|
383 | } | |
383 | } |
|
384 | } | |
384 |
|
385 | |||
385 |
|
386 | |||
386 | if (!m_barRadioButton->isChecked()) { |
|
387 | if (!m_barRadioButton->isChecked()) { | |
387 | m_chart->axisX()->setRange(0, 500); |
|
388 | m_chart->axisX()->setRange(0, 500); | |
388 | m_chart->axisY()->setRange(0, 220); |
|
389 | m_chart->axisY()->setRange(0, 220); | |
389 | } |
|
390 | } | |
390 | m_chart->legend()->setVisible(true); |
|
391 | m_chart->legend()->setVisible(true); | |
391 |
|
392 | |||
392 | // repaint table view colors |
|
393 | // repaint table view colors | |
393 | m_tableView->repaint(); |
|
394 | m_tableView->repaint(); | |
394 | m_tableView->setFocus(); |
|
395 | m_tableView->setFocus(); | |
395 | } |
|
396 | } | |
396 | } |
|
397 | } | |
397 |
|
398 | |||
398 | void TableWidget::testPie() |
|
399 | void TableWidget::testPie() | |
399 | { |
|
400 | { | |
400 | m_tableView->setColumnWidth(10, 250); |
|
401 | m_tableView->setColumnWidth(10, 250); | |
401 | // if (specialPie) { |
|
402 | // if (specialPie) { | |
402 | // specialPie->remove(specialPie->slices().at(2)); |
|
403 | // specialPie->remove(specialPie->slices().at(2)); | |
403 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
404 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | |
404 | // specialPie->append(4, "heloo"); |
|
405 | // specialPie->append(4, "heloo"); | |
405 | // } |
|
406 | // } | |
406 | } |
|
407 | } | |
407 |
|
408 | |||
408 | TableWidget::~TableWidget() |
|
409 | TableWidget::~TableWidget() | |
409 | { |
|
410 | { | |
410 |
|
411 | |||
411 | } |
|
412 | } |
General Comments 0
You need to be logged in to leave comments.
Login now