##// END OF EJS Templates
Minor fix to QXYModelMapper
Marek Rosa -
r1310:3b689b88a3df
parent child
Show More
@@ -1,32 +1,33
1 1 #include "qhxymodelmapper.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
6 6 QXYModelMapper(parent)
7 7 {
8 QXYModelMapper::setOrientation(Qt::Horizontal);
8 9 }
9 10
10 11 int QHXYModelMapper::xRow() const
11 12 {
12 13 return QXYModelMapper::xSection();
13 14 }
14 15
15 16 void QHXYModelMapper::setXRow(int xRow)
16 17 {
17 18 return QXYModelMapper::setXSection(xRow);
18 19 }
19 20
20 21 int QHXYModelMapper::yRow() const
21 22 {
22 23 return QXYModelMapper::ySection();
23 24 }
24 25
25 26 void QHXYModelMapper::setYRow(int yRow)
26 27 {
27 28 return QXYModelMapper::setYSection(yRow);
28 29 }
29 30
30 31 #include "moc_qhxymodelmapper.cpp"
31 32
32 33 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,32 +1,33
1 1 #include "qvxymodelmapper.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
6 6 QXYModelMapper(parent)
7 7 {
8 QXYModelMapper::setOrientation(Qt::Vertical);
8 9 }
9 10
10 11 int QVXYModelMapper::xColumn() const
11 12 {
12 13 return QXYModelMapper::xSection();
13 14 }
14 15
15 16 void QVXYModelMapper::setXColumn(int xColumn)
16 17 {
17 18 return QXYModelMapper::setXSection(xColumn);
18 19 }
19 20
20 21 int QVXYModelMapper::yColumn() const
21 22 {
22 23 return QXYModelMapper::ySection();
23 24 }
24 25
25 26 void QVXYModelMapper::setYColumn(int yColumn)
26 27 {
27 28 return QXYModelMapper::setYSection(yColumn);
28 29 }
29 30
30 31 #include "moc_qvxymodelmapper.cpp"
31 32
32 33 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,573 +1,582
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "tablewidget.h"
22 22 #include <QGridLayout>
23 23 #include <QTableView>
24 24 #include <QChart>
25 25 #include <QStyledItemDelegate>
26 26 #include <QLineSeries>
27 27 #include <QSplineSeries>
28 28 #include <QScatterSeries>
29 29 #include <QVXYModelMapper>
30 #include <QHXYModelMapper>
30 31 #include "customtablemodel.h"
31 32 #include <QPieSeries>
32 33 #include <QVPieModelMapper>
33 34 #include <QPieSlice>
34 35 #include <QAreaSeries>
35 36 #include <QBarSeries>
36 37 #include <QGroupedBarSeries>
37 38 #include <QBarSet>
38 39 #include <QVBarModelMapper>
39 40 #include <QPushButton>
40 41 #include <QRadioButton>
41 42 #include <QLabel>
42 43 #include <QSpinBox>
43 44 #include <QTime>
44 45 #include <QHeaderView>
45 46
46 47 TableWidget::TableWidget(QWidget *parent)
47 48 : QWidget(parent),
48 49 m_series(0),
49 50 m_mapper(0),
50 51 m_model(0),
51 52 m_pieMapper(0),
52 53 m_pieMapper2(0)
53 54 // specialPie(0)
54 55 {
55 56 setGeometry(1900, 100, 1000, 600);
56 57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
57 58 // create simple model for storing data
58 59 // user's table data model
59 60 m_model = new CustomTableModel;
60 61 m_tableView = new QTableView;
61 62 m_tableView->setModel(m_model);
62 63 // m_tableView->setMinimumHeight(300);
63 64 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
64 65 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
65 66
66 67 m_chart = new QChart;
67 68 m_chart->legend()->setVisible(true);
68 69 m_chart->setAnimationOptions(QChart::SeriesAnimations);
69 70 m_chartView = new QChartView(m_chart);
70 71 m_chartView->setRenderHint(QPainter::Antialiasing);
71 72 m_chartView->setMinimumSize(640, 480);
72 73
73 74 // add, remove data buttons
74 75 QPushButton* addRowAboveButton = new QPushButton("Add row above");
75 76 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
76 77
77 78 QPushButton* addRowBelowButton = new QPushButton("Add row below");
78 79 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
79 80
80 81 QPushButton* removeRowButton = new QPushButton("Remove row");
81 82 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
82 83
83 84 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
84 85 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
85 86
86 87 QPushButton* removeColumnButton = new QPushButton("Remove column");
87 88 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
88 89
89 90 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
90 91 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
91 92
92 93 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
93 94 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
94 95
95 96 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
96 97 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
97 98
98 99 QPushButton* xyTestButton = new QPushButton("Append XY point");
99 100 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
100 101
101 102
102 103 QLabel *spinBoxLabel = new QLabel("Rows affected:");
103 104
104 105 // spin box for setting number of affected items (add, remove)
105 106 m_linesCountSpinBox = new QSpinBox;
106 107 m_linesCountSpinBox->setRange(1, 10);
107 108 m_linesCountSpinBox->setValue(1);
108 109
109 110 // buttons layout
110 111 QVBoxLayout* buttonsLayout = new QVBoxLayout;
111 112 buttonsLayout->addWidget(spinBoxLabel);
112 113 buttonsLayout->addWidget(m_linesCountSpinBox);
113 114 // buttonsLayout->addWidget(addRowAboveButton);
114 115 buttonsLayout->addWidget(addRowBelowButton);
115 116 buttonsLayout->addWidget(removeRowButton);
116 117 // buttonsLayout->addWidget(addColumnRightButton);
117 118 // buttonsLayout->addWidget(removeColumnButton);
118 119 buttonsLayout->addWidget(specialPieButton);
119 120 buttonsLayout->addWidget(specialPieButton2);
120 121 buttonsLayout->addWidget(specialPieButton3);
121 122 buttonsLayout->addWidget(xyTestButton);
122 123 buttonsLayout->addStretch();
123 124
124 125 // chart type radio buttons
125 126 m_lineRadioButton = new QRadioButton("Line");
126 127 m_splineRadioButton = new QRadioButton("Spline");
127 128 m_scatterRadioButton = new QRadioButton("Scatter");
128 129 m_pieRadioButton = new QRadioButton("Pie");
129 130 m_areaRadioButton = new QRadioButton("Area");
130 131 m_barRadioButton = new QRadioButton("Bar");
131 132
132 133 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 134 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 135 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 136 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 137 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 138 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 m_barRadioButton->setChecked(true);
139 m_lineRadioButton->setChecked(true);
139 140
140 141 // radio buttons layout
141 142 QVBoxLayout* radioLayout = new QVBoxLayout;
142 143 radioLayout->addWidget(m_lineRadioButton);
143 144 radioLayout->addWidget(m_splineRadioButton);
144 145 radioLayout->addWidget(m_scatterRadioButton);
145 146 radioLayout->addWidget(m_pieRadioButton);
146 147 // radioLayout->addWidget(m_areaRadioButton);
147 148 radioLayout->addWidget(m_barRadioButton);
148 149 radioLayout->addStretch();
149 150
150 151 // create main layout
151 152 QGridLayout* mainLayout = new QGridLayout;
152 153 mainLayout->addLayout(buttonsLayout, 2, 0);
153 154 mainLayout->addLayout(radioLayout, 3, 0);
154 155 mainLayout->addWidget(m_tableView, 1, 0);
155 156 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
156 157 setLayout(mainLayout);
157 158 m_lineRadioButton->setFocus();
158 159 }
159 160
160 161 void TableWidget::addRowAbove()
161 162 {
162 163 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
163 164
164 165 }
165 166
166 167 void TableWidget::addRowBelow()
167 168 {
168 169 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
169 170
170 171 }
171 172
172 173 void TableWidget::removeRow()
173 174 {
174 175 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
175 176 }
176 177
177 178 void TableWidget::addColumnRight()
178 179 {
179 180 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
180 181 }
181 182
182 183 void TableWidget::removeColumn()
183 184 {
184 185 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
185 186 }
186 187
187 188 void TableWidget::updateChartType(bool toggle)
188 189 {
189 190 // this if is needed, so that the function is only called once.
190 191 // For the radioButton that was enabled.
191 192 if (toggle) {
192 193 // specialPie = 0;
193 194 m_chart->removeAllSeries();
194 195 m_series = 0;
195 196 // m_chart->axisX()->setNiceNumbersEnabled(false);
196 197 // m_chart->axisY()->setNiceNumbersEnabled(false);
197 198 if (m_mapper) {
198 199 m_mapper->deleteLater();
199 200 m_mapper = 0;
200 201 }
201 202
202 203 if (m_pieMapper) {
203 204 m_pieMapper->deleteLater();
204 205 m_pieMapper = 0;
205 206 }
206 207
207 208 if (m_pieMapper2) {
208 209 m_pieMapper2->deleteLater();
209 210 m_pieMapper2 = 0;
210 211 }
211 212
212 213 // if (m_series) {
213 214 // delete m_series;
214 215 // m_series = 0;
215 216 // }
216 217
217 218 // renable axes of the chart (pie hides them)
218 219 // x axis
219 220 QAxis *axis = m_chart->axisX();
220 221 axis->setAxisVisible(true);
221 222 axis->setGridLineVisible(true);
222 223 axis->setLabelsVisible(true);
223 224
224 225 // y axis
225 226 axis = m_chart->axisY();
226 227 axis->setAxisVisible(true);
227 228 axis->setGridLineVisible(true);
228 229 axis->setLabelsVisible(true);
229 230
230 231 m_model->clearMapping();
231 232
232 233 QString seriesColorHex = "#000000";
233 234 // QPen pen;
234 235 // pen.setWidth(2);
235 236
236 237 if (m_lineRadioButton->isChecked())
237 238 {
238 239 m_chart->setAnimationOptions(QChart::NoAnimation);
239 240
240 241 // series 1
241 242 m_series = new QLineSeries;
242 243
243 m_mapper = new QVXYModelMapper;
244 m_mapper = new QHXYModelMapper;
244 245 m_mapper->setModel(m_model);
245 246 m_mapper->setSeries(m_series);
246 m_mapper->setXColumn(0);
247 m_mapper->setYColumn(1);
247 m_mapper->setXRow(0);
248 m_mapper->setYRow(1);
248 249 m_mapper->setFirst(3);
249 250 m_mapper->setCount(4);
250 251
252 // m_mapper = new QVXYModelMapper;
253 // m_mapper->setModel(m_model);
254 // m_mapper->setSeries(m_series);
255 // m_mapper->setXColumn(0);
256 // m_mapper->setYColumn(1);
257 // m_mapper->setFirst(3);
258 // m_mapper->setCount(4);
259
251 260 // m_series->setModelMapping(0,1, Qt::Vertical);
252 261 // m_series->setModelMappingRange(3, 4);
253 262 m_chart->addSeries(m_series);
254 263 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
255 264 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
256 265
257 266 // // series 2
258 267 // m_series = new QLineSeries;
259 268 // m_series->setModel(m_model);
260 269
261 270 // mapper = new QXYModelMapper;
262 271 // mapper->setMapX(3);
263 272 // mapper->setMapY(4);
264 273 // // mapper->setFirst(3);
265 274 // // mapper->setCount(4);
266 275 // m_series->setModelMapper(mapper);
267 276 // // m_series->setModelMapping(2,3, Qt::Vertical);
268 277 // m_chart->addSeries(m_series);
269 278 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
270 279 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
271 280
272 281 // // series 3
273 282 // m_series = new QLineSeries;
274 283 // m_series->setModel(m_model);
275 284
276 285 // mapper = new QXYModelMapper;
277 286 // mapper->setMapX(5);
278 287 // mapper->setMapY(6);
279 288 // mapper->setFirst(2);
280 289 // mapper->setCount(-1);
281 290 // m_series->setModelMapper(mapper);
282 291 // // m_series->setModelMapping(4,5, Qt::Vertical);
283 292 // // m_series->setModelMappingRange(2, -1);
284 293 // m_chart->addSeries(m_series);
285 294 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
286 295 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
287 296 }
288 297 else if (m_splineRadioButton->isChecked())
289 298 {
290 299 m_chart->setAnimationOptions(QChart::NoAnimation);
291 300
292 301 // series 1
293 302 m_series = new QSplineSeries;
294 303 // m_series->setModel(m_model);
295 304
296 m_mapper = new QVXYModelMapper;
297 m_mapper->setSeries(m_series);
298 m_mapper->setModel(m_model);
299 m_mapper->setXColumn(0);
300 m_mapper->setYColumn(1);
301 m_mapper->setFirst(0);
302 m_mapper->setCount(-1);
305 // m_mapper = new QVXYModelMapper;
306 // m_mapper->setSeries(m_series);
307 // m_mapper->setModel(m_model);
308 // m_mapper->setXColumn(0);
309 // m_mapper->setYColumn(1);
310 // m_mapper->setFirst(0);
311 // m_mapper->setCount(-1);
303 312
304 313 // m_series->setModelMapper(mapper);
305 314
306 315 m_chart->addSeries(m_series);
307 316 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
308 317 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
309 318
310 319 // // series 2
311 320 // m_series = new QSplineSeries;
312 321 // m_series->setModel(m_model);
313 322
314 323 // mapper = new QXYModelMapper;
315 324 // mapper->setMapX(2);
316 325 // mapper->setMapY(3);
317 326 // mapper->setFirst(2);
318 327 // mapper->setCount(4);
319 328
320 329 // m_series->setModelMapper(mapper);
321 330
322 331 // m_chart->addSeries(m_series);
323 332 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
324 333 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
325 334
326 335 // // series 3
327 336 // m_series = new QSplineSeries;
328 337 // m_series->setModel(m_model);
329 338
330 339 // mapper = new QXYModelMapper;
331 340 // mapper->setMapX(4);
332 341 // mapper->setMapY(5);
333 342 // mapper->setFirst(2);
334 343 // mapper->setCount(-1);
335 344
336 345 // m_series->setModelMapper(mapper);
337 346
338 347 // m_chart->addSeries(m_series);
339 348 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
340 349 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
341 350 } else if (m_scatterRadioButton->isChecked())
342 351 {
343 352 m_chart->setAnimationOptions(QChart::NoAnimation);
344 353
345 354 // series 1
346 355 m_series = new QScatterSeries;
347 356
348 m_mapper = new QVXYModelMapper;
349 m_mapper->setSeries(m_series);
350 m_mapper->setModel(m_model);
351 m_mapper->setXColumn(0);
352 m_mapper->setYColumn(1);
353 m_mapper->setFirst(0);
354 m_mapper->setCount(-1);
357 // m_mapper = new QVXYModelMapper;
358 // m_mapper->setSeries(m_series);
359 // m_mapper->setModel(m_model);
360 // m_mapper->setXColumn(0);
361 // m_mapper->setYColumn(1);
362 // m_mapper->setFirst(0);
363 // m_mapper->setCount(-1);
355 364
356 365 m_chart->addSeries(m_series);
357 366 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
358 367 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
359 368
360 369 // // series 2
361 370 // m_series = new QScatterSeries;
362 371 // m_series->setModel(m_model);
363 372 // m_series->setModelMapping(2,3, Qt::Vertical);
364 373 // // m_series->setModelMappingRange(1, 6);
365 374 // // series->setModelMapping(2,3, Qt::Horizontal);
366 375 // m_chart->addSeries(m_series);
367 376
368 377 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
369 378 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
370 379
371 380 // // series 3
372 381 // m_series = new QScatterSeries;
373 382 // m_series->setModel(m_model);
374 383 // m_series->setModelMapping(4,5, Qt::Vertical);
375 384 // // series->setModelMapping(4,5, Qt::Horizontal);
376 385 // m_chart->addSeries(m_series);
377 386 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
378 387 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
379 388 } else if (m_pieRadioButton->isChecked()) {
380 389 m_chart->setAnimationOptions(QChart::SeriesAnimations);
381 390
382 391 // pie 1
383 392 m_pieSeries = new QPieSeries;
384 393
385 394 m_pieMapper = new QVPieModelMapper;
386 395 m_pieMapper->setValuesColumn(1);
387 396 m_pieMapper->setLabelsColumn(7);
388 397 m_pieMapper->setSeries(m_pieSeries);
389 398 m_pieMapper->setModel(m_model);
390 399 m_pieMapper->setFirst(2);
391 400 // m_pieMapper->setCount(5);
392 401 // pieSeries->setModelMapper(mapper);
393 402
394 403 m_pieSeries->setLabelsVisible(true);
395 404 m_pieSeries->setPieSize(0.35);
396 405 m_pieSeries->setHorizontalPosition(0.25);
397 406 m_pieSeries->setVerticalPosition(0.35);
398 407
399 408 m_chart->addSeries(m_pieSeries);
400 409 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
401 410 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
402 411
403 412
404 413 // pieSeries->slices().at(0)->setValue(400);
405 414 // pieSeries->slices().at(0)->setLabel(QString("36"));
406 415
407 416 // pie 2
408 417 m_pieSeries2 = new QPieSeries;
409 418
410 419 m_pieMapper2 = new QVPieModelMapper;
411 420 m_pieMapper2->setValuesColumn(0);
412 421 m_pieMapper2->setLabelsColumn(7);
413 422 m_pieMapper2->setModel(m_model);
414 423 m_pieMapper2->setSeries(m_pieSeries2);
415 424 m_pieMapper2->setFirst(2);
416 425
417 426 m_pieSeries2->setLabelsVisible(true);
418 427 m_pieSeries2->setPieSize(0.35);
419 428 m_pieSeries2->setHorizontalPosition(0.75);
420 429 m_pieSeries2->setVerticalPosition(0.65);
421 430 m_chart->addSeries(m_pieSeries2);
422 431 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
423 432 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
424 433
425 434 // // pie 3
426 435 // pieSeries = new QPieSeries;
427 436 // pieSeries->setModel(m_model);
428 437 // pieSeries->setModelMapping(2,2, Qt::Vertical);
429 438 // pieSeries->setLabelsVisible(true);
430 439 // pieSeries->setPieSize(0.35);
431 440 // pieSeries->setHorizontalPosition(0.5);
432 441 // pieSeries->setVerticalPosition(0.75);
433 442 // m_chart->addSeries(pieSeries);
434 443 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
435 444 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
436 445
437 446 // // special pie
438 447 // specialPie = new QPieSeries;
439 448 // specialPie->append(17, "1");
440 449 // specialPie->append(45, "2");
441 450 // specialPie->append(77, "3");
442 451 // specialPie->append(37, "4");
443 452 // specialPie->append(27, "5");
444 453 // specialPie->append(47, "6");
445 454 // specialPie->setPieSize(0.35);
446 455 // specialPie->setHorizontalPosition(0.8);
447 456 // specialPie->setVerticalPosition(0.75);
448 457 // specialPie->setLabelsVisible(true);
449 458 // m_chart->addSeries(specialPie);
450 459 }
451 460 // else if (m_areaRadioButton->isChecked())
452 461 // {
453 462 // m_chart->setAnimationOptions(QChart::NoAnimation);
454 463
455 464 // QLineSeries* upperLineSeries = new QLineSeries;
456 465 // upperLineSeries->setModel(m_model);
457 466 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
458 467 // // upperLineSeries->setModelMappingRange(1, 5);
459 468 // QLineSeries* lowerLineSeries = new QLineSeries;
460 469 // lowerLineSeries->setModel(m_model);
461 470 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
462 471 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
463 472 // m_chart->addSeries(areaSeries);
464 473 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
465 474 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
466 475 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
467 476 // }
468 477 else if (m_barRadioButton->isChecked())
469 478 {
470 479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
471 480
472 481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
473 482 // barSeries->setCategories(QStringList());
474 483 // barSeries->setModel(m_model);
475 484 // barSeries->setModelMappingRange(2, 5);
476 485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
477 486
478 487 int first = 3;
479 488 // int count = 4;
480 489 QVBarModelMapper *mapper = new QVBarModelMapper;
481 490 mapper->setCategoriesSection(5);
482 491 mapper->setFirstBarSection(2);
483 492 mapper->setLastBarSection(4);
484 493 mapper->setFirst(first);
485 494 // mapper->setCount(count);
486 495 mapper->setSeries(barSeries);
487 496 mapper->setModel(m_model);
488 497 // barSeries->setModelMapper(mapper);
489 498 m_chart->addSeries(barSeries);
490 499 QList<QBarSet*> barsets = barSeries->barSets();
491 500 for (int i = 0; i < barsets.count(); i++) {
492 501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
493 502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
494 503 }
495 504 }
496 505
497 506
498 507 if (!m_barRadioButton->isChecked()) {
499 508 m_chart->axisX()->setRange(0, 500);
500 509 m_chart->axisY()->setRange(0, 220);
501 510 }
502 511 m_chart->legend()->setVisible(true);
503 512
504 513 // repaint table view colors
505 514 m_tableView->repaint();
506 515 m_tableView->setFocus();
507 516 }
508 517 }
509 518
510 519 void TableWidget::testPie()
511 520 {
512 521 // m_pieMapper->setCount(-1);
513 522 QPieSlice *slice = new QPieSlice("Hehe", 145);
514 523 slice->setLabelVisible();
515 524 m_pieSeries->append(slice);
516 525
517 526 slice = new QPieSlice("Hoho", 34);
518 527 slice->setLabelVisible();
519 528 m_pieSeries->append(slice);
520 529 // m_series->modelMapper()->setMapX(4);
521 530 // m_tableView->setColumnWidth(10, 250);
522 531 // if (specialPie) {
523 532 // specialPie->remove(specialPie->slices().at(2));
524 533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
525 534 // specialPie->append(4, "heloo");
526 535 // }
527 536 }
528 537
529 538 void TableWidget::testPie2()
530 539 {
531 540 QPieSlice *slice;
532 541 if (m_pieSeries->count() > 0) {
533 542 slice = m_pieSeries->slices().last();
534 543 m_pieSeries->remove(slice);
535 544 }
536 545
537 546 if (m_pieSeries->count() > 0) {
538 547 slice = m_pieSeries->slices().first();
539 548 m_pieSeries->remove(slice);
540 549 }
541 550 }
542 551
543 552 void TableWidget::testPie3()
544 553 {
545 554 QPieSlice *slice;
546 555 if (m_pieSeries->count() > 0) {
547 556 slice = m_pieSeries->slices().last();
548 557 slice->setLabel("Dalej");
549 558 slice->setValue(222);
550 559 }
551 560
552 561 if (m_pieSeries->count() > 0) {
553 562 slice = m_pieSeries->slices().first();
554 563 slice->setLabel("Prawie");
555 564 slice->setValue(111);
556 565 }
557 566 }
558 567
559 568 void TableWidget::testXY()
560 569 {
561 570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
562 571 // m_series->append(QPointF(150, 75));
563 572 // }
564 573
565 574 if (m_series->count() > 0) {
566 575 m_series->remove(m_series->points().last());
567 576 }
568 577 }
569 578
570 579 TableWidget::~TableWidget()
571 580 {
572 581
573 582 }
@@ -1,82 +1,83
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 TABLEWIDGET_H
22 22 #define TABLEWIDGET_H
23 23
24 24 #include <QtGui/QWidget>
25 25 //#include <QChartGlobal>
26 26 #include "qchartview.h"
27 27 //#include "qxyseries.h"
28 28 #include <QPieSeries>
29 29 #include <QVPieModelMapper>
30 30 #include <QVXYModelMapper>
31 #include <QHXYModelMapper>
31 32
32 33 class CustomTableModel;
33 34 class QTableView;
34 35 class QRadioButton;
35 36 class QSpinBox;
36 37
37 38 QTCOMMERCIALCHART_USE_NAMESPACE
38 39
39 40 class TableWidget : public QWidget
40 41 {
41 42 Q_OBJECT
42 43
43 44 public:
44 45 TableWidget(QWidget *parent = 0);
45 46 ~TableWidget();
46 47
47 48
48 49 public slots:
49 50 void addRowAbove();
50 51 void addRowBelow();
51 52 void removeRow();
52 53 void addColumnRight();
53 54 void removeColumn();
54 55 void updateChartType(bool toggle);
55 56 void testPie();
56 57 void testPie2();
57 58 void testPie3();
58 59
59 60 void testXY();
60 61
61 62 private:
62 63 QChartView* m_chartView;
63 64 QChart* m_chart;
64 65 QXYSeries* m_series;
65 QVXYModelMapper *m_mapper;
66 QHXYModelMapper *m_mapper;
66 67 CustomTableModel* m_model;
67 68 QTableView* m_tableView;
68 69 QRadioButton* m_lineRadioButton;
69 70 QRadioButton* m_splineRadioButton;
70 71 QRadioButton* m_scatterRadioButton;
71 72 QRadioButton* m_pieRadioButton;
72 73 QRadioButton* m_areaRadioButton;
73 74 QRadioButton* m_barRadioButton;
74 75 QSpinBox* m_linesCountSpinBox;
75 76 QVPieModelMapper *m_pieMapper;
76 77 QPieSeries* m_pieSeries;
77 78 QVPieModelMapper *m_pieMapper2;
78 79 QPieSeries* m_pieSeries2;
79 80 // QPieSeries* specialPie;
80 81 };
81 82
82 83 #endif // TABLEWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now