@@ -1,311 +1,333 | |||
|
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 <QStyledItemDelegate> |
|
25 | 25 | #include <QLineSeries> |
|
26 | 26 | #include <QSplineSeries> |
|
27 | 27 | #include <QScatterSeries> |
|
28 | 28 | #include "customtablemodel.h" |
|
29 | 29 | #include <QPieSeries> |
|
30 | 30 | #include <QPieSlice> |
|
31 | 31 | #include <QAreaSeries> |
|
32 | 32 | #include <QBarSeries> |
|
33 | 33 | #include <QBarSet> |
|
34 | 34 | #include <QPushButton> |
|
35 | 35 | #include <QRadioButton> |
|
36 | #include <QLabel> | |
|
36 | 37 | #include <QSpinBox> |
|
37 | 38 | #include <QTime> |
|
38 | 39 | |
|
39 | 40 | TableWidget::TableWidget(QWidget *parent) |
|
40 | 41 | : QWidget(parent) |
|
41 | 42 | { |
|
42 | 43 | setGeometry(100, 100, 1000, 600); |
|
43 | 44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
44 | 45 | // create simple model for storing data |
|
45 | 46 | // user's table data model |
|
46 | 47 | m_model = new CustomTableModel; |
|
47 | 48 | m_tableView = new QTableView; |
|
48 | 49 | m_tableView->setModel(m_model); |
|
49 | 50 | m_tableView->setMinimumHeight(300); |
|
50 | 51 | // tableView->setMinimumSize(340, 480); |
|
51 | 52 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
52 | 53 | m_chart = new QChart; |
|
53 | 54 | m_chartView = new QChartView(m_chart); |
|
54 | 55 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
55 | 56 | m_chartView->setMinimumSize(640, 480); |
|
56 | 57 | |
|
57 | 58 | // add, remove data buttons |
|
58 | 59 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
59 | 60 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
60 | 61 | |
|
61 | 62 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
62 | 63 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
63 | 64 | |
|
64 | 65 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
65 | 66 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
66 | 67 | |
|
68 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
|
69 | ||
|
67 | 70 | // spin box for setting number of affected items (add, remove) |
|
68 | 71 | m_linesCountSpinBox = new QSpinBox; |
|
69 | 72 | m_linesCountSpinBox->setRange(1, 10); |
|
70 | 73 | m_linesCountSpinBox->setValue(1); |
|
71 | 74 | |
|
72 | 75 | // buttons layout |
|
73 | 76 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
77 | buttonsLayout->addWidget(spinBoxLabel); | |
|
74 | 78 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
75 | 79 | buttonsLayout->addWidget(addRowAboveButton); |
|
76 | 80 | buttonsLayout->addWidget(addRowBelowButton); |
|
77 | 81 | buttonsLayout->addWidget(removeRowButton); |
|
78 | 82 | buttonsLayout->addStretch(); |
|
79 | 83 | |
|
80 | 84 | // chart type radio buttons |
|
81 | 85 | m_lineRadioButton = new QRadioButton("Line"); |
|
82 | 86 | m_splineRadioButton = new QRadioButton("Spline"); |
|
83 | 87 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
84 | 88 | m_pieRadioButton = new QRadioButton("Pie"); |
|
85 | 89 | m_areaRadioButton = new QRadioButton("Area"); |
|
86 | 90 | m_barRadioButton = new QRadioButton("Bar"); |
|
87 | 91 | |
|
88 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
89 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
90 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
91 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
92 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
93 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
|
92 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
93 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
94 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
95 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
96 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
97 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
|
94 | 98 | m_lineRadioButton->setChecked(true); |
|
95 | 99 | |
|
96 | 100 | // radio buttons layout |
|
97 | 101 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
98 | 102 | radioLayout->addWidget(m_lineRadioButton); |
|
99 | 103 | radioLayout->addWidget(m_splineRadioButton); |
|
100 | 104 | radioLayout->addWidget(m_scatterRadioButton); |
|
101 | 105 | radioLayout->addWidget(m_pieRadioButton); |
|
102 | 106 | radioLayout->addWidget(m_areaRadioButton); |
|
103 | 107 | radioLayout->addWidget(m_barRadioButton); |
|
104 | 108 | radioLayout->addStretch(); |
|
105 | 109 | |
|
106 | 110 | // create main layout |
|
107 | 111 | QGridLayout* mainLayout = new QGridLayout; |
|
108 | 112 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
109 | 113 | mainLayout->addLayout(radioLayout, 2, 1); |
|
110 | 114 | mainLayout->addWidget(m_tableView, 1, 0); |
|
111 | 115 | mainLayout->addWidget(m_chartView, 2, 0); |
|
112 | 116 | setLayout(mainLayout); |
|
113 | 117 | m_lineRadioButton->setFocus(); |
|
114 | 118 | } |
|
115 | 119 | |
|
116 | 120 | void TableWidget::addRowAbove() |
|
117 | 121 | { |
|
118 | 122 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
119 | 123 | |
|
120 | 124 | } |
|
121 | 125 | |
|
122 | 126 | void TableWidget::addRowBelow() |
|
123 | 127 | { |
|
124 | 128 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
125 | 129 | |
|
126 | 130 | } |
|
127 | 131 | |
|
128 | 132 | void TableWidget::removeRow() |
|
129 | 133 | { |
|
130 | 134 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
131 | 135 | } |
|
132 | 136 | |
|
133 | void TableWidget::updateChartType() | |
|
137 | void TableWidget::updateChartType(bool toggle) | |
|
134 | 138 | { |
|
135 | m_chart->removeAllSeries(); | |
|
136 | m_model->clearMapping(); | |
|
137 | ||
|
138 | QString seriesColorHex = "#000000"; | |
|
139 | QPen pen; | |
|
140 | pen.setWidth(2); | |
|
141 | ||
|
142 | if (m_lineRadioButton->isChecked()) | |
|
143 | { | |
|
144 | // series 1 | |
|
145 | m_series = new QLineSeries; | |
|
146 | m_series->setModel(m_model); | |
|
147 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
148 | m_series->setModelMappingRange(1, 4); | |
|
149 | m_chart->addSeries(m_series); | |
|
150 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
151 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
|
152 | ||
|
153 | // series 2 | |
|
154 | m_series = new QLineSeries; | |
|
155 | m_series->setModel(m_model); | |
|
156 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
157 | m_chart->addSeries(m_series); | |
|
158 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
159 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
160 | ||
|
161 |
// series |
|
|
162 | m_series = new QLineSeries; | |
|
163 | m_series->setModel(m_model); | |
|
164 |
m_series->setModelMapping( |
|
|
165 |
m_series->setModelMappingRange( |
|
|
166 | m_chart->addSeries(m_series); | |
|
167 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
168 |
m_model->addMapping(seriesColorHex, QRect( |
|
|
169 | } | |
|
170 | else if (m_splineRadioButton->isChecked()) | |
|
171 | { | |
|
172 | // series 1 | |
|
173 | m_series = new QSplineSeries; | |
|
174 | m_series->setModel(m_model); | |
|
175 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
176 | m_series->setModelMappingRange(1, 4); | |
|
177 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
178 | m_chart->addSeries(m_series); | |
|
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
180 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
|
181 | ||
|
182 | // series 2 | |
|
183 | m_series = new QSplineSeries; | |
|
184 | m_series->setModel(m_model); | |
|
185 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
186 | m_series->setModelMappingRange(0, 0); | |
|
187 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
188 | m_chart->addSeries(m_series); | |
|
189 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
190 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
191 | ||
|
192 | // series 3 | |
|
193 | m_series = new QSplineSeries; | |
|
194 | m_series->setModel(m_model); | |
|
195 | m_series->setModelMapping(4,5, Qt::Vertical); | |
|
196 | m_series->setModelMappingRange(2, 0); | |
|
197 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
198 | m_chart->addSeries(m_series); | |
|
199 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
200 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
|
201 | } | |
|
202 | else if (m_scatterRadioButton->isChecked()) | |
|
203 | { | |
|
204 | // series 1 | |
|
205 | m_series = new QScatterSeries; | |
|
206 | m_series->setModel(m_model); | |
|
207 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
208 | m_series->setModelMappingRange(2, 0); | |
|
209 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
210 | m_chart->addSeries(m_series); | |
|
211 | ||
|
212 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
213 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
|
214 | ||
|
215 | // series 2 | |
|
216 | m_series = new QScatterSeries; | |
|
217 | m_series->setModel(m_model); | |
|
218 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
219 | m_series->setModelMappingRange(1, 6); | |
|
220 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
221 | m_chart->addSeries(m_series); | |
|
222 | ||
|
223 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
224 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
|
225 | ||
|
226 | // series 3 | |
|
227 | m_series = new QScatterSeries; | |
|
228 | m_series->setModel(m_model); | |
|
229 | m_series->setModelMapping(4,5, Qt::Vertical); | |
|
230 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
231 | m_chart->addSeries(m_series); | |
|
232 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
233 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
|
234 | } | |
|
235 | else if (m_pieRadioButton->isChecked()) | |
|
236 | { | |
|
237 | // pie 1 | |
|
238 | QPieSeries* pieSeries = new QPieSeries; | |
|
239 | pieSeries->setModel(m_model); | |
|
240 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
|
241 | pieSeries->setLabelsVisible(true); | |
|
242 | pieSeries->setPieSize(0.4); | |
|
243 | pieSeries->setPiePosition(0.2, 0.35); | |
|
244 | ||
|
245 | m_chart->addSeries(pieSeries); | |
|
246 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
247 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |
|
248 | ||
|
249 | // pie 2 | |
|
250 | pieSeries = new QPieSeries; | |
|
251 | pieSeries->setModel(m_model); | |
|
252 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
|
253 | pieSeries->setLabelsVisible(true); | |
|
254 | pieSeries->setPieSize(0.4); | |
|
255 | pieSeries->setPiePosition(0.8, 0.35); | |
|
256 | m_chart->addSeries(pieSeries); | |
|
257 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
258 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |
|
259 | ||
|
260 | // pie 3 | |
|
261 | pieSeries = new QPieSeries; | |
|
262 | pieSeries->setModel(m_model); | |
|
263 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
|
264 | pieSeries->setLabelsVisible(true); | |
|
265 | pieSeries->setPieSize(0.4); | |
|
266 | pieSeries->setPiePosition(0.5, 0.65); | |
|
267 | m_chart->addSeries(pieSeries); | |
|
268 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
269 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
|
270 | } | |
|
271 | else if (m_areaRadioButton->isChecked()) | |
|
272 | { | |
|
273 | QLineSeries* upperLineSeries = new QLineSeries; | |
|
274 | upperLineSeries->setModel(m_model); | |
|
275 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
|
276 | upperLineSeries->setModelMappingRange(1, 5); | |
|
277 | QLineSeries* lowerLineSeries = new QLineSeries; | |
|
278 | lowerLineSeries->setModel(m_model); | |
|
279 |
|
|
|
280 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
|
281 | m_chart->addSeries(areaSeries); | |
|
282 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
|
283 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
|
284 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
285 | } | |
|
286 | else if (m_barRadioButton->isChecked()) | |
|
287 | { | |
|
288 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
|
289 | barSeries->setModel(m_model); | |
|
290 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
|
291 | barSeries->setToolTipEnabled(true); | |
|
292 | m_chart->addSeries(barSeries); | |
|
293 | for (int i = 0; i < barSeries->barsetCount(); i++) { | |
|
294 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
295 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
|
139 | // this if is needed, so that the function is only called once. | |
|
140 | // For the radioButton that was enabled. | |
|
141 | if (toggle) { | |
|
142 | m_chart->removeAllSeries(); | |
|
143 | ||
|
144 | // renable axes of the chart (pie hides them) | |
|
145 | // x axis | |
|
146 | QChartAxis *axis = m_chart->axisX(); | |
|
147 | axis->setAxisVisible(true); | |
|
148 | axis->setGridLineVisible(true); | |
|
149 | axis->setLabelsVisible(true); | |
|
150 | ||
|
151 | // y axis | |
|
152 | axis = m_chart->axisY(); | |
|
153 | axis->setAxisVisible(true); | |
|
154 | axis->setGridLineVisible(true); | |
|
155 | axis->setLabelsVisible(true); | |
|
156 | ||
|
157 | m_model->clearMapping(); | |
|
158 | ||
|
159 | QString seriesColorHex = "#000000"; | |
|
160 | QPen pen; | |
|
161 | pen.setWidth(2); | |
|
162 | ||
|
163 | if (m_lineRadioButton->isChecked()) | |
|
164 | { | |
|
165 | // series 1 | |
|
166 | m_series = new QLineSeries; | |
|
167 | m_series->setModel(m_model); | |
|
168 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
169 | m_series->setModelMappingRange(1, 4); | |
|
170 | m_chart->addSeries(m_series); | |
|
171 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
172 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
|
173 | ||
|
174 | // series 2 | |
|
175 | m_series = new QLineSeries; | |
|
176 | m_series->setModel(m_model); | |
|
177 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
178 | m_chart->addSeries(m_series); | |
|
179 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
180 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
181 | ||
|
182 | // series 3 | |
|
183 | m_series = new QLineSeries; | |
|
184 | m_series->setModel(m_model); | |
|
185 | m_series->setModelMapping(4,5, Qt::Vertical); | |
|
186 | m_series->setModelMappingRange(2, 0); | |
|
187 | m_chart->addSeries(m_series); | |
|
188 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
189 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
|
190 | } | |
|
191 | else if (m_splineRadioButton->isChecked()) | |
|
192 | { | |
|
193 | // series 1 | |
|
194 | m_series = new QSplineSeries; | |
|
195 | m_series->setModel(m_model); | |
|
196 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
197 | m_series->setModelMappingRange(1, 4); | |
|
198 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
199 | m_chart->addSeries(m_series); | |
|
200 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
201 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
|
202 | ||
|
203 | // series 2 | |
|
204 | m_series = new QSplineSeries; | |
|
205 | m_series->setModel(m_model); | |
|
206 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
207 | m_series->setModelMappingRange(0, 0); | |
|
208 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
209 | m_chart->addSeries(m_series); | |
|
210 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
211 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
212 | ||
|
213 | // series 3 | |
|
214 | m_series = new QSplineSeries; | |
|
215 | m_series->setModel(m_model); | |
|
216 | m_series->setModelMapping(4,5, Qt::Vertical); | |
|
217 | m_series->setModelMappingRange(2, 0); | |
|
218 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
219 | m_chart->addSeries(m_series); | |
|
220 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
221 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
|
222 | } | |
|
223 | else if (m_scatterRadioButton->isChecked()) | |
|
224 | { | |
|
225 | // series 1 | |
|
226 | m_series = new QScatterSeries; | |
|
227 | m_series->setModel(m_model); | |
|
228 | m_series->setModelMapping(0,1, Qt::Vertical); | |
|
229 | m_series->setModelMappingRange(2, 0); | |
|
230 | // series->setModelMapping(0,1, Qt::Horizontal); | |
|
231 | m_chart->addSeries(m_series); | |
|
232 | ||
|
233 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
234 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
|
235 | ||
|
236 | // series 2 | |
|
237 | m_series = new QScatterSeries; | |
|
238 | m_series->setModel(m_model); | |
|
239 | m_series->setModelMapping(2,3, Qt::Vertical); | |
|
240 | m_series->setModelMappingRange(1, 6); | |
|
241 | // series->setModelMapping(2,3, Qt::Horizontal); | |
|
242 | m_chart->addSeries(m_series); | |
|
243 | ||
|
244 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
245 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
|
246 | ||
|
247 | // series 3 | |
|
248 | m_series = new QScatterSeries; | |
|
249 | m_series->setModel(m_model); | |
|
250 | m_series->setModelMapping(4,5, Qt::Vertical); | |
|
251 | // series->setModelMapping(4,5, Qt::Horizontal); | |
|
252 | m_chart->addSeries(m_series); | |
|
253 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
|
254 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
|
255 | } | |
|
256 | else if (m_pieRadioButton->isChecked()) | |
|
257 | { | |
|
258 | // pie 1 | |
|
259 | QPieSeries* pieSeries = new QPieSeries; | |
|
260 | pieSeries->setModel(m_model); | |
|
261 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
|
262 | pieSeries->setLabelsVisible(true); | |
|
263 | pieSeries->setPieSize(0.4); | |
|
264 | pieSeries->setPiePosition(0.2, 0.35); | |
|
265 | ||
|
266 | m_chart->addSeries(pieSeries); | |
|
267 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
268 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |
|
269 | ||
|
270 | // pie 2 | |
|
271 | pieSeries = new QPieSeries; | |
|
272 | pieSeries->setModel(m_model); | |
|
273 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
|
274 | pieSeries->setLabelsVisible(true); | |
|
275 | pieSeries->setPieSize(0.4); | |
|
276 | pieSeries->setPiePosition(0.8, 0.35); | |
|
277 | m_chart->addSeries(pieSeries); | |
|
278 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
279 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |
|
280 | ||
|
281 | // pie 3 | |
|
282 | pieSeries = new QPieSeries; | |
|
283 | pieSeries->setModel(m_model); | |
|
284 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
|
285 | pieSeries->setLabelsVisible(true); | |
|
286 | pieSeries->setPieSize(0.4); | |
|
287 | pieSeries->setPiePosition(0.5, 0.65); | |
|
288 | m_chart->addSeries(pieSeries); | |
|
289 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
290 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
|
291 | } | |
|
292 | else if (m_areaRadioButton->isChecked()) | |
|
293 | { | |
|
294 | QLineSeries* upperLineSeries = new QLineSeries; | |
|
295 | upperLineSeries->setModel(m_model); | |
|
296 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
|
297 | upperLineSeries->setModelMappingRange(1, 5); | |
|
298 | QLineSeries* lowerLineSeries = new QLineSeries; | |
|
299 | lowerLineSeries->setModel(m_model); | |
|
300 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
|
301 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
|
302 | m_chart->addSeries(areaSeries); | |
|
303 | seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
|
304 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
|
305 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
|
306 | } | |
|
307 | else if (m_barRadioButton->isChecked()) | |
|
308 | { | |
|
309 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
|
310 | barSeries->setModel(m_model); | |
|
311 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
|
312 | barSeries->setToolTipEnabled(true); | |
|
313 | m_chart->addSeries(barSeries); | |
|
314 | for (int i = 0; i < barSeries->barsetCount(); i++) { | |
|
315 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
316 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
|
317 | } | |
|
296 | 318 | } |
|
297 | } | |
|
298 | 319 | |
|
299 | 320 | |
|
300 | m_chart->axisX()->setRange(0, 500); | |
|
301 | m_chart->axisY()->setRange(0, 120); | |
|
321 | m_chart->axisX()->setRange(0, 500); | |
|
322 | m_chart->axisY()->setRange(0, 120); | |
|
302 | 323 | |
|
303 | // repaint table view colors | |
|
304 | m_tableView->repaint(); | |
|
305 | m_tableView->setFocus(); | |
|
324 | // repaint table view colors | |
|
325 | m_tableView->repaint(); | |
|
326 | m_tableView->setFocus(); | |
|
327 | } | |
|
306 | 328 | } |
|
307 | 329 | |
|
308 | 330 | TableWidget::~TableWidget() |
|
309 | 331 | { |
|
310 | 332 | |
|
311 | 333 | } |
@@ -1,66 +1,66 | |||
|
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 "qchartview.h" |
|
26 | 26 | #include "qxyseries.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | class CustomTableModel; |
|
31 | 31 | class QTableView; |
|
32 | 32 | class QRadioButton; |
|
33 | 33 | class QSpinBox; |
|
34 | 34 | //class QSeries; |
|
35 | 35 | |
|
36 | 36 | class TableWidget : public QWidget |
|
37 | 37 | { |
|
38 | 38 | Q_OBJECT |
|
39 | 39 | |
|
40 | 40 | public: |
|
41 | 41 | TableWidget(QWidget *parent = 0); |
|
42 | 42 | ~TableWidget(); |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | public slots: |
|
46 | 46 | void addRowAbove(); |
|
47 | 47 | void addRowBelow(); |
|
48 | 48 | void removeRow(); |
|
49 | void updateChartType(); | |
|
49 | void updateChartType(bool toggle); | |
|
50 | 50 | |
|
51 | 51 | private: |
|
52 | 52 | QChartView* m_chartView; |
|
53 | 53 | QChart* m_chart; |
|
54 | 54 | QXYSeries* m_series; |
|
55 | 55 | CustomTableModel* m_model; |
|
56 | 56 | QTableView* m_tableView; |
|
57 | 57 | QRadioButton* m_lineRadioButton; |
|
58 | 58 | QRadioButton* m_splineRadioButton; |
|
59 | 59 | QRadioButton* m_scatterRadioButton; |
|
60 | 60 | QRadioButton* m_pieRadioButton; |
|
61 | 61 | QRadioButton* m_areaRadioButton; |
|
62 | 62 | QRadioButton* m_barRadioButton; |
|
63 | 63 | QSpinBox* m_linesCountSpinBox; |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | #endif // TABLEWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now