##// END OF EJS Templates
Removing unused connections and slots...
Mika Salmela -
r2559:c86e17a9d40c
parent child
Show More
@@ -1,532 +1,489
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 "qboxplotmodelmapper.h"
21 #include "qboxplotmodelmapper.h"
22 #include "qboxplotmodelmapper_p.h"
22 #include "qboxplotmodelmapper_p.h"
23 #include "qboxplotseries.h"
23 #include "qboxplotseries.h"
24 #include "qboxset.h"
24 #include "qboxset.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include <QAbstractItemModel>
26 #include <QAbstractItemModel>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 QBoxPlotModelMapper::QBoxPlotModelMapper(QObject *parent) :
30 QBoxPlotModelMapper::QBoxPlotModelMapper(QObject *parent) :
31 QObject(parent),
31 QObject(parent),
32 d_ptr(new QBoxPlotModelMapperPrivate(this))
32 d_ptr(new QBoxPlotModelMapperPrivate(this))
33 {
33 {
34 }
34 }
35
35
36 QAbstractItemModel *QBoxPlotModelMapper::model() const
36 QAbstractItemModel *QBoxPlotModelMapper::model() const
37 {
37 {
38 Q_D(const QBoxPlotModelMapper);
38 Q_D(const QBoxPlotModelMapper);
39 return d->m_model;
39 return d->m_model;
40 }
40 }
41
41
42 void QBoxPlotModelMapper::setModel(QAbstractItemModel *model)
42 void QBoxPlotModelMapper::setModel(QAbstractItemModel *model)
43 {
43 {
44 if (model == 0)
44 if (model == 0)
45 return;
45 return;
46
46
47 Q_D(QBoxPlotModelMapper);
47 Q_D(QBoxPlotModelMapper);
48 if (d->m_model)
48 if (d->m_model)
49 disconnect(d->m_model, 0, d, 0);
49 disconnect(d->m_model, 0, d, 0);
50
50
51 d->m_model = model;
51 d->m_model = model;
52 d->initializeBoxFromModel();
52 d->initializeBoxFromModel();
53 // connect signals from the model
53 // connect signals from the model
54 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
54 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
55 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
55 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
56 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
56 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
60 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
60 connect(d->m_model, SIGNAL(destroyed()), d, SLOT(handleModelDestroyed()));
61 }
61 }
62
62
63 QBoxPlotSeries *QBoxPlotModelMapper::series() const
63 QBoxPlotSeries *QBoxPlotModelMapper::series() const
64 {
64 {
65 Q_D(const QBoxPlotModelMapper);
65 Q_D(const QBoxPlotModelMapper);
66 return d->m_series;
66 return d->m_series;
67 }
67 }
68
68
69 void QBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
69 void QBoxPlotModelMapper::setSeries(QBoxPlotSeries *series)
70 {
70 {
71 Q_D(QBoxPlotModelMapper);
71 Q_D(QBoxPlotModelMapper);
72 if (d->m_series)
72 if (d->m_series)
73 disconnect(d->m_series, 0, d, 0);
73 disconnect(d->m_series, 0, d, 0);
74
74
75 if (series == 0)
75 if (series == 0)
76 return;
76 return;
77
77
78 d->m_series = series;
78 d->m_series = series;
79 d->initializeBoxFromModel();
79 d->initializeBoxFromModel();
80 // connect the signals from the series
80 // connect the signals from the series
81 connect(d->m_series, SIGNAL(boxsetsAdded(QList<QBoxSet *>)), d, SLOT(boxSetsAdded(QList<QBoxSet *>)));
81 connect(d->m_series, SIGNAL(boxsetsAdded(QList<QBoxSet *>)), d, SLOT(boxSetsAdded(QList<QBoxSet *>)));
82 connect(d->m_series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), d, SLOT(boxSetsRemoved(QList<QBoxSet *>)));
82 connect(d->m_series, SIGNAL(boxsetsRemoved(QList<QBoxSet *>)), d, SLOT(boxSetsRemoved(QList<QBoxSet *>)));
83 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
83 connect(d->m_series, SIGNAL(destroyed()), d, SLOT(handleSeriesDestroyed()));
84 }
84 }
85
85
86 /*!
86 /*!
87 Returns which row/column of the model contains the first values of the QBoxSets in the series.
87 Returns which row/column of the model contains the first values of the QBoxSets in the series.
88 The default value is 0.
88 The default value is 0.
89 */
89 */
90 int QBoxPlotModelMapper::first() const
90 int QBoxPlotModelMapper::first() const
91 {
91 {
92 Q_D(const QBoxPlotModelMapper);
92 Q_D(const QBoxPlotModelMapper);
93 return d->m_first;
93 return d->m_first;
94 }
94 }
95
95
96 /*!
96 /*!
97 Sets which row/column of the model contains the \a first values of the QBoxSets in the series.
97 Sets which row/column of the model contains the \a first values of the QBoxSets in the series.
98 The default value is 0.
98 The default value is 0.
99 */
99 */
100 void QBoxPlotModelMapper::setFirst(int first)
100 void QBoxPlotModelMapper::setFirst(int first)
101 {
101 {
102 Q_D(QBoxPlotModelMapper);
102 Q_D(QBoxPlotModelMapper);
103 d->m_first = qMax(first, 0);
103 d->m_first = qMax(first, 0);
104 d->initializeBoxFromModel();
104 d->initializeBoxFromModel();
105 }
105 }
106
106
107 /*!
107 /*!
108 Returns the number of rows/columns of the model that are mapped as the data for QBoxPlotSeries
108 Returns the number of rows/columns of the model that are mapped as the data for QBoxPlotSeries
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
110 */
110 */
111 int QBoxPlotModelMapper::count() const
111 int QBoxPlotModelMapper::count() const
112 {
112 {
113 Q_D(const QBoxPlotModelMapper);
113 Q_D(const QBoxPlotModelMapper);
114 return d->m_count;
114 return d->m_count;
115 }
115 }
116
116
117 /*!
117 /*!
118 Sets the \a count of rows/columns of the model that are mapped as the data for QBoxPlotSeries
118 Sets the \a count of rows/columns of the model that are mapped as the data for QBoxPlotSeries
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
120 */
120 */
121 void QBoxPlotModelMapper::setCount(int count)
121 void QBoxPlotModelMapper::setCount(int count)
122 {
122 {
123 Q_D(QBoxPlotModelMapper);
123 Q_D(QBoxPlotModelMapper);
124 d->m_count = qMax(count, -1);
124 d->m_count = qMax(count, -1);
125 d->initializeBoxFromModel();
125 d->initializeBoxFromModel();
126 }
126 }
127
127
128 /*!
128 /*!
129 Returns the orientation that is used when QBoxPlotModelMapper accesses the model.
129 Returns the orientation that is used when QBoxPlotModelMapper accesses the model.
130 This means whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal)
130 This means whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal)
131 or from columns (Qt::Vertical)
131 or from columns (Qt::Vertical)
132 */
132 */
133 Qt::Orientation QBoxPlotModelMapper::orientation() const
133 Qt::Orientation QBoxPlotModelMapper::orientation() const
134 {
134 {
135 Q_D(const QBoxPlotModelMapper);
135 Q_D(const QBoxPlotModelMapper);
136 return d->m_orientation;
136 return d->m_orientation;
137 }
137 }
138
138
139 /*!
139 /*!
140 Returns the \a orientation that is used when QBoxPlotModelMapper accesses the model.
140 Returns the \a orientation that is used when QBoxPlotModelMapper accesses the model.
141 This mean whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal)
141 This mean whether the consecutive values of the box-and-whiskers set are read from row (Qt::Horizontal)
142 or from columns (Qt::Vertical)
142 or from columns (Qt::Vertical)
143 */
143 */
144 void QBoxPlotModelMapper::setOrientation(Qt::Orientation orientation)
144 void QBoxPlotModelMapper::setOrientation(Qt::Orientation orientation)
145 {
145 {
146 Q_D(QBoxPlotModelMapper);
146 Q_D(QBoxPlotModelMapper);
147 d->m_orientation = orientation;
147 d->m_orientation = orientation;
148 d->initializeBoxFromModel();
148 d->initializeBoxFromModel();
149 }
149 }
150
150
151 /*!
151 /*!
152 Returns which section of the model is used as the data source for the first box set
152 Returns which section of the model is used as the data source for the first box set
153 */
153 */
154 int QBoxPlotModelMapper::firstBoxSetSection() const
154 int QBoxPlotModelMapper::firstBoxSetSection() const
155 {
155 {
156 Q_D(const QBoxPlotModelMapper);
156 Q_D(const QBoxPlotModelMapper);
157 return d->m_firstBoxSetSection;
157 return d->m_firstBoxSetSection;
158 }
158 }
159
159
160 /*!
160 /*!
161 Sets the model section that is used as the data source for the first box set
161 Sets the model section that is used as the data source for the first box set
162 Parameter \a firstBoxSetSection specifies the section of the model.
162 Parameter \a firstBoxSetSection specifies the section of the model.
163 */
163 */
164 void QBoxPlotModelMapper::setFirstBoxSetSection(int firstBoxSetSection)
164 void QBoxPlotModelMapper::setFirstBoxSetSection(int firstBoxSetSection)
165 {
165 {
166 Q_D(QBoxPlotModelMapper);
166 Q_D(QBoxPlotModelMapper);
167 d->m_firstBoxSetSection = qMax(-1, firstBoxSetSection);
167 d->m_firstBoxSetSection = qMax(-1, firstBoxSetSection);
168 d->initializeBoxFromModel();
168 d->initializeBoxFromModel();
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns which section of the model is used as the data source for the last box set
172 Returns which section of the model is used as the data source for the last box set
173 */
173 */
174 int QBoxPlotModelMapper::lastBoxSetSection() const
174 int QBoxPlotModelMapper::lastBoxSetSection() const
175 {
175 {
176 Q_D(const QBoxPlotModelMapper);
176 Q_D(const QBoxPlotModelMapper);
177 return d->m_lastBoxSetSection;
177 return d->m_lastBoxSetSection;
178 }
178 }
179
179
180 /*!
180 /*!
181 Sets the model section that is used as the data source for the last box set
181 Sets the model section that is used as the data source for the last box set
182 Parameter \a lastBoxSetSection specifies the section of the model.
182 Parameter \a lastBoxSetSection specifies the section of the model.
183 */
183 */
184 void QBoxPlotModelMapper::setLastBoxSetSection(int lastBoxSetSection)
184 void QBoxPlotModelMapper::setLastBoxSetSection(int lastBoxSetSection)
185 {
185 {
186 Q_D(QBoxPlotModelMapper);
186 Q_D(QBoxPlotModelMapper);
187 d->m_lastBoxSetSection = qMax(-1, lastBoxSetSection);
187 d->m_lastBoxSetSection = qMax(-1, lastBoxSetSection);
188 d->initializeBoxFromModel();
188 d->initializeBoxFromModel();
189 }
189 }
190
190
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192
192
193 QBoxPlotModelMapperPrivate::QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q) :
193 QBoxPlotModelMapperPrivate::QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q) :
194 QObject(q),
194 QObject(q),
195 m_series(0),
195 m_series(0),
196 m_model(0),
196 m_model(0),
197 m_first(0),
197 m_first(0),
198 m_count(-1),
198 m_count(-1),
199 m_orientation(Qt::Vertical),
199 m_orientation(Qt::Vertical),
200 m_firstBoxSetSection(-1),
200 m_firstBoxSetSection(-1),
201 m_lastBoxSetSection(-1),
201 m_lastBoxSetSection(-1),
202 m_seriesSignalsBlock(false),
202 m_seriesSignalsBlock(false),
203 m_modelSignalsBlock(false),
203 m_modelSignalsBlock(false),
204 q_ptr(q)
204 q_ptr(q)
205 {
205 {
206 }
206 }
207
207
208 void QBoxPlotModelMapperPrivate::blockModelSignals(bool block)
208 void QBoxPlotModelMapperPrivate::blockModelSignals(bool block)
209 {
209 {
210 m_modelSignalsBlock = block;
210 m_modelSignalsBlock = block;
211 }
211 }
212
212
213 void QBoxPlotModelMapperPrivate::blockSeriesSignals(bool block)
213 void QBoxPlotModelMapperPrivate::blockSeriesSignals(bool block)
214 {
214 {
215 m_seriesSignalsBlock = block;
215 m_seriesSignalsBlock = block;
216 }
216 }
217
217
218 QBoxSet *QBoxPlotModelMapperPrivate::boxSet(QModelIndex index)
218 QBoxSet *QBoxPlotModelMapperPrivate::boxSet(QModelIndex index)
219 {
219 {
220 if (!index.isValid())
220 if (!index.isValid())
221 return 0;
221 return 0;
222
222
223 if (m_orientation == Qt::Vertical && index.column() >= m_firstBoxSetSection && index.column() <= m_lastBoxSetSection) {
223 if (m_orientation == Qt::Vertical && index.column() >= m_firstBoxSetSection && index.column() <= m_lastBoxSetSection) {
224 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
224 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
225 return m_series->boxSets().at(index.column() - m_firstBoxSetSection);
225 return m_series->boxSets().at(index.column() - m_firstBoxSetSection);
226 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBoxSetSection && index.row() <= m_lastBoxSetSection) {
226 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBoxSetSection && index.row() <= m_lastBoxSetSection) {
227 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
227 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
228 return m_series->boxSets().at(index.row() - m_firstBoxSetSection);
228 return m_series->boxSets().at(index.row() - m_firstBoxSetSection);
229 }
229 }
230 return 0; // This part of model has not been mapped to any boxset
230 return 0; // This part of model has not been mapped to any boxset
231 }
231 }
232
232
233 QModelIndex QBoxPlotModelMapperPrivate::boxModelIndex(int boxSection, int posInBar)
233 QModelIndex QBoxPlotModelMapperPrivate::boxModelIndex(int boxSection, int posInBar)
234 {
234 {
235 if (m_count != -1 && posInBar >= m_count)
235 if (m_count != -1 && posInBar >= m_count)
236 return QModelIndex(); // invalid
236 return QModelIndex(); // invalid
237
237
238 if (boxSection < m_firstBoxSetSection || boxSection > m_lastBoxSetSection)
238 if (boxSection < m_firstBoxSetSection || boxSection > m_lastBoxSetSection)
239 return QModelIndex(); // invalid
239 return QModelIndex(); // invalid
240
240
241 if (m_orientation == Qt::Vertical)
241 if (m_orientation == Qt::Vertical)
242 return m_model->index(posInBar + m_first, boxSection);
242 return m_model->index(posInBar + m_first, boxSection);
243 else
243 else
244 return m_model->index(boxSection, posInBar + m_first);
244 return m_model->index(boxSection, posInBar + m_first);
245 }
245 }
246
246
247 void QBoxPlotModelMapperPrivate::handleSeriesDestroyed()
247 void QBoxPlotModelMapperPrivate::handleSeriesDestroyed()
248 {
248 {
249 m_series = 0;
249 m_series = 0;
250 }
250 }
251
251
252 void QBoxPlotModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
252 void QBoxPlotModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
253 {
253 {
254 Q_UNUSED(topLeft)
254 Q_UNUSED(topLeft)
255 Q_UNUSED(bottomRight)
255 Q_UNUSED(bottomRight)
256
256
257 if (m_model == 0 || m_series == 0)
257 if (m_model == 0 || m_series == 0)
258 return;
258 return;
259
259
260 if (m_modelSignalsBlock)
260 if (m_modelSignalsBlock)
261 return;
261 return;
262
262
263 blockSeriesSignals();
263 blockSeriesSignals();
264 QModelIndex index;
264 QModelIndex index;
265 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
265 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
266 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
266 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
267 index = topLeft.sibling(row, column);
267 index = topLeft.sibling(row, column);
268 QBoxSet *box = boxSet(index);
268 QBoxSet *box = boxSet(index);
269 if (box) {
269 if (box) {
270 if (m_orientation == Qt::Vertical)
270 if (m_orientation == Qt::Vertical)
271 box->setValue(row - m_first, m_model->data(index).toReal());
271 box->setValue(row - m_first, m_model->data(index).toReal());
272 else
272 else
273 box->setValue(column - m_first, m_model->data(index).toReal());
273 box->setValue(column - m_first, m_model->data(index).toReal());
274 }
274 }
275 }
275 }
276 }
276 }
277 blockSeriesSignals(false);
277 blockSeriesSignals(false);
278 }
278 }
279
279
280 void QBoxPlotModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
280 void QBoxPlotModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
281 {
281 {
282 Q_UNUSED(orientation);
282 Q_UNUSED(orientation);
283 Q_UNUSED(first);
283 Q_UNUSED(first);
284 Q_UNUSED(last);
284 Q_UNUSED(last);
285 }
285 }
286
286
287 void QBoxPlotModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
287 void QBoxPlotModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
288 {
288 {
289 Q_UNUSED(parent)
289 Q_UNUSED(parent)
290 if (m_modelSignalsBlock)
290 if (m_modelSignalsBlock)
291 return;
291 return;
292
292
293 blockSeriesSignals();
293 blockSeriesSignals();
294 if (m_orientation == Qt::Vertical)
294 if (m_orientation == Qt::Vertical)
295 insertData(start, end);
295 insertData(start, end);
296 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
296 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
297 initializeBoxFromModel();
297 initializeBoxFromModel();
298 blockSeriesSignals(false);
298 blockSeriesSignals(false);
299 }
299 }
300
300
301 void QBoxPlotModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
301 void QBoxPlotModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
302 {
302 {
303 Q_UNUSED(parent)
303 Q_UNUSED(parent)
304 if (m_modelSignalsBlock)
304 if (m_modelSignalsBlock)
305 return;
305 return;
306
306
307 blockSeriesSignals();
307 blockSeriesSignals();
308 if (m_orientation == Qt::Vertical)
308 if (m_orientation == Qt::Vertical)
309 removeData(start, end);
309 removeData(start, end);
310 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
310 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
311 initializeBoxFromModel();
311 initializeBoxFromModel();
312 blockSeriesSignals(false);
312 blockSeriesSignals(false);
313 }
313 }
314
314
315 void QBoxPlotModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
315 void QBoxPlotModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
316 {
316 {
317 Q_UNUSED(parent)
317 Q_UNUSED(parent)
318 if (m_modelSignalsBlock)
318 if (m_modelSignalsBlock)
319 return;
319 return;
320
320
321 blockSeriesSignals();
321 blockSeriesSignals();
322 if (m_orientation == Qt::Horizontal)
322 if (m_orientation == Qt::Horizontal)
323 insertData(start, end);
323 insertData(start, end);
324 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
324 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
325 initializeBoxFromModel();
325 initializeBoxFromModel();
326 blockSeriesSignals(false);
326 blockSeriesSignals(false);
327 }
327 }
328
328
329 void QBoxPlotModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
329 void QBoxPlotModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
330 {
330 {
331 Q_UNUSED(parent)
331 Q_UNUSED(parent)
332 if (m_modelSignalsBlock)
332 if (m_modelSignalsBlock)
333 return;
333 return;
334
334
335 blockSeriesSignals();
335 blockSeriesSignals();
336 if (m_orientation == Qt::Horizontal)
336 if (m_orientation == Qt::Horizontal)
337 removeData(start, end);
337 removeData(start, end);
338 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
338 else if (start <= m_firstBoxSetSection || start <= m_lastBoxSetSection) // if the changes affect the map - reinitialize
339 initializeBoxFromModel();
339 initializeBoxFromModel();
340 blockSeriesSignals(false);
340 blockSeriesSignals(false);
341 }
341 }
342
342
343 void QBoxPlotModelMapperPrivate::handleModelDestroyed()
343 void QBoxPlotModelMapperPrivate::handleModelDestroyed()
344 {
344 {
345 m_model = 0;
345 m_model = 0;
346 }
346 }
347
347
348 void QBoxPlotModelMapperPrivate::insertData(int start, int end)
348 void QBoxPlotModelMapperPrivate::insertData(int start, int end)
349 {
349 {
350 Q_UNUSED(end)
350 Q_UNUSED(end)
351 Q_UNUSED(start)
351 Q_UNUSED(start)
352 Q_UNUSED(end)
352 Q_UNUSED(end)
353 // Currently boxplotchart needs to be fully recalculated when change is made.
353 // Currently boxplotchart needs to be fully recalculated when change is made.
354 // Re-initialize
354 // Re-initialize
355 initializeBoxFromModel();
355 initializeBoxFromModel();
356 }
356 }
357
357
358 void QBoxPlotModelMapperPrivate::removeData(int start, int end)
358 void QBoxPlotModelMapperPrivate::removeData(int start, int end)
359 {
359 {
360 Q_UNUSED(end)
360 Q_UNUSED(end)
361 Q_UNUSED(start)
361 Q_UNUSED(start)
362 Q_UNUSED(end)
362 Q_UNUSED(end)
363 // Currently boxplotchart needs to be fully recalculated when change is made.
363 // Currently boxplotchart needs to be fully recalculated when change is made.
364 // Re-initialize
364 // Re-initialize
365 initializeBoxFromModel();
365 initializeBoxFromModel();
366 }
366 }
367
367
368 void QBoxPlotModelMapperPrivate::boxSetsAdded(QList<QBoxSet *> sets)
368 void QBoxPlotModelMapperPrivate::boxSetsAdded(QList<QBoxSet *> sets)
369 {
369 {
370 if (m_seriesSignalsBlock)
370 if (m_seriesSignalsBlock)
371 return;
371 return;
372
372
373 if (sets.count() == 0)
373 if (sets.count() == 0)
374 return;
374 return;
375
375
376 int firstIndex = m_series->boxSets().indexOf(sets.at(0));
376 int firstIndex = m_series->boxSets().indexOf(sets.at(0));
377 if (firstIndex == -1)
377 if (firstIndex == -1)
378 return;
378 return;
379
379
380 int maxCount = 0;
380 int maxCount = 0;
381 for (int i = 0; i < sets.count(); i++) {
381 for (int i = 0; i < sets.count(); i++) {
382 if (sets.at(i)->count() > m_count)
382 if (sets.at(i)->count() > m_count)
383 maxCount = sets.at(i)->count();
383 maxCount = sets.at(i)->count();
384 }
384 }
385
385
386 if (m_count != -1 && m_count < maxCount)
386 if (m_count != -1 && m_count < maxCount)
387 m_count = maxCount;
387 m_count = maxCount;
388
388
389 m_lastBoxSetSection += sets.count();
389 m_lastBoxSetSection += sets.count();
390
390
391 blockModelSignals();
391 blockModelSignals();
392 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
392 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
393 if (maxCount > modelCapacity) {
393 if (maxCount > modelCapacity) {
394 if (m_orientation == Qt::Vertical)
394 if (m_orientation == Qt::Vertical)
395 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
395 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
396 else
396 else
397 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
397 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
398 }
398 }
399
399
400 if (m_orientation == Qt::Vertical)
400 if (m_orientation == Qt::Vertical)
401 m_model->insertColumns(firstIndex + m_firstBoxSetSection, sets.count());
401 m_model->insertColumns(firstIndex + m_firstBoxSetSection, sets.count());
402 else
402 else
403 m_model->insertRows(firstIndex + m_firstBoxSetSection, sets.count());
403 m_model->insertRows(firstIndex + m_firstBoxSetSection, sets.count());
404
404
405
405
406 for (int i = firstIndex + m_firstBoxSetSection; i < firstIndex + m_firstBoxSetSection + sets.count(); i++) {
406 for (int i = firstIndex + m_firstBoxSetSection; i < firstIndex + m_firstBoxSetSection + sets.count(); i++) {
407 for (int j = 0; j < sets.at(i - firstIndex - m_firstBoxSetSection)->count(); j++)
407 for (int j = 0; j < sets.at(i - firstIndex - m_firstBoxSetSection)->count(); j++)
408 m_model->setData(boxModelIndex(i, j), sets.at(i - firstIndex - m_firstBoxSetSection)->at(j));
408 m_model->setData(boxModelIndex(i, j), sets.at(i - firstIndex - m_firstBoxSetSection)->at(j));
409 }
409 }
410 blockModelSignals(false);
410 blockModelSignals(false);
411 initializeBoxFromModel();
411 initializeBoxFromModel();
412 }
412 }
413
413
414 void QBoxPlotModelMapperPrivate::boxSetsRemoved(QList<QBoxSet *> sets)
414 void QBoxPlotModelMapperPrivate::boxSetsRemoved(QList<QBoxSet *> sets)
415 {
415 {
416 if (m_seriesSignalsBlock)
416 if (m_seriesSignalsBlock)
417 return;
417 return;
418
418
419 if (sets.count() == 0)
419 if (sets.count() == 0)
420 return;
420 return;
421
421
422 int firstIndex = m_boxSets.indexOf(sets.at(0));
422 int firstIndex = m_boxSets.indexOf(sets.at(0));
423 if (firstIndex == -1)
423 if (firstIndex == -1)
424 return;
424 return;
425
425
426 m_lastBoxSetSection -= sets.count();
426 m_lastBoxSetSection -= sets.count();
427
427
428 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
428 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
429 m_boxSets.removeAt(i);
429 m_boxSets.removeAt(i);
430
430
431 blockModelSignals();
431 blockModelSignals();
432 if (m_orientation == Qt::Vertical)
432 if (m_orientation == Qt::Vertical)
433 m_model->removeColumns(firstIndex + m_firstBoxSetSection, sets.count());
433 m_model->removeColumns(firstIndex + m_firstBoxSetSection, sets.count());
434 else
434 else
435 m_model->removeRows(firstIndex + m_firstBoxSetSection, sets.count());
435 m_model->removeRows(firstIndex + m_firstBoxSetSection, sets.count());
436 blockModelSignals(false);
436 blockModelSignals(false);
437 initializeBoxFromModel();
437 initializeBoxFromModel();
438 }
438 }
439
439
440 void QBoxPlotModelMapperPrivate::valuesAdded(int index, int count)
441 {
442 if (m_seriesSignalsBlock)
443 return;
444
445 if (m_count != -1)
446 m_count += count;
447
448 int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender()));
449
450 blockModelSignals();
451 if (m_orientation == Qt::Vertical)
452 m_model->insertRows(index + m_first, count);
453 else
454 m_model->insertColumns(index + m_first, count);
455
456 for (int j = index; j < index + count; j++)
457 m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, j), m_boxSets.at(boxSetIndex)->at(j));
458
459 blockModelSignals(false);
460 initializeBoxFromModel();
461 }
462
463 void QBoxPlotModelMapperPrivate::valuesRemoved(int index, int count)
464 {
465 if (m_seriesSignalsBlock)
466 return;
467
468 if (m_count != -1)
469 m_count -= count;
470
471 blockModelSignals();
472 if (m_orientation == Qt::Vertical)
473 m_model->removeRows(index + m_first, count);
474 else
475 m_model->removeColumns(index + m_first, count);
476
477 blockModelSignals(false);
478 initializeBoxFromModel();
479 }
480
481 void QBoxPlotModelMapperPrivate::boxValueChanged(int index)
440 void QBoxPlotModelMapperPrivate::boxValueChanged(int index)
482 {
441 {
483 if (m_seriesSignalsBlock)
442 if (m_seriesSignalsBlock)
484 return;
443 return;
485
444
486 int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender()));
445 int boxSetIndex = m_boxSets.indexOf(qobject_cast<QBoxSet *>(QObject::sender()));
487
446
488 blockModelSignals();
447 blockModelSignals();
489 m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, index), m_boxSets.at(boxSetIndex)->at(index));
448 m_model->setData(boxModelIndex(boxSetIndex + m_firstBoxSetSection, index), m_boxSets.at(boxSetIndex)->at(index));
490 blockModelSignals(false);
449 blockModelSignals(false);
491 initializeBoxFromModel();
450 initializeBoxFromModel();
492 }
451 }
493
452
494 void QBoxPlotModelMapperPrivate::initializeBoxFromModel()
453 void QBoxPlotModelMapperPrivate::initializeBoxFromModel()
495 {
454 {
496 if (m_model == 0 || m_series == 0)
455 if (m_model == 0 || m_series == 0)
497 return;
456 return;
498
457
499 blockSeriesSignals();
458 blockSeriesSignals();
500 // clear current content
459 // clear current content
501 m_series->clear();
460 m_series->clear();
502 m_boxSets.clear();
461 m_boxSets.clear();
503
462
504 // create the initial box-and-whiskers sets
463 // create the initial box-and-whiskers sets
505 for (int i = m_firstBoxSetSection; i <= m_lastBoxSetSection; i++) {
464 for (int i = m_firstBoxSetSection; i <= m_lastBoxSetSection; i++) {
506 int posInBar = 0;
465 int posInBar = 0;
507 QModelIndex boxIndex = boxModelIndex(i, posInBar);
466 QModelIndex boxIndex = boxModelIndex(i, posInBar);
508 // check if there is such model index
467 // check if there is such model index
509 if (boxIndex.isValid()) {
468 if (boxIndex.isValid()) {
510 QBoxSet *boxSet = new QBoxSet();
469 QBoxSet *boxSet = new QBoxSet();
511 while (boxIndex.isValid()) {
470 while (boxIndex.isValid()) {
512 boxSet->append(m_model->data(boxIndex, Qt::DisplayRole).toDouble());
471 boxSet->append(m_model->data(boxIndex, Qt::DisplayRole).toDouble());
513 posInBar++;
472 posInBar++;
514 boxIndex = boxModelIndex(i, posInBar);
473 boxIndex = boxModelIndex(i, posInBar);
515 }
474 }
516 connect(boxSet, SIGNAL(valuesAdded(int,int)), this, SLOT(valuesAdded(int,int)));
517 connect(boxSet, SIGNAL(valuesRemoved(int,int)), this, SLOT(valuesRemoved(int,int)));
518 connect(boxSet, SIGNAL(valueChanged(int)), this, SLOT(boxValueChanged(int)));
475 connect(boxSet, SIGNAL(valueChanged(int)), this, SLOT(boxValueChanged(int)));
519 m_series->append(boxSet);
476 m_series->append(boxSet);
520 m_boxSets.append(boxSet);
477 m_boxSets.append(boxSet);
521 } else {
478 } else {
522 break;
479 break;
523 }
480 }
524 }
481 }
525 blockSeriesSignals(false);
482 blockSeriesSignals(false);
526 }
483 }
527
484
528 #include "moc_qboxplotmodelmapper.cpp"
485 #include "moc_qboxplotmodelmapper.cpp"
529 #include "moc_qboxplotmodelmapper_p.cpp"
486 #include "moc_qboxplotmodelmapper_p.cpp"
530
487
531 QTCOMMERCIALCHART_END_NAMESPACE
488 QTCOMMERCIALCHART_END_NAMESPACE
532
489
@@ -1,95 +1,93
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBOXPLOTMODELMAPPER_P_H
30 #ifndef QBOXPLOTMODELMAPPER_P_H
31 #define QBOXPLOTMODELMAPPER_P_H
31 #define QBOXPLOTMODELMAPPER_P_H
32
32
33 #include <QObject>
33 #include <QObject>
34 #include "qboxplotmodelmapper.h"
34 #include "qboxplotmodelmapper.h"
35
35
36 class QModelIndex;
36 class QModelIndex;
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QBoxSet;
40 class QBoxSet;
41
41
42 class QBoxPlotModelMapperPrivate : public QObject
42 class QBoxPlotModelMapperPrivate : public QObject
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 explicit QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q);
46 explicit QBoxPlotModelMapperPrivate(QBoxPlotModelMapper *q);
47
47
48 public Q_SLOTS:
48 public Q_SLOTS:
49 // for the model
49 // for the model
50 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
50 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
51 void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last);
51 void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last);
52 void modelRowsAdded(QModelIndex parent, int start, int end);
52 void modelRowsAdded(QModelIndex parent, int start, int end);
53 void modelRowsRemoved(QModelIndex parent, int start, int end);
53 void modelRowsRemoved(QModelIndex parent, int start, int end);
54 void modelColumnsAdded(QModelIndex parent, int start, int end);
54 void modelColumnsAdded(QModelIndex parent, int start, int end);
55 void modelColumnsRemoved(QModelIndex parent, int start, int end);
55 void modelColumnsRemoved(QModelIndex parent, int start, int end);
56 void handleModelDestroyed();
56 void handleModelDestroyed();
57
57
58 // for the series
58 // for the series
59 void boxSetsAdded(QList<QBoxSet *> sets);
59 void boxSetsAdded(QList<QBoxSet *> sets);
60 void boxSetsRemoved(QList<QBoxSet *> sets);
60 void boxSetsRemoved(QList<QBoxSet *> sets);
61 void valuesAdded(int index, int count);
62 void valuesRemoved(int index, int count);
63 void boxValueChanged(int index);
61 void boxValueChanged(int index);
64 void handleSeriesDestroyed();
62 void handleSeriesDestroyed();
65
63
66 void initializeBoxFromModel();
64 void initializeBoxFromModel();
67
65
68 private:
66 private:
69 QBoxSet *boxSet(QModelIndex index);
67 QBoxSet *boxSet(QModelIndex index);
70 QModelIndex boxModelIndex(int boxSection, int posInBox);
68 QModelIndex boxModelIndex(int boxSection, int posInBox);
71 void insertData(int start, int end);
69 void insertData(int start, int end);
72 void removeData(int start, int end);
70 void removeData(int start, int end);
73 void blockModelSignals(bool block = true);
71 void blockModelSignals(bool block = true);
74 void blockSeriesSignals(bool block = true);
72 void blockSeriesSignals(bool block = true);
75
73
76 private:
74 private:
77 QBoxPlotSeries *m_series;
75 QBoxPlotSeries *m_series;
78 QList<QBoxSet *> m_boxSets;
76 QList<QBoxSet *> m_boxSets;
79 QAbstractItemModel *m_model;
77 QAbstractItemModel *m_model;
80 int m_first;
78 int m_first;
81 int m_count;
79 int m_count;
82 Qt::Orientation m_orientation;
80 Qt::Orientation m_orientation;
83 int m_firstBoxSetSection;
81 int m_firstBoxSetSection;
84 int m_lastBoxSetSection;
82 int m_lastBoxSetSection;
85 bool m_seriesSignalsBlock;
83 bool m_seriesSignalsBlock;
86 bool m_modelSignalsBlock;
84 bool m_modelSignalsBlock;
87
85
88 private:
86 private:
89 QBoxPlotModelMapper *q_ptr;
87 QBoxPlotModelMapper *q_ptr;
90 Q_DECLARE_PUBLIC(QBoxPlotModelMapper)
88 Q_DECLARE_PUBLIC(QBoxPlotModelMapper)
91 };
89 };
92
90
93 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
94
92
95 #endif // QBOXPLOTMODELMAPPER_P_H
93 #endif // QBOXPLOTMODELMAPPER_P_H
@@ -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 addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
50 QString addCategories[] = {"Jul", "Aug", "Sep", "Nov", "Dec"};
51 static const int maxAddCategories = 5;
51 static const int maxAddCategories = 5;
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 rowPos(0),
58 nSeries(0),
58 nSeries(0),
59 nNewBoxes(0)
59 nNewBoxes(0)
60 {
60 {
61 m_chart = new QChart();
61 m_chart = new QChart();
62
62
63 // Grid layout for the controls for configuring the chart widget
63 // Grid layout for the controls for configuring the chart widget
64 QGridLayout *grid = new QGridLayout();
64 QGridLayout *grid = new QGridLayout();
65
65
66 // Create add a series button
66 // Create add a series button
67 QPushButton *addSeriesButton = new QPushButton("Add a series");
67 QPushButton *addSeriesButton = new QPushButton("Add a series");
68 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
68 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
69 grid->addWidget(addSeriesButton, rowPos++, 1);
69 grid->addWidget(addSeriesButton, rowPos++, 1);
70
70
71 // Create remove a series button
71 // Create remove a series button
72 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
72 QPushButton *removeSeriesButton = new QPushButton("Remove a series");
73 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
73 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
74 grid->addWidget(removeSeriesButton, rowPos++, 1);
74 grid->addWidget(removeSeriesButton, rowPos++, 1);
75
75
76 // Create add a single box button
76 // Create add a single box button
77 QPushButton *addBoxButton = new QPushButton("Add a box");
77 QPushButton *addBoxButton = new QPushButton("Add a box");
78 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
78 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
79 grid->addWidget(addBoxButton, rowPos++, 1);
79 grid->addWidget(addBoxButton, rowPos++, 1);
80
80
81 // Create insert a box button
81 // Create insert a box button
82 QPushButton *insertBoxButton = new QPushButton("Insert a box");
82 QPushButton *insertBoxButton = new QPushButton("Insert a box");
83 connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox()));
83 connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox()));
84 grid->addWidget(insertBoxButton, rowPos++, 1);
84 grid->addWidget(insertBoxButton, rowPos++, 1);
85
85
86 // Create add a single box button
86 // Create add a single box button
87 QPushButton *removeBoxButton = new QPushButton("Remove a box");
87 QPushButton *removeBoxButton = new QPushButton("Remove a box");
88 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
88 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
89 grid->addWidget(removeBoxButton, rowPos++, 1);
89 grid->addWidget(removeBoxButton, rowPos++, 1);
90
90
91 // Create clear button
91 // Create clear button
92 QPushButton *clearButton = new QPushButton("Clear");
92 QPushButton *clearButton = new QPushButton("Clear");
93 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
93 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
94 grid->addWidget(clearButton, rowPos++, 1);
94 grid->addWidget(clearButton, rowPos++, 1);
95
95
96 // Create clear button
96 // Create clear button
97 QPushButton *clearBoxButton = new QPushButton("ClearBox");
97 QPushButton *clearBoxButton = new QPushButton("ClearBox");
98 connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox()));
98 connect(clearBoxButton, SIGNAL(clicked()), this, SLOT(clearBox()));
99 grid->addWidget(clearBoxButton, rowPos++, 1);
99 grid->addWidget(clearBoxButton, rowPos++, 1);
100
100
101
101
102 // Create set brush button
102 // Create set brush button
103 QPushButton *setBrushButton = new QPushButton("Set brush");
103 QPushButton *setBrushButton = new QPushButton("Set brush");
104 connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush()));
104 connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush()));
105 grid->addWidget(setBrushButton, rowPos++, 1);
105 grid->addWidget(setBrushButton, rowPos++, 1);
106
106
107 initThemeCombo(grid);
107 initThemeCombo(grid);
108 initCheckboxes(grid);
108 initCheckboxes(grid);
109
109
110 m_model = new CustomTableModel;
110 m_model = new CustomTableModel();
111 QTableView *tableView = new QTableView;
111 QTableView *tableView = new QTableView;
112 tableView->setModel(m_model);
112 tableView->setModel(m_model);
113 tableView->setMaximumWidth(200);
113 tableView->setMaximumWidth(200);
114 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
114 grid->addWidget(tableView, rowPos++, 0, 3, 2, Qt::AlignLeft);
115 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
115 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
116 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
116 tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
117 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
117 tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
118 #else
118 #else
119 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
119 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
120 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
120 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
121 #endif
121 #endif
122
122
123 // add row with empty label to make all the other rows static
123 // add row with empty label to make all the other rows static
124 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
124 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
125 grid->setRowStretch(grid->rowCount() - 1, 1);
125 grid->setRowStretch(grid->rowCount() - 1, 1);
126
126
127 // Create chart view with the chart
127 // Create chart view with the chart
128 m_chartView = new QChartView(m_chart, this);
128 m_chartView = new QChartView(m_chart, this);
129
129
130 // Another grid layout as a main layout
130 // Another grid layout as a main layout
131 QGridLayout *mainLayout = new QGridLayout();
131 QGridLayout *mainLayout = new QGridLayout();
132 mainLayout->addLayout(grid, 0, 0);
132 mainLayout->addLayout(grid, 0, 0);
133 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
133 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
134 setLayout(mainLayout);
134 setLayout(mainLayout);
135
135
136 legendToggled(false);
136 legendToggled(false);
137 animationToggled(false);
137 animationToggled(false);
138 }
138 }
139
139
140 // Combo box for selecting theme
140 // Combo box for selecting theme
141 void MainWidget::initThemeCombo(QGridLayout *grid)
141 void MainWidget::initThemeCombo(QGridLayout *grid)
142 {
142 {
143 QComboBox *chartTheme = new QComboBox();
143 QComboBox *chartTheme = new QComboBox();
144 chartTheme->addItem("Default");
144 chartTheme->addItem("Default");
145 chartTheme->addItem("Light");
145 chartTheme->addItem("Light");
146 chartTheme->addItem("Blue Cerulean");
146 chartTheme->addItem("Blue Cerulean");
147 chartTheme->addItem("Dark");
147 chartTheme->addItem("Dark");
148 chartTheme->addItem("Brown Sand");
148 chartTheme->addItem("Brown Sand");
149 chartTheme->addItem("Blue NCS");
149 chartTheme->addItem("Blue NCS");
150 chartTheme->addItem("High Contrast");
150 chartTheme->addItem("High Contrast");
151 chartTheme->addItem("Blue Icy");
151 chartTheme->addItem("Blue Icy");
152 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
152 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
153 this, SLOT(changeChartTheme(int)));
153 this, SLOT(changeChartTheme(int)));
154 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
154 grid->addWidget(new QLabel("Chart theme:"), rowPos, 0);
155 grid->addWidget(chartTheme, rowPos++, 1);
155 grid->addWidget(chartTheme, rowPos++, 1);
156 }
156 }
157
157
158 // Different check boxes for customizing chart
158 // Different check boxes for customizing chart
159 void MainWidget::initCheckboxes(QGridLayout *grid)
159 void MainWidget::initCheckboxes(QGridLayout *grid)
160 {
160 {
161 QCheckBox *animationCheckBox = new QCheckBox("Animation");
161 QCheckBox *animationCheckBox = new QCheckBox("Animation");
162 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
162 connect(animationCheckBox, SIGNAL(toggled(bool)), this, SLOT(animationToggled(bool)));
163 animationCheckBox->setChecked(false);
163 animationCheckBox->setChecked(false);
164 grid->addWidget(animationCheckBox, rowPos++, 0);
164 grid->addWidget(animationCheckBox, rowPos++, 0);
165
165
166 QCheckBox *legendCheckBox = new QCheckBox("Legend");
166 QCheckBox *legendCheckBox = new QCheckBox("Legend");
167 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
167 connect(legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(legendToggled(bool)));
168 legendCheckBox->setChecked(false);
168 legendCheckBox->setChecked(false);
169 grid->addWidget(legendCheckBox, rowPos++, 0);
169 grid->addWidget(legendCheckBox, rowPos++, 0);
170
170
171 QCheckBox *titleCheckBox = new QCheckBox("Title");
171 QCheckBox *titleCheckBox = new QCheckBox("Title");
172 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
172 connect(titleCheckBox, SIGNAL(toggled(bool)), this, SLOT(titleToggled(bool)));
173 titleCheckBox->setChecked(false);
173 titleCheckBox->setChecked(false);
174 grid->addWidget(titleCheckBox, rowPos++, 0);
174 grid->addWidget(titleCheckBox, rowPos++, 0);
175
175
176 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
176 QCheckBox *modelMapperCheckBox = new QCheckBox("Use model mapper");
177 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
177 connect(modelMapperCheckBox, SIGNAL(toggled(bool)), this, SLOT(modelMapperToggled(bool)));
178 modelMapperCheckBox->setChecked(false);
178 modelMapperCheckBox->setChecked(false);
179 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
179 grid->addWidget(modelMapperCheckBox, rowPos++, 0);
180
180
181 }
181 }
182
182
183 void MainWidget::addSeries()
183 void MainWidget::addSeries()
184 {
184 {
185 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
185 qDebug() << "BoxPlotTester::MainWidget::addSeries()";
186
186
187 if (nSeries > 9)
187 if (nSeries > 9)
188 return;
188 return;
189
189
190 // Initial data
190 // Initial data
191 QBoxSet *set0 = new QBoxSet();
191 QBoxSet *set0 = new QBoxSet();
192 QBoxSet *set1 = new QBoxSet();
192 QBoxSet *set1 = new QBoxSet();
193 QBoxSet *set2 = new QBoxSet();
193 QBoxSet *set2 = new QBoxSet();
194 QBoxSet *set3 = new QBoxSet();
194 QBoxSet *set3 = new QBoxSet();
195 QBoxSet *set4 = new QBoxSet();
195 QBoxSet *set4 = new QBoxSet();
196 QBoxSet *set5 = new QBoxSet();
196 QBoxSet *set5 = new QBoxSet();
197
197
198 // low bot med top upp
198 // low bot med top upp
199 *set0 << -1 << 2 << 4 << 13 << 15;
199 *set0 << -1 << 2 << 4 << 13 << 15;
200 *set1 << 5 << 6 << 7.5 << 8 << 12;
200 *set1 << 5 << 6 << 7.5 << 8 << 12;
201 *set2 << 3 << 5 << 5.7 << 8 << 9;
201 *set2 << 3 << 5 << 5.7 << 8 << 9;
202 *set3 << 5 << 6 << 6.8 << 7 << 8;
202 *set3 << 5 << 6 << 6.8 << 7 << 8;
203 *set4 << 4 << 5 << 5.2 << 6 << 7;
203 *set4 << 4 << 5 << 5.2 << 6 << 7;
204 *set5 << 4 << 7 << 8.2 << 9 << 10;
204 *set5 << 4 << 7 << 8.2 << 9 << 10;
205
205
206 m_series[nSeries] = new QBoxPlotSeries();
206 m_series[nSeries] = new QBoxPlotSeries();
207 m_series[nSeries]->append(set0);
207 m_series[nSeries]->append(set0);
208 m_series[nSeries]->append(set1);
208 m_series[nSeries]->append(set1);
209 m_series[nSeries]->append(set2);
209 m_series[nSeries]->append(set2);
210 m_series[nSeries]->append(set3);
210 m_series[nSeries]->append(set3);
211 m_series[nSeries]->append(set4);
211 m_series[nSeries]->append(set4);
212 m_series[nSeries]->append(set5);
212 m_series[nSeries]->append(set5);
213 m_series[nSeries]->setName("Box & Whiskers");
213 m_series[nSeries]->setName("Box & Whiskers");
214
214
215 connect(m_series[nSeries], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*)));
215 connect(m_series[nSeries], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*)));
216 connect(m_series[nSeries], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*)));
216 connect(m_series[nSeries], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*)));
217 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
217 connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked()));
218 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
218 connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool)));
219
219
220 m_chart->addSeries(m_series[nSeries]);
220 m_chart->addSeries(m_series[nSeries]);
221
221
222 if (!m_axis) {
222 if (!m_axis) {
223 QStringList categories;
223 QStringList categories;
224 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
224 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
225 m_axis = new QBarCategoryAxis();
225 m_axis = new QBarCategoryAxis();
226 m_axis->append(categories);
226 m_axis->append(categories);
227 m_chart->createDefaultAxes();
227 m_chart->createDefaultAxes();
228 }
228 }
229 m_chart->setAxisX(m_axis, m_series[nSeries]);
229 m_chart->setAxisX(m_axis, m_series[nSeries]);
230
230
231 nSeries++;
231 nSeries++;
232 }
232 }
233
233
234 void MainWidget::removeSeries()
234 void MainWidget::removeSeries()
235 {
235 {
236 qDebug() << "BoxPlotTester::MainWidget::removeSeries()";
236 qDebug() << "BoxPlotTester::MainWidget::removeSeries()";
237
237
238 if (nSeries > 0) {
238 if (nSeries > 0) {
239 nSeries--;
239 nSeries--;
240 m_chart->removeSeries(m_series[nSeries]);
240 m_chart->removeSeries(m_series[nSeries]);
241 delete m_series[nSeries];
241 delete m_series[nSeries];
242 } else {
242 } else {
243 qDebug() << "Create a series first";
243 qDebug() << "Create a series first";
244 }
244 }
245 }
245 }
246
246
247 void MainWidget::addBox()
247 void MainWidget::addBox()
248 {
248 {
249 qDebug() << "BoxPlotTester::MainWidget::addBox()";
249 qDebug() << "BoxPlotTester::MainWidget::addBox()";
250
250
251 if (nSeries > 0 && nNewBoxes < maxAddCategories) {
251 if (nSeries > 0 && nNewBoxes < maxAddCategories) {
252 QBoxSet *newSet = new QBoxSet();
252 QBoxSet *newSet = new QBoxSet();
253 newSet->setValue(QBoxSet::LowerExtreme, 5.0);
253 newSet->setValue(QBoxSet::LowerExtreme, 5.0);
254 newSet->setValue(QBoxSet::LowerQuartile, 6.0);
254 newSet->setValue(QBoxSet::LowerQuartile, 6.0);
255 newSet->setValue(QBoxSet::Median, 6.8);
255 newSet->setValue(QBoxSet::Median, 6.8);
256 newSet->setValue(QBoxSet::UpperQuartile, 7.0);
256 newSet->setValue(QBoxSet::UpperQuartile, 7.0);
257 newSet->setValue(QBoxSet::UpperExtreme, 8.0);
257 newSet->setValue(QBoxSet::UpperExtreme, 8.0);
258
258
259 m_series[0]->append(newSet);
259 m_series[0]->append(newSet);
260
260
261 m_axis->append(addCategories[nNewBoxes]);
261 m_axis->append(addCategories[nNewBoxes]);
262
262
263 nNewBoxes++;
263 nNewBoxes++;
264 }
264 }
265 }
265 }
266
266
267 void MainWidget::insertBox()
267 void MainWidget::insertBox()
268 {
268 {
269 qDebug() << "BoxPlotTester::MainWidget::insertBox()";
269 qDebug() << "BoxPlotTester::MainWidget::insertBox()";
270
270
271 if (nSeries > 0) {
271 if (nSeries > 0) {
272 QBoxSet *newSet = new QBoxSet();
272 QBoxSet *newSet = new QBoxSet();
273 *newSet << 2 << 6 << 6.8 << 7 << 10;
273 *newSet << 2 << 6 << 6.8 << 7 << 10;
274
274
275 for (int i = 0; i < nSeries; i++)
275 for (int i = 0; i < nSeries; i++)
276 m_series[i]->insert(1, newSet);
276 m_series[i]->insert(1, newSet);
277
277
278 m_axis->append(addCategories[nNewBoxes]);
278 m_axis->append(addCategories[nNewBoxes]);
279
279
280 nNewBoxes++;
280 nNewBoxes++;
281 }
281 }
282 }
282 }
283
283
284 void MainWidget::removeBox()
284 void MainWidget::removeBox()
285 {
285 {
286 qDebug() << "BoxPlotTester::MainWidget::removeBox";
286 qDebug() << "BoxPlotTester::MainWidget::removeBox";
287
287
288 if (nSeries > 0) {
288 if (nSeries > 0) {
289 for (int i = 0; i < nSeries; i++) {
289 for (int i = 0; i < nSeries; i++) {
290 qDebug() << "m_series[i]->count() = " << m_series[i]->count();
290 qDebug() << "m_series[i]->count() = " << m_series[i]->count();
291 if (m_series[i]->count() > 3) {
291 if (m_series[i]->count() > 3) {
292 QList<QBoxSet *> sets = m_series[i]->boxSets();
292 QList<QBoxSet *> sets = m_series[i]->boxSets();
293 m_series[i]->remove(sets.at(m_series[i]->count() - 3));
293 m_series[i]->remove(sets.at(m_series[i]->count() - 3));
294 }
294 }
295 }
295 }
296
296
297 if (m_axis->count() > 3)
297 if (m_axis->count() > 3)
298 m_axis->remove(m_axis->at(1));
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 (nSeries > 0)
308 if (nSeries > 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 (nSeries > 0) {
318 if (nSeries > 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 (nSeries > 0) {
330 if (nSeries > 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[nSeries] = new QBoxPlotSeries();
367 m_series[nSeries] = 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[nSeries]);
376 mapper->setSeries(m_series[nSeries]);
377 mapper->setModel(m_model);
377 mapper->setModel(m_model);
378 m_chart->addSeries(m_series[nSeries]);
378 m_chart->addSeries(m_series[nSeries]);
379
379
380 nSeries++;
380 nSeries++;
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 }
General Comments 0
You need to be logged in to leave comments. Login now