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