@@ -1,480 +1,483 | |||||
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 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
172 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
173 | this, SLOT(changeChartTheme(int))); |
|
173 | this, SLOT(changeChartTheme(int))); | |
174 | grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); |
|
174 | grid->addWidget(new QLabel("Chart theme:"), m_rowPos, 0); | |
175 | grid->addWidget(chartTheme, m_rowPos++, 1); |
|
175 | grid->addWidget(chartTheme, m_rowPos++, 1); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | // Different check boxes for customizing chart |
|
178 | // Different check boxes for customizing chart | |
179 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
179 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
180 | { |
|
180 | { | |
181 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); |
|
181 | QCheckBox *animationCheckBox = new QCheckBox("Animation"); | |
182 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); |
|
182 | connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool))); | |
183 | animationCheckBox->setChecked(false); |
|
183 | animationCheckBox->setChecked(false); | |
184 | grid->addWidget(animationCheckBox, m_rowPos++, 0); |
|
184 | grid->addWidget(animationCheckBox, m_rowPos++, 0); | |
185 |
|
185 | |||
186 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); |
|
186 | QCheckBox *legendCheckBox = new QCheckBox("Legend"); | |
187 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); |
|
187 | connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool))); | |
188 | legendCheckBox->setChecked(false); |
|
188 | legendCheckBox->setChecked(false); | |
189 | grid->addWidget(legendCheckBox, m_rowPos++, 0); |
|
189 | grid->addWidget(legendCheckBox, m_rowPos++, 0); | |
190 |
|
190 | |||
191 | QCheckBox *titleCheckBox = new QCheckBox("Title"); |
|
191 | QCheckBox *titleCheckBox = new QCheckBox("Title"); | |
192 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); |
|
192 | connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool))); | |
193 | titleCheckBox->setChecked(false); |
|
193 | titleCheckBox->setChecked(false); | |
194 | grid->addWidget(titleCheckBox, m_rowPos++, 0); |
|
194 | grid->addWidget(titleCheckBox, m_rowPos++, 0); | |
195 |
|
195 | |||
196 | QCheckBox *antialiasingCheckBox = new QCheckBox("Antialiasing"); |
|
196 | QCheckBox *antialiasingCheckBox = new QCheckBox("Antialiasing"); | |
197 | connect(antialiasingCheckBox, SIGNAL(toggled(bool)), this, SLOT(antialiasingToggled(bool))); |
|
197 | connect(antialiasingCheckBox, SIGNAL(toggled(bool)), this, SLOT(antialiasingToggled(bool))); | |
198 | antialiasingCheckBox->setChecked(false); |
|
198 | antialiasingCheckBox->setChecked(false); | |
199 | grid->addWidget(antialiasingCheckBox, m_rowPos++, 0); |
|
199 | grid->addWidget(antialiasingCheckBox, m_rowPos++, 0); | |
200 |
|
200 | |||
201 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); |
|
201 | QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper"); | |
202 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); |
|
202 | connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool))); | |
203 | modelMapperCheckBox->setChecked(false); |
|
203 | modelMapperCheckBox->setChecked(false); | |
204 | grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); |
|
204 | grid->addWidget(modelMapperCheckBox, m_rowPos++, 0); | |
205 |
|
205 | |||
206 | m_boxOutlined = new QCheckBox("Box outlined"); |
|
206 | m_boxOutlined = new QCheckBox("Box outlined"); | |
207 | connect(m_boxOutlined, SIGNAL(toggled(bool)), this, SLOT(boxOutlineToggled(bool))); |
|
207 | connect(m_boxOutlined, SIGNAL(toggled(bool)), this, SLOT(boxOutlineToggled(bool))); | |
208 | m_boxOutlined->setChecked(true); |
|
208 | m_boxOutlined->setChecked(true); | |
209 | grid->addWidget(m_boxOutlined, m_rowPos++, 0); |
|
209 | grid->addWidget(m_boxOutlined, m_rowPos++, 0); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void MainWidget::updateAxis(int categoryCount) |
|
212 | void MainWidget::updateAxis(int categoryCount) | |
213 | { |
|
213 | { | |
214 | if (!m_axis) { |
|
214 | if (!m_axis) { | |
215 | m_chart->createDefaultAxes(); |
|
215 | m_chart->createDefaultAxes(); | |
216 | m_axis = new QBarCategoryAxis(); |
|
216 | m_axis = new QBarCategoryAxis(); | |
217 | } |
|
217 | } | |
218 | QStringList categories; |
|
218 | QStringList categories; | |
219 | for (int i = 0; i < categoryCount; i++) |
|
219 | for (int i = 0; i < categoryCount; i++) | |
220 | categories << allCategories[i]; |
|
220 | categories << allCategories[i]; | |
221 | m_axis->setCategories(categories); |
|
221 | m_axis->setCategories(categories); | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | void MainWidget::addSeries() |
|
224 | void MainWidget::addSeries() | |
225 | { |
|
225 | { | |
226 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; |
|
226 | qDebug() << "BoxPlotTester::MainWidget::addSeries()"; | |
227 |
|
227 | |||
228 | if (m_seriesCount > 9) |
|
228 | if (m_seriesCount > 9) | |
229 | return; |
|
229 | return; | |
230 |
|
230 | |||
231 | // Initial data |
|
231 | // Initial data | |
232 | QBoxSet *set0 = new QBoxSet(); |
|
232 | QBoxSet *set0 = new QBoxSet(); | |
233 | QBoxSet *set1 = new QBoxSet(); |
|
233 | QBoxSet *set1 = new QBoxSet(); | |
234 | QBoxSet *set2 = new QBoxSet(); |
|
234 | QBoxSet *set2 = new QBoxSet(); | |
235 | QBoxSet *set3 = new QBoxSet(); |
|
235 | QBoxSet *set3 = new QBoxSet(); | |
236 | QBoxSet *set4 = new QBoxSet(); |
|
236 | QBoxSet *set4 = new QBoxSet(); | |
237 | QBoxSet *set5 = new QBoxSet(); |
|
237 | QBoxSet *set5 = new QBoxSet(); | |
238 |
|
238 | |||
239 | // low bot med top upp |
|
239 | // low bot med top upp | |
240 | *set0 << -1 << 2 << 4 << 13 << 15; |
|
240 | *set0 << -1 << 2 << 4 << 13 << 15; | |
241 | *set1 << 5 << 6 << 7.5 << 8 << 12; |
|
241 | *set1 << 5 << 6 << 7.5 << 8 << 12; | |
242 | *set2 << 3 << 5 << 5.7 << 8 << 9; |
|
242 | *set2 << 3 << 5 << 5.7 << 8 << 9; | |
243 | *set3 << 5 << 6 << 6.8 << 7 << 8; |
|
243 | *set3 << 5 << 6 << 6.8 << 7 << 8; | |
244 | *set4 << 4 << 5 << 5.2 << 6 << 7; |
|
244 | *set4 << 4 << 5 << 5.2 << 6 << 7; | |
245 | *set5 << 4 << 7 << 8.2 << 9 << 10; |
|
245 | *set5 << 4 << 7 << 8.2 << 9 << 10; | |
246 |
|
246 | |||
247 | m_series[m_seriesCount] = new QBoxPlotSeries(); |
|
247 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
248 | m_series[m_seriesCount]->append(set0); |
|
248 | m_series[m_seriesCount]->append(set0); | |
249 | m_series[m_seriesCount]->append(set1); |
|
249 | m_series[m_seriesCount]->append(set1); | |
250 | m_series[m_seriesCount]->append(set2); |
|
250 | m_series[m_seriesCount]->append(set2); | |
251 | m_series[m_seriesCount]->append(set3); |
|
251 | m_series[m_seriesCount]->append(set3); | |
252 | m_series[m_seriesCount]->append(set4); |
|
252 | m_series[m_seriesCount]->append(set4); | |
253 | m_series[m_seriesCount]->append(set5); |
|
253 | m_series[m_seriesCount]->append(set5); | |
254 | m_series[m_seriesCount]->setName("Box & Whiskers"); |
|
254 | m_series[m_seriesCount]->setName("Box & Whiskers"); | |
255 |
|
255 | |||
256 | connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); |
|
256 | connect(m_series[m_seriesCount], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); | |
257 | connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); |
|
257 | connect(m_series[m_seriesCount], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); | |
258 | connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); |
|
258 | connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); | |
259 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); |
|
259 | connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); | |
260 |
|
260 | |||
261 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); |
|
261 | m_series[m_seriesCount]->setBoxOutlineVisible(m_boxOutlined->checkState()); | |
262 | m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); |
|
262 | m_series[m_seriesCount]->setBoxWidth(m_boxWidthSB->value()); | |
263 |
|
263 | |||
264 | m_chart->addSeries(m_series[m_seriesCount]); |
|
264 | m_chart->addSeries(m_series[m_seriesCount]); | |
265 |
|
265 | |||
266 | updateAxis(m_series[0]->count()); |
|
266 | updateAxis(m_series[0]->count()); | |
267 | m_chart->setAxisX(m_axis, m_series[m_seriesCount]); |
|
267 | m_chart->setAxisX(m_axis, m_series[m_seriesCount]); | |
268 |
|
268 | |||
269 | m_seriesCount++; |
|
269 | m_seriesCount++; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void MainWidget::removeSeries() |
|
272 | void MainWidget::removeSeries() | |
273 | { |
|
273 | { | |
274 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; |
|
274 | qDebug() << "BoxPlotTester::MainWidget::removeSeries()"; | |
275 |
|
275 | |||
276 | if (m_seriesCount > 0) { |
|
276 | if (m_seriesCount > 0) { | |
277 | m_seriesCount--; |
|
277 | m_seriesCount--; | |
278 | m_chart->removeSeries(m_series[m_seriesCount]); |
|
278 | m_chart->removeSeries(m_series[m_seriesCount]); | |
279 | delete m_series[m_seriesCount]; |
|
279 | delete m_series[m_seriesCount]; | |
280 | m_series[m_seriesCount] = 0; |
|
280 | m_series[m_seriesCount] = 0; | |
281 | } else { |
|
281 | } else { | |
282 | qDebug() << "Create a series first"; |
|
282 | qDebug() << "Create a series first"; | |
283 | } |
|
283 | } | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | void MainWidget::addBox() |
|
286 | void MainWidget::addBox() | |
287 | { |
|
287 | { | |
288 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; |
|
288 | qDebug() << "BoxPlotTester::MainWidget::addBox()"; | |
289 |
|
289 | |||
290 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { |
|
290 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
291 | QBoxSet *newSet = new QBoxSet(); |
|
291 | QBoxSet *newSet = new QBoxSet(); | |
292 | newSet->setValue(QBoxSet::LowerExtreme, 5.0); |
|
292 | newSet->setValue(QBoxSet::LowerExtreme, 5.0); | |
293 | newSet->setValue(QBoxSet::LowerQuartile, 6.0); |
|
293 | newSet->setValue(QBoxSet::LowerQuartile, 6.0); | |
294 | newSet->setValue(QBoxSet::Median, 6.8); |
|
294 | newSet->setValue(QBoxSet::Median, 6.8); | |
295 | newSet->setValue(QBoxSet::UpperQuartile, 7.0); |
|
295 | newSet->setValue(QBoxSet::UpperQuartile, 7.0); | |
296 | newSet->setValue(QBoxSet::UpperExtreme, 8.0); |
|
296 | newSet->setValue(QBoxSet::UpperExtreme, 8.0); | |
297 |
|
297 | |||
298 | updateAxis(m_series[0]->count() + 1); |
|
298 | updateAxis(m_series[0]->count() + 1); | |
299 |
|
299 | |||
300 | m_series[0]->append(newSet); |
|
300 | m_series[0]->append(newSet); | |
301 | } |
|
301 | } | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void MainWidget::insertBox() |
|
304 | void MainWidget::insertBox() | |
305 | { |
|
305 | { | |
306 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; |
|
306 | qDebug() << "BoxPlotTester::MainWidget::insertBox()"; | |
307 |
|
307 | |||
308 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { |
|
308 | if (m_seriesCount > 0 && m_series[0]->count() < maxCategories) { | |
309 | updateAxis(m_series[0]->count() + 1); |
|
309 | updateAxis(m_series[0]->count() + 1); | |
310 | for (int i = 0; i < m_seriesCount; i++) { |
|
310 | for (int i = 0; i < m_seriesCount; i++) { | |
311 | QBoxSet *newSet = new QBoxSet(); |
|
311 | QBoxSet *newSet = new QBoxSet(); | |
312 | *newSet << 2 << 6 << 6.8 << 7 << 10; |
|
312 | *newSet << 2 << 6 << 6.8 << 7 << 10; | |
313 | m_series[i]->insert(1, newSet); |
|
313 | m_series[i]->insert(1, newSet); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | void MainWidget::removeBox() |
|
318 | void MainWidget::removeBox() | |
319 | { |
|
319 | { | |
320 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; |
|
320 | qDebug() << "BoxPlotTester::MainWidget::removeBox"; | |
321 |
|
321 | |||
322 | if (m_seriesCount > 0) { |
|
322 | if (m_seriesCount > 0) { | |
323 | for (int i = 0; i < m_seriesCount; i++) { |
|
323 | for (int i = 0; i < m_seriesCount; i++) { | |
324 | qDebug() << "m_series[i]->count() = " << m_series[i]->count(); |
|
324 | qDebug() << "m_series[i]->count() = " << m_series[i]->count(); | |
325 | if (m_series[i]->count()) { |
|
325 | if (m_series[i]->count()) { | |
326 | QList<QBoxSet *> sets = m_series[i]->boxSets(); |
|
326 | QList<QBoxSet *> sets = m_series[i]->boxSets(); | |
327 | m_series[i]->remove(sets.at(m_series[i]->count() - 1)); |
|
327 | m_series[i]->remove(sets.at(m_series[i]->count() - 1)); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | updateAxis(m_series[0]->count()); |
|
331 | updateAxis(m_series[0]->count()); | |
332 | } else { |
|
332 | } else { | |
333 | qDebug() << "Create a series first"; |
|
333 | qDebug() << "Create a series first"; | |
334 | } |
|
334 | } | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void MainWidget::clear() |
|
337 | void MainWidget::clear() | |
338 | { |
|
338 | { | |
339 | qDebug() << "BoxPlotTester::MainWidget::clear"; |
|
339 | qDebug() << "BoxPlotTester::MainWidget::clear"; | |
340 |
|
340 | |||
341 | if (m_seriesCount > 0) |
|
341 | if (m_seriesCount > 0) | |
342 | m_series[0]->clear(); |
|
342 | m_series[0]->clear(); | |
343 | else |
|
343 | else | |
344 | qDebug() << "Create a series first"; |
|
344 | qDebug() << "Create a series first"; | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void MainWidget::clearBox() |
|
347 | void MainWidget::clearBox() | |
348 | { |
|
348 | { | |
349 | qDebug() << "BoxPlotTester::MainWidget::clearBox"; |
|
349 | qDebug() << "BoxPlotTester::MainWidget::clearBox"; | |
350 |
|
350 | |||
351 | if (m_seriesCount > 0) { |
|
351 | if (m_seriesCount > 0) { | |
352 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
352 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
353 | sets.at(1)->clear(); |
|
353 | if (sets.count() > 1) | |
|
354 | sets.at(1)->clear(); | |||
|
355 | else | |||
|
356 | qDebug() << "Create a series with at least two items first"; | |||
354 | } else { |
|
357 | } else { | |
355 | qDebug() << "Create a series first"; |
|
358 | qDebug() << "Create a series first"; | |
356 | } |
|
359 | } | |
357 | } |
|
360 | } | |
358 |
|
361 | |||
359 | void MainWidget::setBrush() |
|
362 | void MainWidget::setBrush() | |
360 | { |
|
363 | { | |
361 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; |
|
364 | qDebug() << "BoxPlotTester::MainWidget::setBrush"; | |
362 |
|
365 | |||
363 | if (m_seriesCount > 0) { |
|
366 | if (m_seriesCount > 0) { | |
364 | QList<QBoxSet *> sets = m_series[0]->boxSets(); |
|
367 | QList<QBoxSet *> sets = m_series[0]->boxSets(); | |
365 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); |
|
368 | sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); | |
366 | } else { |
|
369 | } else { | |
367 | qDebug() << "Create a series first"; |
|
370 | qDebug() << "Create a series first"; | |
368 | } |
|
371 | } | |
369 | } |
|
372 | } | |
370 |
|
373 | |||
371 | void MainWidget::animationToggled(bool enabled) |
|
374 | void MainWidget::animationToggled(bool enabled) | |
372 | { |
|
375 | { | |
373 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; |
|
376 | qDebug() << "BoxPlotTester::Animation toggled to " << enabled; | |
374 | if (enabled) |
|
377 | if (enabled) | |
375 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
378 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
376 | else |
|
379 | else | |
377 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
380 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
378 | } |
|
381 | } | |
379 |
|
382 | |||
380 | void MainWidget::legendToggled(bool enabled) |
|
383 | void MainWidget::legendToggled(bool enabled) | |
381 | { |
|
384 | { | |
382 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; |
|
385 | qDebug() << "BoxPlotTester::Legend toggled to " << enabled; | |
383 | m_chart->legend()->setVisible(enabled); |
|
386 | m_chart->legend()->setVisible(enabled); | |
384 | if (enabled) |
|
387 | if (enabled) | |
385 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
388 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
386 | } |
|
389 | } | |
387 |
|
390 | |||
388 | void MainWidget::titleToggled(bool enabled) |
|
391 | void MainWidget::titleToggled(bool enabled) | |
389 | { |
|
392 | { | |
390 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; |
|
393 | qDebug() << "BoxPlotTester::Title toggled to " << enabled; | |
391 | if (enabled) |
|
394 | if (enabled) | |
392 | m_chart->setTitle("Simple boxplotchart example"); |
|
395 | m_chart->setTitle("Simple boxplotchart example"); | |
393 | else |
|
396 | else | |
394 | m_chart->setTitle(""); |
|
397 | m_chart->setTitle(""); | |
395 | } |
|
398 | } | |
396 |
|
399 | |||
397 | void MainWidget::antialiasingToggled(bool enabled) |
|
400 | void MainWidget::antialiasingToggled(bool enabled) | |
398 | { |
|
401 | { | |
399 | qDebug() << "BoxPlotTester::antialiasingToggled toggled to " << enabled; |
|
402 | qDebug() << "BoxPlotTester::antialiasingToggled toggled to " << enabled; | |
400 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
403 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
401 | } |
|
404 | } | |
402 |
|
405 | |||
403 | void MainWidget::boxOutlineToggled(bool visible) |
|
406 | void MainWidget::boxOutlineToggled(bool visible) | |
404 | { |
|
407 | { | |
405 | qDebug() << "BoxPlotTester::boxOutlineToggled toggled to " << visible; |
|
408 | qDebug() << "BoxPlotTester::boxOutlineToggled toggled to " << visible; | |
406 | for (int i = 0; i < m_seriesCount; i++) |
|
409 | for (int i = 0; i < m_seriesCount; i++) | |
407 | m_series[i]->setBoxOutlineVisible(visible); |
|
410 | m_series[i]->setBoxOutlineVisible(visible); | |
408 | } |
|
411 | } | |
409 |
|
412 | |||
410 | void MainWidget::modelMapperToggled(bool enabled) |
|
413 | void MainWidget::modelMapperToggled(bool enabled) | |
411 | { |
|
414 | { | |
412 | if (enabled) { |
|
415 | if (enabled) { | |
413 | m_series[m_seriesCount] = new QBoxPlotSeries(); |
|
416 | m_series[m_seriesCount] = new QBoxPlotSeries(); | |
414 |
|
417 | |||
415 | int first = 0; |
|
418 | int first = 0; | |
416 | int count = 5; |
|
419 | int count = 5; | |
417 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); |
|
420 | QVBoxPlotModelMapper *mapper = new QVBoxPlotModelMapper(this); | |
418 | mapper->setFirstBoxSetColumn(0); |
|
421 | mapper->setFirstBoxSetColumn(0); | |
419 | mapper->setLastBoxSetColumn(5); |
|
422 | mapper->setLastBoxSetColumn(5); | |
420 | mapper->setFirstRow(first); |
|
423 | mapper->setFirstRow(first); | |
421 | mapper->setRowCount(count); |
|
424 | mapper->setRowCount(count); | |
422 | mapper->setSeries(m_series[m_seriesCount]); |
|
425 | mapper->setSeries(m_series[m_seriesCount]); | |
423 | mapper->setModel(m_model); |
|
426 | mapper->setModel(m_model); | |
424 | m_chart->addSeries(m_series[m_seriesCount]); |
|
427 | m_chart->addSeries(m_series[m_seriesCount]); | |
425 |
|
428 | |||
426 | m_seriesCount++; |
|
429 | m_seriesCount++; | |
427 | } else { |
|
430 | } else { | |
428 | removeSeries(); |
|
431 | removeSeries(); | |
429 | } |
|
432 | } | |
430 | } |
|
433 | } | |
431 |
|
434 | |||
432 | void MainWidget::changeChartTheme(int themeIndex) |
|
435 | void MainWidget::changeChartTheme(int themeIndex) | |
433 | { |
|
436 | { | |
434 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; |
|
437 | qDebug() << "BoxPlotTester::changeChartTheme: " << themeIndex; | |
435 | if (themeIndex == 0) |
|
438 | if (themeIndex == 0) | |
436 | m_chart->setTheme(QChart::ChartThemeLight); |
|
439 | m_chart->setTheme(QChart::ChartThemeLight); | |
437 | else |
|
440 | else | |
438 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); |
|
441 | m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); | |
439 | } |
|
442 | } | |
440 |
|
443 | |||
441 | void MainWidget::boxClicked(QBoxSet *set) |
|
444 | void MainWidget::boxClicked(QBoxSet *set) | |
442 | { |
|
445 | { | |
443 | qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); |
|
446 | qDebug() << "boxClicked, median = " << set->at(QBoxSet::Median); | |
444 | } |
|
447 | } | |
445 |
|
448 | |||
446 | void MainWidget::boxHovered(bool state, QBoxSet *set) |
|
449 | void MainWidget::boxHovered(bool state, QBoxSet *set) | |
447 | { |
|
450 | { | |
448 | if (state) |
|
451 | if (state) | |
449 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; |
|
452 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover started"; | |
450 | else |
|
453 | else | |
451 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; |
|
454 | qDebug() << "box median " << set->at(QBoxSet::Median) << " hover ended"; | |
452 | } |
|
455 | } | |
453 |
|
456 | |||
454 | void MainWidget::singleBoxClicked() |
|
457 | void MainWidget::singleBoxClicked() | |
455 | { |
|
458 | { | |
456 | qDebug() << "singleBoxClicked"; |
|
459 | qDebug() << "singleBoxClicked"; | |
457 | } |
|
460 | } | |
458 |
|
461 | |||
459 | void MainWidget::singleBoxHovered(bool state) |
|
462 | void MainWidget::singleBoxHovered(bool state) | |
460 | { |
|
463 | { | |
461 | if (state) |
|
464 | if (state) | |
462 | qDebug() << "single box hover started"; |
|
465 | qDebug() << "single box hover started"; | |
463 | else |
|
466 | else | |
464 | qDebug() << "single box hover ended"; |
|
467 | qDebug() << "single box hover ended"; | |
465 | } |
|
468 | } | |
466 |
|
469 | |||
467 | void MainWidget::changePen() |
|
470 | void MainWidget::changePen() | |
468 | { |
|
471 | { | |
469 | qDebug() << "changePen() = " << m_penTool->pen(); |
|
472 | qDebug() << "changePen() = " << m_penTool->pen(); | |
470 | for (int i = 0; i < m_seriesCount; i++) |
|
473 | for (int i = 0; i < m_seriesCount; i++) | |
471 | m_series[i]->setPen(m_penTool->pen()); |
|
474 | m_series[i]->setPen(m_penTool->pen()); | |
472 | } |
|
475 | } | |
473 |
|
476 | |||
474 | void MainWidget::setBoxWidth(double width) |
|
477 | void MainWidget::setBoxWidth(double width) | |
475 | { |
|
478 | { | |
476 | qDebug() << "setBoxWidth to " << width; |
|
479 | qDebug() << "setBoxWidth to " << width; | |
477 |
|
480 | |||
478 | for (int i = 0; i < m_seriesCount; i++) |
|
481 | for (int i = 0; i < m_seriesCount; i++) | |
479 | m_series[i]->setBoxWidth(qreal(width)); |
|
482 | m_series[i]->setBoxWidth(qreal(width)); | |
480 | } |
|
483 | } |
General Comments 0
You need to be logged in to leave comments.
Login now