@@ -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 | 1 | # This file is used to ignore files which are generated in the Qt build system |
|
2 | 2 | # ---------------------------------------------------------------------------- |
|
3 | 3 | |
|
4 | 4 | examples/*/*/* |
|
5 | 5 | !examples/*/*/*[.]* |
|
6 | 6 | !examples/*/*/README |
|
7 | 7 | examples/*/*/*[.]app |
|
8 | 8 | !examples/declarative/* |
|
9 | 9 | !examples/tutorials/* |
|
10 | 10 | !examples/tutorials/*/* |
|
11 | 11 | !examples/ja_JP/*/* |
|
12 | demos/*/* | |
|
13 | 12 | !demos/spectrum/* |
|
14 | 13 | demos/spectrum/bin |
|
15 | 14 | !demos/*/*[.]* |
|
16 | 15 | demos/*/*[.]app |
|
17 | 16 | !demos/declarative/* |
|
18 | 17 | config.tests/*/*/* |
|
19 | 18 | !config.tests/*/*/*[.]* |
|
20 | 19 | config.tests/*/*/*[.]app |
|
21 | 20 | |
|
22 | 21 | callgrind.out.* |
|
23 | 22 | pcviewer.cfg |
|
24 | 23 | *~ |
|
25 | 24 | *.a |
|
26 | 25 | *.la |
|
27 | 26 | *.core |
|
28 | 27 | *.moc |
|
29 | 28 | *.o |
|
30 | 29 | *.obj |
|
31 | 30 | *.orig |
|
32 | 31 | *.swp |
|
33 | 32 | *.rej |
|
34 | 33 | *.so |
|
35 | 34 | *.pbxuser |
|
36 | 35 | *.mode1 |
|
37 | 36 | *.mode1v3 |
|
38 | 37 | *_pch.h.cpp |
|
39 | 38 | *_resource.rc |
|
40 | 39 | .#* |
|
41 | 40 | *.*# |
|
42 | 41 | core |
|
43 | 42 | .qmake.cache |
|
44 | 43 | .qmake.vars |
|
45 | 44 | *.prl |
|
46 | 45 | tags |
|
47 | 46 | .DS_Store |
|
48 | 47 | *.debug |
|
49 | 48 | Makefile* |
|
50 | 49 | !qmake/Makefile.win32* |
|
51 | 50 | !qmake/Makefile.unix |
|
52 | 51 | *.prl |
|
53 | 52 | *.app |
|
54 | 53 | *.pro.user* |
|
55 | 54 | *.qmlproject.user* |
|
56 | 55 | *.gcov |
|
57 | 56 | bin/Qt*.dll |
|
58 | 57 | bin/assistant* |
|
59 | 58 | bin/designer* |
|
60 | 59 | bin/dumpcpp* |
|
61 | 60 | bin/idc* |
|
62 | 61 | bin/linguist* |
|
63 | 62 | bin/lrelease* |
|
64 | 63 | bin/lupdate* |
|
65 | 64 | bin/lconvert* |
|
66 | 65 | bin/moc* |
|
67 | 66 | bin/makeqpf* |
|
68 | 67 | bin/pixeltool* |
|
69 | 68 | bin/qmake* |
|
70 | 69 | bin/qdoc3* |
|
71 | 70 | bin/qt3to4* |
|
72 | 71 | bin/qtdemo* |
|
73 | 72 | bin/qttracereplay* |
|
74 | 73 | bin/rcc* |
|
75 | 74 | bin/uic* |
|
76 | 75 | bin/patternist* |
|
77 | 76 | bin/phonon* |
|
78 | 77 | bin/qcollectiongenerator* |
|
79 | 78 | bin/qdbus* |
|
80 | 79 | bin/qhelpconverter* |
|
81 | 80 | bin/qhelpgenerator* |
|
82 | 81 | bin/qtconfig* |
|
83 | 82 | bin/xmlpatterns* |
|
84 | 83 | bin/cetest* |
|
85 | 84 | bin/collectiongenerator |
|
86 | 85 | bin/helpconverter |
|
87 | 86 | bin/helpgenerator |
|
88 | 87 | bin/kmap2qmap* |
|
89 | 88 | bin/qlalr* |
|
90 | 89 | bin/qmlconv* |
|
91 | 90 | bin/qmldebugger* |
|
92 | 91 | bin/qml* |
|
93 | 92 | bin/qttracereplay* |
|
94 | 93 | configure.cache |
|
95 | 94 | config.status |
|
96 | 95 | mkspecs/default |
|
97 | 96 | mkspecs/qconfig.pri |
|
98 | 97 | moc_*.cpp |
|
99 | 98 | qmake/qmake.exe |
|
100 | 99 | qmake/Makefile.bak |
|
101 | 100 | src/corelib/global/qconfig.cpp |
|
102 | 101 | src/corelib/global/qconfig.h |
|
103 | 102 | src/corelib/global/qconfig.h.qmake |
|
104 | 103 | src/tools/uic/qclass_lib_map.h |
|
105 | 104 | ui_*.h |
|
106 | 105 | tests/auto/qprocess/test*/*.exe |
|
107 | 106 | tests/auto/qtcpsocket/stressTest/*.exe |
|
108 | 107 | tests/auto/qprocess/fileWriterProcess/*.exe |
|
109 | 108 | tests/auto/qmake/testdata/quotedfilenames/*.exe |
|
110 | 109 | tests/auto/compilerwarnings/*.exe |
|
111 | 110 | tests/auto/qmake/testdata/quotedfilenames/test.cpp |
|
112 | 111 | tests/auto/qprocess/fileWriterProcess.txt |
|
113 | 112 | .com.apple.timemachine.supported |
|
114 | 113 | tests/auto/qlibrary/libmylib.so* |
|
115 | 114 | tests/auto/qresourceengine/runtime_resource.rcc |
|
116 | 115 | tools/qtestlib/chart/chart* |
|
117 | 116 | tools/qtestlib/updater/updater* |
|
118 | 117 | tools/activeqt/testcon/testcon.tlb |
|
119 | 118 | translations/*.qm |
|
120 | 119 | translations/*_untranslated.ts |
|
121 | 120 | qrc_*.cpp |
|
122 | 121 | |
|
123 | 122 | # Test generated files |
|
124 | 123 | QObject.log |
|
125 | 124 | tst_* |
|
126 | 125 | !tst_*.* |
|
127 | 126 | tst_*.log |
|
128 | 127 | tst_*.debug |
|
129 | 128 | tst_*~ |
|
130 | 129 | |
|
131 | 130 | # xemacs temporary files |
|
132 | 131 | *.flc |
|
133 | 132 | |
|
134 | 133 | # Vim temporary files |
|
135 | 134 | .*.swp |
|
136 | 135 | |
|
137 | 136 | # Visual Studio generated files |
|
138 | 137 | *.ib_pdb_index |
|
139 | 138 | *.idb |
|
140 | 139 | *.ilk |
|
141 | 140 | *.pdb |
|
142 | 141 | *.sln |
|
143 | 142 | *.suo |
|
144 | 143 | *.vcproj |
|
145 | 144 | *vcproj.*.*.user |
|
146 | 145 | *.ncb |
|
147 | 146 | *.vcxproj |
|
148 | 147 | *.vcxproj.filters |
|
149 | 148 | *.vcxproj.user |
|
150 | 149 | |
|
151 | 150 | # MinGW generated files |
|
152 | 151 | *.Debug |
|
153 | 152 | *.Release |
|
154 | 153 | |
|
155 | 154 | # WebKit temp files |
|
156 | 155 | src/3rdparty/webkit/WebCore/mocinclude.tmp |
|
157 | 156 | src/3rdparty/webkit/includes.txt |
|
158 | 157 | src/3rdparty/webkit/includes2.txt |
|
159 | 158 | |
|
160 | 159 | # Symlinks generated by configure |
|
161 | 160 | tools/qvfb/qvfbhdr.h |
|
162 | 161 | tools/qvfb/qlock_p.h |
|
163 | 162 | tools/qvfb/qlock.cpp |
|
164 | 163 | tools/qvfb/qwssignalhandler.cpp |
|
165 | 164 | tools/qvfb/qwssignalhandler_p.h |
|
166 | 165 | .DS_Store |
|
167 | 166 | .pch |
|
168 | 167 | .rcc |
|
169 | 168 | *.app |
|
170 | 169 | config.status |
|
171 | 170 | config.tests/unix/cups/cups |
|
172 | 171 | config.tests/unix/getaddrinfo/getaddrinfo |
|
173 | 172 | config.tests/unix/getifaddrs/getifaddrs |
|
174 | 173 | config.tests/unix/iconv/iconv |
|
175 | 174 | config.tests/unix/ipv6/ipv6 |
|
176 | 175 | config.tests/unix/ipv6ifname/ipv6ifname |
|
177 | 176 | config.tests/unix/largefile/largefile |
|
178 | 177 | config.tests/unix/nis/nis |
|
179 | 178 | config.tests/unix/odbc/odbc |
|
180 | 179 | config.tests/unix/openssl/openssl |
|
181 | 180 | config.tests/unix/stl/stl |
|
182 | 181 | config.tests/unix/zlib/zlib |
|
183 | 182 | config.tests/unix/3dnow/3dnow |
|
184 | 183 | config.tests/unix/mmx/mmx |
|
185 | 184 | config.tests/unix/sse/sse |
|
186 | 185 | config.tests/unix/sse2/sse2 |
|
187 | 186 | |
|
188 | 187 | |
|
189 | 188 | |
|
190 | 189 | # Directories to ignore |
|
191 | 190 | # --------------------- |
|
192 | 191 | |
|
193 | 192 | debug |
|
194 | 193 | examples/tools/plugandpaint/plugins |
|
195 | 194 | include/* |
|
196 | 195 | include/*/* |
|
197 | 196 | lib/* |
|
198 | 197 | !lib/fonts |
|
199 | 198 | !lib/README |
|
200 | 199 | plugins/*/* |
|
201 | 200 | release |
|
202 | 201 | tmp |
|
203 | 202 | doc-build |
|
204 | 203 | doc/html/* |
|
205 | 204 | tools/qdoc3/doc/html/* |
|
206 | 205 | doc/qch |
|
207 | 206 | doc-build |
|
208 | 207 | .rcc |
|
209 | 208 | .pch |
|
210 | 209 | .metadata |
|
211 | 210 | build/* |
|
212 | 211 | bin/* |
|
213 | 212 | coverage/* |
|
214 | 213 | |
|
215 | 214 | # Symbian build system generated files |
|
216 | 215 | # --------------------- |
|
217 | 216 | |
|
218 | 217 | ABLD.BAT |
|
219 | 218 | bld.inf* |
|
220 | 219 | *.mmp |
|
221 | 220 | *.mk |
|
222 | 221 | *.rss |
|
223 | 222 | *.loc |
|
224 | 223 | !s60main.rss |
|
225 | 224 | *.pkg |
|
226 | 225 | plugin_commonu.def |
|
227 | 226 | *.qtplugin |
|
228 | 227 | *.sis |
|
229 | 228 | *.sisx |
|
230 | 229 | *.lst |
|
231 | 230 | *.exe |
|
232 | 231 | *.mif |
|
233 | 232 | *.rsc |
|
234 | 233 | *.sym |
|
235 | 234 | *.lib |
|
236 | 235 | |
|
237 | 236 | # runonphone crash dumps |
|
238 | 237 | d_exc_*.txt |
|
239 | 238 | d_exc_*.stk |
|
240 | 239 | |
|
241 | 240 | # Generated by abldfast.bat from devtools. |
|
242 | 241 | .abldsteps.* |
|
243 | 242 | |
|
244 | 243 | # Carbide project files |
|
245 | 244 | # --------------------- |
|
246 | 245 | .project |
|
247 | 246 | .cproject |
|
248 | 247 | .make.cache |
|
249 | 248 | *.d |
|
250 | 249 | |
|
251 | 250 | # OSX build files |
|
252 | 251 | *.xcodeproj |
|
253 | 252 | Info.plist |
|
254 | 253 | |
|
255 | 254 | qtc-debugging-helper |
|
256 | 255 | qtc-qmldump |
|
257 | 256 | qtc-qmldbg |
|
258 | 257 | |
|
259 | 258 | .pc/ |
|
260 | 259 | |
|
261 | 260 | # INTEGRITY generated files |
|
262 | 261 | *.gpj |
|
263 | 262 | *.int |
|
264 | 263 | *.ael |
|
265 | 264 | *.dla |
|
266 | 265 | *.dnm |
|
267 | 266 | *.dep |
|
268 | 267 | *.map |
|
269 | 268 | work |
|
270 | 269 |
@@ -1,375 +1,376 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "themewidget.h" |
|
22 | 22 | |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QPieSeries> |
|
25 | 25 | #include <QPieSlice> |
|
26 | 26 | #include <QBarSeries> |
|
27 | 27 | #include <QPercentBarSeries> |
|
28 | 28 | #include <QStackedBarSeries> |
|
29 | 29 | #include <QBarSet> |
|
30 | 30 | #include <QLineSeries> |
|
31 | 31 | #include <QSplineSeries> |
|
32 | 32 | #include <QScatterSeries> |
|
33 | 33 | #include <QAreaSeries> |
|
34 | 34 | #include <QLegend> |
|
35 | 35 | #include <QGridLayout> |
|
36 | 36 | #include <QFormLayout> |
|
37 | 37 | #include <QComboBox> |
|
38 | 38 | #include <QSpinBox> |
|
39 | 39 | #include <QCheckBox> |
|
40 | 40 | #include <QGroupBox> |
|
41 | 41 | #include <QLabel> |
|
42 | 42 | #include <QTime> |
|
43 | 43 | |
|
44 | 44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
45 | 45 | QWidget(parent), |
|
46 | 46 | m_listCount(3), |
|
47 | 47 | m_valueMax(10), |
|
48 | 48 | m_valueCount(7), |
|
49 | 49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
50 | 50 | m_themeComboBox(createThemeBox()), |
|
51 | 51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
52 | 52 | m_animatedComboBox(createAnimationBox()), |
|
53 | 53 | m_legendComboBox(createLegendBox()) |
|
54 | 54 | { |
|
55 | 55 | connectSignals(); |
|
56 | 56 | // create layout |
|
57 | 57 | QGridLayout* baseLayout = new QGridLayout(); |
|
58 | 58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
59 | 59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
60 | 60 | settingsLayout->addWidget(m_themeComboBox); |
|
61 | 61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
62 | 62 | settingsLayout->addWidget(m_animatedComboBox); |
|
63 | 63 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
64 | 64 | settingsLayout->addWidget(m_legendComboBox); |
|
65 | 65 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
66 | 66 | settingsLayout->addStretch(); |
|
67 | 67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
68 | 68 | |
|
69 | 69 | //create charts |
|
70 | 70 | |
|
71 | 71 | QChartView *chartView; |
|
72 | 72 | |
|
73 | 73 | chartView = new QChartView(createAreaChart()); |
|
74 | 74 | baseLayout->addWidget(chartView, 1, 0); |
|
75 | 75 | m_charts << chartView; |
|
76 | 76 | |
|
77 | 77 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
78 | 78 | baseLayout->addWidget(chartView, 1, 1); |
|
79 | 79 | m_charts << chartView; |
|
80 | 80 | |
|
81 | 81 | chartView = new QChartView(createLineChart()); |
|
82 | 82 | baseLayout->addWidget(chartView, 1, 2); |
|
83 | 83 | m_charts << chartView; |
|
84 | 84 | |
|
85 | 85 | chartView = new QChartView(createPieChart()); |
|
86 | 86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
87 | 87 | baseLayout->addWidget(chartView, 2, 0); |
|
88 | 88 | m_charts << chartView; |
|
89 | 89 | |
|
90 | 90 | chartView = new QChartView(createSplineChart()); |
|
91 | 91 | baseLayout->addWidget(chartView, 2, 1); |
|
92 | 92 | m_charts << chartView; |
|
93 | 93 | |
|
94 | 94 | chartView = new QChartView(createScatterChart()); |
|
95 | 95 | baseLayout->addWidget(chartView, 2, 2); |
|
96 | 96 | m_charts << chartView; |
|
97 | 97 | |
|
98 | 98 | setLayout(baseLayout); |
|
99 | 99 | |
|
100 | 100 | // Set defaults |
|
101 | 101 | m_antialiasCheckBox->setChecked(true); |
|
102 | 102 | updateUI(); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | ThemeWidget::~ThemeWidget() |
|
106 | 106 | { |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | void ThemeWidget::connectSignals() |
|
110 | 110 | { |
|
111 | 111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
112 | 112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
113 | 113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | 114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
118 | 118 | { |
|
119 | 119 | DataTable dataTable; |
|
120 | 120 | |
|
121 | 121 | // set seed for random stuff |
|
122 | 122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
123 | 123 | |
|
124 | 124 | // generate random data |
|
125 | 125 | for (int i(0); i < listCount; i++) { |
|
126 | 126 | DataList dataList; |
|
127 | 127 | qreal yValue(0); |
|
128 | 128 | for (int j(0); j < valueCount; j++) { |
|
129 | 129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
130 | 130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
131 | 131 | yValue); |
|
132 | 132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
133 | 133 | dataList << Data(value, label); |
|
134 | 134 | } |
|
135 | 135 | dataTable << dataList; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | return dataTable; |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | QComboBox* ThemeWidget::createThemeBox() const |
|
142 | 142 | { |
|
143 | 143 | // settings layout |
|
144 | 144 | QComboBox* themeComboBox = new QComboBox(); |
|
145 | 145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
146 | 146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
147 | 147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
148 | 148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
149 | 149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
150 | 150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
151 | 151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
152 | 152 | return themeComboBox; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | QComboBox* ThemeWidget::createAnimationBox() const |
|
156 | 156 | { |
|
157 | 157 | // settings layout |
|
158 | 158 | QComboBox* animationComboBox = new QComboBox(); |
|
159 | 159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
160 | 160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
161 | 161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
162 | 162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
163 | 163 | return animationComboBox; |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QComboBox* ThemeWidget::createLegendBox() const |
|
167 | 167 | { |
|
168 | 168 | QComboBox* legendComboBox = new QComboBox(); |
|
169 | 169 | legendComboBox->addItem("No Legend ", 0); |
|
170 | 170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
171 | 171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
172 | 172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
173 | 173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
174 | 174 | return legendComboBox; |
|
175 | 175 | } |
|
176 | 176 | |
|
177 | 177 | QChart* ThemeWidget::createAreaChart() const |
|
178 | 178 | { |
|
179 | 179 | QChart *chart = new QChart(); |
|
180 | 180 | chart->axisX()->setNiceNumbersEnabled(true); |
|
181 | 181 | chart->axisY()->setNiceNumbersEnabled(true); |
|
182 | 182 | chart->setTitle("Area chart"); |
|
183 | 183 | |
|
184 | 184 | // The lower series initialized to zero values |
|
185 | 185 | QLineSeries *lowerSeries = 0; |
|
186 | 186 | QString name("Series "); |
|
187 | 187 | int nameIndex = 0; |
|
188 | 188 | for (int i(0); i < m_dataTable.count(); i++) { |
|
189 | 189 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
190 | 190 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
191 | 191 | Data data = m_dataTable[i].at(j); |
|
192 | 192 | if (lowerSeries){ |
|
193 | 193 | const QList<QPointF>& points = lowerSeries->points(); |
|
194 | 194 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
195 | 195 | }else |
|
196 | 196 | upperSeries->append(QPointF(j, data.first.y())); |
|
197 | 197 | } |
|
198 | 198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
199 | 199 | area->setName(name + QString::number(nameIndex)); |
|
200 | 200 | nameIndex++; |
|
201 | 201 | chart->addSeries(area); |
|
202 | 202 | lowerSeries = upperSeries; |
|
203 | 203 | } |
|
204 | 204 | |
|
205 | 205 | return chart; |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
209 | 209 | { |
|
210 | 210 | QChart* chart = new QChart(); |
|
211 | 211 | chart->axisX()->setNiceNumbersEnabled(true); |
|
212 | 212 | chart->axisY()->setNiceNumbersEnabled(true); |
|
213 | 213 | chart->setTitle("Bar chart"); |
|
214 | 214 | |
|
215 | 215 | QBarCategories categories; |
|
216 | 216 | for (int i(0); i < valueCount; i++) |
|
217 | 217 | categories << QString::number(i); |
|
218 | 218 | |
|
219 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
|
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
|
220 | series->setCategories(categories); | |
|
220 | 221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | 222 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
222 | 223 | foreach (Data data, m_dataTable[i]) |
|
223 | 224 | *set << data.first.y(); |
|
224 | 225 | series->appendBarSet(set); |
|
225 | 226 | } |
|
226 | 227 | chart->addSeries(series); |
|
227 | 228 | |
|
228 | 229 | return chart; |
|
229 | 230 | } |
|
230 | 231 | |
|
231 | 232 | QChart* ThemeWidget::createLineChart() const |
|
232 | 233 | { |
|
233 | 234 | QChart* chart = new QChart(); |
|
234 | 235 | chart->axisX()->setNiceNumbersEnabled(true); |
|
235 | 236 | chart->axisY()->setNiceNumbersEnabled(true); |
|
236 | 237 | chart->setTitle("Line chart"); |
|
237 | 238 | |
|
238 | 239 | QString name("Series "); |
|
239 | 240 | int nameIndex = 0; |
|
240 | 241 | foreach (DataList list, m_dataTable) { |
|
241 | 242 | QLineSeries *series = new QLineSeries(chart); |
|
242 | 243 | foreach (Data data, list) |
|
243 | 244 | series->append(data.first); |
|
244 | 245 | series->setName(name + QString::number(nameIndex)); |
|
245 | 246 | nameIndex++; |
|
246 | 247 | chart->addSeries(series); |
|
247 | 248 | } |
|
248 | 249 | |
|
249 | 250 | return chart; |
|
250 | 251 | } |
|
251 | 252 | |
|
252 | 253 | QChart* ThemeWidget::createPieChart() const |
|
253 | 254 | { |
|
254 | 255 | QChart* chart = new QChart(); |
|
255 | 256 | chart->setTitle("Pie chart"); |
|
256 | 257 | |
|
257 | 258 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
258 | 259 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
259 | 260 | QPieSeries *series = new QPieSeries(chart); |
|
260 | 261 | foreach (Data data, m_dataTable[i]) { |
|
261 | 262 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
262 | 263 | if (data == m_dataTable[i].first()) { |
|
263 | 264 | slice->setLabelVisible(); |
|
264 | 265 | slice->setExploded(); |
|
265 | 266 | } |
|
266 | 267 | } |
|
267 | 268 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
268 | 269 | series->setPieSize(pieSize); |
|
269 | 270 | series->setHorizontalPosition(hPos); |
|
270 | 271 | series->setVerticalPosition(0.5); |
|
271 | 272 | chart->addSeries(series); |
|
272 | 273 | } |
|
273 | 274 | |
|
274 | 275 | return chart; |
|
275 | 276 | } |
|
276 | 277 | |
|
277 | 278 | QChart* ThemeWidget::createSplineChart() const |
|
278 | 279 | { // spine chart |
|
279 | 280 | QChart* chart = new QChart(); |
|
280 | 281 | chart->axisX()->setNiceNumbersEnabled(true); |
|
281 | 282 | chart->axisY()->setNiceNumbersEnabled(true); |
|
282 | 283 | chart->setTitle("Spline chart"); |
|
283 | 284 | QString name("Series "); |
|
284 | 285 | int nameIndex = 0; |
|
285 | 286 | foreach (DataList list, m_dataTable) { |
|
286 | 287 | QSplineSeries *series = new QSplineSeries(chart); |
|
287 | 288 | foreach (Data data, list) |
|
288 | 289 | series->append(data.first); |
|
289 | 290 | series->setName(name + QString::number(nameIndex)); |
|
290 | 291 | nameIndex++; |
|
291 | 292 | chart->addSeries(series); |
|
292 | 293 | } |
|
293 | 294 | return chart; |
|
294 | 295 | } |
|
295 | 296 | |
|
296 | 297 | QChart* ThemeWidget::createScatterChart() const |
|
297 | 298 | { // scatter chart |
|
298 | 299 | QChart* chart = new QChart(); |
|
299 | 300 | chart->axisX()->setNiceNumbersEnabled(true); |
|
300 | 301 | chart->axisY()->setNiceNumbersEnabled(true); |
|
301 | 302 | chart->setTitle("Scatter chart"); |
|
302 | 303 | QString name("Series "); |
|
303 | 304 | int nameIndex = 0; |
|
304 | 305 | foreach (DataList list, m_dataTable) { |
|
305 | 306 | QScatterSeries *series = new QScatterSeries(chart); |
|
306 | 307 | foreach (Data data, list) |
|
307 | 308 | series->append(data.first); |
|
308 | 309 | series->setName(name + QString::number(nameIndex)); |
|
309 | 310 | nameIndex++; |
|
310 | 311 | chart->addSeries(series); |
|
311 | 312 | } |
|
312 | 313 | return chart; |
|
313 | 314 | } |
|
314 | 315 | |
|
315 | 316 | void ThemeWidget::updateUI() |
|
316 | 317 | { |
|
317 | 318 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
318 | 319 | |
|
319 | 320 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
320 | 321 | foreach (QChartView *chartView, m_charts) |
|
321 | 322 | chartView->chart()->setTheme(theme); |
|
322 | 323 | |
|
323 | 324 | QPalette pal = window()->palette(); |
|
324 | 325 | if (theme == QChart::ChartThemeLight) { |
|
325 | 326 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
326 | 327 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
327 | 328 | } else if (theme == QChart::ChartThemeDark) { |
|
328 | 329 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
329 | 330 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
330 | 331 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
331 | 332 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
332 | 333 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
333 | 334 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
334 | 335 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
335 | 336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
336 | 337 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
337 | 338 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
338 | 339 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
339 | 340 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
340 | 341 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
341 | 342 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
342 | 343 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
343 | 344 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
344 | 345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
345 | 346 | } else { |
|
346 | 347 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
347 | 348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
348 | 349 | } |
|
349 | 350 | window()->setPalette(pal); |
|
350 | 351 | } |
|
351 | 352 | |
|
352 | 353 | bool checked = m_antialiasCheckBox->isChecked(); |
|
353 | 354 | foreach (QChartView *chart, m_charts) |
|
354 | 355 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
355 | 356 | |
|
356 | 357 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
357 | 358 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
358 | 359 | foreach (QChartView *chartView, m_charts) |
|
359 | 360 | chartView->chart()->setAnimationOptions(options); |
|
360 | 361 | } |
|
361 | 362 | |
|
362 | 363 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
363 | 364 | |
|
364 | 365 | if (!alignment) { |
|
365 | 366 | foreach (QChartView *chartView, m_charts) { |
|
366 | 367 | chartView->chart()->legend()->hide(); |
|
367 | 368 | } |
|
368 | 369 | } else { |
|
369 | 370 | foreach (QChartView *chartView, m_charts) { |
|
370 | 371 | chartView->chart()->legend()->setAlignment(alignment); |
|
371 | 372 | chartView->chart()->legend()->show(); |
|
372 | 373 | } |
|
373 | 374 | } |
|
374 | 375 | } |
|
375 | 376 |
@@ -1,52 +1,47 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | anchors.fill: parent |
|
26 | 26 | |
|
27 | 27 | Chart { |
|
28 | 28 | title: "Car brand shares in Finland" |
|
29 | 29 | anchors.fill: parent |
|
30 | 30 | theme: Chart.ChartThemeLight |
|
31 | 31 | legend: Chart.LegendBottom |
|
32 | 32 | |
|
33 | 33 | PieSeries { |
|
34 |
horizontalPosition: 0. |
|
|
35 |
verticalPosition: 0. |
|
|
36 |
size: 0. |
|
|
34 | horizontalPosition: 0.5 | |
|
35 | verticalPosition: 0.5 | |
|
36 | size: 0.7 | |
|
37 | 37 | slices: [ |
|
38 | 38 | PieSlice { label: "Volkswagen"; value: 13.5 }, |
|
39 | 39 | PieSlice { label: "Toyota"; value: 10.9 }, |
|
40 | 40 | PieSlice { label: "Ford"; value: 8.6 }, |
|
41 | 41 | PieSlice { label: "Skoda"; value: 8.2 }, |
|
42 | 42 | PieSlice { label: "Volvo"; value: 6.8 }, |
|
43 | 43 | PieSlice { label: "Others"; value: 52.0 } |
|
44 | 44 | ] |
|
45 | 45 | } |
|
46 | ||
|
47 | BarSeries { | |
|
48 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
49 | // data implementation missing | |
|
50 | } | |
|
51 | 46 | } |
|
52 | 47 | } |
@@ -1,129 +1,129 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | anchors.fill: parent |
|
26 | 26 | |
|
27 | 27 | Chart { |
|
28 | 28 | title: "NHL All-Star Team Players" |
|
29 | 29 | anchors.fill: parent |
|
30 | 30 | theme: Chart.ChartThemeHighContrast |
|
31 | 31 | legend: Chart.LegendTop |
|
32 | 32 | |
|
33 | 33 | AreaSeries { |
|
34 |
name: " |
|
|
34 | name: "Swedish" | |
|
35 | 35 | points: [ |
|
36 |
XyPoint { x: 0; y: |
|
|
37 |
XyPoint { x: 1; y: |
|
|
38 |
XyPoint { x: 2; y: |
|
|
39 |
XyPoint { x: 3; y: |
|
|
40 |
XyPoint { x: 4; y: |
|
|
36 | XyPoint { x: 0; y: 1 }, | |
|
37 | XyPoint { x: 1; y: 1 }, | |
|
38 | XyPoint { x: 2; y: 3 }, | |
|
39 | XyPoint { x: 3; y: 3 }, | |
|
40 | XyPoint { x: 4; y: 2 }, | |
|
41 | 41 | XyPoint { x: 5; y: 0 }, |
|
42 |
XyPoint { x: 6; y: |
|
|
43 |
XyPoint { x: 7; y: |
|
|
44 |
XyPoint { x: 8; y: |
|
|
45 |
XyPoint { x: 9; y: |
|
|
46 |
XyPoint { x: 10; y: |
|
|
47 |
XyPoint { x: 11; y: |
|
|
42 | XyPoint { x: 6; y: 2 }, | |
|
43 | XyPoint { x: 7; y: 1 }, | |
|
44 | XyPoint { x: 8; y: 2 }, | |
|
45 | XyPoint { x: 9; y: 1 }, | |
|
46 | XyPoint { x: 10; y: 3 }, | |
|
47 | XyPoint { x: 11; y: 3 } | |
|
48 | 48 | ] |
|
49 | 49 | lowerPoints: [ |
|
50 | 50 | XyPoint { x: 0; y: 0 }, |
|
51 | 51 | XyPoint { x: 1; y: 0 }, |
|
52 | 52 | XyPoint { x: 2; y: 0 }, |
|
53 | 53 | XyPoint { x: 3; y: 0 }, |
|
54 | 54 | XyPoint { x: 4; y: 0 }, |
|
55 | 55 | XyPoint { x: 5; y: 0 }, |
|
56 | 56 | XyPoint { x: 6; y: 0 }, |
|
57 | 57 | XyPoint { x: 7; y: 0 }, |
|
58 | 58 | XyPoint { x: 8; y: 0 }, |
|
59 | 59 | XyPoint { x: 9; y: 0 }, |
|
60 | 60 | XyPoint { x: 10; y: 0 }, |
|
61 | 61 | XyPoint { x: 11; y: 0 } |
|
62 | 62 | ] |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | AreaSeries { |
|
66 | 66 | name: "Russian" |
|
67 | 67 | points: [ |
|
68 | 68 | XyPoint { x: 0; y: 1 }, |
|
69 | 69 | XyPoint { x: 1; y: 1 }, |
|
70 | 70 | XyPoint { x: 2; y: 1 }, |
|
71 | 71 | XyPoint { x: 3; y: 1 }, |
|
72 | 72 | XyPoint { x: 4; y: 1 }, |
|
73 | 73 | XyPoint { x: 5; y: 0 }, |
|
74 | 74 | XyPoint { x: 6; y: 1 }, |
|
75 | 75 | XyPoint { x: 7; y: 1 }, |
|
76 | 76 | XyPoint { x: 8; y: 4 }, |
|
77 | 77 | XyPoint { x: 9; y: 3 }, |
|
78 | 78 | XyPoint { x: 10; y: 2 }, |
|
79 | 79 | XyPoint { x: 11; y: 1 } |
|
80 | 80 | ] |
|
81 | 81 | lowerPoints: [ |
|
82 | 82 | XyPoint { x: 0; y: 0 }, |
|
83 | 83 | XyPoint { x: 1; y: 0 }, |
|
84 | 84 | XyPoint { x: 2; y: 0 }, |
|
85 | 85 | XyPoint { x: 3; y: 0 }, |
|
86 | 86 | XyPoint { x: 4; y: 0 }, |
|
87 | 87 | XyPoint { x: 5; y: 0 }, |
|
88 | 88 | XyPoint { x: 6; y: 0 }, |
|
89 | 89 | XyPoint { x: 7; y: 0 }, |
|
90 | 90 | XyPoint { x: 8; y: 0 }, |
|
91 | 91 | XyPoint { x: 9; y: 0 }, |
|
92 | 92 | XyPoint { x: 10; y: 0 }, |
|
93 | 93 | XyPoint { x: 11; y: 0 } |
|
94 | 94 | ] |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | AreaSeries { |
|
98 |
name: " |
|
|
98 | name: "Finnish" | |
|
99 | 99 | points: [ |
|
100 |
XyPoint { x: 0; y: |
|
|
101 |
XyPoint { x: 1; y: |
|
|
102 |
XyPoint { x: 2; y: |
|
|
103 |
XyPoint { x: 3; y: |
|
|
104 |
XyPoint { x: 4; y: |
|
|
100 | XyPoint { x: 0; y: 0 }, | |
|
101 | XyPoint { x: 1; y: 0 }, | |
|
102 | XyPoint { x: 2; y: 0 }, | |
|
103 | XyPoint { x: 3; y: 0 }, | |
|
104 | XyPoint { x: 4; y: 0 }, | |
|
105 | 105 | XyPoint { x: 5; y: 0 }, |
|
106 |
XyPoint { x: 6; y: |
|
|
107 |
XyPoint { x: 7; y: |
|
|
108 |
XyPoint { x: 8; y: |
|
|
109 |
XyPoint { x: 9; y: |
|
|
110 |
XyPoint { x: 10; y: |
|
|
111 |
XyPoint { x: 11; y: |
|
|
106 | XyPoint { x: 6; y: 1 }, | |
|
107 | XyPoint { x: 7; y: 0 }, | |
|
108 | XyPoint { x: 8; y: 0 }, | |
|
109 | XyPoint { x: 9; y: 0 }, | |
|
110 | XyPoint { x: 10; y: 0 }, | |
|
111 | XyPoint { x: 11; y: 1 } | |
|
112 | 112 | ] |
|
113 | 113 | lowerPoints: [ |
|
114 | 114 | XyPoint { x: 0; y: 0 }, |
|
115 | 115 | XyPoint { x: 1; y: 0 }, |
|
116 | 116 | XyPoint { x: 2; y: 0 }, |
|
117 | 117 | XyPoint { x: 3; y: 0 }, |
|
118 | 118 | XyPoint { x: 4; y: 0 }, |
|
119 | 119 | XyPoint { x: 5; y: 0 }, |
|
120 | 120 | XyPoint { x: 6; y: 0 }, |
|
121 | 121 | XyPoint { x: 7; y: 0 }, |
|
122 | 122 | XyPoint { x: 8; y: 0 }, |
|
123 | 123 | XyPoint { x: 9; y: 0 }, |
|
124 | 124 | XyPoint { x: 10; y: 0 }, |
|
125 | 125 | XyPoint { x: 11; y: 0 } |
|
126 | 126 | ] |
|
127 | 127 | } |
|
128 | 128 | } |
|
129 | 129 | } |
@@ -1,53 +1,53 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | width: parent.width |
|
26 | 26 | height: parent.height |
|
27 | 27 | property int __viewNumber: 0 |
|
28 | 28 | |
|
29 | 29 | Timer { |
|
30 | 30 | id: timer |
|
31 | 31 | running: true |
|
32 | 32 | repeat: true |
|
33 | 33 | interval: 5000 |
|
34 | 34 | triggeredOnStart: false |
|
35 | 35 | onTriggered: { |
|
36 | 36 | __viewNumber++; |
|
37 | 37 | } |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | Loader { |
|
41 | 41 | id: loader |
|
42 | 42 | anchors.fill: parent |
|
43 |
source: "View" + (__viewNumber % |
|
|
43 | source: "View" + (__viewNumber % 5 + 1) + ".qml"; | |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | MouseArea { |
|
47 | 47 | anchors.fill: parent |
|
48 | 48 | onClicked: { |
|
49 | 49 | timer.restart(); |
|
50 | 50 | __viewNumber++; |
|
51 | 51 | } |
|
52 | 52 | } |
|
53 | 53 | } |
@@ -1,10 +1,11 | |||
|
1 | 1 | <RCC> |
|
2 | 2 | <qresource prefix="/"> |
|
3 | 3 | <file>qml/qmlchart/loader.qml</file> |
|
4 | 4 | <file>qml/qmlchart/main.qml</file> |
|
5 | 5 | <file>qml/qmlchart/View1.qml</file> |
|
6 | 6 | <file>qml/qmlchart/View2.qml</file> |
|
7 | 7 | <file>qml/qmlchart/View3.qml</file> |
|
8 | 8 | <file>qml/qmlchart/View4.qml</file> |
|
9 | <file>qml/qmlchart/View5.qml</file> | |
|
9 | 10 | </qresource> |
|
10 | 11 | </RCC> |
@@ -1,87 +1,88 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QBarSeries> |
|
25 | 25 | #include <QBarSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | int main(int argc, char *argv[]) |
|
31 | 31 | { |
|
32 | 32 | QApplication a(argc, argv); |
|
33 | 33 | |
|
34 | 34 | //![1] |
|
35 | 35 | QBarCategories categories; |
|
36 | 36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
37 | 37 | //![1] |
|
38 | 38 | |
|
39 | 39 | //![2] |
|
40 | 40 | QBarSet *set0 = new QBarSet("Jane"); |
|
41 | 41 | QBarSet *set1 = new QBarSet("John"); |
|
42 | 42 | QBarSet *set2 = new QBarSet("Axel"); |
|
43 | 43 | QBarSet *set3 = new QBarSet("Mary"); |
|
44 | 44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
45 | 45 | |
|
46 | 46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
47 | 47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
48 | 48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
49 | 49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
50 | 50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QBarSeries* series = new QBarSeries( |
|
|
54 | QBarSeries* series = new QBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
|
58 | 59 | series->appendBarSet(set3); |
|
59 | 60 | series->appendBarSet(set4); |
|
60 | 61 | //![3] |
|
61 | 62 | |
|
62 | 63 | //![4] |
|
63 | 64 | QChart* chart = new QChart(); |
|
64 | 65 | chart->addSeries(series); |
|
65 | 66 | chart->setTitle("Simple barchart example"); |
|
66 | 67 | //![4] |
|
67 | 68 | |
|
68 | 69 | //![5] |
|
69 | 70 | chart->legend()->setVisible(true); |
|
70 | 71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | 72 | chart->axisY()->setNiceNumbersEnabled(true); |
|
72 | 73 | //![5] |
|
73 | 74 | |
|
74 | 75 | //![6] |
|
75 | 76 | QChartView* chartView = new QChartView(chart); |
|
76 | 77 | chartView->setRenderHint(QPainter::Antialiasing); |
|
77 | 78 | //![6] |
|
78 | 79 | |
|
79 | 80 | //![7] |
|
80 | 81 | QMainWindow window; |
|
81 | 82 | window.setCentralWidget(chartView); |
|
82 | 83 | window.resize(400, 300); |
|
83 | 84 | window.show(); |
|
84 | 85 | //![7] |
|
85 | 86 | |
|
86 | 87 | return a.exec(); |
|
87 | 88 | } |
@@ -1,87 +1,88 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QPercentBarSeries> |
|
25 | 25 | #include <QBarSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | int main(int argc, char *argv[]) |
|
31 | 31 | { |
|
32 | 32 | QApplication a(argc, argv); |
|
33 | 33 | |
|
34 | 34 | //![1] |
|
35 | 35 | QBarCategories categories; |
|
36 | 36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
37 | 37 | //![1] |
|
38 | 38 | |
|
39 | 39 | //![2] |
|
40 | 40 | QBarSet *set0 = new QBarSet("Jane"); |
|
41 | 41 | QBarSet *set1 = new QBarSet("John"); |
|
42 | 42 | QBarSet *set2 = new QBarSet("Axel"); |
|
43 | 43 | QBarSet *set3 = new QBarSet("Mary"); |
|
44 | 44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
45 | 45 | |
|
46 | 46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
47 | 47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
48 | 48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
49 | 49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
50 | 50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QPercentBarSeries* series = new QPercentBarSeries( |
|
|
54 | QPercentBarSeries* series = new QPercentBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
|
58 | 59 | series->appendBarSet(set3); |
|
59 | 60 | series->appendBarSet(set4); |
|
60 | 61 | //![3] |
|
61 | 62 | |
|
62 | 63 | //![4] |
|
63 | 64 | QChart* chart = new QChart(); |
|
64 | 65 | chart->addSeries(series); |
|
65 | 66 | chart->setTitle("Simple percentbarchart example"); |
|
66 | 67 | //![4] |
|
67 | 68 | |
|
68 | 69 | //![5] |
|
69 | 70 | chart->legend()->setVisible(true); |
|
70 | 71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | 72 | //![5] |
|
72 | 73 | |
|
73 | 74 | //![6] |
|
74 | 75 | QChartView* chartView = new QChartView(chart); |
|
75 | 76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
76 | 77 | //![6] |
|
77 | 78 | |
|
78 | 79 | //![7] |
|
79 | 80 | QMainWindow window; |
|
80 | 81 | window.setCentralWidget(chartView); |
|
81 | 82 | window.resize(400, 300); |
|
82 | 83 | window.show(); |
|
83 | 84 | //![7] |
|
84 | 85 | |
|
85 | 86 | return a.exec(); |
|
86 | 87 | } |
|
87 | 88 |
@@ -1,88 +1,89 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | 24 | #include <QStackedBarSeries> |
|
25 | 25 | #include <QBarSet> |
|
26 | 26 | #include <QLegend> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | int main(int argc, char *argv[]) |
|
31 | 31 | { |
|
32 | 32 | QApplication a(argc, argv); |
|
33 | 33 | |
|
34 | 34 | //![1] |
|
35 | 35 | QBarCategories categories; |
|
36 | 36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
37 | 37 | //![1] |
|
38 | 38 | |
|
39 | 39 | //![2] |
|
40 | 40 | QBarSet *set0 = new QBarSet("Jane"); |
|
41 | 41 | QBarSet *set1 = new QBarSet("John"); |
|
42 | 42 | QBarSet *set2 = new QBarSet("Axel"); |
|
43 | 43 | QBarSet *set3 = new QBarSet("Mary"); |
|
44 | 44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
45 | 45 | |
|
46 | 46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
47 | 47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
48 | 48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
49 | 49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
50 | 50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
51 | 51 | //![2] |
|
52 | 52 | |
|
53 | 53 | //![3] |
|
54 |
QStackedBarSeries* series = new QStackedBarSeries( |
|
|
54 | QStackedBarSeries* series = new QStackedBarSeries(); | |
|
55 | series->setCategories(categories); | |
|
55 | 56 | series->appendBarSet(set0); |
|
56 | 57 | series->appendBarSet(set1); |
|
57 | 58 | series->appendBarSet(set2); |
|
58 | 59 | series->appendBarSet(set3); |
|
59 | 60 | series->appendBarSet(set4); |
|
60 | 61 | //![3] |
|
61 | 62 | |
|
62 | 63 | //![4] |
|
63 | 64 | QChart* chart = new QChart(); |
|
64 | 65 | chart->addSeries(series); |
|
65 | 66 | chart->setTitle("Simple stackedbarchart example"); |
|
66 | 67 | //![4] |
|
67 | 68 | |
|
68 | 69 | //![5] |
|
69 | 70 | chart->legend()->setVisible(true); |
|
70 | 71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | 72 | chart->axisY()->setNiceNumbersEnabled(true); |
|
72 | 73 | //![5] |
|
73 | 74 | |
|
74 | 75 | //![6] |
|
75 | 76 | QChartView* chartView = new QChartView(chart); |
|
76 | 77 | chartView->setRenderHint(QPainter::Antialiasing); |
|
77 | 78 | //![6] |
|
78 | 79 | |
|
79 | 80 | //![7] |
|
80 | 81 | QMainWindow window; |
|
81 | 82 | window.setCentralWidget(chartView); |
|
82 | 83 | window.resize(400, 300); |
|
83 | 84 | window.show(); |
|
84 | 85 | //![7] |
|
85 | 86 | |
|
86 | 87 | return a.exec(); |
|
87 | 88 | } |
|
88 | 89 |
@@ -1,40 +1,41 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "drilldownseries.h" |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) |
|
26 |
: QStackedBarSeries( |
|
|
26 | : QStackedBarSeries(parent) | |
|
27 | 27 | { |
|
28 | setCategories(categories); | |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
|
31 | 32 | { |
|
32 | 33 | mDrilldownSeries[category] = drilldownSeries; |
|
33 | 34 | } |
|
34 | 35 | |
|
35 | 36 | DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(QString category) |
|
36 | 37 | { |
|
37 | 38 | return mDrilldownSeries[category]; |
|
38 | 39 | } |
|
39 | 40 | |
|
40 | 41 | #include "moc_drilldownseries.cpp" |
@@ -1,70 +1,65 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativeareaseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qlineseries.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | DeclarativeAreaSeries::DeclarativeAreaSeries(QObject *parent) : |
|
29 | 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 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendPoints); |
|
41 | 36 | } |
|
42 | 37 | |
|
43 | 38 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeAreaSeries::lowerPoints() |
|
44 | 39 | { |
|
45 | 40 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeAreaSeries::appendLowerPoints); |
|
46 | 41 | } |
|
47 | 42 | |
|
48 | 43 | void DeclarativeAreaSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
49 | 44 | DeclarativeXyPoint *element) |
|
50 | 45 | { |
|
51 | 46 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); |
|
52 | 47 | if (series) { |
|
53 | 48 | QLineSeries *upper = series->upperSeries(); |
|
54 | 49 | upper->append(element->x(), element->y()); |
|
55 | 50 | } |
|
56 | 51 | } |
|
57 | 52 | |
|
58 | 53 | void DeclarativeAreaSeries::appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
59 | 54 | DeclarativeXyPoint *element) |
|
60 | 55 | { |
|
61 | 56 | QAreaSeries *series = qobject_cast<QAreaSeries *>(list->object); |
|
62 | 57 | if (series) { |
|
63 | 58 | QLineSeries *lower = series->lowerSeries(); |
|
64 | 59 | lower->append(element->x(), element->y()); |
|
65 | 60 | } |
|
66 | 61 | } |
|
67 | 62 | |
|
68 | 63 | #include "moc_declarativeareaseries.cpp" |
|
69 | 64 | |
|
70 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,52 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVEAREASERIES_H |
|
22 | 22 | #define DECLARATIVEAREASERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qareaseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | class DeclarativeAreaSeries : public QAreaSeries, public DeclarativeXySeries |
|
31 | 31 | { |
|
32 | 32 | Q_OBJECT |
|
33 | 33 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
34 | 34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints READ lowerPoints) |
|
35 | 35 | |
|
36 | 36 | public: |
|
37 | 37 | explicit DeclarativeAreaSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | QDeclarativeListProperty<DeclarativeXyPoint> lowerPoints(); |
|
43 | 42 | |
|
44 | 43 | public Q_SLOTS: |
|
45 | 44 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
46 | 45 | DeclarativeXyPoint *element); |
|
47 | 46 | static void appendLowerPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
48 | 47 | DeclarativeXyPoint *element); |
|
49 | 48 | }; |
|
50 | 49 | |
|
51 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | 51 | |
|
53 | 52 | #endif // DECLARATIVEAREASERIES_H |
@@ -1,79 +1,81 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativebarseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qbarseries.h" |
|
25 | 25 | #include "qbarset.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
30 | 30 | QDeclarativeItem(parent) |
|
31 | 31 | { |
|
32 | 32 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | void DeclarativeBarSeries::componentComplete() |
|
36 | 36 | { |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
|
40 | 40 | { |
|
41 | 41 | m_categories = categories; |
|
42 | 42 | |
|
43 | 43 | if (m_series) { |
|
44 | 44 | delete m_series; |
|
45 | 45 | m_series = 0; |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
49 | 49 | if (declarativeChart) { |
|
50 | 50 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
51 | 51 | Q_ASSERT(chart); |
|
52 | 52 | |
|
53 | m_series = new QBarSeries(m_categories); | |
|
53 | // m_series = new QBarSeries(m_categories); | |
|
54 | m_series = new QBarSeries(); | |
|
55 | m_series->setCategories(m_categories); | |
|
54 | 56 | |
|
55 | 57 | // TODO: use data from model |
|
56 | 58 | QBarSet *set0 = new QBarSet("Bub"); |
|
57 | 59 | QBarSet *set1 = new QBarSet("Bob"); |
|
58 | 60 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
59 | 61 | |
|
60 | 62 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
61 | 63 | *set1 << 5 << 1 << 2 << 4 << 1 << 7; |
|
62 | 64 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
63 | 65 | |
|
64 | 66 | m_series->appendBarSet(set0); |
|
65 | 67 | m_series->appendBarSet(set1); |
|
66 | 68 | m_series->appendBarSet(set2); |
|
67 | 69 | |
|
68 | 70 | chart->addSeries(m_series); |
|
69 | 71 | } |
|
70 | 72 | } |
|
71 | 73 | |
|
72 | 74 | QStringList DeclarativeBarSeries::barCategories() |
|
73 | 75 | { |
|
74 | 76 | return m_categories; |
|
75 | 77 | } |
|
76 | 78 | |
|
77 | 79 | #include "moc_declarativebarseries.cpp" |
|
78 | 80 | |
|
79 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,114 +1,135 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativechart.h" |
|
22 | #include "declarativepieseries.h" | |
|
22 | 23 | #include <QPainter> |
|
23 | 24 | |
|
24 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 26 | |
|
26 | 27 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
27 | 28 | : QDeclarativeItem(parent), |
|
28 | 29 | m_chart(new QChart(this)), |
|
29 | 30 | m_legend(LegendDisabled) |
|
30 | 31 | { |
|
31 | 32 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
32 | 33 | } |
|
33 | 34 | |
|
34 | 35 | DeclarativeChart::~DeclarativeChart() |
|
35 | 36 | { |
|
36 | 37 | delete m_chart; |
|
37 | 38 | } |
|
38 | 39 | |
|
40 | void DeclarativeChart::childEvent(QChildEvent *event) | |
|
41 | { | |
|
42 | if (event->type() == QEvent::ChildAdded) { | |
|
43 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
|
44 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
|
45 | } | |
|
46 | } | |
|
47 | } | |
|
48 | ||
|
49 | void DeclarativeChart::componentComplete() | |
|
50 | { | |
|
51 | foreach(QObject *child, children()) { | |
|
52 | if (qobject_cast<QAbstractSeries *>(child)) { | |
|
53 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
|
54 | } | |
|
55 | } | |
|
56 | ||
|
57 | QDeclarativeItem::componentComplete(); | |
|
58 | } | |
|
59 | ||
|
39 | 60 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
40 | 61 | { |
|
41 | 62 | Q_UNUSED(oldGeometry) |
|
42 | 63 | |
|
43 | 64 | if (newGeometry.isValid()) { |
|
44 | 65 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
45 | 66 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
46 | 67 | } |
|
47 | 68 | } |
|
48 | 69 | } |
|
49 | 70 | |
|
50 | 71 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | 72 | { |
|
52 | 73 | Q_UNUSED(option) |
|
53 | 74 | Q_UNUSED(widget) |
|
54 | 75 | |
|
55 | 76 | // TODO: optimized? |
|
56 | 77 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
57 | 78 | } |
|
58 | 79 | |
|
59 | 80 | void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations) |
|
60 | 81 | { |
|
61 | 82 | m_chart->setAnimationOptions(animations); |
|
62 | 83 | } |
|
63 | 84 | |
|
64 | 85 | QChart::AnimationOption DeclarativeChart::animationOptions() |
|
65 | 86 | { |
|
66 | 87 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
67 | 88 | return QChart::AllAnimations; |
|
68 | 89 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
69 | 90 | return QChart::GridAxisAnimations; |
|
70 | 91 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
71 | 92 | return QChart::SeriesAnimations; |
|
72 | 93 | else |
|
73 | 94 | return QChart::NoAnimation; |
|
74 | 95 | } |
|
75 | 96 | |
|
76 | 97 | void DeclarativeChart::setLegend(ChartLegend legend) |
|
77 | 98 | { |
|
78 | 99 | if (legend != m_legend) { |
|
79 | 100 | m_legend = legend; |
|
80 | 101 | switch (m_legend) { |
|
81 | 102 | case LegendDisabled: |
|
82 | 103 | m_chart->legend()->setVisible(false); |
|
83 | 104 | break; |
|
84 | 105 | case LegendTop: |
|
85 | 106 | m_chart->legend()->setVisible(true); |
|
86 | 107 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); |
|
87 | 108 | break; |
|
88 | 109 | case LegendBottom: |
|
89 | 110 | m_chart->legend()->setVisible(true); |
|
90 | 111 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
91 | 112 | break; |
|
92 | 113 | case LegendLeft: |
|
93 | 114 | m_chart->legend()->setVisible(true); |
|
94 | 115 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); |
|
95 | 116 | break; |
|
96 | 117 | case LegendRight: |
|
97 | 118 | m_chart->legend()->setVisible(true); |
|
98 | 119 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); |
|
99 | 120 | break; |
|
100 | 121 | default: |
|
101 | 122 | m_chart->legend()->setVisible(false); |
|
102 | 123 | break; |
|
103 | 124 | } |
|
104 | 125 | } |
|
105 | 126 | } |
|
106 | 127 | |
|
107 | 128 | DeclarativeChart::ChartLegend DeclarativeChart::legend() |
|
108 | 129 | { |
|
109 | 130 | return m_legend; |
|
110 | 131 | } |
|
111 | 132 | |
|
112 | 133 | #include "moc_declarativechart.cpp" |
|
113 | 134 | |
|
114 | 135 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVECHART_H |
|
22 | 22 | #define DECLARATIVECHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QtCore/QtGlobal> |
|
25 | 25 | #include <QDeclarativeItem> |
|
26 | 26 | #include <qchart.h> |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | // TODO: Derive from QChart for easier definition of properties? |
|
31 | 31 | class DeclarativeChart : public QDeclarativeItem |
|
32 | 32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
33 | 33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
37 | 37 | Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions) |
|
38 | 38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
39 | 39 | Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend) |
|
40 | 40 | Q_ENUMS(ChartLegend) |
|
41 | 41 | |
|
42 | 42 | public: |
|
43 | 43 | enum ChartLegend { |
|
44 | 44 | LegendDisabled = 0, |
|
45 | 45 | LegendTop, |
|
46 | 46 | LegendBottom, |
|
47 | 47 | LegendLeft, |
|
48 | 48 | LegendRight |
|
49 | 49 | }; |
|
50 | 50 | |
|
51 | 51 | public: |
|
52 | 52 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
53 | 53 | ~DeclarativeChart(); |
|
54 | 54 | |
|
55 | 55 | public: // From QDeclarativeItem/QGraphicsItem |
|
56 | void childEvent(QChildEvent *event); | |
|
57 | void componentComplete(); | |
|
56 | 58 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
57 | 59 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
58 | 60 | |
|
59 | 61 | public: |
|
60 | 62 | void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);} |
|
61 | 63 | QChart::ChartTheme theme() {return m_chart->theme();} |
|
62 | 64 | void setAnimationOptions(QChart::AnimationOption animations); |
|
63 | 65 | QChart::AnimationOption animationOptions(); |
|
64 | 66 | void setTitle(QString title) {m_chart->setTitle(title);} |
|
65 | 67 | QString title() { return m_chart->title();} |
|
66 | 68 | void setLegend(ChartLegend legend); |
|
67 | 69 | ChartLegend legend(); |
|
68 | 70 | |
|
69 | 71 | public: |
|
70 | 72 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
71 | 73 | // multi inheritance, so we now have a QChart as a member instead |
|
72 | 74 | QChart *m_chart; |
|
73 | 75 | ChartLegend m_legend; |
|
74 | 76 | }; |
|
75 | 77 | |
|
76 | 78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | 79 | |
|
78 | 80 | #endif // DECLARATIVECHART_H |
@@ -1,45 +1,40 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativelineseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qlineseries.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) : |
|
29 | 29 | QLineSeries(parent) |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | QAbstractSeries *DeclarativeLineSeries::series() | |
|
34 | { | |
|
35 | return this; | |
|
36 | } | |
|
37 | ||
|
38 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
41 | 36 | } |
|
42 | 37 | |
|
43 | 38 | #include "moc_declarativelineseries.cpp" |
|
44 | 39 | |
|
45 | 40 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVELINESERIES_H |
|
22 | 22 | #define DECLARATIVELINESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qlineseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
35 | 35 | |
|
36 | 36 | public: |
|
37 | 37 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 | |
|
44 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 44 | |
|
46 | 45 | #endif // DECLARATIVELINESERIES_H |
@@ -1,62 +1,47 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativepieseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
28 |
QPieSeries(parent) |
|
|
29 | m_chart(0) | |
|
28 | QPieSeries(parent) | |
|
30 | 29 | { |
|
31 | 30 | } |
|
32 | 31 | |
|
33 | void DeclarativePieSeries::classBegin() | |
|
34 | { | |
|
35 | } | |
|
36 | ||
|
37 | void DeclarativePieSeries::componentComplete() | |
|
38 | { | |
|
39 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
|
40 | if (declarativeChart) { | |
|
41 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
|
42 | Q_ASSERT(chart); | |
|
43 | chart->addSeries(this); | |
|
44 | } | |
|
45 | } | |
|
46 | ||
|
47 | 32 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices() |
|
48 | 33 | { |
|
49 | 34 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice); |
|
50 | 35 | } |
|
51 | 36 | |
|
52 | 37 | void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list, |
|
53 | 38 | QPieSlice *slice) |
|
54 | 39 | { |
|
55 | 40 | DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object); |
|
56 | 41 | if (series) |
|
57 | 42 | series->append(slice->value(), slice->label()); |
|
58 | 43 | } |
|
59 | 44 | |
|
60 | 45 | #include "moc_declarativepieseries.cpp" |
|
61 | 46 | |
|
62 | 47 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,49 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVEPIESERIES_H |
|
22 | 22 | #define DECLARATIVEPIESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qpieslice.h" |
|
26 | 26 | #include "qpieseries.h" |
|
27 |
#include <QDeclarative |
|
|
27 | #include <QDeclarativeListProperty> | |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QChart; |
|
32 | 32 | |
|
33 |
class DeclarativePieSeries : public QPieSeries |
|
|
33 | class DeclarativePieSeries : public QPieSeries | |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | Q_INTERFACES(QDeclarativeParserStatus) | |
|
37 | 36 | Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices) |
|
38 | 37 | |
|
39 | 38 | public: |
|
40 | 39 | explicit DeclarativePieSeries(QObject *parent = 0); |
|
41 | 40 | QDeclarativeListProperty<QPieSlice> slices(); |
|
42 | 41 | |
|
43 | public: // from QDeclarativeParserStatus | |
|
44 | void classBegin(); | |
|
45 | void componentComplete(); | |
|
46 | ||
|
47 | 42 | public Q_SLOTS: |
|
48 | 43 | static void appendSlice(QDeclarativeListProperty<QPieSlice> *list, |
|
49 | 44 | QPieSlice *element); |
|
50 | ||
|
51 | private: | |
|
52 | QChart *m_chart; | |
|
53 | 45 | }; |
|
54 | 46 | |
|
55 | 47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | 48 | |
|
57 | 49 | #endif // DECLARATIVEPIESERIES_H |
@@ -1,45 +1,40 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativescatterseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qscatterseries.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) : |
|
29 | 29 | QScatterSeries(parent) |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | QAbstractSeries *DeclarativeScatterSeries::series() | |
|
34 | { | |
|
35 | return this; | |
|
36 | } | |
|
37 | ||
|
38 | 33 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() |
|
39 | 34 | { |
|
40 | 35 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
41 | 36 | } |
|
42 | 37 | |
|
43 | 38 | #include "moc_declarativescatterseries.cpp" |
|
44 | 39 | |
|
45 | 40 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVESCATTERSERIES_H |
|
22 | 22 | #define DECLARATIVESCATTERSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
35 | 35 | |
|
36 | 36 | public: |
|
37 | 37 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 | |
|
44 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 44 | |
|
46 | 45 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -1,44 +1,39 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativesplineseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) : |
|
28 | 28 | QSplineSeries(parent) |
|
29 | 29 | { |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | QAbstractSeries *DeclarativeSplineSeries::series() | |
|
33 | { | |
|
34 | return this; | |
|
35 | } | |
|
36 | ||
|
37 | 32 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points() |
|
38 | 33 | { |
|
39 | 34 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints); |
|
40 | 35 | } |
|
41 | 36 | |
|
42 | 37 | #include "moc_declarativesplineseries.cpp" |
|
43 | 38 | |
|
44 | 39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVESPLINESERIES_H |
|
22 | 22 | #define DECLARATIVESPLINESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qsplineseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) |
|
35 | 35 | |
|
36 | 36 | public: |
|
37 | 37 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
38 | 38 | |
|
39 | 39 | public: |
|
40 | QAbstractSeries *series(); | |
|
41 | 40 | QDeclarativeListProperty<DeclarativeXyPoint> points(); |
|
42 | 41 | }; |
|
43 | 42 | |
|
44 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | 44 | |
|
46 | 45 | #endif // DECLARATIVESPLINESERIES_H |
@@ -1,60 +1,44 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | //#include "DeclarativeXySeries.h" |
|
22 | 22 | #include "declarativexyseries.h" |
|
23 | 23 | #include "qxyseries.h" |
|
24 | 24 | #include "declarativechart.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | DeclarativeXySeries::DeclarativeXySeries() |
|
29 | 29 | { |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 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 | 36 | void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
53 | 37 | DeclarativeXyPoint *element) |
|
54 | 38 | { |
|
55 | 39 | QXYSeries *series = qobject_cast<QXYSeries *>(list->object); |
|
56 | 40 | if (series) |
|
57 | 41 | series->append(element->x(), element->y()); |
|
58 | 42 | } |
|
59 | 43 | |
|
60 | 44 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,51 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVE_XY_SERIES_H |
|
22 | 22 | #define DECLARATIVE_XY_SERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "declarativexypoint.h" |
|
26 | #include <QDeclarativeParserStatus> | |
|
27 | 26 | #include <QDeclarativeListProperty> |
|
28 | 27 | |
|
29 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 29 | |
|
31 | 30 | class QChart; |
|
32 | 31 | class QAbstractSeries; |
|
33 | 32 | |
|
34 | class DeclarativeXySeries : public QDeclarativeParserStatus | |
|
33 | class DeclarativeXySeries | |
|
35 | 34 | { |
|
36 | 35 | Q_INTERFACES(QDeclarativeParserStatus) |
|
37 | 36 | |
|
38 | 37 | public: |
|
39 | 38 | explicit DeclarativeXySeries(); |
|
40 | 39 | ~DeclarativeXySeries(); |
|
41 | 40 | |
|
42 | public: // from QDeclarativeParserStatus | |
|
43 | virtual void classBegin(); | |
|
44 | virtual void componentComplete(); | |
|
45 | ||
|
46 | 41 | public: |
|
47 | virtual QAbstractSeries *series() = 0; | |
|
48 | 42 | virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0; |
|
49 | 43 | |
|
50 | 44 | public Q_SLOTS: |
|
51 | 45 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, |
|
52 | 46 | DeclarativeXyPoint *element); |
|
53 | 47 | }; |
|
54 | 48 | |
|
55 | 49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | 50 | |
|
57 | 51 | #endif // DECLARATIVE_XY_SERIES_H |
@@ -1,665 +1,704 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | |
|
31 | 31 | #include <QAbstractItemModel> |
|
32 | 32 | #include <QModelIndex> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \class QBarSeries |
|
38 | 38 | \brief part of QtCommercial chart API. |
|
39 | 39 | \mainclass |
|
40 | 40 | |
|
41 | 41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
42 | 42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
43 | 43 | by QStringList. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
53 | 53 | |
|
54 | 54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
55 | 55 | contained by the series. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
60 | 60 | |
|
61 | 61 | The signal is emitted if mouse is hovered on top of series. |
|
62 | 62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
63 | 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 | 67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
68 | 68 | QBarSeries is QObject which is a child of a \a parent. |
|
69 | 69 | */ |
|
70 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : | |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(categories, this),parent) | |
|
70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : | |
|
71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) | |
|
72 | 72 | { |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | Destructs barseries and owned barsets. |
|
77 | 77 | */ |
|
78 | 78 | QBarSeries::~QBarSeries() |
|
79 | 79 | { |
|
80 | 80 | // NOTE: d_ptr destroyed by QObject |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \internal |
|
85 | 85 | */ |
|
86 | 86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
87 | 87 | QAbstractSeries(d,parent) |
|
88 | 88 | { |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | Returns the type of series. Derived classes override this. |
|
93 | 93 | */ |
|
94 | 94 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
95 | 95 | { |
|
96 | 96 | return QAbstractSeries::SeriesTypeBar; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | void QBarSeries::setCategories(QBarCategories categories) | |
|
100 | { | |
|
101 | Q_D(QBarSeries); | |
|
102 | d->setCategories(categories); | |
|
103 | emit d->categoriesUpdated(); | |
|
104 | } | |
|
105 | ||
|
99 | 106 | /*! |
|
100 | 107 | Adds a set of bars to series. Takes ownership of \a set. |
|
101 | 108 | */ |
|
102 |
|
|
|
109 | bool QBarSeries::appendBarSet(QBarSet *set) | |
|
103 | 110 | { |
|
104 | 111 | Q_D(QBarSeries); |
|
112 | if ((d->m_barSets.contains(set)) || (set == 0)) { | |
|
113 | // Fail if set is already in list or set is null. | |
|
114 | return false; | |
|
115 | } | |
|
105 | 116 | d->m_barSets.append(set); |
|
106 | 117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
107 | 118 | emit d->restructuredBars(); |
|
119 | return true; | |
|
108 | 120 | } |
|
109 | 121 | |
|
110 | 122 | /*! |
|
111 | 123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
112 | 124 | */ |
|
113 |
|
|
|
125 | bool QBarSeries::removeBarSet(QBarSet *set) | |
|
114 | 126 | { |
|
115 | 127 | Q_D(QBarSeries); |
|
116 | if (d->m_barSets.contains(set)) { | |
|
117 | d->m_barSets.removeOne(set); | |
|
118 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
|
119 | emit d->restructuredBars(); | |
|
128 | if (!d->m_barSets.contains(set)) { | |
|
129 | // Fail if set is not in list | |
|
130 | return false; | |
|
120 | 131 | } |
|
132 | d->m_barSets.removeOne(set); | |
|
133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); | |
|
134 | emit d->restructuredBars(); | |
|
135 | return true; | |
|
121 | 136 | } |
|
122 | 137 | |
|
123 | 138 | /*! |
|
124 | 139 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
125 | 140 | */ |
|
126 |
|
|
|
141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
|
127 | 142 | { |
|
128 | 143 | Q_D(QBarSeries); |
|
129 | 144 | foreach (QBarSet* set, sets) { |
|
145 | if ((set == 0) || (d->m_barSets.contains(set))) { | |
|
146 | // Fail if any of the sets is null or is already appended. | |
|
147 | return false; | |
|
148 | } | |
|
149 | if (sets.count(set) != 1) { | |
|
150 | // Also fail if same set is more than once in given list. | |
|
151 | return false; | |
|
152 | } | |
|
153 | } | |
|
154 | ||
|
155 | foreach (QBarSet* set, sets) { | |
|
130 | 156 | d->m_barSets.append(set); |
|
131 | 157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
132 | 158 | } |
|
133 | 159 | emit d->restructuredBars(); |
|
160 | return true; | |
|
134 | 161 | } |
|
135 | 162 | |
|
136 | 163 | /*! |
|
137 | 164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
138 | 165 | */ |
|
139 |
|
|
|
166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
|
140 | 167 | { |
|
141 | 168 | Q_D(QBarSeries); |
|
142 | 169 | |
|
170 | bool setsRemoved = false; | |
|
143 | 171 | foreach (QBarSet* set, sets) { |
|
144 | 172 | if (d->m_barSets.contains(set)) { |
|
145 | 173 | d->m_barSets.removeOne(set); |
|
146 | 174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
175 | setsRemoved = true; | |
|
147 | 176 | } |
|
148 | 177 | } |
|
149 | emit d->restructuredBars(); | |
|
178 | ||
|
179 | if (setsRemoved) { | |
|
180 | emit d->restructuredBars(); | |
|
181 | } | |
|
182 | return setsRemoved; | |
|
150 | 183 | } |
|
151 | 184 | |
|
152 | 185 | /*! |
|
153 | 186 | Returns number of sets in series. |
|
154 | 187 | */ |
|
155 | 188 | int QBarSeries::barsetCount() const |
|
156 | 189 | { |
|
157 | 190 | Q_D(const QBarSeries); |
|
158 | 191 | return d->m_barSets.count(); |
|
159 | 192 | } |
|
160 | 193 | |
|
161 | 194 | /*! |
|
162 | 195 | Returns number of categories in series |
|
163 | 196 | */ |
|
164 | 197 | int QBarSeries::categoryCount() const |
|
165 | 198 | { |
|
166 | 199 | Q_D(const QBarSeries); |
|
167 | 200 | return d->m_categories.count(); |
|
168 | 201 | } |
|
169 | 202 | |
|
170 | 203 | /*! |
|
171 | 204 | Returns a list of sets in series. Keeps ownership of sets. |
|
172 | 205 | */ |
|
173 | 206 | QList<QBarSet*> QBarSeries::barSets() const |
|
174 | 207 | { |
|
175 | 208 | Q_D(const QBarSeries); |
|
176 | 209 | return d->m_barSets; |
|
177 | 210 | } |
|
178 | 211 | |
|
179 | 212 | /*! |
|
180 | 213 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
181 | 214 | Sets the \a model to be used as a data source |
|
182 | 215 | */ |
|
183 | 216 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
184 | 217 | { |
|
185 | 218 | Q_D(QBarSeries); |
|
186 | 219 | return d->setModel(model); |
|
187 | 220 | } |
|
188 | 221 | |
|
189 | 222 | /*! |
|
190 | 223 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
191 | 224 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
192 | 225 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
193 | 226 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
194 | 227 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
195 | 228 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
196 | 229 | */ |
|
197 | 230 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
198 | 231 | { |
|
199 | 232 | Q_D(QBarSeries); |
|
200 | 233 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
201 | 234 | } |
|
202 | 235 | |
|
203 | 236 | void QBarSeries::setModelMappingRange(int first, int count) |
|
204 | 237 | { |
|
205 | 238 | Q_D(QBarSeries); |
|
206 | 239 | d->setModelMappingRange(first, count); |
|
207 | 240 | } |
|
208 | 241 | |
|
209 | 242 | /*! |
|
210 | 243 | Returns the bar categories of the series. |
|
211 | 244 | */ |
|
212 | 245 | QBarCategories QBarSeries::categories() const |
|
213 | 246 | { |
|
214 | 247 | Q_D(const QBarSeries); |
|
215 | 248 | return d->m_categories; |
|
216 | 249 | } |
|
217 | 250 | |
|
218 | 251 | /*! |
|
219 | 252 | Sets the visibility of labels in series to \a visible |
|
220 | 253 | */ |
|
221 | 254 | void QBarSeries::setLabelsVisible(bool visible) |
|
222 | 255 | { |
|
223 | 256 | foreach (QBarSet* s, barSets()) { |
|
224 | 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 | 264 | QAbstractSeriesPrivate(q), |
|
232 | m_categories(categories), | |
|
265 | // m_categories(categories), | |
|
233 | 266 | m_mapCategories(-1), |
|
234 | 267 | m_mapBarBottom(-1), |
|
235 | 268 | m_mapBarTop(-1) |
|
236 | 269 | { |
|
237 | 270 | } |
|
238 | 271 | |
|
272 | void QBarSeriesPrivate::setCategories(QBarCategories categories) | |
|
273 | { | |
|
274 | m_categories = categories; | |
|
275 | } | |
|
276 | ||
|
277 | ||
|
239 | 278 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
240 | 279 | { |
|
241 | 280 | return m_barSets.at(index); |
|
242 | 281 | } |
|
243 | 282 | |
|
244 | 283 | QString QBarSeriesPrivate::categoryName(int category) |
|
245 | 284 | { |
|
246 | 285 | return m_categories.at(category); |
|
247 | 286 | } |
|
248 | 287 | |
|
249 | 288 | qreal QBarSeriesPrivate::min() |
|
250 | 289 | { |
|
251 | 290 | if (m_barSets.count() <= 0) { |
|
252 | 291 | return 0; |
|
253 | 292 | } |
|
254 | 293 | qreal min = INT_MAX; |
|
255 | 294 | |
|
256 | 295 | for (int i = 0; i < m_barSets.count(); i++) { |
|
257 | 296 | int categoryCount = m_barSets.at(i)->count(); |
|
258 | 297 | for (int j = 0; j < categoryCount; j++) { |
|
259 | 298 | qreal temp = m_barSets.at(i)->at(j); |
|
260 | 299 | if (temp < min) |
|
261 | 300 | min = temp; |
|
262 | 301 | } |
|
263 | 302 | } |
|
264 | 303 | return min; |
|
265 | 304 | } |
|
266 | 305 | |
|
267 | 306 | qreal QBarSeriesPrivate::max() |
|
268 | 307 | { |
|
269 | 308 | if (m_barSets.count() <= 0) { |
|
270 | 309 | return 0; |
|
271 | 310 | } |
|
272 | 311 | qreal max = INT_MIN; |
|
273 | 312 | |
|
274 | 313 | for (int i = 0; i < m_barSets.count(); i++) { |
|
275 | 314 | int categoryCount = m_barSets.at(i)->count(); |
|
276 | 315 | for (int j = 0; j < categoryCount; j++) { |
|
277 | 316 | qreal temp = m_barSets.at(i)->at(j); |
|
278 | 317 | if (temp > max) |
|
279 | 318 | max = temp; |
|
280 | 319 | } |
|
281 | 320 | } |
|
282 | 321 | |
|
283 | 322 | return max; |
|
284 | 323 | } |
|
285 | 324 | |
|
286 | 325 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
287 | 326 | { |
|
288 | 327 | if ((set < 0) || (set >= m_barSets.count())) { |
|
289 | 328 | // No set, no value. |
|
290 | 329 | return 0; |
|
291 | 330 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
292 | 331 | // No category, no value. |
|
293 | 332 | return 0; |
|
294 | 333 | } |
|
295 | 334 | |
|
296 | 335 | return m_barSets.at(set)->at(category); |
|
297 | 336 | } |
|
298 | 337 | |
|
299 | 338 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
300 | 339 | { |
|
301 | 340 | if ((set < 0) || (set >= m_barSets.count())) { |
|
302 | 341 | // No set, no value. |
|
303 | 342 | return 0; |
|
304 | 343 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
305 | 344 | // No category, no value. |
|
306 | 345 | return 0; |
|
307 | 346 | } |
|
308 | 347 | |
|
309 | 348 | qreal value = m_barSets.at(set)->at(category); |
|
310 | 349 | qreal sum = categorySum(category); |
|
311 | 350 | if ( qFuzzyIsNull(sum) ) { |
|
312 | 351 | return 0; |
|
313 | 352 | } |
|
314 | 353 | |
|
315 | 354 | return value / sum; |
|
316 | 355 | } |
|
317 | 356 | |
|
318 | 357 | qreal QBarSeriesPrivate::categorySum(int category) |
|
319 | 358 | { |
|
320 | 359 | qreal sum(0); |
|
321 | 360 | int count = m_barSets.count(); // Count sets |
|
322 | 361 | for (int set = 0; set < count; set++) { |
|
323 | 362 | if (category < m_barSets.at(set)->count()) |
|
324 | 363 | sum += m_barSets.at(set)->at(category); |
|
325 | 364 | } |
|
326 | 365 | return sum; |
|
327 | 366 | } |
|
328 | 367 | |
|
329 | 368 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
330 | 369 | { |
|
331 | 370 | qreal sum(0); |
|
332 | 371 | int count = m_barSets.count(); // Count sets |
|
333 | 372 | for (int set = 0; set < count; set++) { |
|
334 | 373 | if (category < m_barSets.at(set)->count()) |
|
335 | 374 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
336 | 375 | } |
|
337 | 376 | return sum; |
|
338 | 377 | } |
|
339 | 378 | |
|
340 | 379 | qreal QBarSeriesPrivate::maxCategorySum() |
|
341 | 380 | { |
|
342 | 381 | qreal max = INT_MIN; |
|
343 | 382 | int count = m_categories.count(); |
|
344 | 383 | for (int i = 0; i < count; i++) { |
|
345 | 384 | qreal sum = categorySum(i); |
|
346 | 385 | if (sum > max) |
|
347 | 386 | max = sum; |
|
348 | 387 | } |
|
349 | 388 | return max; |
|
350 | 389 | } |
|
351 | 390 | |
|
352 | 391 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
353 | 392 | { |
|
354 | 393 | // disconnect signals from old model |
|
355 | 394 | if(m_model) |
|
356 | 395 | { |
|
357 | 396 | disconnect(m_model, 0, this, 0); |
|
358 | 397 | m_mapCategories = -1; |
|
359 | 398 | m_mapBarBottom = -1; |
|
360 | 399 | m_mapBarTop = -1; |
|
361 | 400 | m_mapOrientation = Qt::Vertical; |
|
362 | 401 | } |
|
363 | 402 | |
|
364 | 403 | // set new model |
|
365 | 404 | if(model) |
|
366 | 405 | { |
|
367 | 406 | m_model = model; |
|
368 | 407 | return true; |
|
369 | 408 | } |
|
370 | 409 | else |
|
371 | 410 | { |
|
372 | 411 | m_model = 0; |
|
373 | 412 | return false; |
|
374 | 413 | } |
|
375 | 414 | } |
|
376 | 415 | |
|
377 | 416 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
378 | 417 | { |
|
379 | 418 | Q_Q(QBarSeries); |
|
380 | 419 | |
|
381 | 420 | if (m_model == 0) |
|
382 | 421 | return; |
|
383 | 422 | |
|
384 | 423 | m_mapCategories = categories; |
|
385 | 424 | m_mapBarBottom = bottomBoundry; |
|
386 | 425 | m_mapBarTop = topBoundry; |
|
387 | 426 | m_mapOrientation = orientation; |
|
388 | 427 | |
|
389 | 428 | // connect the signals |
|
390 | 429 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
391 | 430 | if (m_mapOrientation == Qt::Vertical) { |
|
392 | 431 | connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
393 | 432 | connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
394 | 433 | } else { |
|
395 | 434 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
396 | 435 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
397 | 436 | } |
|
398 | 437 | |
|
399 | 438 | // create the initial bars |
|
400 | 439 | m_categories.clear(); |
|
401 | 440 | if (m_mapOrientation == Qt::Vertical) { |
|
402 | 441 | int rowCount = 0; |
|
403 | 442 | if(m_mapCount == -1) |
|
404 | 443 | rowCount = m_model->rowCount() - m_mapFirst; |
|
405 | 444 | else |
|
406 | 445 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
407 | 446 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
408 | 447 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
409 | 448 | } |
|
410 | 449 | |
|
411 | 450 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
412 | 451 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
413 | 452 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
414 | 453 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
415 | 454 | q->appendBarSet(barSet); |
|
416 | 455 | } |
|
417 | 456 | } else { |
|
418 | 457 | int columnCount = 0; |
|
419 | 458 | if(m_mapCount == -1) |
|
420 | 459 | columnCount = m_model->columnCount() - m_mapFirst; |
|
421 | 460 | else |
|
422 | 461 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
423 | 462 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
424 | 463 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
425 | 464 | } |
|
426 | 465 | |
|
427 | 466 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
428 | 467 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
429 | 468 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
430 | 469 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
431 | 470 | q->appendBarSet(barSet); |
|
432 | 471 | } |
|
433 | 472 | } |
|
434 | 473 | } |
|
435 | 474 | |
|
436 | 475 | void QBarSeriesPrivate::setModelMappingRange(int first, int count) |
|
437 | 476 | { |
|
438 | 477 | m_mapFirst = first; |
|
439 | 478 | m_mapCount = count; |
|
440 | 479 | } |
|
441 | 480 | |
|
442 | 481 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
443 | 482 | { |
|
444 | 483 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
445 | 484 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
446 | 485 | if (m_mapOrientation == Qt::Vertical) |
|
447 | 486 | { |
|
448 | 487 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
449 | 488 | if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { |
|
450 | 489 | if (column >= m_mapBarBottom && column <= m_mapBarTop) |
|
451 | 490 | barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
452 | 491 | // if (column == m_mapCategories);// TODO: |
|
453 | 492 | } |
|
454 | 493 | } |
|
455 | 494 | else |
|
456 | 495 | { |
|
457 | 496 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
458 | 497 | if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { |
|
459 | 498 | if (row >= m_mapBarBottom && row <= m_mapBarTop) |
|
460 | 499 | barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
461 | 500 | // if (row == m_mapCategories);// TODO: |
|
462 | 501 | } |
|
463 | 502 | } |
|
464 | 503 | } |
|
465 | 504 | } |
|
466 | 505 | } |
|
467 | 506 | |
|
468 | 507 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
469 | 508 | { |
|
470 | 509 | Q_UNUSED(parent); |
|
471 | 510 | Q_UNUSED(start); |
|
472 | 511 | Q_UNUSED(end); |
|
473 | 512 | initializeDataFromModel(); |
|
474 | 513 | // // series uses model as a data sourceupda |
|
475 | 514 | // int addedCount = end - start + 1; |
|
476 | 515 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { |
|
477 | 516 | // return; |
|
478 | 517 | // } else { |
|
479 | 518 | |
|
480 | 519 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { |
|
481 | 520 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); |
|
482 | 521 | // // adding items to unlimited map |
|
483 | 522 | // if (m_mapCount == -1 && start >= m_mapFirst) { |
|
484 | 523 | // for (int i = start; i <= end; i++) { |
|
485 | 524 | // if (bar == m_mapBarBottom) |
|
486 | 525 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
487 | 526 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
488 | 527 | // } |
|
489 | 528 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { |
|
490 | 529 | // // not all newly added items |
|
491 | 530 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
492 | 531 | // if (bar == m_mapBarBottom) |
|
493 | 532 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
494 | 533 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
495 | 534 | // } |
|
496 | 535 | // } |
|
497 | 536 | |
|
498 | 537 | // // adding items to limited map |
|
499 | 538 | // else if (start >= m_mapFirst) { |
|
500 | 539 | // // remove the items that will no longer fit into the map |
|
501 | 540 | // // int toRemove = addedCount - (count - points().size()); |
|
502 | 541 | // for (int i = start; i <= end; i++) { |
|
503 | 542 | // if (bar == m_mapBarBottom) |
|
504 | 543 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
505 | 544 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
506 | 545 | // } |
|
507 | 546 | // if (m_barSets.size() > m_mapCount) |
|
508 | 547 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
509 | 548 | // if (bar == m_mapBarBottom) |
|
510 | 549 | // removeCategory(i); |
|
511 | 550 | // barSet->remove(i); |
|
512 | 551 | // } |
|
513 | 552 | // } else { |
|
514 | 553 | // // |
|
515 | 554 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
516 | 555 | // if (bar == m_mapBarBottom) |
|
517 | 556 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
518 | 557 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
519 | 558 | // } |
|
520 | 559 | // if (m_barSets.size() > m_mapCount) |
|
521 | 560 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
522 | 561 | // if (bar == m_mapBarBottom) |
|
523 | 562 | // removeCategory(i); |
|
524 | 563 | // barSet->remove(i); |
|
525 | 564 | // } |
|
526 | 565 | // } |
|
527 | 566 | // } |
|
528 | 567 | // emit restructuredBars(); |
|
529 | 568 | // emit barsetChanged(); |
|
530 | 569 | // emit categoriesUpdated(); |
|
531 | 570 | // } |
|
532 | 571 | } |
|
533 | 572 | |
|
534 | 573 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
535 | 574 | { |
|
536 | 575 | Q_UNUSED(parent); |
|
537 | 576 | Q_UNUSED(start); |
|
538 | 577 | Q_UNUSED(end); |
|
539 | 578 | initializeDataFromModel(); |
|
540 | 579 | } |
|
541 | 580 | |
|
542 | 581 | void QBarSeriesPrivate::initializeDataFromModel() |
|
543 | 582 | { |
|
544 | 583 | Q_Q(QBarSeries); |
|
545 | 584 | |
|
546 | 585 | if (m_model == 0) |
|
547 | 586 | return; |
|
548 | 587 | |
|
549 | 588 | // connect the signals |
|
550 | 589 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
551 | 590 | // if (m_mapOrientation == Qt::Vertical) { |
|
552 | 591 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
553 | 592 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
554 | 593 | // } else { |
|
555 | 594 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
556 | 595 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
557 | 596 | // } |
|
558 | 597 | |
|
559 | 598 | // create the initial bars |
|
560 | 599 | m_categories.clear(); |
|
561 | 600 | m_barSets.clear(); |
|
562 | 601 | // emit restructuredBars(); |
|
563 | 602 | if (m_mapOrientation == Qt::Vertical) { |
|
564 | 603 | int rowCount = 0; |
|
565 | 604 | if(m_mapCount == -1) |
|
566 | 605 | rowCount = m_model->rowCount() - m_mapFirst; |
|
567 | 606 | else |
|
568 | 607 | rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
569 | 608 | for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
570 | 609 | m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
571 | 610 | } |
|
572 | 611 | |
|
573 | 612 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
574 | 613 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
575 | 614 | for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
576 | 615 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
577 | 616 | q->appendBarSet(barSet); |
|
578 | 617 | } |
|
579 | 618 | } else { |
|
580 | 619 | int columnCount = 0; |
|
581 | 620 | if(m_mapCount == -1) |
|
582 | 621 | columnCount = m_model->columnCount() - m_mapFirst; |
|
583 | 622 | else |
|
584 | 623 | columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
585 | 624 | for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
586 | 625 | m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
587 | 626 | } |
|
588 | 627 | |
|
589 | 628 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
590 | 629 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
591 | 630 | for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
592 | 631 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
593 | 632 | q->appendBarSet(barSet); |
|
594 | 633 | } |
|
595 | 634 | } |
|
596 | 635 | emit restructuredBars(); |
|
597 | 636 | // emit updatedBars(); |
|
598 | 637 | } |
|
599 | 638 | |
|
600 | 639 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
601 | 640 | { |
|
602 | 641 | m_categories.insert(index, category); |
|
603 | 642 | emit categoriesUpdated(); |
|
604 | 643 | } |
|
605 | 644 | |
|
606 | 645 | void QBarSeriesPrivate::removeCategory(int index) |
|
607 | 646 | { |
|
608 | 647 | m_categories.removeAt(index); |
|
609 | 648 | emit categoriesUpdated(); |
|
610 | 649 | } |
|
611 | 650 | |
|
612 | 651 | void QBarSeriesPrivate::barsetChanged() |
|
613 | 652 | { |
|
614 | 653 | emit updatedBars(); |
|
615 | 654 | } |
|
616 | 655 | |
|
617 | 656 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
618 | 657 | { |
|
619 | 658 | qreal minX(domain.minX()); |
|
620 | 659 | qreal minY(domain.minY()); |
|
621 | 660 | qreal maxX(domain.maxX()); |
|
622 | 661 | qreal maxY(domain.maxY()); |
|
623 | 662 | int tickXCount(domain.tickXCount()); |
|
624 | 663 | int tickYCount(domain.tickYCount()); |
|
625 | 664 | |
|
626 | 665 | qreal x = m_categories.count(); |
|
627 | 666 | qreal y = max(); |
|
628 | 667 | minX = qMin(minX, x); |
|
629 | 668 | minY = qMin(minY, y); |
|
630 | 669 | maxX = qMax(maxX, x); |
|
631 | 670 | maxY = qMax(maxY, y); |
|
632 | 671 | tickXCount = x+1; |
|
633 | 672 | |
|
634 | 673 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
635 | 674 | } |
|
636 | 675 | |
|
637 | 676 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
638 | 677 | { |
|
639 | 678 | Q_Q(QBarSeries); |
|
640 | 679 | |
|
641 | 680 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
642 | 681 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
643 | 682 | presenter->animator()->addAnimation(bar); |
|
644 | 683 | } |
|
645 | 684 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
646 | 685 | return bar; |
|
647 | 686 | |
|
648 | 687 | } |
|
649 | 688 | |
|
650 | 689 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
651 | 690 | { |
|
652 | 691 | Q_Q(QBarSeries); |
|
653 | 692 | QList<LegendMarker*> markers; |
|
654 | 693 | foreach(QBarSet* set, q->barSets()) { |
|
655 | 694 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
656 | 695 | markers << marker; |
|
657 | 696 | } |
|
658 | 697 | |
|
659 | 698 | return markers; |
|
660 | 699 | } |
|
661 | 700 | |
|
662 | 701 | #include "moc_qbarseries.cpp" |
|
663 | 702 | #include "moc_qbarseries_p.cpp" |
|
664 | 703 | |
|
665 | 704 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef BARSERIES_H |
|
22 | 22 | #define BARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | 27 | class QModelIndex; |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | typedef QStringList QBarCategories; |
|
32 | 32 | |
|
33 | 33 | class QBarSet; |
|
34 | 34 | class BarCategory; |
|
35 | 35 | class QBarSeriesPrivate; |
|
36 | 36 | |
|
37 | 37 | // Container for series |
|
38 | 38 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | public: |
|
42 | explicit QBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
42 | explicit QBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
43 | 43 | virtual ~QBarSeries(); |
|
44 | 44 | |
|
45 | 45 | QAbstractSeries::SeriesType type() const; |
|
46 | void setCategories(QBarCategories categories); | |
|
46 | 47 | |
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
48 | bool appendBarSet(QBarSet *set); // Takes ownership of set | |
|
49 | bool removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
|
50 | bool appendBarSets(QList<QBarSet* > sets); | |
|
51 | bool removeBarSets(QList<QBarSet* > sets); | |
|
51 | 52 | int barsetCount() const; |
|
52 | 53 | int categoryCount() const; |
|
53 | 54 | QList<QBarSet*> barSets() const; |
|
54 | 55 | QBarCategories categories() const; |
|
55 | 56 | |
|
56 | 57 | void setLabelsVisible(bool visible = true); |
|
57 | 58 | |
|
58 | 59 | bool setModel(QAbstractItemModel *model); |
|
59 | 60 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
60 | 61 | void setModelMappingRange(int first, int count = -1); |
|
61 | 62 | |
|
62 | 63 | protected: |
|
63 | 64 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
64 | 65 | |
|
65 | 66 | Q_SIGNALS: |
|
66 | 67 | void clicked(QBarSet *barset, QString category); |
|
67 | 68 | void hovered(QBarSet* barset, bool status); |
|
68 | 69 | |
|
69 | 70 | protected: |
|
70 | 71 | Q_DECLARE_PRIVATE(QBarSeries) |
|
71 | 72 | friend class BarChartItem; |
|
72 | 73 | friend class PercentBarChartItem; |
|
73 | 74 | friend class StackedBarChartItem; |
|
74 | 75 | }; |
|
75 | 76 | |
|
76 | 77 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | 78 | |
|
78 | 79 | #endif // BARSERIES_H |
@@ -1,68 +1,69 | |||
|
1 | 1 | #ifndef QBARSERIES_P_H |
|
2 | 2 | #define QBARSERIES_P_H |
|
3 | 3 | |
|
4 | 4 | #include "qbarseries.h" |
|
5 | 5 | #include "qabstractseries_p.h" |
|
6 | 6 | #include <QStringList> |
|
7 | 7 | #include <QAbstractSeries> |
|
8 | 8 | |
|
9 | 9 | class QModelIndex; |
|
10 | 10 | |
|
11 | 11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 12 | |
|
13 | 13 | // Container for series |
|
14 | 14 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
15 | 15 | { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | public: |
|
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); | |
|
18 | QBarSeriesPrivate(/*QBarCategories categories,*/ QBarSeries *parent); | |
|
19 | void setCategories(QBarCategories categories); | |
|
19 | 20 | |
|
20 | 21 | void scaleDomain(Domain& domain); |
|
21 | 22 | Chart* createGraphics(ChartPresenter* presenter); |
|
22 | 23 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
23 | 24 | |
|
24 | 25 | bool setModel(QAbstractItemModel *model); |
|
25 | 26 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
26 | 27 | void setModelMappingRange(int first, int count = -1); |
|
27 | 28 | |
|
28 | 29 | void insertCategory(int index, const QString category); |
|
29 | 30 | void removeCategory(int index); |
|
30 | 31 | |
|
31 | 32 | QBarSet* barsetAt(int index); |
|
32 | 33 | QString categoryName(int category); |
|
33 | 34 | qreal min(); |
|
34 | 35 | qreal max(); |
|
35 | 36 | qreal valueAt(int set, int category); |
|
36 | 37 | qreal percentageAt(int set, int category); |
|
37 | 38 | qreal categorySum(int category); |
|
38 | 39 | qreal absoluteCategorySum(int category); |
|
39 | 40 | qreal maxCategorySum(); |
|
40 | 41 | |
|
41 | 42 | Q_SIGNALS: |
|
42 | 43 | void clicked(QBarSet *barset, QString category); |
|
43 | 44 | void updatedBars(); |
|
44 | 45 | void restructuredBars(); |
|
45 | 46 | void categoriesUpdated(); |
|
46 | 47 | |
|
47 | 48 | private Q_SLOTS: |
|
48 | 49 | // slots for updating bars when data in model changes |
|
49 | 50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
50 | 51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
51 | 52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
52 | 53 | void initializeDataFromModel(); |
|
53 | 54 | void barsetChanged(); |
|
54 | 55 | |
|
55 | 56 | protected: |
|
56 | 57 | QList<QBarSet *> m_barSets; |
|
57 | 58 | QBarCategories m_categories; |
|
58 | 59 | |
|
59 | 60 | int m_mapCategories; |
|
60 | 61 | int m_mapBarBottom; |
|
61 | 62 | int m_mapBarTop; |
|
62 | 63 | private: |
|
63 | 64 | Q_DECLARE_PUBLIC(QBarSeries) |
|
64 | 65 | }; |
|
65 | 66 | |
|
66 | 67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | 68 | |
|
68 | 69 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,109 +1,109 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpercentbarseries.h" |
|
22 | 22 | #include "qpercentbarseries_p.h" |
|
23 | 23 | #include "percentbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | /*! |
|
32 | 32 | \class QPercentBarSeries |
|
33 | 33 | \brief part of QtCommercial chart API. |
|
34 | 34 | \mainclass |
|
35 | 35 | |
|
36 | 36 | QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage |
|
37 | 37 | of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets. |
|
38 | 38 | QBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
39 | 39 | |
|
40 | 40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
41 | 41 | \image examples_percentbarchart.png |
|
42 | 42 | |
|
43 | 43 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | /*! |
|
47 | 47 | \fn virtual QSeriesType QPercentBarSeries::type() const |
|
48 | 48 | \brief Returns type of series. |
|
49 | 49 | \sa QAbstractSeries, QSeriesType |
|
50 | 50 | */ |
|
51 | 51 | |
|
52 | 52 | /*! |
|
53 | 53 | Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart. |
|
54 | 54 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
55 | 55 | */ |
|
56 | QPercentBarSeries::QPercentBarSeries(QBarCategories categories, QObject *parent) | |
|
57 | : QBarSeries(*new QPercentBarSeriesPrivate(categories,this), parent) | |
|
56 | QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
|
57 | : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent) | |
|
58 | 58 | { |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
62 | 62 | { |
|
63 | 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 | 73 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
74 | 74 | { |
|
75 | 75 | Q_Q(QPercentBarSeries); |
|
76 | 76 | qreal minX(domain.minX()); |
|
77 | 77 | qreal minY(domain.minY()); |
|
78 | 78 | qreal maxX(domain.maxX()); |
|
79 | 79 | qreal maxY(domain.maxY()); |
|
80 | 80 | int tickXCount(domain.tickXCount()); |
|
81 | 81 | int tickYCount(domain.tickYCount()); |
|
82 | 82 | |
|
83 | 83 | qreal x = q->categoryCount(); |
|
84 | 84 | minX = qMin(minX, x); |
|
85 | 85 | maxX = qMax(maxX, x); |
|
86 | 86 | minY = 0; |
|
87 | 87 | maxY = 100; |
|
88 | 88 | tickXCount = x+1; |
|
89 | 89 | |
|
90 | 90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
95 | 95 | { |
|
96 | 96 | Q_Q(QPercentBarSeries); |
|
97 | 97 | |
|
98 | 98 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
99 | 99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
100 | 100 | presenter->animator()->addAnimation(bar); |
|
101 | 101 | } |
|
102 | 102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
103 | 103 | return bar; |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | #include "moc_qpercentbarseries.cpp" |
|
107 | 107 | |
|
108 | 108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
109 | 109 |
@@ -1,44 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef PERCENTBARSERIES_H |
|
22 | 22 | #define PERCENTBARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <QStringList> |
|
25 | 25 | #include <qbarseries.h> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QPercentBarSeriesPrivate; |
|
30 | 30 | |
|
31 | 31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | public: |
|
35 | explicit QPercentBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
35 | explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
36 | 36 | QAbstractSeries::SeriesType type() const; |
|
37 | ||
|
37 | 38 | private: |
|
38 | 39 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
39 | 40 | Q_DISABLE_COPY(QPercentBarSeries) |
|
40 | 41 | }; |
|
41 | 42 | |
|
42 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | 44 | |
|
44 | 45 | #endif // PERCENTBARSERIES_H |
@@ -1,52 +1,52 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QPERCENTBARSERIES_P_H |
|
31 | 31 | #define QPERCENTBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | QPercentBarSeriesPrivate(QBarCategories categories,QPercentBarSeries* q); | |
|
42 | QPercentBarSeriesPrivate(/*QBarCategories categories,*/QPercentBarSeries* q); | |
|
43 | 43 | void scaleDomain(Domain& domain); |
|
44 | 44 | Chart* createGraphics(ChartPresenter* presenter); |
|
45 | 45 | |
|
46 | 46 | private: |
|
47 | 47 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 51 | |
|
52 | 52 | #endif |
@@ -1,108 +1,108 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qstackedbarseries.h" |
|
22 | 22 | #include "qstackedbarseries_p.h" |
|
23 | 23 | #include "stackedbarchartitem_p.h" |
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | /*! |
|
31 | 31 | \class QStackedBarSeries |
|
32 | 32 | \brief part of QtCommercial chart API. |
|
33 | 33 | \mainclass |
|
34 | 34 | |
|
35 | 35 | QStackedBarSeries represents a series of data shown as bars. All bars in same category are |
|
36 | 36 | stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets. |
|
37 | 37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
38 | 38 | |
|
39 | 39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
40 | 40 | \image examples_stackedbarchart.png |
|
41 | 41 | |
|
42 | 42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | 46 | \fn virtual QSeriesType QStackedBarSeries::type() const |
|
47 | 47 | \brief Returns type of series. |
|
48 | 48 | \sa QSeriesType |
|
49 | 49 | */ |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | 53 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
54 | 54 | */ |
|
55 | QStackedBarSeries::QStackedBarSeries(QBarCategories categories, QObject *parent) | |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(categories,this), parent) | |
|
55 | QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent) | |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent) | |
|
57 | 57 | { |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
61 | 61 | { |
|
62 | 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 | 72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
73 | 73 | { |
|
74 | 74 | qreal minX(domain.minX()); |
|
75 | 75 | qreal minY(domain.minY()); |
|
76 | 76 | qreal maxX(domain.maxX()); |
|
77 | 77 | qreal maxY(domain.maxY()); |
|
78 | 78 | int tickXCount(domain.tickXCount()); |
|
79 | 79 | int tickYCount(domain.tickYCount()); |
|
80 | 80 | |
|
81 | 81 | qreal x = m_categories.count(); |
|
82 | 82 | qreal y = maxCategorySum(); |
|
83 | 83 | minX = qMin(minX, x); |
|
84 | 84 | minY = qMin(minY, y); |
|
85 | 85 | maxX = qMax(maxX, x); |
|
86 | 86 | maxY = qMax(maxY, y); |
|
87 | 87 | tickXCount = x+1; |
|
88 | 88 | |
|
89 | 89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
94 | 94 | { |
|
95 | 95 | Q_Q(QStackedBarSeries); |
|
96 | 96 | |
|
97 | 97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
98 | 98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
99 | 99 | presenter->animator()->addAnimation(bar); |
|
100 | 100 | } |
|
101 | 101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
102 | 102 | return bar; |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | #include "moc_qstackedbarseries.cpp" |
|
106 | 106 | |
|
107 | 107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | 108 |
@@ -1,44 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef STACKEDBARSERIES_H |
|
22 | 22 | #define STACKEDBARSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <QStringList> |
|
25 | 25 | #include <qbarseries.h> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | class QStackedBarSeriesPrivate; |
|
30 | 30 | |
|
31 | 31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries |
|
32 | 32 | { |
|
33 | 33 | Q_OBJECT |
|
34 | 34 | public: |
|
35 | explicit QStackedBarSeries(QBarCategories categories, QObject *parent = 0); | |
|
35 | explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0); | |
|
36 | 36 | QAbstractSeries::SeriesType type() const; |
|
37 | ||
|
37 | 38 | private: |
|
38 | 39 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
39 | 40 | Q_DISABLE_COPY(QStackedBarSeries) |
|
40 | 41 | }; |
|
41 | 42 | |
|
42 | 43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | 44 | |
|
44 | 45 | #endif // STACKEDBARSERIES_H |
@@ -1,52 +1,52 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QSTACKEDBARSERIES_P_H |
|
31 | 31 | #define QSTACKEDBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qbarseries_p.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | public: |
|
42 | QStackedBarSeriesPrivate(QBarCategories categories,QStackedBarSeries* q); | |
|
42 | QStackedBarSeriesPrivate(/*QBarCategories categories,*/QStackedBarSeries* q); | |
|
43 | 43 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | 44 | void scaleDomain(Domain& domain); |
|
45 | 45 | |
|
46 | 46 | private: |
|
47 | 47 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
48 | 48 | }; |
|
49 | 49 | |
|
50 | 50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | 51 | |
|
52 | 52 | #endif |
@@ -1,6 +1,9 | |||
|
1 | 1 | !include( ../test.pri ) { |
|
2 | 2 | error( "Couldn't find the test.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | CONFIG += qtestlib |
|
6 | 6 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") |
|
7 | ||
|
8 | INCLUDEPATH += ../inc | |
|
9 | HEADERS += ../inc/tst_definitions.h |
@@ -1,10 +1,10 | |||
|
1 | 1 | !include( ../test.pri ) { |
|
2 | 2 | error( "Couldn't find the test.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qpieslice qpieseries | |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qpieslice qpieseries | |
|
7 | 7 | |
|
8 | 8 | test_private:{ |
|
9 | 9 | SUBDIRS += chartdataset domain |
|
10 | 10 | } |
@@ -1,532 +1,533 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qaxis.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <private/chartdataset_p.h> |
|
25 | 25 | #include <private/domain_p.h> |
|
26 | #include <tst_definitions.h> | |
|
26 | 27 | |
|
27 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 29 | |
|
29 | 30 | Q_DECLARE_METATYPE(Domain *) |
|
30 | 31 | Q_DECLARE_METATYPE(QAxis *) |
|
31 | 32 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
32 | 33 | Q_DECLARE_METATYPE(QLineSeries *) |
|
33 | 34 | |
|
34 | 35 | class tst_ChartDataSet: public QObject { |
|
35 | 36 | |
|
36 | 37 | Q_OBJECT |
|
37 | 38 | |
|
38 | 39 | public Q_SLOTS: |
|
39 | 40 | void initTestCase(); |
|
40 | 41 | void cleanupTestCase(); |
|
41 | 42 | void init(); |
|
42 | 43 | void cleanup(); |
|
43 | 44 | |
|
44 | 45 | private Q_SLOTS: |
|
45 | 46 | void chartdataset_data(); |
|
46 | 47 | void chartdataset(); |
|
47 | 48 | void addSeries_data(); |
|
48 | 49 | void addSeries(); |
|
49 | 50 | void removeSeries_data(); |
|
50 | 51 | void removeSeries(); |
|
51 | 52 | void removeAllSeries_data(); |
|
52 | 53 | void removeAllSeries(); |
|
53 | 54 | void axisY_data(); |
|
54 | 55 | void axisY(); |
|
55 | 56 | void seriesCount_data(); |
|
56 | 57 | void seriesCount(); |
|
57 | 58 | void seriesIndex_data(); |
|
58 | 59 | void seriesIndex(); |
|
59 | 60 | void domain_data(); |
|
60 | 61 | void domain(); |
|
61 | 62 | void zoomInDomain_data(); |
|
62 | 63 | void zoomInDomain(); |
|
63 | 64 | void zoomOutDomain_data(); |
|
64 | 65 | void zoomOutDomain(); |
|
65 | 66 | void scrollDomain_data(); |
|
66 | 67 | void scrollDomain(); |
|
67 | 68 | private: |
|
68 | 69 | ChartDataSet* m_dataset; |
|
69 | 70 | }; |
|
70 | 71 | |
|
71 | 72 | void tst_ChartDataSet::initTestCase() |
|
72 | 73 | { |
|
73 | 74 | qRegisterMetaType<Domain*>(); |
|
74 | 75 | qRegisterMetaType<QAxis*>(); |
|
75 | 76 | qRegisterMetaType<QAbstractSeries*>(); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | void tst_ChartDataSet::cleanupTestCase() |
|
79 | 80 | { |
|
80 | 81 | } |
|
81 | 82 | |
|
82 | 83 | void tst_ChartDataSet::init() |
|
83 | 84 | { |
|
84 | 85 | m_dataset = new ChartDataSet(); |
|
85 | 86 | } |
|
86 | 87 | |
|
87 | 88 | |
|
88 | 89 | void tst_ChartDataSet::cleanup() |
|
89 | 90 | { |
|
90 | 91 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
91 | 92 | foreach(QAbstractSeries* serie, series) |
|
92 | 93 | { |
|
93 | 94 | m_dataset->removeSeries(serie); |
|
94 | 95 | } |
|
95 | 96 | } |
|
96 | 97 | |
|
97 | 98 | void tst_ChartDataSet::chartdataset_data() |
|
98 | 99 | { |
|
99 | 100 | } |
|
100 | 101 | |
|
101 | 102 | void tst_ChartDataSet::chartdataset() |
|
102 | 103 | { |
|
103 | 104 | QVERIFY2(m_dataset->axisX(), "Missing axisX."); |
|
104 | 105 | QVERIFY2(m_dataset->axisY(), "Missing axisY."); |
|
105 | 106 | //check if not dangling pointer |
|
106 | 107 | m_dataset->axisX()->objectName(); |
|
107 | 108 | m_dataset->axisY()->objectName(); |
|
108 | 109 | QLineSeries* series = new QLineSeries(this); |
|
109 | 110 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
110 | 111 | } |
|
111 | 112 | |
|
112 | 113 | void tst_ChartDataSet::addSeries_data() |
|
113 | 114 | { |
|
114 | 115 | QTest::addColumn<QLineSeries*>("series0"); |
|
115 | 116 | QTest::addColumn<QAxis*>("axis0"); |
|
116 | 117 | QTest::addColumn<QLineSeries*>("series1"); |
|
117 | 118 | QTest::addColumn<QAxis*>("axis1"); |
|
118 | 119 | QTest::addColumn<QLineSeries*>("series2"); |
|
119 | 120 | QTest::addColumn<QAxis*>("axis2"); |
|
120 | 121 | QTest::addColumn<int>("axisCount"); |
|
121 | 122 | |
|
122 | 123 | QLineSeries* series0 = new QLineSeries(this); |
|
123 | 124 | QLineSeries* series1 = new QLineSeries(this); |
|
124 | 125 | QLineSeries* series2 = new QLineSeries(this); |
|
125 | 126 | |
|
126 | 127 | QAxis* axis0 = new QAxis(this); |
|
127 | 128 | QAxis* axis1 = new QAxis(this); |
|
128 | 129 | QAxis* axis2 = new QAxis(this); |
|
129 | 130 | |
|
130 | 131 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QAxis*)0 << series1 << (QAxis*)0 << series2 << (QAxis*)0 << 2; |
|
131 | 132 | QTest::newRow("default axis Y: series0, axis0: series1,series2") << series0 << (QAxis*)0 << series1 << axis0 << series2 << axis0 << 3; |
|
132 | 133 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; |
|
133 | 134 | } |
|
134 | 135 | |
|
135 | 136 | void tst_ChartDataSet::addSeries() |
|
136 | 137 | { |
|
137 | 138 | QFETCH(QLineSeries*, series0); |
|
138 | 139 | QFETCH(QAxis*, axis0); |
|
139 | 140 | QFETCH(QLineSeries*, series1); |
|
140 | 141 | QFETCH(QAxis*, axis1); |
|
141 | 142 | QFETCH(QLineSeries*, series2); |
|
142 | 143 | QFETCH(QAxis*, axis2); |
|
143 | 144 | QFETCH(int, axisCount); |
|
144 | 145 | |
|
145 | 146 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); |
|
146 | 147 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); |
|
147 | 148 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
148 | 149 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
149 | 150 | |
|
150 | 151 | m_dataset->addSeries(series0,axis0); |
|
151 | 152 | m_dataset->addSeries(series1,axis1); |
|
152 | 153 | m_dataset->addSeries(series2,axis2); |
|
153 | 154 | |
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
155 | TRY_COMPARE(spy0.count(), axisCount); | |
|
156 | TRY_COMPARE(spy1.count(), 0); | |
|
157 | TRY_COMPARE(spy2.count(), 3); | |
|
158 | TRY_COMPARE(spy3.count(), 0); | |
|
158 | 159 | |
|
159 | 160 | if(axis0==0) axis0 = m_dataset->axisY(); |
|
160 | 161 | if(axis1==0) axis1 = m_dataset->axisY(); |
|
161 | 162 | if(axis2==0) axis2 = m_dataset->axisY(); |
|
162 | 163 | |
|
163 | 164 | QVERIFY(axis0 == m_dataset->removeSeries(series0)); |
|
164 | 165 | QVERIFY(axis1 == m_dataset->removeSeries(series1)); |
|
165 | 166 | QVERIFY(axis2 == m_dataset->removeSeries(series2)); |
|
166 | 167 | } |
|
167 | 168 | |
|
168 | 169 | void tst_ChartDataSet::removeSeries_data() |
|
169 | 170 | { |
|
170 | 171 | addSeries_data(); |
|
171 | 172 | } |
|
172 | 173 | |
|
173 | 174 | void tst_ChartDataSet::removeSeries() |
|
174 | 175 | { |
|
175 | 176 | QFETCH(QLineSeries*, series0); |
|
176 | 177 | QFETCH(QAxis*, axis0); |
|
177 | 178 | QFETCH(QLineSeries*, series1); |
|
178 | 179 | QFETCH(QAxis*, axis1); |
|
179 | 180 | QFETCH(QLineSeries*, series2); |
|
180 | 181 | QFETCH(QAxis*, axis2); |
|
181 | 182 | QFETCH(int, axisCount); |
|
182 | 183 | |
|
183 | 184 | m_dataset->addSeries(series0,axis0); |
|
184 | 185 | m_dataset->addSeries(series1,axis1); |
|
185 | 186 | m_dataset->addSeries(series2,axis2); |
|
186 | 187 | |
|
187 | 188 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
188 | 189 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
189 | 190 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
190 | 191 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
191 | 192 | |
|
192 | 193 | m_dataset->removeSeries(series0); |
|
193 | 194 | m_dataset->removeSeries(series1); |
|
194 | 195 | m_dataset->removeSeries(series2); |
|
195 | 196 | |
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
197 | TRY_COMPARE(spy0.count(), 0); | |
|
198 | TRY_COMPARE(spy1.count(), axisCount); | |
|
199 | TRY_COMPARE(spy2.count(), 0); | |
|
200 | TRY_COMPARE(spy3.count(), 3); | |
|
200 | 201 | } |
|
201 | 202 | |
|
202 | 203 | void tst_ChartDataSet::removeAllSeries_data() |
|
203 | 204 | { |
|
204 | 205 | |
|
205 | 206 | } |
|
206 | 207 | |
|
207 | 208 | void tst_ChartDataSet::removeAllSeries() |
|
208 | 209 | { |
|
209 | 210 | QLineSeries* series0 = new QLineSeries(this); |
|
210 | 211 | QLineSeries* series1 = new QLineSeries(this); |
|
211 | 212 | QLineSeries* series2 = new QLineSeries(this); |
|
212 | 213 | |
|
213 | 214 | QAxis* axis0 = new QAxis(this); |
|
214 | 215 | QAxis* axis1 = new QAxis(this); |
|
215 | 216 | QAxis* axis2 = new QAxis(this); |
|
216 | 217 | |
|
217 | 218 | m_dataset->addSeries(series0, axis0); |
|
218 | 219 | m_dataset->addSeries(series1, axis1); |
|
219 | 220 | m_dataset->addSeries(series2, axis2); |
|
220 | 221 | |
|
221 | 222 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
222 | 223 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
223 | 224 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
224 | 225 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
225 | 226 | |
|
226 | 227 | m_dataset->removeAllSeries(); |
|
227 | 228 | |
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
229 | TRY_COMPARE(spy0.count(), 0); | |
|
230 | TRY_COMPARE(spy1.count(), 4); | |
|
231 | TRY_COMPARE(spy2.count(), 0); | |
|
232 | TRY_COMPARE(spy3.count(), 3); | |
|
232 | 233 | } |
|
233 | 234 | |
|
234 | 235 | |
|
235 | 236 | void tst_ChartDataSet::axisY_data() |
|
236 | 237 | { |
|
237 | 238 | QTest::addColumn<QAxis*>("axis0"); |
|
238 | 239 | QTest::addColumn<QAxis*>("axis1"); |
|
239 | 240 | QTest::addColumn<QAxis*>("axis2"); |
|
240 | 241 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
241 | 242 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
242 | 243 | } |
|
243 | 244 | |
|
244 | 245 | void tst_ChartDataSet::axisY() |
|
245 | 246 | { |
|
246 | 247 | QFETCH(QAxis*, axis0); |
|
247 | 248 | QFETCH(QAxis*, axis1); |
|
248 | 249 | QFETCH(QAxis*, axis2); |
|
249 | 250 | |
|
250 | 251 | QAxis* defaultAxisY = m_dataset->axisY(); |
|
251 | 252 | |
|
252 | 253 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
253 | 254 | |
|
254 | 255 | QLineSeries* series0 = new QLineSeries(); |
|
255 | 256 | m_dataset->addSeries(series0,axis0); |
|
256 | 257 | |
|
257 | 258 | QLineSeries* series1 = new QLineSeries(); |
|
258 | 259 | m_dataset->addSeries(series1,axis1); |
|
259 | 260 | |
|
260 | 261 | QLineSeries* series2 = new QLineSeries(); |
|
261 | 262 | m_dataset->addSeries(series2,axis2); |
|
262 | 263 | |
|
263 | 264 | if(!axis0) axis0=defaultAxisY ; |
|
264 | 265 | if(!axis1) axis1=defaultAxisY ; |
|
265 | 266 | if(!axis2) axis2=defaultAxisY ; |
|
266 | 267 | |
|
267 | 268 | QVERIFY(m_dataset->axisY(series0) == axis0); |
|
268 | 269 | QVERIFY(m_dataset->axisY(series1) == axis1); |
|
269 | 270 | QVERIFY(m_dataset->axisY(series2) == axis2); |
|
270 | 271 | |
|
271 | 272 | } |
|
272 | 273 | |
|
273 | 274 | void tst_ChartDataSet::seriesCount_data() |
|
274 | 275 | { |
|
275 | 276 | addSeries_data(); |
|
276 | 277 | } |
|
277 | 278 | |
|
278 | 279 | void tst_ChartDataSet::seriesCount() |
|
279 | 280 | { |
|
280 | 281 | QFETCH(QLineSeries*, series0); |
|
281 | 282 | QFETCH(QAxis*, axis0); |
|
282 | 283 | QFETCH(QLineSeries*, series1); |
|
283 | 284 | QFETCH(QAxis*, axis1); |
|
284 | 285 | QFETCH(QLineSeries*, series2); |
|
285 | 286 | QFETCH(QAxis*, axis2); |
|
286 | 287 | QFETCH(int, axisCount); |
|
287 | 288 | Q_UNUSED(axisCount); |
|
288 | 289 | |
|
289 | 290 | m_dataset->addSeries(series0, axis0); |
|
290 | 291 | m_dataset->addSeries(series1, axis1); |
|
291 | 292 | m_dataset->addSeries(series2, axis2); |
|
292 | 293 | |
|
293 | 294 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
294 | 295 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
295 | 296 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
296 | 297 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
297 | 298 | |
|
298 | 299 | QCOMPARE(m_dataset->seriesCount(series0->type()),3); |
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
300 | TRY_COMPARE(spy0.count(), 0); | |
|
301 | TRY_COMPARE(spy1.count(), 0); | |
|
302 | TRY_COMPARE(spy2.count(), 0); | |
|
303 | TRY_COMPARE(spy3.count(), 0); | |
|
303 | 304 | } |
|
304 | 305 | |
|
305 | 306 | void tst_ChartDataSet::seriesIndex_data() |
|
306 | 307 | { |
|
307 | 308 | addSeries_data(); |
|
308 | 309 | } |
|
309 | 310 | |
|
310 | 311 | void tst_ChartDataSet::seriesIndex() |
|
311 | 312 | { |
|
312 | 313 | //TODO: rewrite this series_index_data to match better |
|
313 | 314 | |
|
314 | 315 | QFETCH(QLineSeries*, series0); |
|
315 | 316 | QFETCH(QAxis*, axis0); |
|
316 | 317 | QFETCH(QLineSeries*, series1); |
|
317 | 318 | QFETCH(QAxis*, axis1); |
|
318 | 319 | QFETCH(QLineSeries*, series2); |
|
319 | 320 | QFETCH(QAxis*, axis2); |
|
320 | 321 | QFETCH(int, axisCount); |
|
321 | 322 | Q_UNUSED(axisCount); |
|
322 | 323 | |
|
323 | 324 | m_dataset->addSeries(series0, axis0); |
|
324 | 325 | m_dataset->addSeries(series1, axis1); |
|
325 | 326 | m_dataset->addSeries(series2, axis2); |
|
326 | 327 | |
|
327 | 328 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis*,Domain*))); |
|
328 | 329 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis*))); |
|
329 | 330 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
330 | 331 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
331 | 332 | |
|
332 | 333 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
333 | 334 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
334 | 335 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
335 | 336 | |
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
337 | TRY_COMPARE(spy0.count(), 0); | |
|
338 | TRY_COMPARE(spy1.count(), 0); | |
|
339 | TRY_COMPARE(spy2.count(), 0); | |
|
340 | TRY_COMPARE(spy3.count(), 0); | |
|
340 | 341 | |
|
341 | 342 | m_dataset->removeSeries(series0); |
|
342 | 343 | m_dataset->removeSeries(series1); |
|
343 | 344 | m_dataset->removeSeries(series2); |
|
344 | 345 | |
|
345 | 346 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
346 | 347 | QCOMPARE(m_dataset->seriesIndex(series1),-1); |
|
347 | 348 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
348 | 349 | |
|
349 | 350 | m_dataset->addSeries(series0, axis0); |
|
350 | 351 | m_dataset->addSeries(series1, axis1); |
|
351 | 352 | m_dataset->addSeries(series2, axis2); |
|
352 | 353 | |
|
353 | 354 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
354 | 355 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
355 | 356 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
356 | 357 | |
|
357 | 358 | m_dataset->removeSeries(series1); |
|
358 | 359 | |
|
359 | 360 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
360 | 361 | QCOMPARE(m_dataset->seriesIndex(series1),-1); |
|
361 | 362 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
362 | 363 | |
|
363 | 364 | m_dataset->addSeries(series1, axis1); |
|
364 | 365 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
365 | 366 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
366 | 367 | QCOMPARE(m_dataset->seriesIndex(series2),2); |
|
367 | 368 | |
|
368 | 369 | m_dataset->removeSeries(series2); |
|
369 | 370 | QCOMPARE(m_dataset->seriesIndex(series0),0); |
|
370 | 371 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
371 | 372 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
372 | 373 | |
|
373 | 374 | m_dataset->removeSeries(series0); |
|
374 | 375 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
375 | 376 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
376 | 377 | QCOMPARE(m_dataset->seriesIndex(series2),-1); |
|
377 | 378 | |
|
378 | 379 | m_dataset->addSeries(series2); |
|
379 | 380 | QCOMPARE(m_dataset->seriesIndex(series0),-1); |
|
380 | 381 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
381 | 382 | QCOMPARE(m_dataset->seriesIndex(series2),0); |
|
382 | 383 | |
|
383 | 384 | m_dataset->addSeries(series0); |
|
384 | 385 | QCOMPARE(m_dataset->seriesIndex(series0),2); |
|
385 | 386 | QCOMPARE(m_dataset->seriesIndex(series1),1); |
|
386 | 387 | QCOMPARE(m_dataset->seriesIndex(series2),0); |
|
387 | 388 | } |
|
388 | 389 | |
|
389 | 390 | void tst_ChartDataSet::domain_data() |
|
390 | 391 | { |
|
391 | 392 | addSeries_data(); |
|
392 | 393 | } |
|
393 | 394 | |
|
394 | 395 | void tst_ChartDataSet::domain() |
|
395 | 396 | { |
|
396 | 397 | QFETCH(QLineSeries*, series0); |
|
397 | 398 | QFETCH(QAxis*, axis0); |
|
398 | 399 | QFETCH(QLineSeries*, series1); |
|
399 | 400 | QFETCH(QAxis*, axis1); |
|
400 | 401 | QFETCH(QLineSeries*, series2); |
|
401 | 402 | QFETCH(QAxis*, axis2); |
|
402 | 403 | QFETCH(int, axisCount); |
|
403 | 404 | Q_UNUSED(axisCount); |
|
404 | 405 | |
|
405 | 406 | m_dataset->addSeries(series0, axis0); |
|
406 | 407 | m_dataset->addSeries(series1, axis1); |
|
407 | 408 | m_dataset->addSeries(series2, axis2); |
|
408 | 409 | |
|
409 | 410 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
410 | 411 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
411 | 412 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
412 | 413 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
413 | 414 | |
|
414 | 415 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); |
|
415 | 416 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); |
|
416 | 417 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); |
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
418 | TRY_COMPARE(spy0.count(), 0); | |
|
419 | TRY_COMPARE(spy1.count(), 0); | |
|
420 | TRY_COMPARE(spy2.count(), 0); | |
|
421 | TRY_COMPARE(spy3.count(), 0); | |
|
421 | 422 | } |
|
422 | 423 | |
|
423 | 424 | void tst_ChartDataSet::zoomInDomain_data() |
|
424 | 425 | { |
|
425 | 426 | addSeries_data(); |
|
426 | 427 | } |
|
427 | 428 | |
|
428 | 429 | void tst_ChartDataSet::zoomInDomain() |
|
429 | 430 | { |
|
430 | 431 | QFETCH(QLineSeries*, series0); |
|
431 | 432 | QFETCH(QAxis*, axis0); |
|
432 | 433 | QFETCH(QLineSeries*, series1); |
|
433 | 434 | QFETCH(QAxis*, axis1); |
|
434 | 435 | QFETCH(QLineSeries*, series2); |
|
435 | 436 | QFETCH(QAxis*, axis2); |
|
436 | 437 | QFETCH(int, axisCount); |
|
437 | 438 | Q_UNUSED(axisCount); |
|
438 | 439 | |
|
439 | 440 | m_dataset->addSeries(series0, axis0); |
|
440 | 441 | m_dataset->addSeries(series1, axis1); |
|
441 | 442 | m_dataset->addSeries(series2, axis2); |
|
442 | 443 | |
|
443 | 444 | Domain* domain0 = m_dataset->domain(series0); |
|
444 | 445 | Domain* domain1 = m_dataset->domain(series1); |
|
445 | 446 | Domain* domain2 = m_dataset->domain(series2); |
|
446 | 447 | |
|
447 | 448 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
448 | 449 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
449 | 450 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
450 | 451 | |
|
451 | 452 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
452 | 453 | |
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
|
454 | TRY_COMPARE(spy0.count(), 1); | |
|
455 | TRY_COMPARE(spy1.count(), 1); | |
|
456 | TRY_COMPARE(spy2.count(), 1); | |
|
456 | 457 | } |
|
457 | 458 | |
|
458 | 459 | void tst_ChartDataSet::zoomOutDomain_data() |
|
459 | 460 | { |
|
460 | 461 | addSeries_data(); |
|
461 | 462 | } |
|
462 | 463 | |
|
463 | 464 | void tst_ChartDataSet::zoomOutDomain() |
|
464 | 465 | { |
|
465 | 466 | QFETCH(QLineSeries*, series0); |
|
466 | 467 | QFETCH(QAxis*, axis0); |
|
467 | 468 | QFETCH(QLineSeries*, series1); |
|
468 | 469 | QFETCH(QAxis*, axis1); |
|
469 | 470 | QFETCH(QLineSeries*, series2); |
|
470 | 471 | QFETCH(QAxis*, axis2); |
|
471 | 472 | QFETCH(int, axisCount); |
|
472 | 473 | |
|
473 | 474 | Q_UNUSED(axisCount); |
|
474 | 475 | |
|
475 | 476 | m_dataset->addSeries(series0, axis0); |
|
476 | 477 | m_dataset->addSeries(series1, axis1); |
|
477 | 478 | m_dataset->addSeries(series2, axis2); |
|
478 | 479 | |
|
479 | 480 | Domain* domain0 = m_dataset->domain(series0); |
|
480 | 481 | Domain* domain1 = m_dataset->domain(series1); |
|
481 | 482 | Domain* domain2 = m_dataset->domain(series2); |
|
482 | 483 | |
|
483 | 484 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
484 | 485 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
485 | 486 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
486 | 487 | |
|
487 | 488 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
488 | 489 | |
|
489 |
|
|
|
490 |
|
|
|
491 |
|
|
|
490 | TRY_COMPARE(spy0.count(), 1); | |
|
491 | TRY_COMPARE(spy1.count(), 1); | |
|
492 | TRY_COMPARE(spy2.count(), 1); | |
|
492 | 493 | } |
|
493 | 494 | |
|
494 | 495 | void tst_ChartDataSet::scrollDomain_data() |
|
495 | 496 | { |
|
496 | 497 | addSeries_data(); |
|
497 | 498 | } |
|
498 | 499 | |
|
499 | 500 | void tst_ChartDataSet::scrollDomain() |
|
500 | 501 | { |
|
501 | 502 | QFETCH(QLineSeries*, series0); |
|
502 | 503 | QFETCH(QAxis*, axis0); |
|
503 | 504 | QFETCH(QLineSeries*, series1); |
|
504 | 505 | QFETCH(QAxis*, axis1); |
|
505 | 506 | QFETCH(QLineSeries*, series2); |
|
506 | 507 | QFETCH(QAxis*, axis2); |
|
507 | 508 | QFETCH(int, axisCount); |
|
508 | 509 | |
|
509 | 510 | Q_UNUSED(axisCount); |
|
510 | 511 | |
|
511 | 512 | m_dataset->addSeries(series0, axis0); |
|
512 | 513 | m_dataset->addSeries(series1, axis1); |
|
513 | 514 | m_dataset->addSeries(series2, axis2); |
|
514 | 515 | |
|
515 | 516 | Domain* domain0 = m_dataset->domain(series0); |
|
516 | 517 | Domain* domain1 = m_dataset->domain(series1); |
|
517 | 518 | Domain* domain2 = m_dataset->domain(series2); |
|
518 | 519 | |
|
519 | 520 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
520 | 521 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
521 | 522 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
522 | 523 | |
|
523 | 524 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
524 | 525 | |
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
|
526 | TRY_COMPARE(spy0.count(), 1); | |
|
527 | TRY_COMPARE(spy1.count(), 1); | |
|
528 | TRY_COMPARE(spy2.count(), 1); | |
|
528 | 529 | } |
|
529 | 530 | |
|
530 | 531 | QTEST_MAIN(tst_ChartDataSet) |
|
531 | 532 | #include "tst_chartdataset.moc" |
|
532 | 533 |
@@ -1,712 +1,712 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <private/domain_p.h> |
|
23 | 23 | #include <qaxis.h> |
|
24 | #include <tst_definitions.h> | |
|
24 | 25 | |
|
25 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 27 | |
|
27 | 28 | Q_DECLARE_METATYPE(Domain*) |
|
28 | 29 | Q_DECLARE_METATYPE(QSizeF) |
|
29 | 30 | |
|
30 | 31 | class tst_Domain: public QObject |
|
31 | 32 | { |
|
32 | 33 | Q_OBJECT |
|
33 | 34 | |
|
34 | 35 | public Q_SLOTS: |
|
35 | 36 | void initTestCase(); |
|
36 | 37 | void cleanupTestCase(); |
|
37 | 38 | void init(); |
|
38 | 39 | void cleanup(); |
|
39 | 40 | |
|
40 | 41 | private Q_SLOTS: |
|
41 | 42 | void domain(); |
|
42 | 43 | void handleAxisRangeXChanged_data(); |
|
43 | 44 | void handleAxisRangeXChanged(); |
|
44 | 45 | void handleAxisRangeYChanged_data(); |
|
45 | 46 | void handleAxisRangeYChanged(); |
|
46 | 47 | void isEmpty_data(); |
|
47 | 48 | void isEmpty(); |
|
48 | 49 | void maxX_data(); |
|
49 | 50 | void maxX(); |
|
50 | 51 | void maxY_data(); |
|
51 | 52 | void maxY(); |
|
52 | 53 | void minX_data(); |
|
53 | 54 | void minX(); |
|
54 | 55 | void minY_data(); |
|
55 | 56 | void minY(); |
|
56 | 57 | void operatorEquals_data(); |
|
57 | 58 | void operatorEquals(); |
|
58 | 59 | void setRange_data(); |
|
59 | 60 | void setRange(); |
|
60 | 61 | void setRangeX_data(); |
|
61 | 62 | void setRangeX(); |
|
62 | 63 | void setRangeY_data(); |
|
63 | 64 | void setRangeY(); |
|
64 | 65 | void spanX_data(); |
|
65 | 66 | void spanX(); |
|
66 | 67 | void spanY_data(); |
|
67 | 68 | void spanY(); |
|
68 | 69 | void zoom_data(); |
|
69 | 70 | void zoom(); |
|
70 | 71 | void move_data(); |
|
71 | 72 | void move(); |
|
72 | 73 | void handleAxisXChanged_data(); |
|
73 | 74 | void handleAxisXChanged(); |
|
74 | 75 | void handleAxisYChanged_data(); |
|
75 | 76 | void handleAxisYChanged(); |
|
76 | 77 | }; |
|
77 | 78 | |
|
78 | 79 | void tst_Domain::initTestCase() |
|
79 | 80 | { |
|
80 | 81 | } |
|
81 | 82 | |
|
82 | 83 | void tst_Domain::cleanupTestCase() |
|
83 | 84 | { |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | void tst_Domain::init() |
|
87 | 88 | { |
|
88 | 89 | } |
|
89 | 90 | |
|
90 | 91 | void tst_Domain::cleanup() |
|
91 | 92 | { |
|
92 | 93 | } |
|
93 | 94 | |
|
94 | 95 | void tst_Domain::domain() |
|
95 | 96 | { |
|
96 | 97 | Domain domain; |
|
97 | 98 | |
|
98 | 99 | QCOMPARE(domain.isEmpty(), true); |
|
99 | 100 | QCOMPARE(domain.maxX(), 0.0); |
|
100 | 101 | QCOMPARE(domain.maxY(), 0.0); |
|
101 | 102 | QCOMPARE(domain.minX(), 0.0); |
|
102 | 103 | QCOMPARE(domain.minY(), 0.0); |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | void tst_Domain::handleAxisRangeXChanged_data() |
|
106 | 107 | { |
|
107 | 108 | QTest::addColumn<qreal>("min"); |
|
108 | 109 | QTest::addColumn<qreal>("max"); |
|
109 | 110 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
110 | 111 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
111 | 112 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
112 | 113 | } |
|
113 | 114 | |
|
114 | 115 | void tst_Domain::handleAxisRangeXChanged() |
|
115 | 116 | { |
|
116 | 117 | QFETCH(qreal, min); |
|
117 | 118 | QFETCH(qreal, max); |
|
118 | 119 | |
|
119 | 120 | Domain domain; |
|
120 | 121 | |
|
121 | 122 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
122 | 123 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
123 | 124 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
124 | 125 | |
|
125 | 126 | domain.handleAxisXChanged(min, max); |
|
126 | 127 | |
|
127 | 128 | QList<QVariant> arg0 = spy0.first(); |
|
128 | 129 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
129 | 130 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
130 | 131 | |
|
131 | 132 | QList<QVariant> arg1 = spy1.first(); |
|
132 | 133 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
133 | 134 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
134 | 135 | |
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
136 | TRY_COMPARE(spy0.count(), 1); | |
|
137 | TRY_COMPARE(spy1.count(), 1); | |
|
138 | TRY_COMPARE(spy2.count(), 0); | |
|
138 | 139 | |
|
139 | 140 | } |
|
140 | 141 | |
|
141 | 142 | void tst_Domain::handleAxisRangeYChanged_data() |
|
142 | 143 | { |
|
143 | 144 | QTest::addColumn<qreal>("min"); |
|
144 | 145 | QTest::addColumn<qreal>("max"); |
|
145 | 146 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
146 | 147 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
147 | 148 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
148 | 149 | } |
|
149 | 150 | |
|
150 | 151 | void tst_Domain::handleAxisRangeYChanged() |
|
151 | 152 | { |
|
152 | 153 | QFETCH(qreal, min); |
|
153 | 154 | QFETCH(qreal, max); |
|
154 | 155 | |
|
155 | 156 | Domain domain; |
|
156 | 157 | |
|
157 | 158 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
158 | 159 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
159 | 160 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
160 | 161 | |
|
161 | 162 | domain.handleAxisYChanged(min, max, 5); |
|
162 | 163 | |
|
163 | 164 | QList<QVariant> arg0 = spy0.first(); |
|
164 | 165 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
165 | 166 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
166 | 167 | |
|
167 | 168 | QList<QVariant> arg1 = spy2.first(); |
|
168 | 169 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
169 | 170 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
170 | 171 | |
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
172 | TRY_COMPARE(spy0.count(), 1); | |
|
173 | TRY_COMPARE(spy1.count(), 0); | |
|
174 | TRY_COMPARE(spy2.count(), 1); | |
|
174 | 175 | } |
|
175 | 176 | |
|
176 | 177 | void tst_Domain::isEmpty_data() |
|
177 | 178 | { |
|
178 | 179 | QTest::addColumn<qreal>("minX"); |
|
179 | 180 | QTest::addColumn<qreal>("maxX"); |
|
180 | 181 | QTest::addColumn<qreal>("minY"); |
|
181 | 182 | QTest::addColumn<qreal>("maxY"); |
|
182 | 183 | QTest::addColumn<bool>("isEmpty"); |
|
183 | 184 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; |
|
184 | 185 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
185 | 186 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; |
|
186 | 187 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; |
|
187 | 188 | } |
|
188 | 189 | |
|
189 | 190 | void tst_Domain::isEmpty() |
|
190 | 191 | { |
|
191 | 192 | QFETCH(qreal, minX); |
|
192 | 193 | QFETCH(qreal, maxX); |
|
193 | 194 | QFETCH(qreal, minY); |
|
194 | 195 | QFETCH(qreal, maxY); |
|
195 | 196 | QFETCH(bool, isEmpty); |
|
196 | 197 | |
|
197 | 198 | Domain domain; |
|
198 | 199 | domain.setRange(minX, maxX, minY, maxY); |
|
199 | 200 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
200 | 201 | } |
|
201 | 202 | |
|
202 | 203 | void tst_Domain::maxX_data() |
|
203 | 204 | { |
|
204 | 205 | QTest::addColumn<qreal>("maxX1"); |
|
205 | 206 | QTest::addColumn<qreal>("maxX2"); |
|
206 | 207 | QTest::addColumn<int>("count"); |
|
207 | 208 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
208 | 209 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
209 | 210 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
210 | 211 | } |
|
211 | 212 | |
|
212 | 213 | void tst_Domain::maxX() |
|
213 | 214 | { |
|
214 | 215 | QFETCH(qreal, maxX1); |
|
215 | 216 | QFETCH(qreal, maxX2); |
|
216 | 217 | QFETCH(int, count); |
|
217 | 218 | |
|
218 | 219 | Domain domain; |
|
219 | 220 | |
|
220 | 221 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
221 | 222 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
222 | 223 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
223 | 224 | |
|
224 | 225 | domain.setMaxX(maxX1); |
|
225 | 226 | QCOMPARE(domain.maxX(), maxX1); |
|
226 | 227 | domain.setMaxX(maxX2); |
|
227 | 228 | QCOMPARE(domain.maxX(), maxX2); |
|
228 | 229 | |
|
229 |
|
|
|
230 |
|
|
|
231 |
|
|
|
230 | TRY_COMPARE(spy0.count(), count); | |
|
231 | TRY_COMPARE(spy1.count(), count); | |
|
232 | TRY_COMPARE(spy2.count(), 0); | |
|
232 | 233 | |
|
233 | 234 | } |
|
234 | 235 | |
|
235 | 236 | void tst_Domain::maxY_data() |
|
236 | 237 | { |
|
237 | 238 | QTest::addColumn<qreal>("maxY1"); |
|
238 | 239 | QTest::addColumn<qreal>("maxY2"); |
|
239 | 240 | QTest::addColumn<int>("count"); |
|
240 | 241 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
241 | 242 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
242 | 243 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
243 | 244 | } |
|
244 | 245 | |
|
245 | 246 | void tst_Domain::maxY() |
|
246 | 247 | { |
|
247 | 248 | QFETCH(qreal, maxY1); |
|
248 | 249 | QFETCH(qreal, maxY2); |
|
249 | 250 | QFETCH(int, count); |
|
250 | 251 | |
|
251 | 252 | Domain domain; |
|
252 | 253 | |
|
253 | 254 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
254 | 255 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
255 | 256 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
256 | 257 | |
|
257 | 258 | domain.setMaxY(maxY1); |
|
258 | 259 | QCOMPARE(domain.maxY(), maxY1); |
|
259 | 260 | domain.setMaxY(maxY2); |
|
260 | 261 | QCOMPARE(domain.maxY(), maxY2); |
|
261 | 262 | |
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
263 | TRY_COMPARE(spy0.count(), count); | |
|
264 | TRY_COMPARE(spy1.count(), 0); | |
|
265 | TRY_COMPARE(spy2.count(), count); | |
|
265 | 266 | } |
|
266 | 267 | |
|
267 | 268 | void tst_Domain::minX_data() |
|
268 | 269 | { |
|
269 | 270 | QTest::addColumn<qreal>("minX1"); |
|
270 | 271 | QTest::addColumn<qreal>("minX2"); |
|
271 | 272 | QTest::addColumn<int>("count"); |
|
272 | 273 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
273 | 274 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
274 | 275 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
275 | 276 | } |
|
276 | 277 | |
|
277 | 278 | void tst_Domain::minX() |
|
278 | 279 | { |
|
279 | 280 | QFETCH(qreal, minX1); |
|
280 | 281 | QFETCH(qreal, minX2); |
|
281 | 282 | QFETCH(int, count); |
|
282 | 283 | |
|
283 | 284 | Domain domain; |
|
284 | 285 | |
|
285 | 286 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
286 | 287 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
287 | 288 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
288 | 289 | |
|
289 | 290 | domain.setMinX(minX1); |
|
290 | 291 | QCOMPARE(domain.minX(), minX1); |
|
291 | 292 | domain.setMinX(minX2); |
|
292 | 293 | QCOMPARE(domain.minX(), minX2); |
|
293 | 294 | |
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
295 | TRY_COMPARE(spy0.count(), count); | |
|
296 | TRY_COMPARE(spy1.count(), count); | |
|
297 | TRY_COMPARE(spy2.count(), 0); | |
|
297 | 298 | } |
|
298 | 299 | |
|
299 | 300 | void tst_Domain::minY_data() |
|
300 | 301 | { |
|
301 | 302 | QTest::addColumn<qreal>("minY1"); |
|
302 | 303 | QTest::addColumn<qreal>("minY2"); |
|
303 | 304 | QTest::addColumn<int>("count"); |
|
304 | 305 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
305 | 306 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
306 | 307 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
307 | 308 | } |
|
308 | 309 | |
|
309 | 310 | void tst_Domain::minY() |
|
310 | 311 | { |
|
311 | 312 | QFETCH(qreal, minY1); |
|
312 | 313 | QFETCH(qreal, minY2); |
|
313 | 314 | QFETCH(int, count); |
|
314 | 315 | |
|
315 | 316 | Domain domain; |
|
316 | 317 | |
|
317 | 318 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
318 | 319 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
319 | 320 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
320 | 321 | |
|
321 | 322 | domain.setMinY(minY1); |
|
322 | 323 | QCOMPARE(domain.minY(), minY1); |
|
323 | 324 | domain.setMinY(minY2); |
|
324 | 325 | QCOMPARE(domain.minY(), minY2); |
|
325 | 326 | |
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
327 | TRY_COMPARE(spy0.count(), count); | |
|
328 | TRY_COMPARE(spy1.count(), 0); | |
|
329 | TRY_COMPARE(spy2.count(), count); | |
|
329 | 330 | } |
|
330 | 331 | |
|
331 | 332 | void tst_Domain::operatorEquals_data() |
|
332 | 333 | { |
|
333 | 334 | |
|
334 | 335 | QTest::addColumn<Domain*>("domain1"); |
|
335 | 336 | QTest::addColumn<Domain*>("domain2"); |
|
336 | 337 | QTest::addColumn<bool>("equals"); |
|
337 | 338 | QTest::addColumn<bool>("notEquals"); |
|
338 | 339 | Domain* a; |
|
339 | 340 | Domain* b; |
|
340 | 341 | a = new Domain(); |
|
341 | 342 | a->setRange(0, 100, 0, 100); |
|
342 | 343 | b = new Domain(); |
|
343 | 344 | b->setRange(0, 100, 0, 100); |
|
344 | 345 | QTest::newRow("equals") << a << b << true << false; |
|
345 | 346 | a = new Domain(); |
|
346 | 347 | a->setRange(0, 100, 0, 100); |
|
347 | 348 | b = new Domain(); |
|
348 | 349 | b->setRange(0, 100, 0, 1); |
|
349 | 350 | QTest::newRow("equals") << a << b << false << true; |
|
350 | 351 | a = new Domain(); |
|
351 | 352 | a->setRange(0, 100, 0, 100); |
|
352 | 353 | b = new Domain(); |
|
353 | 354 | b->setRange(0, 1, 0, 100); |
|
354 | 355 | QTest::newRow("equals") << a << b << false << true; |
|
355 | 356 | |
|
356 | 357 | } |
|
357 | 358 | |
|
358 | 359 | void tst_Domain::operatorEquals() |
|
359 | 360 | { |
|
360 | 361 | QFETCH(Domain*, domain1); |
|
361 | 362 | QFETCH(Domain*, domain2); |
|
362 | 363 | QFETCH(bool, equals); |
|
363 | 364 | QFETCH(bool, notEquals); |
|
364 | 365 | |
|
365 | 366 | Domain domain; |
|
366 | 367 | |
|
367 | 368 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
368 | 369 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
369 | 370 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
370 | 371 | |
|
371 | 372 | QCOMPARE(*domain1==*domain2, equals); |
|
372 | 373 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
373 | 374 | |
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
375 | TRY_COMPARE(spy0.count(), 0); | |
|
376 | TRY_COMPARE(spy1.count(), 0); | |
|
377 | TRY_COMPARE(spy2.count(), 0); | |
|
377 | 378 | } |
|
378 | 379 | |
|
379 | 380 | void tst_Domain::setRange_data() |
|
380 | 381 | { |
|
381 | 382 | QTest::addColumn<qreal>("minX"); |
|
382 | 383 | QTest::addColumn<qreal>("maxX"); |
|
383 | 384 | QTest::addColumn<qreal>("minY"); |
|
384 | 385 | QTest::addColumn<qreal>("maxY"); |
|
385 | 386 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
386 | 387 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
387 | 388 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
388 | 389 | } |
|
389 | 390 | |
|
390 | 391 | void tst_Domain::setRange() |
|
391 | 392 | { |
|
392 | 393 | QFETCH(qreal, minX); |
|
393 | 394 | QFETCH(qreal, maxX); |
|
394 | 395 | QFETCH(qreal, minY); |
|
395 | 396 | QFETCH(qreal, maxY); |
|
396 | 397 | |
|
397 | 398 | Domain domain; |
|
398 | 399 | |
|
399 | 400 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
400 | 401 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
401 | 402 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
402 | 403 | |
|
403 | 404 | domain.setRange(minX, maxX, minY, maxY); |
|
404 | 405 | |
|
405 | 406 | QCOMPARE(domain.minX(), minX); |
|
406 | 407 | QCOMPARE(domain.maxX(), maxX); |
|
407 | 408 | QCOMPARE(domain.minY(), minY); |
|
408 | 409 | QCOMPARE(domain.maxY(), maxY); |
|
409 | 410 | |
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
411 | TRY_COMPARE(spy0.count(), 1); | |
|
412 | TRY_COMPARE(spy1.count(), 1); | |
|
413 | TRY_COMPARE(spy2.count(), 1); | |
|
413 | 414 | |
|
414 | 415 | } |
|
415 | 416 | |
|
416 | 417 | void tst_Domain::setRangeX_data() |
|
417 | 418 | { |
|
418 | 419 | QTest::addColumn<qreal>("min"); |
|
419 | 420 | QTest::addColumn<qreal>("max"); |
|
420 | 421 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
421 | 422 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
422 | 423 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
423 | 424 | } |
|
424 | 425 | |
|
425 | 426 | void tst_Domain::setRangeX() |
|
426 | 427 | { |
|
427 | 428 | QFETCH(qreal, min); |
|
428 | 429 | QFETCH(qreal, max); |
|
429 | 430 | |
|
430 | 431 | Domain domain; |
|
431 | 432 | |
|
432 | 433 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
433 | 434 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
434 | 435 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
435 | 436 | |
|
436 | 437 | domain.setRangeX(min, max); |
|
437 | 438 | |
|
438 | 439 | QList<QVariant> arg0 = spy0.first(); |
|
439 | 440 | QVERIFY(qFuzzyIsNull(arg0.at(0).toReal() - min)); |
|
440 | 441 | QVERIFY(qFuzzyIsNull(arg0.at(1).toReal() - max)); |
|
441 | 442 | |
|
442 | 443 | QList<QVariant> arg1 = spy1.first(); |
|
443 | 444 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
444 | 445 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
445 | 446 | |
|
446 |
|
|
|
447 |
|
|
|
448 |
|
|
|
447 | TRY_COMPARE(spy0.count(), 1); | |
|
448 | TRY_COMPARE(spy1.count(), 1); | |
|
449 | TRY_COMPARE(spy2.count(), 0); | |
|
449 | 450 | } |
|
450 | 451 | |
|
451 | 452 | void tst_Domain::setRangeY_data() |
|
452 | 453 | { |
|
453 | 454 | QTest::addColumn<qreal>("min"); |
|
454 | 455 | QTest::addColumn<qreal>("max"); |
|
455 | 456 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
456 | 457 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
457 | 458 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
458 | 459 | } |
|
459 | 460 | |
|
460 | 461 | void tst_Domain::setRangeY() |
|
461 | 462 | { |
|
462 | 463 | QFETCH(qreal, min); |
|
463 | 464 | QFETCH(qreal, max); |
|
464 | 465 | |
|
465 | 466 | Domain domain; |
|
466 | 467 | |
|
467 | 468 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
468 | 469 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
469 | 470 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
470 | 471 | |
|
471 | 472 | domain.setRangeY(min, max); |
|
472 | 473 | |
|
473 | 474 | QList<QVariant> arg0 = spy0.first(); |
|
474 | 475 | QVERIFY(qFuzzyIsNull(arg0.at(2).toReal() - min)); |
|
475 | 476 | QVERIFY(qFuzzyIsNull(arg0.at(3).toReal() - max)); |
|
476 | 477 | |
|
477 | 478 | QList<QVariant> arg1 = spy2.first(); |
|
478 | 479 | QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min)); |
|
479 | 480 | QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max)); |
|
480 | 481 | |
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
|
482 | TRY_COMPARE(spy0.count(), 1); | |
|
483 | TRY_COMPARE(spy1.count(), 0); | |
|
484 | TRY_COMPARE(spy2.count(), 1); | |
|
484 | 485 | } |
|
485 | 486 | |
|
486 | 487 | void tst_Domain::spanX_data() |
|
487 | 488 | { |
|
488 | 489 | QTest::addColumn<qreal>("minX"); |
|
489 | 490 | QTest::addColumn<qreal>("maxX"); |
|
490 | 491 | QTest::addColumn<qreal>("spanX"); |
|
491 | 492 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
492 | 493 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
493 | 494 | } |
|
494 | 495 | |
|
495 | 496 | void tst_Domain::spanX() |
|
496 | 497 | { |
|
497 | 498 | QFETCH(qreal, minX); |
|
498 | 499 | QFETCH(qreal, maxX); |
|
499 | 500 | QFETCH(qreal, spanX); |
|
500 | 501 | |
|
501 | 502 | Domain domain; |
|
502 | 503 | |
|
503 | 504 | domain.setRangeX(minX, maxX); |
|
504 | 505 | |
|
505 | 506 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
506 | 507 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
507 | 508 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
508 | 509 | |
|
509 | 510 | QCOMPARE(domain.spanX(), spanX); |
|
510 | 511 | |
|
511 |
|
|
|
512 |
|
|
|
513 |
|
|
|
512 | TRY_COMPARE(spy0.count(), 0); | |
|
513 | TRY_COMPARE(spy1.count(), 0); | |
|
514 | TRY_COMPARE(spy2.count(), 0); | |
|
514 | 515 | } |
|
515 | 516 | |
|
516 | 517 | void tst_Domain::spanY_data() |
|
517 | 518 | { |
|
518 | 519 | QTest::addColumn<qreal>("minY"); |
|
519 | 520 | QTest::addColumn<qreal>("maxY"); |
|
520 | 521 | QTest::addColumn<qreal>("spanY"); |
|
521 | 522 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
522 | 523 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
523 | 524 | } |
|
524 | 525 | |
|
525 | 526 | void tst_Domain::spanY() |
|
526 | 527 | { |
|
527 | 528 | QFETCH(qreal, minY); |
|
528 | 529 | QFETCH(qreal, maxY); |
|
529 | 530 | QFETCH(qreal, spanY); |
|
530 | 531 | |
|
531 | 532 | Domain domain; |
|
532 | 533 | |
|
533 | 534 | domain.setRangeY(minY, maxY); |
|
534 | 535 | |
|
535 | 536 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
536 | 537 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
537 | 538 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
538 | 539 | |
|
539 | 540 | QCOMPARE(domain.spanY(), spanY); |
|
540 | 541 | |
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
542 | TRY_COMPARE(spy0.count(), 0); | |
|
543 | TRY_COMPARE(spy1.count(), 0); | |
|
544 | TRY_COMPARE(spy2.count(), 0); | |
|
544 | 545 | } |
|
545 | 546 | |
|
546 | 547 | void tst_Domain::zoom_data() |
|
547 | 548 | { |
|
548 | 549 | QTest::addColumn<QRectF>("rect0"); |
|
549 | 550 | QTest::addColumn<QSizeF>("size0"); |
|
550 | 551 | QTest::addColumn<QRectF>("rect1"); |
|
551 | 552 | QTest::addColumn<QSizeF>("size1"); |
|
552 | 553 | QTest::addColumn<QRectF>("rect2"); |
|
553 | 554 | QTest::addColumn<QSizeF>("size2"); |
|
554 | 555 | QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000) |
|
555 | 556 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
556 | 557 | << QSizeF(1000, 1000); |
|
557 | 558 | QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000) |
|
558 | 559 | << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100) |
|
559 | 560 | << QSizeF(1000, 1000); |
|
560 | 561 | QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20) |
|
561 | 562 | << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100); |
|
562 | 563 | } |
|
563 | 564 | |
|
564 | 565 | void tst_Domain::zoom() |
|
565 | 566 | { |
|
566 | 567 | QFETCH(QRectF, rect0); |
|
567 | 568 | QFETCH(QSizeF, size0); |
|
568 | 569 | QFETCH(QRectF, rect1); |
|
569 | 570 | QFETCH(QSizeF, size1); |
|
570 | 571 | QFETCH(QRectF, rect2); |
|
571 | 572 | QFETCH(QSizeF, size2); |
|
572 | 573 | |
|
573 | 574 | Domain domain; |
|
574 | 575 | |
|
575 | 576 | domain.setRange(0, 1000, 0, 1000); |
|
576 | 577 | |
|
577 | 578 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
578 | 579 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
579 | 580 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
580 | 581 | |
|
581 | 582 | Domain domain0; |
|
582 | 583 | domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
583 | 584 | domain.zoomIn(rect0, size0); |
|
584 | 585 | Domain domain1; |
|
585 | 586 | domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
586 | 587 | domain.zoomIn(rect1, size1); |
|
587 | 588 | Domain domain2; |
|
588 | 589 | domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY()); |
|
589 | 590 | domain.zoomIn(rect2, size2); |
|
590 | 591 | domain.zoomOut(rect2, size2); |
|
591 | 592 | QCOMPARE(domain == domain2, true); |
|
592 | 593 | domain.zoomOut(rect1, size1); |
|
593 | 594 | QCOMPARE(domain == domain1, true); |
|
594 | 595 | domain.zoomOut(rect0, size0); |
|
595 | 596 | QCOMPARE(domain == domain0, true); |
|
596 |
|
|
|
597 |
|
|
|
598 |
|
|
|
599 | ||
|
597 | TRY_COMPARE(spy0.count(), 6); | |
|
598 | TRY_COMPARE(spy1.count(), 6); | |
|
599 | TRY_COMPARE(spy2.count(), 6); | |
|
600 | 600 | } |
|
601 | 601 | |
|
602 | 602 | void tst_Domain::move_data() |
|
603 | 603 | { |
|
604 | 604 | QTest::addColumn<int>("dx"); |
|
605 | 605 | QTest::addColumn<int>("dy"); |
|
606 | 606 | QTest::addColumn<QSizeF>("size"); |
|
607 | 607 | QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000); |
|
608 | 608 | QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000); |
|
609 | 609 | QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000); |
|
610 | 610 | QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000); |
|
611 | 611 | QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000); |
|
612 | 612 | QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000); |
|
613 | 613 | } |
|
614 | 614 | |
|
615 | 615 | void tst_Domain::move() |
|
616 | 616 | { |
|
617 | 617 | QFETCH(int, dx); |
|
618 | 618 | QFETCH(int, dy); |
|
619 | 619 | QFETCH(QSizeF, size); |
|
620 | 620 | Domain domain; |
|
621 | 621 | |
|
622 | 622 | domain.setRange(0, size.width(), 0, size.height()); |
|
623 | 623 | |
|
624 | 624 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
625 | 625 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
626 | 626 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
627 | 627 | |
|
628 | 628 | domain.move(dx, dy, size); |
|
629 | 629 | |
|
630 | 630 | Domain result; |
|
631 | 631 | result.setRange(dx, size.width() + dx, dy, size.height() + dy); |
|
632 | 632 | |
|
633 | 633 | QCOMPARE(domain == result, true); |
|
634 |
|
|
|
635 |
|
|
|
636 |
|
|
|
634 | TRY_COMPARE(spy0.count(), 1); | |
|
635 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); | |
|
636 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); | |
|
637 | 637 | } |
|
638 | 638 | |
|
639 | 639 | void tst_Domain::handleAxisXChanged_data() |
|
640 | 640 | { |
|
641 | 641 | QTest::addColumn<qreal>("min"); |
|
642 | 642 | QTest::addColumn<qreal>("max"); |
|
643 | 643 | QTest::addColumn<int>("tickCount"); |
|
644 | 644 | QTest::addColumn<bool>("niceNumbers"); |
|
645 | 645 | QTest::addColumn<qreal>("resultMin"); |
|
646 | 646 | QTest::addColumn<qreal>("resultMax"); |
|
647 | 647 | QTest::addColumn<int>("resultTickCount"); |
|
648 | 648 | QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5; |
|
649 | 649 | QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6; |
|
650 | 650 | QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6; |
|
651 | 651 | QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6; |
|
652 | 652 | } |
|
653 | 653 | |
|
654 | 654 | void tst_Domain::handleAxisXChanged() |
|
655 | 655 | { |
|
656 | 656 | QFETCH(qreal, min); |
|
657 | 657 | QFETCH(qreal, max); |
|
658 | 658 | QFETCH(int, tickCount); |
|
659 | 659 | QFETCH(bool, niceNumbers); |
|
660 | 660 | QFETCH(qreal, resultMin); |
|
661 | 661 | QFETCH(qreal, resultMax); |
|
662 | 662 | QFETCH(int, resultTickCount); |
|
663 | 663 | |
|
664 | 664 | Domain domain; |
|
665 | 665 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
666 | 666 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
667 | 667 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
668 | 668 | |
|
669 | 669 | domain.handleAxisXChanged(min, max, tickCount, niceNumbers); |
|
670 | 670 | |
|
671 | 671 | QCOMPARE(resultMin, domain.minX()); |
|
672 | 672 | QCOMPARE(resultMax, domain.maxX()); |
|
673 | 673 | QCOMPARE(resultTickCount, domain.tickXCount()); |
|
674 |
|
|
|
675 |
|
|
|
676 |
|
|
|
674 | TRY_COMPARE(spy0.count(), 1); | |
|
675 | TRY_COMPARE(spy1.count(), 1); | |
|
676 | TRY_COMPARE(spy2.count(), 0); | |
|
677 | 677 | |
|
678 | 678 | } |
|
679 | 679 | |
|
680 | 680 | void tst_Domain::handleAxisYChanged_data() |
|
681 | 681 | { |
|
682 | 682 | handleAxisXChanged_data(); |
|
683 | 683 | } |
|
684 | 684 | |
|
685 | 685 | void tst_Domain::handleAxisYChanged() |
|
686 | 686 | { |
|
687 | 687 | QFETCH(qreal, min); |
|
688 | 688 | QFETCH(qreal, max); |
|
689 | 689 | QFETCH(int, tickCount); |
|
690 | 690 | QFETCH(bool, niceNumbers); |
|
691 | 691 | QFETCH(qreal, resultMin); |
|
692 | 692 | QFETCH(qreal, resultMax); |
|
693 | 693 | QFETCH(int, resultTickCount); |
|
694 | 694 | |
|
695 | 695 | Domain domain; |
|
696 | 696 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
697 | 697 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal,int))); |
|
698 | 698 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal,int))); |
|
699 | 699 | |
|
700 | 700 | domain.handleAxisYChanged(min, max, tickCount, niceNumbers); |
|
701 | 701 | |
|
702 | 702 | QCOMPARE(resultMin, domain.minY()); |
|
703 | 703 | QCOMPARE(resultMax, domain.maxY()); |
|
704 | 704 | QCOMPARE(resultTickCount, domain.tickYCount()); |
|
705 |
|
|
|
706 |
|
|
|
707 |
|
|
|
705 | TRY_COMPARE(spy0.count(), 1); | |
|
706 | TRY_COMPARE(spy1.count(), 0); | |
|
707 | TRY_COMPARE(spy2.count(), 1); | |
|
708 | 708 | } |
|
709 | 709 | |
|
710 | 710 | QTEST_MAIN(tst_Domain) |
|
711 | 711 | #include "tst_domain.moc" |
|
712 | 712 |
@@ -1,318 +1,428 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qbarseries.h> |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | class tst_QBarSeries : public QObject |
|
28 | 28 | { |
|
29 | 29 | Q_OBJECT |
|
30 | 30 | |
|
31 | 31 | public slots: |
|
32 | 32 | void initTestCase(); |
|
33 | 33 | void cleanupTestCase(); |
|
34 | 34 | void init(); |
|
35 | 35 | void cleanup(); |
|
36 | 36 | |
|
37 | 37 | private slots: |
|
38 | 38 | void qbarseries_data(); |
|
39 | 39 | void qbarseries(); |
|
40 | 40 | void type_data(); |
|
41 | 41 | void type(); |
|
42 | void setCategories_data(); | |
|
43 | void setCategories(); | |
|
42 | 44 | void appendBarSet_data(); |
|
43 | 45 | void appendBarSet(); |
|
44 | 46 | void removeBarSet_data(); |
|
45 | 47 | void removeBarSet(); |
|
46 | 48 | void appendBarSets_data(); |
|
47 | 49 | void appendBarSets(); |
|
48 | 50 | void removeBarSets_data(); |
|
49 | 51 | void removeBarSets(); |
|
50 | 52 | void barsetCount_data(); |
|
51 | 53 | void barsetCount(); |
|
52 | 54 | void categoryCount_data(); |
|
53 | 55 | void categoryCount(); |
|
54 | 56 | void barSets_data(); |
|
55 | 57 | void barSets(); |
|
56 | 58 | void categories_data(); |
|
57 | 59 | void categories(); |
|
58 | 60 | void setLabelsVisible_data(); |
|
59 | 61 | void setLabelsVisible(); |
|
60 | 62 | |
|
61 | 63 | private: |
|
62 | 64 | QBarSeries* m_barseries; |
|
63 | 65 | QBarSeries* m_barseries_with_sets; |
|
64 | 66 | |
|
65 | 67 | QList<QBarSet*> m_testSets; |
|
66 | 68 | |
|
67 | 69 | QBarCategories m_categories; |
|
68 | 70 | }; |
|
69 | 71 | |
|
70 | 72 | void tst_QBarSeries::initTestCase() |
|
71 | 73 | { |
|
72 | 74 | } |
|
73 | 75 | |
|
74 | 76 | void tst_QBarSeries::cleanupTestCase() |
|
75 | 77 | { |
|
76 | 78 | } |
|
77 | 79 | |
|
78 | 80 | void tst_QBarSeries::init() |
|
79 | 81 | { |
|
80 | 82 | m_categories << "category0" << "category1" << "category2"; |
|
81 |
m_barseries = new QBarSeries( |
|
|
82 |
m_barseries |
|
|
83 | m_barseries = new QBarSeries(); | |
|
84 | m_barseries->setCategories(m_categories); | |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
|
86 | m_barseries_with_sets->setCategories(m_categories); | |
|
83 | 87 | |
|
84 | 88 | for (int i=0; i<5; i++) { |
|
85 | 89 | m_testSets.append(new QBarSet("testset")); |
|
86 | 90 | m_barseries_with_sets->appendBarSet(m_testSets.at(i)); |
|
87 | 91 | } |
|
88 | 92 | } |
|
89 | 93 | |
|
90 | 94 | void tst_QBarSeries::cleanup() |
|
91 | 95 | { |
|
92 | 96 | foreach(QBarSet* s, m_testSets) { |
|
93 | 97 | m_barseries_with_sets->removeBarSet(s); |
|
94 | 98 | delete s; |
|
95 | 99 | } |
|
96 | 100 | m_testSets.clear(); |
|
97 | 101 | |
|
98 | 102 | delete m_barseries; |
|
99 | 103 | m_barseries = 0; |
|
100 | 104 | delete m_barseries_with_sets; |
|
101 | 105 | m_barseries_with_sets = 0; |
|
102 | 106 | m_categories.clear(); |
|
103 | 107 | } |
|
104 | 108 | |
|
105 | 109 | void tst_QBarSeries::qbarseries_data() |
|
106 | 110 | { |
|
107 | 111 | QTest::addColumn<QBarCategories> ("categories"); |
|
108 | 112 | QBarCategories c; |
|
109 | 113 | c << "category0" << "category1" << "category2"; |
|
110 | 114 | QTest::newRow("categories") << c; |
|
111 | 115 | } |
|
112 | 116 | |
|
113 | 117 | void tst_QBarSeries::qbarseries() |
|
114 | 118 | { |
|
115 | 119 | QFETCH(QBarCategories, categories); |
|
116 |
QBarSeries *barseries = new QBarSeries( |
|
|
120 | QBarSeries *barseries = new QBarSeries(); | |
|
117 | 121 | QVERIFY(barseries != 0); |
|
122 | barseries->setCategories(categories); | |
|
118 | 123 | QBarCategories verifyCategories = barseries->categories(); |
|
119 | 124 | |
|
120 | 125 | QVERIFY(verifyCategories.count() == categories.count()); |
|
121 | 126 | for (int i=0; i<categories.count(); i++) { |
|
122 | 127 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
123 | 128 | } |
|
124 | 129 | } |
|
125 | 130 | |
|
126 | 131 | void tst_QBarSeries::type_data() |
|
127 | 132 | { |
|
128 | 133 | |
|
129 | 134 | } |
|
130 | 135 | |
|
131 | 136 | void tst_QBarSeries::type() |
|
132 | 137 | { |
|
133 | 138 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
134 | 139 | } |
|
135 | 140 | |
|
141 | void tst_QBarSeries::setCategories_data() | |
|
142 | { | |
|
143 | QTest::addColumn<QBarCategories> ("categories"); | |
|
144 | QBarCategories categories; | |
|
145 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; | |
|
146 | QTest::newRow("cat") << categories; | |
|
147 | } | |
|
148 | ||
|
149 | void tst_QBarSeries::setCategories() | |
|
150 | { | |
|
151 | QVERIFY(m_barseries->categories().count() == m_categories.count()); | |
|
152 | ||
|
153 | QFETCH(QBarCategories, categories); | |
|
154 | m_barseries->setCategories(categories); | |
|
155 | ||
|
156 | QVERIFY(m_barseries->categories().count() == categories.count()); | |
|
157 | for (int i=0; i<categories.count(); i++) { | |
|
158 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); | |
|
159 | } | |
|
160 | } | |
|
161 | ||
|
136 | 162 | void tst_QBarSeries::appendBarSet_data() |
|
137 | 163 | { |
|
138 | 164 | } |
|
139 | 165 | |
|
140 | 166 | void tst_QBarSeries::appendBarSet() |
|
141 | 167 | { |
|
142 | 168 | QVERIFY(m_barseries->barsetCount() == 0); |
|
143 | 169 | |
|
170 | bool ret = false; | |
|
171 | ||
|
172 | // Try adding barset | |
|
144 | 173 | QBarSet *barset = new QBarSet("testset"); |
|
145 | m_barseries->appendBarSet(barset); | |
|
174 | ret = m_barseries->appendBarSet(barset); | |
|
146 | 175 | |
|
176 | QVERIFY(ret == true); | |
|
147 | 177 | QVERIFY(m_barseries->barsetCount() == 1); |
|
148 | 178 | |
|
179 | // Try adding another set | |
|
149 | 180 | QBarSet *barset2 = new QBarSet("testset2"); |
|
150 | m_barseries->appendBarSet(barset2); | |
|
181 | ret = m_barseries->appendBarSet(barset2); | |
|
182 | ||
|
183 | QVERIFY(ret == true); | |
|
184 | QVERIFY(m_barseries->barsetCount() == 2); | |
|
151 | 185 | |
|
186 | // Try adding same set again | |
|
187 | ret = m_barseries->appendBarSet(barset2); | |
|
188 | QVERIFY(ret == false); | |
|
152 | 189 | QVERIFY(m_barseries->barsetCount() == 2); |
|
190 | ||
|
191 | // Try adding null set | |
|
192 | ret = m_barseries->appendBarSet(0); | |
|
193 | QVERIFY(ret == false); | |
|
194 | QVERIFY(m_barseries->barsetCount() == 2); | |
|
195 | ||
|
153 | 196 | } |
|
154 | 197 | |
|
155 | 198 | void tst_QBarSeries::removeBarSet_data() |
|
156 | 199 | { |
|
157 | 200 | } |
|
158 | 201 | |
|
159 | 202 | void tst_QBarSeries::removeBarSet() |
|
160 | 203 | { |
|
161 | 204 | int count = m_testSets.count(); |
|
162 | 205 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
163 | 206 | |
|
207 | // Try to remove null pointer (should not remove, should not crash) | |
|
208 | bool ret = false; | |
|
209 | ret = m_barseries_with_sets->removeBarSet(0); | |
|
210 | QVERIFY(ret == false); | |
|
211 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
212 | ||
|
213 | // Try to remove invalid pointer (should not remove, should not crash) | |
|
214 | ret = m_barseries_with_sets->removeBarSet((QBarSet*) (m_testSets.at(0) + 1) ); | |
|
215 | QVERIFY(ret == false); | |
|
216 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
217 | ||
|
164 | 218 | // remove some sets |
|
165 | m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
|
166 | m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
|
167 |
m_barseries_with_sets->removeBarSet(m_testSets.at( |
|
|
219 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(2)); | |
|
220 | QVERIFY(ret == true); | |
|
221 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(3)); | |
|
222 | QVERIFY(ret == true); | |
|
223 | ret = m_barseries_with_sets->removeBarSet(m_testSets.at(4)); | |
|
224 | QVERIFY(ret == true); | |
|
168 | 225 | |
|
169 | 226 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
170 | 227 | |
|
171 | 228 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
172 | 229 | |
|
173 | 230 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
174 | 231 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
175 | 232 | |
|
176 | // Try removing all sets again | |
|
233 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
|
234 | ret = false; | |
|
177 | 235 | for (int i=0; i<count; i++) { |
|
178 | m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
|
236 | ret |= m_barseries_with_sets->removeBarSet(m_testSets.at(i)); | |
|
179 | 237 | } |
|
180 | 238 | |
|
239 | QVERIFY(ret == true); | |
|
181 | 240 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
182 | 241 | } |
|
183 | 242 | |
|
184 | 243 | void tst_QBarSeries::appendBarSets_data() |
|
185 | 244 | { |
|
186 | 245 | |
|
187 | 246 | } |
|
188 | 247 | |
|
189 | 248 | void tst_QBarSeries::appendBarSets() |
|
190 | 249 | { |
|
191 | 250 | int count = 5; |
|
192 | 251 | QVERIFY(m_barseries->barsetCount() == 0); |
|
193 | 252 | |
|
194 | 253 | QList<QBarSet*> sets; |
|
195 | 254 | for (int i=0; i<count; i++) { |
|
196 | 255 | sets.append(new QBarSet("testset")); |
|
197 | 256 | } |
|
198 | 257 | |
|
199 | m_barseries->appendBarSets(sets); | |
|
258 | // Append new sets (should succeed, count should match the count of sets) | |
|
259 | bool ret = false; | |
|
260 | ret = m_barseries->appendBarSets(sets); | |
|
261 | QVERIFY(ret == true); | |
|
262 | QVERIFY(m_barseries->barsetCount() == count); | |
|
263 | ||
|
264 | // Append same sets again (should fail, count should remain same) | |
|
265 | ret = m_barseries->appendBarSets(sets); | |
|
266 | QVERIFY(ret == false); | |
|
267 | QVERIFY(m_barseries->barsetCount() == count); | |
|
268 | ||
|
269 | // Try append empty list (should succeed, but count should remain same) | |
|
270 | QList<QBarSet*> invalidList; | |
|
271 | ret = m_barseries->appendBarSets(invalidList); | |
|
272 | QVERIFY(ret == true); | |
|
273 | QVERIFY(m_barseries->barsetCount() == count); | |
|
274 | ||
|
275 | // Try append list with one new and one existing set (should fail, count remains same) | |
|
276 | invalidList.append(new QBarSet("ok set")); | |
|
277 | invalidList.append(sets.at(0)); | |
|
278 | ret = m_barseries->appendBarSets(invalidList); | |
|
279 | QVERIFY(ret == false); | |
|
280 | QVERIFY(m_barseries->barsetCount() == count); | |
|
281 | ||
|
282 | // Try append list with null pointers (should fail, count remains same) | |
|
283 | QList<QBarSet*> invalidList2; | |
|
284 | invalidList2.append(0); | |
|
285 | invalidList2.append(0); | |
|
286 | invalidList2.append(0); | |
|
287 | ret = m_barseries->appendBarSets(invalidList2); | |
|
288 | QVERIFY(ret == false); | |
|
200 | 289 | QVERIFY(m_barseries->barsetCount() == count); |
|
201 | 290 | } |
|
202 | 291 | |
|
203 | 292 | void tst_QBarSeries::removeBarSets_data() |
|
204 | 293 | { |
|
205 | 294 | |
|
206 | 295 | } |
|
207 | 296 | |
|
208 | 297 | void tst_QBarSeries::removeBarSets() |
|
209 | 298 | { |
|
210 | 299 | int count = m_testSets.count(); |
|
211 | 300 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
212 | 301 | |
|
213 | // Try removing empty list of sets | |
|
214 | QList<QBarSet*> empty; | |
|
215 | m_barseries_with_sets->removeBarSets(empty); | |
|
302 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
|
303 | bool ret = false; | |
|
304 | QList<QBarSet*> invalidList; | |
|
305 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
306 | QVERIFY(ret == false); | |
|
216 | 307 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
217 | 308 | |
|
218 | // remove all sets | |
|
219 | m_barseries_with_sets->removeBarSets(m_testSets); | |
|
309 | // Add some null pointers to list | |
|
310 | invalidList.append(0); | |
|
311 | invalidList.append(0); | |
|
312 | invalidList.append(0); | |
|
313 | ||
|
314 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |
|
315 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
316 | QVERIFY(ret == false); | |
|
317 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
|
318 | ||
|
319 | // remove all sets (should return true, since sets were removed) | |
|
320 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
|
321 | QVERIFY(ret == true); | |
|
220 | 322 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
221 | 323 | |
|
222 | // Try removing empty list again | |
|
223 |
m_barseries_with_sets->removeBarSets( |
|
|
324 | // Try removing invalid list again (should return false, since no barsets were removed) | |
|
325 | ret = m_barseries_with_sets->removeBarSets(invalidList); | |
|
326 | QVERIFY(ret == false); | |
|
224 | 327 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
225 | 328 | |
|
226 | // remove all sets again | |
|
227 | m_barseries_with_sets->removeBarSets(m_testSets); | |
|
329 | // remove all sets again (should return false, since barsets were already removed) | |
|
330 | ret = m_barseries_with_sets->removeBarSets(m_testSets); | |
|
331 | QVERIFY(ret == false); | |
|
228 | 332 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
229 | 333 | } |
|
230 | 334 | |
|
231 | 335 | void tst_QBarSeries::barsetCount_data() |
|
232 | 336 | { |
|
233 | 337 | |
|
234 | 338 | } |
|
235 | 339 | |
|
236 | 340 | void tst_QBarSeries::barsetCount() |
|
237 | 341 | { |
|
238 | 342 | QVERIFY(m_barseries->barsetCount() == 0); |
|
239 | 343 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); |
|
240 | 344 | } |
|
241 | 345 | |
|
242 | 346 | void tst_QBarSeries::categoryCount_data() |
|
243 | 347 | { |
|
244 | 348 | |
|
245 | 349 | } |
|
246 | 350 | |
|
247 | 351 | void tst_QBarSeries::categoryCount() |
|
248 | 352 | { |
|
249 | 353 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); |
|
250 | 354 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); |
|
251 | 355 | } |
|
252 | 356 | |
|
253 | 357 | void tst_QBarSeries::barSets_data() |
|
254 | 358 | { |
|
255 | 359 | |
|
256 | 360 | } |
|
257 | 361 | |
|
258 | 362 | void tst_QBarSeries::barSets() |
|
259 | 363 | { |
|
260 | 364 | QVERIFY(m_barseries->barSets().count() == 0); |
|
261 | 365 | |
|
262 | 366 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
263 | 367 | QVERIFY(sets.count() == m_testSets.count()); |
|
264 | 368 | |
|
265 | 369 | for (int i=0; i<m_testSets.count(); i++) { |
|
266 | 370 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
267 | 371 | } |
|
268 | 372 | } |
|
269 | 373 | |
|
270 | 374 | void tst_QBarSeries::categories_data() |
|
271 | 375 | { |
|
272 | 376 | |
|
273 | 377 | } |
|
274 | 378 | |
|
275 | 379 | void tst_QBarSeries::categories() |
|
276 | 380 | { |
|
277 | 381 | QBarCategories categories = m_barseries->categories(); |
|
278 | 382 | |
|
279 | 383 | QVERIFY(categories.count() == m_categories.count()); |
|
280 | 384 | for (int i=0; i<m_categories.count(); i++) { |
|
281 | 385 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); |
|
282 | 386 | } |
|
283 | 387 | } |
|
284 | 388 | |
|
285 | 389 | void tst_QBarSeries::setLabelsVisible_data() |
|
286 | 390 | { |
|
287 | 391 | |
|
288 | 392 | } |
|
289 | 393 | |
|
290 | 394 | void tst_QBarSeries::setLabelsVisible() |
|
291 | 395 | { |
|
396 | // labels should be invisible by default | |
|
292 | 397 | foreach (QBarSet* s, m_testSets) { |
|
293 | 398 | QVERIFY(s->labelsVisible() == false); |
|
294 | 399 | } |
|
295 | 400 | |
|
401 | // turn labels to visible | |
|
296 | 402 | m_barseries_with_sets->setLabelsVisible(true); |
|
297 | 403 | foreach (QBarSet* s, m_testSets) { |
|
298 | 404 | QVERIFY(s->labelsVisible() == true); |
|
299 | 405 | } |
|
300 | 406 | |
|
407 | // turn labels to invisible | |
|
301 | 408 | m_barseries_with_sets->setLabelsVisible(false); |
|
302 | 409 | foreach (QBarSet* s, m_testSets) { |
|
303 | 410 | QVERIFY(s->labelsVisible() == false); |
|
304 | 411 | } |
|
412 | ||
|
413 | // without parameter, should turn labels to visible | |
|
414 | m_barseries_with_sets->setLabelsVisible(); | |
|
415 | foreach (QBarSet* s, m_testSets) { | |
|
416 | QVERIFY(s->labelsVisible() == true); | |
|
417 | } | |
|
305 | 418 | } |
|
306 | 419 | |
|
307 | 420 | /* |
|
308 | ||
|
309 | void setLabelsVisible(bool visible = true); | |
|
310 | ||
|
311 | 421 | bool setModel(QAbstractItemModel *model); |
|
312 | 422 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
313 | 423 | void setModelMappingRange(int first, int count = -1); |
|
314 | 424 | */ |
|
315 | 425 | QTEST_MAIN(tst_QBarSeries) |
|
316 | 426 | |
|
317 | 427 | #include "tst_qbarseries.moc" |
|
318 | 428 |
@@ -1,568 +1,585 | |||
|
1 | 1 | #include <QtTest/QtTest> |
|
2 | 2 | #include <qchartview.h> |
|
3 | 3 | #include <qlineseries.h> |
|
4 | 4 | #include <qareaseries.h> |
|
5 | 5 | #include <qscatterseries.h> |
|
6 | 6 | #include <qsplineseries.h> |
|
7 | 7 | #include <qpieseries.h> |
|
8 | 8 | #include <qbarseries.h> |
|
9 | 9 | #include <qpercentbarseries.h> |
|
10 | 10 | #include <qstackedbarseries.h> |
|
11 | 11 | |
|
12 | 12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
13 | 13 | |
|
14 | 14 | Q_DECLARE_METATYPE(QAxis *) |
|
15 | 15 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
16 | 16 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
17 | 17 | Q_DECLARE_METATYPE(QBrush) |
|
18 | 18 | Q_DECLARE_METATYPE(QPen) |
|
19 | 19 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
20 | 20 | |
|
21 | 21 | class tst_QChart : public QObject |
|
22 | 22 | { |
|
23 | 23 | Q_OBJECT |
|
24 | 24 | |
|
25 | 25 | public slots: |
|
26 | 26 | void initTestCase(); |
|
27 | 27 | void cleanupTestCase(); |
|
28 | 28 | void init(); |
|
29 | 29 | void cleanup(); |
|
30 | 30 | |
|
31 | 31 | private slots: |
|
32 | 32 | void qchart_data(); |
|
33 | 33 | void qchart(); |
|
34 | 34 | |
|
35 | 35 | void addSeries_data(); |
|
36 | 36 | void addSeries(); |
|
37 | 37 | void animationOptions_data(); |
|
38 | 38 | void animationOptions(); |
|
39 | 39 | void axisX_data(); |
|
40 | 40 | void axisX(); |
|
41 | 41 | void axisY_data(); |
|
42 | 42 | void axisY(); |
|
43 | 43 | void backgroundBrush_data(); |
|
44 | 44 | void backgroundBrush(); |
|
45 | 45 | void backgroundPen_data(); |
|
46 | 46 | void backgroundPen(); |
|
47 | 47 | void isBackgroundVisible_data(); |
|
48 | 48 | void isBackgroundVisible(); |
|
49 | 49 | void legend_data(); |
|
50 | 50 | void legend(); |
|
51 | 51 | void margins_data(); |
|
52 | 52 | void margins(); |
|
53 | 53 | void removeAllSeries_data(); |
|
54 | 54 | void removeAllSeries(); |
|
55 | 55 | void removeSeries_data(); |
|
56 | 56 | void removeSeries(); |
|
57 | 57 | void scrollDown_data(); |
|
58 | 58 | void scrollDown(); |
|
59 | 59 | void scrollLeft_data(); |
|
60 | 60 | void scrollLeft(); |
|
61 | 61 | void scrollRight_data(); |
|
62 | 62 | void scrollRight(); |
|
63 | 63 | void scrollUp_data(); |
|
64 | 64 | void scrollUp(); |
|
65 | 65 | void theme_data(); |
|
66 | 66 | void theme(); |
|
67 | 67 | void title_data(); |
|
68 | 68 | void title(); |
|
69 | 69 | void titleBrush_data(); |
|
70 | 70 | void titleBrush(); |
|
71 | 71 | void titleFont_data(); |
|
72 | 72 | void titleFont(); |
|
73 | 73 | void zoomIn_data(); |
|
74 | 74 | void zoomIn(); |
|
75 | 75 | void zoomOut_data(); |
|
76 | 76 | void zoomOut(); |
|
77 | 77 | |
|
78 | 78 | private: |
|
79 | 79 | void createTestData(); |
|
80 | 80 | |
|
81 | 81 | private: |
|
82 | 82 | QChartView* m_view; |
|
83 | 83 | QChart* m_chart; |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | void tst_QChart::initTestCase() |
|
87 | 87 | { |
|
88 | 88 | |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | void tst_QChart::cleanupTestCase() |
|
92 | 92 | { |
|
93 | 93 | |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | void tst_QChart::init() |
|
97 | 97 | { |
|
98 | 98 | m_view = new QChartView(new QChart()); |
|
99 | 99 | m_chart = m_view->chart(); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | void tst_QChart::createTestData() |
|
103 | 103 | { |
|
104 | 104 | QLineSeries* series0 = new QLineSeries(this); |
|
105 | 105 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
106 | 106 | m_chart->addSeries(series0); |
|
107 | 107 | m_view->show(); |
|
108 | 108 | QTest::qWaitForWindowShown(m_view); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void tst_QChart::cleanup() |
|
112 | 112 | { |
|
113 | 113 | delete m_view; |
|
114 | 114 | m_view = 0; |
|
115 | 115 | m_chart = 0; |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | void tst_QChart::qchart_data() |
|
119 | 119 | { |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | void tst_QChart::qchart() |
|
123 | 123 | { |
|
124 | 124 | QVERIFY(m_chart); |
|
125 | 125 | QVERIFY(m_chart->legend()); |
|
126 | 126 | QVERIFY(!m_chart->legend()->isVisible()); |
|
127 | 127 | |
|
128 | 128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
129 | 129 | QVERIFY(m_chart->axisX()); |
|
130 | 130 | QVERIFY(m_chart->axisY()); |
|
131 | 131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
132 | 132 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
133 | 133 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
134 | 134 | |
|
135 | 135 | QVERIFY(m_chart->margins().top()>0); |
|
136 | 136 | QVERIFY(m_chart->margins().left()>0); |
|
137 | 137 | QVERIFY(m_chart->margins().right()>0); |
|
138 | 138 | QVERIFY(m_chart->margins().bottom()>0); |
|
139 | 139 | |
|
140 | 140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
141 | 141 | QCOMPARE(m_chart->title(), QString()); |
|
142 | 142 | |
|
143 | 143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
144 | 144 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
145 | 145 | |
|
146 | 146 | m_chart->removeAllSeries(); |
|
147 | 147 | m_chart->scrollDown(); |
|
148 | 148 | m_chart->scrollLeft(); |
|
149 | 149 | m_chart->scrollRight(); |
|
150 | 150 | m_chart->scrollUp(); |
|
151 | 151 | |
|
152 | 152 | m_chart->zoomIn(); |
|
153 | 153 | m_chart->zoomIn(QRectF()); |
|
154 | 154 | m_chart->zoomOut(); |
|
155 | 155 | } |
|
156 | 156 | |
|
157 | 157 | void tst_QChart::addSeries_data() |
|
158 | 158 | { |
|
159 | 159 | QTest::addColumn<QAbstractSeries *>("series"); |
|
160 | 160 | QTest::addColumn<QAxis *>("axis"); |
|
161 | 161 | |
|
162 | 162 | QAbstractSeries* series0 = new QLineSeries(this); |
|
163 | 163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
164 | 164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
165 | 165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
166 | 166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
167 |
QAbstractSeries* series5 = new QBarSeries( |
|
|
168 |
QAbstractSeries* series6 = new QPercentBarSeries( |
|
|
169 |
QAbstractSeries* series7 = new QStackedBarSeries( |
|
|
167 | QAbstractSeries* series5 = new QBarSeries(this); | |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
|
170 | ||
|
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); | |
|
172 | s5->setCategories(QBarCategories()); | |
|
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); | |
|
174 | s6->setCategories(QBarCategories()); | |
|
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); | |
|
176 | s7->setCategories(QBarCategories()); | |
|
170 | 177 | |
|
171 | 178 | QAxis* axis = new QAxis(this); |
|
172 | 179 | |
|
173 | 180 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; |
|
174 | 181 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
175 | 182 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; |
|
176 | 183 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
177 | 184 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; |
|
178 | 185 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
179 | 186 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; |
|
180 | 187 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
181 | 188 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; |
|
182 | 189 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
183 | 190 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; |
|
184 | 191 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
185 | 192 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; |
|
186 | 193 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
187 | 194 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; |
|
188 | 195 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
189 | 196 | |
|
190 | 197 | } |
|
191 | 198 | |
|
192 | 199 | void tst_QChart::addSeries() |
|
193 | 200 | { |
|
194 | 201 | QFETCH(QAbstractSeries *, series); |
|
195 | 202 | QFETCH(QAxis *, axis); |
|
196 | 203 | m_view->show(); |
|
197 | 204 | QTest::qWaitForWindowShown(m_view); |
|
198 | 205 | if(!axis) axis = m_chart->axisY(); |
|
199 | 206 | m_chart->addSeries(series,axis); |
|
200 | 207 | QCOMPARE(m_chart->axisY(series),axis); |
|
201 | 208 | m_chart->removeSeries(series); |
|
202 | 209 | |
|
203 | 210 | } |
|
204 | 211 | |
|
205 | 212 | void tst_QChart::animationOptions_data() |
|
206 | 213 | { |
|
207 | 214 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
208 | 215 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
209 | 216 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
210 | 217 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
211 | 218 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
212 | 219 | } |
|
213 | 220 | |
|
214 | 221 | void tst_QChart::animationOptions() |
|
215 | 222 | { |
|
216 | 223 | createTestData(); |
|
217 | 224 | QFETCH(QChart::AnimationOption, animationOptions); |
|
218 | 225 | m_chart->setAnimationOptions(animationOptions); |
|
219 | 226 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
220 | 227 | } |
|
221 | 228 | |
|
222 | 229 | void tst_QChart::axisX_data() |
|
223 | 230 | { |
|
224 | 231 | |
|
225 | 232 | } |
|
226 | 233 | |
|
227 | 234 | void tst_QChart::axisX() |
|
228 | 235 | { |
|
229 | 236 | QVERIFY(m_chart->axisX()); |
|
230 | 237 | QAxis* axis = m_chart->axisX(); |
|
231 | 238 | createTestData(); |
|
232 | 239 | //it should be the same axis |
|
233 | 240 | QCOMPARE(axis,m_chart->axisX()); |
|
234 | 241 | } |
|
235 | 242 | |
|
236 | 243 | void tst_QChart::axisY_data() |
|
237 | 244 | { |
|
238 | 245 | QTest::addColumn<QAxis*>("axis0"); |
|
239 | 246 | QTest::addColumn<QAxis*>("axis1"); |
|
240 | 247 | QTest::addColumn<QAxis*>("axis2"); |
|
241 | 248 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
242 | 249 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
243 | 250 | } |
|
244 | 251 | |
|
245 | 252 | |
|
246 | 253 | void tst_QChart::axisY() |
|
247 | 254 | { |
|
248 | 255 | QFETCH(QAxis*, axis0); |
|
249 | 256 | QFETCH(QAxis*, axis1); |
|
250 | 257 | QFETCH(QAxis*, axis2); |
|
251 | 258 | |
|
252 | 259 | QAxis* defaultAxisY = m_chart->axisY(); |
|
253 | 260 | |
|
254 | 261 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
255 | 262 | |
|
256 | 263 | QLineSeries* series0 = new QLineSeries(); |
|
257 | 264 | m_chart->addSeries(series0, axis0); |
|
258 | 265 | |
|
259 | 266 | QLineSeries* series1 = new QLineSeries(); |
|
260 | 267 | m_chart->addSeries(series1, axis1); |
|
261 | 268 | |
|
262 | 269 | QLineSeries* series2 = new QLineSeries(); |
|
263 | 270 | m_chart->addSeries(series2, axis2); |
|
264 | 271 | |
|
265 | 272 | if (!axis0) |
|
266 | 273 | axis0 = defaultAxisY; |
|
267 | 274 | if (!axis1) |
|
268 | 275 | axis1 = defaultAxisY; |
|
269 | 276 | if (!axis2) |
|
270 | 277 | axis2 = defaultAxisY; |
|
271 | 278 | |
|
272 | 279 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
273 | 280 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
274 | 281 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
275 | 282 | } |
|
276 | 283 | |
|
277 | 284 | void tst_QChart::backgroundBrush_data() |
|
278 | 285 | { |
|
279 | 286 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
280 | 287 | QTest::newRow("null") << QBrush(); |
|
281 | 288 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
282 | 289 | QTest::newRow("white") << QBrush(Qt::white); |
|
283 | 290 | QTest::newRow("black") << QBrush(Qt::black); |
|
284 | 291 | } |
|
285 | 292 | |
|
286 | 293 | void tst_QChart::backgroundBrush() |
|
287 | 294 | { |
|
288 | 295 | QFETCH(QBrush, backgroundBrush); |
|
289 | 296 | m_chart->setBackgroundBrush(backgroundBrush); |
|
290 | 297 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
291 | 298 | } |
|
292 | 299 | |
|
293 | 300 | void tst_QChart::backgroundPen_data() |
|
294 | 301 | { |
|
295 | 302 | QTest::addColumn<QPen>("backgroundPen"); |
|
296 | 303 | QTest::newRow("null") << QPen(); |
|
297 | 304 | QTest::newRow("blue") << QPen(Qt::blue); |
|
298 | 305 | QTest::newRow("white") << QPen(Qt::white); |
|
299 | 306 | QTest::newRow("black") << QPen(Qt::black); |
|
300 | 307 | } |
|
301 | 308 | |
|
302 | 309 | |
|
303 | 310 | void tst_QChart::backgroundPen() |
|
304 | 311 | { |
|
305 | 312 | QFETCH(QPen, backgroundPen); |
|
306 | 313 | m_chart->setBackgroundPen(backgroundPen); |
|
307 | 314 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
308 | 315 | } |
|
309 | 316 | |
|
310 | 317 | void tst_QChart::isBackgroundVisible_data() |
|
311 | 318 | { |
|
312 | 319 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
313 | 320 | QTest::newRow("true") << true; |
|
314 | 321 | QTest::newRow("false") << false; |
|
315 | 322 | } |
|
316 | 323 | |
|
317 | 324 | void tst_QChart::isBackgroundVisible() |
|
318 | 325 | { |
|
319 | 326 | QFETCH(bool, isBackgroundVisible); |
|
320 | 327 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
321 | 328 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
322 | 329 | } |
|
323 | 330 | |
|
324 | 331 | void tst_QChart::legend_data() |
|
325 | 332 | { |
|
326 | 333 | |
|
327 | 334 | } |
|
328 | 335 | |
|
329 | 336 | void tst_QChart::legend() |
|
330 | 337 | { |
|
331 | 338 | QVERIFY(m_chart->legend()); |
|
332 | 339 | } |
|
333 | 340 | |
|
334 | 341 | void tst_QChart::margins_data() |
|
335 | 342 | { |
|
336 | 343 | |
|
337 | 344 | } |
|
338 | 345 | |
|
339 | 346 | void tst_QChart::margins() |
|
340 | 347 | { |
|
341 | 348 | createTestData(); |
|
342 | 349 | QRectF rect = m_chart->geometry(); |
|
343 | 350 | |
|
344 | 351 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
345 | 352 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
346 | 353 | } |
|
347 | 354 | |
|
348 | 355 | void tst_QChart::removeAllSeries_data() |
|
349 | 356 | { |
|
350 | 357 | |
|
351 | 358 | } |
|
352 | 359 | |
|
353 | 360 | void tst_QChart::removeAllSeries() |
|
354 | 361 | { |
|
355 | 362 | QLineSeries* series0 = new QLineSeries(this); |
|
356 | 363 | QLineSeries* series1 = new QLineSeries(this); |
|
357 | 364 | QLineSeries* series2 = new QLineSeries(this); |
|
358 | 365 | |
|
359 | 366 | m_chart->addSeries(series0); |
|
360 | 367 | m_chart->addSeries(series1); |
|
361 | 368 | m_chart->addSeries(series2); |
|
362 | 369 | m_view->show(); |
|
363 | 370 | QTest::qWaitForWindowShown(m_view); |
|
364 | 371 | |
|
365 | 372 | QVERIFY(m_chart->axisY(series0)!=0); |
|
366 | 373 | QVERIFY(m_chart->axisY(series1)!=0); |
|
367 | 374 | QVERIFY(m_chart->axisY(series2)!=0); |
|
368 | 375 | |
|
369 | 376 | m_chart->removeAllSeries(); |
|
370 | 377 | |
|
371 | 378 | QVERIFY(m_chart->axisY(series0)==0); |
|
372 | 379 | QVERIFY(m_chart->axisY(series1)==0); |
|
373 | 380 | QVERIFY(m_chart->axisY(series2)==0); |
|
374 | 381 | } |
|
375 | 382 | |
|
376 | 383 | void tst_QChart::removeSeries_data() |
|
377 | 384 | { |
|
378 | 385 | addSeries_data(); |
|
379 | 386 | } |
|
380 | 387 | |
|
381 | 388 | void tst_QChart::removeSeries() |
|
382 | 389 | { |
|
383 | 390 | QFETCH(QAbstractSeries *, series); |
|
384 | 391 | QFETCH(QAxis *, axis); |
|
385 | 392 | m_view->show(); |
|
386 | 393 | QTest::qWaitForWindowShown(m_view); |
|
387 | 394 | if(!axis) axis = m_chart->axisY(); |
|
388 | 395 | m_chart->addSeries(series,axis); |
|
389 | 396 | QCOMPARE(m_chart->axisY(series),axis); |
|
390 | 397 | m_chart->removeSeries(series); |
|
391 | 398 | QVERIFY(m_chart->axisY(series)==0); |
|
392 | 399 | } |
|
393 | 400 | |
|
394 | 401 | void tst_QChart::scrollDown_data() |
|
395 | 402 | { |
|
396 | 403 | |
|
397 | 404 | } |
|
398 | 405 | |
|
399 | 406 | void tst_QChart::scrollDown() |
|
400 | 407 | { |
|
401 | 408 | createTestData(); |
|
402 | 409 | qreal min = m_chart->axisY()->min(); |
|
403 | 410 | m_chart->scrollDown(); |
|
404 | 411 | QVERIFY(m_chart->axisY()->min()<min); |
|
405 | 412 | } |
|
406 | 413 | |
|
407 | 414 | void tst_QChart::scrollLeft_data() |
|
408 | 415 | { |
|
409 | 416 | |
|
410 | 417 | } |
|
411 | 418 | |
|
412 | 419 | void tst_QChart::scrollLeft() |
|
413 | 420 | { |
|
414 | 421 | createTestData(); |
|
415 | 422 | qreal min = m_chart->axisX()->min(); |
|
416 | 423 | m_chart->scrollLeft(); |
|
417 | 424 | QVERIFY(m_chart->axisX()->min()<min); |
|
418 | 425 | } |
|
419 | 426 | |
|
420 | 427 | void tst_QChart::scrollRight_data() |
|
421 | 428 | { |
|
422 | 429 | |
|
423 | 430 | } |
|
424 | 431 | |
|
425 | 432 | void tst_QChart::scrollRight() |
|
426 | 433 | { |
|
427 | 434 | createTestData(); |
|
428 | 435 | qreal min = m_chart->axisX()->min(); |
|
429 | 436 | m_chart->scrollRight(); |
|
430 | 437 | QVERIFY(m_chart->axisX()->min()>min); |
|
431 | 438 | } |
|
432 | 439 | |
|
433 | 440 | void tst_QChart::scrollUp_data() |
|
434 | 441 | { |
|
435 | 442 | |
|
436 | 443 | } |
|
437 | 444 | |
|
438 | 445 | void tst_QChart::scrollUp() |
|
439 | 446 | { |
|
440 | 447 | createTestData(); |
|
441 | 448 | qreal min = m_chart->axisY()->min(); |
|
442 | 449 | m_chart->scrollUp(); |
|
443 | 450 | QVERIFY(m_chart->axisY()->min()>min); |
|
444 | 451 | } |
|
445 | 452 | |
|
446 | 453 | void tst_QChart::theme_data() |
|
447 | 454 | { |
|
448 | 455 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
449 | 456 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
450 | 457 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
451 | 458 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
452 | 459 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
453 | 460 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
454 | 461 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
455 | 462 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
456 | 463 | } |
|
457 | 464 | |
|
458 | 465 | void tst_QChart::theme() |
|
459 | 466 | { |
|
460 | 467 | QFETCH(QChart::ChartTheme, theme); |
|
461 | 468 | createTestData(); |
|
462 | 469 | m_chart->setTheme(theme); |
|
463 | 470 | QVERIFY(m_chart->theme()==theme); |
|
464 | 471 | } |
|
465 | 472 | |
|
466 | 473 | void tst_QChart::title_data() |
|
467 | 474 | { |
|
468 | 475 | QTest::addColumn<QString>("title"); |
|
469 | 476 | QTest::newRow("null") << QString(); |
|
470 | 477 | QTest::newRow("foo") << QString("foo"); |
|
471 | 478 | } |
|
472 | 479 | |
|
473 | 480 | void tst_QChart::title() |
|
474 | 481 | { |
|
475 | 482 | QFETCH(QString, title); |
|
476 | 483 | m_chart->setTitle(title); |
|
477 | 484 | QCOMPARE(m_chart->title(), title); |
|
478 | 485 | } |
|
479 | 486 | |
|
480 | 487 | void tst_QChart::titleBrush_data() |
|
481 | 488 | { |
|
482 | 489 | QTest::addColumn<QBrush>("titleBrush"); |
|
483 | 490 | QTest::newRow("null") << QBrush(); |
|
484 | 491 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
485 | 492 | QTest::newRow("white") << QBrush(Qt::white); |
|
486 | 493 | QTest::newRow("black") << QBrush(Qt::black); |
|
487 | 494 | } |
|
488 | 495 | |
|
489 | 496 | void tst_QChart::titleBrush() |
|
490 | 497 | { |
|
491 | 498 | QFETCH(QBrush, titleBrush); |
|
492 | 499 | m_chart->setTitleBrush(titleBrush); |
|
493 | 500 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
494 | 501 | } |
|
495 | 502 | |
|
496 | 503 | void tst_QChart::titleFont_data() |
|
497 | 504 | { |
|
498 | 505 | QTest::addColumn<QFont>("titleFont"); |
|
499 | 506 | QTest::newRow("null") << QFont(); |
|
500 | 507 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
501 | 508 | } |
|
502 | 509 | |
|
503 | 510 | void tst_QChart::titleFont() |
|
504 | 511 | { |
|
505 | 512 | QFETCH(QFont, titleFont); |
|
506 | 513 | m_chart->setTitleFont(titleFont); |
|
507 | 514 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
508 | 515 | } |
|
509 | 516 | |
|
510 | 517 | void tst_QChart::zoomIn_data() |
|
511 | 518 | { |
|
512 | 519 | QTest::addColumn<QRectF>("rect"); |
|
513 | 520 | QTest::newRow("null") << QRectF(); |
|
514 | 521 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
515 | 522 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
516 | 523 | } |
|
517 | 524 | |
|
518 | 525 | |
|
519 | 526 | void tst_QChart::zoomIn() |
|
520 | 527 | { |
|
521 | 528 | QFETCH(QRectF, rect); |
|
522 | 529 | createTestData(); |
|
523 | 530 | QRectF marigns = m_chart->margins(); |
|
524 | 531 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
525 | 532 | qreal minX = m_chart->axisX()->min(); |
|
526 | 533 | qreal minY = m_chart->axisY()->min(); |
|
527 | 534 | qreal maxX = m_chart->axisX()->max(); |
|
528 | 535 | qreal maxY = m_chart->axisY()->max(); |
|
529 | 536 | m_chart->zoomIn(rect); |
|
530 | 537 | if(rect.isValid()){ |
|
531 | 538 | QVERIFY(minX<m_chart->axisX()->min()); |
|
532 | 539 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
533 | 540 | QVERIFY(minY<m_chart->axisY()->min()); |
|
534 | 541 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
535 | 542 | } |
|
536 | 543 | } |
|
537 | 544 | |
|
538 | 545 | void tst_QChart::zoomOut_data() |
|
539 | 546 | { |
|
540 | 547 | |
|
541 | 548 | } |
|
542 | 549 | |
|
543 | 550 | void tst_QChart::zoomOut() |
|
544 | 551 | { |
|
545 | 552 | createTestData(); |
|
546 | 553 | qreal minX = m_chart->axisX()->min(); |
|
547 | 554 | qreal minY = m_chart->axisY()->min(); |
|
548 | 555 | qreal maxX = m_chart->axisX()->max(); |
|
549 | 556 | qreal maxY = m_chart->axisY()->max(); |
|
550 | 557 | |
|
551 | 558 | m_chart->zoomIn(); |
|
552 | 559 | |
|
553 | QVERIFY(minX<m_chart->axisX()->min()); | |
|
554 | QVERIFY(maxX>m_chart->axisX()->max()); | |
|
555 | QVERIFY(minY<m_chart->axisY()->min()); | |
|
556 | QVERIFY(maxY>m_chart->axisY()->max()); | |
|
560 | QVERIFY(minX < m_chart->axisX()->min()); | |
|
561 | QVERIFY(maxX > m_chart->axisX()->max()); | |
|
562 | QVERIFY(minY < m_chart->axisY()->min()); | |
|
563 | QVERIFY(maxY > m_chart->axisY()->max()); | |
|
557 | 564 | |
|
558 | 565 | m_chart->zoomOut(); |
|
559 | 566 | |
|
560 | QVERIFY(minX==m_chart->axisX()->min()); | |
|
561 | QVERIFY(maxX==m_chart->axisX()->max()); | |
|
562 |
QVERIFY( |
|
|
563 | QVERIFY(maxY==m_chart->axisY()->max()); | |
|
567 | // min x may be a zero value | |
|
568 | if (qFuzzyIsNull(minX)) | |
|
569 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
|
570 | else | |
|
571 | QCOMPARE(minX, m_chart->axisX()->min()); | |
|
572 | ||
|
573 | // min y may be a zero value | |
|
574 | if (qFuzzyIsNull(minY)) | |
|
575 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
|
576 | else | |
|
577 | QCOMPARE(minY, m_chart->axisY()->min()); | |
|
578 | ||
|
579 | QVERIFY(maxX == m_chart->axisX()->max()); | |
|
580 | QVERIFY(maxY == m_chart->axisY()->max()); | |
|
564 | 581 | } |
|
565 | 582 | |
|
566 | 583 | QTEST_MAIN(tst_QChart) |
|
567 | 584 | #include "tst_qchart.moc" |
|
568 | 585 |
@@ -1,170 +1,171 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <cmath> |
|
25 | #include <tst_definitions.h> | |
|
25 | 26 | |
|
26 | 27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 28 | |
|
28 | 29 | |
|
29 | 30 | Q_DECLARE_METATYPE(QChart*) |
|
30 | 31 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
31 | 32 | Q_DECLARE_METATYPE(Qt::Key) |
|
32 | 33 | |
|
33 | 34 | class tst_QChartView : public QObject |
|
34 | 35 | { |
|
35 | 36 | Q_OBJECT |
|
36 | 37 | |
|
37 | 38 | public Q_SLOTS: |
|
38 | 39 | void initTestCase(); |
|
39 | 40 | void cleanupTestCase(); |
|
40 | 41 | void init(); |
|
41 | 42 | void cleanup(); |
|
42 | 43 | |
|
43 | 44 | private Q_SLOTS: |
|
44 | 45 | void qchartview_data(); |
|
45 | 46 | void qchartview(); |
|
46 | 47 | void chart_data(); |
|
47 | 48 | void chart(); |
|
48 | 49 | void rubberBand_data(); |
|
49 | 50 | void rubberBand(); |
|
50 | 51 | |
|
51 | 52 | private: |
|
52 | 53 | QChartView* m_view; |
|
53 | 54 | }; |
|
54 | 55 | |
|
55 | 56 | void tst_QChartView::initTestCase() |
|
56 | 57 | { |
|
57 | 58 | //test tracks mouse, give a while to user to relese it |
|
58 | 59 | QTest::qWait(1000); |
|
59 | 60 | } |
|
60 | 61 | |
|
61 | 62 | void tst_QChartView::cleanupTestCase() |
|
62 | 63 | { |
|
63 | 64 | } |
|
64 | 65 | |
|
65 | 66 | void tst_QChartView::init() |
|
66 | 67 | { |
|
67 | 68 | m_view = new QChartView(new QChart()); |
|
68 | 69 | m_view->chart()->legend()->setVisible(false); |
|
69 | 70 | } |
|
70 | 71 | |
|
71 | 72 | void tst_QChartView::cleanup() |
|
72 | 73 | { |
|
73 | 74 | delete m_view; |
|
74 | 75 | m_view =0; |
|
75 | 76 | } |
|
76 | 77 | |
|
77 | 78 | void tst_QChartView::qchartview_data() |
|
78 | 79 | { |
|
79 | 80 | |
|
80 | 81 | } |
|
81 | 82 | |
|
82 | 83 | void tst_QChartView::qchartview() |
|
83 | 84 | { |
|
84 | 85 | QVERIFY(m_view->chart()); |
|
85 | 86 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
86 | 87 | m_view->show(); |
|
87 | 88 | QTest::qWaitForWindowShown(m_view); |
|
88 | 89 | } |
|
89 | 90 | |
|
90 | 91 | void tst_QChartView::chart_data() |
|
91 | 92 | { |
|
92 | 93 | |
|
93 | 94 | QTest::addColumn<QChart*>("chart"); |
|
94 | 95 | QTest::newRow("qchart") << new QChart(); |
|
95 | 96 | } |
|
96 | 97 | |
|
97 | 98 | void tst_QChartView::chart() |
|
98 | 99 | { |
|
99 | 100 | QFETCH(QChart*, chart); |
|
100 | 101 | QChartView* view = new QChartView(chart); |
|
101 | 102 | QCOMPARE(view->chart(), chart); |
|
102 | 103 | delete view; |
|
103 | 104 | } |
|
104 | 105 | |
|
105 | 106 | void tst_QChartView::rubberBand_data() |
|
106 | 107 | { |
|
107 | 108 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
108 | 109 | QTest::addColumn<int>("Xcount"); |
|
109 | 110 | QTest::addColumn<int>("Ycount"); |
|
110 | 111 | |
|
111 | 112 | QTest::addColumn<int>("minX"); |
|
112 | 113 | QTest::addColumn<int>("maxX"); |
|
113 | 114 | QTest::addColumn<int>("minY"); |
|
114 | 115 | QTest::addColumn<int>("maxY"); |
|
115 | 116 | |
|
116 | 117 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
117 | 118 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
118 | 119 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
119 | 120 | } |
|
120 | 121 | |
|
121 | 122 | void tst_QChartView::rubberBand() |
|
122 | 123 | { |
|
123 | 124 | QFETCH(QChartView::RubberBands, rubberBand); |
|
124 | 125 | QFETCH(int, Xcount); |
|
125 | 126 | QFETCH(int, Ycount); |
|
126 | 127 | QFETCH(int, minX); |
|
127 | 128 | QFETCH(int, maxX); |
|
128 | 129 | QFETCH(int, minY); |
|
129 | 130 | QFETCH(int, maxY); |
|
130 | 131 | |
|
131 | 132 | m_view->setRubberBand(rubberBand); |
|
132 | 133 | QRectF padding = m_view->chart()->margins(); |
|
133 | 134 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
134 | 135 | |
|
135 | 136 | QLineSeries* line = new QLineSeries(); |
|
136 | 137 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
137 | 138 | |
|
138 | 139 | m_view->chart()->addSeries(line); |
|
139 | 140 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
140 | 141 | m_view->show(); |
|
141 | 142 | |
|
142 | 143 | //this is hack since view does not get events otherwise |
|
143 | 144 | m_view->setMouseTracking(true); |
|
144 | 145 | |
|
145 | 146 | QAxis* axisY = m_view->chart()->axisY(); |
|
146 | 147 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
147 | 148 | QAxis* axisX = m_view->chart()->axisX(); |
|
148 | 149 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
149 | 150 | |
|
150 | 151 | QTest::qWaitForWindowShown(m_view); |
|
151 | 152 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
152 | 153 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
153 | 154 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
154 | 155 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
155 | 156 | |
|
156 |
|
|
|
157 |
|
|
|
157 | TRY_COMPARE(spy0.count(), Xcount); | |
|
158 | TRY_COMPARE(spy1.count(), Ycount); | |
|
158 | 159 | |
|
159 | 160 | //this is hack since view does not get events otherwise |
|
160 | 161 | m_view->setMouseTracking(false); |
|
161 | 162 | |
|
162 | 163 | QVERIFY(axisX->min() - minX < 1); |
|
163 | 164 | QVERIFY(axisX->max() - maxX < 1); |
|
164 | 165 | QVERIFY(axisY->min() - minY < 1); |
|
165 | 166 | QVERIFY(axisY->max() - maxY < 1); |
|
166 | 167 | } |
|
167 | 168 | |
|
168 | 169 | QTEST_MAIN(tst_QChartView) |
|
169 | 170 | #include "tst_qchartview.moc" |
|
170 | 171 |
@@ -1,636 +1,625 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qlineseries.h> |
|
23 | 23 | #include <qchartview.h> |
|
24 | 24 | #include <QStandardItemModel> |
|
25 | #include <tst_definitions.h> | |
|
25 | 26 | |
|
26 | 27 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
27 | 28 | |
|
28 | 29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 30 | |
|
30 | 31 | class tst_QLineSeries : public QObject |
|
31 | 32 | { |
|
32 | 33 | Q_OBJECT |
|
33 | 34 | |
|
34 | 35 | public slots: |
|
35 | 36 | void initTestCase(); |
|
36 | 37 | void cleanupTestCase(); |
|
37 | 38 | void init(); |
|
38 | 39 | void cleanup(); |
|
39 | 40 | |
|
40 | 41 | private slots: |
|
41 | 42 | void qlineseries_data(); |
|
42 | 43 | void qlineseries(); |
|
43 | 44 | void append_raw_data(); |
|
44 | 45 | void append_raw(); |
|
45 | 46 | void append_chart_data(); |
|
46 | 47 | void append_chart(); |
|
47 | 48 | void append_chart_animation_data(); |
|
48 | 49 | void append_chart_animation(); |
|
49 | 50 | void chart_append_data(); |
|
50 | 51 | void chart_append(); |
|
51 | 52 | void count_raw_data(); |
|
52 | 53 | void count_raw(); |
|
53 | 54 | void oper_data(); |
|
54 | 55 | void oper(); |
|
55 | 56 | void pen_data(); |
|
56 | 57 | void pen(); |
|
57 | 58 | void pointsVisible_raw_data(); |
|
58 | 59 | void pointsVisible_raw(); |
|
59 | 60 | void remove_raw_data(); |
|
60 | 61 | void remove_raw(); |
|
61 | 62 | void remove_chart_data(); |
|
62 | 63 | void remove_chart(); |
|
63 | 64 | void remove_chart_animation_data(); |
|
64 | 65 | void remove_chart_animation(); |
|
65 | 66 | void removeAll_raw_data(); |
|
66 | 67 | void removeAll_raw(); |
|
67 | 68 | void removeAll_chart_data(); |
|
68 | 69 | void removeAll_chart(); |
|
69 | 70 | void removeAll_chart_animation_data(); |
|
70 | 71 | void removeAll_chart_animation(); |
|
71 | 72 | void replace_raw_data(); |
|
72 | 73 | void replace_raw(); |
|
73 | 74 | void replace_chart_data(); |
|
74 | 75 | void replace_chart(); |
|
75 | 76 | void replace_chart_animation_data(); |
|
76 | 77 | void replace_chart_animation(); |
|
77 | 78 | void setModel_data(); |
|
78 | 79 | void setModel(); |
|
79 | 80 | void setModelMapping_data(); |
|
80 | 81 | void setModelMapping(); |
|
81 | 82 | void setModelMappingRange_data(); |
|
82 | 83 | void setModelMappingRange(); |
|
83 | 84 | void modelUpdated(); |
|
84 | 85 | void modelUpdatedCustomMapping(); |
|
85 | 86 | private: |
|
86 | 87 | void append_data(); |
|
87 | 88 | void count_data(); |
|
88 | 89 | void pointsVisible_data(); |
|
89 | 90 | |
|
90 | 91 | private: |
|
91 | 92 | QChartView* m_view; |
|
92 | 93 | QChart* m_chart; |
|
93 | 94 | QLineSeries* m_series; |
|
94 | 95 | }; |
|
95 | 96 | |
|
96 | 97 | void tst_QLineSeries::initTestCase() |
|
97 | 98 | { |
|
98 | 99 | } |
|
99 | 100 | |
|
100 | 101 | void tst_QLineSeries::cleanupTestCase() |
|
101 | 102 | { |
|
102 | 103 | } |
|
103 | 104 | |
|
104 | 105 | void tst_QLineSeries::init() |
|
105 | 106 | { |
|
106 | 107 | m_view = new QChartView(new QChart()); |
|
107 | 108 | m_chart = m_view->chart(); |
|
108 | 109 | m_series = new QLineSeries(); |
|
109 | 110 | } |
|
110 | 111 | |
|
111 | 112 | void tst_QLineSeries::cleanup() |
|
112 | 113 | { |
|
113 | 114 | delete m_series; |
|
114 | 115 | delete m_view; |
|
115 | 116 | m_view = 0; |
|
116 | 117 | m_chart = 0; |
|
117 | 118 | m_series = 0; |
|
118 | 119 | } |
|
119 | 120 | |
|
120 | 121 | void tst_QLineSeries::qlineseries_data() |
|
121 | 122 | { |
|
122 | 123 | |
|
123 | 124 | } |
|
124 | 125 | |
|
125 | 126 | void tst_QLineSeries::qlineseries() |
|
126 | 127 | { |
|
127 | 128 | QLineSeries series; |
|
128 | 129 | |
|
129 | 130 | QCOMPARE(series.count(),0); |
|
130 | 131 | QCOMPARE(series.brush(), QBrush()); |
|
131 | 132 | QCOMPARE(series.points(), QList<QPointF>()); |
|
132 | 133 | QCOMPARE(series.pen(), QPen()); |
|
133 | 134 | QCOMPARE(series.pointsVisible(), false); |
|
134 | 135 | |
|
135 | 136 | series.append(QList<QPointF>()); |
|
136 | 137 | series.append(0.0,0.0); |
|
137 | 138 | series.append(QPointF()); |
|
138 | 139 | |
|
139 | 140 | series.remove(0.0,0.0); |
|
140 | 141 | series.remove(QPointF()); |
|
141 | 142 | series.removeAll(); |
|
142 | 143 | |
|
143 | 144 | series.replace(QPointF(),QPointF()); |
|
144 | 145 | series.replace(0,0,0,0); |
|
145 | 146 | series.setBrush(QBrush()); |
|
146 | 147 | |
|
147 | 148 | QCOMPARE(series.setModel((QAbstractItemModel*)0), false); |
|
148 | 149 | |
|
149 | 150 | series.setModelMapping(-1, -1, Qt::Orientation(0)); |
|
150 | 151 | |
|
151 | 152 | series.setPen(QPen()); |
|
152 | 153 | series.setPointsVisible(false); |
|
153 | 154 | |
|
154 | 155 | m_chart->addSeries(&series); |
|
155 | 156 | m_view->show(); |
|
156 | 157 | QTest::qWaitForWindowShown(m_view); |
|
157 | 158 | } |
|
158 | 159 | |
|
159 | 160 | void tst_QLineSeries::append_data() |
|
160 | 161 | { |
|
161 | 162 | QTest::addColumn< QList<QPointF> >("points"); |
|
162 | 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 | 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 | 168 | void tst_QLineSeries::append_raw_data() |
|
168 | 169 | { |
|
169 | 170 | append_data(); |
|
170 | 171 | } |
|
171 | 172 | |
|
172 | 173 | void tst_QLineSeries::append_raw() |
|
173 | 174 | { |
|
174 | 175 | QFETCH(QList<QPointF>, points); |
|
175 | 176 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
176 | QTest::qWait(200); | |
|
177 | 177 | m_series->append(points); |
|
178 | QTest::qWait(200); | |
|
179 | QCOMPARE(spy0.count(), 0); | |
|
178 | TRY_COMPARE(spy0.count(), 0); | |
|
180 | 179 | QCOMPARE(m_series->points(), points); |
|
181 | 180 | } |
|
182 | 181 | |
|
183 | 182 | void tst_QLineSeries::chart_append_data() |
|
184 | 183 | { |
|
185 | 184 | append_data(); |
|
186 | 185 | } |
|
187 | 186 | |
|
188 | 187 | void tst_QLineSeries::chart_append() |
|
189 | 188 | { |
|
190 | 189 | append_raw(); |
|
191 | 190 | m_chart->addSeries(m_series); |
|
192 | 191 | m_view->show(); |
|
193 | 192 | QTest::qWaitForWindowShown(m_view); |
|
194 | 193 | } |
|
195 | 194 | |
|
196 | 195 | void tst_QLineSeries::append_chart_data() |
|
197 | 196 | { |
|
198 | 197 | append_data(); |
|
199 | 198 | } |
|
200 | 199 | |
|
201 | 200 | void tst_QLineSeries::append_chart() |
|
202 | 201 | { |
|
203 | 202 | m_view->show(); |
|
204 | 203 | m_chart->addSeries(m_series); |
|
205 | 204 | QTest::qWaitForWindowShown(m_view); |
|
206 | 205 | append_raw(); |
|
207 | 206 | |
|
208 | 207 | } |
|
209 | 208 | |
|
210 | 209 | void tst_QLineSeries::append_chart_animation_data() |
|
211 | 210 | { |
|
212 | 211 | append_data(); |
|
213 | 212 | } |
|
214 | 213 | |
|
215 | 214 | void tst_QLineSeries::append_chart_animation() |
|
216 | 215 | { |
|
217 | 216 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
218 | 217 | append_chart(); |
|
219 | 218 | } |
|
220 | 219 | |
|
221 | 220 | void tst_QLineSeries::count_data() |
|
222 | 221 | { |
|
223 | 222 | QTest::addColumn<int>("count"); |
|
224 | 223 | QTest::newRow("0") << 0; |
|
225 | 224 | QTest::newRow("5") << 5; |
|
226 | 225 | QTest::newRow("10") << 5; |
|
227 | 226 | } |
|
228 | 227 | |
|
229 | 228 | void tst_QLineSeries::count_raw_data() |
|
230 | 229 | { |
|
231 | 230 | count_data(); |
|
232 | 231 | } |
|
233 | 232 | |
|
234 | 233 | void tst_QLineSeries::count_raw() |
|
235 | 234 | { |
|
236 | 235 | QFETCH(int, count); |
|
237 | 236 | |
|
238 | 237 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
239 | 238 | |
|
240 | 239 | for(int i=0 ; i< count; ++i) |
|
241 | 240 | m_series->append(i,i); |
|
242 | 241 | |
|
243 |
|
|
|
242 | TRY_COMPARE(spy0.count(), 0); | |
|
244 | 243 | QCOMPARE(m_series->count(), count); |
|
245 | 244 | } |
|
246 | 245 | |
|
247 | 246 | void tst_QLineSeries::oper_data() |
|
248 | 247 | { |
|
249 | 248 | append_data(); |
|
250 | 249 | } |
|
251 | 250 | |
|
252 | 251 | void tst_QLineSeries::oper() |
|
253 | 252 | { |
|
254 | 253 | QFETCH(QList<QPointF>, points); |
|
255 | 254 | QLineSeries series; |
|
256 | 255 | |
|
257 | 256 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); |
|
258 | 257 | |
|
259 | 258 | foreach(const QPointF& point,points) |
|
260 | 259 | { |
|
261 | 260 | series<<point; |
|
262 | 261 | } |
|
263 | 262 | |
|
264 | 263 | QCOMPARE(series.points(), points); |
|
265 |
|
|
|
264 | TRY_COMPARE(spy0.count(), 0); | |
|
266 | 265 | } |
|
267 | 266 | |
|
268 | 267 | |
|
269 | 268 | void tst_QLineSeries::pen_data() |
|
270 | 269 | { |
|
271 | 270 | QTest::addColumn<QPen>("pen"); |
|
272 | 271 | QTest::newRow("null") << QPen(); |
|
273 | 272 | QTest::newRow("blue") << QPen(Qt::blue); |
|
274 | 273 | QTest::newRow("black") << QPen(Qt::black); |
|
275 | 274 | QTest::newRow("red") << QPen(Qt::red); |
|
276 | 275 | } |
|
277 | 276 | |
|
278 | 277 | void tst_QLineSeries::pen() |
|
279 | 278 | { |
|
280 | 279 | QFETCH(QPen, pen); |
|
281 | 280 | QLineSeries series; |
|
282 | 281 | |
|
283 | 282 | QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); |
|
284 | 283 | series.setPen(pen); |
|
285 | 284 | |
|
286 |
|
|
|
285 | TRY_COMPARE(spy0.count(), 0); | |
|
287 | 286 | QCOMPARE(series.pen(), pen); |
|
288 | 287 | |
|
289 | 288 | m_chart->addSeries(&series); |
|
290 | 289 | |
|
291 | 290 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); |
|
292 | 291 | |
|
293 | 292 | m_chart->setTheme(QChart::ChartThemeDark); |
|
294 | 293 | |
|
295 | 294 | if(pen!=QPen()) QCOMPARE(series.pen(), pen); |
|
296 | 295 | } |
|
297 | 296 | |
|
298 | 297 | void tst_QLineSeries::pointsVisible_data() |
|
299 | 298 | { |
|
300 | 299 | QTest::addColumn<bool>("pointsVisible"); |
|
301 | 300 | QTest::newRow("true") << true; |
|
302 | 301 | QTest::newRow("false") << false; |
|
303 | 302 | } |
|
304 | 303 | |
|
305 | 304 | void tst_QLineSeries::pointsVisible_raw_data() |
|
306 | 305 | { |
|
307 | 306 | pointsVisible_data(); |
|
308 | 307 | } |
|
309 | 308 | |
|
310 | 309 | void tst_QLineSeries::pointsVisible_raw() |
|
311 | 310 | { |
|
312 | 311 | QFETCH(bool, pointsVisible); |
|
313 | 312 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
314 | 313 | m_series->setPointsVisible(pointsVisible); |
|
315 |
|
|
|
314 | TRY_COMPARE(spy0.count(), 0); | |
|
316 | 315 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
317 | 316 | } |
|
318 | 317 | |
|
319 | 318 | void tst_QLineSeries::remove_raw_data() |
|
320 | 319 | { |
|
321 | 320 | append_data(); |
|
322 | 321 | } |
|
323 | 322 | |
|
324 | 323 | void tst_QLineSeries::remove_raw() |
|
325 | 324 | { |
|
326 | 325 | QFETCH(QList<QPointF>, points); |
|
327 | 326 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
328 | 327 | m_series->append(points); |
|
329 | QTest::qWait(200); | |
|
330 | QCOMPARE(spy0.count(), 0); | |
|
328 | TRY_COMPARE(spy0.count(), 0); | |
|
331 | 329 | QCOMPARE(m_series->points(), points); |
|
332 | 330 | |
|
333 | 331 | foreach(const QPointF& point,points) |
|
334 | { | |
|
335 | 332 | m_series->remove(point); |
|
336 | QTest::qWait(200); | |
|
337 | } | |
|
338 | 333 | |
|
339 |
|
|
|
334 | TRY_COMPARE(spy0.count(), 0); | |
|
340 | 335 | QCOMPARE(m_series->points().count(), 0); |
|
341 | 336 | } |
|
342 | 337 | |
|
343 | 338 | void tst_QLineSeries::remove_chart_data() |
|
344 | 339 | { |
|
345 | 340 | append_data(); |
|
346 | 341 | } |
|
347 | 342 | |
|
348 | 343 | void tst_QLineSeries::remove_chart() |
|
349 | 344 | { |
|
350 | 345 | m_view->show(); |
|
351 | 346 | m_chart->addSeries(m_series); |
|
352 | 347 | QTest::qWaitForWindowShown(m_view); |
|
353 | 348 | remove_raw(); |
|
354 | 349 | } |
|
355 | 350 | |
|
356 | 351 | void tst_QLineSeries::remove_chart_animation_data() |
|
357 | 352 | { |
|
358 | 353 | append_data(); |
|
359 | 354 | } |
|
360 | 355 | |
|
361 | 356 | void tst_QLineSeries::remove_chart_animation() |
|
362 | 357 | { |
|
363 | 358 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
364 | 359 | remove_chart(); |
|
365 | 360 | } |
|
366 | 361 | |
|
367 | 362 | |
|
368 | 363 | void tst_QLineSeries::removeAll_raw_data() |
|
369 | 364 | { |
|
370 | 365 | append_data(); |
|
371 | 366 | } |
|
372 | 367 | |
|
373 | 368 | void tst_QLineSeries::removeAll_raw() |
|
374 | 369 | { |
|
375 | 370 | QFETCH(QList<QPointF>, points); |
|
376 | 371 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
377 | 372 | m_series->append(points); |
|
378 |
|
|
|
373 | TRY_COMPARE(spy0.count(), 0); | |
|
379 | 374 | QCOMPARE(m_series->points(), points); |
|
380 | QTest::qWait(200); | |
|
381 | 375 | m_series->removeAll(); |
|
382 | QTest::qWait(200); | |
|
383 | QCOMPARE(spy0.count(), 0); | |
|
376 | TRY_COMPARE(spy0.count(), 0); | |
|
384 | 377 | QCOMPARE(m_series->points().count(), 0); |
|
385 | 378 | } |
|
386 | 379 | |
|
387 | 380 | void tst_QLineSeries::removeAll_chart_data() |
|
388 | 381 | { |
|
389 | 382 | append_data(); |
|
390 | 383 | } |
|
391 | 384 | |
|
392 | 385 | void tst_QLineSeries::removeAll_chart() |
|
393 | 386 | { |
|
394 | 387 | m_view->show(); |
|
395 | 388 | m_chart->addSeries(m_series); |
|
396 | 389 | QTest::qWaitForWindowShown(m_view); |
|
397 | 390 | removeAll_raw(); |
|
398 | 391 | } |
|
399 | 392 | |
|
400 | 393 | void tst_QLineSeries::removeAll_chart_animation_data() |
|
401 | 394 | { |
|
402 | 395 | append_data(); |
|
403 | 396 | } |
|
404 | 397 | |
|
405 | 398 | void tst_QLineSeries::removeAll_chart_animation() |
|
406 | 399 | { |
|
407 | 400 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
408 | 401 | removeAll_chart(); |
|
409 | 402 | } |
|
410 | 403 | |
|
411 | 404 | void tst_QLineSeries::replace_raw_data() |
|
412 | 405 | { |
|
413 | 406 | append_data(); |
|
414 | 407 | } |
|
415 | 408 | |
|
416 | 409 | void tst_QLineSeries::replace_raw() |
|
417 | 410 | { |
|
418 | 411 | QFETCH(QList<QPointF>, points); |
|
419 | 412 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
420 | 413 | m_series->append(points); |
|
421 |
|
|
|
414 | TRY_COMPARE(spy0.count(), 0); | |
|
422 | 415 | QCOMPARE(m_series->points(), points); |
|
423 | QTest::qWait(200); | |
|
424 | 416 | |
|
425 | 417 | foreach(const QPointF& point,points) |
|
426 | { | |
|
427 | m_series->replace(point.x(),point.y(),point.x(),0); | |
|
428 | QTest::qWait(200); | |
|
429 | } | |
|
418 | m_series->replace(point.x(),point.y(),point.x(),0); | |
|
430 | 419 | |
|
431 | 420 | QList<QPointF> newPoints = m_series->points(); |
|
432 | 421 | |
|
433 | 422 | QCOMPARE(newPoints.count(), points.count()); |
|
434 | 423 | |
|
435 | 424 | for(int i =0 ; i<points.count() ; ++i) { |
|
436 | 425 | QCOMPARE(points[i].x(), newPoints[i].x()); |
|
437 | 426 | QCOMPARE(newPoints[i].y(), 0.0); |
|
438 | 427 | } |
|
439 | 428 | } |
|
440 | 429 | |
|
441 | 430 | |
|
442 | 431 | void tst_QLineSeries::replace_chart_data() |
|
443 | 432 | { |
|
444 | 433 | append_data(); |
|
445 | 434 | } |
|
446 | 435 | |
|
447 | 436 | void tst_QLineSeries::replace_chart() |
|
448 | 437 | { |
|
449 | 438 | m_view->show(); |
|
450 | 439 | m_chart->addSeries(m_series); |
|
451 | 440 | QTest::qWaitForWindowShown(m_view); |
|
452 | 441 | replace_raw(); |
|
453 | 442 | } |
|
454 | 443 | |
|
455 | 444 | void tst_QLineSeries::replace_chart_animation_data() |
|
456 | 445 | { |
|
457 | 446 | append_data(); |
|
458 | 447 | } |
|
459 | 448 | |
|
460 | 449 | void tst_QLineSeries::replace_chart_animation() |
|
461 | 450 | { |
|
462 | 451 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
463 | 452 | replace_chart(); |
|
464 | 453 | } |
|
465 | 454 | |
|
466 | 455 | void tst_QLineSeries::setModel_data() |
|
467 | 456 | { |
|
468 | 457 | |
|
469 | 458 | } |
|
470 | 459 | |
|
471 | 460 | void tst_QLineSeries::setModel() |
|
472 | 461 | { |
|
473 | 462 | QLineSeries series; |
|
474 | 463 | series.setModel(0); |
|
475 | 464 | QVERIFY2(series.model() == 0, "Model should be unset"); |
|
476 | 465 | |
|
477 | 466 | QStandardItemModel *stdModel = new QStandardItemModel(); |
|
478 | 467 | series.setModel(stdModel); |
|
479 | 468 | QVERIFY2((series.model()) == stdModel, "Model should be stdModel"); |
|
480 | 469 | |
|
481 | 470 | // unset the model |
|
482 | 471 | series.setModel(0); |
|
483 | 472 | QVERIFY2(series.model() == 0, "Model should be unset"); |
|
484 | 473 | |
|
485 | 474 | } |
|
486 | 475 | |
|
487 | 476 | Q_DECLARE_METATYPE(Qt::Orientation) |
|
488 | 477 | void tst_QLineSeries::setModelMapping_data() |
|
489 | 478 | { |
|
490 | 479 | QTest::addColumn<int>("modelX"); |
|
491 | 480 | QTest::addColumn<int>("modelY"); |
|
492 | 481 | QTest::addColumn<Qt::Orientation>("orientation"); |
|
493 | 482 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; |
|
494 | 483 | QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; |
|
495 | 484 | QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; |
|
496 | 485 | |
|
497 | 486 | QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; |
|
498 | 487 | QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; |
|
499 | 488 | QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; |
|
500 | 489 | } |
|
501 | 490 | |
|
502 | 491 | void tst_QLineSeries::setModelMapping() |
|
503 | 492 | { |
|
504 | 493 | QFETCH(int, modelX); |
|
505 | 494 | QFETCH(int, modelY); |
|
506 | 495 | QFETCH(Qt::Orientation, orientation); |
|
507 | 496 | |
|
508 | 497 | QLineSeries series; |
|
509 | 498 | |
|
510 | 499 | // model has not been set so setting mapping should do nothing |
|
511 | 500 | series.setModelMapping(modelX, modelY, orientation); |
|
512 | 501 | QCOMPARE(series.mapX(), -1); |
|
513 | 502 | QCOMPARE(series.mapY(), -1); |
|
514 | 503 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); |
|
515 | 504 | |
|
516 | 505 | // now let us set the model |
|
517 | 506 | series.setModel(new QStandardItemModel()); |
|
518 | 507 | series.setModelMapping(modelX, modelY, orientation); |
|
519 | 508 | QCOMPARE(series.mapX(), modelX); |
|
520 | 509 | QCOMPARE(series.mapY(), modelY); |
|
521 | 510 | QVERIFY2(series.mapOrientation() == orientation, "not good"); |
|
522 | 511 | |
|
523 | 512 | // now let us remove the model, the values should go back to default ones. |
|
524 | 513 | series.setModel(0); |
|
525 | 514 | QCOMPARE(series.mapX(), -1); |
|
526 | 515 | QCOMPARE(series.mapY(), -1); |
|
527 | 516 | QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); |
|
528 | 517 | } |
|
529 | 518 | |
|
530 | 519 | void tst_QLineSeries::setModelMappingRange_data() |
|
531 | 520 | { |
|
532 | 521 | QTest::addColumn<int>("first"); |
|
533 | 522 | QTest::addColumn<int>("count"); |
|
534 | 523 | QTest::newRow("first: 0, count: unlimited") << 0 << -1; |
|
535 | 524 | QTest::newRow("first: 0, count: 5") << 0 << 5; |
|
536 | 525 | QTest::newRow("first: 3, count: unlimited") << 3 << -1; |
|
537 | 526 | QTest::newRow("first: 3, count: 5") << 3 << 5; |
|
538 | 527 | QTest::newRow("first: -3, count: 5") << -3 << 5; |
|
539 | 528 | QTest::newRow("first: 3, count: -5") << 3 << -5; |
|
540 | 529 | QTest::newRow("first: -3, count: -5") << 3 << -5; |
|
541 | 530 | QTest::newRow("first: -3, count: 0") << -3 << 0; |
|
542 | 531 | QTest::newRow("first: 0, count: -5") << 0 << -5; |
|
543 | 532 | QTest::newRow("first: 0, count: 0") << 0 << 0; |
|
544 | 533 | } |
|
545 | 534 | |
|
546 | 535 | void tst_QLineSeries::setModelMappingRange() |
|
547 | 536 | { |
|
548 | 537 | QFETCH(int, first); |
|
549 | 538 | QFETCH(int, count); |
|
550 | 539 | QLineSeries series; |
|
551 | 540 | |
|
552 | 541 | QStandardItemModel *model = new QStandardItemModel(0, 2); |
|
553 | 542 | series.setModel(model); |
|
554 | 543 | series.setModelMapping(0, 1); |
|
555 | 544 | series.setModelMappingRange(first, count); |
|
556 | 545 | |
|
557 | 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 | 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 | 548 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); |
|
560 | 549 | |
|
561 | 550 | for (int row = 0; row < 3; ++row) { |
|
562 | 551 | for (int column = 0; column < 2; column++) { |
|
563 | 552 | QStandardItem *item = new QStandardItem(row * column); |
|
564 | 553 | model->setItem(row, column, item); |
|
565 | 554 | } |
|
566 | 555 | } |
|
567 | 556 | if (qMax(count, -1) != -1) |
|
568 | 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 | 558 | else |
|
570 | 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 | 561 | // let's add few more rows to the model |
|
573 | 562 | for (int row = 0; row < 10; ++row) { |
|
574 | 563 | QList<QStandardItem *> newRow; |
|
575 | 564 | for (int column = 0; column < 2; column++) { |
|
576 | 565 | newRow.append(new QStandardItem(row * column)); |
|
577 | 566 | } |
|
578 | 567 | model->appendRow(newRow); |
|
579 | 568 | } |
|
580 | 569 | if (qMax(count, -1) != -1) |
|
581 | 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 | 571 | else |
|
583 | 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 | 574 | // unset the model, values should be default |
|
586 | 575 | series.setModel(0); |
|
587 | 576 | QCOMPARE(series.mapFirst(), 0); |
|
588 | 577 | QCOMPARE(series.mapCount(), -1); |
|
589 | 578 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); |
|
590 | 579 | } |
|
591 | 580 | |
|
592 | 581 | void tst_QLineSeries::modelUpdated() |
|
593 | 582 | { |
|
594 | 583 | QStandardItemModel *model = new QStandardItemModel; |
|
595 | 584 | for (int row = 0; row < 10; ++row) { |
|
596 | 585 | QList<QStandardItem *> newRow; |
|
597 | 586 | for (int column = 0; column < 2; column++) { |
|
598 | 587 | newRow.append(new QStandardItem(row * column)); |
|
599 | 588 | } |
|
600 | 589 | model->appendRow(newRow); |
|
601 | 590 | } |
|
602 | 591 | |
|
603 | 592 | QLineSeries series; |
|
604 | 593 | series.setModel(model); |
|
605 | 594 | series.setModelMapping(0, 1); |
|
606 | 595 | |
|
607 | 596 | model->setData(model->index(3, 1), 34); |
|
608 | 597 | // check that the update data is correctly taken from the model |
|
609 | 598 | QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34)); |
|
610 | 599 | } |
|
611 | 600 | |
|
612 | 601 | void tst_QLineSeries::modelUpdatedCustomMapping() |
|
613 | 602 | { |
|
614 | 603 | |
|
615 | 604 | QStandardItemModel *model = new QStandardItemModel; |
|
616 | 605 | for (int row = 0; row < 10; ++row) { |
|
617 | 606 | QList<QStandardItem *> newRow; |
|
618 | 607 | for (int column = 0; column < 2; column++) { |
|
619 | 608 | newRow.append(new QStandardItem(row * column)); |
|
620 | 609 | } |
|
621 | 610 | model->appendRow(newRow); |
|
622 | 611 | } |
|
623 | 612 | |
|
624 | 613 | QLineSeries series; |
|
625 | 614 | series.setModel(model); |
|
626 | 615 | series.setModelMapping(0, 1); |
|
627 | 616 | series.setModelMappingRange(3, 4); |
|
628 | 617 | |
|
629 | 618 | model->setData(model->index(3, 1), 34); |
|
630 | 619 | QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34)); |
|
631 | 620 | } |
|
632 | 621 | |
|
633 | 622 | QTEST_MAIN(tst_QLineSeries) |
|
634 | 623 | |
|
635 | 624 | #include "tst_qlineseries.moc" |
|
636 | 625 |
@@ -1,220 +1,328 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | #include <qchartview.h> | |
|
23 | #include <qchart.h> | |
|
22 | 24 | #include <qpieseries.h> |
|
23 | 25 | #include <qpieslice.h> |
|
26 | #include <tst_definitions.h> | |
|
24 | 27 | |
|
25 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 29 | |
|
30 | Q_DECLARE_METATYPE(QPieSlice*) | |
|
31 | ||
|
27 | 32 | class tst_qpieseries : public QObject |
|
28 | 33 | { |
|
29 | 34 | Q_OBJECT |
|
30 | 35 | |
|
31 | 36 | public slots: |
|
32 | 37 | void initTestCase(); |
|
33 | 38 | void cleanupTestCase(); |
|
34 | 39 | void init(); |
|
35 | 40 | void cleanup(); |
|
36 | 41 | |
|
37 | 42 | private slots: |
|
38 | 43 | void construction(); |
|
39 | 44 | void append(); |
|
40 | 45 | void insert(); |
|
41 | 46 | void remove(); |
|
42 |
|
|
|
43 | //void themes(); | |
|
44 |
|
|
|
45 | //void hoverSignal(); | |
|
47 | void calculatedValues(); | |
|
48 | void clickedSignal(); | |
|
49 | void hoverSignal(); | |
|
46 | 50 | |
|
47 | 51 | private: |
|
48 | ||
|
52 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
|
49 | 53 | |
|
50 | 54 | private: |
|
51 | 55 | |
|
52 | 56 | }; |
|
53 | 57 | |
|
54 | 58 | void tst_qpieseries::initTestCase() |
|
55 | 59 | { |
|
60 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
|
56 | 61 | } |
|
57 | 62 | |
|
58 | 63 | void tst_qpieseries::cleanupTestCase() |
|
59 | 64 | { |
|
60 | 65 | } |
|
61 | 66 | |
|
62 | 67 | void tst_qpieseries::init() |
|
63 | 68 | { |
|
64 | 69 | |
|
65 | 70 | } |
|
66 | 71 | |
|
67 | 72 | void tst_qpieseries::cleanup() |
|
68 | 73 | { |
|
69 | 74 | |
|
70 | 75 | } |
|
71 | 76 | |
|
72 | 77 | void tst_qpieseries::construction() |
|
73 | 78 | { |
|
74 | 79 | // verify default values |
|
75 | 80 | QPieSeries s; |
|
76 | 81 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); |
|
77 | 82 | QVERIFY(s.count() == 0); |
|
78 | 83 | QVERIFY(s.isEmpty()); |
|
79 | QVERIFY(qFuzzyIsNull(s.sum())); | |
|
80 |
Q |
|
|
81 |
Q |
|
|
82 |
Q |
|
|
83 |
Q |
|
|
84 |
Q |
|
|
84 | QCOMPARE(s.sum(), 0.0); | |
|
85 | QCOMPARE(s.horizontalPosition(), 0.5); | |
|
86 | QCOMPARE(s.verticalPosition(), 0.5); | |
|
87 | QCOMPARE(s.pieSize(), 0.7); | |
|
88 | QCOMPARE(s.pieStartAngle(), 0.0); | |
|
89 | QCOMPARE(s.pieEndAngle(), 360.0); | |
|
85 | 90 | } |
|
86 | 91 | |
|
87 | 92 | void tst_qpieseries::append() |
|
88 | 93 | { |
|
89 | 94 | QPieSeries s; |
|
90 | 95 | |
|
91 | 96 | // append pointer |
|
92 | 97 | QPieSlice *slice1 = 0; |
|
93 | 98 | QVERIFY(!s.append(slice1)); |
|
94 | 99 | slice1 = new QPieSlice(1, "slice 1"); |
|
95 | 100 | QVERIFY(s.append(slice1)); |
|
96 | 101 | QVERIFY(!s.append(slice1)); |
|
97 | 102 | QCOMPARE(s.count(), 1); |
|
98 | 103 | |
|
99 | 104 | // append pointer list |
|
100 | 105 | QList<QPieSlice *> list; |
|
101 | 106 | QVERIFY(!s.append(list)); |
|
102 | 107 | list << (QPieSlice *) 0; |
|
103 | 108 | QVERIFY(!s.append(list)); |
|
104 | 109 | list.clear(); |
|
105 | 110 | list << new QPieSlice(2, "slice 2"); |
|
106 | 111 | list << new QPieSlice(3, "slice 3"); |
|
107 | 112 | QVERIFY(s.append(list)); |
|
108 | 113 | QVERIFY(!s.append(list)); |
|
109 | 114 | QCOMPARE(s.count(), 3); |
|
110 | 115 | |
|
111 | 116 | // append operator |
|
112 | 117 | s << new QPieSlice(4, "slice 4"); |
|
113 | 118 | s << slice1; // fails because already added |
|
114 | 119 | QCOMPARE(s.count(), 4); |
|
115 | 120 | |
|
116 | 121 | // append with params |
|
117 | 122 | QPieSlice *slice5 = s.append(5, "slice 5"); |
|
118 | 123 | QVERIFY(slice5 != 0); |
|
119 |
Q |
|
|
124 | QCOMPARE(slice5->value(), 5.0); | |
|
120 | 125 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
121 | 126 | QCOMPARE(s.count(), 5); |
|
122 | 127 | |
|
123 | 128 | // check slices |
|
124 | 129 | QVERIFY(!s.isEmpty()); |
|
125 | 130 | for (int i=0; i<s.count(); i++) { |
|
126 |
Q |
|
|
131 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
|
127 | 132 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
128 | 133 | } |
|
129 | 134 | } |
|
130 | 135 | |
|
131 | 136 | void tst_qpieseries::insert() |
|
132 | 137 | { |
|
133 | 138 | QPieSeries s; |
|
134 | 139 | |
|
135 | 140 | // insert one slice |
|
136 | 141 | QPieSlice *slice1 = 0; |
|
137 | 142 | QVERIFY(!s.insert(0, slice1)); |
|
138 | 143 | slice1 = new QPieSlice(1, "slice 1"); |
|
139 | 144 | QVERIFY(!s.insert(-1, slice1)); |
|
140 | 145 | QVERIFY(!s.insert(5, slice1)); |
|
141 | 146 | QVERIFY(s.insert(0, slice1)); |
|
142 | 147 | QVERIFY(!s.insert(0, slice1)); |
|
143 | 148 | QCOMPARE(s.count(), 1); |
|
144 | 149 | |
|
145 | 150 | // add some more slices |
|
146 | 151 | s.append(2, "slice 2"); |
|
147 | 152 | s.append(4, "slice 4"); |
|
148 | 153 | QCOMPARE(s.count(), 3); |
|
149 | 154 | |
|
150 | 155 | // insert between slices |
|
151 | 156 | s.insert(2, new QPieSlice(3, "slice 3")); |
|
152 | 157 | QCOMPARE(s.count(), 4); |
|
153 | 158 | |
|
154 | 159 | // check slices |
|
155 | 160 | for (int i=0; i<s.count(); i++) { |
|
156 |
Q |
|
|
161 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
|
157 | 162 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
158 | 163 | } |
|
159 | 164 | } |
|
160 | 165 | |
|
161 | 166 | void tst_qpieseries::remove() |
|
162 | 167 | { |
|
163 | 168 | QPieSeries s; |
|
164 | 169 | |
|
165 | 170 | // add some slices |
|
166 | 171 | QPieSlice *slice1 = s.append(1, "slice 1"); |
|
167 | 172 | QPieSlice *slice2 = s.append(2, "slice 2"); |
|
168 | 173 | QPieSlice *slice3 = s.append(3, "slice 3"); |
|
169 | 174 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
170 | 175 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
171 | 176 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
172 | 177 | QCOMPARE(s.count(), 3); |
|
173 | 178 | |
|
174 | 179 | // null pointer remove |
|
175 | 180 | QVERIFY(!s.remove(0)); |
|
176 | 181 | |
|
177 | 182 | // remove first |
|
178 | 183 | QVERIFY(s.remove(slice1)); |
|
179 | 184 | QVERIFY(!s.remove(slice1)); |
|
180 | 185 | QCOMPARE(s.count(), 2); |
|
181 | 186 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); |
|
182 | 187 | |
|
183 | 188 | // remove all |
|
184 | 189 | s.clear(); |
|
185 | 190 | QVERIFY(s.isEmpty()); |
|
186 | 191 | QVERIFY(s.slices().isEmpty()); |
|
187 | 192 | QCOMPARE(s.count(), 0); |
|
188 | 193 | |
|
189 | 194 | // check that slices were actually destroyed |
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
195 | TRY_COMPARE(spy1.count(), 1); | |
|
196 | TRY_COMPARE(spy2.count(), 1); | |
|
197 | TRY_COMPARE(spy3.count(), 1); | |
|
193 | 198 | } |
|
194 | 199 | |
|
195 | /* | |
|
196 | 200 | void tst_qpieseries::calculatedValues() |
|
197 | 201 | { |
|
202 | bool ok; | |
|
203 | QPieSeries s; | |
|
204 | ||
|
205 | // add a slice | |
|
206 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
|
207 | verifyCalculatedData(s, &ok); | |
|
208 | if (!ok) | |
|
209 | return; | |
|
198 | 210 | |
|
211 | // add some more slices | |
|
212 | QList<QPieSlice *> list; | |
|
213 | list << new QPieSlice(2, "slice 2"); | |
|
214 | list << new QPieSlice(3, "slice 3"); | |
|
215 | s.append(list); | |
|
216 | verifyCalculatedData(s, &ok); | |
|
217 | if (!ok) | |
|
218 | return; | |
|
219 | ||
|
220 | // remove a slice | |
|
221 | s.remove(slice1); | |
|
222 | verifyCalculatedData(s, &ok); | |
|
223 | if (!ok) | |
|
224 | return; | |
|
225 | ||
|
226 | // insert a slice | |
|
227 | s.insert(0, new QPieSlice(1, "Slice 4")); | |
|
228 | verifyCalculatedData(s, &ok); | |
|
229 | if (!ok) | |
|
230 | return; | |
|
231 | ||
|
232 | // clear all | |
|
233 | s.clear(); | |
|
234 | verifyCalculatedData(s, &ok); | |
|
199 | 235 | } |
|
200 | 236 | |
|
201 | void tst_qpieseries::themes() | |
|
237 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
|
202 | 238 | { |
|
239 | *ok = false; | |
|
240 | ||
|
241 | qreal sum = 0; | |
|
242 | foreach (const QPieSlice *slice, series.slices()) | |
|
243 | sum += slice->value(); | |
|
244 | QCOMPARE(series.sum(), sum); | |
|
245 | ||
|
246 | qreal startAngle = series.pieStartAngle(); | |
|
247 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
|
248 | foreach (const QPieSlice *slice, series.slices()) { | |
|
249 | qreal ratio = slice->value() / sum; | |
|
250 | qreal sliceSpan = pieAngleSpan * ratio; | |
|
251 | QCOMPARE(slice->startAngle(), startAngle); | |
|
252 | QCOMPARE(slice->endAngle(), startAngle + sliceSpan); | |
|
253 | QCOMPARE(slice->percentage(), ratio); | |
|
254 | startAngle += sliceSpan; | |
|
255 | } | |
|
256 | ||
|
257 | if (!series.isEmpty()) | |
|
258 | QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); | |
|
203 | 259 | |
|
260 | *ok = true; | |
|
204 | 261 | } |
|
205 | 262 | |
|
263 | ||
|
206 | 264 | void tst_qpieseries::clickedSignal() |
|
207 | 265 | { |
|
208 | ||
|
266 | // create a pie series | |
|
267 | QPieSeries *series = new QPieSeries(); | |
|
268 | series->setPieSize(1.0); | |
|
269 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
270 | series->append(2, "slice 2"); | |
|
271 | series->append(3, "slice 3"); | |
|
272 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); | |
|
273 | ||
|
274 | // add series to the chart | |
|
275 | QChartView view(new QChart()); | |
|
276 | view.resize(200, 200); | |
|
277 | view.chart()->addSeries(series); | |
|
278 | view.show(); | |
|
279 | QTest::qWaitForWindowShown(&view); | |
|
280 | ||
|
281 | // simulate clicks | |
|
282 | // pie rectangle: QRectF(60,60 121x121) | |
|
283 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
|
284 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
285 | QCOMPARE(clickSpy1.count(), 1); | |
|
286 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy1.at(0).at(0)), s1); | |
|
209 | 287 | } |
|
210 | 288 | |
|
211 | 289 | void tst_qpieseries::hoverSignal() |
|
212 | 290 | { |
|
213 | ||
|
291 | // create a pie series | |
|
292 | QPieSeries *series = new QPieSeries(); | |
|
293 | series->setPieSize(1.0); | |
|
294 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
295 | series->append(2, "slice 2"); | |
|
296 | series->append(3, "slice 3"); | |
|
297 | ||
|
298 | // add series to the chart | |
|
299 | QChartView view(new QChart()); | |
|
300 | view.resize(200, 200); | |
|
301 | view.chart()->addSeries(series); | |
|
302 | view.show(); | |
|
303 | QTest::qWaitForWindowShown(&view); | |
|
304 | ||
|
305 | // first move to right top corner | |
|
306 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
307 | ||
|
308 | // move inside the slice | |
|
309 | // pie rectangle: QRectF(60,60 121x121) | |
|
310 | QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); | |
|
311 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
|
312 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
313 | QCOMPARE(hoverSpy.count(), 1); | |
|
314 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |
|
315 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |
|
316 | ||
|
317 | // move outside the slice | |
|
318 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
319 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
320 | QCOMPARE(hoverSpy.count(), 2); | |
|
321 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |
|
322 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |
|
214 | 323 | } |
|
215 | */ | |
|
216 | 324 | |
|
217 | 325 | QTEST_MAIN(tst_qpieseries) |
|
218 | 326 | |
|
219 | 327 | #include "tst_qpieseries.moc" |
|
220 | 328 |
@@ -1,131 +1,270 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | #include <tst_definitions.h> | |
|
23 | #include <qchartview.h> | |
|
24 | #include <qchart.h> | |
|
22 | 25 | #include <qpieslice.h> |
|
26 | #include <qpieseries.h> | |
|
23 | 27 | |
|
24 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
25 | 29 | |
|
26 | 30 | class tst_qpieslice : public QObject |
|
27 | 31 | { |
|
28 | 32 | Q_OBJECT |
|
29 | 33 | |
|
30 | 34 | public slots: |
|
31 | 35 | void initTestCase(); |
|
32 | 36 | void cleanupTestCase(); |
|
33 | 37 | void init(); |
|
34 | 38 | void cleanup(); |
|
35 | 39 | |
|
36 | 40 | private slots: |
|
37 | 41 | void construction(); |
|
38 | 42 | void changedSignals(); |
|
43 | void customize(); | |
|
44 | void mouseClick(); | |
|
45 | void mouseHover(); | |
|
39 | 46 | |
|
40 | 47 | private: |
|
41 | 48 | |
|
42 | 49 | |
|
43 | 50 | private: |
|
44 | 51 | |
|
45 | 52 | }; |
|
46 | 53 | |
|
47 | 54 | void tst_qpieslice::initTestCase() |
|
48 | 55 | { |
|
49 | 56 | } |
|
50 | 57 | |
|
51 | 58 | void tst_qpieslice::cleanupTestCase() |
|
52 | 59 | { |
|
53 | 60 | } |
|
54 | 61 | |
|
55 | 62 | void tst_qpieslice::init() |
|
56 | 63 | { |
|
57 | 64 | |
|
58 | 65 | } |
|
59 | 66 | |
|
60 | 67 | void tst_qpieslice::cleanup() |
|
61 | 68 | { |
|
62 | 69 | |
|
63 | 70 | } |
|
64 | 71 | |
|
65 | 72 | void tst_qpieslice::construction() |
|
66 | 73 | { |
|
67 | 74 | // no params |
|
68 | 75 | QPieSlice slice1; |
|
69 |
Q |
|
|
76 | QCOMPARE(slice1.value(), 0.0); | |
|
70 | 77 | QVERIFY(slice1.label().isEmpty()); |
|
71 | 78 | QVERIFY(!slice1.isLabelVisible()); |
|
72 | 79 | QVERIFY(!slice1.isExploded()); |
|
73 | 80 | QCOMPARE(slice1.pen(), QPen()); |
|
74 | 81 | QCOMPARE(slice1.brush(), QBrush()); |
|
75 | 82 | QCOMPARE(slice1.labelPen(), QPen()); |
|
76 | 83 | QCOMPARE(slice1.labelFont(), QFont()); |
|
77 |
Q |
|
|
78 |
Q |
|
|
79 |
Q |
|
|
80 |
Q |
|
|
81 |
Q |
|
|
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value | |
|
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value | |
|
86 | QCOMPARE(slice1.percentage(), 0.0); | |
|
87 | QCOMPARE(slice1.startAngle(), 0.0); | |
|
88 | QCOMPARE(slice1.endAngle(), 0.0); | |
|
82 | 89 | |
|
83 | 90 | // value and label params |
|
84 | 91 | QPieSlice slice2(1.0, "foobar"); |
|
85 |
Q |
|
|
92 | QCOMPARE(slice2.value(), 1.0); | |
|
86 | 93 | QCOMPARE(slice2.label(), QString("foobar")); |
|
87 | 94 | QVERIFY(!slice2.isLabelVisible()); |
|
88 | 95 | QVERIFY(!slice2.isExploded()); |
|
89 | 96 | QCOMPARE(slice2.pen(), QPen()); |
|
90 | 97 | QCOMPARE(slice2.brush(), QBrush()); |
|
91 | 98 | QCOMPARE(slice2.labelPen(), QPen()); |
|
92 | 99 | QCOMPARE(slice2.labelFont(), QFont()); |
|
93 |
Q |
|
|
94 |
Q |
|
|
95 |
Q |
|
|
96 |
Q |
|
|
97 |
Q |
|
|
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value | |
|
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value | |
|
102 | QCOMPARE(slice2.percentage(), 0.0); | |
|
103 | QCOMPARE(slice2.startAngle(), 0.0); | |
|
104 | QCOMPARE(slice2.endAngle(), 0.0); | |
|
98 | 105 | } |
|
99 | 106 | |
|
100 | 107 | void tst_qpieslice::changedSignals() |
|
101 | 108 | { |
|
102 | 109 | // set everything twice to see we do not get unnecessary signals |
|
103 | 110 | QPieSlice slice; |
|
104 | 111 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined |
|
105 | 112 | slice.setValue(1); |
|
106 | 113 | slice.setValue(1); |
|
107 | 114 | slice.setLabel("foobar"); |
|
108 | 115 | slice.setLabel("foobar"); |
|
109 | 116 | slice.setLabelVisible(); |
|
110 | 117 | slice.setLabelVisible(); |
|
111 | 118 | slice.setExploded(); |
|
112 | 119 | slice.setExploded(); |
|
113 | 120 | slice.setPen(QPen(Qt::red)); |
|
114 | 121 | slice.setPen(QPen(Qt::red)); |
|
115 | 122 | slice.setBrush(QBrush(Qt::red)); |
|
116 | 123 | slice.setBrush(QBrush(Qt::red)); |
|
117 | 124 | slice.setLabelPen(QPen(Qt::green)); |
|
118 | 125 | slice.setLabelPen(QPen(Qt::green)); |
|
119 | 126 | slice.setLabelFont(QFont("Tahoma")); |
|
120 | 127 | slice.setLabelFont(QFont("Tahoma")); |
|
121 | 128 | slice.setLabelArmLengthFactor(0.1); |
|
122 | 129 | slice.setLabelArmLengthFactor(0.1); |
|
123 | 130 | slice.setExplodeDistanceFactor(0.1); |
|
124 | 131 | slice.setExplodeDistanceFactor(0.1); |
|
125 |
|
|
|
132 | TRY_COMPARE(spy.count(), 10); | |
|
133 | } | |
|
134 | ||
|
135 | void tst_qpieslice::customize() | |
|
136 | { | |
|
137 | // create a pie series | |
|
138 | QPieSeries *series = new QPieSeries(); | |
|
139 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
140 | QPieSlice *s2 = series->append(2, "slice 2"); | |
|
141 | series->append(3, "slice 3"); | |
|
142 | ||
|
143 | // customize a slice | |
|
144 | QPen p1(Qt::red); | |
|
145 | s1->setPen(p1); | |
|
146 | QBrush b1(Qt::red); | |
|
147 | s1->setBrush(b1); | |
|
148 | s1->setLabelPen(p1); | |
|
149 | QFont f1("Consolas"); | |
|
150 | s1->setLabelFont(f1); | |
|
151 | ||
|
152 | // add series to the chart | |
|
153 | QChartView view(new QChart()); | |
|
154 | view.resize(200, 200); | |
|
155 | view.chart()->addSeries(series); | |
|
156 | view.show(); | |
|
157 | QTest::qWaitForWindowShown(&view); | |
|
158 | //QTest::qWait(1000); | |
|
159 | ||
|
160 | // check that customizations persist | |
|
161 | QCOMPARE(s1->pen(), p1); | |
|
162 | QCOMPARE(s1->brush(), b1); | |
|
163 | QCOMPARE(s1->labelPen(), p1); | |
|
164 | QCOMPARE(s1->labelFont(), f1); | |
|
165 | ||
|
166 | // remove a slice | |
|
167 | series->remove(s2); | |
|
168 | QCOMPARE(s1->pen(), p1); | |
|
169 | QCOMPARE(s1->brush(), b1); | |
|
170 | QCOMPARE(s1->labelPen(), p1); | |
|
171 | QCOMPARE(s1->labelFont(), f1); | |
|
172 | ||
|
173 | // add a slice | |
|
174 | series->append(4, "slice 4"); | |
|
175 | QCOMPARE(s1->pen(), p1); | |
|
176 | QCOMPARE(s1->brush(), b1); | |
|
177 | QCOMPARE(s1->labelPen(), p1); | |
|
178 | QCOMPARE(s1->labelFont(), f1); | |
|
179 | ||
|
180 | // insert a slice | |
|
181 | series->insert(0, new QPieSlice(5, "slice 5")); | |
|
182 | QCOMPARE(s1->pen(), p1); | |
|
183 | QCOMPARE(s1->brush(), b1); | |
|
184 | QCOMPARE(s1->labelPen(), p1); | |
|
185 | QCOMPARE(s1->labelFont(), f1); | |
|
186 | ||
|
187 | // change theme | |
|
188 | // theme will overwrite customizations | |
|
189 | view.chart()->setTheme(QChart::ChartThemeHighContrast); | |
|
190 | QVERIFY(s1->pen() != p1); | |
|
191 | QVERIFY(s1->brush() != b1); | |
|
192 | QVERIFY(s1->labelPen() != p1); | |
|
193 | QVERIFY(s1->labelFont() != f1); | |
|
194 | } | |
|
195 | ||
|
196 | void tst_qpieslice::mouseClick() | |
|
197 | { | |
|
198 | // create a pie series | |
|
199 | QPieSeries *series = new QPieSeries(); | |
|
200 | series->setPieSize(1.0); | |
|
201 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
202 | QPieSlice *s2 = series->append(2, "slice 2"); | |
|
203 | QPieSlice *s3 = series->append(3, "slice 3"); | |
|
204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); | |
|
205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); | |
|
206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); | |
|
207 | ||
|
208 | // add series to the chart | |
|
209 | QChartView view(new QChart()); | |
|
210 | view.resize(200, 200); | |
|
211 | view.chart()->addSeries(series); | |
|
212 | view.show(); | |
|
213 | QTest::qWaitForWindowShown(&view); | |
|
214 | ||
|
215 | // simulate clicks | |
|
216 | // pie rectangle: QRectF(60,60 121x121) | |
|
217 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
|
218 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 | |
|
219 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 | |
|
220 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice | |
|
221 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice | |
|
222 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
223 | QCOMPARE(clickSpy1.count(), 1); | |
|
224 | QCOMPARE(clickSpy2.count(), 1); | |
|
225 | QCOMPARE(clickSpy3.count(), 1); | |
|
226 | } | |
|
227 | ||
|
228 | void tst_qpieslice::mouseHover() | |
|
229 | { | |
|
230 | // create a pie series | |
|
231 | QPieSeries *series = new QPieSeries(); | |
|
232 | series->setPieSize(1.0); | |
|
233 | QPieSlice *s1 = series->append(1, "slice 1"); | |
|
234 | series->append(2, "slice 2"); | |
|
235 | series->append(3, "slice 3"); | |
|
236 | ||
|
237 | // add series to the chart | |
|
238 | QChartView view(new QChart()); | |
|
239 | view.resize(200, 200); | |
|
240 | view.chart()->addSeries(series); | |
|
241 | view.show(); | |
|
242 | QTest::qWaitForWindowShown(&view); | |
|
243 | ||
|
244 | // first move to right top corner | |
|
245 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
246 | ||
|
247 | // move inside slice rectangle but NOT the actual slice | |
|
248 | // pie rectangle: QRectF(60,60 121x121) | |
|
249 | QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); | |
|
250 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); | |
|
251 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
252 | QCOMPARE(hoverSpy.count(), 0); | |
|
253 | ||
|
254 | // move inside the slice | |
|
255 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
|
256 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
257 | QCOMPARE(hoverSpy.count(), 1); | |
|
258 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); | |
|
259 | ||
|
260 | // move outside the slice | |
|
261 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
262 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
263 | QCOMPARE(hoverSpy.count(), 2); | |
|
264 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); | |
|
126 | 265 | } |
|
127 | 266 | |
|
128 | 267 | QTEST_MAIN(tst_qpieslice) |
|
129 | 268 | |
|
130 | 269 | #include "tst_qpieslice.moc" |
|
131 | 270 |
@@ -1,345 +1,349 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | #include "dataseriedialog.h" |
|
23 | 23 | #include "qchartview.h" |
|
24 | 24 | #include "qpieseries.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "qlineseries.h" |
|
27 | 27 | #include <qareaseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qbarset.h> |
|
30 | 30 | #include <qbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qpercentbarseries.h> |
|
33 | 33 | #include <QPushButton> |
|
34 | 34 | #include <QComboBox> |
|
35 | 35 | #include <QSpinBox> |
|
36 | 36 | #include <QCheckBox> |
|
37 | 37 | #include <QGridLayout> |
|
38 | 38 | #include <QHBoxLayout> |
|
39 | 39 | #include <QLabel> |
|
40 | 40 | #include <QSpacerItem> |
|
41 | 41 | #include <QMessageBox> |
|
42 | 42 | #include <cmath> |
|
43 | 43 | #include <QDebug> |
|
44 | 44 | #include <QStandardItemModel> |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | 48 | |
|
49 | 49 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | 50 | QWidget(parent), |
|
51 | 51 | m_addSerieDialog(0), |
|
52 | 52 | m_chart(0) |
|
53 | 53 | { |
|
54 | 54 | m_chart = new QChart(); |
|
55 | 55 | |
|
56 | 56 | // Grid layout for the controls for configuring the chart widget |
|
57 | 57 | QGridLayout *grid = new QGridLayout(); |
|
58 | 58 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | 59 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | 60 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | 61 | initBackroundCombo(grid); |
|
62 | 62 | initScaleControls(grid); |
|
63 | 63 | initThemeCombo(grid); |
|
64 | 64 | initCheckboxes(grid); |
|
65 | 65 | |
|
66 | 66 | // add row with empty label to make all the other rows static |
|
67 | 67 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | 68 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | 69 | |
|
70 | 70 | // Create chart view with the chart |
|
71 | 71 | m_chartView = new QChartView(m_chart, this); |
|
72 | 72 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | 73 | |
|
74 | 74 | // Another grid layout as a main layout |
|
75 | 75 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | 76 | mainLayout->addLayout(grid, 0, 0); |
|
77 | 77 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | 78 | setLayout(mainLayout); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | // Combo box for selecting the chart's background |
|
82 | 82 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | 83 | { |
|
84 | 84 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | 85 | backgroundCombo->addItem("Color"); |
|
86 | 86 | backgroundCombo->addItem("Gradient"); |
|
87 | 87 | backgroundCombo->addItem("Image"); |
|
88 | 88 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | 89 | this, SLOT(backgroundChanged(int))); |
|
90 | 90 | |
|
91 | 91 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | 92 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | 96 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | 97 | { |
|
98 | 98 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | 99 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | 100 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | 101 | m_xMinSpin = new QSpinBox(); |
|
102 | 102 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | 103 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | 104 | m_xMinSpin->setValue(0); |
|
105 | 105 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | 106 | m_xMaxSpin = new QSpinBox(); |
|
107 | 107 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | 108 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | 109 | m_xMaxSpin->setValue(10); |
|
110 | 110 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | 111 | m_yMinSpin = new QSpinBox(); |
|
112 | 112 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | 113 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | 114 | m_yMinSpin->setValue(0); |
|
115 | 115 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | 116 | m_yMaxSpin = new QSpinBox(); |
|
117 | 117 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | 118 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | 119 | m_yMaxSpin->setValue(10); |
|
120 | 120 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | 121 | |
|
122 | 122 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | 123 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | 124 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | 125 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | 126 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | 127 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | 128 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | 129 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | 130 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | 131 | |
|
132 | 132 | m_autoScaleCheck->setChecked(true); |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | // Combo box for selecting theme |
|
136 | 136 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | 137 | { |
|
138 | 138 | QComboBox *chartTheme = new QComboBox(); |
|
139 | 139 | chartTheme->addItem("Default"); |
|
140 | 140 | chartTheme->addItem("Light"); |
|
141 | 141 | chartTheme->addItem("Blue Cerulean"); |
|
142 | 142 | chartTheme->addItem("Dark"); |
|
143 | 143 | chartTheme->addItem("Brown Sand"); |
|
144 | 144 | chartTheme->addItem("Blue NCS"); |
|
145 | 145 | chartTheme->addItem("High Contrast"); |
|
146 | 146 | chartTheme->addItem("Blue Icy"); |
|
147 | 147 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | 148 | this, SLOT(changeChartTheme(int))); |
|
149 | 149 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | 150 | grid->addWidget(chartTheme, 8, 1); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | // Different check boxes for customizing chart |
|
154 | 154 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | 155 | { |
|
156 | 156 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | 157 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | 158 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | 159 | zoomCheckBox->setChecked(true); |
|
160 | 160 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | 161 | |
|
162 | 162 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | 163 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | 164 | aliasCheckBox->setChecked(false); |
|
165 | 165 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void MainWidget::antiAliasToggled(bool enabled) |
|
169 | 169 | { |
|
170 | 170 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void MainWidget::addSeries() |
|
174 | 174 | { |
|
175 | 175 | if (!m_addSerieDialog) { |
|
176 | 176 | m_addSerieDialog = new DataSerieDialog(this); |
|
177 | 177 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
178 | 178 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
179 | 179 | } |
|
180 | 180 | m_addSerieDialog->exec(); |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
184 | 184 | { |
|
185 | 185 | // TODO: dataCharacteristics |
|
186 | 186 | QList<RealList> testData; |
|
187 | 187 | for (int j(0); j < columnCount; j++) { |
|
188 | 188 | QList <qreal> newColumn; |
|
189 | 189 | for (int i(0); i < rowCount; i++) { |
|
190 | 190 | if (dataCharacteristics == "Sin") { |
|
191 | 191 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
192 | 192 | } else if (dataCharacteristics == "Sin + random") { |
|
193 | 193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
194 | 194 | } else if (dataCharacteristics == "Random") { |
|
195 | 195 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
196 | 196 | } else if (dataCharacteristics == "Linear") { |
|
197 | 197 | //newColumn.append(i * (j + 1.0)); |
|
198 | 198 | // TODO: temporary hack to make pie work; prevent zero values: |
|
199 | 199 | newColumn.append(i * (j + 1.0) + 0.1); |
|
200 | 200 | } else { // "constant" |
|
201 | 201 | newColumn.append((j + 1.0)); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | testData.append(newColumn); |
|
205 | 205 | } |
|
206 | 206 | return testData; |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | QStringList MainWidget::generateLabels(int count) |
|
210 | 210 | { |
|
211 | 211 | QStringList result; |
|
212 | 212 | for (int i(0); i < count; i++) |
|
213 | 213 | result.append("label" + QString::number(i)); |
|
214 | 214 | return result; |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
218 | 218 | { |
|
219 | 219 | qDebug() << "addSeries: " << seriesName |
|
220 | 220 | << " columnCount: " << columnCount |
|
221 | 221 | << " rowCount: " << rowCount |
|
222 | 222 | << " dataCharacteristics: " << dataCharacteristics |
|
223 | 223 | << " labels enabled: " << labelsEnabled; |
|
224 | 224 | m_defaultSeriesName = seriesName; |
|
225 | 225 | |
|
226 | 226 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
227 | 227 | |
|
228 | 228 | // Line series and scatter series use similar data |
|
229 | 229 | if (seriesName == "Line") { |
|
230 | 230 | for (int j(0); j < data.count(); j ++) { |
|
231 | 231 | QList<qreal> column = data.at(j); |
|
232 | 232 | QLineSeries *series = new QLineSeries(); |
|
233 | 233 | series->setName("line" + QString::number(j)); |
|
234 | 234 | for (int i(0); i < column.count(); i++) |
|
235 | 235 | series->append(i, column.at(i)); |
|
236 | 236 | m_chart->addSeries(series); |
|
237 | 237 | } |
|
238 | 238 | } else if (seriesName == "Area") { |
|
239 | 239 | // TODO: lower series for the area? |
|
240 | 240 | for (int j(0); j < data.count(); j ++) { |
|
241 | 241 | QList<qreal> column = data.at(j); |
|
242 | 242 | QLineSeries *lineSeries = new QLineSeries(); |
|
243 | 243 | for (int i(0); i < column.count(); i++) |
|
244 | 244 | lineSeries->append(i, column.at(i)); |
|
245 | 245 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
246 | 246 | areaSeries->setName("area" + QString::number(j)); |
|
247 | 247 | m_chart->addSeries(areaSeries); |
|
248 | 248 | } |
|
249 | 249 | } else if (seriesName == "Scatter") { |
|
250 | 250 | for (int j(0); j < data.count(); j++) { |
|
251 | 251 | QList<qreal> column = data.at(j); |
|
252 | 252 | QScatterSeries *series = new QScatterSeries(); |
|
253 | 253 | series->setName("scatter" + QString::number(j)); |
|
254 | 254 | for (int i(0); i < column.count(); i++) |
|
255 | 255 | series->append(i, column.at(i)); |
|
256 | 256 | m_chart->addSeries(series); |
|
257 | 257 | } |
|
258 | 258 | } else if (seriesName == "Pie") { |
|
259 | 259 | QStringList labels = generateLabels(rowCount); |
|
260 | 260 | for (int j(0); j < data.count(); j++) { |
|
261 | 261 | QPieSeries *series = new QPieSeries(); |
|
262 | 262 | QList<qreal> column = data.at(j); |
|
263 | 263 | for (int i(0); i < column.count(); i++) |
|
264 | 264 | series->append(column.at(i), labels.at(i)); |
|
265 | 265 | m_chart->addSeries(series); |
|
266 | 266 | } |
|
267 | 267 | } else if (seriesName == "Bar" |
|
268 | 268 | || seriesName == "Stacked bar" |
|
269 | 269 | || seriesName == "Percent bar") { |
|
270 | 270 | QStringList category; |
|
271 | 271 | QStringList labels = generateLabels(rowCount); |
|
272 | 272 | foreach(QString label, labels) |
|
273 | 273 | category << label; |
|
274 | 274 | QBarSeries* series = 0; |
|
275 | if (seriesName == "Bar") | |
|
276 |
series = new QBarSeries( |
|
|
277 | else if (seriesName == "Stacked bar") | |
|
278 | series = new QStackedBarSeries(category, this); | |
|
279 | else | |
|
280 |
series |
|
|
275 | if (seriesName == "Bar") { | |
|
276 | series = new QBarSeries(this); | |
|
277 | series->setCategories(category); | |
|
278 | } else if (seriesName == "Stacked bar") { | |
|
279 | series = new QStackedBarSeries(this); | |
|
280 | series->setCategories(category); | |
|
281 | } else { | |
|
282 | series = new QPercentBarSeries(this); | |
|
283 | series->setCategories(category); | |
|
284 | } | |
|
281 | 285 | |
|
282 | 286 | for (int j(0); j < data.count(); j++) { |
|
283 | 287 | QList<qreal> column = data.at(j); |
|
284 | 288 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
285 | 289 | for (int i(0); i < column.count(); i++) |
|
286 | 290 | *set << column.at(i); |
|
287 | 291 | series->appendBarSet(set); |
|
288 | 292 | } |
|
289 | 293 | |
|
290 | 294 | m_chart->addSeries(series); |
|
291 | 295 | } else if (seriesName == "Spline") { |
|
292 | 296 | for (int j(0); j < data.count(); j ++) { |
|
293 | 297 | QList<qreal> column = data.at(j); |
|
294 | 298 | QSplineSeries *series = new QSplineSeries(); |
|
295 | 299 | for (int i(0); i < column.count(); i++) |
|
296 | 300 | series->append(i, column.at(i)); |
|
297 | 301 | m_chart->addSeries(series); |
|
298 | 302 | } |
|
299 | 303 | } |
|
300 | 304 | } |
|
301 | 305 | |
|
302 | 306 | void MainWidget::backgroundChanged(int itemIndex) |
|
303 | 307 | { |
|
304 | 308 | qDebug() << "backgroundChanged: " << itemIndex; |
|
305 | 309 | } |
|
306 | 310 | |
|
307 | 311 | void MainWidget::autoScaleChanged(int value) |
|
308 | 312 | { |
|
309 | 313 | if (value) { |
|
310 | 314 | // TODO: enable auto scaling |
|
311 | 315 | } else { |
|
312 | 316 | // TODO: set scaling manually (and disable auto scaling) |
|
313 | 317 | } |
|
314 | 318 | |
|
315 | 319 | m_xMinSpin->setEnabled(!value); |
|
316 | 320 | m_xMaxSpin->setEnabled(!value); |
|
317 | 321 | m_yMinSpin->setEnabled(!value); |
|
318 | 322 | m_yMaxSpin->setEnabled(!value); |
|
319 | 323 | } |
|
320 | 324 | |
|
321 | 325 | void MainWidget::xMinChanged(int value) |
|
322 | 326 | { |
|
323 | 327 | qDebug() << "xMinChanged: " << value; |
|
324 | 328 | } |
|
325 | 329 | |
|
326 | 330 | void MainWidget::xMaxChanged(int value) |
|
327 | 331 | { |
|
328 | 332 | qDebug() << "xMaxChanged: " << value; |
|
329 | 333 | } |
|
330 | 334 | |
|
331 | 335 | void MainWidget::yMinChanged(int value) |
|
332 | 336 | { |
|
333 | 337 | qDebug() << "yMinChanged: " << value; |
|
334 | 338 | } |
|
335 | 339 | |
|
336 | 340 | void MainWidget::yMaxChanged(int value) |
|
337 | 341 | { |
|
338 | 342 | qDebug() << "yMaxChanged: " << value; |
|
339 | 343 | } |
|
340 | 344 | |
|
341 | 345 | void MainWidget::changeChartTheme(int themeIndex) |
|
342 | 346 | { |
|
343 | 347 | qDebug() << "changeChartTheme: " << themeIndex; |
|
344 | 348 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
345 | 349 | } |
@@ -1,244 +1,245 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "widget.h" |
|
22 | 22 | |
|
23 | 23 | #include <QChart> |
|
24 | 24 | #include <QScatterSeries> |
|
25 | 25 | #include <QAxis> |
|
26 | 26 | #include <QBarSet> |
|
27 | 27 | #include <QBarSeries> |
|
28 | 28 | #include <QLegend> |
|
29 | 29 | |
|
30 | 30 | #include <QGridLayout> |
|
31 | 31 | #include <QPushButton> |
|
32 | 32 | #include <QLabel> |
|
33 | 33 | #include <QListWidget> |
|
34 | 34 | #include <QPrinter> |
|
35 | 35 | #include <QPrintDialog> |
|
36 | 36 | #include <QRadioButton> |
|
37 | 37 | #include <QStringList> |
|
38 | 38 | #include <QSqlQuery> |
|
39 | 39 | #include <QDebug> |
|
40 | 40 | |
|
41 | 41 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
42 | 42 | |
|
43 | 43 | Widget::Widget(QWidget *parent) |
|
44 | 44 | : QWidget(parent) |
|
45 | 45 | { |
|
46 | 46 | setGeometry(100, 100, 1000, 600); |
|
47 | 47 | |
|
48 | 48 | // right panel layout |
|
49 | 49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); |
|
50 | 50 | barChartRadioButton->setChecked(true); |
|
51 | 51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); |
|
52 | 52 | scatterChartRadioButton->setChecked(false); |
|
53 | 53 | countrieslist = new QListWidget; |
|
54 | 54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
55 | 55 | |
|
56 | 56 | //list of years widget |
|
57 | 57 | yearslist = new QListWidget; |
|
58 | 58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
59 | 59 | for (int i = 1990; i < 2011; i++) |
|
60 | 60 | yearslist->addItem(QString("%1").arg(i)); |
|
61 | 61 | |
|
62 | 62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
63 | 63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
64 | 64 | |
|
65 | 65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); |
|
66 | 66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); |
|
67 | 67 | |
|
68 | 68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
69 | 69 | rightPanelLayout->addWidget(barChartRadioButton); |
|
70 | 70 | rightPanelLayout->addWidget(scatterChartRadioButton); |
|
71 | 71 | rightPanelLayout->addWidget(countrieslist); |
|
72 | 72 | rightPanelLayout->addWidget(yearslist); |
|
73 | 73 | rightPanelLayout->addWidget(refreshButton); |
|
74 | 74 | rightPanelLayout->addWidget(printButton); |
|
75 | 75 | rightPanelLayout->setStretch(0, 1); |
|
76 | 76 | rightPanelLayout->setStretch(1, 0); |
|
77 | 77 | |
|
78 | 78 | QChart *chart = new QChart(); |
|
79 | 79 | chart->setTitle("GDP by country"); |
|
80 | 80 | chart->legend()->setVisible(true); |
|
81 | 81 | |
|
82 | 82 | // main layout |
|
83 | 83 | chartView = new QChartView(chart); |
|
84 | 84 | QGridLayout* mainLayout = new QGridLayout; |
|
85 | 85 | mainLayout->addWidget(chartView, 0, 0); |
|
86 | 86 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
87 | 87 | mainLayout->setColumnStretch(0,1); |
|
88 | 88 | setLayout(mainLayout); |
|
89 | 89 | |
|
90 | 90 | // connect to the database |
|
91 | 91 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
92 | 92 | db.setDatabaseName("gdpData"); |
|
93 | 93 | if(!db.open()) |
|
94 | 94 | { |
|
95 | 95 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
96 | 96 | return; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | // get the list of all countires and regions. |
|
100 | 100 | QSqlQuery query; |
|
101 | 101 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
102 | 102 | |
|
103 | 103 | // add the countries to the country filter |
|
104 | 104 | while (query.next()) { |
|
105 | 105 | countrieslist->addItem(query.value(0).toString()); |
|
106 | 106 | } |
|
107 | 107 | } |
|
108 | 108 | |
|
109 | 109 | Widget::~Widget() |
|
110 | 110 | { |
|
111 | 111 | // |
|
112 | 112 | db.close(); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | /*! |
|
116 | 116 | refreshes the chart |
|
117 | 117 | */ |
|
118 | 118 | void Widget::refreshChart() |
|
119 | 119 | { |
|
120 | 120 | chartView->chart()->removeAllSeries(); |
|
121 | 121 | |
|
122 | 122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
123 | 123 | QStringList selectedCountriesStrings; |
|
124 | 124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
125 | 125 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
126 | 126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
127 | 127 | selectedCountriesStrings.sort(); |
|
128 | 128 | |
|
129 | 129 | QSqlQuery query; |
|
130 | 130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. |
|
131 | 131 | QList<int> selectedYearsInts; |
|
132 | 132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
133 | 133 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
134 | 134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
135 | 135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); |
|
136 | 136 | |
|
137 | 137 | if (barChartRadioButton->isChecked()) |
|
138 | 138 | { |
|
139 | 139 | // use the sorted selected coutries list to initialize BarCategory |
|
140 | 140 | QStringList category; |
|
141 | 141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
142 | 142 | category << selectedCountriesStrings[i]; |
|
143 |
QBarSeries* series0 = new QBarSeries( |
|
|
144 |
series0 |
|
|
143 | QBarSeries* series0 = new QBarSeries(); | |
|
144 | series0->setCategories(category); | |
|
145 | // series0 = new QBarSeries(category); | |
|
145 | 146 | |
|
146 | 147 | // prepare the selected counries SQL query |
|
147 | 148 | QString countriesQuery = "country IN ("; |
|
148 | 149 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
149 | 150 | { |
|
150 | 151 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
151 | 152 | if ( i < selectedCountriesStrings.size() - 1) |
|
152 | 153 | countriesQuery.append(","); |
|
153 | 154 | else |
|
154 | 155 | countriesQuery.append(")"); |
|
155 | 156 | } |
|
156 | 157 | |
|
157 | 158 | // perform a query for each selected year |
|
158 | 159 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
159 | 160 | { |
|
160 | 161 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
161 | 162 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); |
|
162 | 163 | |
|
163 | 164 | // while (query.next()) { |
|
164 | 165 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
165 | 166 | // } |
|
166 | 167 | query.first(); |
|
167 | 168 | |
|
168 | 169 | // the data for some of the coutries for some years might be missing. |
|
169 | 170 | // QBarChart needs bars to have same size |
|
170 | 171 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
171 | 172 | { |
|
172 | 173 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
173 | 174 | { |
|
174 | 175 | *barSet << query.value(1).toReal(); |
|
175 | 176 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
176 | 177 | query.next(); |
|
177 | 178 | } |
|
178 | 179 | else |
|
179 | 180 | { |
|
180 | 181 | // data missing, put 0 |
|
181 | 182 | *barSet << 0.0f; |
|
182 | 183 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
183 | 184 | } |
|
184 | 185 | } |
|
185 | 186 | series0->appendBarSet(barSet); |
|
186 | 187 | } |
|
187 | 188 | // add the serie to the chart |
|
188 | 189 | chartView->chart()->addSeries(series0); |
|
189 | 190 | } |
|
190 | 191 | else if (scatterChartRadioButton->isChecked()) |
|
191 | 192 | { |
|
192 | 193 | QString yearsQuery = "year IN ("; |
|
193 | 194 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
194 | 195 | { |
|
195 | 196 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); |
|
196 | 197 | if ( i < selectedYearsInts.size() - 1) |
|
197 | 198 | yearsQuery.append(","); |
|
198 | 199 | else |
|
199 | 200 | yearsQuery.append(")"); |
|
200 | 201 | } |
|
201 | 202 | |
|
202 | 203 | // perform a query for each selected country |
|
203 | 204 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
204 | 205 | { |
|
205 | 206 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); |
|
206 | 207 | query.first(); |
|
207 | 208 | |
|
208 | 209 | QScatterSeries* series = new QScatterSeries; |
|
209 | 210 | series->setName(selectedCountriesStrings[i]); |
|
210 | 211 | // the data for some of the coutries for some years might be missing. |
|
211 | 212 | for (int k = 0; k < selectedYearsInts.size(); k++) |
|
212 | 213 | { |
|
213 | 214 | if (selectedYearsInts[k] == query.value(0).toInt()) |
|
214 | 215 | { |
|
215 | 216 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); |
|
216 | 217 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); |
|
217 | 218 | query.next(); |
|
218 | 219 | } |
|
219 | 220 | else |
|
220 | 221 | { |
|
221 | 222 | // data missing, put 0 |
|
222 | 223 | *series << QPointF(selectedYearsInts[k] , 0.0f); |
|
223 | 224 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); |
|
224 | 225 | } |
|
225 | 226 | } |
|
226 | 227 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); |
|
227 | 228 | chartView->chart()->addSeries(series); |
|
228 | 229 | } |
|
229 | 230 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); |
|
230 | 231 | } |
|
231 | 232 | } |
|
232 | 233 | |
|
233 | 234 | void Widget::printChart() |
|
234 | 235 | { |
|
235 | 236 | QPrinter printer; |
|
236 | 237 | // QPrinter printer(QPrinter::HighResolution); |
|
237 | 238 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
238 | 239 | printer.setOrientation(QPrinter::Landscape); |
|
239 | 240 | printer.setOutputFileName("print.pdf"); |
|
240 | 241 | |
|
241 | 242 | QPainter painter; |
|
242 | 243 | painter.begin(&printer); |
|
243 | 244 | chartView->render(&painter); |
|
244 | 245 | } |
@@ -1,411 +1,412 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include <QGridLayout> |
|
23 | 23 | #include <QTableView> |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QStyledItemDelegate> |
|
26 | 26 | #include <QLineSeries> |
|
27 | 27 | #include <QSplineSeries> |
|
28 | 28 | #include <QScatterSeries> |
|
29 | 29 | #include "customtablemodel.h" |
|
30 | 30 | #include <QPieSeries> |
|
31 | 31 | #include <QPieSlice> |
|
32 | 32 | #include <QAreaSeries> |
|
33 | 33 | #include <QBarSeries> |
|
34 | 34 | #include <QBarSet> |
|
35 | 35 | #include <QPushButton> |
|
36 | 36 | #include <QRadioButton> |
|
37 | 37 | #include <QLabel> |
|
38 | 38 | #include <QSpinBox> |
|
39 | 39 | #include <QTime> |
|
40 | 40 | #include <QHeaderView> |
|
41 | 41 | |
|
42 | 42 | TableWidget::TableWidget(QWidget *parent) |
|
43 | 43 | : QWidget(parent) |
|
44 | 44 | // specialPie(0) |
|
45 | 45 | { |
|
46 | 46 | setGeometry(1900, 100, 1000, 600); |
|
47 | 47 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
48 | 48 | // create simple model for storing data |
|
49 | 49 | // user's table data model |
|
50 | 50 | m_model = new CustomTableModel; |
|
51 | 51 | m_tableView = new QTableView; |
|
52 | 52 | m_tableView->setModel(m_model); |
|
53 | 53 | // m_tableView->setMinimumHeight(300); |
|
54 | 54 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
55 | 55 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
56 | 56 | |
|
57 | 57 | m_chart = new QChart; |
|
58 | 58 | m_chart->legend()->setVisible(true); |
|
59 | 59 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
60 | 60 | m_chartView = new QChartView(m_chart); |
|
61 | 61 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
62 | 62 | m_chartView->setMinimumSize(640, 480); |
|
63 | 63 | |
|
64 | 64 | // add, remove data buttons |
|
65 | 65 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
66 | 66 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
67 | 67 | |
|
68 | 68 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
69 | 69 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
70 | 70 | |
|
71 | 71 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
72 | 72 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
73 | 73 | |
|
74 | 74 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
75 | 75 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
76 | 76 | |
|
77 | 77 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
78 | 78 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
79 | 79 | |
|
80 | 80 | QPushButton* specialPieButton = new QPushButton("Test pie"); |
|
81 | 81 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
82 | 82 | |
|
83 | 83 | |
|
84 | 84 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
85 | 85 | |
|
86 | 86 | // spin box for setting number of affected items (add, remove) |
|
87 | 87 | m_linesCountSpinBox = new QSpinBox; |
|
88 | 88 | m_linesCountSpinBox->setRange(1, 10); |
|
89 | 89 | m_linesCountSpinBox->setValue(1); |
|
90 | 90 | |
|
91 | 91 | // buttons layout |
|
92 | 92 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
93 | 93 | // buttonsLayout->addWidget(spinBoxLabel); |
|
94 | 94 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
95 | 95 | // buttonsLayout->addWidget(addRowAboveButton); |
|
96 | 96 | buttonsLayout->addWidget(addRowBelowButton); |
|
97 | 97 | buttonsLayout->addWidget(removeRowButton); |
|
98 | 98 | // buttonsLayout->addWidget(addColumnRightButton); |
|
99 | 99 | // buttonsLayout->addWidget(removeColumnButton); |
|
100 | 100 | // buttonsLayout->addWidget(specialPieButton); |
|
101 | 101 | buttonsLayout->addStretch(); |
|
102 | 102 | |
|
103 | 103 | // chart type radio buttons |
|
104 | 104 | m_lineRadioButton = new QRadioButton("Line"); |
|
105 | 105 | m_splineRadioButton = new QRadioButton("Spline"); |
|
106 | 106 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
107 | 107 | m_pieRadioButton = new QRadioButton("Pie"); |
|
108 | 108 | m_areaRadioButton = new QRadioButton("Area"); |
|
109 | 109 | m_barRadioButton = new QRadioButton("Bar"); |
|
110 | 110 | |
|
111 | 111 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
112 | 112 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
113 | 113 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
114 | 114 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
115 | 115 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
116 | 116 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
117 | 117 | m_pieRadioButton->setChecked(true); |
|
118 | 118 | |
|
119 | 119 | // radio buttons layout |
|
120 | 120 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
121 | 121 | radioLayout->addWidget(m_lineRadioButton); |
|
122 | 122 | // radioLayout->addWidget(m_splineRadioButton); |
|
123 | 123 | // radioLayout->addWidget(m_scatterRadioButton); |
|
124 | 124 | radioLayout->addWidget(m_pieRadioButton); |
|
125 | 125 | // radioLayout->addWidget(m_areaRadioButton); |
|
126 | 126 | radioLayout->addWidget(m_barRadioButton); |
|
127 | 127 | radioLayout->addStretch(); |
|
128 | 128 | |
|
129 | 129 | // create main layout |
|
130 | 130 | QGridLayout* mainLayout = new QGridLayout; |
|
131 | 131 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
132 | 132 | // mainLayout->addLayout(radioLayout, 2, 1); |
|
133 | 133 | mainLayout->addWidget(m_tableView, 1, 0); |
|
134 | 134 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
135 | 135 | setLayout(mainLayout); |
|
136 | 136 | m_lineRadioButton->setFocus(); |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | void TableWidget::addRowAbove() |
|
140 | 140 | { |
|
141 | 141 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
142 | 142 | |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | void TableWidget::addRowBelow() |
|
146 | 146 | { |
|
147 | 147 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
148 | 148 | |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void TableWidget::removeRow() |
|
152 | 152 | { |
|
153 | 153 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void TableWidget::addColumnRight() |
|
157 | 157 | { |
|
158 | 158 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void TableWidget::removeColumn() |
|
162 | 162 | { |
|
163 | 163 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | void TableWidget::updateChartType(bool toggle) |
|
167 | 167 | { |
|
168 | 168 | // this if is needed, so that the function is only called once. |
|
169 | 169 | // For the radioButton that was enabled. |
|
170 | 170 | if (toggle) { |
|
171 | 171 | // specialPie = 0; |
|
172 | 172 | m_chart->removeAllSeries(); |
|
173 | 173 | m_chart->axisX()->setNiceNumbersEnabled(false); |
|
174 | 174 | m_chart->axisY()->setNiceNumbersEnabled(false); |
|
175 | 175 | |
|
176 | 176 | // renable axes of the chart (pie hides them) |
|
177 | 177 | // x axis |
|
178 | 178 | QAxis *axis = m_chart->axisX(); |
|
179 | 179 | axis->setAxisVisible(true); |
|
180 | 180 | axis->setGridLineVisible(true); |
|
181 | 181 | axis->setLabelsVisible(true); |
|
182 | 182 | |
|
183 | 183 | // y axis |
|
184 | 184 | axis = m_chart->axisY(); |
|
185 | 185 | axis->setAxisVisible(true); |
|
186 | 186 | axis->setGridLineVisible(true); |
|
187 | 187 | axis->setLabelsVisible(true); |
|
188 | 188 | |
|
189 | 189 | m_model->clearMapping(); |
|
190 | 190 | |
|
191 | 191 | QString seriesColorHex = "#000000"; |
|
192 | 192 | QPen pen; |
|
193 | 193 | pen.setWidth(2); |
|
194 | 194 | |
|
195 | 195 | if (m_lineRadioButton->isChecked()) |
|
196 | 196 | { |
|
197 | 197 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
198 | 198 | |
|
199 | 199 | // series 1 |
|
200 | 200 | m_series = new QLineSeries; |
|
201 | 201 | m_series->setModel(m_model); |
|
202 | 202 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
203 | 203 | m_series->setModelMappingRange(3, 4); |
|
204 | 204 | m_chart->addSeries(m_series); |
|
205 | 205 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
206 | 206 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
207 | 207 | |
|
208 | 208 | // series 2 |
|
209 | 209 | m_series = new QLineSeries; |
|
210 | 210 | m_series->setModel(m_model); |
|
211 | 211 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
212 | 212 | m_chart->addSeries(m_series); |
|
213 | 213 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
214 | 214 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
215 | 215 | |
|
216 | 216 | // series 3 |
|
217 | 217 | m_series = new QLineSeries; |
|
218 | 218 | m_series->setModel(m_model); |
|
219 | 219 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
220 | 220 | m_series->setModelMappingRange(2, -1); |
|
221 | 221 | m_chart->addSeries(m_series); |
|
222 | 222 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
223 | 223 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
224 | 224 | } |
|
225 | 225 | else if (m_splineRadioButton->isChecked()) |
|
226 | 226 | { |
|
227 | 227 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
228 | 228 | |
|
229 | 229 | // series 1 |
|
230 | 230 | m_series = new QSplineSeries; |
|
231 | 231 | m_series->setModel(m_model); |
|
232 | 232 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
233 | 233 | // m_series->setModelMappingRange(1, 4); |
|
234 | 234 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
235 | 235 | m_chart->addSeries(m_series); |
|
236 | 236 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
237 | 237 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
238 | 238 | |
|
239 | 239 | // series 2 |
|
240 | 240 | m_series = new QSplineSeries; |
|
241 | 241 | m_series->setModel(m_model); |
|
242 | 242 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
243 | 243 | m_series->setModelMappingRange(2, 4); |
|
244 | 244 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
245 | 245 | m_chart->addSeries(m_series); |
|
246 | 246 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
247 | 247 | m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
248 | 248 | |
|
249 | 249 | // series 3 |
|
250 | 250 | m_series = new QSplineSeries; |
|
251 | 251 | m_series->setModel(m_model); |
|
252 | 252 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
253 | 253 | m_series->setModelMappingRange(2, -1); |
|
254 | 254 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
255 | 255 | m_chart->addSeries(m_series); |
|
256 | 256 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
257 | 257 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
258 | 258 | } |
|
259 | 259 | else if (m_scatterRadioButton->isChecked()) |
|
260 | 260 | { |
|
261 | 261 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
262 | 262 | |
|
263 | 263 | // series 1 |
|
264 | 264 | m_series = new QScatterSeries; |
|
265 | 265 | m_series->setModel(m_model); |
|
266 | 266 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
267 | 267 | // m_series->setModelMappingRange(2, 0); |
|
268 | 268 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
269 | 269 | m_chart->addSeries(m_series); |
|
270 | 270 | |
|
271 | 271 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
272 | 272 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
273 | 273 | |
|
274 | 274 | // series 2 |
|
275 | 275 | m_series = new QScatterSeries; |
|
276 | 276 | m_series->setModel(m_model); |
|
277 | 277 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
278 | 278 | // m_series->setModelMappingRange(1, 6); |
|
279 | 279 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
280 | 280 | m_chart->addSeries(m_series); |
|
281 | 281 | |
|
282 | 282 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
283 | 283 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
284 | 284 | |
|
285 | 285 | // series 3 |
|
286 | 286 | m_series = new QScatterSeries; |
|
287 | 287 | m_series->setModel(m_model); |
|
288 | 288 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
289 | 289 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
290 | 290 | m_chart->addSeries(m_series); |
|
291 | 291 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
292 | 292 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
293 | 293 | } |
|
294 | 294 | else if (m_pieRadioButton->isChecked()) |
|
295 | 295 | { |
|
296 | 296 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
297 | 297 | |
|
298 | 298 | // pie 1 |
|
299 | 299 | QPieSeries* pieSeries = new QPieSeries; |
|
300 | 300 | pieSeries->setModel(m_model); |
|
301 | 301 | pieSeries->setModelMappingRange(2, 5); |
|
302 | 302 | pieSeries->setModelMapping(1, 0, Qt::Vertical); |
|
303 | 303 | pieSeries->setLabelsVisible(true); |
|
304 | 304 | pieSeries->setPieSize(0.75); |
|
305 | 305 | // pieSeries->setHorizontalPosition(0.2); |
|
306 | 306 | // pieSeries->setVerticalPosition(0.3); |
|
307 | 307 | |
|
308 | 308 | m_chart->addSeries(pieSeries); |
|
309 | 309 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
310 | 310 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
311 | 311 | |
|
312 | 312 | // // pie 2 |
|
313 | 313 | // pieSeries = new QPieSeries; |
|
314 | 314 | // pieSeries->setModel(m_model); |
|
315 | 315 | |
|
316 | 316 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
317 | 317 | // pieSeries->setModelMappingRange(2, -1); |
|
318 | 318 | // pieSeries->setLabelsVisible(true); |
|
319 | 319 | // pieSeries->setPieSize(0.35); |
|
320 | 320 | // pieSeries->setHorizontalPosition(0.8); |
|
321 | 321 | // pieSeries->setVerticalPosition(0.3); |
|
322 | 322 | // m_chart->addSeries(pieSeries); |
|
323 | 323 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
324 | 324 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
325 | 325 | |
|
326 | 326 | // // pie 3 |
|
327 | 327 | // pieSeries = new QPieSeries; |
|
328 | 328 | // pieSeries->setModel(m_model); |
|
329 | 329 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
330 | 330 | // pieSeries->setLabelsVisible(true); |
|
331 | 331 | // pieSeries->setPieSize(0.35); |
|
332 | 332 | // pieSeries->setHorizontalPosition(0.5); |
|
333 | 333 | // pieSeries->setVerticalPosition(0.75); |
|
334 | 334 | // m_chart->addSeries(pieSeries); |
|
335 | 335 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
336 | 336 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
337 | 337 | |
|
338 | 338 | // // special pie |
|
339 | 339 | // specialPie = new QPieSeries; |
|
340 | 340 | // specialPie->append(17, "1"); |
|
341 | 341 | // specialPie->append(45, "2"); |
|
342 | 342 | // specialPie->append(77, "3"); |
|
343 | 343 | // specialPie->append(37, "4"); |
|
344 | 344 | // specialPie->append(27, "5"); |
|
345 | 345 | // specialPie->append(47, "6"); |
|
346 | 346 | // specialPie->setPieSize(0.35); |
|
347 | 347 | // specialPie->setHorizontalPosition(0.8); |
|
348 | 348 | // specialPie->setVerticalPosition(0.75); |
|
349 | 349 | // specialPie->setLabelsVisible(true); |
|
350 | 350 | // m_chart->addSeries(specialPie); |
|
351 | 351 | } |
|
352 | 352 | else if (m_areaRadioButton->isChecked()) |
|
353 | 353 | { |
|
354 | 354 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
355 | 355 | |
|
356 | 356 | QLineSeries* upperLineSeries = new QLineSeries; |
|
357 | 357 | upperLineSeries->setModel(m_model); |
|
358 | 358 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
359 | 359 | // upperLineSeries->setModelMappingRange(1, 5); |
|
360 | 360 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
361 | 361 | lowerLineSeries->setModel(m_model); |
|
362 | 362 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
363 | 363 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
364 | 364 | m_chart->addSeries(areaSeries); |
|
365 | 365 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
366 | 366 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
367 | 367 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
368 | 368 | } |
|
369 | 369 | else if (m_barRadioButton->isChecked()) |
|
370 | 370 | { |
|
371 | 371 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
372 | 372 | |
|
373 |
QBarSeries* barSeries = new QBarSeries( |
|
|
373 | QBarSeries* barSeries = new QBarSeries(); | |
|
374 | barSeries->setCategories(QStringList()); | |
|
374 | 375 | barSeries->setModel(m_model); |
|
375 | 376 | // barSeries->setModelMappingRange(2, 5); |
|
376 | 377 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
377 | 378 | m_chart->addSeries(barSeries); |
|
378 | 379 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
379 | 380 | for (int i = 0; i < barsets.count(); i++) { |
|
380 | 381 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
381 | 382 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
382 | 383 | } |
|
383 | 384 | } |
|
384 | 385 | |
|
385 | 386 | |
|
386 | 387 | if (!m_barRadioButton->isChecked()) { |
|
387 | 388 | m_chart->axisX()->setRange(0, 500); |
|
388 | 389 | m_chart->axisY()->setRange(0, 220); |
|
389 | 390 | } |
|
390 | 391 | m_chart->legend()->setVisible(true); |
|
391 | 392 | |
|
392 | 393 | // repaint table view colors |
|
393 | 394 | m_tableView->repaint(); |
|
394 | 395 | m_tableView->setFocus(); |
|
395 | 396 | } |
|
396 | 397 | } |
|
397 | 398 | |
|
398 | 399 | void TableWidget::testPie() |
|
399 | 400 | { |
|
400 | 401 | m_tableView->setColumnWidth(10, 250); |
|
401 | 402 | // if (specialPie) { |
|
402 | 403 | // specialPie->remove(specialPie->slices().at(2)); |
|
403 | 404 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
404 | 405 | // specialPie->append(4, "heloo"); |
|
405 | 406 | // } |
|
406 | 407 | } |
|
407 | 408 | |
|
408 | 409 | TableWidget::~TableWidget() |
|
409 | 410 | { |
|
410 | 411 | |
|
411 | 412 | } |
General Comments 0
You need to be logged in to leave comments.
Login now