@@ -1,386 +1,385 | |||
|
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 <QAbstractBarSeries> |
|
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 | #include <QCategoriesAxis> |
|
44 | 44 | |
|
45 | 45 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
46 | 46 | QWidget(parent), |
|
47 | 47 | m_listCount(3), |
|
48 | 48 | m_valueMax(10), |
|
49 | 49 | m_valueCount(7), |
|
50 | 50 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
51 | 51 | m_themeComboBox(createThemeBox()), |
|
52 | 52 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
53 | 53 | m_animatedComboBox(createAnimationBox()), |
|
54 | 54 | m_legendComboBox(createLegendBox()) |
|
55 | 55 | { |
|
56 | 56 | connectSignals(); |
|
57 | 57 | // create layout |
|
58 | 58 | QGridLayout* baseLayout = new QGridLayout(); |
|
59 | 59 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
60 | 60 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
61 | 61 | settingsLayout->addWidget(m_themeComboBox); |
|
62 | 62 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
63 | 63 | settingsLayout->addWidget(m_animatedComboBox); |
|
64 | 64 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
65 | 65 | settingsLayout->addWidget(m_legendComboBox); |
|
66 | 66 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
67 | 67 | settingsLayout->addStretch(); |
|
68 | 68 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
69 | 69 | |
|
70 | 70 | //create charts |
|
71 | 71 | |
|
72 | 72 | QChartView *chartView; |
|
73 | 73 | |
|
74 | 74 | chartView = new QChartView(createAreaChart()); |
|
75 | 75 | baseLayout->addWidget(chartView, 1, 0); |
|
76 | 76 | m_charts << chartView; |
|
77 | 77 | |
|
78 | 78 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
79 | 79 | baseLayout->addWidget(chartView, 1, 1); |
|
80 | 80 | m_charts << chartView; |
|
81 | 81 | |
|
82 | 82 | chartView = new QChartView(createLineChart()); |
|
83 | 83 | baseLayout->addWidget(chartView, 1, 2); |
|
84 | 84 | m_charts << chartView; |
|
85 | 85 | |
|
86 | 86 | chartView = new QChartView(createPieChart()); |
|
87 | 87 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
88 | 88 | baseLayout->addWidget(chartView, 2, 0); |
|
89 | 89 | m_charts << chartView; |
|
90 | 90 | |
|
91 | 91 | chartView = new QChartView(createSplineChart()); |
|
92 | 92 | baseLayout->addWidget(chartView, 2, 1); |
|
93 | 93 | m_charts << chartView; |
|
94 | 94 | |
|
95 | 95 | chartView = new QChartView(createScatterChart()); |
|
96 | 96 | baseLayout->addWidget(chartView, 2, 2); |
|
97 | 97 | m_charts << chartView; |
|
98 | 98 | |
|
99 | 99 | setLayout(baseLayout); |
|
100 | 100 | |
|
101 | 101 | // Set defaults |
|
102 | 102 | m_antialiasCheckBox->setChecked(true); |
|
103 | 103 | updateUI(); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | ThemeWidget::~ThemeWidget() |
|
107 | 107 | { |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void ThemeWidget::connectSignals() |
|
111 | 111 | { |
|
112 | 112 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | 113 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
114 | 114 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
115 | 115 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
119 | 119 | { |
|
120 | 120 | DataTable dataTable; |
|
121 | 121 | |
|
122 | 122 | // set seed for random stuff |
|
123 | 123 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
124 | 124 | |
|
125 | 125 | // generate random data |
|
126 | 126 | for (int i(0); i < listCount; i++) { |
|
127 | 127 | DataList dataList; |
|
128 | 128 | qreal yValue(0); |
|
129 | 129 | for (int j(0); j < valueCount; j++) { |
|
130 | 130 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
131 | 131 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
132 | 132 | yValue); |
|
133 | 133 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
134 | 134 | dataList << Data(value, label); |
|
135 | 135 | } |
|
136 | 136 | dataTable << dataList; |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | return dataTable; |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | QComboBox* ThemeWidget::createThemeBox() const |
|
143 | 143 | { |
|
144 | 144 | // settings layout |
|
145 | 145 | QComboBox* themeComboBox = new QComboBox(); |
|
146 | 146 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
147 | 147 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
148 | 148 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
149 | 149 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
150 | 150 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
151 | 151 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
152 | 152 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
153 | 153 | return themeComboBox; |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | QComboBox* ThemeWidget::createAnimationBox() const |
|
157 | 157 | { |
|
158 | 158 | // settings layout |
|
159 | 159 | QComboBox* animationComboBox = new QComboBox(); |
|
160 | 160 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
161 | 161 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
162 | 162 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
163 | 163 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
164 | 164 | return animationComboBox; |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | QComboBox* ThemeWidget::createLegendBox() const |
|
168 | 168 | { |
|
169 | 169 | QComboBox* legendComboBox = new QComboBox(); |
|
170 | 170 | legendComboBox->addItem("No Legend ", 0); |
|
171 | 171 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
172 | 172 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
173 | 173 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
174 | 174 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
175 | 175 | return legendComboBox; |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | QChart* ThemeWidget::createAreaChart() const |
|
179 | 179 | { |
|
180 | 180 | QChart *chart = new QChart(); |
|
181 | 181 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
182 | 182 | // chart->axisY()->setNiceNumbersEnabled(true); |
|
183 | 183 | chart->setTitle("Area chart"); |
|
184 | 184 | |
|
185 | 185 | // The lower series initialized to zero values |
|
186 | 186 | QLineSeries *lowerSeries = 0; |
|
187 | 187 | QString name("Series "); |
|
188 | 188 | int nameIndex = 0; |
|
189 | 189 | for (int i(0); i < m_dataTable.count(); i++) { |
|
190 | 190 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
191 | 191 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
192 | 192 | Data data = m_dataTable[i].at(j); |
|
193 | 193 | if (lowerSeries){ |
|
194 | 194 | const QList<QPointF>& points = lowerSeries->points(); |
|
195 | 195 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
196 | 196 | }else |
|
197 | 197 | upperSeries->append(QPointF(j, data.first.y())); |
|
198 | 198 | } |
|
199 | 199 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
200 | 200 | area->setName(name + QString::number(nameIndex)); |
|
201 | 201 | nameIndex++; |
|
202 | 202 | chart->addSeries(area); |
|
203 | 203 | chart->createDefaultAxes(); |
|
204 | 204 | lowerSeries = upperSeries; |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | return chart; |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
211 | 211 | { |
|
212 | 212 | QChart* chart = new QChart(); |
|
213 | 213 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
214 | 214 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
215 | 215 | chart->setTitle("Bar chart"); |
|
216 | 216 | |
|
217 | 217 | QStringList categories; |
|
218 | 218 | for (int i(0); i < valueCount; i++) |
|
219 | 219 | categories << QString::number(i); |
|
220 | 220 | |
|
221 | 221 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
222 | 222 | axis->append(categories); |
|
223 | 223 | |
|
224 | 224 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
225 | 225 | for (int i(0); i < m_dataTable.count(); i++) { |
|
226 | 226 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
227 | 227 | foreach (Data data, m_dataTable[i]) |
|
228 | 228 | *set << data.first.y(); |
|
229 | 229 | series->append(set); |
|
230 | 230 | } |
|
231 | 231 | chart->addSeries(series); |
|
232 | 232 | chart->createDefaultAxes(); |
|
233 | 233 | chart->setAxisX(axis, series); |
|
234 | 234 | |
|
235 | 235 | return chart; |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | QChart* ThemeWidget::createLineChart() const |
|
239 | 239 | { |
|
240 | 240 | QChart* chart = new QChart(); |
|
241 | 241 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
242 | 242 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
243 | 243 | chart->setTitle("Line chart"); |
|
244 | 244 | |
|
245 | 245 | QString name("Series "); |
|
246 | 246 | int nameIndex = 0; |
|
247 | 247 | foreach (DataList list, m_dataTable) { |
|
248 | 248 | QLineSeries *series = new QLineSeries(chart); |
|
249 | 249 | foreach (Data data, list) |
|
250 | 250 | series->append(data.first); |
|
251 | 251 | series->setName(name + QString::number(nameIndex)); |
|
252 | 252 | nameIndex++; |
|
253 | 253 | chart->addSeries(series); |
|
254 | chart->createDefaultAxes(); | |
|
255 | ||
|
256 | 254 | } |
|
255 | chart->createDefaultAxes(); | |
|
257 | 256 | |
|
258 | 257 | return chart; |
|
259 | 258 | } |
|
260 | 259 | |
|
261 | 260 | QChart* ThemeWidget::createPieChart() const |
|
262 | 261 | { |
|
263 | 262 | QChart* chart = new QChart(); |
|
264 | 263 | chart->setTitle("Pie chart"); |
|
265 | 264 | |
|
266 | 265 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
267 | 266 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
268 | 267 | QPieSeries *series = new QPieSeries(chart); |
|
269 | 268 | foreach (Data data, m_dataTable[i]) { |
|
270 | 269 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
271 | 270 | if (data == m_dataTable[i].first()) { |
|
272 | 271 | slice->setLabelVisible(); |
|
273 | 272 | slice->setExploded(); |
|
274 | 273 | } |
|
275 | 274 | } |
|
276 | 275 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
277 | 276 | series->setPieSize(pieSize); |
|
278 | 277 | series->setHorizontalPosition(hPos); |
|
279 | 278 | series->setVerticalPosition(0.5); |
|
280 | 279 | chart->addSeries(series); |
|
281 | 280 | } |
|
282 | 281 | |
|
283 | 282 | return chart; |
|
284 | 283 | } |
|
285 | 284 | |
|
286 | 285 | QChart* ThemeWidget::createSplineChart() const |
|
287 | 286 | { // spine chart |
|
288 | 287 | QChart* chart = new QChart(); |
|
289 | 288 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
290 | 289 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
291 | 290 | chart->setTitle("Spline chart"); |
|
292 | 291 | QString name("Series "); |
|
293 | 292 | int nameIndex = 0; |
|
294 | 293 | foreach (DataList list, m_dataTable) { |
|
295 | 294 | QSplineSeries *series = new QSplineSeries(chart); |
|
296 | 295 | foreach (Data data, list) |
|
297 | 296 | series->append(data.first); |
|
298 | 297 | series->setName(name + QString::number(nameIndex)); |
|
299 | 298 | nameIndex++; |
|
300 | 299 | chart->addSeries(series); |
|
301 | chart->createDefaultAxes(); | |
|
302 | 300 | } |
|
301 | chart->createDefaultAxes(); | |
|
303 | 302 | return chart; |
|
304 | 303 | } |
|
305 | 304 | |
|
306 | 305 | QChart* ThemeWidget::createScatterChart() const |
|
307 | 306 | { // scatter chart |
|
308 | 307 | QChart* chart = new QChart(); |
|
309 | 308 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
310 | 309 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
311 | 310 | chart->setTitle("Scatter chart"); |
|
312 | 311 | QString name("Series "); |
|
313 | 312 | int nameIndex = 0; |
|
314 | 313 | foreach (DataList list, m_dataTable) { |
|
315 | 314 | QScatterSeries *series = new QScatterSeries(chart); |
|
316 | 315 | foreach (Data data, list) |
|
317 | 316 | series->append(data.first); |
|
318 | 317 | series->setName(name + QString::number(nameIndex)); |
|
319 | 318 | nameIndex++; |
|
320 | 319 | chart->addSeries(series); |
|
321 | chart->createDefaultAxes(); | |
|
322 | 320 | } |
|
321 | chart->createDefaultAxes(); | |
|
323 | 322 | return chart; |
|
324 | 323 | } |
|
325 | 324 | |
|
326 | 325 | void ThemeWidget::updateUI() |
|
327 | 326 | { |
|
328 | 327 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
329 | 328 | |
|
330 | 329 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
331 | 330 | foreach (QChartView *chartView, m_charts) |
|
332 | 331 | chartView->chart()->setTheme(theme); |
|
333 | 332 | |
|
334 | 333 | QPalette pal = window()->palette(); |
|
335 | 334 | if (theme == QChart::ChartThemeLight) { |
|
336 | 335 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
337 | 336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
338 | 337 | } else if (theme == QChart::ChartThemeDark) { |
|
339 | 338 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
340 | 339 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
341 | 340 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
342 | 341 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
343 | 342 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
344 | 343 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
345 | 344 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
346 | 345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
347 | 346 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
348 | 347 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
349 | 348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
350 | 349 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
351 | 350 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
352 | 351 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
353 | 352 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
354 | 353 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
355 | 354 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
356 | 355 | } else { |
|
357 | 356 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
358 | 357 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
359 | 358 | } |
|
360 | 359 | window()->setPalette(pal); |
|
361 | 360 | } |
|
362 | 361 | |
|
363 | 362 | bool checked = m_antialiasCheckBox->isChecked(); |
|
364 | 363 | foreach (QChartView *chart, m_charts) |
|
365 | 364 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
366 | 365 | |
|
367 | 366 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
368 | 367 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
369 | 368 | foreach (QChartView *chartView, m_charts) |
|
370 | 369 | chartView->chart()->setAnimationOptions(options); |
|
371 | 370 | } |
|
372 | 371 | |
|
373 | 372 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
374 | 373 | |
|
375 | 374 | if (!alignment) { |
|
376 | 375 | foreach (QChartView *chartView, m_charts) { |
|
377 | 376 | chartView->chart()->legend()->hide(); |
|
378 | 377 | } |
|
379 | 378 | } else { |
|
380 | 379 | foreach (QChartView *chartView, m_charts) { |
|
381 | 380 | chartView->chart()->legend()->setAlignment(alignment); |
|
382 | 381 | chartView->chart()->legend()->show(); |
|
383 | 382 | } |
|
384 | 383 | } |
|
385 | 384 | } |
|
386 | 385 |
@@ -1,396 +1,406 | |||
|
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 "qareaseries.h" |
|
22 | 22 | #include "qareaseries_p.h" |
|
23 | 23 | #include "qlineseries.h" |
|
24 | 24 | #include "areachartitem_p.h" |
|
25 | 25 | #include "legendmarker_p.h" |
|
26 | 26 | #include "domain_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | #include "qvaluesaxis.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QAreaSeries |
|
36 | 36 | \brief The QAreaSeries class is used for making area charts. |
|
37 | 37 | |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
41 | 41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
42 | 42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
43 | 43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
44 | 44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
45 | 45 | |
|
46 | 46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
47 | 47 | \image examples_areachart.png |
|
48 | 48 | */ |
|
49 | 49 | /*! |
|
50 | 50 | \qmlclass AreaSeries QAreaSeries |
|
51 | 51 | |
|
52 | 52 | The following QML shows how to create a simple area chart: |
|
53 | 53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
54 | 54 | \beginfloatleft |
|
55 | 55 | \image demos_qmlchart4.png |
|
56 | 56 | \endfloat |
|
57 | 57 | \clearfloat |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \property QAreaSeries::upperSeries |
|
62 | 62 | \brief The upper one of the two line series used to define area series boundaries. |
|
63 | 63 | */ |
|
64 | 64 | /*! |
|
65 | 65 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
66 | 66 | The upper one of the two line series used to define area series boundaries. |
|
67 | 67 | */ |
|
68 | 68 | |
|
69 | 69 | /*! |
|
70 | 70 | \property QAreaSeries::lowerSeries |
|
71 | 71 | The lower one of the two line series used to define are series boundaries. Note if |
|
72 | 72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
73 | 73 | */ |
|
74 | 74 | /*! |
|
75 | 75 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
76 | 76 | The lower one of the two line series used to define are series boundaries. Note if |
|
77 | 77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \property QAreaSeries::color |
|
82 | 82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
83 | 83 | \sa QAreaSeries::brush() |
|
84 | 84 | */ |
|
85 | 85 | /*! |
|
86 | 86 | \qmlproperty color AreaSeries::color |
|
87 | 87 | Fill (brush) color of the series. |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \property QAreaSeries::borderColor |
|
92 | 92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
93 | 93 | \sa QAreaSeries::pen() |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlproperty color AreaSeries::borderColor |
|
97 | 97 | Line (pen) color of the series. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \fn QPen QAreaSeries::pen() const |
|
102 | 102 | \brief Returns the pen used to draw line for this series. |
|
103 | 103 | \sa setPen() |
|
104 | 104 | */ |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | \fn QPen QAreaSeries::brush() const |
|
108 | 108 | \brief Returns the brush used to draw line for this series. |
|
109 | 109 | \sa setBrush() |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QAreaSeries::colorChanged(QColor color) |
|
114 | 114 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
115 | 115 | */ |
|
116 | 116 | /*! |
|
117 | 117 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
118 | 118 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
119 | 119 | */ |
|
120 | 120 | |
|
121 | 121 | /*! |
|
122 | 122 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
123 | 123 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
124 | 124 | */ |
|
125 | 125 | /*! |
|
126 | 126 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
127 | 127 | Signal is emitted when the line (pen) color has changed to \a color. |
|
128 | 128 | */ |
|
129 | 129 | |
|
130 | 130 | /*! |
|
131 | 131 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
132 | 132 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
133 | 133 | */ |
|
134 | 134 | /*! |
|
135 | 135 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
136 | 136 | Signal is emitted when user clicks the \a point on area chart. |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \fn void QAreaSeries::selected() |
|
141 | 141 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
142 | 142 | implemented by the user of QAreaSeries API. |
|
143 | 143 | */ |
|
144 | 144 | /*! |
|
145 | 145 | \qmlsignal AreaSeries::onSelected() |
|
146 | 146 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
147 | 147 | implemented by the user of AreaSeries API. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QAreaSeriesPrivate::updated() |
|
152 | 152 | \brief \internal |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
157 | 157 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
158 | 158 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
159 | 159 | */ |
|
160 | 160 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
161 | 161 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
162 | 162 | { |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | Constructs area series object without upper or lower series with \a parent object. |
|
167 | 167 | */ |
|
168 | 168 | QAreaSeries::QAreaSeries(QObject *parent) |
|
169 | 169 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
170 | 170 | { |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | Destroys the object. |
|
175 | 175 | */ |
|
176 | 176 | QAreaSeries::~QAreaSeries() |
|
177 | 177 | { |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | /*! |
|
181 | 181 | Returns QChartSeries::SeriesTypeArea. |
|
182 | 182 | */ |
|
183 | 183 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
184 | 184 | { |
|
185 | 185 | return QAbstractSeries::SeriesTypeArea; |
|
186 | 186 | } |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | Sets the \a series that is to be used as the area chart upper series. |
|
190 | 190 | */ |
|
191 | 191 | void QAreaSeries::setUpperSeries(QLineSeries* series) |
|
192 | 192 | { |
|
193 | 193 | Q_D(QAreaSeries); |
|
194 | 194 | d->m_upperSeries = series; |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | QLineSeries* QAreaSeries::upperSeries() const |
|
198 | 198 | { |
|
199 | 199 | Q_D(const QAreaSeries); |
|
200 | 200 | return d->m_upperSeries; |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Sets the \a series that is to be used as the area chart lower series. |
|
205 | 205 | */ |
|
206 | 206 | void QAreaSeries::setLowerSeries(QLineSeries* series) |
|
207 | 207 | { |
|
208 | 208 | Q_D(QAreaSeries); |
|
209 | 209 | d->m_lowerSeries = series; |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | QLineSeries* QAreaSeries::lowerSeries() const |
|
213 | 213 | { |
|
214 | 214 | Q_D(const QAreaSeries); |
|
215 | 215 | return d->m_lowerSeries; |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | /*! |
|
219 | 219 | Sets \a pen used for drawing area outline. |
|
220 | 220 | */ |
|
221 | 221 | void QAreaSeries::setPen(const QPen &pen) |
|
222 | 222 | { |
|
223 | 223 | Q_D(QAreaSeries); |
|
224 | 224 | if (d->m_pen != pen) { |
|
225 | 225 | d->m_pen = pen; |
|
226 | 226 | emit d->updated(); |
|
227 | 227 | } |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | QPen QAreaSeries::pen() const |
|
231 | 231 | { |
|
232 | 232 | Q_D(const QAreaSeries); |
|
233 | 233 | return d->m_pen; |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | /*! |
|
237 | 237 | Sets \a brush used for filling the area. |
|
238 | 238 | */ |
|
239 | 239 | void QAreaSeries::setBrush(const QBrush &brush) |
|
240 | 240 | { |
|
241 | 241 | Q_D(QAreaSeries); |
|
242 | 242 | if (d->m_brush != brush) { |
|
243 | 243 | d->m_brush = brush; |
|
244 | 244 | emit d->updated(); |
|
245 | 245 | } |
|
246 | 246 | } |
|
247 | 247 | |
|
248 | 248 | QBrush QAreaSeries::brush() const |
|
249 | 249 | { |
|
250 | 250 | Q_D(const QAreaSeries); |
|
251 | 251 | return d->m_brush; |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | void QAreaSeries::setColor(const QColor &color) |
|
255 | 255 | { |
|
256 | 256 | QBrush b = brush(); |
|
257 | 257 | if (b.color() != color) { |
|
258 | 258 | b.setColor(color); |
|
259 | 259 | setBrush(b); |
|
260 | 260 | emit colorChanged(color); |
|
261 | 261 | } |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | QColor QAreaSeries::color() const |
|
265 | 265 | { |
|
266 | 266 | return brush().color(); |
|
267 | 267 | } |
|
268 | 268 | |
|
269 | 269 | void QAreaSeries::setBorderColor(const QColor &color) |
|
270 | 270 | { |
|
271 | 271 | QPen p = pen(); |
|
272 | 272 | if (p.color() != color) { |
|
273 | 273 | p.setColor(color); |
|
274 | 274 | setPen(p); |
|
275 | 275 | emit borderColorChanged(color); |
|
276 | 276 | } |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | QColor QAreaSeries::borderColor() const |
|
280 | 280 | { |
|
281 | 281 | return pen().color(); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | /*! |
|
285 | 285 | Sets if data points are \a visible and should be drawn on line. |
|
286 | 286 | */ |
|
287 | 287 | void QAreaSeries::setPointsVisible(bool visible) |
|
288 | 288 | { |
|
289 | 289 | Q_D(QAreaSeries); |
|
290 | 290 | if (d->m_pointsVisible != visible) { |
|
291 | 291 | d->m_pointsVisible = visible; |
|
292 | 292 | emit d->updated(); |
|
293 | 293 | } |
|
294 | 294 | } |
|
295 | 295 | |
|
296 | 296 | /*! |
|
297 | 297 | Returns if the points are drawn for this series. |
|
298 | 298 | \sa setPointsVisible() |
|
299 | 299 | */ |
|
300 | 300 | bool QAreaSeries::pointsVisible() const |
|
301 | 301 | { |
|
302 | 302 | Q_D(const QAreaSeries); |
|
303 | 303 | return d->m_pointsVisible; |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
307 | 307 | |
|
308 | 308 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
|
309 | 309 | QAbstractSeriesPrivate(q), |
|
310 | 310 | m_upperSeries(upperSeries), |
|
311 | 311 | m_lowerSeries(lowerSeries), |
|
312 | 312 | m_pointsVisible(false) |
|
313 | 313 | { |
|
314 | 314 | } |
|
315 | 315 | |
|
316 | 316 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
317 | 317 | { |
|
318 | 318 | Q_Q(QAreaSeries); |
|
319 | 319 | |
|
320 | 320 | qreal minX(domain.minX()); |
|
321 | 321 | qreal minY(domain.minY()); |
|
322 | 322 | qreal maxX(domain.maxX()); |
|
323 | 323 | qreal maxY(domain.maxY()); |
|
324 | 324 | int tickXCount(domain.tickXCount()); |
|
325 | 325 | int tickYCount(domain.tickYCount()); |
|
326 | 326 | |
|
327 | 327 | QLineSeries* upperSeries = q->upperSeries(); |
|
328 | 328 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
329 | 329 | |
|
330 | 330 | const QList<QPointF>& points = upperSeries->points(); |
|
331 | 331 | |
|
332 | 332 | for (int i = 0; i < points.count(); i++) |
|
333 | 333 | { |
|
334 | 334 | qreal x = points[i].x(); |
|
335 | 335 | qreal y = points[i].y(); |
|
336 | 336 | minX = qMin(minX, x); |
|
337 | 337 | minY = qMin(minY, y); |
|
338 | 338 | maxX = qMax(maxX, x); |
|
339 | 339 | maxY = qMax(maxY, y); |
|
340 | 340 | } |
|
341 | 341 | if(lowerSeries) { |
|
342 | 342 | |
|
343 | 343 | const QList<QPointF>& points = lowerSeries->points(); |
|
344 | 344 | |
|
345 | 345 | for (int i = 0; i < points.count(); i++) |
|
346 | 346 | { |
|
347 | 347 | qreal x = points[i].x(); |
|
348 | 348 | qreal y = points[i].y(); |
|
349 | 349 | minX = qMin(minX, x); |
|
350 | 350 | minY = qMin(minY, y); |
|
351 | 351 | maxX = qMax(maxX, x); |
|
352 | 352 | maxY = qMax(maxY, y); |
|
353 | 353 | }} |
|
354 | 354 | |
|
355 | 355 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
356 | 356 | } |
|
357 | 357 | |
|
358 | 358 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
359 | 359 | { |
|
360 | 360 | Q_Q(QAreaSeries); |
|
361 | 361 | |
|
362 | 362 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
363 | 363 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
364 | 364 | area->upperLineItem()->setAnimator(presenter->animator()); |
|
365 | 365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
366 | 366 | if(q->lowerSeries()) { |
|
367 | 367 | area->lowerLineItem()->setAnimator(presenter->animator()); |
|
368 | 368 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
369 | 369 | } |
|
370 | 370 | } |
|
371 | 371 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
372 | 372 | return area; |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) |
|
376 | 376 | { |
|
377 | 377 | Q_Q(QAreaSeries); |
|
378 | 378 | QList<LegendMarker*> list; |
|
379 | 379 | return list << new AreaLegendMarker(q,legend); |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | |
|
383 |
|
|
|
383 | void QAreaSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
|
384 | 384 | { |
|
385 | return new QValuesAxis(parent); | |
|
385 | Q_UNUSED(axis); | |
|
386 | 386 | } |
|
387 | 387 | |
|
388 |
|
|
|
388 | void QAreaSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
|
389 | 389 | { |
|
390 | return new QValuesAxis(parent); | |
|
390 | Q_UNUSED(axis); | |
|
391 | } | |
|
392 | ||
|
393 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisXType() const | |
|
394 | { | |
|
395 | return QAbstractAxis::AxisTypeValues; | |
|
396 | } | |
|
397 | ||
|
398 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisYType() const | |
|
399 | { | |
|
400 | return QAbstractAxis::AxisTypeValues; | |
|
391 | 401 | } |
|
392 | 402 | |
|
393 | 403 | #include "moc_qareaseries.cpp" |
|
394 | 404 | #include "moc_qareaseries_p.cpp" |
|
395 | 405 | |
|
396 | 406 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,69 | |||
|
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 QAREASERIES_P_H |
|
31 | 31 | #define QAREASERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QAreaSeries; |
|
38 | 38 | |
|
39 | 39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); |
|
45 | 45 | |
|
46 | 46 | void scaleDomain(Domain& domain); |
|
47 | 47 | Chart* createGraphics(ChartPresenter* presenter); |
|
48 | 48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
49 | QAbstractAxis* createAxisX(QObject* parent = 0); | |
|
50 | QAbstractAxis* createAxisY(QObject* parent = 0); | |
|
49 | void initializeAxisX(QAbstractAxis* axis); | |
|
50 | void initializeAxisY(QAbstractAxis* axis); | |
|
51 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
52 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
51 | 53 | |
|
52 | 54 | Q_SIGNALS: |
|
53 | 55 | void updated(); |
|
54 | 56 | |
|
55 | 57 | protected: |
|
56 | 58 | QBrush m_brush; |
|
57 | 59 | QPen m_pen; |
|
58 | 60 | QLineSeries* m_upperSeries; |
|
59 | 61 | QLineSeries* m_lowerSeries; |
|
60 | 62 | bool m_pointsVisible; |
|
61 | 63 | private: |
|
62 | 64 | Q_DECLARE_PUBLIC(QAreaSeries); |
|
63 | 65 | }; |
|
64 | 66 | |
|
65 | 67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | 68 | |
|
67 | 69 | #endif |
@@ -1,130 +1,133 | |||
|
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 QABSTRACTAXIS_H |
|
22 | 22 | #define QABSTRACTAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QFont> |
|
27 | 27 | #include <QVariant> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QAbstractAxisPrivate; |
|
32 | 32 | |
|
33 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | |
|
37 | 37 | Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) |
|
38 | 38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
39 | 39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
40 | 40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
41 | 41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
42 | 42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
43 | 43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
44 | 44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
45 | 45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
46 | 46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
47 | 47 | |
|
48 | 48 | public: |
|
49 | 49 | |
|
50 | 50 | enum AxisType { |
|
51 |
AxisType |
|
|
52 |
AxisType |
|
|
51 | AxisTypeNoAxis = 0x0, | |
|
52 | AxisTypeValues = 0x1, | |
|
53 | AxisTypeCategories = 0x2 | |
|
53 | 54 | }; |
|
54 | 55 | |
|
56 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |
|
57 | ||
|
55 | 58 | protected: |
|
56 | 59 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
57 | 60 | |
|
58 | 61 | public: |
|
59 | 62 | ~QAbstractAxis(); |
|
60 | 63 | |
|
61 | 64 | virtual AxisType type() const = 0; |
|
62 | 65 | |
|
63 | 66 | //axis handling |
|
64 | 67 | bool isAxisVisible() const; |
|
65 | 68 | void setAxisVisible(bool visible = true); |
|
66 | 69 | void setAxisPen(const QPen &pen); |
|
67 | 70 | QPen axisPen() const; |
|
68 | 71 | void setAxisPenColor(QColor color); |
|
69 | 72 | QColor axisPenColor() const; |
|
70 | 73 | |
|
71 | 74 | //grid handling |
|
72 | 75 | bool isGridLineVisible() const; |
|
73 | 76 | void setGridLineVisible(bool visible = true); |
|
74 | 77 | void setGridLinePen(const QPen &pen); |
|
75 | 78 | QPen gridLinePen() const; |
|
76 | 79 | |
|
77 | 80 | //labels handling |
|
78 | 81 | bool labelsVisible() const; |
|
79 | 82 | void setLabelsVisible(bool visible = true); |
|
80 | 83 | void setLabelsPen(const QPen &pen); |
|
81 | 84 | QPen labelsPen() const; |
|
82 | 85 | void setLabelsBrush(const QBrush &brush); |
|
83 | 86 | QBrush labelsBrush() const; |
|
84 | 87 | void setLabelsFont(const QFont &font); |
|
85 | 88 | QFont labelsFont() const; |
|
86 | 89 | void setLabelsAngle(int angle); |
|
87 | 90 | int labelsAngle() const; |
|
88 | 91 | void setLabelsColor(QColor color); |
|
89 | 92 | QColor labelsColor() const; |
|
90 | 93 | |
|
91 | 94 | //shades handling |
|
92 | 95 | bool shadesVisible() const; |
|
93 | 96 | void setShadesVisible(bool visible = true); |
|
94 | 97 | void setShadesPen(const QPen &pen); |
|
95 | 98 | QPen shadesPen() const; |
|
96 | 99 | void setShadesBrush(const QBrush &brush); |
|
97 | 100 | QBrush shadesBrush() const; |
|
98 | 101 | void setShadesColor(QColor color); |
|
99 | 102 | QColor shadesColor() const; |
|
100 | 103 | void setShadesBorderColor(QColor color); |
|
101 | 104 | QColor shadesBorderColor() const; |
|
102 | 105 | |
|
103 | 106 | //range handling |
|
104 | 107 | void setMin(const QVariant &min); |
|
105 | 108 | void setMax(const QVariant &max); |
|
106 | 109 | void setRange(const QVariant &min, const QVariant &max); |
|
107 | 110 | |
|
108 | 111 | void show(); |
|
109 | 112 | void hide(); |
|
110 | 113 | |
|
111 | 114 | Q_SIGNALS: |
|
112 | 115 | void visibleChanged(bool visible); |
|
113 | 116 | void labelsVisibleChanged(bool visible); |
|
114 | 117 | void gridVisibleChanged(bool visible); |
|
115 | 118 | void colorChanged(QColor color); |
|
116 | 119 | void labelsColorChanged(QColor color); |
|
117 | 120 | void shadesVisibleChanged(bool visible); |
|
118 | 121 | void shadesColorChanged(QColor color); |
|
119 | 122 | void shadesBorderColorChanged(QColor color); |
|
120 | 123 | |
|
121 | 124 | protected: |
|
122 | 125 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
123 | 126 | Q_DISABLE_COPY(QAbstractAxis); |
|
124 | 127 | friend class ChartDataSet; |
|
125 | 128 | friend class ChartAxis; |
|
126 | 129 | friend class ChartPresenter; |
|
127 | 130 | }; |
|
128 | 131 | |
|
129 | 132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
130 | 133 | #endif |
@@ -1,724 +1,735 | |||
|
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 "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_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 | #include "qvaluesaxis.h" |
|
31 | 31 | #include "qcategoriesaxis.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | /*! |
|
36 | 36 | \class QAbstractBarSeries |
|
37 | 37 | \brief Series for creating a bar chart |
|
38 | 38 | \mainclass |
|
39 | 39 | |
|
40 | 40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 43 | shows the x-values. |
|
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 | \qmlclass BarSeries QAbstractBarSeries |
|
52 | \inherits AbstractSeries | |
|
52 | \inherits QAbstractSeries | |
|
53 | 53 | |
|
54 | 54 | The following QML shows how to create a simple bar chart: |
|
55 | 55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 56 | |
|
57 | 57 | \beginfloatleft |
|
58 | 58 | \image demos_qmlchart6.png |
|
59 | 59 | \endfloat |
|
60 | 60 | \clearfloat |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QAbstractBarSeries::barWidth |
|
65 | 65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 | 68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
69 | 69 | \sa QGroupedBarSeries |
|
70 | 70 | */ |
|
71 | 71 | /*! |
|
72 | 72 | \qmlproperty real BarSeries::barWidth |
|
73 | 73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 | 76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
77 | 77 | */ |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | \property QAbstractBarSeries::count |
|
81 | 81 | Holds the number of sets in series. |
|
82 | 82 | */ |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty int BarSeries::count |
|
85 | 85 | Holds the number of sets in series. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \property QAbstractBarSeries::labelsVisible |
|
90 | 90 | Defines the visibility of the labels in series |
|
91 | 91 | */ |
|
92 | 92 | /*! |
|
93 | 93 | \qmlproperty bool BarSeries::labelsVisible |
|
94 | 94 | Defines the visibility of the labels in series |
|
95 | 95 | */ |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 100 | Clicked bar inside set is indexed by \a index |
|
101 | 101 | */ |
|
102 | 102 | /*! |
|
103 | 103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) |
|
104 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 105 | Clicked bar inside set is indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 110 | |
|
111 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) |
|
117 | 117 | |
|
118 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 121 | */ |
|
122 | 122 | |
|
123 | 123 | /*! |
|
124 | 124 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 126 | */ |
|
127 | 127 | /*! |
|
128 | 128 | \qmlsignal BarSeries::onCountChanged() |
|
129 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 134 | This signal is emitted when labels visibility have changed. |
|
135 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 140 | This signal is emitted when \a sets have been added to the series. |
|
141 | 141 | \sa append(), insert() |
|
142 | 142 | */ |
|
143 | 143 | /*! |
|
144 | 144 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
145 | 145 | Emitted when \a barset has been added to the series. |
|
146 | 146 | */ |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 151 | \sa remove() |
|
152 | 152 | */ |
|
153 | 153 | /*! |
|
154 | 154 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
155 | 155 | Emitted when \a barset has been removed from the series. |
|
156 | 156 | */ |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | \qmlmethod BarSet BarSeries::at(int index) |
|
160 | 160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 161 | */ |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
165 | 165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
166 | 166 | For example: |
|
167 | 167 | \code |
|
168 | 168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
170 | 170 | \endcode |
|
171 | 171 | */ |
|
172 | 172 | |
|
173 | 173 | /*! |
|
174 | 174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
175 | 175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
176 | 176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
177 | 177 | appended. |
|
178 | 178 | \sa BarSeries::append() |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
183 | 183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
184 | 184 | */ |
|
185 | 185 | |
|
186 | 186 | /*! |
|
187 | 187 | \qmlmethod BarSeries::clear() |
|
188 | 188 | Removes all barsets from the series. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | Constructs empty QAbstractBarSeries. |
|
193 | 193 | QAbstractBarSeries is QObject which is a child of a \a parent. |
|
194 | 194 | */ |
|
195 | 195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
196 | 196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
197 | 197 | { |
|
198 | 198 | } |
|
199 | 199 | |
|
200 | 200 | /*! |
|
201 | 201 | Destructs barseries and owned barsets. |
|
202 | 202 | */ |
|
203 | 203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
204 | 204 | { |
|
205 | 205 | Q_D(QAbstractBarSeries); |
|
206 | 206 | if(d->m_dataset){ |
|
207 | 207 | d->m_dataset->removeSeries(this); |
|
208 | 208 | } |
|
209 | 209 | } |
|
210 | 210 | |
|
211 | 211 | /*! |
|
212 | 212 | \internal |
|
213 | 213 | */ |
|
214 | 214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
215 | 215 | QAbstractSeries(d,parent) |
|
216 | 216 | { |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | /*! |
|
220 | 220 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
221 | 221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
222 | 222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
223 | 223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
224 | 224 | */ |
|
225 | 225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
226 | 226 | { |
|
227 | 227 | Q_D(QAbstractBarSeries); |
|
228 | 228 | d->setBarWidth(width); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Returns the width of the bars of the series. |
|
233 | 233 | \sa setBarWidth() |
|
234 | 234 | */ |
|
235 | 235 | qreal QAbstractBarSeries::barWidth() const |
|
236 | 236 | { |
|
237 | 237 | Q_D(const QAbstractBarSeries); |
|
238 | 238 | return d->barWidth(); |
|
239 | 239 | } |
|
240 | 240 | |
|
241 | 241 | /*! |
|
242 | 242 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
243 | 243 | Returns true, if appending succeeded. |
|
244 | 244 | */ |
|
245 | 245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
246 | 246 | { |
|
247 | 247 | Q_D(QAbstractBarSeries); |
|
248 | 248 | bool success = d->append(set); |
|
249 | 249 | if (success) { |
|
250 | 250 | QList<QBarSet*> sets; |
|
251 | 251 | sets.append(set); |
|
252 | 252 | emit barsetsAdded(sets); |
|
253 | 253 | emit countChanged(); |
|
254 | 254 | } |
|
255 | 255 | return success; |
|
256 | 256 | } |
|
257 | 257 | |
|
258 | 258 | /*! |
|
259 | 259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
260 | 260 | Returns true, if set was removed. |
|
261 | 261 | */ |
|
262 | 262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
263 | 263 | { |
|
264 | 264 | Q_D(QAbstractBarSeries); |
|
265 | 265 | bool success = d->remove(set); |
|
266 | 266 | if (success) { |
|
267 | 267 | QList<QBarSet*> sets; |
|
268 | 268 | sets.append(set); |
|
269 | 269 | emit barsetsRemoved(sets); |
|
270 | 270 | emit countChanged(); |
|
271 | 271 | } |
|
272 | 272 | return success; |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
277 | 277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
278 | 278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
279 | 279 | and function returns false. |
|
280 | 280 | */ |
|
281 | 281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
282 | 282 | { |
|
283 | 283 | Q_D(QAbstractBarSeries); |
|
284 | 284 | bool success = d->append(sets); |
|
285 | 285 | if (success) { |
|
286 | 286 | emit barsetsAdded(sets); |
|
287 | 287 | emit countChanged(); |
|
288 | 288 | } |
|
289 | 289 | return success; |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | /*! |
|
293 | 293 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
294 | 294 | Returns true, if inserting succeeded. |
|
295 | 295 | |
|
296 | 296 | */ |
|
297 | 297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
298 | 298 | { |
|
299 | 299 | Q_D(QAbstractBarSeries); |
|
300 | 300 | bool success = d->insert(index, set); |
|
301 | 301 | if (success) { |
|
302 | 302 | QList<QBarSet*> sets; |
|
303 | 303 | sets.append(set); |
|
304 | 304 | emit barsetsAdded(sets); |
|
305 | 305 | emit countChanged(); |
|
306 | 306 | } |
|
307 | 307 | return success; |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | /*! |
|
311 | 311 | Removes all of the bar sets from the series |
|
312 | 312 | */ |
|
313 | 313 | void QAbstractBarSeries::clear() |
|
314 | 314 | { |
|
315 | 315 | Q_D(QAbstractBarSeries); |
|
316 | 316 | QList<QBarSet *> sets = barSets(); |
|
317 | 317 | bool success = d->remove(sets); |
|
318 | 318 | if (success) { |
|
319 | 319 | emit barsetsRemoved(sets); |
|
320 | 320 | emit countChanged(); |
|
321 | 321 | } |
|
322 | 322 | } |
|
323 | 323 | |
|
324 | 324 | /*! |
|
325 | 325 | Returns number of sets in series. |
|
326 | 326 | */ |
|
327 | 327 | int QAbstractBarSeries::count() const |
|
328 | 328 | { |
|
329 | 329 | Q_D(const QAbstractBarSeries); |
|
330 | 330 | return d->m_barSets.count(); |
|
331 | 331 | } |
|
332 | 332 | |
|
333 | 333 | /*! |
|
334 | 334 | Returns a list of sets in series. Keeps ownership of sets. |
|
335 | 335 | */ |
|
336 | 336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
337 | 337 | { |
|
338 | 338 | Q_D(const QAbstractBarSeries); |
|
339 | 339 | return d->m_barSets; |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | /*! |
|
343 | 343 | Sets the visibility of labels in series to \a visible |
|
344 | 344 | */ |
|
345 | 345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
346 | 346 | { |
|
347 | 347 | Q_D(QAbstractBarSeries); |
|
348 | 348 | if (d->m_labelsVisible != visible) { |
|
349 | 349 | d->setLabelsVisible(visible); |
|
350 | 350 | emit labelsVisibleChanged(); |
|
351 | 351 | } |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | /*! |
|
355 | 355 | Returns the visibility of labels |
|
356 | 356 | */ |
|
357 | 357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
358 | 358 | { |
|
359 | 359 | Q_D(const QAbstractBarSeries); |
|
360 | 360 | return d->m_labelsVisible; |
|
361 | 361 | } |
|
362 | 362 | |
|
363 | 363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
364 | 364 | |
|
365 | 365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
366 | 366 | QAbstractSeriesPrivate(q), |
|
367 | 367 | m_barWidth(0.5), // Default value is 50% of category width |
|
368 | 368 | m_labelsVisible(false), |
|
369 | 369 | m_visible(true) |
|
370 | 370 | { |
|
371 | 371 | } |
|
372 | 372 | |
|
373 | 373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
374 | 374 | { |
|
375 | 375 | // No categories defined. return count of longest set. |
|
376 | 376 | int count = 0; |
|
377 | 377 | for (int i=0; i<m_barSets.count(); i++) { |
|
378 | 378 | if (m_barSets.at(i)->count() > count) { |
|
379 | 379 | count = m_barSets.at(i)->count(); |
|
380 | 380 | } |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | return count; |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
387 | 387 | { |
|
388 | 388 | if (width < 0.0) { |
|
389 | 389 | width = 0.0; |
|
390 | 390 | } |
|
391 | 391 | m_barWidth = width; |
|
392 | 392 | emit updatedBars(); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
396 | 396 | { |
|
397 | 397 | return m_barWidth; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
401 | 401 | { |
|
402 | 402 | return m_barSets.at(index); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
406 | 406 | { |
|
407 | 407 | m_visible = visible; |
|
408 | 408 | emit updatedBars(); |
|
409 | 409 | } |
|
410 | 410 | |
|
411 | 411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
412 | 412 | { |
|
413 | 413 | m_labelsVisible = visible; |
|
414 | 414 | emit labelsVisibleChanged(visible); |
|
415 | 415 | } |
|
416 | 416 | |
|
417 | 417 | qreal QAbstractBarSeriesPrivate::min() |
|
418 | 418 | { |
|
419 | 419 | if (m_barSets.count() <= 0) { |
|
420 | 420 | return 0; |
|
421 | 421 | } |
|
422 | 422 | qreal min = INT_MAX; |
|
423 | 423 | |
|
424 | 424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
425 | 425 | int categoryCount = m_barSets.at(i)->count(); |
|
426 | 426 | for (int j = 0; j < categoryCount; j++) { |
|
427 | 427 | qreal temp = m_barSets.at(i)->at(j); |
|
428 | 428 | if (temp < min) |
|
429 | 429 | min = temp; |
|
430 | 430 | } |
|
431 | 431 | } |
|
432 | 432 | return min; |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | qreal QAbstractBarSeriesPrivate::max() |
|
436 | 436 | { |
|
437 | 437 | if (m_barSets.count() <= 0) { |
|
438 | 438 | return 0; |
|
439 | 439 | } |
|
440 | 440 | qreal max = INT_MIN; |
|
441 | 441 | |
|
442 | 442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
443 | 443 | int categoryCount = m_barSets.at(i)->count(); |
|
444 | 444 | for (int j = 0; j < categoryCount; j++) { |
|
445 | 445 | qreal temp = m_barSets.at(i)->at(j); |
|
446 | 446 | if (temp > max) |
|
447 | 447 | max = temp; |
|
448 | 448 | } |
|
449 | 449 | } |
|
450 | 450 | |
|
451 | 451 | return max; |
|
452 | 452 | } |
|
453 | 453 | |
|
454 | 454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
455 | 455 | { |
|
456 | 456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
457 | 457 | // No set, no value. |
|
458 | 458 | return 0; |
|
459 | 459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
460 | 460 | // No category, no value. |
|
461 | 461 | return 0; |
|
462 | 462 | } |
|
463 | 463 | |
|
464 | 464 | return m_barSets.at(set)->at(category); |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
468 | 468 | { |
|
469 | 469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
470 | 470 | // No set, no value. |
|
471 | 471 | return 0; |
|
472 | 472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
473 | 473 | // No category, no value. |
|
474 | 474 | return 0; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | qreal value = m_barSets.at(set)->at(category); |
|
478 | 478 | qreal sum = categorySum(category); |
|
479 | 479 | if ( qFuzzyIsNull(sum) ) { |
|
480 | 480 | return 0; |
|
481 | 481 | } |
|
482 | 482 | |
|
483 | 483 | return value / sum; |
|
484 | 484 | } |
|
485 | 485 | |
|
486 | 486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
487 | 487 | { |
|
488 | 488 | qreal sum(0); |
|
489 | 489 | int count = m_barSets.count(); // Count sets |
|
490 | 490 | for (int set = 0; set < count; set++) { |
|
491 | 491 | if (category < m_barSets.at(set)->count()) |
|
492 | 492 | sum += m_barSets.at(set)->at(category); |
|
493 | 493 | } |
|
494 | 494 | return sum; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
498 | 498 | { |
|
499 | 499 | qreal sum(0); |
|
500 | 500 | int count = m_barSets.count(); // Count sets |
|
501 | 501 | for (int set = 0; set < count; set++) { |
|
502 | 502 | if (category < m_barSets.at(set)->count()) |
|
503 | 503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
504 | 504 | } |
|
505 | 505 | return sum; |
|
506 | 506 | } |
|
507 | 507 | |
|
508 | 508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
509 | 509 | { |
|
510 | 510 | qreal max = INT_MIN; |
|
511 | 511 | int count = categoryCount(); |
|
512 | 512 | for (int i = 0; i < count; i++) { |
|
513 | 513 | qreal sum = categorySum(i); |
|
514 | 514 | if (sum > max) |
|
515 | 515 | max = sum; |
|
516 | 516 | } |
|
517 | 517 | return max; |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | qreal QAbstractBarSeriesPrivate::minX() |
|
521 | 521 | { |
|
522 | 522 | if (m_barSets.count() <= 0) { |
|
523 | 523 | return 0; |
|
524 | 524 | } |
|
525 | 525 | qreal min = INT_MAX; |
|
526 | 526 | |
|
527 | 527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
528 | 528 | int categoryCount = m_barSets.at(i)->count(); |
|
529 | 529 | for (int j = 0; j < categoryCount; j++) { |
|
530 | 530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
531 | 531 | if (temp < min) |
|
532 | 532 | min = temp; |
|
533 | 533 | } |
|
534 | 534 | } |
|
535 | 535 | return min; |
|
536 | 536 | } |
|
537 | 537 | |
|
538 | 538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
539 | 539 | { |
|
540 | 540 | if (m_barSets.count() <= 0) { |
|
541 | 541 | return 0; |
|
542 | 542 | } |
|
543 | 543 | qreal max = INT_MIN; |
|
544 | 544 | |
|
545 | 545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
546 | 546 | int categoryCount = m_barSets.at(i)->count(); |
|
547 | 547 | for (int j = 0; j < categoryCount; j++) { |
|
548 | 548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
549 | 549 | if (temp > max) |
|
550 | 550 | max = temp; |
|
551 | 551 | } |
|
552 | 552 | } |
|
553 | 553 | |
|
554 | 554 | return max; |
|
555 | 555 | } |
|
556 | 556 | |
|
557 | 557 | |
|
558 | 558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
559 | 559 | { |
|
560 | 560 | qreal minX(domain.minX()); |
|
561 | 561 | qreal minY(domain.minY()); |
|
562 | 562 | qreal maxX(domain.maxX()); |
|
563 | 563 | qreal maxY(domain.maxY()); |
|
564 | 564 | int tickXCount(domain.tickXCount()); |
|
565 | 565 | int tickYCount(domain.tickYCount()); |
|
566 | 566 | |
|
567 | 567 | qreal seriesMinX = this->minX(); |
|
568 | 568 | qreal seriesMaxX = this->maxX(); |
|
569 | 569 | qreal y = max(); |
|
570 | 570 | minX = qMin(minX, seriesMinX - 0.5); |
|
571 | 571 | minY = qMin(minY, y); |
|
572 | 572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
573 | 573 | maxY = qMax(maxY, y); |
|
574 | 574 | tickXCount = categoryCount()+1; |
|
575 | 575 | |
|
576 | 576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
580 | 580 | { |
|
581 | 581 | Q_Q(QAbstractBarSeries); |
|
582 | 582 | |
|
583 | 583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
584 | 584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
585 | 585 | presenter->animator()->addAnimation(bar); |
|
586 | 586 | } |
|
587 | 587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
588 | 588 | return bar; |
|
589 | 589 | |
|
590 | 590 | } |
|
591 | 591 | |
|
592 | 592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
593 | 593 | { |
|
594 | 594 | Q_Q(QAbstractBarSeries); |
|
595 | 595 | QList<LegendMarker*> markers; |
|
596 | 596 | foreach(QBarSet* set, q->barSets()) { |
|
597 | 597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
598 | 598 | markers << marker; |
|
599 | 599 | } |
|
600 | 600 | |
|
601 | 601 | return markers; |
|
602 | 602 | } |
|
603 | 603 | |
|
604 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent) | |
|
605 | { | |
|
606 | return new QCategoriesAxis(parent); | |
|
607 | } | |
|
608 | ||
|
609 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent) | |
|
610 | { | |
|
611 | return new QValuesAxis(parent); | |
|
612 | } | |
|
613 | ||
|
614 | 604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
615 | 605 | { |
|
616 | 606 | Q_Q(QAbstractBarSeries); |
|
617 | 607 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
618 | 608 | // Fail if set is already in list or set is null. |
|
619 | 609 | return false; |
|
620 | 610 | } |
|
621 | 611 | m_barSets.append(set); |
|
622 | 612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
623 | 613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
624 | 614 | emit restructuredBars(); // this notifies barchartitem |
|
625 | 615 | if (m_dataset) { |
|
626 | 616 | m_dataset->updateSeries(q); // this notifies legend |
|
627 | 617 | } |
|
628 | 618 | return true; |
|
629 | 619 | } |
|
630 | 620 | |
|
631 | 621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
632 | 622 | { |
|
633 | 623 | Q_Q(QAbstractBarSeries); |
|
634 | 624 | if (!m_barSets.contains(set)) { |
|
635 | 625 | // Fail if set is not in list |
|
636 | 626 | return false; |
|
637 | 627 | } |
|
638 | 628 | m_barSets.removeOne(set); |
|
639 | 629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
640 | 630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
641 | 631 | emit restructuredBars(); // this notifies barchartitem |
|
642 | 632 | if (m_dataset) { |
|
643 | 633 | m_dataset->updateSeries(q); // this notifies legend |
|
644 | 634 | } |
|
645 | 635 | return true; |
|
646 | 636 | } |
|
647 | 637 | |
|
648 | 638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
649 | 639 | { |
|
650 | 640 | Q_Q(QAbstractBarSeries); |
|
651 | 641 | foreach (QBarSet* set, sets) { |
|
652 | 642 | if ((set == 0) || (m_barSets.contains(set))) { |
|
653 | 643 | // Fail if any of the sets is null or is already appended. |
|
654 | 644 | return false; |
|
655 | 645 | } |
|
656 | 646 | if (sets.count(set) != 1) { |
|
657 | 647 | // Also fail if same set is more than once in given list. |
|
658 | 648 | return false; |
|
659 | 649 | } |
|
660 | 650 | } |
|
661 | 651 | |
|
662 | 652 | foreach (QBarSet* set, sets) { |
|
663 | 653 | m_barSets.append(set); |
|
664 | 654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
665 | 655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
666 | 656 | } |
|
667 | 657 | emit restructuredBars(); // this notifies barchartitem |
|
668 | 658 | if (m_dataset) { |
|
669 | 659 | m_dataset->updateSeries(q); // this notifies legend |
|
670 | 660 | } |
|
671 | 661 | return true; |
|
672 | 662 | } |
|
673 | 663 | |
|
674 | 664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
675 | 665 | { |
|
676 | 666 | Q_Q(QAbstractBarSeries); |
|
677 | 667 | if (sets.count() == 0) { |
|
678 | 668 | return false; |
|
679 | 669 | } |
|
680 | 670 | foreach (QBarSet* set, sets) { |
|
681 | 671 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
682 | 672 | // Fail if any of the sets is null or is not in series |
|
683 | 673 | return false; |
|
684 | 674 | } |
|
685 | 675 | if (sets.count(set) != 1) { |
|
686 | 676 | // Also fail if same set is more than once in given list. |
|
687 | 677 | return false; |
|
688 | 678 | } |
|
689 | 679 | } |
|
690 | 680 | |
|
691 | 681 | foreach (QBarSet* set, sets) { |
|
692 | 682 | m_barSets.removeOne(set); |
|
693 | 683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
694 | 684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
695 | 685 | } |
|
696 | 686 | |
|
697 | 687 | emit restructuredBars(); // this notifies barchartitem |
|
698 | 688 | if (m_dataset) { |
|
699 | 689 | m_dataset->updateSeries(q); // this notifies legend |
|
700 | 690 | } |
|
701 | 691 | return true; |
|
702 | 692 | } |
|
703 | 693 | |
|
704 | 694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
705 | 695 | { |
|
706 | 696 | Q_Q(QAbstractBarSeries); |
|
707 | 697 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
708 | 698 | // Fail if set is already in list or set is null. |
|
709 | 699 | return false; |
|
710 | 700 | } |
|
711 | 701 | m_barSets.insert(index, set); |
|
712 | 702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
713 | 703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
714 | 704 | emit restructuredBars(); // this notifies barchartitem |
|
715 | 705 | if (m_dataset) { |
|
716 | 706 | m_dataset->updateSeries(q); // this notifies legend |
|
717 | 707 | } |
|
718 | 708 | return true; |
|
719 | 709 | } |
|
720 | 710 | |
|
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
|
712 | { | |
|
713 | Q_UNUSED(axis); | |
|
714 | } | |
|
715 | ||
|
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
|
717 | { | |
|
718 | Q_UNUSED(axis) | |
|
719 | } | |
|
720 | ||
|
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const | |
|
722 | { | |
|
723 | return QAbstractAxis::AxisTypeCategories; | |
|
724 | } | |
|
725 | ||
|
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const | |
|
727 | { | |
|
728 | return QAbstractAxis::AxisTypeValues; | |
|
729 | } | |
|
730 | ||
|
721 | 731 | #include "moc_qabstractbarseries.cpp" |
|
722 | 732 | #include "moc_qabstractbarseries_p.cpp" |
|
723 | 733 | |
|
734 | ||
|
724 | 735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,99 | |||
|
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 QABSTRACTBARSERIES_P_H |
|
31 | 31 | #define QABSTRACTBARSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractbarseries.h" |
|
34 | 34 | #include "qabstractseries_p.h" |
|
35 | 35 | #include <QStringList> |
|
36 | 36 | #include <QAbstractSeries> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QBarModelMapper; |
|
41 | 41 | |
|
42 | 42 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | public: |
|
46 | 46 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); |
|
47 | 47 | int categoryCount() const; |
|
48 | 48 | |
|
49 | 49 | void setBarWidth(qreal width); |
|
50 | 50 | qreal barWidth() const; |
|
51 | 51 | |
|
52 | 52 | void setVisible(bool visible); |
|
53 | 53 | void setLabelsVisible(bool visible); |
|
54 | 54 | |
|
55 | 55 | void scaleDomain(Domain& domain); |
|
56 | 56 | Chart* createGraphics(ChartPresenter* presenter); |
|
57 | 57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
58 | 58 | |
|
59 | QAbstractAxis* createAxisX(QObject* parent = 0); | |
|
60 | QAbstractAxis* createAxisY(QObject* parent = 0); | |
|
59 | void initializeAxisX(QAbstractAxis* axis); | |
|
60 | void initializeAxisY(QAbstractAxis* axis); | |
|
61 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
62 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
61 | 63 | |
|
62 | 64 | bool append(QBarSet *set); |
|
63 | 65 | bool remove(QBarSet *set); |
|
64 | 66 | bool append(QList<QBarSet* > sets); |
|
65 | 67 | bool remove(QList<QBarSet* > sets); |
|
66 | 68 | bool insert(int index, QBarSet *set); |
|
67 | 69 | |
|
68 | 70 | QBarSet* barsetAt(int index); |
|
69 | 71 | qreal min(); |
|
70 | 72 | qreal max(); |
|
71 | 73 | qreal valueAt(int set, int category); |
|
72 | 74 | qreal percentageAt(int set, int category); |
|
73 | 75 | qreal categorySum(int category); |
|
74 | 76 | qreal absoluteCategorySum(int category); |
|
75 | 77 | qreal maxCategorySum(); |
|
76 | 78 | qreal minX(); |
|
77 | 79 | qreal maxX(); |
|
78 | 80 | |
|
79 | 81 | Q_SIGNALS: |
|
80 | 82 | void clicked(int index, QBarSet *barset); |
|
81 | 83 | void updatedBars(); |
|
82 | 84 | void restructuredBars(); |
|
83 | 85 | void labelsVisibleChanged(bool visible); |
|
84 | 86 | |
|
85 | 87 | protected: |
|
86 | 88 | QList<QBarSet *> m_barSets; |
|
87 | 89 | qreal m_barWidth; |
|
88 | 90 | bool m_labelsVisible; |
|
89 | 91 | bool m_visible; |
|
90 | 92 | |
|
91 | 93 | private: |
|
92 | 94 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
93 | 95 | }; |
|
94 | 96 | |
|
95 | 97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
96 | 98 | |
|
97 | 99 | #endif // QABSTRACTBARSERIES_P_H |
@@ -1,117 +1,117 | |||
|
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 | #include "qcategoriesaxis.h" |
|
28 | 28 | #include "qvaluesaxis.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \class QPercentBarSeries |
|
34 | 34 | \brief Series for creating percent bar chart |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
38 | 38 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
39 | 39 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
40 | 40 | |
|
41 | 41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
42 | 42 | \image examples_percentbarchart.png |
|
43 | 43 | |
|
44 | 44 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
45 | 45 | */ |
|
46 | 46 | /*! |
|
47 | 47 | \qmlclass PercentBarSeries QPercentBarSeries |
|
48 | \inherits BarSeries | |
|
48 | \inherits QAbstractBarSeries | |
|
49 | 49 | |
|
50 | 50 | The following QML shows how to create a simple percent bar chart: |
|
51 | 51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 |
|
52 | 52 | \beginfloatleft |
|
53 | 53 | \image demos_qmlchart9.png |
|
54 | 54 | \endfloat |
|
55 | 55 | \clearfloat |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | Constructs empty QPercentBarSeries. |
|
60 | 60 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
61 | 61 | */ |
|
62 | 62 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
63 | 63 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
64 | 64 | { |
|
65 | 65 | } |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | Returns QChartSeries::SeriesTypePercentBar. |
|
69 | 69 | */ |
|
70 | 70 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
71 | 71 | { |
|
72 | 72 | return QAbstractSeries::SeriesTypePercentBar; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | 76 | |
|
77 | 77 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | 83 | { |
|
84 | 84 | qreal minX(domain.minX()); |
|
85 | 85 | qreal minY(domain.minY()); |
|
86 | 86 | qreal maxX(domain.maxX()); |
|
87 | 87 | qreal maxY(domain.maxY()); |
|
88 | 88 | int tickXCount(domain.tickXCount()); |
|
89 | 89 | int tickYCount(domain.tickYCount()); |
|
90 | 90 | |
|
91 | 91 | qreal x = categoryCount(); |
|
92 | 92 | minX = qMin(minX, -0.5); |
|
93 | 93 | maxX = qMax(maxX, x - 0.5); |
|
94 | 94 | minY = 0; |
|
95 | 95 | maxY = 100; |
|
96 | 96 | tickXCount = x+1; |
|
97 | 97 | |
|
98 | 98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | 99 | } |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | 103 | { |
|
104 | 104 | Q_Q(QPercentBarSeries); |
|
105 | 105 | |
|
106 | 106 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
107 | 107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | 108 | presenter->animator()->addAnimation(bar); |
|
109 | 109 | } |
|
110 | 110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | 111 | return bar; |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | #include "moc_qpercentbarseries.cpp" |
|
115 | 115 | |
|
116 | 116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | 117 |
@@ -1,339 +1,417 | |||
|
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 "chartdataset_p.h" |
|
22 | 22 | #include "qchart.h" |
|
23 | 23 | #include "qvaluesaxis.h" |
|
24 | #include "qcategoriesaxis.h" | |
|
24 | 25 | #include "qvaluesaxis_p.h" |
|
25 | 26 | #include "qabstractseries_p.h" |
|
26 | 27 | #include "qabstractbarseries.h" |
|
27 | 28 | #include "qstackedbarseries.h" |
|
28 | 29 | #include "qpercentbarseries.h" |
|
29 | 30 | #include "qpieseries.h" |
|
30 | 31 | |
|
31 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 33 | |
|
33 | 34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
34 | 35 | m_domainIndex(0) |
|
35 | 36 | { |
|
36 | 37 | |
|
37 | 38 | } |
|
38 | 39 | |
|
39 | 40 | ChartDataSet::~ChartDataSet() |
|
40 | 41 | { |
|
41 | 42 | removeAllSeries(); |
|
42 | 43 | } |
|
43 | 44 | |
|
44 | 45 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
45 | 46 | { |
|
46 | 47 | Domain* domain = m_seriesDomainMap.value(series); |
|
47 | 48 | |
|
48 | 49 | if(domain) { |
|
49 | 50 | qWarning() << "Can not add series. Series already on the chart"; |
|
50 | 51 | return; |
|
51 | 52 | } |
|
52 | 53 | |
|
53 | 54 | series->setParent(this); // take ownership |
|
54 | 55 | |
|
55 | 56 | domain = new Domain(series); |
|
56 | 57 | |
|
57 | 58 | m_seriesDomainMap.insert(series,domain); |
|
58 | 59 | |
|
59 | 60 | series->d_ptr->scaleDomain(*domain); |
|
60 | 61 | |
|
61 | 62 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
62 | 63 | |
|
63 | 64 | int key=0; |
|
64 | 65 | while (i.hasNext()) { |
|
65 | 66 | i.next(); |
|
66 | 67 | if(i.key()!=key) { |
|
67 | 68 | break; |
|
68 | 69 | } |
|
69 | 70 | key++; |
|
70 | 71 | } |
|
71 | 72 | |
|
72 | 73 | m_indexSeriesMap.insert(key,series); |
|
73 | 74 | |
|
74 | 75 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
75 | 76 | series->d_ptr->m_dataset = this; |
|
76 | 77 | |
|
77 | 78 | emit seriesAdded(series,domain); |
|
78 | 79 | |
|
79 | 80 | } |
|
80 | 81 | |
|
81 | 82 | void ChartDataSet::createDefaultAxes() |
|
82 | 83 | { |
|
83 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
|
84 | 84 | |
|
85 | if(m_seriesDomainMap.isEmpty()) return; | |
|
86 | ||
|
87 | QAbstractAxis::AxisTypes typeX(0); | |
|
88 | QAbstractAxis::AxisTypes typeY(0); | |
|
89 | ||
|
90 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
|
85 | 91 | while (i.hasNext()) { |
|
86 | i.next(); | |
|
92 | i.next(); | |
|
93 | removeAxes(i.key()); | |
|
94 | } | |
|
87 | 95 | |
|
88 | if(!m_seriesAxisXMap.value(i.key())) | |
|
89 | { | |
|
96 | i.toFront(); | |
|
90 | 97 | |
|
91 | QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this); | |
|
98 | while (i.hasNext()) { | |
|
99 | i.next(); | |
|
100 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
|
101 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
|
102 | if(axisX) typeX&=axisX->type(); | |
|
103 | else typeX|=i.key()->d_ptr->defaultAxisXType(); | |
|
104 | if(axisY) typeY&=axisY->type(); | |
|
105 | else typeY|=i.key()->d_ptr->defaultAxisYType(); | |
|
106 | } | |
|
92 | 107 | |
|
93 | if(axisX) { | |
|
94 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
|
95 | QObject::connect(i.value(),SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
|
96 | axisX->d_ptr->m_orientation=Qt::Horizontal; | |
|
97 | emit axisAdded(axisX,i.value()); | |
|
98 | m_seriesAxisXMap.insert(i.key(),axisX); | |
|
99 | } | |
|
100 | 108 | |
|
109 | if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories)) | |
|
110 | { | |
|
111 | i.toFront(); | |
|
112 | while (i.hasNext()) { | |
|
113 | i.next(); | |
|
114 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType()); | |
|
115 | i.key()->d_ptr->initializeAxisX(axis); | |
|
116 | addAxisX(axis,i.key()); | |
|
117 | emit axisAdded(axis,i.value()); | |
|
101 | 118 | } |
|
102 | 119 | |
|
103 | if(!m_seriesAxisYMap.value(i.key())) | |
|
104 | { | |
|
105 | QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this); | |
|
106 | ||
|
107 | if(axisY) { | |
|
108 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
|
109 | QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
|
110 | axisY->d_ptr->m_orientation=Qt::Vertical; | |
|
111 |
|
|
|
112 | m_seriesAxisYMap.insert(i.key(),axisY); | |
|
113 | } | |
|
120 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |
|
121 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX))); | |
|
122 | i.toFront(); | |
|
123 | while (i.hasNext()) { | |
|
124 | i.next(); | |
|
125 | i.key()->d_ptr->initializeAxisX(axis); | |
|
126 | addAxisX(axis,i.key()); | |
|
127 | } | |
|
128 | emit axisAdded(axis,i.value()); | |
|
129 | ||
|
130 | } | |
|
131 | ||
|
132 | if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories)) | |
|
133 | { | |
|
134 | i.toFront(); | |
|
135 | while (i.hasNext()) { | |
|
136 | i.next(); | |
|
137 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType()); | |
|
138 | i.key()->d_ptr->initializeAxisY(axis); | |
|
139 | addAxisY(axis,i.key()); | |
|
140 | emit axisAdded(axis,i.value()); | |
|
114 | 141 | } |
|
142 | ||
|
143 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |
|
144 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY))); | |
|
145 | i.toFront(); | |
|
146 | while (i.hasNext()) { | |
|
147 | i.next(); | |
|
148 | i.key()->d_ptr->initializeAxisY(axis); | |
|
149 | addAxisY(axis,i.key()); | |
|
150 | } | |
|
151 | emit axisAdded(axis,i.value()); | |
|
152 | ||
|
115 | 153 | } |
|
116 | 154 | } |
|
117 | 155 | |
|
118 | 156 | |
|
157 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type) | |
|
158 | { | |
|
159 | QAbstractAxis* axis =0; | |
|
160 | ||
|
161 | switch(type) { | |
|
162 | case QAbstractAxis::AxisTypeValues: | |
|
163 | axis = new QValuesAxis(this); | |
|
164 | break; | |
|
165 | case QAbstractAxis::AxisTypeCategories: | |
|
166 | axis = new QCategoriesAxis(this); | |
|
167 | break; | |
|
168 | default: | |
|
169 | axis = 0; | |
|
170 | break; | |
|
171 | } | |
|
172 | ||
|
173 | return axis; | |
|
174 | } | |
|
175 | ||
|
176 | void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) { | |
|
177 | Domain* domain = m_seriesDomainMap.value(series); | |
|
178 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
|
179 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
|
180 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
|
181 | m_seriesAxisXMap.insert(series,axis); | |
|
182 | } | |
|
183 | ||
|
184 | void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) { | |
|
185 | Domain* domain = m_seriesDomainMap.value(series); | |
|
186 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
|
187 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
|
188 | axis->d_ptr->m_orientation=Qt::Vertical; | |
|
189 | m_seriesAxisYMap.insert(series,axis); | |
|
190 | } | |
|
191 | ||
|
119 | 192 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
120 | 193 | { |
|
121 | 194 | Domain* domain = m_seriesDomainMap.take(series); |
|
122 | 195 | |
|
123 | 196 | if(!domain) { |
|
124 | 197 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
125 | 198 | } |
|
126 | 199 | |
|
127 | 200 | emit seriesRemoved(series); |
|
128 | 201 | |
|
129 | 202 | delete domain; |
|
130 | 203 | domain = 0; |
|
131 | 204 | |
|
132 | 205 | int key = seriesIndex(series); |
|
133 | 206 | Q_ASSERT(key!=-1); |
|
134 | 207 | |
|
135 | 208 | m_indexSeriesMap.remove(key); |
|
136 | 209 | |
|
137 | 210 | series->setParent(0); |
|
138 | 211 | series->d_ptr->m_chart = 0; |
|
139 | 212 | series->d_ptr->m_dataset = 0; |
|
140 | 213 | |
|
214 | removeAxes(series); | |
|
215 | } | |
|
216 | ||
|
217 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
|
218 | { | |
|
141 | 219 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
142 | 220 | |
|
143 | 221 | if(axisX) { |
|
144 | 222 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
145 | 223 | int x = axesX.indexOf(axisX); |
|
146 | 224 | |
|
147 | 225 | if(x==-1) { |
|
148 | 226 | emit axisRemoved(axisX); |
|
149 | 227 | axisX->deleteLater(); |
|
150 | 228 | } |
|
151 | 229 | } |
|
152 | 230 | |
|
153 | 231 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
154 | 232 | |
|
155 | 233 | if(axisY) { |
|
156 | 234 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
157 | 235 | |
|
158 | 236 | int y = axesY.indexOf(axisY); |
|
159 | 237 | |
|
160 | 238 | if(y==-1) { |
|
161 | 239 | emit axisRemoved(axisY); |
|
162 | 240 | axisY->deleteLater(); |
|
163 | 241 | } |
|
164 | 242 | } |
|
165 | 243 | } |
|
166 | 244 | |
|
167 | 245 | void ChartDataSet::removeAllSeries() |
|
168 | 246 | { |
|
169 | 247 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
170 | 248 | foreach(QAbstractSeries *s , series) { |
|
171 | 249 | removeSeries(s); |
|
172 | 250 | } |
|
173 | 251 | |
|
174 | 252 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
175 | 253 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
176 | 254 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
177 | 255 | |
|
178 | 256 | qDeleteAll(series); |
|
179 | 257 | } |
|
180 | 258 | |
|
181 | 259 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
182 | 260 | { |
|
183 | 261 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
184 | 262 | while (i.hasNext()) { |
|
185 | 263 | i.next(); |
|
186 | 264 | i.value()->zoomIn(rect,size); |
|
187 | 265 | } |
|
188 | 266 | } |
|
189 | 267 | |
|
190 | 268 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
191 | 269 | { |
|
192 | 270 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
193 | 271 | while (i.hasNext()) { |
|
194 | 272 | i.next(); |
|
195 | 273 | i.value()->zoomOut(rect,size); |
|
196 | 274 | } |
|
197 | 275 | } |
|
198 | 276 | |
|
199 | 277 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
200 | 278 | { |
|
201 | 279 | int count=0; |
|
202 | 280 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
203 | 281 | while (i.hasNext()) { |
|
204 | 282 | i.next(); |
|
205 | 283 | if(i.key()->type()==type) count++; |
|
206 | 284 | } |
|
207 | 285 | return count; |
|
208 | 286 | } |
|
209 | 287 | |
|
210 | 288 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
211 | 289 | { |
|
212 | 290 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
213 | 291 | while (i.hasNext()) { |
|
214 | 292 | i.next(); |
|
215 | 293 | if (i.value() == series) |
|
216 | 294 | return i.key(); |
|
217 | 295 | } |
|
218 | 296 | return -1; |
|
219 | 297 | } |
|
220 | 298 | |
|
221 | 299 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
222 | 300 | { |
|
223 | 301 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
224 | 302 | return m_seriesAxisXMap.value(series); |
|
225 | 303 | } |
|
226 | 304 | |
|
227 | 305 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
228 | 306 | { |
|
229 | 307 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
230 | 308 | return m_seriesAxisYMap.value(series); |
|
231 | 309 | } |
|
232 | 310 | |
|
233 | 311 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
234 | 312 | { |
|
235 | 313 | Q_ASSERT(axis); |
|
236 | 314 | Domain* domain = m_seriesDomainMap.value(series); |
|
237 | 315 | |
|
238 | 316 | if(!domain) { |
|
239 | 317 | qWarning() << "Series not found on the chart."; |
|
240 | 318 | return; |
|
241 | 319 | } |
|
242 | 320 | |
|
243 | 321 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
244 | 322 | qWarning()<<"Axis already defined as axis Y"; |
|
245 | 323 | return; |
|
246 | 324 | } |
|
247 | 325 | |
|
248 | 326 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
249 | 327 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
250 | 328 | |
|
251 | 329 | if(oldAxis) { |
|
252 | 330 | |
|
253 | 331 | int x = axesX.indexOf(oldAxis); |
|
254 | 332 | if(x==-1) { |
|
255 | 333 | emit axisRemoved(oldAxis); |
|
256 | 334 | oldAxis->deleteLater(); |
|
257 | 335 | } |
|
258 | 336 | } |
|
259 | 337 | |
|
260 | 338 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
261 | 339 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
262 | 340 | |
|
263 | 341 | int x = axesX.indexOf(axis); |
|
264 | 342 | if(x==-1) { |
|
265 | 343 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
266 | 344 | emit axisAdded(axis,domain); |
|
267 | 345 | } |
|
268 | 346 | |
|
269 | 347 | m_seriesAxisXMap.insert(series,axis); |
|
270 | 348 | |
|
271 | 349 | // Force range update |
|
272 | 350 | axis->d_ptr->updateRange(); |
|
273 | 351 | } |
|
274 | 352 | |
|
275 | 353 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
276 | 354 | { |
|
277 | 355 | Q_ASSERT(axis); |
|
278 | 356 | Domain* domain = m_seriesDomainMap.value(series); |
|
279 | 357 | |
|
280 | 358 | if(!domain) { |
|
281 | 359 | qWarning() << "Series not found on the chart."; |
|
282 | 360 | return; |
|
283 | 361 | } |
|
284 | 362 | |
|
285 | 363 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
286 | 364 | qWarning()<<"Axis already defined as axis X"; |
|
287 | 365 | return; |
|
288 | 366 | } |
|
289 | 367 | |
|
290 | 368 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
291 | 369 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
292 | 370 | |
|
293 | 371 | if(oldAxis) { |
|
294 | 372 | int y = axesY.indexOf(oldAxis); |
|
295 | 373 | if(y==-1) { |
|
296 | 374 | emit axisRemoved(oldAxis); |
|
297 | 375 | oldAxis->deleteLater(); |
|
298 | 376 | } |
|
299 | 377 | } |
|
300 | 378 | |
|
301 | 379 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
302 | 380 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
303 | 381 | |
|
304 | 382 | int y = axesY.indexOf(axis); |
|
305 | 383 | if(y==-1) { |
|
306 | 384 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
307 | 385 | emit axisAdded(axis,domain); |
|
308 | 386 | } |
|
309 | 387 | |
|
310 | 388 | m_seriesAxisYMap.insert(series,axis); |
|
311 | 389 | } |
|
312 | 390 | |
|
313 | 391 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
314 | 392 | { |
|
315 | 393 | return m_seriesDomainMap.value(series); |
|
316 | 394 | } |
|
317 | 395 | |
|
318 | 396 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
319 | 397 | { |
|
320 | 398 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
321 | 399 | while (i.hasNext()) { |
|
322 | 400 | i.next(); |
|
323 | 401 | i.value()->move(dx,dy,size); |
|
324 | 402 | } |
|
325 | 403 | } |
|
326 | 404 | |
|
327 | 405 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
328 | 406 | { |
|
329 | 407 | return m_seriesAxisXMap.keys(); |
|
330 | 408 | } |
|
331 | 409 | |
|
332 | 410 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
333 | 411 | { |
|
334 | 412 | emit seriesUpdated(series); |
|
335 | 413 | } |
|
336 | 414 | |
|
337 | 415 | #include "moc_chartdataset_p.cpp" |
|
338 | 416 | |
|
339 | 417 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +1,97 | |||
|
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 CHARTDATASET_P_H |
|
31 | 31 | #define CHARTDATASET_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | #include "qabstractaxis_p.h" | |
|
35 | 36 | #include <QVector> |
|
36 | 37 | |
|
37 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 39 | |
|
39 | 40 | class QAbstractAxis; |
|
40 | 41 | |
|
41 | 42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
42 | 43 | { |
|
43 | 44 | Q_OBJECT |
|
44 | 45 | public: |
|
45 | 46 | ChartDataSet(QChart* parent=0); |
|
46 | 47 | virtual ~ChartDataSet(); |
|
47 | 48 | |
|
48 | 49 | void addSeries(QAbstractSeries* series); |
|
49 | 50 | void removeSeries(QAbstractSeries* series); |
|
50 | 51 | void removeAllSeries(); |
|
51 | 52 | void updateSeries(QAbstractSeries* series); |
|
52 | 53 | |
|
53 | 54 | void zoomInDomain(const QRectF& rect, const QSizeF& size); |
|
54 | 55 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
55 | 56 | void scrollDomain(qreal dx,qreal dy,const QSizeF& size); |
|
56 | 57 | |
|
57 | 58 | int seriesCount(QAbstractSeries::SeriesType type); |
|
58 | 59 | int seriesIndex(QAbstractSeries *series); |
|
59 | 60 | |
|
60 | 61 | QAbstractAxis* axisX(QAbstractSeries *series) const; |
|
61 | 62 | QAbstractAxis* axisY(QAbstractSeries *series) const; |
|
62 | 63 | |
|
63 | 64 | void setAxisX(QAbstractSeries *series, QAbstractAxis *axis); |
|
64 | 65 | void setAxisY(QAbstractSeries *series, QAbstractAxis *axis); |
|
65 | 66 | |
|
66 | 67 | QList<QAbstractSeries*> series() const; |
|
67 | 68 | Domain* domain(QAbstractSeries *series) const; |
|
68 | 69 | |
|
69 | 70 | void createDefaultAxes(); |
|
70 | 71 | |
|
71 | 72 | Q_SIGNALS: |
|
72 | 73 | void seriesAdded(QAbstractSeries* series, Domain* domain); |
|
73 | 74 | void seriesRemoved(QAbstractSeries* series); |
|
74 | 75 | void seriesUpdated(QAbstractSeries* series); |
|
75 | 76 | void axisAdded(QAbstractAxis* axis,Domain* domain); |
|
76 | 77 | void axisRemoved(QAbstractAxis* axis); |
|
77 | 78 | |
|
78 | 79 | private: |
|
79 | QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max); | |
|
80 | 80 | void calculateDomain(QAbstractSeries* series,Domain* domain); |
|
81 | QAbstractAxis* createAxis(QAbstractAxis::AxisType type); | |
|
82 | void addAxisX(QAbstractAxis* axis,QAbstractSeries* series); | |
|
83 | void addAxisY(QAbstractAxis* axis,QAbstractSeries* series); | |
|
84 | void removeAxes(QAbstractSeries* series); | |
|
81 | 85 | |
|
82 | 86 | private: |
|
83 | 87 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap; |
|
84 | 88 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap; |
|
85 | 89 | QMap<QAbstractSeries*, Domain*> m_seriesDomainMap; |
|
86 | 90 | QMap<int, QAbstractSeries*> m_indexSeriesMap; |
|
87 | 91 | int m_domainIndex; |
|
88 | 92 | |
|
89 | 93 | }; |
|
90 | 94 | |
|
91 | 95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | 96 | |
|
93 | 97 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,773 +1,781 | |||
|
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 "qpieseries.h" |
|
22 | 22 | #include "qpieseries_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | 24 | #include "qpieslice_p.h" |
|
25 | 25 | #include "pieslicedata_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "chartanimator_p.h" |
|
29 | 29 | #include "legendmarker_p.h" |
|
30 | 30 | #include "qabstractaxis.h" |
|
31 | 31 | |
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | /*! |
|
35 | 35 | \class QPieSeries |
|
36 | 36 | \brief Pie series API for QtCommercial Charts |
|
37 | 37 | |
|
38 | 38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
39 | 39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
40 | 40 | The actual slice size is determined by that relative value. |
|
41 | 41 | |
|
42 | 42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
43 | 43 | These relate to the actual chart rectangle. |
|
44 | 44 | |
|
45 | 45 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
46 | 46 | This can be done by setting a starting angle and angle span to the series. |
|
47 | 47 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
48 | 48 | |
|
49 | 49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
50 | 50 | \image examples_piechart.png |
|
51 | 51 | */ |
|
52 | 52 | /*! |
|
53 | 53 | \qmlclass PieSeries QPieSeries |
|
54 | 54 | \inherits AbstractSeries |
|
55 | 55 | |
|
56 | 56 | The following QML shows how to create a simple pie chart. |
|
57 | 57 | |
|
58 | 58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
59 | 59 | |
|
60 | 60 | \beginfloatleft |
|
61 | 61 | \image demos_qmlchart1.png |
|
62 | 62 | \endfloat |
|
63 | 63 | \clearfloat |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \property QPieSeries::horizontalPosition |
|
68 | 68 | \brief Defines the horizontal position of the pie. |
|
69 | 69 | |
|
70 | 70 | The value is a relative value to the chart rectangle where: |
|
71 | 71 | |
|
72 | 72 | \list |
|
73 | 73 | \o 0.0 is the absolute left. |
|
74 | 74 | \o 1.0 is the absolute right. |
|
75 | 75 | \endlist |
|
76 | 76 | Default value is 0.5 (center). |
|
77 | 77 | \sa verticalPosition |
|
78 | 78 | */ |
|
79 | 79 | |
|
80 | 80 | /*! |
|
81 | 81 | \qmlproperty real PieSeries::horizontalPosition |
|
82 | 82 | |
|
83 | 83 | Defines the horizontal position of the pie. |
|
84 | 84 | |
|
85 | 85 | The value is a relative value to the chart rectangle where: |
|
86 | 86 | |
|
87 | 87 | \list |
|
88 | 88 | \o 0.0 is the absolute left. |
|
89 | 89 | \o 1.0 is the absolute right. |
|
90 | 90 | \endlist |
|
91 | 91 | Default value is 0.5 (center). |
|
92 | 92 | \sa verticalPosition |
|
93 | 93 | */ |
|
94 | 94 | |
|
95 | 95 | /*! |
|
96 | 96 | \property QPieSeries::verticalPosition |
|
97 | 97 | \brief Defines the vertical position of the pie. |
|
98 | 98 | |
|
99 | 99 | The value is a relative value to the chart rectangle where: |
|
100 | 100 | |
|
101 | 101 | \list |
|
102 | 102 | \o 0.0 is the absolute top. |
|
103 | 103 | \o 1.0 is the absolute bottom. |
|
104 | 104 | \endlist |
|
105 | 105 | Default value is 0.5 (center). |
|
106 | 106 | \sa horizontalPosition |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | 110 | \qmlproperty real PieSeries::verticalPosition |
|
111 | 111 | |
|
112 | 112 | Defines the vertical position of the pie. |
|
113 | 113 | |
|
114 | 114 | The value is a relative value to the chart rectangle where: |
|
115 | 115 | |
|
116 | 116 | \list |
|
117 | 117 | \o 0.0 is the absolute top. |
|
118 | 118 | \o 1.0 is the absolute bottom. |
|
119 | 119 | \endlist |
|
120 | 120 | Default value is 0.5 (center). |
|
121 | 121 | \sa horizontalPosition |
|
122 | 122 | */ |
|
123 | 123 | |
|
124 | 124 | /*! |
|
125 | 125 | \property QPieSeries::size |
|
126 | 126 | \brief Defines the pie size. |
|
127 | 127 | |
|
128 | 128 | The value is a relative value to the chart rectangle where: |
|
129 | 129 | |
|
130 | 130 | \list |
|
131 | 131 | \o 0.0 is the minimum size (pie not drawn). |
|
132 | 132 | \o 1.0 is the maximum size that can fit the chart. |
|
133 | 133 | \endlist |
|
134 | 134 | |
|
135 | 135 | Default value is 0.7. |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \qmlproperty real PieSeries::size |
|
140 | 140 | |
|
141 | 141 | Defines the pie size. |
|
142 | 142 | |
|
143 | 143 | The value is a relative value to the chart rectangle where: |
|
144 | 144 | |
|
145 | 145 | \list |
|
146 | 146 | \o 0.0 is the minimum size (pie not drawn). |
|
147 | 147 | \o 1.0 is the maximum size that can fit the chart. |
|
148 | 148 | \endlist |
|
149 | 149 | |
|
150 | 150 | Default value is 0.7. |
|
151 | 151 | */ |
|
152 | 152 | |
|
153 | 153 | /*! |
|
154 | 154 | \property QPieSeries::startAngle |
|
155 | 155 | \brief Defines the starting angle of the pie. |
|
156 | 156 | |
|
157 | 157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
158 | 158 | |
|
159 | 159 | Default is value is 0. |
|
160 | 160 | */ |
|
161 | 161 | |
|
162 | 162 | /*! |
|
163 | 163 | \qmlproperty real PieSeries::startAngle |
|
164 | 164 | |
|
165 | 165 | Defines the starting angle of the pie. |
|
166 | 166 | |
|
167 | 167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
168 | 168 | |
|
169 | 169 | Default is value is 0. |
|
170 | 170 | */ |
|
171 | 171 | |
|
172 | 172 | /*! |
|
173 | 173 | \property QPieSeries::endAngle |
|
174 | 174 | \brief Defines the ending angle of the pie. |
|
175 | 175 | |
|
176 | 176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
177 | 177 | |
|
178 | 178 | Default is value is 360. |
|
179 | 179 | */ |
|
180 | 180 | |
|
181 | 181 | /*! |
|
182 | 182 | \qmlproperty real PieSeries::endAngle |
|
183 | 183 | |
|
184 | 184 | Defines the ending angle of the pie. |
|
185 | 185 | |
|
186 | 186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
187 | 187 | |
|
188 | 188 | Default is value is 360. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \property QPieSeries::count |
|
193 | 193 | |
|
194 | 194 | Number of slices in the series. |
|
195 | 195 | */ |
|
196 | 196 | |
|
197 | 197 | /*! |
|
198 | 198 | \qmlproperty int PieSeries::count |
|
199 | 199 | |
|
200 | 200 | Number of slices in the series. |
|
201 | 201 | */ |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | \fn void QPieSeries::countChanged() |
|
205 | 205 | Emitted when the slice count has changed. |
|
206 | 206 | \sa count |
|
207 | 207 | */ |
|
208 | 208 | /*! |
|
209 | 209 | \qmlsignal PieSeries::onCountChanged() |
|
210 | 210 | Emitted when the slice count has changed. |
|
211 | 211 | */ |
|
212 | 212 | |
|
213 | 213 | /*! |
|
214 | 214 | \property QPieSeries::sum |
|
215 | 215 | |
|
216 | 216 | Sum of all slices. |
|
217 | 217 | |
|
218 | 218 | The series keeps track of the sum of all slices it holds. |
|
219 | 219 | */ |
|
220 | 220 | |
|
221 | 221 | /*! |
|
222 | 222 | \qmlproperty real PieSeries::sum |
|
223 | 223 | |
|
224 | 224 | Sum of all slices. |
|
225 | 225 | |
|
226 | 226 | The series keeps track of the sum of all slices it holds. |
|
227 | 227 | */ |
|
228 | 228 | |
|
229 | 229 | /*! |
|
230 | 230 | \fn void QPieSeries::sumChanged() |
|
231 | 231 | Emitted when the sum of all slices has changed. |
|
232 | 232 | \sa sum |
|
233 | 233 | */ |
|
234 | 234 | /*! |
|
235 | 235 | \qmlsignal PieSeries::onSumChanged() |
|
236 | 236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
237 | 237 | change value of a slice. |
|
238 | 238 | */ |
|
239 | 239 | |
|
240 | 240 | /*! |
|
241 | 241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
242 | 242 | |
|
243 | 243 | This signal is emitted when \a slices have been added to the series. |
|
244 | 244 | |
|
245 | 245 | \sa append(), insert() |
|
246 | 246 | */ |
|
247 | 247 | /*! |
|
248 | 248 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
249 | 249 | Emitted when \a slice has been added to the series. |
|
250 | 250 | */ |
|
251 | 251 | |
|
252 | 252 | /*! |
|
253 | 253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
254 | 254 | This signal is emitted when \a slices have been removed from the series. |
|
255 | 255 | \sa remove() |
|
256 | 256 | */ |
|
257 | 257 | /*! |
|
258 | 258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
259 | 259 | Emitted when \a slice has been removed from the series. |
|
260 | 260 | */ |
|
261 | 261 | |
|
262 | 262 | /*! |
|
263 | 263 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
264 | 264 | This signal is emitted when a \a slice has been clicked. |
|
265 | 265 | \sa QPieSlice::clicked() |
|
266 | 266 | */ |
|
267 | 267 | /*! |
|
268 | 268 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
269 | 269 | This signal is emitted when a \a slice has been clicked. |
|
270 | 270 | */ |
|
271 | 271 | |
|
272 | 272 | /*! |
|
273 | 273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
274 | 274 | This signal is emitted when user has hovered over or away from the \a slice. |
|
275 | 275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
276 | 276 | \sa QPieSlice::hovered() |
|
277 | 277 | */ |
|
278 | 278 | /*! |
|
279 | 279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
280 | 280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
281 | 281 | over the slice and false when hover has moved away from the slice. |
|
282 | 282 | */ |
|
283 | 283 | |
|
284 | 284 | /*! |
|
285 | 285 | \qmlmethod PieSlice PieSeries::at(int index) |
|
286 | 286 | Returns slice at \a index. Returns null if the index is not valid. |
|
287 | 287 | */ |
|
288 | 288 | |
|
289 | 289 | /*! |
|
290 | 290 | \qmlmethod PieSlice PieSeries::find(string label) |
|
291 | 291 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
292 | 292 | */ |
|
293 | 293 | |
|
294 | 294 | /*! |
|
295 | 295 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
296 | 296 | Adds a new slice with \a label and \a value to the pie. |
|
297 | 297 | */ |
|
298 | 298 | |
|
299 | 299 | /*! |
|
300 | 300 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
301 | 301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. |
|
302 | 302 | */ |
|
303 | 303 | |
|
304 | 304 | /*! |
|
305 | 305 | \qmlmethod PieSeries::clear() |
|
306 | 306 | Removes all slices from the pie. |
|
307 | 307 | */ |
|
308 | 308 | |
|
309 | 309 | /*! |
|
310 | 310 | Constructs a series object which is a child of \a parent. |
|
311 | 311 | */ |
|
312 | 312 | QPieSeries::QPieSeries(QObject *parent) : |
|
313 | 313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
314 | 314 | { |
|
315 | 315 | |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | /*! |
|
319 | 319 | Destroys the series and its slices. |
|
320 | 320 | */ |
|
321 | 321 | QPieSeries::~QPieSeries() |
|
322 | 322 | { |
|
323 | 323 | // NOTE: d_prt destroyed by QObject |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | /*! |
|
327 | 327 | Returns QChartSeries::SeriesTypePie. |
|
328 | 328 | */ |
|
329 | 329 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
330 | 330 | { |
|
331 | 331 | return QAbstractSeries::SeriesTypePie; |
|
332 | 332 | } |
|
333 | 333 | |
|
334 | 334 | /*! |
|
335 | 335 | Appends a single \a slice to the series. |
|
336 | 336 | Slice ownership is passed to the series. |
|
337 | 337 | |
|
338 | 338 | Returns true if append was succesfull. |
|
339 | 339 | */ |
|
340 | 340 | bool QPieSeries::append(QPieSlice* slice) |
|
341 | 341 | { |
|
342 | 342 | return append(QList<QPieSlice*>() << slice); |
|
343 | 343 | } |
|
344 | 344 | |
|
345 | 345 | /*! |
|
346 | 346 | Appends an array of \a slices to the series. |
|
347 | 347 | Slice ownership is passed to the series. |
|
348 | 348 | |
|
349 | 349 | Returns true if append was successfull. |
|
350 | 350 | */ |
|
351 | 351 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
352 | 352 | { |
|
353 | 353 | Q_D(QPieSeries); |
|
354 | 354 | |
|
355 | 355 | if (slices.count() == 0) |
|
356 | 356 | return false; |
|
357 | 357 | |
|
358 | 358 | foreach (QPieSlice* s, slices) { |
|
359 | 359 | if (!s || d->m_slices.contains(s)) |
|
360 | 360 | return false; |
|
361 | 361 | if (s->series()) // already added to some series |
|
362 | 362 | return false; |
|
363 | 363 | } |
|
364 | 364 | |
|
365 | 365 | foreach (QPieSlice* s, slices) { |
|
366 | 366 | s->setParent(this); |
|
367 | 367 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
368 | 368 | d->m_slices << s; |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | d->updateDerivativeData(); |
|
372 | 372 | |
|
373 | 373 | foreach (QPieSlice* s, slices) { |
|
374 | 374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
375 | 375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
376 | 376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
377 | 377 | } |
|
378 | 378 | |
|
379 | 379 | emit added(slices); |
|
380 | 380 | emit countChanged(); |
|
381 | 381 | |
|
382 | 382 | return true; |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | /*! |
|
386 | 386 | Appends a single \a slice to the series and returns a reference to the series. |
|
387 | 387 | Slice ownership is passed to the series. |
|
388 | 388 | */ |
|
389 | 389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
390 | 390 | { |
|
391 | 391 | append(slice); |
|
392 | 392 | return *this; |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | Appends a single slice to the series with give \a value and \a label. |
|
398 | 398 | Slice ownership is passed to the series. |
|
399 | 399 | */ |
|
400 | 400 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
401 | 401 | { |
|
402 | 402 | QPieSlice* slice = new QPieSlice(label, value); |
|
403 | 403 | append(slice); |
|
404 | 404 | return slice; |
|
405 | 405 | } |
|
406 | 406 | |
|
407 | 407 | /*! |
|
408 | 408 | Inserts a single \a slice to the series before the slice at \a index position. |
|
409 | 409 | Slice ownership is passed to the series. |
|
410 | 410 | |
|
411 | 411 | Returns true if insert was successfull. |
|
412 | 412 | */ |
|
413 | 413 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
414 | 414 | { |
|
415 | 415 | Q_D(QPieSeries); |
|
416 | 416 | |
|
417 | 417 | if (index < 0 || index > d->m_slices.count()) |
|
418 | 418 | return false; |
|
419 | 419 | |
|
420 | 420 | if (!slice || d->m_slices.contains(slice)) |
|
421 | 421 | return false; |
|
422 | 422 | |
|
423 | 423 | if (slice->series()) // already added to some series |
|
424 | 424 | return false; |
|
425 | 425 | |
|
426 | 426 | slice->setParent(this); |
|
427 | 427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
428 | 428 | d->m_slices.insert(index, slice); |
|
429 | 429 | |
|
430 | 430 | d->updateDerivativeData(); |
|
431 | 431 | |
|
432 | 432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
433 | 433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
434 | 434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
435 | 435 | |
|
436 | 436 | emit added(QList<QPieSlice*>() << slice); |
|
437 | 437 | emit countChanged(); |
|
438 | 438 | |
|
439 | 439 | return true; |
|
440 | 440 | } |
|
441 | 441 | |
|
442 | 442 | /*! |
|
443 | 443 | Removes a single \a slice from the series and deletes the slice. |
|
444 | 444 | |
|
445 | 445 | Do not reference the pointer after this call. |
|
446 | 446 | |
|
447 | 447 | Returns true if remove was successfull. |
|
448 | 448 | */ |
|
449 | 449 | bool QPieSeries::remove(QPieSlice* slice) |
|
450 | 450 | { |
|
451 | 451 | Q_D(QPieSeries); |
|
452 | 452 | |
|
453 | 453 | if (!d->m_slices.removeOne(slice)) |
|
454 | 454 | return false; |
|
455 | 455 | |
|
456 | 456 | d->updateDerivativeData(); |
|
457 | 457 | |
|
458 | 458 | emit removed(QList<QPieSlice*>() << slice); |
|
459 | 459 | emit countChanged(); |
|
460 | 460 | |
|
461 | 461 | delete slice; |
|
462 | 462 | slice = 0; |
|
463 | 463 | |
|
464 | 464 | return true; |
|
465 | 465 | } |
|
466 | 466 | |
|
467 | 467 | /*! |
|
468 | 468 | Clears all slices from the series. |
|
469 | 469 | */ |
|
470 | 470 | void QPieSeries::clear() |
|
471 | 471 | { |
|
472 | 472 | Q_D(QPieSeries); |
|
473 | 473 | if (d->m_slices.count() == 0) |
|
474 | 474 | return; |
|
475 | 475 | |
|
476 | 476 | QList<QPieSlice*> slices = d->m_slices; |
|
477 | 477 | foreach (QPieSlice* s, d->m_slices) { |
|
478 | 478 | d->m_slices.removeOne(s); |
|
479 | 479 | delete s; |
|
480 | 480 | } |
|
481 | 481 | |
|
482 | 482 | d->updateDerivativeData(); |
|
483 | 483 | |
|
484 | 484 | emit removed(slices); |
|
485 | 485 | emit countChanged(); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | /*! |
|
489 | 489 | Returns a list of slices that belong to this series. |
|
490 | 490 | */ |
|
491 | 491 | QList<QPieSlice*> QPieSeries::slices() const |
|
492 | 492 | { |
|
493 | 493 | Q_D(const QPieSeries); |
|
494 | 494 | return d->m_slices; |
|
495 | 495 | } |
|
496 | 496 | |
|
497 | 497 | /*! |
|
498 | 498 | returns the number of the slices in this series. |
|
499 | 499 | */ |
|
500 | 500 | int QPieSeries::count() const |
|
501 | 501 | { |
|
502 | 502 | Q_D(const QPieSeries); |
|
503 | 503 | return d->m_slices.count(); |
|
504 | 504 | } |
|
505 | 505 | |
|
506 | 506 | /*! |
|
507 | 507 | Returns true is the series is empty. |
|
508 | 508 | */ |
|
509 | 509 | bool QPieSeries::isEmpty() const |
|
510 | 510 | { |
|
511 | 511 | Q_D(const QPieSeries); |
|
512 | 512 | return d->m_slices.isEmpty(); |
|
513 | 513 | } |
|
514 | 514 | |
|
515 | 515 | /*! |
|
516 | 516 | Returns the sum of all slice values in this series. |
|
517 | 517 | |
|
518 | 518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
519 | 519 | */ |
|
520 | 520 | qreal QPieSeries::sum() const |
|
521 | 521 | { |
|
522 | 522 | Q_D(const QPieSeries); |
|
523 | 523 | return d->m_sum; |
|
524 | 524 | } |
|
525 | 525 | |
|
526 | 526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
527 | 527 | { |
|
528 | 528 | Q_D(QPieSeries); |
|
529 | 529 | |
|
530 | 530 | if (relativePosition < 0.0) |
|
531 | 531 | relativePosition = 0.0; |
|
532 | 532 | if (relativePosition > 1.0) |
|
533 | 533 | relativePosition = 1.0; |
|
534 | 534 | |
|
535 | 535 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
536 | 536 | d->m_pieRelativeHorPos = relativePosition; |
|
537 | 537 | emit d->horizontalPositionChanged(); |
|
538 | 538 | } |
|
539 | 539 | } |
|
540 | 540 | |
|
541 | 541 | qreal QPieSeries::horizontalPosition() const |
|
542 | 542 | { |
|
543 | 543 | Q_D(const QPieSeries); |
|
544 | 544 | return d->m_pieRelativeHorPos; |
|
545 | 545 | } |
|
546 | 546 | |
|
547 | 547 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
548 | 548 | { |
|
549 | 549 | Q_D(QPieSeries); |
|
550 | 550 | |
|
551 | 551 | if (relativePosition < 0.0) |
|
552 | 552 | relativePosition = 0.0; |
|
553 | 553 | if (relativePosition > 1.0) |
|
554 | 554 | relativePosition = 1.0; |
|
555 | 555 | |
|
556 | 556 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
557 | 557 | d->m_pieRelativeVerPos = relativePosition; |
|
558 | 558 | emit d->verticalPositionChanged(); |
|
559 | 559 | } |
|
560 | 560 | } |
|
561 | 561 | |
|
562 | 562 | qreal QPieSeries::verticalPosition() const |
|
563 | 563 | { |
|
564 | 564 | Q_D(const QPieSeries); |
|
565 | 565 | return d->m_pieRelativeVerPos; |
|
566 | 566 | } |
|
567 | 567 | |
|
568 | 568 | void QPieSeries::setPieSize(qreal relativeSize) |
|
569 | 569 | { |
|
570 | 570 | Q_D(QPieSeries); |
|
571 | 571 | |
|
572 | 572 | if (relativeSize < 0.0) |
|
573 | 573 | relativeSize = 0.0; |
|
574 | 574 | if (relativeSize > 1.0) |
|
575 | 575 | relativeSize = 1.0; |
|
576 | 576 | |
|
577 | 577 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
578 | 578 | d->m_pieRelativeSize = relativeSize; |
|
579 | 579 | emit d->pieSizeChanged(); |
|
580 | 580 | } |
|
581 | 581 | } |
|
582 | 582 | |
|
583 | 583 | qreal QPieSeries::pieSize() const |
|
584 | 584 | { |
|
585 | 585 | Q_D(const QPieSeries); |
|
586 | 586 | return d->m_pieRelativeSize; |
|
587 | 587 | } |
|
588 | 588 | |
|
589 | 589 | |
|
590 | 590 | void QPieSeries::setPieStartAngle(qreal angle) |
|
591 | 591 | { |
|
592 | 592 | Q_D(QPieSeries); |
|
593 | 593 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
594 | 594 | return; |
|
595 | 595 | d->m_pieStartAngle = angle; |
|
596 | 596 | d->updateDerivativeData(); |
|
597 | 597 | emit d->pieStartAngleChanged(); |
|
598 | 598 | } |
|
599 | 599 | |
|
600 | 600 | qreal QPieSeries::pieStartAngle() const |
|
601 | 601 | { |
|
602 | 602 | Q_D(const QPieSeries); |
|
603 | 603 | return d->m_pieStartAngle; |
|
604 | 604 | } |
|
605 | 605 | |
|
606 | 606 | /*! |
|
607 | 607 | Sets the end angle of the pie. |
|
608 | 608 | |
|
609 | 609 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
610 | 610 | |
|
611 | 611 | \a angle must be greater than start angle. |
|
612 | 612 | |
|
613 | 613 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
614 | 614 | */ |
|
615 | 615 | void QPieSeries::setPieEndAngle(qreal angle) |
|
616 | 616 | { |
|
617 | 617 | Q_D(QPieSeries); |
|
618 | 618 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
619 | 619 | return; |
|
620 | 620 | d->m_pieEndAngle = angle; |
|
621 | 621 | d->updateDerivativeData(); |
|
622 | 622 | emit d->pieEndAngleChanged(); |
|
623 | 623 | } |
|
624 | 624 | |
|
625 | 625 | /*! |
|
626 | 626 | Returns the end angle of the pie. |
|
627 | 627 | |
|
628 | 628 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
629 | 629 | |
|
630 | 630 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
631 | 631 | */ |
|
632 | 632 | qreal QPieSeries::pieEndAngle() const |
|
633 | 633 | { |
|
634 | 634 | Q_D(const QPieSeries); |
|
635 | 635 | return d->m_pieEndAngle; |
|
636 | 636 | } |
|
637 | 637 | |
|
638 | 638 | /*! |
|
639 | 639 | Sets the all the slice labels \a visible or invisible. |
|
640 | 640 | |
|
641 | 641 | Note that this affects only the current slices in the series. |
|
642 | 642 | If user adds a new slice the default label visibility is false. |
|
643 | 643 | |
|
644 | 644 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
645 | 645 | */ |
|
646 | 646 | void QPieSeries::setLabelsVisible(bool visible) |
|
647 | 647 | { |
|
648 | 648 | Q_D(QPieSeries); |
|
649 | 649 | foreach (QPieSlice* s, d->m_slices) |
|
650 | 650 | s->setLabelVisible(visible); |
|
651 | 651 | } |
|
652 | 652 | |
|
653 | 653 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
654 | 654 | |
|
655 | 655 | |
|
656 | 656 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
657 | 657 | QAbstractSeriesPrivate(parent), |
|
658 | 658 | m_pieRelativeHorPos(0.5), |
|
659 | 659 | m_pieRelativeVerPos(0.5), |
|
660 | 660 | m_pieRelativeSize(0.7), |
|
661 | 661 | m_pieStartAngle(0), |
|
662 | 662 | m_pieEndAngle(360), |
|
663 | 663 | m_sum(0) |
|
664 | 664 | { |
|
665 | 665 | } |
|
666 | 666 | |
|
667 | 667 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
668 | 668 | { |
|
669 | 669 | } |
|
670 | 670 | |
|
671 | 671 | void QPieSeriesPrivate::updateDerivativeData() |
|
672 | 672 | { |
|
673 | 673 | // calculate sum of all slices |
|
674 | 674 | qreal sum = 0; |
|
675 | 675 | foreach (QPieSlice* s, m_slices) |
|
676 | 676 | sum += s->value(); |
|
677 | 677 | |
|
678 | 678 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
679 | 679 | m_sum = sum; |
|
680 | 680 | emit q_func()->sumChanged(); |
|
681 | 681 | } |
|
682 | 682 | |
|
683 | 683 | // nothing to show.. |
|
684 | 684 | if (qFuzzyIsNull(m_sum)) |
|
685 | 685 | return; |
|
686 | 686 | |
|
687 | 687 | // update slice attributes |
|
688 | 688 | qreal sliceAngle = m_pieStartAngle; |
|
689 | 689 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
690 | 690 | QVector<QPieSlice*> changed; |
|
691 | 691 | foreach (QPieSlice* s, m_slices) { |
|
692 | 692 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
693 | 693 | d->setPercentage(s->value() / m_sum); |
|
694 | 694 | d->setStartAngle(sliceAngle); |
|
695 | 695 | d->setAngleSpan(pieSpan * s->percentage()); |
|
696 | 696 | sliceAngle += s->angleSpan(); |
|
697 | 697 | } |
|
698 | 698 | |
|
699 | 699 | |
|
700 | 700 | emit calculatedDataChanged(); |
|
701 | 701 | } |
|
702 | 702 | |
|
703 | 703 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
704 | 704 | { |
|
705 | 705 | return series->d_func(); |
|
706 | 706 | } |
|
707 | 707 | |
|
708 | 708 | void QPieSeriesPrivate::sliceValueChanged() |
|
709 | 709 | { |
|
710 | 710 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
711 | 711 | updateDerivativeData(); |
|
712 | 712 | } |
|
713 | 713 | |
|
714 | 714 | void QPieSeriesPrivate::sliceClicked() |
|
715 | 715 | { |
|
716 | 716 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
717 | 717 | Q_ASSERT(m_slices.contains(slice)); |
|
718 | 718 | Q_Q(QPieSeries); |
|
719 | 719 | emit q->clicked(slice); |
|
720 | 720 | } |
|
721 | 721 | |
|
722 | 722 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
723 | 723 | { |
|
724 | 724 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
725 | 725 | Q_ASSERT(m_slices.contains(slice)); |
|
726 | 726 | Q_Q(QPieSeries); |
|
727 | 727 | emit q->hovered(slice, state); |
|
728 | 728 | } |
|
729 | 729 | |
|
730 | 730 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
731 | 731 | { |
|
732 | 732 | Q_UNUSED(domain); |
|
733 | 733 | // does not apply to pie |
|
734 | 734 | } |
|
735 | 735 | |
|
736 | 736 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
737 | 737 | { |
|
738 | 738 | Q_Q(QPieSeries); |
|
739 | 739 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
740 | 740 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
741 | 741 | presenter->animator()->addAnimation(pie); |
|
742 | 742 | } |
|
743 | 743 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
744 | 744 | return pie; |
|
745 | 745 | } |
|
746 | 746 | |
|
747 | 747 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
748 | 748 | { |
|
749 | 749 | Q_Q(QPieSeries); |
|
750 | 750 | QList<LegendMarker*> markers; |
|
751 | 751 | foreach(QPieSlice* slice, q->slices()) { |
|
752 | 752 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
753 | 753 | markers << marker; |
|
754 | 754 | } |
|
755 | 755 | return markers; |
|
756 | 756 | } |
|
757 | 757 | |
|
758 |
|
|
|
758 | void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
|
759 | 759 | { |
|
760 |
Q_UNUSED( |
|
|
761 | return 0; | |
|
760 | Q_UNUSED(axis); | |
|
762 | 761 | } |
|
763 | 762 | |
|
764 |
|
|
|
763 | void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
|
765 | 764 | { |
|
766 |
Q_UNUSED( |
|
|
767 | return 0; | |
|
765 | Q_UNUSED(axis); | |
|
766 | } | |
|
767 | ||
|
768 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const | |
|
769 | { | |
|
770 | return QAbstractAxis::AxisTypeNoAxis; | |
|
771 | } | |
|
772 | ||
|
773 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const | |
|
774 | { | |
|
775 | return QAbstractAxis::AxisTypeNoAxis; | |
|
768 | 776 | } |
|
769 | 777 | |
|
770 | 778 | #include "moc_qpieseries.cpp" |
|
771 | 779 | #include "moc_qpieseries_p.cpp" |
|
772 | 780 | |
|
773 | 781 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,86 +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 | // 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 QPIESERIES_P_H |
|
31 | 31 | #define QPIESERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qpieseries.h" |
|
34 | 34 | #include "qabstractseries_p.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | 37 | class QLegendPrivate; |
|
38 | 38 | |
|
39 | 39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | QPieSeriesPrivate(QPieSeries *parent); |
|
45 | 45 | ~QPieSeriesPrivate(); |
|
46 | 46 | |
|
47 | 47 | void scaleDomain(Domain& domain); |
|
48 | 48 | Chart* createGraphics(ChartPresenter *presenter); |
|
49 | 49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); |
|
50 | QAbstractAxis* createAxisX(QObject* parent); | |
|
51 | QAbstractAxis* createAxisY(QObject* parent); | |
|
50 | void initializeAxisX(QAbstractAxis* axis); | |
|
51 | void initializeAxisY(QAbstractAxis* axis); | |
|
52 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
53 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
52 | 54 | |
|
53 | 55 | void updateDerivativeData(); |
|
54 | 56 | |
|
55 | 57 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); |
|
56 | 58 | |
|
57 | 59 | signals: |
|
58 | 60 | void calculatedDataChanged(); |
|
59 | 61 | void pieSizeChanged(); |
|
60 | 62 | void pieStartAngleChanged(); |
|
61 | 63 | void pieEndAngleChanged(); |
|
62 | 64 | void horizontalPositionChanged(); |
|
63 | 65 | void verticalPositionChanged(); |
|
64 | 66 | |
|
65 | 67 | public Q_SLOTS: |
|
66 | 68 | void sliceValueChanged(); |
|
67 | 69 | void sliceClicked(); |
|
68 | 70 | void sliceHovered(bool state); |
|
69 | 71 | |
|
70 | 72 | private: |
|
71 | 73 | QList<QPieSlice*> m_slices; |
|
72 | 74 | qreal m_pieRelativeHorPos; |
|
73 | 75 | qreal m_pieRelativeVerPos; |
|
74 | 76 | qreal m_pieRelativeSize; |
|
75 | 77 | qreal m_pieStartAngle; |
|
76 | 78 | qreal m_pieEndAngle; |
|
77 | 79 | qreal m_sum; |
|
78 | 80 | |
|
79 | 81 | private: |
|
80 | 82 | friend class QLegendPrivate; |
|
81 | 83 | Q_DECLARE_PUBLIC(QPieSeries) |
|
82 | 84 | }; |
|
83 | 85 | |
|
84 | 86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | 87 | |
|
86 | 88 | #endif // QPIESERIES_P_H |
@@ -1,83 +1,85 | |||
|
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 QABSTRACTSERIES_H |
|
22 | 22 | #define QABSTRACTSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | #include <qabstractaxis.h> | |
|
25 | 26 | #include <QObject> |
|
26 | 27 | #include <QPen> |
|
27 | 28 | |
|
28 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 30 | |
|
30 | 31 | class QAbstractSeriesPrivate; |
|
31 | 32 | class QChart; |
|
32 | 33 | |
|
33 | 34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
34 | 35 | { |
|
35 | 36 | Q_OBJECT |
|
36 | 37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
37 | 38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | 39 | Q_PROPERTY(SeriesType type READ type) |
|
39 | 40 | Q_ENUMS(SeriesType) |
|
40 | 41 | |
|
41 | 42 | public: |
|
42 | 43 | enum SeriesType { |
|
43 | 44 | SeriesTypeLine, |
|
44 | 45 | SeriesTypeArea, |
|
45 | 46 | SeriesTypeBar, |
|
46 | 47 | SeriesTypeStackedBar, |
|
47 | 48 | SeriesTypePercentBar, |
|
48 | 49 | SeriesTypeGroupedBar, |
|
49 | 50 | SeriesTypePie, |
|
50 | 51 | SeriesTypeScatter, |
|
51 | 52 | SeriesTypeSpline |
|
52 | 53 | }; |
|
53 | 54 | |
|
54 | 55 | protected: |
|
55 | 56 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
56 | 57 | |
|
57 | 58 | public: |
|
58 | 59 | ~QAbstractSeries(); |
|
59 | 60 | virtual SeriesType type() const = 0; |
|
61 | ||
|
60 | 62 | void setName(const QString& name); |
|
61 | 63 | QString name() const; |
|
62 | 64 | void setVisible(bool visible = true); |
|
63 | 65 | bool isVisible() const; |
|
64 | 66 | QChart* chart() const; |
|
65 | 67 | |
|
66 | 68 | void adjustView(); |
|
67 | 69 | void show(); |
|
68 | 70 | void hide(); |
|
69 | 71 | |
|
70 | 72 | Q_SIGNALS: |
|
71 | 73 | void nameChanged(); |
|
72 | 74 | void visibleChanged(); |
|
73 | 75 | |
|
74 | 76 | protected: |
|
75 | 77 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
76 | 78 | friend class ChartDataSet; |
|
77 | 79 | friend class ChartPresenter; |
|
78 | 80 | friend class QLegendPrivate; |
|
79 | 81 | }; |
|
80 | 82 | |
|
81 | 83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | 84 | |
|
83 | 85 | #endif |
@@ -1,71 +1,73 | |||
|
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 QABSTRACTSERIES_P_H |
|
31 | 31 | #define QABSTRACTSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class Domain; |
|
38 | 38 | class ChartPresenter; |
|
39 | 39 | class Chart; |
|
40 | 40 | class LegendMarker; |
|
41 | 41 | class QLegend; |
|
42 | 42 | class ChartDataSet; |
|
43 | 43 | class QAbstractAxis; |
|
44 | 44 | |
|
45 | 45 | class QAbstractSeriesPrivate : public QObject |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | public: |
|
49 | 49 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
50 | 50 | ~QAbstractSeriesPrivate(); |
|
51 | 51 | |
|
52 | 52 | virtual void scaleDomain(Domain& domain) = 0; |
|
53 | 53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
54 | 54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
55 |
virtual QAbstractAxis* |
|
|
56 |
virtual QAbstractAxis* |
|
|
55 | virtual void initializeAxisX(QAbstractAxis* axis) = 0; | |
|
56 | virtual void initializeAxisY(QAbstractAxis* axis) = 0; | |
|
57 | virtual QAbstractAxis::AxisType defaultAxisXType() const = 0; | |
|
58 | virtual QAbstractAxis::AxisType defaultAxisYType() const = 0; | |
|
57 | 59 | |
|
58 | 60 | protected: |
|
59 | 61 | QAbstractSeries *q_ptr; |
|
60 | 62 | QChart *m_chart; |
|
61 | 63 | ChartDataSet *m_dataset; |
|
62 | 64 | QString m_name; |
|
63 | 65 | bool m_visible; |
|
64 | 66 | |
|
65 | 67 | friend class QAbstractSeries; |
|
66 | 68 | friend class ChartDataSet; |
|
67 | 69 | }; |
|
68 | 70 | |
|
69 | 71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | 72 | |
|
71 | 73 | #endif |
@@ -1,451 +1,461 | |||
|
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 "qxyseries.h" |
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "domain_p.h" |
|
24 | 24 | #include "legendmarker_p.h" |
|
25 | 25 | #include "qvaluesaxis.h" |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | /*! |
|
30 | 30 | \class QXYSeries |
|
31 | 31 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
32 | 32 | */ |
|
33 | 33 | /*! |
|
34 | 34 | \qmlclass XYSeries |
|
35 | 35 | \inherits AbstractSeries |
|
36 | 36 | The XYSeries class is a base class for line, spline and scatter series. |
|
37 | 37 | |
|
38 | 38 | The class cannot be instantiated directly. |
|
39 | 39 | */ |
|
40 | 40 | |
|
41 | 41 | /*! |
|
42 | 42 | \property QXYSeries::pointsVisible |
|
43 | 43 | Controls if the data points are visible and should be drawn. |
|
44 | 44 | */ |
|
45 | 45 | /*! |
|
46 | 46 | \qmlproperty bool XYSeries::pointsVisible |
|
47 | 47 | Controls if the data points are visible and should be drawn. |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | /*! |
|
51 | 51 | \fn QPen QXYSeries::pen() const |
|
52 | 52 | \brief Returns pen used to draw points for series. |
|
53 | 53 | \sa setPen() |
|
54 | 54 | */ |
|
55 | 55 | |
|
56 | 56 | /*! |
|
57 | 57 | \fn QBrush QXYSeries::brush() const |
|
58 | 58 | \brief Returns brush used to draw points for series. |
|
59 | 59 | \sa setBrush() |
|
60 | 60 | */ |
|
61 | 61 | |
|
62 | 62 | /*! |
|
63 | 63 | \property QXYSeries::color |
|
64 | 64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
65 | 65 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
66 | 66 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
67 | 67 | */ |
|
68 | 68 | /*! |
|
69 | 69 | \qmlproperty color XYSeries::color |
|
70 | 70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
71 | 71 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
72 | 72 | */ |
|
73 | 73 | |
|
74 | 74 | /*! |
|
75 | 75 | \fn void QXYSeries::clicked(const QPointF& point) |
|
76 | 76 | \brief Signal is emitted when user clicks the \a point on chart. |
|
77 | 77 | */ |
|
78 | 78 | /*! |
|
79 | 79 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
80 | 80 | Signal is emitted when user clicks the \a point on chart. For example: |
|
81 | 81 | \code |
|
82 | 82 | LineSeries { |
|
83 | 83 | XYPoint { x: 0; y: 0 } |
|
84 | 84 | XYPoint { x: 1.1; y: 2.1 } |
|
85 | 85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
86 | 86 | } |
|
87 | 87 | \endcode |
|
88 | 88 | */ |
|
89 | 89 | |
|
90 | 90 | /*! |
|
91 | 91 | \fn void QXYSeries::pointReplaced(int index) |
|
92 | 92 | Signal is emitted when a point has been replaced at \a index. |
|
93 | 93 | \sa replace() |
|
94 | 94 | */ |
|
95 | 95 | /*! |
|
96 | 96 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
97 | 97 | Signal is emitted when a point has been replaced at \a index. |
|
98 | 98 | */ |
|
99 | 99 | |
|
100 | 100 | /*! |
|
101 | 101 | \fn void QXYSeries::pointAdded(int index) |
|
102 | 102 | Signal is emitted when a point has been added at \a index. |
|
103 | 103 | \sa append(), insert() |
|
104 | 104 | */ |
|
105 | 105 | /*! |
|
106 | 106 | \qmlsignal XYSeries::onPointAdded(int index) |
|
107 | 107 | Signal is emitted when a point has been added at \a index. |
|
108 | 108 | */ |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | \fn void QXYSeries::pointRemoved(int index) |
|
112 | 112 | Signal is emitted when a point has been removed from \a index. |
|
113 | 113 | \sa remove() |
|
114 | 114 | */ |
|
115 | 115 | /*! |
|
116 | 116 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
117 | 117 | Signal is emitted when a point has been removed from \a index. |
|
118 | 118 | */ |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \fn void QXYSeries::colorChanged(QColor color) |
|
122 | 122 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
123 | 123 | */ |
|
124 | 124 | /*! |
|
125 | 125 | \qmlsignal XYSeries::onColorChanged(color color) |
|
126 | 126 | Signal is emitted when the line (pen) color has changed to \a color. |
|
127 | 127 | */ |
|
128 | 128 | |
|
129 | 129 | /*! |
|
130 | 130 | \fn void QXYSeriesPrivate::updated() |
|
131 | 131 | \brief \internal |
|
132 | 132 | */ |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | \qmlmethod XYSeries::append(real x, real y) |
|
136 | 136 | Append point (\a x, \a y) to the series |
|
137 | 137 | */ |
|
138 | 138 | |
|
139 | 139 | /*! |
|
140 | 140 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
141 | 141 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
142 | 142 | exist. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \qmlmethod XYSeries::remove(real x, real y) |
|
147 | 147 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
152 | 152 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
153 | 153 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
154 | 154 | */ |
|
155 | 155 | |
|
156 | 156 | /*! |
|
157 | 157 | \qmlmethod QPointF XYSeries::at(int index) |
|
158 | 158 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \internal |
|
163 | 163 | |
|
164 | 164 | Constructs empty series object which is a child of \a parent. |
|
165 | 165 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
166 | 166 | */ |
|
167 | 167 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
168 | 168 | { |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | /*! |
|
172 | 172 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
173 | 173 | and are deleted when mentioned object are destroyed. |
|
174 | 174 | */ |
|
175 | 175 | QXYSeries::~QXYSeries() |
|
176 | 176 | { |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
181 | 181 | */ |
|
182 | 182 | void QXYSeries::append(qreal x,qreal y) |
|
183 | 183 | { |
|
184 | 184 | append(QPointF(x,y)); |
|
185 | 185 | } |
|
186 | 186 | |
|
187 | 187 | /*! |
|
188 | 188 | This is an overloaded function. |
|
189 | 189 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
190 | 190 | */ |
|
191 | 191 | void QXYSeries::append(const QPointF &point) |
|
192 | 192 | { |
|
193 | 193 | Q_D(QXYSeries); |
|
194 | 194 | d->m_points<<point; |
|
195 | 195 | // emit d->pointAdded(d->m_points.count()-1); |
|
196 | 196 | emit pointAdded(d->m_points.count()-1); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 | 199 | /*! |
|
200 | 200 | This is an overloaded function. |
|
201 | 201 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
202 | 202 | */ |
|
203 | 203 | void QXYSeries::append(const QList<QPointF> &points) |
|
204 | 204 | { |
|
205 | 205 | foreach(const QPointF& point , points) { |
|
206 | 206 | append(point); |
|
207 | 207 | } |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | 210 | /*! |
|
211 | 211 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
212 | 212 | */ |
|
213 | 213 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
214 | 214 | { |
|
215 | 215 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | /*! |
|
219 | 219 | Replaces \a oldPoint with \a newPoint. |
|
220 | 220 | */ |
|
221 | 221 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
222 | 222 | { |
|
223 | 223 | Q_D(QXYSeries); |
|
224 | 224 | int index = d->m_points.indexOf(oldPoint); |
|
225 | 225 | if(index==-1) return; |
|
226 | 226 | d->m_points[index] = newPoint; |
|
227 | 227 | // emit d->pointReplaced(index); |
|
228 | 228 | emit pointReplaced(index); |
|
229 | 229 | } |
|
230 | 230 | |
|
231 | 231 | /*! |
|
232 | 232 | Removes current \a x and \a y value. |
|
233 | 233 | */ |
|
234 | 234 | void QXYSeries::remove(qreal x,qreal y) |
|
235 | 235 | { |
|
236 | 236 | remove(QPointF(x,y)); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | /*! |
|
240 | 240 | Removes current \a point x value. |
|
241 | 241 | |
|
242 | 242 | Note: point y value is ignored. |
|
243 | 243 | */ |
|
244 | 244 | void QXYSeries::remove(const QPointF &point) |
|
245 | 245 | { |
|
246 | 246 | Q_D(QXYSeries); |
|
247 | 247 | int index = d->m_points.indexOf(point); |
|
248 | 248 | if(index==-1) return; |
|
249 | 249 | d->m_points.remove(index); |
|
250 | 250 | // emit d->pointRemoved(index); |
|
251 | 251 | emit pointRemoved(index); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | /*! |
|
255 | 255 | Inserts a \a point in the series at \a index position. |
|
256 | 256 | */ |
|
257 | 257 | void QXYSeries::insert(int index, const QPointF &point) |
|
258 | 258 | { |
|
259 | 259 | Q_D(QXYSeries); |
|
260 | 260 | d->m_points.insert(index, point); |
|
261 | 261 | // emit d->pointAdded(index); |
|
262 | 262 | emit pointAdded(index); |
|
263 | 263 | } |
|
264 | 264 | |
|
265 | 265 | /*! |
|
266 | 266 | Removes all points from the series. |
|
267 | 267 | */ |
|
268 | 268 | void QXYSeries::clear() |
|
269 | 269 | { |
|
270 | 270 | Q_D(QXYSeries); |
|
271 | 271 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
272 | 272 | remove(d->m_points.at(i)); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | \internal \a pos |
|
277 | 277 | */ |
|
278 | 278 | QList<QPointF> QXYSeries::points() const |
|
279 | 279 | { |
|
280 | 280 | Q_D(const QXYSeries); |
|
281 | 281 | return d->m_points.toList(); |
|
282 | 282 | } |
|
283 | 283 | |
|
284 | 284 | /*! |
|
285 | 285 | Returns number of data points within series. |
|
286 | 286 | */ |
|
287 | 287 | int QXYSeries::count() const |
|
288 | 288 | { |
|
289 | 289 | Q_D(const QXYSeries); |
|
290 | 290 | return d->m_points.count(); |
|
291 | 291 | } |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | /*! |
|
295 | 295 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
296 | 296 | pen from chart theme is used. |
|
297 | 297 | \sa QChart::setTheme() |
|
298 | 298 | */ |
|
299 | 299 | void QXYSeries::setPen(const QPen &pen) |
|
300 | 300 | { |
|
301 | 301 | Q_D(QXYSeries); |
|
302 | 302 | if (d->m_pen != pen) { |
|
303 | 303 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
304 | 304 | d->m_pen = pen; |
|
305 | 305 | emit d->updated(); |
|
306 | 306 | if (emitColorChanged) |
|
307 | 307 | emit colorChanged(pen.color()); |
|
308 | 308 | } |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | QPen QXYSeries::pen() const |
|
312 | 312 | { |
|
313 | 313 | Q_D(const QXYSeries); |
|
314 | 314 | return d->m_pen; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
319 | 319 | from chart theme setting is used. |
|
320 | 320 | \sa QChart::setTheme() |
|
321 | 321 | */ |
|
322 | 322 | void QXYSeries::setBrush(const QBrush &brush) |
|
323 | 323 | { |
|
324 | 324 | Q_D(QXYSeries); |
|
325 | 325 | if (d->m_brush!=brush) { |
|
326 | 326 | d->m_brush = brush; |
|
327 | 327 | emit d->updated(); |
|
328 | 328 | } |
|
329 | 329 | } |
|
330 | 330 | |
|
331 | 331 | QBrush QXYSeries::brush() const |
|
332 | 332 | { |
|
333 | 333 | Q_D(const QXYSeries); |
|
334 | 334 | return d->m_brush; |
|
335 | 335 | } |
|
336 | 336 | |
|
337 | 337 | void QXYSeries::setColor(const QColor &color) |
|
338 | 338 | { |
|
339 | 339 | QPen p = pen(); |
|
340 | 340 | if (p.color() != color) { |
|
341 | 341 | p.setColor(color); |
|
342 | 342 | setPen(p); |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | QColor QXYSeries::color() const |
|
347 | 347 | { |
|
348 | 348 | return pen().color(); |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void QXYSeries::setPointsVisible(bool visible) |
|
352 | 352 | { |
|
353 | 353 | Q_D(QXYSeries); |
|
354 | 354 | if (d->m_pointsVisible != visible){ |
|
355 | 355 | d->m_pointsVisible = visible; |
|
356 | 356 | emit d->updated(); |
|
357 | 357 | } |
|
358 | 358 | } |
|
359 | 359 | |
|
360 | 360 | bool QXYSeries::pointsVisible() const |
|
361 | 361 | { |
|
362 | 362 | Q_D(const QXYSeries); |
|
363 | 363 | return d->m_pointsVisible; |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | |
|
367 | 367 | /*! |
|
368 | 368 | Stream operator for adding a data \a point to the series. |
|
369 | 369 | \sa append() |
|
370 | 370 | */ |
|
371 | 371 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
372 | 372 | { |
|
373 | 373 | append(point); |
|
374 | 374 | return *this; |
|
375 | 375 | } |
|
376 | 376 | |
|
377 | 377 | |
|
378 | 378 | /*! |
|
379 | 379 | Stream operator for adding a list of \a points to the series. |
|
380 | 380 | \sa append() |
|
381 | 381 | */ |
|
382 | 382 | |
|
383 | 383 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
384 | 384 | { |
|
385 | 385 | append(points); |
|
386 | 386 | return *this; |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
390 | 390 | |
|
391 | 391 | |
|
392 | 392 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
393 | 393 | QAbstractSeriesPrivate(q), |
|
394 | 394 | m_pointsVisible(false) |
|
395 | 395 | { |
|
396 | 396 | } |
|
397 | 397 | |
|
398 | 398 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
399 | 399 | { |
|
400 | 400 | qreal minX(domain.minX()); |
|
401 | 401 | qreal minY(domain.minY()); |
|
402 | 402 | qreal maxX(domain.maxX()); |
|
403 | 403 | qreal maxY(domain.maxY()); |
|
404 | 404 | int tickXCount(domain.tickXCount()); |
|
405 | 405 | int tickYCount(domain.tickYCount()); |
|
406 | 406 | |
|
407 | 407 | Q_Q(QXYSeries); |
|
408 | 408 | |
|
409 | 409 | const QList<QPointF>& points = q->points(); |
|
410 | 410 | |
|
411 | 411 | |
|
412 | 412 | if (points.isEmpty()){ |
|
413 | 413 | minX = qMin(minX, 0.0); |
|
414 | 414 | minY = qMin(minY, 0.0); |
|
415 | 415 | maxX = qMax(maxX, 1.0); |
|
416 | 416 | maxY = qMax(maxY, 1.0); |
|
417 | 417 | } |
|
418 | 418 | |
|
419 | 419 | for (int i = 0; i < points.count(); i++) { |
|
420 | 420 | qreal x = points[i].x(); |
|
421 | 421 | qreal y = points[i].y(); |
|
422 | 422 | minX = qMin(minX, x); |
|
423 | 423 | minY = qMin(minY, y); |
|
424 | 424 | maxX = qMax(maxX, x); |
|
425 | 425 | maxY = qMax(maxY, y); |
|
426 | 426 | } |
|
427 | 427 | |
|
428 | 428 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
429 | 429 | } |
|
430 | 430 | |
|
431 | 431 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
432 | 432 | { |
|
433 | 433 | Q_Q(QXYSeries); |
|
434 | 434 | QList<LegendMarker*> list; |
|
435 | 435 | return list << new XYLegendMarker(q,legend); |
|
436 | 436 | } |
|
437 | 437 | |
|
438 |
|
|
|
438 | void QXYSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
|
439 | 439 | { |
|
440 | return new QValuesAxis(parent); | |
|
440 | Q_UNUSED(axis); | |
|
441 | 441 | } |
|
442 | 442 | |
|
443 |
|
|
|
443 | void QXYSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
|
444 | 444 | { |
|
445 | return new QValuesAxis(parent); | |
|
445 | Q_UNUSED(axis); | |
|
446 | } | |
|
447 | ||
|
448 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisXType() const | |
|
449 | { | |
|
450 | return QAbstractAxis::AxisTypeValues; | |
|
451 | } | |
|
452 | ||
|
453 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisYType() const | |
|
454 | { | |
|
455 | return QAbstractAxis::AxisTypeValues; | |
|
446 | 456 | } |
|
447 | 457 | |
|
448 | 458 | #include "moc_qxyseries.cpp" |
|
449 | 459 | #include "moc_qxyseries_p.cpp" |
|
450 | 460 | |
|
451 | 461 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,74 | |||
|
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 QXYSERIES_P_H |
|
31 | 31 | #define QXYSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QXYSeries; |
|
38 | 38 | class QAbstractAxis; |
|
39 | 39 | |
|
40 | 40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | QXYSeriesPrivate(QXYSeries* q); |
|
46 | 46 | |
|
47 | 47 | void scaleDomain(Domain& domain); |
|
48 | 48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
49 | 49 | |
|
50 | QAbstractAxis* createAxisX(QObject* parent); | |
|
51 | QAbstractAxis* createAxisY(QObject* parent); | |
|
50 | void initializeAxisX(QAbstractAxis* axis); | |
|
51 | void initializeAxisY(QAbstractAxis* axis); | |
|
52 | QAbstractAxis::AxisType defaultAxisXType() const; | |
|
53 | QAbstractAxis::AxisType defaultAxisYType() const; | |
|
52 | 54 | |
|
53 | 55 | Q_SIGNALS: |
|
54 | 56 | void updated(); |
|
55 | 57 | // void pointReplaced(int index); |
|
56 | 58 | // void pointRemoved(int index); |
|
57 | 59 | // void pointAdded(int index); |
|
58 | 60 | |
|
59 | 61 | protected: |
|
60 | 62 | QVector<QPointF> m_points; |
|
61 | 63 | QPen m_pen; |
|
62 | 64 | QBrush m_brush; |
|
63 | 65 | bool m_pointsVisible; |
|
64 | 66 | |
|
65 | 67 | private: |
|
66 | 68 | Q_DECLARE_PUBLIC(QXYSeries) |
|
67 | 69 | friend class QScatterSeries; |
|
68 | 70 | }; |
|
69 | 71 | |
|
70 | 72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | 73 | |
|
72 | 74 | #endif |
@@ -1,634 +1,636 | |||
|
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 <qabstractaxis.h> |
|
23 | 23 | #include <qvaluesaxis.h> |
|
24 | 24 | #include <qcategoriesaxis.h> |
|
25 | 25 | #include <qlineseries.h> |
|
26 | 26 | #include <qareaseries.h> |
|
27 | 27 | #include <qscatterseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qpieseries.h> |
|
30 | 30 | #include <qgroupedbarseries.h> |
|
31 | 31 | #include <qpercentbarseries.h> |
|
32 | 32 | #include <qstackedbarseries.h> |
|
33 | 33 | #include <private/chartdataset_p.h> |
|
34 | 34 | #include <private/domain_p.h> |
|
35 | 35 | #include <tst_definitions.h> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | Q_DECLARE_METATYPE(Domain *) |
|
40 | 40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
43 | 43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
44 | 44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
45 | 45 | |
|
46 | 46 | class tst_ChartDataSet: public QObject { |
|
47 | 47 | |
|
48 | 48 | Q_OBJECT |
|
49 | 49 | |
|
50 | 50 | public Q_SLOTS: |
|
51 | 51 | void initTestCase(); |
|
52 | 52 | void cleanupTestCase(); |
|
53 | 53 | void init(); |
|
54 | 54 | void cleanup(); |
|
55 | 55 | |
|
56 | 56 | private Q_SLOTS: |
|
57 | 57 | void chartdataset_data(); |
|
58 | 58 | void chartdataset(); |
|
59 | 59 | void addSeries_data(); |
|
60 | 60 | void addSeries(); |
|
61 | 61 | void setAxisX_data(); |
|
62 | 62 | void setAxisX(); |
|
63 | 63 | void setAxisY_data(); |
|
64 | 64 | void setAxisY(); |
|
65 | 65 | void removeSeries_data(); |
|
66 | 66 | void removeSeries(); |
|
67 | 67 | void removeAllSeries_data(); |
|
68 | 68 | void removeAllSeries(); |
|
69 | 69 | void seriesCount_data(); |
|
70 | 70 | void seriesCount(); |
|
71 | 71 | void seriesIndex_data(); |
|
72 | 72 | void seriesIndex(); |
|
73 | 73 | void domain_data(); |
|
74 | 74 | void domain(); |
|
75 | 75 | void zoomInDomain_data(); |
|
76 | 76 | void zoomInDomain(); |
|
77 | 77 | /* |
|
78 | 78 | void zoomOutDomain_data(); |
|
79 | 79 | void zoomOutDomain(); |
|
80 | 80 | void scrollDomain_data(); |
|
81 | 81 | void scrollDomain(); |
|
82 | 82 | */ |
|
83 | 83 | private: |
|
84 | 84 | ChartDataSet* m_dataset; |
|
85 | 85 | }; |
|
86 | 86 | |
|
87 | 87 | void tst_ChartDataSet::initTestCase() |
|
88 | 88 | { |
|
89 | 89 | qRegisterMetaType<Domain*>(); |
|
90 | 90 | qRegisterMetaType<QAbstractAxis*>(); |
|
91 | 91 | qRegisterMetaType<QAbstractSeries*>(); |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | void tst_ChartDataSet::cleanupTestCase() |
|
95 | 95 | { |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void tst_ChartDataSet::init() |
|
99 | 99 | { |
|
100 | 100 | m_dataset = new ChartDataSet(); |
|
101 | 101 | } |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | void tst_ChartDataSet::cleanup() |
|
105 | 105 | { |
|
106 | 106 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
107 | 107 | foreach(QAbstractSeries* serie, series) |
|
108 | 108 | { |
|
109 | 109 | m_dataset->removeSeries(serie); |
|
110 | 110 | } |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_ChartDataSet::chartdataset_data() |
|
114 | 114 | { |
|
115 | 115 | } |
|
116 | 116 | |
|
117 | 117 | void tst_ChartDataSet::chartdataset() |
|
118 | 118 | { |
|
119 | 119 | QVERIFY(m_dataset->axisX(0) == 0); |
|
120 | 120 | QVERIFY(m_dataset->axisY(0) == 0); |
|
121 | 121 | QLineSeries* series = new QLineSeries(this); |
|
122 | 122 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
123 | 123 | QVERIFY(m_dataset->domain(series) == 0); |
|
124 | 124 | QVERIFY(m_dataset->axisX(series) == 0); |
|
125 | 125 | QVERIFY(m_dataset->axisY(series) == 0); |
|
126 | 126 | m_dataset->createDefaultAxes(); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | |
|
130 | 130 | void tst_ChartDataSet::addSeries_data() |
|
131 | 131 | { |
|
132 | 132 | QTest::addColumn<QAbstractSeries*>("series"); |
|
133 | 133 | |
|
134 | 134 | QAbstractSeries* line = new QLineSeries(this); |
|
135 | 135 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
136 | 136 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
137 | 137 | QAbstractSeries* spline = new QSplineSeries(this); |
|
138 | 138 | QAbstractSeries* pie = new QPieSeries(this); |
|
139 | 139 | QAbstractSeries* bar = new QGroupedBarSeries(this); |
|
140 | 140 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
141 | 141 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
142 | 142 | |
|
143 | 143 | QTest::newRow("line") << line; |
|
144 | 144 | QTest::newRow("area") << area; |
|
145 | 145 | QTest::newRow("scatter") << scatter; |
|
146 | 146 | QTest::newRow("spline") << spline; |
|
147 | 147 | QTest::newRow("pie") << pie; |
|
148 | 148 | QTest::newRow("bar") << bar; |
|
149 | 149 | QTest::newRow("percent") << percent; |
|
150 | 150 | QTest::newRow("stacked") << stacked; |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | void tst_ChartDataSet::addSeries() |
|
154 | 154 | { |
|
155 | 155 | |
|
156 | 156 | QFETCH(QAbstractSeries*, series); |
|
157 | 157 | |
|
158 | 158 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
159 | 159 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
160 | 160 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
161 | 161 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
162 | 162 | |
|
163 | 163 | m_dataset->addSeries(series); |
|
164 | 164 | m_dataset->createDefaultAxes(); |
|
165 | 165 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
166 | 166 | TRY_COMPARE(spy0.count(), 0); |
|
167 | 167 | }else{ |
|
168 | 168 | TRY_COMPARE(spy0.count(), 2); |
|
169 | 169 | } |
|
170 | 170 | TRY_COMPARE(spy1.count(), 0); |
|
171 | 171 | TRY_COMPARE(spy2.count(), 1); |
|
172 | 172 | TRY_COMPARE(spy3.count(), 0); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | 175 | |
|
176 | 176 | void tst_ChartDataSet::setAxisX_data() |
|
177 | 177 | { |
|
178 | 178 | |
|
179 | 179 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
180 | 180 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
181 | 181 | QTest::addColumn<int>("axisCount"); |
|
182 | 182 | |
|
183 | 183 | QAbstractSeries* line = new QLineSeries(this); |
|
184 | 184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
185 | 185 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
186 | 186 | QAbstractSeries* spline = new QSplineSeries(this); |
|
187 | 187 | QAbstractSeries* pie = new QPieSeries(this); |
|
188 | 188 | QAbstractSeries* bar = new QGroupedBarSeries(this); |
|
189 | 189 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
190 | 190 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
191 | 191 | |
|
192 | 192 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
193 | 193 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
194 | 194 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; |
|
195 | 195 | |
|
196 | 196 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
197 | 197 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; |
|
198 | 198 | |
|
199 | 199 | QList<QAbstractAxis*> axes0; |
|
200 | 200 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); |
|
201 | 201 | axes0 << axes0.last(); |
|
202 | 202 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
203 | 203 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
204 | 204 | << axes0 << 2; |
|
205 | 205 | //TODO: add more test cases |
|
206 | 206 | } |
|
207 | 207 | |
|
208 | 208 | void tst_ChartDataSet::setAxisX() |
|
209 | 209 | { |
|
210 | 210 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
211 | 211 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
212 | 212 | QFETCH(int, axisCount); |
|
213 | 213 | |
|
214 | 214 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
215 | 215 | |
|
216 | 216 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
217 | 217 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
218 | 218 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
219 | 219 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
220 | 220 | |
|
221 | 221 | foreach(QAbstractSeries* series, seriesList){ |
|
222 | 222 | m_dataset->addSeries(series); |
|
223 | 223 | } |
|
224 | 224 | |
|
225 | 225 | TRY_COMPARE(spy0.count(), 0); |
|
226 | 226 | TRY_COMPARE(spy1.count(), 0); |
|
227 | 227 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
228 | 228 | TRY_COMPARE(spy3.count(), 0); |
|
229 | 229 | |
|
230 | 230 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
231 | 231 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
232 | 232 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
233 | 233 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
234 | 234 | |
|
235 | 235 | for(int i=0 ; i < seriesList.count(); i++){ |
|
236 | 236 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
237 | 237 | } |
|
238 | 238 | |
|
239 | 239 | TRY_COMPARE(spy4.count(), axisCount); |
|
240 | 240 | TRY_COMPARE(spy5.count(), 0); |
|
241 | 241 | TRY_COMPARE(spy6.count(), 0); |
|
242 | 242 | TRY_COMPARE(spy7.count(), 0); |
|
243 | 243 | |
|
244 | 244 | for(int i=0 ; i < seriesList.count(); i++){ |
|
245 | 245 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
246 | 246 | } |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void tst_ChartDataSet::setAxisY_data() |
|
250 | 250 | { |
|
251 | 251 | setAxisX_data(); |
|
252 | 252 | } |
|
253 | 253 | |
|
254 | 254 | void tst_ChartDataSet::setAxisY() |
|
255 | 255 | { |
|
256 | 256 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
257 | 257 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
258 | 258 | QFETCH(int, axisCount); |
|
259 | 259 | |
|
260 | 260 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
261 | 261 | |
|
262 | 262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
263 | 263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
264 | 264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
265 | 265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
266 | 266 | |
|
267 | 267 | foreach(QAbstractSeries* series, seriesList){ |
|
268 | 268 | m_dataset->addSeries(series); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | TRY_COMPARE(spy0.count(), 0); |
|
272 | 272 | TRY_COMPARE(spy1.count(), 0); |
|
273 | 273 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
274 | 274 | TRY_COMPARE(spy3.count(), 0); |
|
275 | 275 | |
|
276 | 276 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
277 | 277 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
278 | 278 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
279 | 279 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
280 | 280 | |
|
281 | 281 | for(int i=0 ; i < seriesList.count(); i++){ |
|
282 | 282 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | TRY_COMPARE(spy4.count(), axisCount); |
|
286 | 286 | TRY_COMPARE(spy5.count(), 0); |
|
287 | 287 | TRY_COMPARE(spy6.count(), 0); |
|
288 | 288 | TRY_COMPARE(spy7.count(), 0); |
|
289 | 289 | |
|
290 | 290 | for(int i=0 ; i < seriesList.count(); i++){ |
|
291 | 291 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
292 | 292 | } |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void tst_ChartDataSet::removeSeries_data() |
|
296 | 296 | { |
|
297 | 297 | addSeries_data(); |
|
298 | 298 | } |
|
299 | 299 | |
|
300 | 300 | void tst_ChartDataSet::removeSeries() |
|
301 | 301 | { |
|
302 | 302 | QFETCH(QAbstractSeries*, series); |
|
303 | 303 | |
|
304 | 304 | m_dataset->addSeries(series); |
|
305 | 305 | m_dataset->createDefaultAxes(); |
|
306 | 306 | |
|
307 | 307 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
308 | 308 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
309 | 309 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
310 | 310 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
311 | 311 | |
|
312 | 312 | m_dataset->removeSeries(series); |
|
313 | 313 | |
|
314 | 314 | TRY_COMPARE(spy0.count(), 0); |
|
315 | 315 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
316 | 316 | TRY_COMPARE(spy1.count(), 0); |
|
317 | 317 | } |
|
318 | 318 | else { |
|
319 | 319 | TRY_COMPARE(spy1.count(), 2); |
|
320 | 320 | } |
|
321 | 321 | TRY_COMPARE(spy2.count(), 0); |
|
322 | 322 | TRY_COMPARE(spy3.count(), 1); |
|
323 | 323 | } |
|
324 | 324 | |
|
325 | 325 | void tst_ChartDataSet::removeAllSeries_data() |
|
326 | 326 | { |
|
327 | 327 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
328 | 328 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
329 | 329 | QTest::addColumn<int>("axisCount"); |
|
330 | 330 | |
|
331 | 331 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
332 | 332 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
333 | 333 | << new QScatterSeries(this)) |
|
334 | 334 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) |
|
335 | 335 | << new QValuesAxis(this)) << 3; |
|
336 | 336 | //TODO: |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | void tst_ChartDataSet::removeAllSeries() |
|
340 | 340 | { |
|
341 | 341 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
342 | 342 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
343 | 343 | QFETCH(int, axisCount); |
|
344 | 344 | |
|
345 | 345 | foreach(QAbstractSeries* series, seriesList) { |
|
346 | 346 | m_dataset->addSeries(series); |
|
347 | 347 | } |
|
348 | 348 | |
|
349 | 349 | for (int i = 0; i < seriesList.count(); i++) { |
|
350 | 350 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
354 | 354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
355 | 355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
356 | 356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
357 | 357 | |
|
358 | 358 | m_dataset->removeAllSeries(); |
|
359 | 359 | |
|
360 | 360 | TRY_COMPARE(spy0.count(), 0); |
|
361 | 361 | TRY_COMPARE(spy1.count(), axisCount); |
|
362 | 362 | TRY_COMPARE(spy2.count(), 0); |
|
363 | 363 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
364 | 364 | } |
|
365 | 365 | |
|
366 | 366 | |
|
367 | 367 | void tst_ChartDataSet::seriesCount_data() |
|
368 | 368 | { |
|
369 | 369 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
370 | 370 | QTest::addColumn<int>("seriesCount"); |
|
371 | 371 | |
|
372 | 372 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
373 | 373 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void tst_ChartDataSet::seriesCount() |
|
377 | 377 | { |
|
378 | 378 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
379 | 379 | QFETCH(int, seriesCount); |
|
380 | 380 | |
|
381 | 381 | foreach(QAbstractSeries* series, seriesList){ |
|
382 | 382 | m_dataset->addSeries(series); |
|
383 | 383 | } |
|
384 | 384 | |
|
385 | 385 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
386 | 386 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
387 | 387 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
388 | 388 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
389 | 389 | |
|
390 | 390 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
391 | 391 | TRY_COMPARE(spy0.count(), 0); |
|
392 | 392 | TRY_COMPARE(spy1.count(), 0); |
|
393 | 393 | TRY_COMPARE(spy2.count(), 0); |
|
394 | 394 | TRY_COMPARE(spy3.count(), 0); |
|
395 | 395 | } |
|
396 | 396 | |
|
397 | 397 | void tst_ChartDataSet::seriesIndex_data() |
|
398 | 398 | { |
|
399 | 399 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
400 | 400 | |
|
401 | 401 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
402 | 402 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | void tst_ChartDataSet::seriesIndex() |
|
406 | 406 | { |
|
407 | 407 | |
|
408 | 408 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
409 | 409 | |
|
410 | 410 | foreach(QAbstractSeries* series, seriesList) { |
|
411 | 411 | m_dataset->addSeries(series); |
|
412 | 412 | } |
|
413 | 413 | |
|
414 | 414 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
415 | 415 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
416 | 416 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
417 | 417 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
418 | 418 | |
|
419 | 419 | for (int i = 0; i < seriesList.count(); i++) { |
|
420 | 420 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
421 | 421 | } |
|
422 | 422 | |
|
423 | 423 | TRY_COMPARE(spy0.count(), 0); |
|
424 | 424 | TRY_COMPARE(spy1.count(), 0); |
|
425 | 425 | TRY_COMPARE(spy2.count(), 0); |
|
426 | 426 | TRY_COMPARE(spy3.count(), 0); |
|
427 | 427 | |
|
428 | 428 | foreach(QAbstractSeries* series, seriesList) { |
|
429 | 429 | m_dataset->removeSeries(series); |
|
430 | 430 | } |
|
431 | 431 | |
|
432 | 432 | for (int i = 0; i < seriesList.count(); i++) { |
|
433 | 433 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
434 | 434 | } |
|
435 | 435 | |
|
436 | 436 | foreach(QAbstractSeries* series, seriesList) { |
|
437 | 437 | m_dataset->addSeries(series); |
|
438 | 438 | } |
|
439 | 439 | |
|
440 | 440 | for (int i = 0; i < seriesList.count(); i++) { |
|
441 | 441 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
442 | 442 | } |
|
443 | 443 | |
|
444 | 444 | m_dataset->removeSeries(seriesList.at(1)); |
|
445 | 445 | |
|
446 | 446 | for (int i = 0; i < seriesList.count(); i++) { |
|
447 | 447 | if (i != 1) |
|
448 | 448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
449 | 449 | else |
|
450 | 450 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
451 | 451 | } |
|
452 | 452 | |
|
453 | 453 | m_dataset->addSeries(seriesList.at(1)); |
|
454 | 454 | |
|
455 | 455 | for (int i = 0; i < seriesList.count(); i++) { |
|
456 | 456 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | m_dataset->removeSeries(seriesList.at(2)); |
|
460 | 460 | |
|
461 | 461 | for (int i = 0; i < seriesList.count(); i++) { |
|
462 | 462 | if (i != 2) |
|
463 | 463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
464 | 464 | else |
|
465 | 465 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
466 | 466 | } |
|
467 | 467 | |
|
468 | 468 | m_dataset->removeSeries(seriesList.at(0)); |
|
469 | 469 | |
|
470 | 470 | for (int i = 0; i < seriesList.count(); i++) { |
|
471 | 471 | if (i != 2 && i != 0) |
|
472 | 472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
473 | 473 | else |
|
474 | 474 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | m_dataset->addSeries(seriesList.at(2)); |
|
478 | 478 | m_dataset->addSeries(seriesList.at(0)); |
|
479 | 479 | |
|
480 | 480 | for (int i = 0; i < seriesList.count(); i++) { |
|
481 | 481 | if (i == 2) |
|
482 | 482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
483 | 483 | else if (i == 0) |
|
484 | 484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
485 | 485 | else |
|
486 | 486 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
487 | 487 | } |
|
488 | 488 | |
|
489 | 489 | } |
|
490 | 490 | |
|
491 | 491 | void tst_ChartDataSet::domain_data() |
|
492 | 492 | { |
|
493 | 493 | addSeries_data(); |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | void tst_ChartDataSet::domain() |
|
497 | 497 | { |
|
498 | 498 | QFETCH(QAbstractSeries*, series); |
|
499 | 499 | |
|
500 | 500 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
501 | 501 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
502 | 502 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
503 | 503 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
504 | 504 | |
|
505 | 505 | m_dataset->addSeries(series); |
|
506 | 506 | QVERIFY(m_dataset->domain(series)); |
|
507 | 507 | |
|
508 | 508 | |
|
509 | 509 | TRY_COMPARE(spy0.count(), 0); |
|
510 | 510 | TRY_COMPARE(spy1.count(), 0); |
|
511 | 511 | TRY_COMPARE(spy2.count(), 1); |
|
512 | 512 | |
|
513 | 513 | QList<QVariant> arguments = spy2.takeFirst(); |
|
514 | 514 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
515 | 515 | QVERIFY(m_dataset->domain(series) == domain); |
|
516 | 516 | |
|
517 | 517 | TRY_COMPARE(spy3.count(), 0); |
|
518 | 518 | |
|
519 | 519 | } |
|
520 | 520 | |
|
521 | 521 | void tst_ChartDataSet::zoomInDomain_data() |
|
522 | 522 | { |
|
523 | 523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
524 | 524 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | void tst_ChartDataSet::zoomInDomain() |
|
528 | 528 | { |
|
529 | 529 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
530 | 530 | |
|
531 | 531 | foreach(QAbstractSeries* series, seriesList) { |
|
532 | 532 | m_dataset->addSeries(series); |
|
533 | 533 | } |
|
534 | 534 | |
|
535 | 535 | /* |
|
536 | 536 | QValuesAxis* axis = new QValuesAxis(); |
|
537 | 537 | |
|
538 | 538 | for (int i = 0; i < seriesList.count(); i++) { |
|
539 | 539 | m_dataset->setAxisX(seriesList.at(i), axis); |
|
540 | 540 | } |
|
541 | 541 | */ |
|
542 | 542 | m_dataset->createDefaultAxes(); |
|
543 | 543 | |
|
544 | ||
|
545 | ||
|
544 | 546 | QList<QSignalSpy*> spyList; |
|
545 | 547 | |
|
546 | 548 | foreach(QAbstractSeries* series, seriesList) { |
|
547 | 549 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
548 | 550 | } |
|
549 | 551 | |
|
550 | 552 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
551 | 553 | |
|
552 | 554 | foreach(QSignalSpy* spy, spyList) { |
|
553 | 555 | TRY_COMPARE(spy->count(), 1); |
|
554 | 556 | } |
|
555 | 557 | |
|
556 | 558 | qDeleteAll(spyList); |
|
557 | 559 | } |
|
558 | 560 | |
|
559 | 561 | /* |
|
560 | 562 | void tst_ChartDataSet::zoomOutDomain_data() |
|
561 | 563 | { |
|
562 | 564 | addSeries_data(); |
|
563 | 565 | } |
|
564 | 566 | |
|
565 | 567 | void tst_ChartDataSet::zoomOutDomain() |
|
566 | 568 | { |
|
567 | 569 | QFETCH(QLineSeries*, series0); |
|
568 | 570 | QFETCH(QAxis*, axis0); |
|
569 | 571 | QFETCH(QLineSeries*, series1); |
|
570 | 572 | QFETCH(QAxis*, axis1); |
|
571 | 573 | QFETCH(QLineSeries*, series2); |
|
572 | 574 | QFETCH(QAxis*, axis2); |
|
573 | 575 | QFETCH(int, axisCount); |
|
574 | 576 | |
|
575 | 577 | Q_UNUSED(axisCount); |
|
576 | 578 | |
|
577 | 579 | m_dataset->addSeries(series0, axis0); |
|
578 | 580 | m_dataset->addSeries(series1, axis1); |
|
579 | 581 | m_dataset->addSeries(series2, axis2); |
|
580 | 582 | |
|
581 | 583 | Domain* domain0 = m_dataset->domain(series0); |
|
582 | 584 | Domain* domain1 = m_dataset->domain(series1); |
|
583 | 585 | Domain* domain2 = m_dataset->domain(series2); |
|
584 | 586 | |
|
585 | 587 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
586 | 588 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
587 | 589 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
588 | 590 | |
|
589 | 591 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
590 | 592 | |
|
591 | 593 | TRY_COMPARE(spy0.count(), 1); |
|
592 | 594 | TRY_COMPARE(spy1.count(), 1); |
|
593 | 595 | TRY_COMPARE(spy2.count(), 1); |
|
594 | 596 | } |
|
595 | 597 | |
|
596 | 598 | void tst_ChartDataSet::scrollDomain_data() |
|
597 | 599 | { |
|
598 | 600 | addSeries_data(); |
|
599 | 601 | } |
|
600 | 602 | |
|
601 | 603 | void tst_ChartDataSet::scrollDomain() |
|
602 | 604 | { |
|
603 | 605 | QFETCH(QLineSeries*, series0); |
|
604 | 606 | QFETCH(QAxis*, axis0); |
|
605 | 607 | QFETCH(QLineSeries*, series1); |
|
606 | 608 | QFETCH(QAxis*, axis1); |
|
607 | 609 | QFETCH(QLineSeries*, series2); |
|
608 | 610 | QFETCH(QAxis*, axis2); |
|
609 | 611 | QFETCH(int, axisCount); |
|
610 | 612 | |
|
611 | 613 | Q_UNUSED(axisCount); |
|
612 | 614 | |
|
613 | 615 | m_dataset->addSeries(series0, axis0); |
|
614 | 616 | m_dataset->addSeries(series1, axis1); |
|
615 | 617 | m_dataset->addSeries(series2, axis2); |
|
616 | 618 | |
|
617 | 619 | Domain* domain0 = m_dataset->domain(series0); |
|
618 | 620 | Domain* domain1 = m_dataset->domain(series1); |
|
619 | 621 | Domain* domain2 = m_dataset->domain(series2); |
|
620 | 622 | |
|
621 | 623 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
622 | 624 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
623 | 625 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
624 | 626 | |
|
625 | 627 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
626 | 628 | |
|
627 | 629 | TRY_COMPARE(spy0.count(), 1); |
|
628 | 630 | TRY_COMPARE(spy1.count(), 1); |
|
629 | 631 | TRY_COMPARE(spy2.count(), 1); |
|
630 | 632 | } |
|
631 | 633 | */ |
|
632 | 634 | QTEST_MAIN(tst_ChartDataSet) |
|
633 | 635 | #include "tst_chartdataset.moc" |
|
634 | 636 |
General Comments 0
You need to be logged in to leave comments.
Login now