@@ -1,419 +1,419 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | #include "customtablemodel.h" |
|
23 | 23 | #include <QVBoxPlotModelMapper> |
|
24 | 24 | #include <QTableView> |
|
25 | 25 | #include <QHeaderView> |
|
26 | 26 | #include <QChartView> |
|
27 | 27 | #include <QBoxPlotSeries> |
|
28 | 28 | #include <QBoxSet> |
|
29 | 29 | #include <QLegend> |
|
30 | 30 | #include <QBarCategoryAxis> |
|
31 | 31 | #include <QBrush> |
|
32 | 32 | #include <QColor> |
|
33 | 33 | #include <QPushButton> |
|
34 | 34 | #include <QComboBox> |
|
35 | 35 | #include <QSpinBox> |
|
36 | 36 | #include <QCheckBox> |
|
37 | 37 | #include <QGridLayout> |
|
38 | 38 | #include <QHBoxLayout> |
|
39 | 39 | #include <QLabel> |
|
40 | 40 | #include <QSpacerItem> |
|
41 | 41 | #include <QMessageBox> |
|
42 | 42 | #include <cmath> |
|
43 | 43 | #include <QDebug> |
|
44 | 44 | #include <QStandardItemModel> |
|
45 | 45 | #include <QBarCategoryAxis> |
|
46 | 46 | #include <QLogValueAxis> |
|
47 | 47 | |
|
48 | 48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | 49 | |
|
50 |
QString a |
|
|
51 |
static const int max |
|
|
50 | static const QString allCategories[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; | |
|
51 | static const int maxCategories = 12; | |
|
52 | 52 | |
|
53 | 53 | MainWidget::MainWidget(QWidget *parent) : |
|
54 | 54 | QWidget(parent), |
|
55 | 55 | m_chart(0), |
|
56 | 56 | m_axis(0), |
|
57 | rowPos(0), | |
|
58 |
|
|
|
59 | nNewBoxes(0) | |
|
57 | m_rowPos(0), | |
|
58 | m_seriesCount(0) | |
|
60 | 59 | { |
|
61 | 60 | m_chart = new QChart(); |
|
62 | 61 | |
|
63 | 62 | // Grid layout for the controls for configuring the chart widget |
|
64 | 63 | QGridLayout *grid = new QGridLayout(); |
|
65 | 64 | |
|
66 | 65 | // Create add a series button |
|
67 | 66 | QPushButton *addSeriesButton = new QPushButton("Add a series"); |
|
68 | 67 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
69 | grid->addWidget(addSeriesButton, rowPos++, 1); | |
|
68 | grid->addWidget(addSeriesButton, m_rowPos++, 1); | |
|
70 | 69 | |
|
71 | 70 | // Create remove a series button |
|
72 | 71 | QPushButton *removeSeriesButton = new QPushButton("Remove a series"); |
|
73 | 72 | connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); |
|
74 | grid->addWidget(removeSeriesButton, rowPos++, 1); | |
|
73 | grid->addWidget(removeSeriesButton, m_rowPos++, 1); | |
|
75 | 74 | |
|
76 | 75 | // Create add a single box button |
|
77 | 76 | QPushButton *addBoxButton = new QPushButton("Add a box"); |
|
78 | 77 | connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); |
|
79 | grid->addWidget(addBoxButton, rowPos++, 1); | |
|
78 | grid->addWidget(addBoxButton, m_rowPos++, 1); | |
|
80 | 79 | |
|
81 | 80 | // Create insert a box button |
|
82 | 81 | QPushButton *insertBoxButton = new QPushButton("Insert a box"); |
|
83 | 82 | connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox())); |
|
84 | grid->addWidget(insertBoxButton, rowPos++, 1); | |
|
83 | grid->addWidget(insertBoxButton, m_rowPos++, 1); | |
|
85 | 84 | |
|
86 | 85 | // Create add a single box button |
|
87 | 86 | QPushButton *removeBoxButton = new QPushButton("Remove a box"); |
|
88 | 87 | connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); |
|
89 | grid->addWidget(removeBoxButton, rowPos++, 1); | |
|
88 | grid->addWidget(removeBoxButton, m_rowPos++, 1); | |
|
90 | 89 | |
|
91 | 90 | // Create clear button |
|
92 | 91 | QPushButton *clearButton = new QPushButton("Clear"); |
|
93 | 92 | connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); |
|
94 | grid->addWidget(clearButton, rowPos++, 1); | |
|
93 | grid->addWidget(clearButton, m_rowPos++, 1); | |
|
95 | 94 | |
|
96 | 95 | // Create clear button |
|
97 | 96 | QPushButton *clearBoxButton = new QPushButton("ClearBox"); |
|
98 | 97 | connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox())); |
|
99 | grid->addWidget(clearBoxButton, rowPos++, 1); | |
|
98 | grid->addWidget(clearBoxButton, m_rowPos++, 1); | |
|
100 | 99 | |
|
101 | 100 | |
|
102 | 101 | // Create set brush button |
|
103 | 102 | QPushButton *setBrushButton = new QPushButton("Set brush"); |
|
104 | 103 | connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush())); |
|
105 | grid->addWidget(setBrushButton, rowPos++, 1); | |
|
104 | grid->addWidget(setBrushButton, m_rowPos++, 1); | |
|
106 | 105 | |
|
107 | 106 | initThemeCombo(grid); |
|
108 | 107 | initCheckboxes(grid); |
|
109 | 108 | |
|
110 | 109 | m_model = new CustomTableModel(); |
|
111 | 110 | QTableView *tableView = new QTableView; |
|
112 | 111 | tableView->setModel(m_model); |
|
113 | 112 | tableView->setMaximumWidth(200); |
|
114 | grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft); | |
|
113 | grid->addWidget(tableView, m_rowPos++, 0, 3, 2, Qt::AlignLeft); | |
|
115 | 114 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) |
|
116 | 115 | tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
117 | 116 | tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
118 | 117 | #else |
|
119 | 118 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
120 | 119 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
121 | 120 | #endif |
|
122 | 121 | |
|
123 | 122 | // add row with empty label to make all the other rows static |
|
124 | 123 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
125 | 124 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
126 | 125 | |
|
127 | 126 | // Create chart view with the chart |
|
128 | 127 | m_chartView = new QChartView(m_chart, this); |
|
129 | 128 | |
|
130 | 129 | // Another grid layout as a main layout |
|
131 | 130 | QGridLayout *mainLayout = new QGridLayout(); |
|
132 | 131 | mainLayout->addLayout(grid, 0, 0); |
|
133 | 132 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
134 | 133 | setLayout(mainLayout); |
|
135 | 134 | |
|
136 | 135 | legendToggled(false); |
|
137 | 136 | animationToggled(false); |
|
138 | 137 | } |
|
139 | 138 | |
|
140 | 139 | // Combo box for selecting theme |
|
141 | 140 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
142 | 141 | { |
|
143 | 142 | QComboBox *chartTheme = new QComboBox(); |
|
144 | 143 | chartTheme->addItem("Default"); |
|
145 | 144 | chartTheme->addItem("Light"); |
|
146 | 145 | chartTheme->addItem("Blue Cerulean"); |
|
147 | 146 | chartTheme->addItem("Dark"); |
|
148 | 147 | chartTheme->addItem("Brown Sand"); |
|
149 | 148 | chartTheme->addItem("Blue NCS"); |
|
150 | 149 | chartTheme->addItem("High Contrast"); |
|
151 | 150 | chartTheme->addItem("Blue Icy"); |
|
152 | 151 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
153 | 152 | this, SLOT(changeChartTheme(int))); |
|
154 | grid->addWidget(new QLabel("Chart theme:"), rowPos, 0); | |
|
155 | grid->addWidget(chartTheme, rowPos++, 1); | |
|
153 | grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); | |
|
154 | grid->addWidget(chartTheme, m_rowPos++, 1); | |
|
156 | 155 | } |
|
157 | 156 | |
|
158 | 157 | // Different check boxes for customizing chart |
|
159 | 158 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
160 | 159 | { |
|
161 | 160 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
162 | 161 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
163 | 162 | animationCheckBox->setChecked(false); |
|
164 | grid->addWidget(animationCheckBox, rowPos++, 0); | |
|
163 | grid->addWidget(animationCheckBox, m_rowPos++, 0); | |
|
165 | 164 | |
|
166 | 165 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
167 | 166 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
168 | 167 | legendCheckBox->setChecked(false); |
|
169 | grid->addWidget(legendCheckBox, rowPos++, 0); | |
|
168 | grid->addWidget(legendCheckBox, m_rowPos++, 0); | |
|
170 | 169 | |
|
171 | 170 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
172 | 171 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
173 | 172 | titleCheckBox->setChecked(false); |
|
174 | grid->addWidget(titleCheckBox, rowPos++, 0); | |
|
173 | grid->addWidget(titleCheckBox, m_rowPos++, 0); | |
|
175 | 174 | |
|
176 | 175 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
177 | 176 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
178 | 177 | modelMapperCheckBox->setChecked(false); |
|
179 | grid->addWidget(modelMapperCheckBox, rowPos++, 0); | |
|
178 | grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); | |
|
180 | 179 | |
|
181 | 180 | } |
|
182 | 181 | |
|
182 | void MainWidget::updateAxis(int categoryCount) | |
|
183 | { | |
|
184 | if (!m_axis) { | |
|
185 | m_chart->createDefaultAxes(); | |
|
186 | m_axis = new QBarCategoryAxis(); | |
|
187 | } | |
|
188 | QStringList categories; | |
|
189 | for (int i = 0; i < categoryCount; i++) | |
|
190 | categories << allCategories[i]; | |
|
191 | m_axis->setCategories(categories); | |
|
192 | } | |
|
193 | ||
|
183 | 194 | void MainWidget::addSeries() |
|
184 | 195 | { |
|
185 | 196 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
186 | 197 | |
|
187 |
if ( |
|
|
198 | if (m_seriesCount > 9) | |
|
188 | 199 | return; |
|
189 | 200 | |
|
190 | 201 | // Initial data |
|
191 | 202 | QBoxSet *set0 = new QBoxSet(); |
|
192 | 203 | QBoxSet *set1 = new QBoxSet(); |
|
193 | 204 | QBoxSet *set2 = new QBoxSet(); |
|
194 | 205 | QBoxSet *set3 = new QBoxSet(); |
|
195 | 206 | QBoxSet *set4 = new QBoxSet(); |
|
196 | 207 | QBoxSet *set5 = new QBoxSet(); |
|
197 | 208 | |
|
198 | 209 | // low bot med top upp |
|
199 | 210 | *set0 << -1 << 2 << 4 << 13 << 15; |
|
200 | 211 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
201 | 212 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
202 | 213 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
203 | 214 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
204 | 215 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
205 | 216 | |
|
206 |
m_series[ |
|
|
207 |
m_series[ |
|
|
208 |
m_series[ |
|
|
209 |
m_series[ |
|
|
210 |
m_series[ |
|
|
211 |
m_series[ |
|
|
212 |
m_series[ |
|
|
213 |
m_series[ |
|
|
214 | ||
|
215 |
connect(m_series[ |
|
|
216 |
connect(m_series[ |
|
|
217 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
|
218 | m_series[m_seriesCount]->append(set0); | |
|
219 | m_series[m_seriesCount]->append(set1); | |
|
220 | m_series[m_seriesCount]->append(set2); | |
|
221 | m_series[m_seriesCount]->append(set3); | |
|
222 | m_series[m_seriesCount]->append(set4); | |
|
223 | m_series[m_seriesCount]->append(set5); | |
|
224 | m_series[m_seriesCount]->setName("Box & Whiskers"); | |
|
225 | ||
|
226 | connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); | |
|
227 | connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); | |
|
217 | 228 | connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); |
|
218 | 229 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); |
|
219 | 230 | |
|
220 |
m_chart->addSeries(m_series[ |
|
|
231 | m_chart->addSeries(m_series[m_seriesCount]); | |
|
221 | 232 | |
|
222 | if (!m_axis) { | |
|
223 | QStringList categories; | |
|
224 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
|
225 | m_axis = new QBarCategoryAxis(); | |
|
226 | m_axis->append(categories); | |
|
227 | m_chart->createDefaultAxes(); | |
|
228 | } | |
|
229 | m_chart->setAxisX(m_axis, m_series[nSeries]); | |
|
233 | updateAxis(m_series[0]->count()); | |
|
234 | m_chart->setAxisX(m_axis, m_series[m_seriesCount]); | |
|
230 | 235 | |
|
231 |
|
|
|
236 | m_seriesCount++; | |
|
232 | 237 | } |
|
233 | 238 | |
|
234 | 239 | void MainWidget::removeSeries() |
|
235 | 240 | { |
|
236 | 241 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; |
|
237 | 242 | |
|
238 |
if ( |
|
|
239 |
|
|
|
240 |
m_chart->removeSeries(m_series[ |
|
|
241 |
delete m_series[ |
|
|
243 | if (m_seriesCount > 0) { | |
|
244 | m_seriesCount--; | |
|
245 | m_chart->removeSeries(m_series[m_seriesCount]); | |
|
246 | delete m_series[m_seriesCount]; | |
|
247 | m_series[m_seriesCount] = 0; | |
|
242 | 248 | } else { |
|
243 | 249 | qDebug() << "Create a series first"; |
|
244 | 250 | } |
|
245 | 251 | } |
|
246 | 252 | |
|
247 | 253 | void MainWidget::addBox() |
|
248 | 254 | { |
|
249 | 255 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
250 | 256 | |
|
251 |
if ( |
|
|
257 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
|
252 | 258 | QBoxSet *newSet = new QBoxSet(); |
|
253 | 259 | newSet->setValue(QBoxSet::LowerExtreme, 5.0); |
|
254 | 260 | newSet->setValue(QBoxSet::LowerQuartile, 6.0); |
|
255 | 261 | newSet->setValue(QBoxSet::Median, 6.8); |
|
256 | 262 | newSet->setValue(QBoxSet::UpperQuartile, 7.0); |
|
257 | 263 | newSet->setValue(QBoxSet::UpperExtreme, 8.0); |
|
258 | 264 | |
|
259 |
m_series[0]-> |
|
|
260 | ||
|
261 | m_axis->append(addCategories[nNewBoxes]); | |
|
265 | updateAxis(m_series[0]->count() + 1); | |
|
262 | 266 | |
|
263 | nNewBoxes++; | |
|
267 | m_series[0]->append(newSet); | |
|
264 | 268 | } |
|
265 | 269 | } |
|
266 | 270 | |
|
267 | 271 | void MainWidget::insertBox() |
|
268 | 272 | { |
|
269 | 273 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; |
|
270 | 274 | |
|
271 | if (nSeries > 0) { | |
|
272 | QBoxSet *newSet = new QBoxSet(); | |
|
273 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |
|
274 | ||
|
275 | for (int i = 0; i < nSeries; i++) | |
|
275 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
|
276 | updateAxis(m_series[0]->count() + 1); | |
|
277 | for (int i = 0; i < m_seriesCount; i++) { | |
|
278 | QBoxSet *newSet = new QBoxSet(); | |
|
279 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |
|
276 | 280 | m_series[i]->insert(1, newSet); |
|
277 | ||
|
278 | m_axis->append(addCategories[nNewBoxes]); | |
|
279 | ||
|
280 | nNewBoxes++; | |
|
281 | } | |
|
281 | 282 | } |
|
282 | 283 | } |
|
283 | 284 | |
|
284 | 285 | void MainWidget::removeBox() |
|
285 | 286 | { |
|
286 | 287 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; |
|
287 | 288 | |
|
288 |
if ( |
|
|
289 |
for (int i = 0; i < |
|
|
289 | if (m_seriesCount > 0) { | |
|
290 | for (int i = 0; i < m_seriesCount; i++) { | |
|
290 | 291 | qDebug() << "m_series[i]->count() = " << m_series[i]->count(); |
|
291 |
if (m_series[i]->count() |
|
|
292 | if (m_series[i]->count()) { | |
|
292 | 293 | QList<QBoxSet *> sets = m_series[i]->boxSets(); |
|
293 |
m_series[i]->remove(sets.at(m_series[i]->count() - |
|
|
294 | m_series[i]->remove(sets.at(m_series[i]->count() - 1)); | |
|
294 | 295 | } |
|
295 | 296 | } |
|
296 | 297 | |
|
297 |
|
|
|
298 | m_axis->remove(m_axis->at(1)); | |
|
298 | updateAxis(m_series[0]->count()); | |
|
299 | 299 | } else { |
|
300 | 300 | qDebug() << "Create a series first"; |
|
301 | 301 | } |
|
302 | 302 | } |
|
303 | 303 | |
|
304 | 304 | void MainWidget::clear() |
|
305 | 305 | { |
|
306 | 306 | qDebug() << "BoxPlotTester::MainWidget::clear"; |
|
307 | 307 | |
|
308 |
if ( |
|
|
308 | if (m_seriesCount > 0) | |
|
309 | 309 | m_series[0]->clear(); |
|
310 | 310 | else |
|
311 | 311 | qDebug() << "Create a series first"; |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | void MainWidget::clearBox() |
|
315 | 315 | { |
|
316 | 316 | qDebug() << "BoxPlotTester::MainWidget::clearBox"; |
|
317 | 317 | |
|
318 |
if ( |
|
|
318 | if (m_seriesCount > 0) { | |
|
319 | 319 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
320 | 320 | sets.at(1)->clear(); |
|
321 | 321 | } else { |
|
322 | 322 | qDebug() << "Create a series first"; |
|
323 | 323 | } |
|
324 | 324 | } |
|
325 | 325 | |
|
326 | 326 | void MainWidget::setBrush() |
|
327 | 327 | { |
|
328 | 328 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; |
|
329 | 329 | |
|
330 |
if ( |
|
|
330 | if (m_seriesCount > 0) { | |
|
331 | 331 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
332 | 332 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); |
|
333 | 333 | } else { |
|
334 | 334 | qDebug() << "Create a series first"; |
|
335 | 335 | } |
|
336 | 336 | } |
|
337 | 337 | |
|
338 | 338 | void MainWidget::animationToggled(bool enabled) |
|
339 | 339 | { |
|
340 | 340 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
341 | 341 | if (enabled) |
|
342 | 342 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
343 | 343 | else |
|
344 | 344 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
345 | 345 | } |
|
346 | 346 | |
|
347 | 347 | void MainWidget::legendToggled(bool enabled) |
|
348 | 348 | { |
|
349 | 349 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
350 | 350 | m_chart->legend()->setVisible(enabled); |
|
351 | 351 | if (enabled) |
|
352 | 352 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | void MainWidget::titleToggled(bool enabled) |
|
356 | 356 | { |
|
357 | 357 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
358 | 358 | if (enabled) |
|
359 | 359 | m_chart->setTitle("Simple boxplotchart example"); |
|
360 | 360 | else |
|
361 | 361 | m_chart->setTitle(""); |
|
362 | 362 | } |
|
363 | 363 | |
|
364 | 364 | void MainWidget::modelMapperToggled(bool enabled) |
|
365 | 365 | { |
|
366 | 366 | if (enabled) { |
|
367 |
m_series[ |
|
|
367 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
|
368 | 368 | |
|
369 | 369 | int first = 0; |
|
370 | 370 | int count = 5; |
|
371 | 371 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); |
|
372 | 372 | mapper->setFirstBoxSetColumn(0); |
|
373 | 373 | mapper->setLastBoxSetColumn(5); |
|
374 | 374 | mapper->setFirstRow(first); |
|
375 | 375 | mapper->setRowCount(count); |
|
376 |
mapper->setSeries(m_series[ |
|
|
376 | mapper->setSeries(m_series[m_seriesCount]); | |
|
377 | 377 | mapper->setModel(m_model); |
|
378 |
m_chart->addSeries(m_series[ |
|
|
378 | m_chart->addSeries(m_series[m_seriesCount]); | |
|
379 | 379 | |
|
380 |
|
|
|
380 | m_seriesCount++; | |
|
381 | 381 | } else { |
|
382 | 382 | removeSeries(); |
|
383 | 383 | } |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void MainWidget::changeChartTheme(int themeIndex) |
|
387 | 387 | { |
|
388 | 388 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
389 | 389 | if (themeIndex == 0) |
|
390 | 390 | m_chart->setTheme(QChart::ChartThemeLight); |
|
391 | 391 | else |
|
392 | 392 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
393 | 393 | } |
|
394 | 394 | |
|
395 | 395 | void MainWidget::boxClicked(QBoxSet *set) |
|
396 | 396 | { |
|
397 | 397 | qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | 400 | void MainWidget::boxHovered(bool state, QBoxSet *set) |
|
401 | 401 | { |
|
402 | 402 | if (state) |
|
403 | 403 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; |
|
404 | 404 | else |
|
405 | 405 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | void MainWidget::singleBoxClicked() |
|
409 | 409 | { |
|
410 | 410 | qDebug() << "singleBoxClicked"; |
|
411 | 411 | } |
|
412 | 412 | |
|
413 | 413 | void MainWidget::singleBoxHovered(bool state) |
|
414 | 414 | { |
|
415 | 415 | if (state) |
|
416 | 416 | qDebug() << "single box hover started"; |
|
417 | 417 | else |
|
418 | 418 | qDebug() << "single box hover ended"; |
|
419 | 419 | } |
@@ -1,80 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 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 MAINWIDGET_H |
|
22 | 22 | #define MAINWIDGET_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qchart.h" |
|
26 | 26 | #include "qchartview.h" |
|
27 | 27 | #include "customtablemodel.h" |
|
28 | 28 | #include <QWidget> |
|
29 | 29 | #include <QBoxPlotSeries> |
|
30 | 30 | #include <QBarCategoryAxis> |
|
31 | 31 | #include <QBoxSet> |
|
32 | 32 | |
|
33 | 33 | class QGridLayout; |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class MainWidget : public QWidget |
|
38 | 38 | { |
|
39 | 39 | Q_OBJECT |
|
40 | 40 | public: |
|
41 | 41 | explicit MainWidget(QWidget *parent = 0); |
|
42 | 42 | |
|
43 | 43 | signals: |
|
44 | 44 | |
|
45 | 45 | private: |
|
46 | 46 | void initThemeCombo(QGridLayout *grid); |
|
47 | 47 | void initCheckboxes(QGridLayout *grid); |
|
48 | void updateAxis(int categoryCount); | |
|
48 | 49 | |
|
49 | 50 | private slots: |
|
50 | 51 | void addSeries(); |
|
51 | 52 | void removeSeries(); |
|
52 | 53 | void addBox(); |
|
53 | 54 | void insertBox(); |
|
54 | 55 | void removeBox(); |
|
55 | 56 | void clear(); |
|
56 | 57 | void clearBox(); |
|
57 | 58 | void setBrush(); |
|
58 | 59 | void animationToggled(bool enabled); |
|
59 | 60 | void legendToggled(bool enabled); |
|
60 | 61 | void titleToggled(bool enabled); |
|
61 | 62 | void modelMapperToggled(bool enabled); |
|
62 | 63 | void changeChartTheme(int themeIndex); |
|
63 | 64 | void boxClicked(QBoxSet *set); |
|
64 | 65 | void boxHovered(bool state, QBoxSet *set); |
|
65 | 66 | void singleBoxClicked(); |
|
66 | 67 | void singleBoxHovered(bool state); |
|
67 | 68 | |
|
68 | 69 | private: |
|
69 | 70 | QChart *m_chart; |
|
70 | 71 | QChartView *m_chartView; |
|
71 | 72 | QGridLayout *m_scatterLayout; |
|
72 | 73 | QBarCategoryAxis *m_axis; |
|
73 | 74 | CustomTableModel *m_model; |
|
74 | int rowPos; | |
|
75 |
int |
|
|
76 | int nNewBoxes; | |
|
75 | int m_rowPos; | |
|
76 | int m_seriesCount; | |
|
77 | 77 | QBoxPlotSeries *m_series[10]; |
|
78 | 78 | }; |
|
79 | 79 | |
|
80 | 80 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now