##// END OF EJS Templates
Fixed problem with qhxymodelmapper
Marek Rosa -
r1317:1951d151d7af
parent child
Show More
@@ -1,424 +1,440
1 #include "qxymodelmapper.h"
1 #include "qxymodelmapper.h"
2 #include "qxymodelmapper_p.h"
2 #include "qxymodelmapper_p.h"
3 #include "qxyseries.h"
3 #include "qxyseries.h"
4 #include <QAbstractItemModel>
4 #include <QAbstractItemModel>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 QXYModelMapper::QXYModelMapper(QObject *parent):
8 QXYModelMapper::QXYModelMapper(QObject *parent):
9 QObject(parent),
9 QObject(parent),
10 d_ptr(new QXYModelMapperPrivate(this))
10 d_ptr(new QXYModelMapperPrivate(this))
11 {
11 {
12 }
12 }
13
13
14 QXYModelMapper::~QXYModelMapper()
14 QXYModelMapper::~QXYModelMapper()
15 {
15 {
16 Q_D(QXYModelMapper);
16 Q_D(QXYModelMapper);
17 disconnect(d->m_model, 0, d, 0);
17 disconnect(d->m_model, 0, d, 0);
18 // disconnect(d->m_series, 0, d, 0);
18 // disconnect(d->m_series, 0, d, 0);
19 }
19 }
20
20
21 QAbstractItemModel* QXYModelMapper::model() const
21 QAbstractItemModel* QXYModelMapper::model() const
22 {
22 {
23 Q_D(const QXYModelMapper);
23 Q_D(const QXYModelMapper);
24 return d->m_model;
24 return d->m_model;
25 }
25 }
26
26
27 void QXYModelMapper::setModel(QAbstractItemModel *model)
27 void QXYModelMapper::setModel(QAbstractItemModel *model)
28 {
28 {
29 if (model == 0)
29 if (model == 0)
30 return;
30 return;
31
31
32 Q_D(QXYModelMapper);
32 Q_D(QXYModelMapper);
33 if (d->m_model) {
33 if (d->m_model) {
34 disconnect(d->m_model, 0, d, 0);
34 disconnect(d->m_model, 0, d, 0);
35 }
35 }
36
36
37 d->m_model = model;
37 d->m_model = model;
38 d->initializeXYFromModel();
38 d->initializeXYFromModel();
39 // connect signals from the model
39 // connect signals from the model
40 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
40 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
41 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
41 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
42 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
42 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
43 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
43 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
44 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
44 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
45 }
45 }
46
46
47 QXYSeries* QXYModelMapper::series() const
47 QXYSeries* QXYModelMapper::series() const
48 {
48 {
49 Q_D(const QXYModelMapper);
49 Q_D(const QXYModelMapper);
50 return d->m_series;
50 return d->m_series;
51 }
51 }
52
52
53 void QXYModelMapper::setSeries(QXYSeries *series)
53 void QXYModelMapper::setSeries(QXYSeries *series)
54 {
54 {
55 Q_D(QXYModelMapper);
55 Q_D(QXYModelMapper);
56 if (d->m_series) {
56 if (d->m_series) {
57 disconnect(d->m_series, 0, d, 0);
57 disconnect(d->m_series, 0, d, 0);
58 }
58 }
59
59
60 if (series == 0)
60 if (series == 0)
61 return;
61 return;
62
62
63 d->m_series = series;
63 d->m_series = series;
64 d->initializeXYFromModel();
64 d->initializeXYFromModel();
65 // connect the signals from the series
65 // connect the signals from the series
66 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
66 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
67 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
67 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
68 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
68 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
69 }
69 }
70
70
71 int QXYModelMapper::first() const
71 int QXYModelMapper::first() const
72 {
72 {
73 Q_D(const QXYModelMapper);
73 Q_D(const QXYModelMapper);
74 return d->m_first;
74 return d->m_first;
75 }
75 }
76
76
77 void QXYModelMapper::setFirst(int first)
77 void QXYModelMapper::setFirst(int first)
78 {
78 {
79 Q_D(QXYModelMapper);
79 Q_D(QXYModelMapper);
80 d->m_first = qMax(first, 0);
80 d->m_first = qMax(first, 0);
81 d->initializeXYFromModel();
81 d->initializeXYFromModel();
82 }
82 }
83
83
84 int QXYModelMapper::count() const
84 int QXYModelMapper::count() const
85 {
85 {
86 Q_D(const QXYModelMapper);
86 Q_D(const QXYModelMapper);
87 return d->m_count;
87 return d->m_count;
88 }
88 }
89
89
90 void QXYModelMapper::setCount(int count)
90 void QXYModelMapper::setCount(int count)
91 {
91 {
92 Q_D(QXYModelMapper);
92 Q_D(QXYModelMapper);
93 d->m_count = qMax(count, -1);
93 d->m_count = qMax(count, -1);
94 d->initializeXYFromModel();
94 d->initializeXYFromModel();
95 }
95 }
96
96
97 Qt::Orientation QXYModelMapper::orientation() const
97 Qt::Orientation QXYModelMapper::orientation() const
98 {
98 {
99 Q_D(const QXYModelMapper);
99 Q_D(const QXYModelMapper);
100 return d->m_orientation;
100 return d->m_orientation;
101 }
101 }
102
102
103 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
103 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
104 {
104 {
105 Q_D(QXYModelMapper);
105 Q_D(QXYModelMapper);
106 d->m_orientation = orientation;
106 d->m_orientation = orientation;
107 d->initializeXYFromModel();
107 d->initializeXYFromModel();
108 }
108 }
109
109
110 int QXYModelMapper::xSection() const
110 int QXYModelMapper::xSection() const
111 {
111 {
112 Q_D(const QXYModelMapper);
112 Q_D(const QXYModelMapper);
113 return d->m_xSection;
113 return d->m_xSection;
114 }
114 }
115
115
116 void QXYModelMapper::setXSection(int xSection)
116 void QXYModelMapper::setXSection(int xSection)
117 {
117 {
118 Q_D(QXYModelMapper);
118 Q_D(QXYModelMapper);
119 d->m_xSection = xSection;
119 d->m_xSection = xSection;
120 d->initializeXYFromModel();
120 d->initializeXYFromModel();
121 }
121 }
122
122
123 int QXYModelMapper::ySection() const
123 int QXYModelMapper::ySection() const
124 {
124 {
125 Q_D(const QXYModelMapper);
125 Q_D(const QXYModelMapper);
126 return d->m_ySection;
126 return d->m_ySection;
127 }
127 }
128
128
129 void QXYModelMapper::setYSection(int ySection)
129 void QXYModelMapper::setYSection(int ySection)
130 {
130 {
131 Q_D(QXYModelMapper);
131 Q_D(QXYModelMapper);
132 d->m_ySection = ySection;
132 d->m_ySection = ySection;
133 d->initializeXYFromModel();
133 d->initializeXYFromModel();
134 }
134 }
135
135
136 void QXYModelMapper::reset()
136 void QXYModelMapper::reset()
137 {
137 {
138 Q_D(QXYModelMapper);
138 Q_D(QXYModelMapper);
139 d->m_first = 0;
139 d->m_first = 0;
140 d->m_count = -1;
140 d->m_count = -1;
141 d->m_orientation = Qt::Vertical;
141 d->m_orientation = Qt::Vertical;
142 d->m_xSection = -1;
142 d->m_xSection = -1;
143 d->m_ySection = -1;
143 d->m_ySection = -1;
144 d->initializeXYFromModel();
144 d->initializeXYFromModel();
145 }
145 }
146
146
147 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148
148
149 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
149 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
150 m_series(0),
150 m_series(0),
151 m_model(0),
151 m_model(0),
152 m_first(0),
152 m_first(0),
153 m_count(-1),
153 m_count(-1),
154 m_orientation(Qt::Vertical),
154 m_orientation(Qt::Vertical),
155 m_xSection(-1),
155 m_xSection(-1),
156 m_ySection(-1),
156 m_ySection(-1),
157 m_seriesSignalsBlock(false),
157 m_seriesSignalsBlock(false),
158 m_modelSignalsBlock(false),
158 m_modelSignalsBlock(false),
159 q_ptr(q)
159 q_ptr(q)
160 {
160 {
161 }
161 }
162
162
163 void QXYModelMapperPrivate::blockModelSignals(bool block)
163 void QXYModelMapperPrivate::blockModelSignals(bool block)
164 {
164 {
165 m_modelSignalsBlock = block;
165 m_modelSignalsBlock = block;
166 }
166 }
167
167
168 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
168 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
169 {
169 {
170 m_seriesSignalsBlock = block;
170 m_seriesSignalsBlock = block;
171 }
171 }
172
172
173 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
173 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
174 {
174 {
175 if (m_count != -1 && xPos >= m_count)
175 if (m_count != -1 && xPos >= m_count)
176 return QModelIndex(); // invalid
176 return QModelIndex(); // invalid
177
177
178 if (m_orientation == Qt::Vertical)
178 if (m_orientation == Qt::Vertical)
179 return m_model->index(xPos + m_first, m_xSection);
179 return m_model->index(xPos + m_first, m_xSection);
180 else
180 else
181 return m_model->index(m_xSection, xPos + m_first);
181 return m_model->index(m_xSection, xPos + m_first);
182 }
182 }
183
183
184 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
184 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
185 {
185 {
186 if (m_count != -1 && yPos >= m_count)
186 if (m_count != -1 && yPos >= m_count)
187 return QModelIndex(); // invalid
187 return QModelIndex(); // invalid
188
188
189 if (m_orientation == Qt::Vertical)
189 if (m_orientation == Qt::Vertical)
190 return m_model->index(yPos + m_first, m_ySection);
190 return m_model->index(yPos + m_first, m_ySection);
191 else
191 else
192 return m_model->index(m_ySection, yPos + m_first);
192 return m_model->index(m_ySection, yPos + m_first);
193 }
193 }
194
194
195 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
195 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
196 {
196 {
197 if (m_seriesSignalsBlock)
197 if (m_seriesSignalsBlock)
198 return;
198 return;
199
199
200 if (m_count != -1)
200 if (m_count != -1)
201 m_count += 1;
201 m_count += 1;
202
202
203 blockModelSignals();
203 blockModelSignals();
204 if (m_orientation == Qt::Vertical)
204 if (m_orientation == Qt::Vertical)
205 m_model->insertRows(pointPos + m_first, 1);
205 m_model->insertRows(pointPos + m_first, 1);
206 else
206 else
207 m_model->insertColumns(pointPos + m_first, 1);
207 m_model->insertColumns(pointPos + m_first, 1);
208
208
209 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
209 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
210 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
210 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
211 blockModelSignals(false);
211 blockModelSignals(false);
212 }
212 }
213
213
214 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
214 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
215 {
215 {
216 if (m_seriesSignalsBlock)
216 if (m_seriesSignalsBlock)
217 return;
217 return;
218
218
219 if (m_count != -1)
219 if (m_count != -1)
220 m_count -= 1;
220 m_count -= 1;
221
221
222 blockModelSignals();
222 blockModelSignals();
223 if (m_orientation == Qt::Vertical)
223 if (m_orientation == Qt::Vertical)
224 m_model->removeRow(pointPos + m_first);
224 m_model->removeRow(pointPos + m_first);
225 else
225 else
226 m_model->removeColumn(pointPos + m_first);
226 m_model->removeColumn(pointPos + m_first);
227 blockModelSignals(false);
227 blockModelSignals(false);
228 }
228 }
229
229
230 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
230 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
231 {
231 {
232 if (m_seriesSignalsBlock)
232 if (m_seriesSignalsBlock)
233 return;
233 return;
234
234
235 blockModelSignals();
235 blockModelSignals();
236 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
236 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
237 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
237 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
238 blockModelSignals(false);
238 blockModelSignals(false);
239 }
239 }
240
240
241 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
241 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
242 {
242 {
243 if (m_model == 0 || m_series == 0)
243 if (m_model == 0 || m_series == 0)
244 return;
244 return;
245
245
246 if (m_modelSignalsBlock)
246 if (m_modelSignalsBlock)
247 return;
247 return;
248
248
249 blockSeriesSignals();
249 blockSeriesSignals();
250 QModelIndex index;
250 QModelIndex index;
251 QPointF oldPoint;
251 QPointF oldPoint;
252 QPointF newPoint;
252 QPointF newPoint;
253 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
253 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
254 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
254 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
255 index = topLeft.sibling(row, column);
255 index = topLeft.sibling(row, column);
256 if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) {
256 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
257 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
257 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
258 oldPoint = m_series->points().at(index.row() - m_first);
258 QModelIndex xIndex = xModelIndex(index.row() - m_first);
259 newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal());
259 QModelIndex yIndex = yModelIndex(index.row() - m_first);
260 newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal());
260 if (xIndex.isValid() && yIndex.isValid()) {
261 oldPoint = m_series->points().at(index.row() - m_first);
262 newPoint.setX(m_model->data(xIndex).toReal());
263 newPoint.setY(m_model->data(yIndex).toReal());
264 }
261 }
265 }
262 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
266 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
263 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
267 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
264 oldPoint = m_series->points().at(index.column() - m_first);
268 QModelIndex xIndex = xModelIndex(index.column() - m_first);
265 newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal());
269 QModelIndex yIndex = yModelIndex(index.column() - m_first);
266 newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal());
270 if (xIndex.isValid() && yIndex.isValid()) {
271 oldPoint = m_series->points().at(index.column() - m_first);
272 newPoint.setX(m_model->data(xIndex).toReal());
273 newPoint.setY(m_model->data(yIndex).toReal());
274 }
267 }
275 }
268 } else {
276 } else {
269 continue;
277 continue;
270 }
278 }
271 m_series->replace(oldPoint, newPoint);
279 m_series->replace(oldPoint, newPoint);
272 }
280 }
273 }
281 }
274 blockSeriesSignals(false);
282 blockSeriesSignals(false);
275 }
283 }
276
284
277 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
285 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
278 {
286 {
279 Q_UNUSED(parent);
287 Q_UNUSED(parent);
280 if (m_modelSignalsBlock)
288 if (m_modelSignalsBlock)
281 return;
289 return;
282
290
283 blockSeriesSignals();
291 blockSeriesSignals();
284 if (m_orientation == Qt::Vertical)
292 if (m_orientation == Qt::Vertical)
285 insertData(start, end);
293 insertData(start, end);
286 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
294 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
287 initializeXYFromModel();
295 initializeXYFromModel();
288 blockSeriesSignals(false);
296 blockSeriesSignals(false);
289 }
297 }
290
298
291 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
299 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
292 {
300 {
293 Q_UNUSED(parent);
301 Q_UNUSED(parent);
294 if (m_modelSignalsBlock)
302 if (m_modelSignalsBlock)
295 return;
303 return;
296
304
297 blockSeriesSignals();
305 blockSeriesSignals();
298 if (m_orientation == Qt::Vertical)
306 if (m_orientation == Qt::Vertical)
299 removeData(start, end);
307 removeData(start, end);
300 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
308 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
301 initializeXYFromModel();
309 initializeXYFromModel();
302 blockSeriesSignals(false);
310 blockSeriesSignals(false);
303 }
311 }
304
312
305 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
313 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
306 {
314 {
307 Q_UNUSED(parent);
315 Q_UNUSED(parent);
308 if (m_modelSignalsBlock)
316 if (m_modelSignalsBlock)
309 return;
317 return;
310
318
311 blockSeriesSignals();
319 blockSeriesSignals();
312 if (m_orientation == Qt::Horizontal)
320 if (m_orientation == Qt::Horizontal)
313 insertData(start, end);
321 insertData(start, end);
314 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
322 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
315 initializeXYFromModel();
323 initializeXYFromModel();
316 blockSeriesSignals(false);
324 blockSeriesSignals(false);
317 }
325 }
318
326
319 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
327 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
320 {
328 {
321 Q_UNUSED(parent);
329 Q_UNUSED(parent);
322 if (m_modelSignalsBlock)
330 if (m_modelSignalsBlock)
323 return;
331 return;
324
332
325 blockSeriesSignals();
333 blockSeriesSignals();
326 if (m_orientation == Qt::Horizontal)
334 if (m_orientation == Qt::Horizontal)
327 removeData(start, end);
335 removeData(start, end);
328 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
336 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
329 initializeXYFromModel();
337 initializeXYFromModel();
330 blockSeriesSignals(false);
338 blockSeriesSignals(false);
331 }
339 }
332
340
333 void QXYModelMapperPrivate::insertData(int start, int end)
341 void QXYModelMapperPrivate::insertData(int start, int end)
334 {
342 {
335 if (m_model == 0 || m_series == 0)
343 if (m_model == 0 || m_series == 0)
336 return;
344 return;
337
345
338 if (m_count != -1 && start >= m_first + m_count) {
346 if (m_count != -1 && start >= m_first + m_count) {
339 return;
347 return;
340 } else {
348 } else {
341 int addedCount = end - start + 1;
349 int addedCount = end - start + 1;
342 if (m_count != -1 && addedCount > m_count)
350 if (m_count != -1 && addedCount > m_count)
343 addedCount = m_count;
351 addedCount = m_count;
344 int first = qMax(start, m_first);
352 int first = qMax(start, m_first);
345 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
353 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
346 for (int i = first; i <= last; i++) {
354 for (int i = first; i <= last; i++) {
347 QPointF point;
355 QPointF point;
348 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
356 QModelIndex xIndex = xModelIndex(i - m_first);
349 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
357 QModelIndex yIndex = yModelIndex(i - m_first);
350 m_series->insert(i - m_first, point);
358 if (xIndex.isValid() && yIndex.isValid()) {
359 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
360 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
361 m_series->insert(i - m_first, point);
362 }
351 }
363 }
352
364
353 // remove excess of slices (abouve m_count)
365 // remove excess of slices (abouve m_count)
354 if (m_count != -1 && m_series->points().size() > m_count)
366 if (m_count != -1 && m_series->points().size() > m_count)
355 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
367 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
356 m_series->remove(m_series->points().at(i));
368 m_series->remove(m_series->points().at(i));
357 }
369 }
358 }
370 }
359 }
371 }
360
372
361 void QXYModelMapperPrivate::removeData(int start, int end)
373 void QXYModelMapperPrivate::removeData(int start, int end)
362 {
374 {
363 if (m_model == 0 || m_series == 0)
375 if (m_model == 0 || m_series == 0)
364 return;
376 return;
365
377
366 int removedCount = end - start + 1;
378 int removedCount = end - start + 1;
367 if (m_count != -1 && start >= m_first + m_count) {
379 if (m_count != -1 && start >= m_first + m_count) {
368 return;
380 return;
369 } else {
381 } else {
370 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
382 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
371 int first = qMax(start, m_first); // get the index of the first item that will be removed.
383 int first = qMax(start, m_first); // get the index of the first item that will be removed.
372 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
384 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
373 for (int i = last; i >= first; i--) {
385 for (int i = last; i >= first; i--) {
374 m_series->remove(m_series->points().at(i - m_first));
386 m_series->remove(m_series->points().at(i - m_first));
375 }
387 }
376
388
377 if (m_count != -1) {
389 if (m_count != -1) {
378 int itemsAvailable; // check how many are available to be added
390 int itemsAvailable; // check how many are available to be added
379 if (m_orientation == Qt::Vertical)
391 if (m_orientation == Qt::Vertical)
380 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
392 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
381 else
393 else
382 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
394 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
383 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
395 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
384 int currentSize = m_series->count();
396 int currentSize = m_series->count();
385 if (toBeAdded > 0)
397 if (toBeAdded > 0)
386 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
398 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
387 QPointF point;
399 QPointF point;
388 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
400 QModelIndex xIndex = xModelIndex(i);
389 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
401 QModelIndex yIndex = yModelIndex(i);
390 m_series->insert(i, point);
402 if (xIndex.isValid() && yIndex.isValid()) {
403 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
404 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
405 m_series->insert(i, point);
406 }
391 }
407 }
392 }
408 }
393 }
409 }
394 }
410 }
395
411
396 void QXYModelMapperPrivate::initializeXYFromModel()
412 void QXYModelMapperPrivate::initializeXYFromModel()
397 {
413 {
398 if (m_model == 0 || m_series == 0)
414 if (m_model == 0 || m_series == 0)
399 return;
415 return;
400
416
401 blockSeriesSignals();
417 blockSeriesSignals();
402 // clear current content
418 // clear current content
403 m_series->clear();
419 m_series->clear();
404
420
405 // create the initial slices set
421 // create the initial slices set
406 int pointPos = 0;
422 int pointPos = 0;
407 QModelIndex xIndex = xModelIndex(pointPos);
423 QModelIndex xIndex = xModelIndex(pointPos);
408 QModelIndex yIndex = yModelIndex(pointPos);
424 QModelIndex yIndex = yModelIndex(pointPos);
409 while (xIndex.isValid() && yIndex.isValid()) {
425 while (xIndex.isValid() && yIndex.isValid()) {
410 QPointF point;
426 QPointF point;
411 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
427 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
412 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
428 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
413 m_series->append(point);
429 m_series->append(point);
414 pointPos++;
430 pointPos++;
415 xIndex = xModelIndex(pointPos);
431 xIndex = xModelIndex(pointPos);
416 yIndex = yModelIndex(pointPos);
432 yIndex = yModelIndex(pointPos);
417 }
433 }
418 blockSeriesSignals(false);
434 blockSeriesSignals(false);
419 }
435 }
420
436
421 #include "moc_qxymodelmapper.cpp"
437 #include "moc_qxymodelmapper.cpp"
422 #include "moc_qxymodelmapper_p.cpp"
438 #include "moc_qxymodelmapper_p.cpp"
423
439
424 QTCOMMERCIALCHART_END_NAMESPACE
440 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,276 +1,276
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 "customtablemodel.h"
21 #include "customtablemodel.h"
22 #include <QVector>
22 #include <QVector>
23 #include <QTime>
23 #include <QTime>
24 #include <QRect>
24 #include <QRect>
25 #include <QColor>
25 #include <QColor>
26
26
27 CustomTableModel::CustomTableModel(QObject *parent) :
27 CustomTableModel::CustomTableModel(QObject *parent) :
28 QAbstractTableModel(parent)
28 QAbstractTableModel(parent)
29 {
29 {
30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
31
31
32 m_columnCount = 7;
32 m_columnCount = 7;
33 m_rowCount = 9;
33 m_rowCount = 1029;
34
34
35 m_labels.append("Apples");
35 m_labels.append("Apples");
36 m_labels.append("Oranges");
36 m_labels.append("Oranges");
37 m_labels.append("Pears");
37 m_labels.append("Pears");
38 m_labels.append("Peaches");
38 m_labels.append("Peaches");
39 m_labels.append("Coconuts");
39 m_labels.append("Coconuts");
40 m_labels.append("Bananas");
40 m_labels.append("Bananas");
41 m_labels.append("Kiwis");
41 m_labels.append("Kiwis");
42 m_labels.append("Grapes");
42 m_labels.append("Grapes");
43 m_labels.append("Plums");
43 m_labels.append("Plums");
44
44
45 // m_data
45 // m_data
46 for (int i = 0; i < m_rowCount; i++)
46 for (int i = 0; i < m_rowCount; i++)
47 {
47 {
48 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
48 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
49 for (int k = 0; k < dataVec->size(); k++)
49 for (int k = 0; k < dataVec->size(); k++)
50 {
50 {
51 if (k%2 == 0)
51 if (k%2 == 0)
52 dataVec->replace(k, i * 50 + qrand()%20);
52 dataVec->replace(k, i * 50 + qrand()%20);
53 else
53 else
54 dataVec->replace(k, qrand()%100);
54 dataVec->replace(k, qrand()%100);
55 }
55 }
56 m_data.append(dataVec);
56 m_data.append(dataVec);
57 // m_labels.append(QString("Row: %1").arg((i + 1)));
57 // m_labels.append(QString("Row: %1").arg((i + 1)));
58 }
58 }
59 }
59 }
60
60
61 int CustomTableModel::rowCount(const QModelIndex & parent) const
61 int CustomTableModel::rowCount(const QModelIndex & parent) const
62 {
62 {
63 Q_UNUSED(parent)
63 Q_UNUSED(parent)
64 return m_data.count();
64 return m_data.count();
65 }
65 }
66
66
67 int CustomTableModel::columnCount(const QModelIndex & parent) const
67 int CustomTableModel::columnCount(const QModelIndex & parent) const
68 {
68 {
69 Q_UNUSED(parent)
69 Q_UNUSED(parent)
70 return m_columnCount + 1;
70 return m_columnCount;// + 1;
71 }
71 }
72
72
73 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
73 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
74 {
74 {
75 if (role != Qt::DisplayRole)
75 if (role != Qt::DisplayRole)
76 return QVariant();
76 return QVariant();
77
77
78 if (orientation == Qt::Horizontal)
78 if (orientation == Qt::Horizontal)
79 {
79 {
80 switch(section)
80 switch(section)
81 {
81 {
82 case 7:
82 case 7:
83 return "Fruit";
83 return "Fruit";
84 case 1:
84 case 1:
85 return "Count";
85 return "Count";
86 case 2:
86 case 2:
87 return "Ordered";
87 return "Ordered";
88 default:
88 default:
89 if (section%2 == 0)
89 if (section%2 == 0)
90 return "x";
90 return "x";
91 else
91 else
92 return "y";
92 return "y";
93 }
93 }
94 }
94 }
95 else
95 else
96 return QString("%1").arg(section /*+ 1*/);
96 return QString("%1").arg(section /*+ 1*/);
97 }
97 }
98
98
99 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
99 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
100 {
100 {
101 if (role == Qt::DisplayRole)
101 if (role == Qt::DisplayRole)
102 {
102 {
103 switch(index.column())
103 switch(index.column())
104 {
104 {
105 case 7:
105 // case 7:
106 return m_labels[index.row()];
106 // return m_labels[index.row()];
107 default:
107 default:
108 return m_data[index.row()]->at(index.column());
108 return m_data[index.row()]->at(index.column());
109 break;
109 break;
110 }
110 }
111 }
111 }
112 else if (role == Qt::EditRole)
112 else if (role == Qt::EditRole)
113 {
113 {
114 switch(index.column())
114 switch(index.column())
115 {
115 {
116 case 7:
116 // case 7:
117 return m_labels[index.row()];
117 // return m_labels[index.row()];
118 default:
118 default:
119 return m_data[index.row()]->at(index.column());
119 return m_data[index.row()]->at(index.column());
120 break;
120 break;
121 }
121 }
122 }
122 }
123 else if (role == Qt::BackgroundRole)
123 else if (role == Qt::BackgroundRole)
124 {
124 {
125 QRect rect;
125 QRect rect;
126 foreach(rect, m_mapping)
126 foreach(rect, m_mapping)
127 if(rect.contains(index.column(), index.row()))
127 if(rect.contains(index.column(), index.row()))
128 return QColor(m_mapping.key(rect));
128 return QColor(m_mapping.key(rect));
129
129
130 // cell not mapped return white color
130 // cell not mapped return white color
131 return QColor(Qt::white);
131 return QColor(Qt::white);
132 }
132 }
133 return QVariant();
133 return QVariant();
134 }
134 }
135
135
136 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
136 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
137 {
137 {
138 if (index.isValid() && role == Qt::EditRole)
138 if (index.isValid() && role == Qt::EditRole)
139 {
139 {
140 switch(index.column())
140 switch(index.column())
141 {
141 {
142 case 7:
142 case 7:
143 m_labels.replace(index.row(), value.toString());
143 m_labels.replace(index.row(), value.toString());
144 break;
144 break;
145 default:
145 default:
146 m_data[index.row()]->replace(index.column(), value.toDouble());
146 m_data[index.row()]->replace(index.column(), value.toDouble());
147 break;
147 break;
148 }
148 }
149 emit dataChanged(index, index);
149 emit dataChanged(index, index);
150 return true;
150 return true;
151 }
151 }
152 return false;
152 return false;
153 }
153 }
154
154
155 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
155 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
156 {
156 {
157 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
157 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
158 }
158 }
159
159
160 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
160 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
161 {
161 {
162 Q_UNUSED(parent)
162 Q_UNUSED(parent)
163
163
164 if (row < 0)
164 if (row < 0)
165 row = 0;
165 row = 0;
166 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
166 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
167 for (int i = row; i < row + count; i++)
167 for (int i = row; i < row + count; i++)
168 {
168 {
169 // m_points.insert(row, QPointF(10,20));
169 // m_points.insert(row, QPointF(10,20));
170 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
170 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
171 QVector<QColor>* colorVec = new QVector<QColor>(m_columnCount);
171 QVector<QColor>* colorVec = new QVector<QColor>(m_columnCount);
172 for (int k = 0; k < dataVec->size(); k++)
172 for (int k = 0; k < dataVec->size(); k++)
173 {
173 {
174 if (k%2 == 0)
174 if (k%2 == 0)
175 // dataVec->replace(k, i * 50 + qrand()%20);
175 // dataVec->replace(k, i * 50 + qrand()%20);
176 {
176 {
177 int difference = 0;
177 int difference = 0;
178 if (i < m_data.size())
178 if (i < m_data.size())
179 {
179 {
180 if (i - 1 >= 0)
180 if (i - 1 >= 0)
181 {
181 {
182 if (row > 0)
182 if (row > 0)
183 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
183 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
184 else
184 else
185 difference = (int)((qAbs(m_data[i]->at(k)/count)));
185 difference = (int)((qAbs(m_data[i]->at(k)/count)));
186 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
186 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
187 }
187 }
188 else
188 else
189 dataVec->replace(k, qrand()%40 + 10);
189 dataVec->replace(k, qrand()%40 + 10);
190 }
190 }
191 else
191 else
192 {
192 {
193 if (i - 1 >= 0)
193 if (i - 1 >= 0)
194 {
194 {
195 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
195 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
196 }
196 }
197 else
197 else
198 {
198 {
199 dataVec->replace(k, qrand()%40 + 10);
199 dataVec->replace(k, qrand()%40 + 10);
200 }
200 }
201 }
201 }
202 }
202 }
203 else
203 else
204 dataVec->replace(k, qrand()%100);
204 dataVec->replace(k, qrand()%100);
205 colorVec->replace(k, QColor(Qt::white));
205 colorVec->replace(k, QColor(Qt::white));
206 }
206 }
207 m_data.insert(i, dataVec);
207 m_data.insert(i, dataVec);
208 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
208 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
209 }
209 }
210 endInsertRows();
210 endInsertRows();
211 return true;
211 return true;
212 }
212 }
213
213
214 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
214 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
215 {
215 {
216 if (row > this->rowCount() - 1)
216 if (row > this->rowCount() - 1)
217 return false;
217 return false;
218 if (row < 0)
218 if (row < 0)
219 row = 0;
219 row = 0;
220 if (row + count > rowCount())
220 if (row + count > rowCount())
221 return false;
221 return false;
222 beginRemoveRows(parent, row, row + count - 1);
222 beginRemoveRows(parent, row, row + count - 1);
223 for (int i = row; i < row + count; i++)
223 for (int i = row; i < row + count; i++)
224 {
224 {
225 QVector<qreal>* item = m_data.at(row);
225 QVector<qreal>* item = m_data.at(row);
226 m_data.removeAt(row);
226 m_data.removeAt(row);
227 delete item;
227 delete item;
228 m_labels.removeAt(row);
228 m_labels.removeAt(row);
229 }
229 }
230 endRemoveRows();
230 endRemoveRows();
231 return true;
231 return true;
232 }
232 }
233
233
234 bool CustomTableModel::insertColumns ( int column, int count, const QModelIndex & parent)
234 bool CustomTableModel::insertColumns ( int column, int count, const QModelIndex & parent)
235 {
235 {
236 if (column < 0)
236 if (column < 0)
237 column = 0;
237 column = 0;
238 beginInsertColumns(parent, column, column + count - 1);
238 beginInsertColumns(parent, column, column + count - 1);
239 m_columnCount += count;
239 m_columnCount += count;
240 for (int i = column; i < column + count; i++)
240 for (int i = column; i < column + count; i++)
241 for (int k = 0; k < rowCount(); k++)
241 for (int k = 0; k < rowCount(); k++)
242 if (k - 1 >= 0) {
242 if (k - 1 >= 0) {
243 m_data[k]->insert(i, m_data[k - 1]->at(i) + qrand()%40 + 10);
243 m_data[k]->insert(i, m_data[k - 1]->at(i) + qrand()%40 + 10);
244 } else {
244 } else {
245 m_data[k]->insert(i, qrand()%40);
245 m_data[k]->insert(i, qrand()%40);
246 }
246 }
247 endInsertColumns();
247 endInsertColumns();
248 return true;
248 return true;
249 }
249 }
250
250
251 bool CustomTableModel::removeColumns ( int column, int count, const QModelIndex & parent)
251 bool CustomTableModel::removeColumns ( int column, int count, const QModelIndex & parent)
252 {
252 {
253 if (column > columnCount() - 1)
253 if (column > columnCount() - 1)
254 return false;
254 return false;
255 if (column < 0)
255 if (column < 0)
256 column = 0;
256 column = 0;
257 if (column + count > columnCount())
257 if (column + count > columnCount())
258 return false;
258 return false;
259 beginRemoveColumns(parent, column, column + count -1);
259 beginRemoveColumns(parent, column, column + count -1);
260 m_columnCount -= count;
260 m_columnCount -= count;
261 for (int i = column; i < column + count; i++)
261 for (int i = column; i < column + count; i++)
262 for (int k = 0; k < rowCount(); k++)
262 for (int k = 0; k < rowCount(); k++)
263 m_data[k]->remove(column);
263 m_data[k]->remove(column);
264 endRemoveColumns();
264 endRemoveColumns();
265 return true;
265 return true;
266 }
266 }
267
267
268 void CustomTableModel::addMapping(QString color, QRect area)
268 void CustomTableModel::addMapping(QString color, QRect area)
269 {
269 {
270 m_mapping.insertMulti(color, area);
270 m_mapping.insertMulti(color, area);
271 }
271 }
272
272
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
274 {
274 {
275 addMapping(color, QRect(QPoint(left, top), QPoint(right, bottom)));
275 addMapping(color, QRect(QPoint(left, top), QPoint(right, bottom)));
276 }
276 }
@@ -1,582 +1,582
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 "tablewidget.h"
21 #include "tablewidget.h"
22 #include <QGridLayout>
22 #include <QGridLayout>
23 #include <QTableView>
23 #include <QTableView>
24 #include <QChart>
24 #include <QChart>
25 #include <QStyledItemDelegate>
25 #include <QStyledItemDelegate>
26 #include <QLineSeries>
26 #include <QLineSeries>
27 #include <QSplineSeries>
27 #include <QSplineSeries>
28 #include <QScatterSeries>
28 #include <QScatterSeries>
29 #include <QVXYModelMapper>
29 #include <QVXYModelMapper>
30 #include <QHXYModelMapper>
30 #include <QHXYModelMapper>
31 #include "customtablemodel.h"
31 #include "customtablemodel.h"
32 #include <QPieSeries>
32 #include <QPieSeries>
33 #include <QVPieModelMapper>
33 #include <QVPieModelMapper>
34 #include <QPieSlice>
34 #include <QPieSlice>
35 #include <QAreaSeries>
35 #include <QAreaSeries>
36 #include <QBarSeries>
36 #include <QBarSeries>
37 #include <QGroupedBarSeries>
37 #include <QGroupedBarSeries>
38 #include <QBarSet>
38 #include <QBarSet>
39 #include <QVBarModelMapper>
39 #include <QVBarModelMapper>
40 #include <QPushButton>
40 #include <QPushButton>
41 #include <QRadioButton>
41 #include <QRadioButton>
42 #include <QLabel>
42 #include <QLabel>
43 #include <QSpinBox>
43 #include <QSpinBox>
44 #include <QTime>
44 #include <QTime>
45 #include <QHeaderView>
45 #include <QHeaderView>
46
46
47 TableWidget::TableWidget(QWidget *parent)
47 TableWidget::TableWidget(QWidget *parent)
48 : QWidget(parent),
48 : QWidget(parent),
49 m_series(0),
49 m_series(0),
50 m_mapper(0),
50 m_mapper(0),
51 m_model(0),
51 m_model(0),
52 m_pieMapper(0),
52 m_pieMapper(0),
53 m_pieMapper2(0)
53 m_pieMapper2(0)
54 // specialPie(0)
54 // specialPie(0)
55 {
55 {
56 setGeometry(1900, 100, 1000, 600);
56 setGeometry(1900, 100, 1000, 600);
57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
57 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
58 // create simple model for storing data
58 // create simple model for storing data
59 // user's table data model
59 // user's table data model
60 m_model = new CustomTableModel;
60 m_model = new CustomTableModel;
61 m_tableView = new QTableView;
61 m_tableView = new QTableView;
62 m_tableView->setModel(m_model);
62 m_tableView->setModel(m_model);
63 // m_tableView->setMinimumHeight(300);
63 // m_tableView->setMinimumHeight(300);
64 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
64 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
65 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
65 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
66
66
67 m_chart = new QChart;
67 m_chart = new QChart;
68 m_chart->legend()->setVisible(true);
68 m_chart->legend()->setVisible(true);
69 m_chart->setAnimationOptions(QChart::SeriesAnimations);
69 m_chart->setAnimationOptions(QChart::SeriesAnimations);
70 m_chartView = new QChartView(m_chart);
70 m_chartView = new QChartView(m_chart);
71 m_chartView->setRenderHint(QPainter::Antialiasing);
71 m_chartView->setRenderHint(QPainter::Antialiasing);
72 m_chartView->setMinimumSize(640, 480);
72 m_chartView->setMinimumSize(640, 480);
73
73
74 // add, remove data buttons
74 // add, remove data buttons
75 QPushButton* addRowAboveButton = new QPushButton("Add row above");
75 QPushButton* addRowAboveButton = new QPushButton("Add row above");
76 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
76 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
77
77
78 QPushButton* addRowBelowButton = new QPushButton("Add row below");
78 QPushButton* addRowBelowButton = new QPushButton("Add row below");
79 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
79 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
80
80
81 QPushButton* removeRowButton = new QPushButton("Remove row");
81 QPushButton* removeRowButton = new QPushButton("Remove row");
82 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
82 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
83
83
84 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
84 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
85 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
85 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
86
86
87 QPushButton* removeColumnButton = new QPushButton("Remove column");
87 QPushButton* removeColumnButton = new QPushButton("Remove column");
88 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
88 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
89
89
90 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
90 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
91 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
91 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
92
92
93 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
93 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
94 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
94 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
95
95
96 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
96 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
97 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
97 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
98
98
99 QPushButton* xyTestButton = new QPushButton("Append XY point");
99 QPushButton* xyTestButton = new QPushButton("Append XY point");
100 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
100 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
101
101
102
102
103 QLabel *spinBoxLabel = new QLabel("Rows affected:");
103 QLabel *spinBoxLabel = new QLabel("Rows affected:");
104
104
105 // spin box for setting number of affected items (add, remove)
105 // spin box for setting number of affected items (add, remove)
106 m_linesCountSpinBox = new QSpinBox;
106 m_linesCountSpinBox = new QSpinBox;
107 m_linesCountSpinBox->setRange(1, 10);
107 m_linesCountSpinBox->setRange(1, 10);
108 m_linesCountSpinBox->setValue(1);
108 m_linesCountSpinBox->setValue(1);
109
109
110 // buttons layout
110 // buttons layout
111 QVBoxLayout* buttonsLayout = new QVBoxLayout;
111 QVBoxLayout* buttonsLayout = new QVBoxLayout;
112 buttonsLayout->addWidget(spinBoxLabel);
112 buttonsLayout->addWidget(spinBoxLabel);
113 buttonsLayout->addWidget(m_linesCountSpinBox);
113 buttonsLayout->addWidget(m_linesCountSpinBox);
114 // buttonsLayout->addWidget(addRowAboveButton);
114 // buttonsLayout->addWidget(addRowAboveButton);
115 buttonsLayout->addWidget(addRowBelowButton);
115 buttonsLayout->addWidget(addRowBelowButton);
116 buttonsLayout->addWidget(removeRowButton);
116 buttonsLayout->addWidget(removeRowButton);
117 // buttonsLayout->addWidget(addColumnRightButton);
117 // buttonsLayout->addWidget(addColumnRightButton);
118 // buttonsLayout->addWidget(removeColumnButton);
118 // buttonsLayout->addWidget(removeColumnButton);
119 buttonsLayout->addWidget(specialPieButton);
119 buttonsLayout->addWidget(specialPieButton);
120 buttonsLayout->addWidget(specialPieButton2);
120 buttonsLayout->addWidget(specialPieButton2);
121 buttonsLayout->addWidget(specialPieButton3);
121 buttonsLayout->addWidget(specialPieButton3);
122 buttonsLayout->addWidget(xyTestButton);
122 buttonsLayout->addWidget(xyTestButton);
123 buttonsLayout->addStretch();
123 buttonsLayout->addStretch();
124
124
125 // chart type radio buttons
125 // chart type radio buttons
126 m_lineRadioButton = new QRadioButton("Line");
126 m_lineRadioButton = new QRadioButton("Line");
127 m_splineRadioButton = new QRadioButton("Spline");
127 m_splineRadioButton = new QRadioButton("Spline");
128 m_scatterRadioButton = new QRadioButton("Scatter");
128 m_scatterRadioButton = new QRadioButton("Scatter");
129 m_pieRadioButton = new QRadioButton("Pie");
129 m_pieRadioButton = new QRadioButton("Pie");
130 m_areaRadioButton = new QRadioButton("Area");
130 m_areaRadioButton = new QRadioButton("Area");
131 m_barRadioButton = new QRadioButton("Bar");
131 m_barRadioButton = new QRadioButton("Bar");
132
132
133 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
139 m_lineRadioButton->setChecked(true);
139 m_lineRadioButton->setChecked(true);
140
140
141 // radio buttons layout
141 // radio buttons layout
142 QVBoxLayout* radioLayout = new QVBoxLayout;
142 QVBoxLayout* radioLayout = new QVBoxLayout;
143 radioLayout->addWidget(m_lineRadioButton);
143 radioLayout->addWidget(m_lineRadioButton);
144 radioLayout->addWidget(m_splineRadioButton);
144 radioLayout->addWidget(m_splineRadioButton);
145 radioLayout->addWidget(m_scatterRadioButton);
145 radioLayout->addWidget(m_scatterRadioButton);
146 radioLayout->addWidget(m_pieRadioButton);
146 radioLayout->addWidget(m_pieRadioButton);
147 // radioLayout->addWidget(m_areaRadioButton);
147 // radioLayout->addWidget(m_areaRadioButton);
148 radioLayout->addWidget(m_barRadioButton);
148 radioLayout->addWidget(m_barRadioButton);
149 radioLayout->addStretch();
149 radioLayout->addStretch();
150
150
151 // create main layout
151 // create main layout
152 QGridLayout* mainLayout = new QGridLayout;
152 QGridLayout* mainLayout = new QGridLayout;
153 mainLayout->addLayout(buttonsLayout, 2, 0);
153 mainLayout->addLayout(buttonsLayout, 2, 0);
154 mainLayout->addLayout(radioLayout, 3, 0);
154 mainLayout->addLayout(radioLayout, 3, 0);
155 mainLayout->addWidget(m_tableView, 1, 0);
155 mainLayout->addWidget(m_tableView, 1, 0);
156 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
156 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
157 setLayout(mainLayout);
157 setLayout(mainLayout);
158 m_lineRadioButton->setFocus();
158 m_lineRadioButton->setFocus();
159 }
159 }
160
160
161 void TableWidget::addRowAbove()
161 void TableWidget::addRowAbove()
162 {
162 {
163 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
163 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
164
164
165 }
165 }
166
166
167 void TableWidget::addRowBelow()
167 void TableWidget::addRowBelow()
168 {
168 {
169 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
169 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
170
170
171 }
171 }
172
172
173 void TableWidget::removeRow()
173 void TableWidget::removeRow()
174 {
174 {
175 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
175 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
176 }
176 }
177
177
178 void TableWidget::addColumnRight()
178 void TableWidget::addColumnRight()
179 {
179 {
180 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
180 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
181 }
181 }
182
182
183 void TableWidget::removeColumn()
183 void TableWidget::removeColumn()
184 {
184 {
185 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
185 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
186 }
186 }
187
187
188 void TableWidget::updateChartType(bool toggle)
188 void TableWidget::updateChartType(bool toggle)
189 {
189 {
190 // this if is needed, so that the function is only called once.
190 // this if is needed, so that the function is only called once.
191 // For the radioButton that was enabled.
191 // For the radioButton that was enabled.
192 if (toggle) {
192 if (toggle) {
193 // specialPie = 0;
193 // specialPie = 0;
194 m_chart->removeAllSeries();
194 m_chart->removeAllSeries();
195 m_series = 0;
195 m_series = 0;
196 // m_chart->axisX()->setNiceNumbersEnabled(false);
196 // m_chart->axisX()->setNiceNumbersEnabled(false);
197 // m_chart->axisY()->setNiceNumbersEnabled(false);
197 // m_chart->axisY()->setNiceNumbersEnabled(false);
198 if (m_mapper) {
198 if (m_mapper) {
199 m_mapper->deleteLater();
199 m_mapper->deleteLater();
200 m_mapper = 0;
200 m_mapper = 0;
201 }
201 }
202
202
203 if (m_pieMapper) {
203 if (m_pieMapper) {
204 m_pieMapper->deleteLater();
204 m_pieMapper->deleteLater();
205 m_pieMapper = 0;
205 m_pieMapper = 0;
206 }
206 }
207
207
208 if (m_pieMapper2) {
208 if (m_pieMapper2) {
209 m_pieMapper2->deleteLater();
209 m_pieMapper2->deleteLater();
210 m_pieMapper2 = 0;
210 m_pieMapper2 = 0;
211 }
211 }
212
212
213 // if (m_series) {
213 // if (m_series) {
214 // delete m_series;
214 // delete m_series;
215 // m_series = 0;
215 // m_series = 0;
216 // }
216 // }
217
217
218 // renable axes of the chart (pie hides them)
218 // renable axes of the chart (pie hides them)
219 // x axis
219 // x axis
220 QAxis *axis = m_chart->axisX();
220 QAxis *axis = m_chart->axisX();
221 axis->setAxisVisible(true);
221 axis->setAxisVisible(true);
222 axis->setGridLineVisible(true);
222 axis->setGridLineVisible(true);
223 axis->setLabelsVisible(true);
223 axis->setLabelsVisible(true);
224
224
225 // y axis
225 // y axis
226 axis = m_chart->axisY();
226 axis = m_chart->axisY();
227 axis->setAxisVisible(true);
227 axis->setAxisVisible(true);
228 axis->setGridLineVisible(true);
228 axis->setGridLineVisible(true);
229 axis->setLabelsVisible(true);
229 axis->setLabelsVisible(true);
230
230
231 m_model->clearMapping();
231 m_model->clearMapping();
232
232
233 QString seriesColorHex = "#000000";
233 QString seriesColorHex = "#000000";
234 // QPen pen;
234 // QPen pen;
235 // pen.setWidth(2);
235 // pen.setWidth(2);
236
236
237 if (m_lineRadioButton->isChecked())
237 if (m_lineRadioButton->isChecked())
238 {
238 {
239 m_chart->setAnimationOptions(QChart::NoAnimation);
239 // m_chart->setAnimationOptions(QChart::NoAnimation);
240
240
241 // series 1
241 // series 1
242 m_series = new QLineSeries;
242 m_series = new QLineSeries;
243
243
244 m_mapper = new QHXYModelMapper;
244 // m_mapper = new QHXYModelMapper;
245 m_mapper->setModel(m_model);
246 m_mapper->setSeries(m_series);
247 m_mapper->setXRow(0);
248 m_mapper->setYRow(1);
249 m_mapper->setFirst(3);
250 m_mapper->setCount(4);
251
252 // m_mapper = new QVXYModelMapper;
253 // m_mapper->setModel(m_model);
245 // m_mapper->setModel(m_model);
254 // m_mapper->setSeries(m_series);
246 // m_mapper->setSeries(m_series);
255 // m_mapper->setXColumn(0);
247 // m_mapper->setXRow(0);
256 // m_mapper->setYColumn(1);
248 // m_mapper->setYRow(1);
257 // m_mapper->setFirst(3);
249 // m_mapper->setFirst(3);
258 // m_mapper->setCount(4);
250 // m_mapper->setCount(4);
259
251
252 m_mapper = new QVXYModelMapper;
253 m_mapper->setModel(m_model);
254 m_mapper->setSeries(m_series);
255 m_mapper->setXColumn(0);
256 m_mapper->setYColumn(1);
257 m_mapper->setFirst(3);
258 // m_mapper->setCount(4);
259
260 // m_series->setModelMapping(0,1, Qt::Vertical);
260 // m_series->setModelMapping(0,1, Qt::Vertical);
261 // m_series->setModelMappingRange(3, 4);
261 // m_series->setModelMappingRange(3, 4);
262 m_chart->addSeries(m_series);
262 m_chart->addSeries(m_series);
263 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
263 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
264 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
264 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
265
265
266 // // series 2
266 // // series 2
267 // m_series = new QLineSeries;
267 // m_series = new QLineSeries;
268 // m_series->setModel(m_model);
268 // m_series->setModel(m_model);
269
269
270 // mapper = new QXYModelMapper;
270 // mapper = new QXYModelMapper;
271 // mapper->setMapX(3);
271 // mapper->setMapX(3);
272 // mapper->setMapY(4);
272 // mapper->setMapY(4);
273 // // mapper->setFirst(3);
273 // // mapper->setFirst(3);
274 // // mapper->setCount(4);
274 // // mapper->setCount(4);
275 // m_series->setModelMapper(mapper);
275 // m_series->setModelMapper(mapper);
276 // // m_series->setModelMapping(2,3, Qt::Vertical);
276 // // m_series->setModelMapping(2,3, Qt::Vertical);
277 // m_chart->addSeries(m_series);
277 // m_chart->addSeries(m_series);
278 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
278 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
279 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
279 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
280
280
281 // // series 3
281 // // series 3
282 // m_series = new QLineSeries;
282 // m_series = new QLineSeries;
283 // m_series->setModel(m_model);
283 // m_series->setModel(m_model);
284
284
285 // mapper = new QXYModelMapper;
285 // mapper = new QXYModelMapper;
286 // mapper->setMapX(5);
286 // mapper->setMapX(5);
287 // mapper->setMapY(6);
287 // mapper->setMapY(6);
288 // mapper->setFirst(2);
288 // mapper->setFirst(2);
289 // mapper->setCount(-1);
289 // mapper->setCount(-1);
290 // m_series->setModelMapper(mapper);
290 // m_series->setModelMapper(mapper);
291 // // m_series->setModelMapping(4,5, Qt::Vertical);
291 // // m_series->setModelMapping(4,5, Qt::Vertical);
292 // // m_series->setModelMappingRange(2, -1);
292 // // m_series->setModelMappingRange(2, -1);
293 // m_chart->addSeries(m_series);
293 // m_chart->addSeries(m_series);
294 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
294 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
295 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
295 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
296 }
296 }
297 else if (m_splineRadioButton->isChecked())
297 else if (m_splineRadioButton->isChecked())
298 {
298 {
299 m_chart->setAnimationOptions(QChart::NoAnimation);
299 m_chart->setAnimationOptions(QChart::NoAnimation);
300
300
301 // series 1
301 // series 1
302 m_series = new QSplineSeries;
302 m_series = new QSplineSeries;
303 // m_series->setModel(m_model);
303 // m_series->setModel(m_model);
304
304
305 // m_mapper = new QVXYModelMapper;
305 // m_mapper = new QVXYModelMapper;
306 // m_mapper->setSeries(m_series);
306 // m_mapper->setSeries(m_series);
307 // m_mapper->setModel(m_model);
307 // m_mapper->setModel(m_model);
308 // m_mapper->setXColumn(0);
308 // m_mapper->setXColumn(0);
309 // m_mapper->setYColumn(1);
309 // m_mapper->setYColumn(1);
310 // m_mapper->setFirst(0);
310 // m_mapper->setFirst(0);
311 // m_mapper->setCount(-1);
311 // m_mapper->setCount(-1);
312
312
313 // m_series->setModelMapper(mapper);
313 // m_series->setModelMapper(mapper);
314
314
315 m_chart->addSeries(m_series);
315 m_chart->addSeries(m_series);
316 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
316 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
317 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
317 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
318
318
319 // // series 2
319 // // series 2
320 // m_series = new QSplineSeries;
320 // m_series = new QSplineSeries;
321 // m_series->setModel(m_model);
321 // m_series->setModel(m_model);
322
322
323 // mapper = new QXYModelMapper;
323 // mapper = new QXYModelMapper;
324 // mapper->setMapX(2);
324 // mapper->setMapX(2);
325 // mapper->setMapY(3);
325 // mapper->setMapY(3);
326 // mapper->setFirst(2);
326 // mapper->setFirst(2);
327 // mapper->setCount(4);
327 // mapper->setCount(4);
328
328
329 // m_series->setModelMapper(mapper);
329 // m_series->setModelMapper(mapper);
330
330
331 // m_chart->addSeries(m_series);
331 // m_chart->addSeries(m_series);
332 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
332 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
333 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
333 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
334
334
335 // // series 3
335 // // series 3
336 // m_series = new QSplineSeries;
336 // m_series = new QSplineSeries;
337 // m_series->setModel(m_model);
337 // m_series->setModel(m_model);
338
338
339 // mapper = new QXYModelMapper;
339 // mapper = new QXYModelMapper;
340 // mapper->setMapX(4);
340 // mapper->setMapX(4);
341 // mapper->setMapY(5);
341 // mapper->setMapY(5);
342 // mapper->setFirst(2);
342 // mapper->setFirst(2);
343 // mapper->setCount(-1);
343 // mapper->setCount(-1);
344
344
345 // m_series->setModelMapper(mapper);
345 // m_series->setModelMapper(mapper);
346
346
347 // m_chart->addSeries(m_series);
347 // m_chart->addSeries(m_series);
348 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
348 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
349 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
349 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
350 } else if (m_scatterRadioButton->isChecked())
350 } else if (m_scatterRadioButton->isChecked())
351 {
351 {
352 m_chart->setAnimationOptions(QChart::NoAnimation);
352 m_chart->setAnimationOptions(QChart::NoAnimation);
353
353
354 // series 1
354 // series 1
355 m_series = new QScatterSeries;
355 m_series = new QScatterSeries;
356
356
357 // m_mapper = new QVXYModelMapper;
357 // m_mapper = new QVXYModelMapper;
358 // m_mapper->setSeries(m_series);
358 // m_mapper->setSeries(m_series);
359 // m_mapper->setModel(m_model);
359 // m_mapper->setModel(m_model);
360 // m_mapper->setXColumn(0);
360 // m_mapper->setXColumn(0);
361 // m_mapper->setYColumn(1);
361 // m_mapper->setYColumn(1);
362 // m_mapper->setFirst(0);
362 // m_mapper->setFirst(0);
363 // m_mapper->setCount(-1);
363 // m_mapper->setCount(-1);
364
364
365 m_chart->addSeries(m_series);
365 m_chart->addSeries(m_series);
366 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
366 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
367 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
367 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
368
368
369 // // series 2
369 // // series 2
370 // m_series = new QScatterSeries;
370 // m_series = new QScatterSeries;
371 // m_series->setModel(m_model);
371 // m_series->setModel(m_model);
372 // m_series->setModelMapping(2,3, Qt::Vertical);
372 // m_series->setModelMapping(2,3, Qt::Vertical);
373 // // m_series->setModelMappingRange(1, 6);
373 // // m_series->setModelMappingRange(1, 6);
374 // // series->setModelMapping(2,3, Qt::Horizontal);
374 // // series->setModelMapping(2,3, Qt::Horizontal);
375 // m_chart->addSeries(m_series);
375 // m_chart->addSeries(m_series);
376
376
377 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
377 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
378 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
378 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
379
379
380 // // series 3
380 // // series 3
381 // m_series = new QScatterSeries;
381 // m_series = new QScatterSeries;
382 // m_series->setModel(m_model);
382 // m_series->setModel(m_model);
383 // m_series->setModelMapping(4,5, Qt::Vertical);
383 // m_series->setModelMapping(4,5, Qt::Vertical);
384 // // series->setModelMapping(4,5, Qt::Horizontal);
384 // // series->setModelMapping(4,5, Qt::Horizontal);
385 // m_chart->addSeries(m_series);
385 // m_chart->addSeries(m_series);
386 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
386 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
387 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
387 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
388 } else if (m_pieRadioButton->isChecked()) {
388 } else if (m_pieRadioButton->isChecked()) {
389 m_chart->setAnimationOptions(QChart::SeriesAnimations);
389 m_chart->setAnimationOptions(QChart::SeriesAnimations);
390
390
391 // pie 1
391 // pie 1
392 m_pieSeries = new QPieSeries;
392 m_pieSeries = new QPieSeries;
393
393
394 m_pieMapper = new QVPieModelMapper;
394 m_pieMapper = new QVPieModelMapper;
395 m_pieMapper->setValuesColumn(1);
395 m_pieMapper->setValuesColumn(1);
396 m_pieMapper->setLabelsColumn(7);
396 m_pieMapper->setLabelsColumn(7);
397 m_pieMapper->setSeries(m_pieSeries);
397 m_pieMapper->setSeries(m_pieSeries);
398 m_pieMapper->setModel(m_model);
398 m_pieMapper->setModel(m_model);
399 m_pieMapper->setFirst(2);
399 m_pieMapper->setFirst(2);
400 // m_pieMapper->setCount(5);
400 // m_pieMapper->setCount(5);
401 // pieSeries->setModelMapper(mapper);
401 // pieSeries->setModelMapper(mapper);
402
402
403 m_pieSeries->setLabelsVisible(true);
403 m_pieSeries->setLabelsVisible(true);
404 m_pieSeries->setPieSize(0.35);
404 m_pieSeries->setPieSize(0.35);
405 m_pieSeries->setHorizontalPosition(0.25);
405 m_pieSeries->setHorizontalPosition(0.25);
406 m_pieSeries->setVerticalPosition(0.35);
406 m_pieSeries->setVerticalPosition(0.35);
407
407
408 m_chart->addSeries(m_pieSeries);
408 m_chart->addSeries(m_pieSeries);
409 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
409 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
410 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
410 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
411
411
412
412
413 // pieSeries->slices().at(0)->setValue(400);
413 // pieSeries->slices().at(0)->setValue(400);
414 // pieSeries->slices().at(0)->setLabel(QString("36"));
414 // pieSeries->slices().at(0)->setLabel(QString("36"));
415
415
416 // pie 2
416 // pie 2
417 m_pieSeries2 = new QPieSeries;
417 m_pieSeries2 = new QPieSeries;
418
418
419 m_pieMapper2 = new QVPieModelMapper;
419 m_pieMapper2 = new QVPieModelMapper;
420 m_pieMapper2->setValuesColumn(0);
420 m_pieMapper2->setValuesColumn(0);
421 m_pieMapper2->setLabelsColumn(7);
421 m_pieMapper2->setLabelsColumn(7);
422 m_pieMapper2->setModel(m_model);
422 m_pieMapper2->setModel(m_model);
423 m_pieMapper2->setSeries(m_pieSeries2);
423 m_pieMapper2->setSeries(m_pieSeries2);
424 m_pieMapper2->setFirst(2);
424 m_pieMapper2->setFirst(2);
425
425
426 m_pieSeries2->setLabelsVisible(true);
426 m_pieSeries2->setLabelsVisible(true);
427 m_pieSeries2->setPieSize(0.35);
427 m_pieSeries2->setPieSize(0.35);
428 m_pieSeries2->setHorizontalPosition(0.75);
428 m_pieSeries2->setHorizontalPosition(0.75);
429 m_pieSeries2->setVerticalPosition(0.65);
429 m_pieSeries2->setVerticalPosition(0.65);
430 m_chart->addSeries(m_pieSeries2);
430 m_chart->addSeries(m_pieSeries2);
431 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
431 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
432 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
432 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
433
433
434 // // pie 3
434 // // pie 3
435 // pieSeries = new QPieSeries;
435 // pieSeries = new QPieSeries;
436 // pieSeries->setModel(m_model);
436 // pieSeries->setModel(m_model);
437 // pieSeries->setModelMapping(2,2, Qt::Vertical);
437 // pieSeries->setModelMapping(2,2, Qt::Vertical);
438 // pieSeries->setLabelsVisible(true);
438 // pieSeries->setLabelsVisible(true);
439 // pieSeries->setPieSize(0.35);
439 // pieSeries->setPieSize(0.35);
440 // pieSeries->setHorizontalPosition(0.5);
440 // pieSeries->setHorizontalPosition(0.5);
441 // pieSeries->setVerticalPosition(0.75);
441 // pieSeries->setVerticalPosition(0.75);
442 // m_chart->addSeries(pieSeries);
442 // m_chart->addSeries(pieSeries);
443 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
443 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
444 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
444 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
445
445
446 // // special pie
446 // // special pie
447 // specialPie = new QPieSeries;
447 // specialPie = new QPieSeries;
448 // specialPie->append(17, "1");
448 // specialPie->append(17, "1");
449 // specialPie->append(45, "2");
449 // specialPie->append(45, "2");
450 // specialPie->append(77, "3");
450 // specialPie->append(77, "3");
451 // specialPie->append(37, "4");
451 // specialPie->append(37, "4");
452 // specialPie->append(27, "5");
452 // specialPie->append(27, "5");
453 // specialPie->append(47, "6");
453 // specialPie->append(47, "6");
454 // specialPie->setPieSize(0.35);
454 // specialPie->setPieSize(0.35);
455 // specialPie->setHorizontalPosition(0.8);
455 // specialPie->setHorizontalPosition(0.8);
456 // specialPie->setVerticalPosition(0.75);
456 // specialPie->setVerticalPosition(0.75);
457 // specialPie->setLabelsVisible(true);
457 // specialPie->setLabelsVisible(true);
458 // m_chart->addSeries(specialPie);
458 // m_chart->addSeries(specialPie);
459 }
459 }
460 // else if (m_areaRadioButton->isChecked())
460 // else if (m_areaRadioButton->isChecked())
461 // {
461 // {
462 // m_chart->setAnimationOptions(QChart::NoAnimation);
462 // m_chart->setAnimationOptions(QChart::NoAnimation);
463
463
464 // QLineSeries* upperLineSeries = new QLineSeries;
464 // QLineSeries* upperLineSeries = new QLineSeries;
465 // upperLineSeries->setModel(m_model);
465 // upperLineSeries->setModel(m_model);
466 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
466 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
467 // // upperLineSeries->setModelMappingRange(1, 5);
467 // // upperLineSeries->setModelMappingRange(1, 5);
468 // QLineSeries* lowerLineSeries = new QLineSeries;
468 // QLineSeries* lowerLineSeries = new QLineSeries;
469 // lowerLineSeries->setModel(m_model);
469 // lowerLineSeries->setModel(m_model);
470 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
470 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
471 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
471 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
472 // m_chart->addSeries(areaSeries);
472 // m_chart->addSeries(areaSeries);
473 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
473 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
474 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
474 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
475 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
475 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
476 // }
476 // }
477 else if (m_barRadioButton->isChecked())
477 else if (m_barRadioButton->isChecked())
478 {
478 {
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
479 m_chart->setAnimationOptions(QChart::SeriesAnimations);
480
480
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
481 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
482 // barSeries->setCategories(QStringList());
482 // barSeries->setCategories(QStringList());
483 // barSeries->setModel(m_model);
483 // barSeries->setModel(m_model);
484 // barSeries->setModelMappingRange(2, 5);
484 // barSeries->setModelMappingRange(2, 5);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
486
486
487 int first = 3;
487 int first = 3;
488 // int count = 4;
488 // int count = 4;
489 QVBarModelMapper *mapper = new QVBarModelMapper;
489 QVBarModelMapper *mapper = new QVBarModelMapper;
490 mapper->setCategoriesSection(5);
490 mapper->setCategoriesSection(5);
491 mapper->setFirstBarSetSection(2);
491 mapper->setFirstBarSetSection(2);
492 mapper->setLastBarSetSection(4);
492 mapper->setLastBarSetSection(4);
493 mapper->setFirst(first);
493 mapper->setFirst(first);
494 // mapper->setCount(count);
494 // mapper->setCount(count);
495 mapper->setSeries(barSeries);
495 mapper->setSeries(barSeries);
496 mapper->setModel(m_model);
496 mapper->setModel(m_model);
497 // barSeries->setModelMapper(mapper);
497 // barSeries->setModelMapper(mapper);
498 m_chart->addSeries(barSeries);
498 m_chart->addSeries(barSeries);
499 QList<QBarSet*> barsets = barSeries->barSets();
499 QList<QBarSet*> barsets = barSeries->barSets();
500 for (int i = 0; i < barsets.count(); i++) {
500 for (int i = 0; i < barsets.count(); i++) {
501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
503 }
503 }
504 }
504 }
505
505
506
506
507 if (!m_barRadioButton->isChecked()) {
507 if (!m_barRadioButton->isChecked()) {
508 m_chart->axisX()->setRange(0, 500);
508 // m_chart->axisX()->setRange(0, 500);
509 m_chart->axisY()->setRange(0, 220);
509 // m_chart->axisY()->setRange(0, 220);
510 }
510 }
511 m_chart->legend()->setVisible(true);
511 m_chart->legend()->setVisible(true);
512
512
513 // repaint table view colors
513 // repaint table view colors
514 m_tableView->repaint();
514 m_tableView->repaint();
515 m_tableView->setFocus();
515 m_tableView->setFocus();
516 }
516 }
517 }
517 }
518
518
519 void TableWidget::testPie()
519 void TableWidget::testPie()
520 {
520 {
521 // m_pieMapper->setCount(-1);
521 // m_pieMapper->setCount(-1);
522 QPieSlice *slice = new QPieSlice("Hehe", 145);
522 QPieSlice *slice = new QPieSlice("Hehe", 145);
523 slice->setLabelVisible();
523 slice->setLabelVisible();
524 m_pieSeries->append(slice);
524 m_pieSeries->append(slice);
525
525
526 slice = new QPieSlice("Hoho", 34);
526 slice = new QPieSlice("Hoho", 34);
527 slice->setLabelVisible();
527 slice->setLabelVisible();
528 m_pieSeries->append(slice);
528 m_pieSeries->append(slice);
529 // m_series->modelMapper()->setMapX(4);
529 // m_series->modelMapper()->setMapX(4);
530 // m_tableView->setColumnWidth(10, 250);
530 // m_tableView->setColumnWidth(10, 250);
531 // if (specialPie) {
531 // if (specialPie) {
532 // specialPie->remove(specialPie->slices().at(2));
532 // specialPie->remove(specialPie->slices().at(2));
533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
534 // specialPie->append(4, "heloo");
534 // specialPie->append(4, "heloo");
535 // }
535 // }
536 }
536 }
537
537
538 void TableWidget::testPie2()
538 void TableWidget::testPie2()
539 {
539 {
540 QPieSlice *slice;
540 QPieSlice *slice;
541 if (m_pieSeries->count() > 0) {
541 if (m_pieSeries->count() > 0) {
542 slice = m_pieSeries->slices().last();
542 slice = m_pieSeries->slices().last();
543 m_pieSeries->remove(slice);
543 m_pieSeries->remove(slice);
544 }
544 }
545
545
546 if (m_pieSeries->count() > 0) {
546 if (m_pieSeries->count() > 0) {
547 slice = m_pieSeries->slices().first();
547 slice = m_pieSeries->slices().first();
548 m_pieSeries->remove(slice);
548 m_pieSeries->remove(slice);
549 }
549 }
550 }
550 }
551
551
552 void TableWidget::testPie3()
552 void TableWidget::testPie3()
553 {
553 {
554 QPieSlice *slice;
554 QPieSlice *slice;
555 if (m_pieSeries->count() > 0) {
555 if (m_pieSeries->count() > 0) {
556 slice = m_pieSeries->slices().last();
556 slice = m_pieSeries->slices().last();
557 slice->setLabel("Dalej");
557 slice->setLabel("Dalej");
558 slice->setValue(222);
558 slice->setValue(222);
559 }
559 }
560
560
561 if (m_pieSeries->count() > 0) {
561 if (m_pieSeries->count() > 0) {
562 slice = m_pieSeries->slices().first();
562 slice = m_pieSeries->slices().first();
563 slice->setLabel("Prawie");
563 slice->setLabel("Prawie");
564 slice->setValue(111);
564 slice->setValue(111);
565 }
565 }
566 }
566 }
567
567
568 void TableWidget::testXY()
568 void TableWidget::testXY()
569 {
569 {
570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
571 // m_series->append(QPointF(150, 75));
571 // m_series->append(QPointF(150, 75));
572 // }
572 // }
573
573
574 if (m_series->count() > 0) {
574 if (m_series->count() > 0) {
575 m_series->remove(m_series->points().last());
575 m_series->remove(m_series->points().last());
576 }
576 }
577 }
577 }
578
578
579 TableWidget::~TableWidget()
579 TableWidget::~TableWidget()
580 {
580 {
581
581
582 }
582 }
@@ -1,83 +1,83
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 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 TABLEWIDGET_H
21 #ifndef TABLEWIDGET_H
22 #define TABLEWIDGET_H
22 #define TABLEWIDGET_H
23
23
24 #include <QtGui/QWidget>
24 #include <QtGui/QWidget>
25 //#include <QChartGlobal>
25 //#include <QChartGlobal>
26 #include "qchartview.h"
26 #include "qchartview.h"
27 //#include "qxyseries.h"
27 //#include "qxyseries.h"
28 #include <QPieSeries>
28 #include <QPieSeries>
29 #include <QVPieModelMapper>
29 #include <QVPieModelMapper>
30 #include <QVXYModelMapper>
30 #include <QVXYModelMapper>
31 #include <QHXYModelMapper>
31 #include <QHXYModelMapper>
32
32
33 class CustomTableModel;
33 class CustomTableModel;
34 class QTableView;
34 class QTableView;
35 class QRadioButton;
35 class QRadioButton;
36 class QSpinBox;
36 class QSpinBox;
37
37
38 QTCOMMERCIALCHART_USE_NAMESPACE
38 QTCOMMERCIALCHART_USE_NAMESPACE
39
39
40 class TableWidget : public QWidget
40 class TableWidget : public QWidget
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43
43
44 public:
44 public:
45 TableWidget(QWidget *parent = 0);
45 TableWidget(QWidget *parent = 0);
46 ~TableWidget();
46 ~TableWidget();
47
47
48
48
49 public slots:
49 public slots:
50 void addRowAbove();
50 void addRowAbove();
51 void addRowBelow();
51 void addRowBelow();
52 void removeRow();
52 void removeRow();
53 void addColumnRight();
53 void addColumnRight();
54 void removeColumn();
54 void removeColumn();
55 void updateChartType(bool toggle);
55 void updateChartType(bool toggle);
56 void testPie();
56 void testPie();
57 void testPie2();
57 void testPie2();
58 void testPie3();
58 void testPie3();
59
59
60 void testXY();
60 void testXY();
61
61
62 private:
62 private:
63 QChartView* m_chartView;
63 QChartView* m_chartView;
64 QChart* m_chart;
64 QChart* m_chart;
65 QXYSeries* m_series;
65 QXYSeries* m_series;
66 QHXYModelMapper *m_mapper;
66 QVXYModelMapper *m_mapper;
67 CustomTableModel* m_model;
67 CustomTableModel* m_model;
68 QTableView* m_tableView;
68 QTableView* m_tableView;
69 QRadioButton* m_lineRadioButton;
69 QRadioButton* m_lineRadioButton;
70 QRadioButton* m_splineRadioButton;
70 QRadioButton* m_splineRadioButton;
71 QRadioButton* m_scatterRadioButton;
71 QRadioButton* m_scatterRadioButton;
72 QRadioButton* m_pieRadioButton;
72 QRadioButton* m_pieRadioButton;
73 QRadioButton* m_areaRadioButton;
73 QRadioButton* m_areaRadioButton;
74 QRadioButton* m_barRadioButton;
74 QRadioButton* m_barRadioButton;
75 QSpinBox* m_linesCountSpinBox;
75 QSpinBox* m_linesCountSpinBox;
76 QVPieModelMapper *m_pieMapper;
76 QVPieModelMapper *m_pieMapper;
77 QPieSeries* m_pieSeries;
77 QPieSeries* m_pieSeries;
78 QVPieModelMapper *m_pieMapper2;
78 QVPieModelMapper *m_pieMapper2;
79 QPieSeries* m_pieSeries2;
79 QPieSeries* m_pieSeries2;
80 // QPieSeries* specialPie;
80 // QPieSeries* specialPie;
81 };
81 };
82
82
83 #endif // TABLEWIDGET_H
83 #endif // TABLEWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now