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