##// END OF EJS Templates
BarModelMapper: implemented model updated slots. Some more work needed with categories
Marek Rosa -
r1295:2f3c0756d825
parent child
Show More
@@ -1,407 +1,423
1 #include "qbarmodelmapper.h"
1 #include "qbarmodelmapper.h"
2 #include "qbarmodelmapper_p.h"
2 #include "qbarmodelmapper_p.h"
3 #include "qbarseries.h"
3 #include "qbarseries.h"
4 #include "qbarset.h"
4 #include "qbarset.h"
5 #include <QAbstractItemModel>
5 #include <QAbstractItemModel>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QBarModelMapper::QBarModelMapper(QObject *parent) :
9 QBarModelMapper::QBarModelMapper(QObject *parent) :
10 QObject(parent),
10 QObject(parent),
11 d_ptr(new QBarModelMapperPrivate(this))
11 d_ptr(new QBarModelMapperPrivate(this))
12 {
12 {
13 }
13 }
14
14
15 QAbstractItemModel* QBarModelMapper::model() const
15 QAbstractItemModel* QBarModelMapper::model() const
16 {
16 {
17 Q_D(const QBarModelMapper);
17 Q_D(const QBarModelMapper);
18 return d->m_model;
18 return d->m_model;
19 }
19 }
20
20
21 void QBarModelMapper::setModel(QAbstractItemModel *model)
21 void QBarModelMapper::setModel(QAbstractItemModel *model)
22 {
22 {
23 if (model == 0)
23 if (model == 0)
24 return;
24 return;
25
25
26 Q_D(QBarModelMapper);
26 Q_D(QBarModelMapper);
27 if (d->m_model) {
27 if (d->m_model) {
28 disconnect(d->m_model, 0, d, 0);
28 disconnect(d->m_model, 0, d, 0);
29 }
29 }
30
30
31 d->m_model = model;
31 d->m_model = model;
32 d->initializeBarFromModel();
32 d->initializeBarFromModel();
33 // connect signals from the model
33 // connect signals from the model
34 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
34 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
35 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
35 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
36 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
36 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
37 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
37 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
38 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
38 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
39 }
39 }
40
40
41 QBarSeries* QBarModelMapper::series() const
41 QBarSeries* QBarModelMapper::series() const
42 {
42 {
43 Q_D(const QBarModelMapper);
43 Q_D(const QBarModelMapper);
44 return d->m_series;
44 return d->m_series;
45 }
45 }
46
46
47 void QBarModelMapper::setSeries(QBarSeries *series)
47 void QBarModelMapper::setSeries(QBarSeries *series)
48 {
48 {
49 Q_D(QBarModelMapper);
49 Q_D(QBarModelMapper);
50 if (d->m_series) {
50 if (d->m_series) {
51 disconnect(d->m_series, 0, d, 0);
51 disconnect(d->m_series, 0, d, 0);
52 }
52 }
53
53
54 if (series == 0)
54 if (series == 0)
55 return;
55 return;
56
56
57 d->m_series = series;
57 d->m_series = series;
58 d->initializeBarFromModel();
58 d->initializeBarFromModel();
59 // connect the signals from the series
59 // connect the signals from the series
60 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
60 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
61 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
61 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
62 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
62 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
63 }
63 }
64
64
65 int QBarModelMapper::first() const
65 int QBarModelMapper::first() const
66 {
66 {
67 Q_D(const QBarModelMapper);
67 Q_D(const QBarModelMapper);
68 return d->m_first;
68 return d->m_first;
69 }
69 }
70
70
71 void QBarModelMapper::setFirst(int first)
71 void QBarModelMapper::setFirst(int first)
72 {
72 {
73 Q_D(QBarModelMapper);
73 Q_D(QBarModelMapper);
74 d->m_first = qMax(first, 0);
74 d->m_first = qMax(first, 0);
75 d->initializeBarFromModel();
75 d->initializeBarFromModel();
76 }
76 }
77
77
78 int QBarModelMapper::count() const
78 int QBarModelMapper::count() const
79 {
79 {
80 Q_D(const QBarModelMapper);
80 Q_D(const QBarModelMapper);
81 return d->m_count;
81 return d->m_count;
82 }
82 }
83
83
84 void QBarModelMapper::setCount(int count)
84 void QBarModelMapper::setCount(int count)
85 {
85 {
86 Q_D(QBarModelMapper);
86 Q_D(QBarModelMapper);
87 d->m_count = qMax(count, -1);
87 d->m_count = qMax(count, -1);
88 d->initializeBarFromModel();
88 d->initializeBarFromModel();
89 }
89 }
90
90
91 Qt::Orientation QBarModelMapper::orientation() const
91 Qt::Orientation QBarModelMapper::orientation() const
92 {
92 {
93 Q_D(const QBarModelMapper);
93 Q_D(const QBarModelMapper);
94 return d->m_orientation;
94 return d->m_orientation;
95 }
95 }
96
96
97 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
97 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
98 {
98 {
99 Q_D(QBarModelMapper);
99 Q_D(QBarModelMapper);
100 d->m_orientation = orientation;
100 d->m_orientation = orientation;
101 d->initializeBarFromModel();
101 d->initializeBarFromModel();
102 }
102 }
103
103
104 int QBarModelMapper::firstBarSection() const
104 int QBarModelMapper::firstBarSection() const
105 {
105 {
106 Q_D(const QBarModelMapper);
106 Q_D(const QBarModelMapper);
107 return d->m_firstBarSection;
107 return d->m_firstBarSection;
108 }
108 }
109
109
110 void QBarModelMapper::setFirstBarSection(int firstBarSection)
110 void QBarModelMapper::setFirstBarSection(int firstBarSection)
111 {
111 {
112 Q_D(QBarModelMapper);
112 Q_D(QBarModelMapper);
113 d->m_firstBarSection = firstBarSection;
113 d->m_firstBarSection = firstBarSection;
114 d->initializeBarFromModel();
114 d->initializeBarFromModel();
115 }
115 }
116
116
117 int QBarModelMapper::lastBarSection() const
117 int QBarModelMapper::lastBarSection() const
118 {
118 {
119 Q_D(const QBarModelMapper);
119 Q_D(const QBarModelMapper);
120 return d->m_lastBarSection;
120 return d->m_lastBarSection;
121 }
121 }
122
122
123 void QBarModelMapper::setLastBarSection(int lastBarSection)
123 void QBarModelMapper::setLastBarSection(int lastBarSection)
124 {
124 {
125 Q_D(QBarModelMapper);
125 Q_D(QBarModelMapper);
126 d->m_lastBarSection = lastBarSection;
126 d->m_lastBarSection = lastBarSection;
127 d->initializeBarFromModel();
127 d->initializeBarFromModel();
128 }
128 }
129
129
130 int QBarModelMapper::categoriesSection() const
130 int QBarModelMapper::categoriesSection() const
131 {
131 {
132 Q_D(const QBarModelMapper);
132 Q_D(const QBarModelMapper);
133 return d->m_categoriesSection;
133 return d->m_categoriesSection;
134 }
134 }
135
135
136 void QBarModelMapper::setCategoriesSection(int categoriesSection)
136 void QBarModelMapper::setCategoriesSection(int categoriesSection)
137 {
137 {
138 Q_D(QBarModelMapper);
138 Q_D(QBarModelMapper);
139 d->m_categoriesSection = categoriesSection;
139 d->m_categoriesSection = categoriesSection;
140 d->initializeBarFromModel();
140 d->initializeBarFromModel();
141 }
141 }
142
142
143 void QBarModelMapper::reset()
143 void QBarModelMapper::reset()
144 {
144 {
145 Q_D(QBarModelMapper);
145 Q_D(QBarModelMapper);
146 d->m_first = 0;
146 d->m_first = 0;
147 d->m_count = -1;
147 d->m_count = -1;
148 d->m_orientation = Qt::Vertical;
148 d->m_orientation = Qt::Vertical;
149 d->m_firstBarSection = -1;
149 d->m_firstBarSection = -1;
150 d->m_lastBarSection = -1;
150 d->m_lastBarSection = -1;
151 d->m_categoriesSection = -1;
151 d->m_categoriesSection = -1;
152 d->initializeBarFromModel();
152 d->initializeBarFromModel();
153 }
153 }
154
154
155 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156
156
157 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
157 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
158 m_series(0),
158 m_series(0),
159 m_model(0),
159 m_model(0),
160 m_first(0),
160 m_first(0),
161 m_count(-1),
161 m_count(-1),
162 m_orientation(Qt::Vertical),
162 m_orientation(Qt::Vertical),
163 m_firstBarSection(-1),
163 m_firstBarSection(-1),
164 m_lastBarSection(-1),
164 m_lastBarSection(-1),
165 m_categoriesSection(-1),
165 m_categoriesSection(-1),
166 m_seriesSignalsBlock(false),
166 m_seriesSignalsBlock(false),
167 m_modelSignalsBlock(false),
167 m_modelSignalsBlock(false),
168 q_ptr(q)
168 q_ptr(q)
169 {
169 {
170 }
170 }
171
171
172 void QBarModelMapperPrivate::blockModelSignals(bool block)
172 void QBarModelMapperPrivate::blockModelSignals(bool block)
173 {
173 {
174 m_modelSignalsBlock = block;
174 m_modelSignalsBlock = block;
175 }
175 }
176
176
177 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
177 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
178 {
178 {
179 m_seriesSignalsBlock = block;
179 m_seriesSignalsBlock = block;
180 }
180 }
181
181
182 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
183 {
184 if (!index.isValid())
185 return 0;
186
187 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSection && index.column() <= m_lastBarSection) {
188 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
189 return m_series->barSets().at(index.column() - m_firstBarSection);
190 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSection && index.row() <= m_lastBarSection) {
191 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
192 return m_series->barSets().at(index.row() - m_firstBarSection);
193 }
194 return 0; // This part of model has not been mapped to any slice
195 }
196
182 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
197 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
183 {
198 {
184 if (m_count != -1 && posInBar >= m_count)
199 if (m_count != -1 && posInBar >= m_count)
185 return QModelIndex(); // invalid
200 return QModelIndex(); // invalid
186
201
187 if (barSection < m_firstBarSection || barSection > m_lastBarSection)
202 if (barSection < m_firstBarSection || barSection > m_lastBarSection)
188 return QModelIndex(); // invalid
203 return QModelIndex(); // invalid
189
204
190 if (m_orientation == Qt::Vertical)
205 if (m_orientation == Qt::Vertical)
191 return m_model->index(posInBar + m_first, barSection);
206 return m_model->index(posInBar + m_first, barSection);
192 else
207 else
193 return m_model->index(barSection, posInBar + m_first);
208 return m_model->index(barSection, posInBar + m_first);
194 }
209 }
195
210
196 QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories)
211 QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories)
197 {
212 {
198 if (m_count != -1 && posInCategories >= m_count)
213 if (m_count != -1 && posInCategories >= m_count)
199 return QModelIndex(); // invalid
214 return QModelIndex(); // invalid
200
215
201 if (m_orientation == Qt::Vertical)
216 if (m_orientation == Qt::Vertical)
202 return m_model->index(posInCategories + m_first, m_categoriesSection);
217 return m_model->index(posInCategories + m_first, m_categoriesSection);
203 else
218 else
204 return m_model->index(m_categoriesSection, posInCategories + m_first);
219 return m_model->index(m_categoriesSection, posInCategories + m_first);
205 }
220 }
206
221
207 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
222 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
208 {
223 {
209 Q_UNUSED(topLeft)
224 Q_UNUSED(topLeft)
210 Q_UNUSED(bottomRight)
225 Q_UNUSED(bottomRight)
211
226
212 if (m_model == 0 || m_series == 0)
227 if (m_model == 0 || m_series == 0)
213 return;
228 return;
214
229
215 if (m_modelSignalsBlock)
230 if (m_modelSignalsBlock)
216 return;
231 return;
217
232
218 // blockSeriesSignals();
233 blockSeriesSignals();
219 // QModelIndex index;
234 QModelIndex index;
220 // QPointF oldPoint;
235 // QPointF oldPoint;
221 // QPointF newPoint;
236 // QPointF newPoint;
222 // for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
237 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
223 // for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
238 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
224 // index = topLeft.sibling(row, column);
239 index = topLeft.sibling(row, column);
225 // if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) {
240 QBarSet* bar = barSet(index);
226 // if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
241 if (bar) {
227 // oldPoint = m_series->points().at(index.row() - m_first);
242 if (m_orientation == Qt::Vertical)
228 // newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal());
243 bar->replace(row - m_first, m_model->data(index).toReal());
229 // newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal());
244 else
230 // }
245 bar->replace(column - m_first, m_model->data(index).toReal());
231 // } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
246 }
232 // if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
247 }
233 // oldPoint = m_series->points().at(index.column() - m_first);
248 }
234 // newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal());
249 blockSeriesSignals(false);
235 // newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal());
236 // }
237 // } else {
238 // continue;
239 // }
240 // m_series->replace(oldPoint, newPoint);
241 // }
242 // blockSeriesSignals(false);
243 // }
244 }
250 }
245
251
246 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
252 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
247 {
253 {
248 Q_UNUSED(parent);
254 Q_UNUSED(parent);
255 Q_UNUSED(end)
249 if (m_modelSignalsBlock)
256 if (m_modelSignalsBlock)
250 return;
257 return;
251
258
252 blockSeriesSignals();
259 blockSeriesSignals();
253 if (m_orientation == Qt::Vertical)
260 if (m_orientation == Qt::Vertical)
254 insertData(start, end);
261 // insertData(start, end);
262 initializeBarFromModel();
255 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
263 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
256 initializeBarFromModel();
264 initializeBarFromModel();
257 blockSeriesSignals(false);
265 blockSeriesSignals(false);
258 }
266 }
259
267
260 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
268 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
261 {
269 {
262 Q_UNUSED(parent);
270 Q_UNUSED(parent);
271 Q_UNUSED(end)
263 if (m_modelSignalsBlock)
272 if (m_modelSignalsBlock)
264 return;
273 return;
265
274
266 blockSeriesSignals();
275 blockSeriesSignals();
267 if (m_orientation == Qt::Vertical)
276 if (m_orientation == Qt::Vertical)
268 removeData(start, end);
277 // removeData(start, end);
278 initializeBarFromModel();
269 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
279 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
270 initializeBarFromModel();
280 initializeBarFromModel();
271 blockSeriesSignals(false);
281 blockSeriesSignals(false);
272 }
282 }
273
283
274 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
284 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
275 {
285 {
276 Q_UNUSED(parent);
286 Q_UNUSED(parent);
287 Q_UNUSED(end)
277 if (m_modelSignalsBlock)
288 if (m_modelSignalsBlock)
278 return;
289 return;
279
290
280 blockSeriesSignals();
291 blockSeriesSignals();
281 if (m_orientation == Qt::Horizontal)
292 if (m_orientation == Qt::Horizontal)
282 insertData(start, end);
293 // insertData(start, end);
294 initializeBarFromModel();
283 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
295 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
284 initializeBarFromModel();
296 initializeBarFromModel();
285 blockSeriesSignals(false);
297 blockSeriesSignals(false);
286 }
298 }
287
299
288 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
300 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
289 {
301 {
290 Q_UNUSED(parent);
302 Q_UNUSED(parent);
303 Q_UNUSED(end)
291 if (m_modelSignalsBlock)
304 if (m_modelSignalsBlock)
292 return;
305 return;
293
306
294 blockSeriesSignals();
307 blockSeriesSignals();
295 if (m_orientation == Qt::Horizontal)
308 if (m_orientation == Qt::Horizontal)
296 removeData(start, end);
309 // removeData(start, end);
310 initializeBarFromModel();
297 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
311 else if (start <= m_firstBarSection || start <= m_lastBarSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
298 initializeBarFromModel();
312 initializeBarFromModel();
299 blockSeriesSignals(false);
313 blockSeriesSignals(false);
300 }
314 }
301
315
302 void QBarModelMapperPrivate::insertData(int start, int end)
316 void QBarModelMapperPrivate::insertData(int start, int end)
303 {
317 {
304 Q_UNUSED(end)
318 Q_UNUSED(end)
305 if (m_model == 0 || m_series == 0)
319 if (m_model == 0 || m_series == 0)
306 return;
320 return;
307
321
308 if (m_count != -1 && start >= m_first + m_count) {
322 if (m_count != -1 && start >= m_first + m_count) {
309 return;
323 return;
310 } /*else {
324 } /*else {
311 int addedCount = end - start + 1;
325 int addedCount = end - start + 1;
312 if (m_count != -1 && addedCount > m_count)
326 if (m_count != -1 && addedCount > m_count)
313 addedCount = m_count;
327 addedCount = m_count;
314 int first = qMax(start, m_first);
328 int first = qMax(start, m_first);
315 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
329 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
316 for (int i = first; i <= last; i++) {
330 for (int k = 0; k < m_series->barSets().count(); k++) {
317 QPointF point;
331 for (int i = first; i <= last; i++) {
318 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
332 QBar point;
319 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
333 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
320 m_series->insert(i - m_first, point);
334 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
335 m_series->insert(i - m_first, point);
336 }
321 }
337 }
322
338
323 // remove excess of slices (abouve m_count)
339 // remove excess of slices (abouve m_count)
324 if (m_count != -1 && m_series->points().size() > m_count)
340 if (m_count != -1 && m_series->points().size() > m_count)
325 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
341 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
326 m_series->remove(m_series->points().at(i));
342 m_series->remove(m_series->points().at(i));
327 }
343 }
328 }*/
344 }*/
329 }
345 }
330
346
331 void QBarModelMapperPrivate::removeData(int start, int end)
347 void QBarModelMapperPrivate::removeData(int start, int end)
332 {
348 {
333 Q_UNUSED(end)
349 Q_UNUSED(end)
334 if (m_model == 0 || m_series == 0)
350 if (m_model == 0 || m_series == 0)
335 return;
351 return;
336
352
337 // int removedCount = end - start + 1;
353 // int removedCount = end - start + 1;
338 if (m_count != -1 && start >= m_first + m_count) {
354 if (m_count != -1 && start >= m_first + m_count) {
339 return;
355 return;
340 } /*else {
356 } /*else {
341 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
357 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
342 int first = qMax(start, m_first); // get the index of the first item that will be removed.
358 int first = qMax(start, m_first); // get the index of the first item that will be removed.
343 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
359 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
344 for (int i = last; i >= first; i--) {
360 for (int i = last; i >= first; i--) {
345 m_series->remove(m_series->points().at(i - m_first));
361 m_series->remove(m_series->points().at(i - m_first));
346 }
362 }
347
363
348 if (m_count != -1) {
364 if (m_count != -1) {
349 int itemsAvailable; // check how many are available to be added
365 int itemsAvailable; // check how many are available to be added
350 if (m_orientation == Qt::Vertical)
366 if (m_orientation == Qt::Vertical)
351 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
367 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
352 else
368 else
353 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
369 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
354 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
370 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
355 int currentSize = m_series->count();
371 int currentSize = m_series->count();
356 if (toBeAdded > 0)
372 if (toBeAdded > 0)
357 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
373 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
358 QPointF point;
374 QPointF point;
359 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
375 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
360 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
376 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
361 m_series->insert(i, point);
377 m_series->insert(i, point);
362 }
378 }
363 }
379 }
364 }*/
380 }*/
365 }
381 }
366
382
367 void QBarModelMapperPrivate::initializeBarFromModel()
383 void QBarModelMapperPrivate::initializeBarFromModel()
368 {
384 {
369 if (m_model == 0 || m_series == 0)
385 if (m_model == 0 || m_series == 0)
370 return;
386 return;
371
387
372 blockSeriesSignals();
388 blockSeriesSignals();
373 // clear current content
389 // clear current content
374 // m_series->clear();
390 m_series->clear();
375
391
376 // create the initial bar sets
392 // create the initial bar sets
377 for (int i = m_firstBarSection; i <= m_lastBarSection; i++) {
393 for (int i = m_firstBarSection; i <= m_lastBarSection; i++) {
378 int posInBar = 0;
394 int posInBar = 0;
379 QModelIndex barIndex = barModelIndex(i, posInBar);
395 QModelIndex barIndex = barModelIndex(i, posInBar);
380 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
396 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
381 // QModelIndex yIndex = yModelIndex(pointPos);
397 // QModelIndex yIndex = yModelIndex(pointPos);
382 while (barIndex.isValid()) {
398 while (barIndex.isValid()) {
383 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
399 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
384 posInBar++;
400 posInBar++;
385 barIndex = barModelIndex(i, posInBar);
401 barIndex = barModelIndex(i, posInBar);
386 }
402 }
387 m_series->append(barSet);
403 m_series->append(barSet);
388 }
404 }
389
405
390 if (m_categoriesSection != -1) {
406 if (m_categoriesSection != -1) {
391 int posInCategories = 0;
407 int posInCategories = 0;
392 QStringList categories;
408 QStringList categories;
393 QModelIndex categoriesIndex = categoriesModelIndex(posInCategories);
409 QModelIndex categoriesIndex = categoriesModelIndex(posInCategories);
394 while (categoriesIndex.isValid()) {
410 while (categoriesIndex.isValid()) {
395 categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString());
411 categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString());
396 posInCategories++;
412 posInCategories++;
397 categoriesIndex = categoriesModelIndex(posInCategories);
413 categoriesIndex = categoriesModelIndex(posInCategories);
398 }
414 }
399 m_series->setCategories(categories);
415 m_series->setCategories(categories);
400 }
416 }
401 blockSeriesSignals(false);
417 blockSeriesSignals(false);
402 }
418 }
403
419
404 #include "moc_qbarmodelmapper.cpp"
420 #include "moc_qbarmodelmapper.cpp"
405 #include "moc_qbarmodelmapper_p.cpp"
421 #include "moc_qbarmodelmapper_p.cpp"
406
422
407 QTCOMMERCIALCHART_END_NAMESPACE
423 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,63
1 #ifndef QBARMODELMAPPER_P_H
1 #ifndef QBARMODELMAPPER_P_H
2 #define QBARMODELMAPPER_P_H
2 #define QBARMODELMAPPER_P_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6 #include "qbarmodelmapper.h"
6 #include "qbarmodelmapper.h"
7
7
8 class QModelIndex;
8 class QModelIndex;
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QBarSet;
13
12 class QBarModelMapperPrivate : public QObject
14 class QBarModelMapperPrivate : public QObject
13 {
15 {
14 Q_OBJECT
16 Q_OBJECT
15 public:
17 public:
16 explicit QBarModelMapperPrivate(QBarModelMapper *q);
18 explicit QBarModelMapperPrivate(QBarModelMapper *q);
17
19
18 public Q_SLOTS:
20 public Q_SLOTS:
19 // for the model
21 // for the model
20 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
22 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
21 void modelRowsAdded(QModelIndex parent, int start, int end);
23 void modelRowsAdded(QModelIndex parent, int start, int end);
22 void modelRowsRemoved(QModelIndex parent, int start, int end);
24 void modelRowsRemoved(QModelIndex parent, int start, int end);
23 void modelColumnsAdded(QModelIndex parent, int start, int end);
25 void modelColumnsAdded(QModelIndex parent, int start, int end);
24 void modelColumnsRemoved(QModelIndex parent, int start, int end);
26 void modelColumnsRemoved(QModelIndex parent, int start, int end);
25
27
26 // // for the series
28 // // for the series
27 // void handlePointAdded(int pointPos);
29 // void handlePointAdded(int pointPos);
28 // void handlePointRemoved(int pointPos);
30 // void handlePointRemoved(int pointPos);
29 // void handlePointReplaced(int pointPos);
31 // void handlePointReplaced(int pointPos);
30
32
31 void initializeBarFromModel();
33 void initializeBarFromModel();
32
34
33 private:
35 private:
36 QBarSet* barSet(QModelIndex index);
34 QModelIndex barModelIndex(int barSection, int posInBar);
37 QModelIndex barModelIndex(int barSection, int posInBar);
35 QModelIndex categoriesModelIndex(int posInCategories);
38 QModelIndex categoriesModelIndex(int posInCategories);
36 void insertData(int start, int end);
39 void insertData(int start, int end);
37 void removeData(int start, int end);
40 void removeData(int start, int end);
38 void blockModelSignals(bool block = true);
41 void blockModelSignals(bool block = true);
39 void blockSeriesSignals(bool block = true);
42 void blockSeriesSignals(bool block = true);
40
43
41 private:
44 private:
42 QBarSeries *m_series;
45 QBarSeries *m_series;
43 QAbstractItemModel *m_model;
46 QAbstractItemModel *m_model;
44 int m_first;
47 int m_first;
45 int m_count;
48 int m_count;
46 Qt::Orientation m_orientation;
49 Qt::Orientation m_orientation;
47 int m_firstBarSection;
50 int m_firstBarSection;
48 int m_lastBarSection;
51 int m_lastBarSection;
49 int m_categoriesSection;
52 int m_categoriesSection;
50 bool m_seriesSignalsBlock;
53 bool m_seriesSignalsBlock;
51 bool m_modelSignalsBlock;
54 bool m_modelSignalsBlock;
52
55
53 private:
56 private:
54 QBarModelMapper *q_ptr;
57 QBarModelMapper *q_ptr;
55 Q_DECLARE_PUBLIC(QBarModelMapper)
58 Q_DECLARE_PUBLIC(QBarModelMapper)
56 };
59 };
57
60
58 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
59
62
60 #endif // QBARMODELMAPPER_P_H
63 #endif // QBARMODELMAPPER_P_H
@@ -1,568 +1,575
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 "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QBarSeries
34 \class QBarSeries
35 \brief part of QtCommercial chart API.
35 \brief part of QtCommercial chart API.
36 \mainclass
36 \mainclass
37
37
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 shows the x-values.
41 shows the x-values.
42
42
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 \image examples_barchart.png
44 \image examples_barchart.png
45
45
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn void QBarSeries::clicked(QBarSet *barset, QString category)
50 \fn void QBarSeries::clicked(QBarSet *barset, QString category)
51
51
52 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category
52 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category
53 contained by the series.
53 contained by the series.
54 */
54 */
55
55
56 /*!
56 /*!
57 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
57 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
58
58
59 The signal is emitted if mouse is hovered on top of series.
59 The signal is emitted if mouse is hovered on top of series.
60 Parameter \a barset is the pointer of barset, where hover happened.
60 Parameter \a barset is the pointer of barset, where hover happened.
61 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
61 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
62 */
62 */
63
63
64 /*!
64 /*!
65 Constructs empty QBarSeries.
65 Constructs empty QBarSeries.
66 QBarSeries is QObject which is a child of a \a parent.
66 QBarSeries is QObject which is a child of a \a parent.
67 */
67 */
68 QBarSeries::QBarSeries(QObject *parent) :
68 QBarSeries::QBarSeries(QObject *parent) :
69 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
69 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
70 {
70 {
71 }
71 }
72
72
73 /*!
73 /*!
74 Destructs barseries and owned barsets.
74 Destructs barseries and owned barsets.
75 */
75 */
76 QBarSeries::~QBarSeries()
76 QBarSeries::~QBarSeries()
77 {
77 {
78 Q_D(QBarSeries);
78 Q_D(QBarSeries);
79 if(d->m_dataset){
79 if(d->m_dataset){
80 d->m_dataset->removeSeries(this);
80 d->m_dataset->removeSeries(this);
81 }
81 }
82 }
82 }
83
83
84 /*!
84 /*!
85 \internal
85 \internal
86 */
86 */
87 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
87 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
88 QAbstractSeries(d,parent)
88 QAbstractSeries(d,parent)
89 {
89 {
90 }
90 }
91
91
92 /*!
92 /*!
93 Returns the type of series. Derived classes override this.
93 Returns the type of series. Derived classes override this.
94 */
94 */
95 QAbstractSeries::SeriesType QBarSeries::type() const
95 QAbstractSeries::SeriesType QBarSeries::type() const
96 {
96 {
97 return QAbstractSeries::SeriesTypeBar;
97 return QAbstractSeries::SeriesTypeBar;
98 }
98 }
99
99
100 /*!
100 /*!
101 Sets the \a categories, which are used to to group the data.
101 Sets the \a categories, which are used to to group the data.
102 */
102 */
103 void QBarSeries::setCategories(QBarCategories categories)
103 void QBarSeries::setCategories(QBarCategories categories)
104 {
104 {
105 Q_D(QBarSeries);
105 Q_D(QBarSeries);
106 d->setCategories(categories);
106 d->setCategories(categories);
107 emit d->categoriesUpdated();
107 emit d->categoriesUpdated();
108 }
108 }
109
109
110 void QBarSeries::setBarMargin(qreal margin)
110 void QBarSeries::setBarMargin(qreal margin)
111 {
111 {
112 Q_D(QBarSeries);
112 Q_D(QBarSeries);
113 d->setBarMargin(margin);
113 d->setBarMargin(margin);
114 }
114 }
115
115
116 qreal QBarSeries::barMargin() const
116 qreal QBarSeries::barMargin() const
117 {
117 {
118 Q_D(const QBarSeries);
118 Q_D(const QBarSeries);
119 return d->barMargin();
119 return d->barMargin();
120 }
120 }
121
121
122 /*!
122 /*!
123 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
123 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
124 Returns true, if appending succeeded.
124 Returns true, if appending succeeded.
125
125
126 */
126 */
127 bool QBarSeries::append(QBarSet *set)
127 bool QBarSeries::append(QBarSet *set)
128 {
128 {
129 Q_D(QBarSeries);
129 Q_D(QBarSeries);
130 return d->append(set);
130 return d->append(set);
131 }
131 }
132
132
133 /*!
133 /*!
134 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
134 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
135 Returns true, if set was removed.
135 Returns true, if set was removed.
136 */
136 */
137 bool QBarSeries::remove(QBarSet *set)
137 bool QBarSeries::remove(QBarSet *set)
138 {
138 {
139 Q_D(QBarSeries);
139 Q_D(QBarSeries);
140 return d->remove(set);
140 return d->remove(set);
141 }
141 }
142
142
143 /*!
143 /*!
144 Adds a list of barsets to series. Takes ownership of \a sets.
144 Adds a list of barsets to series. Takes ownership of \a sets.
145 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
145 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
146 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
146 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
147 and function returns false.
147 and function returns false.
148 */
148 */
149 bool QBarSeries::append(QList<QBarSet* > sets)
149 bool QBarSeries::append(QList<QBarSet* > sets)
150 {
150 {
151 Q_D(QBarSeries);
151 Q_D(QBarSeries);
152 return d->append(sets);
152 return d->append(sets);
153 }
153 }
154
154
155 /*!
155 /*!
156 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
156 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
157 */
157 */
158 bool QBarSeries::remove(QList<QBarSet* > sets)
158 bool QBarSeries::remove(QList<QBarSet* > sets)
159 {
159 {
160 Q_D(QBarSeries);
160 Q_D(QBarSeries);
161 return d->remove(sets);
161 return d->remove(sets);
162 }
162 }
163
163
164 void QBarSeries::clear()
165 {
166 Q_D(QBarSeries);
167 d->m_barSets.clear();
168 d->m_categories.clear();
169 }
170
164 /*!
171 /*!
165 Returns number of sets in series.
172 Returns number of sets in series.
166 */
173 */
167 int QBarSeries::barsetCount() const
174 int QBarSeries::barsetCount() const
168 {
175 {
169 Q_D(const QBarSeries);
176 Q_D(const QBarSeries);
170 return d->m_barSets.count();
177 return d->m_barSets.count();
171 }
178 }
172
179
173 /*!
180 /*!
174 Returns number of categories in series
181 Returns number of categories in series
175 */
182 */
176 int QBarSeries::categoryCount() const
183 int QBarSeries::categoryCount() const
177 {
184 {
178 Q_D(const QBarSeries);
185 Q_D(const QBarSeries);
179 return d->categoryCount();
186 return d->categoryCount();
180 }
187 }
181
188
182 /*!
189 /*!
183 Returns a list of sets in series. Keeps ownership of sets.
190 Returns a list of sets in series. Keeps ownership of sets.
184 */
191 */
185 QList<QBarSet*> QBarSeries::barSets() const
192 QList<QBarSet*> QBarSeries::barSets() const
186 {
193 {
187 Q_D(const QBarSeries);
194 Q_D(const QBarSeries);
188 return d->m_barSets;
195 return d->m_barSets;
189 }
196 }
190
197
191 /*!
198 /*!
192 Returns the bar categories of the series.
199 Returns the bar categories of the series.
193 */
200 */
194 QBarCategories QBarSeries::categories() const
201 QBarCategories QBarSeries::categories() const
195 {
202 {
196 Q_D(const QBarSeries);
203 Q_D(const QBarSeries);
197 return d->categories();
204 return d->categories();
198 }
205 }
199
206
200 void QBarSeries::setVisible(bool visible)
207 void QBarSeries::setVisible(bool visible)
201 {
208 {
202 Q_D(QBarSeries);
209 Q_D(QBarSeries);
203 d->setVisible(visible);
210 d->setVisible(visible);
204 }
211 }
205
212
206 bool QBarSeries::isVisible() const
213 bool QBarSeries::isVisible() const
207 {
214 {
208 Q_D(const QBarSeries);
215 Q_D(const QBarSeries);
209 return d->isVisible();
216 return d->isVisible();
210 }
217 }
211
218
212 /*!
219 /*!
213 Sets the visibility of labels in series to \a visible
220 Sets the visibility of labels in series to \a visible
214 */
221 */
215 void QBarSeries::setLabelsVisible(bool visible)
222 void QBarSeries::setLabelsVisible(bool visible)
216 {
223 {
217 Q_D(QBarSeries);
224 Q_D(QBarSeries);
218 if (d->m_labelsVisible != visible) {
225 if (d->m_labelsVisible != visible) {
219 d->m_labelsVisible = visible;
226 d->m_labelsVisible = visible;
220 emit d->updatedBars();
227 emit d->updatedBars();
221 }
228 }
222 }
229 }
223
230
224 bool QBarSeries::isLabelsVisible() const
231 bool QBarSeries::isLabelsVisible() const
225 {
232 {
226 Q_D(const QBarSeries);
233 Q_D(const QBarSeries);
227 return d->m_labelsVisible;
234 return d->m_labelsVisible;
228 }
235 }
229
236
230 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231
238
232 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
239 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
233 QAbstractSeriesPrivate(q),
240 QAbstractSeriesPrivate(q),
234 m_barMargin(0.5), // Default value is 50% of category width
241 m_barMargin(0.5), // Default value is 50% of category width
235 m_labelsVisible(false),
242 m_labelsVisible(false),
236 m_visible(true)
243 m_visible(true)
237 {
244 {
238 }
245 }
239
246
240 void QBarSeriesPrivate::setCategories(QBarCategories categories)
247 void QBarSeriesPrivate::setCategories(QBarCategories categories)
241 {
248 {
242 m_categories = categories;
249 m_categories = categories;
243 }
250 }
244
251
245 void QBarSeriesPrivate::insertCategory(int index, const QString category)
252 void QBarSeriesPrivate::insertCategory(int index, const QString category)
246 {
253 {
247 m_categories.insert(index, category);
254 m_categories.insert(index, category);
248 emit categoriesUpdated();
255 emit categoriesUpdated();
249 }
256 }
250
257
251 void QBarSeriesPrivate::removeCategory(int index)
258 void QBarSeriesPrivate::removeCategory(int index)
252 {
259 {
253 m_categories.removeAt(index);
260 m_categories.removeAt(index);
254 emit categoriesUpdated();
261 emit categoriesUpdated();
255 }
262 }
256
263
257 int QBarSeriesPrivate::categoryCount() const
264 int QBarSeriesPrivate::categoryCount() const
258 {
265 {
259 if (m_categories.count() > 0) {
266 if (m_categories.count() > 0) {
260 return m_categories.count();
267 return m_categories.count();
261 }
268 }
262
269
263 // No categories defined. return count of longest set.
270 // No categories defined. return count of longest set.
264 int count = 0;
271 int count = 0;
265 for (int i=0; i<m_barSets.count(); i++) {
272 for (int i=0; i<m_barSets.count(); i++) {
266 if (m_barSets.at(i)->count() > count) {
273 if (m_barSets.at(i)->count() > count) {
267 count = m_barSets.at(i)->count();
274 count = m_barSets.at(i)->count();
268 }
275 }
269 }
276 }
270
277
271 return count;
278 return count;
272 }
279 }
273
280
274 QBarCategories QBarSeriesPrivate::categories() const
281 QBarCategories QBarSeriesPrivate::categories() const
275 {
282 {
276 if (m_categories.count() > 0) {
283 if (m_categories.count() > 0) {
277 return m_categories;
284 return m_categories;
278 }
285 }
279
286
280 // No categories defined. retun list of indices.
287 // No categories defined. retun list of indices.
281 QBarCategories categories;
288 QBarCategories categories;
282
289
283 int count = categoryCount();
290 int count = categoryCount();
284 for (int i = 0; i < count; i++) {
291 for (int i = 0; i < count; i++) {
285 categories.append(QString::number(i));
292 categories.append(QString::number(i));
286 }
293 }
287 return categories;
294 return categories;
288 }
295 }
289
296
290 void QBarSeriesPrivate::setBarMargin(qreal margin)
297 void QBarSeriesPrivate::setBarMargin(qreal margin)
291 {
298 {
292 if (margin > 1.0) {
299 if (margin > 1.0) {
293 margin = 1.0;
300 margin = 1.0;
294 } else if (margin < 0.0) {
301 } else if (margin < 0.0) {
295 margin = 0.0;
302 margin = 0.0;
296 }
303 }
297
304
298 m_barMargin = margin;
305 m_barMargin = margin;
299 emit updatedBars();
306 emit updatedBars();
300 }
307 }
301
308
302 qreal QBarSeriesPrivate::barMargin() const
309 qreal QBarSeriesPrivate::barMargin() const
303 {
310 {
304 return m_barMargin;
311 return m_barMargin;
305 }
312 }
306
313
307 QBarSet* QBarSeriesPrivate::barsetAt(int index)
314 QBarSet* QBarSeriesPrivate::barsetAt(int index)
308 {
315 {
309 return m_barSets.at(index);
316 return m_barSets.at(index);
310 }
317 }
311
318
312 void QBarSeriesPrivate::setVisible(bool visible)
319 void QBarSeriesPrivate::setVisible(bool visible)
313 {
320 {
314 if (m_visible != visible) {
321 if (m_visible != visible) {
315 m_visible = visible;
322 m_visible = visible;
316 emit updatedBars();
323 emit updatedBars();
317 }
324 }
318 }
325 }
319
326
320 bool QBarSeriesPrivate::isVisible() const
327 bool QBarSeriesPrivate::isVisible() const
321 {
328 {
322 return m_visible;
329 return m_visible;
323 }
330 }
324
331
325 QString QBarSeriesPrivate::categoryName(int category)
332 QString QBarSeriesPrivate::categoryName(int category)
326 {
333 {
327 if ((category >= 0) && (category < m_categories.count())) {
334 if ((category >= 0) && (category < m_categories.count())) {
328 return m_categories.at(category);
335 return m_categories.at(category);
329 }
336 }
330
337
331 return QString::number(category);
338 return QString::number(category);
332 }
339 }
333
340
334 qreal QBarSeriesPrivate::min()
341 qreal QBarSeriesPrivate::min()
335 {
342 {
336 if (m_barSets.count() <= 0) {
343 if (m_barSets.count() <= 0) {
337 return 0;
344 return 0;
338 }
345 }
339 qreal min = INT_MAX;
346 qreal min = INT_MAX;
340
347
341 for (int i = 0; i < m_barSets.count(); i++) {
348 for (int i = 0; i < m_barSets.count(); i++) {
342 int categoryCount = m_barSets.at(i)->count();
349 int categoryCount = m_barSets.at(i)->count();
343 for (int j = 0; j < categoryCount; j++) {
350 for (int j = 0; j < categoryCount; j++) {
344 qreal temp = m_barSets.at(i)->at(j).y();
351 qreal temp = m_barSets.at(i)->at(j).y();
345 if (temp < min)
352 if (temp < min)
346 min = temp;
353 min = temp;
347 }
354 }
348 }
355 }
349 return min;
356 return min;
350 }
357 }
351
358
352 qreal QBarSeriesPrivate::max()
359 qreal QBarSeriesPrivate::max()
353 {
360 {
354 if (m_barSets.count() <= 0) {
361 if (m_barSets.count() <= 0) {
355 return 0;
362 return 0;
356 }
363 }
357 qreal max = INT_MIN;
364 qreal max = INT_MIN;
358
365
359 for (int i = 0; i < m_barSets.count(); i++) {
366 for (int i = 0; i < m_barSets.count(); i++) {
360 int categoryCount = m_barSets.at(i)->count();
367 int categoryCount = m_barSets.at(i)->count();
361 for (int j = 0; j < categoryCount; j++) {
368 for (int j = 0; j < categoryCount; j++) {
362 qreal temp = m_barSets.at(i)->at(j).y();
369 qreal temp = m_barSets.at(i)->at(j).y();
363 if (temp > max)
370 if (temp > max)
364 max = temp;
371 max = temp;
365 }
372 }
366 }
373 }
367
374
368 return max;
375 return max;
369 }
376 }
370
377
371 qreal QBarSeriesPrivate::valueAt(int set, int category)
378 qreal QBarSeriesPrivate::valueAt(int set, int category)
372 {
379 {
373 if ((set < 0) || (set >= m_barSets.count())) {
380 if ((set < 0) || (set >= m_barSets.count())) {
374 // No set, no value.
381 // No set, no value.
375 return 0;
382 return 0;
376 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
383 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
377 // No category, no value.
384 // No category, no value.
378 return 0;
385 return 0;
379 }
386 }
380
387
381 return m_barSets.at(set)->at(category).y();
388 return m_barSets.at(set)->at(category).y();
382 }
389 }
383
390
384 qreal QBarSeriesPrivate::percentageAt(int set, int category)
391 qreal QBarSeriesPrivate::percentageAt(int set, int category)
385 {
392 {
386 if ((set < 0) || (set >= m_barSets.count())) {
393 if ((set < 0) || (set >= m_barSets.count())) {
387 // No set, no value.
394 // No set, no value.
388 return 0;
395 return 0;
389 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
396 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
390 // No category, no value.
397 // No category, no value.
391 return 0;
398 return 0;
392 }
399 }
393
400
394 qreal value = m_barSets.at(set)->at(category).y();
401 qreal value = m_barSets.at(set)->at(category).y();
395 qreal sum = categorySum(category);
402 qreal sum = categorySum(category);
396 if ( qFuzzyIsNull(sum) ) {
403 if ( qFuzzyIsNull(sum) ) {
397 return 0;
404 return 0;
398 }
405 }
399
406
400 return value / sum;
407 return value / sum;
401 }
408 }
402
409
403 qreal QBarSeriesPrivate::categorySum(int category)
410 qreal QBarSeriesPrivate::categorySum(int category)
404 {
411 {
405 qreal sum(0);
412 qreal sum(0);
406 int count = m_barSets.count(); // Count sets
413 int count = m_barSets.count(); // Count sets
407 for (int set = 0; set < count; set++) {
414 for (int set = 0; set < count; set++) {
408 if (category < m_barSets.at(set)->count())
415 if (category < m_barSets.at(set)->count())
409 sum += m_barSets.at(set)->at(category).y();
416 sum += m_barSets.at(set)->at(category).y();
410 }
417 }
411 return sum;
418 return sum;
412 }
419 }
413
420
414 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
421 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
415 {
422 {
416 qreal sum(0);
423 qreal sum(0);
417 int count = m_barSets.count(); // Count sets
424 int count = m_barSets.count(); // Count sets
418 for (int set = 0; set < count; set++) {
425 for (int set = 0; set < count; set++) {
419 if (category < m_barSets.at(set)->count())
426 if (category < m_barSets.at(set)->count())
420 sum += qAbs(m_barSets.at(set)->at(category).y());
427 sum += qAbs(m_barSets.at(set)->at(category).y());
421 }
428 }
422 return sum;
429 return sum;
423 }
430 }
424
431
425 qreal QBarSeriesPrivate::maxCategorySum()
432 qreal QBarSeriesPrivate::maxCategorySum()
426 {
433 {
427 qreal max = INT_MIN;
434 qreal max = INT_MIN;
428 int count = categoryCount();
435 int count = categoryCount();
429 for (int i = 0; i < count; i++) {
436 for (int i = 0; i < count; i++) {
430 qreal sum = categorySum(i);
437 qreal sum = categorySum(i);
431 if (sum > max)
438 if (sum > max)
432 max = sum;
439 max = sum;
433 }
440 }
434 return max;
441 return max;
435 }
442 }
436
443
437 void QBarSeriesPrivate::barsetChanged()
444 void QBarSeriesPrivate::barsetChanged()
438 {
445 {
439 emit updatedBars();
446 emit updatedBars();
440 }
447 }
441
448
442 void QBarSeriesPrivate::scaleDomain(Domain& domain)
449 void QBarSeriesPrivate::scaleDomain(Domain& domain)
443 {
450 {
444 qreal minX(domain.minX());
451 qreal minX(domain.minX());
445 qreal minY(domain.minY());
452 qreal minY(domain.minY());
446 qreal maxX(domain.maxX());
453 qreal maxX(domain.maxX());
447 qreal maxY(domain.maxY());
454 qreal maxY(domain.maxY());
448 int tickXCount(domain.tickXCount());
455 int tickXCount(domain.tickXCount());
449 int tickYCount(domain.tickYCount());
456 int tickYCount(domain.tickYCount());
450
457
451 qreal x = categoryCount();
458 qreal x = categoryCount();
452 qreal y = max();
459 qreal y = max();
453 minX = qMin(minX, x) - 0.5;
460 minX = qMin(minX, x) - 0.5;
454 minY = qMin(minY, y);
461 minY = qMin(minY, y);
455 maxX = qMax(maxX, x) - 0.5;
462 maxX = qMax(maxX, x) - 0.5;
456 maxY = qMax(maxY, y);
463 maxY = qMax(maxY, y);
457 tickXCount = x+1;
464 tickXCount = x+1;
458
465
459 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
466 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
460 }
467 }
461
468
462 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
469 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
463 {
470 {
464 Q_Q(QBarSeries);
471 Q_Q(QBarSeries);
465
472
466 BarChartItem* bar = new BarChartItem(q,presenter);
473 BarChartItem* bar = new BarChartItem(q,presenter);
467 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
474 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
468 presenter->animator()->addAnimation(bar);
475 presenter->animator()->addAnimation(bar);
469 }
476 }
470 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
477 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
471 return bar;
478 return bar;
472
479
473 }
480 }
474
481
475 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
482 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
476 {
483 {
477 Q_Q(QBarSeries);
484 Q_Q(QBarSeries);
478 QList<LegendMarker*> markers;
485 QList<LegendMarker*> markers;
479 foreach(QBarSet* set, q->barSets()) {
486 foreach(QBarSet* set, q->barSets()) {
480 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
487 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
481 markers << marker;
488 markers << marker;
482 }
489 }
483
490
484 return markers;
491 return markers;
485 }
492 }
486
493
487 bool QBarSeriesPrivate::append(QBarSet *set)
494 bool QBarSeriesPrivate::append(QBarSet *set)
488 {
495 {
489 Q_Q(QBarSeries);
496 Q_Q(QBarSeries);
490 if ((m_barSets.contains(set)) || (set == 0)) {
497 if ((m_barSets.contains(set)) || (set == 0)) {
491 // Fail if set is already in list or set is null.
498 // Fail if set is already in list or set is null.
492 return false;
499 return false;
493 }
500 }
494 m_barSets.append(set);
501 m_barSets.append(set);
495 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
502 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
496 if (m_dataset) {
503 if (m_dataset) {
497 m_dataset->updateSeries(q); // this notifies legend
504 m_dataset->updateSeries(q); // this notifies legend
498 }
505 }
499 emit restructuredBars(); // this notifies barchartitem
506 emit restructuredBars(); // this notifies barchartitem
500 return true;
507 return true;
501 }
508 }
502
509
503 bool QBarSeriesPrivate::remove(QBarSet *set)
510 bool QBarSeriesPrivate::remove(QBarSet *set)
504 {
511 {
505 Q_Q(QBarSeries);
512 Q_Q(QBarSeries);
506 if (!m_barSets.contains(set)) {
513 if (!m_barSets.contains(set)) {
507 // Fail if set is not in list
514 // Fail if set is not in list
508 return false;
515 return false;
509 }
516 }
510 m_barSets.removeOne(set);
517 m_barSets.removeOne(set);
511 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
518 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
512 if (m_dataset) {
519 if (m_dataset) {
513 m_dataset->updateSeries(q); // this notifies legend
520 m_dataset->updateSeries(q); // this notifies legend
514 }
521 }
515 emit restructuredBars(); // this notifies barchartitem
522 emit restructuredBars(); // this notifies barchartitem
516 return true;
523 return true;
517 }
524 }
518
525
519 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
526 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
520 {
527 {
521 Q_Q(QBarSeries);
528 Q_Q(QBarSeries);
522 foreach (QBarSet* set, sets) {
529 foreach (QBarSet* set, sets) {
523 if ((set == 0) || (m_barSets.contains(set))) {
530 if ((set == 0) || (m_barSets.contains(set))) {
524 // Fail if any of the sets is null or is already appended.
531 // Fail if any of the sets is null or is already appended.
525 return false;
532 return false;
526 }
533 }
527 if (sets.count(set) != 1) {
534 if (sets.count(set) != 1) {
528 // Also fail if same set is more than once in given list.
535 // Also fail if same set is more than once in given list.
529 return false;
536 return false;
530 }
537 }
531 }
538 }
532
539
533 foreach (QBarSet* set, sets) {
540 foreach (QBarSet* set, sets) {
534 m_barSets.append(set);
541 m_barSets.append(set);
535 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
542 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
536 }
543 }
537 if (m_dataset) {
544 if (m_dataset) {
538 m_dataset->updateSeries(q); // this notifies legend
545 m_dataset->updateSeries(q); // this notifies legend
539 }
546 }
540 emit restructuredBars(); // this notifies barchartitem
547 emit restructuredBars(); // this notifies barchartitem
541 return true;
548 return true;
542 }
549 }
543
550
544 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
551 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
545 {
552 {
546 Q_Q(QBarSeries);
553 Q_Q(QBarSeries);
547 bool setsRemoved = false;
554 bool setsRemoved = false;
548 foreach (QBarSet* set, sets) {
555 foreach (QBarSet* set, sets) {
549 if (m_barSets.contains(set)) {
556 if (m_barSets.contains(set)) {
550 m_barSets.removeOne(set);
557 m_barSets.removeOne(set);
551 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
558 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
552 setsRemoved = true;
559 setsRemoved = true;
553 }
560 }
554 }
561 }
555
562
556 if (setsRemoved) {
563 if (setsRemoved) {
557 if (m_dataset) {
564 if (m_dataset) {
558 m_dataset->updateSeries(q); // this notifies legend
565 m_dataset->updateSeries(q); // this notifies legend
559 }
566 }
560 emit restructuredBars(); // this notifies barchartitem
567 emit restructuredBars(); // this notifies barchartitem
561 }
568 }
562 return setsRemoved;
569 return setsRemoved;
563 }
570 }
564
571
565 #include "moc_qbarseries.cpp"
572 #include "moc_qbarseries.cpp"
566 #include "moc_qbarseries_p.cpp"
573 #include "moc_qbarseries_p.cpp"
567
574
568 QTCOMMERCIALCHART_END_NAMESPACE
575 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,80 +1,81
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 BARSERIES_H
21 #ifndef BARSERIES_H
22 #define BARSERIES_H
22 #define BARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 typedef QStringList QBarCategories;
29 typedef QStringList QBarCategories;
30
30
31 class QBarSet;
31 class QBarSet;
32 class BarCategory;
32 class BarCategory;
33 class QBarSeriesPrivate;
33 class QBarSeriesPrivate;
34
34
35 // Container for series
35 // Container for series
36 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
36 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 public:
39 public:
40 explicit QBarSeries(QObject *parent = 0);
40 explicit QBarSeries(QObject *parent = 0);
41 virtual ~QBarSeries();
41 virtual ~QBarSeries();
42
42
43 QAbstractSeries::SeriesType type() const;
43 QAbstractSeries::SeriesType type() const;
44 void setCategories(QBarCategories categories);
44 void setCategories(QBarCategories categories);
45
45
46 void setBarMargin(qreal margin);
46 void setBarMargin(qreal margin);
47 qreal barMargin() const;
47 qreal barMargin() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
53 int barsetCount() const;
53 int barsetCount() const;
54 int categoryCount() const;
54 int categoryCount() const;
55 QList<QBarSet*> barSets() const;
55 QList<QBarSet*> barSets() const;
56 QBarCategories categories() const;
56 QBarCategories categories() const;
57 void clear();
57
58
58 void setVisible(bool visible = true);
59 void setVisible(bool visible = true);
59 bool isVisible() const;
60 bool isVisible() const;
60 void setLabelsVisible(bool visible = true);
61 void setLabelsVisible(bool visible = true);
61 bool isLabelsVisible() const;
62 bool isLabelsVisible() const;
62
63
63 protected:
64 protected:
64 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
65 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
65
66
66 Q_SIGNALS:
67 Q_SIGNALS:
67 void clicked(QBarSet *barset, QString category);
68 void clicked(QBarSet *barset, QString category);
68 void hovered(QBarSet* barset, bool status);
69 void hovered(QBarSet* barset, bool status);
69
70
70 protected:
71 protected:
71 Q_DECLARE_PRIVATE(QBarSeries)
72 Q_DECLARE_PRIVATE(QBarSeries)
72 friend class BarChartItem;
73 friend class BarChartItem;
73 friend class PercentBarChartItem;
74 friend class PercentBarChartItem;
74 friend class StackedBarChartItem;
75 friend class StackedBarChartItem;
75 friend class GroupedBarChartItem;
76 friend class GroupedBarChartItem;
76 };
77 };
77
78
78 QTCOMMERCIALCHART_END_NAMESPACE
79 QTCOMMERCIALCHART_END_NAMESPACE
79
80
80 #endif // BARSERIES_H
81 #endif // BARSERIES_H
@@ -1,424 +1,424
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 oldPoint = m_series->points().at(index.row() - m_first);
259 newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal());
259 newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal());
260 newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal());
260 newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal());
261 }
261 }
262 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
262 } 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)) {
263 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
264 oldPoint = m_series->points().at(index.column() - m_first);
264 oldPoint = m_series->points().at(index.column() - m_first);
265 newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal());
265 newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal());
266 newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal());
266 newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal());
267 }
267 }
268 } else {
268 } else {
269 continue;
269 continue;
270 }
270 }
271 m_series->replace(oldPoint, newPoint);
271 m_series->replace(oldPoint, newPoint);
272 }
272 }
273 blockSeriesSignals(false);
274 }
273 }
274 blockSeriesSignals(false);
275 }
275 }
276
276
277 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
277 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
278 {
278 {
279 Q_UNUSED(parent);
279 Q_UNUSED(parent);
280 if (m_modelSignalsBlock)
280 if (m_modelSignalsBlock)
281 return;
281 return;
282
282
283 blockSeriesSignals();
283 blockSeriesSignals();
284 if (m_orientation == Qt::Vertical)
284 if (m_orientation == Qt::Vertical)
285 insertData(start, end);
285 insertData(start, end);
286 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
286 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
287 initializeXYFromModel();
287 initializeXYFromModel();
288 blockSeriesSignals(false);
288 blockSeriesSignals(false);
289 }
289 }
290
290
291 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
291 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
292 {
292 {
293 Q_UNUSED(parent);
293 Q_UNUSED(parent);
294 if (m_modelSignalsBlock)
294 if (m_modelSignalsBlock)
295 return;
295 return;
296
296
297 blockSeriesSignals();
297 blockSeriesSignals();
298 if (m_orientation == Qt::Vertical)
298 if (m_orientation == Qt::Vertical)
299 removeData(start, end);
299 removeData(start, end);
300 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
300 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
301 initializeXYFromModel();
301 initializeXYFromModel();
302 blockSeriesSignals(false);
302 blockSeriesSignals(false);
303 }
303 }
304
304
305 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
305 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
306 {
306 {
307 Q_UNUSED(parent);
307 Q_UNUSED(parent);
308 if (m_modelSignalsBlock)
308 if (m_modelSignalsBlock)
309 return;
309 return;
310
310
311 blockSeriesSignals();
311 blockSeriesSignals();
312 if (m_orientation == Qt::Horizontal)
312 if (m_orientation == Qt::Horizontal)
313 insertData(start, end);
313 insertData(start, end);
314 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
314 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
315 initializeXYFromModel();
315 initializeXYFromModel();
316 blockSeriesSignals(false);
316 blockSeriesSignals(false);
317 }
317 }
318
318
319 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
319 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
320 {
320 {
321 Q_UNUSED(parent);
321 Q_UNUSED(parent);
322 if (m_modelSignalsBlock)
322 if (m_modelSignalsBlock)
323 return;
323 return;
324
324
325 blockSeriesSignals();
325 blockSeriesSignals();
326 if (m_orientation == Qt::Horizontal)
326 if (m_orientation == Qt::Horizontal)
327 removeData(start, end);
327 removeData(start, end);
328 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
328 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
329 initializeXYFromModel();
329 initializeXYFromModel();
330 blockSeriesSignals(false);
330 blockSeriesSignals(false);
331 }
331 }
332
332
333 void QXYModelMapperPrivate::insertData(int start, int end)
333 void QXYModelMapperPrivate::insertData(int start, int end)
334 {
334 {
335 if (m_model == 0 || m_series == 0)
335 if (m_model == 0 || m_series == 0)
336 return;
336 return;
337
337
338 if (m_count != -1 && start >= m_first + m_count) {
338 if (m_count != -1 && start >= m_first + m_count) {
339 return;
339 return;
340 } else {
340 } else {
341 int addedCount = end - start + 1;
341 int addedCount = end - start + 1;
342 if (m_count != -1 && addedCount > m_count)
342 if (m_count != -1 && addedCount > m_count)
343 addedCount = m_count;
343 addedCount = m_count;
344 int first = qMax(start, m_first);
344 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);
345 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++) {
346 for (int i = first; i <= last; i++) {
347 QPointF point;
347 QPointF point;
348 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
348 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
349 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
349 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
350 m_series->insert(i - m_first, point);
350 m_series->insert(i - m_first, point);
351 }
351 }
352
352
353 // remove excess of slices (abouve m_count)
353 // remove excess of slices (abouve m_count)
354 if (m_count != -1 && m_series->points().size() > m_count)
354 if (m_count != -1 && m_series->points().size() > m_count)
355 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
355 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
356 m_series->remove(m_series->points().at(i));
356 m_series->remove(m_series->points().at(i));
357 }
357 }
358 }
358 }
359 }
359 }
360
360
361 void QXYModelMapperPrivate::removeData(int start, int end)
361 void QXYModelMapperPrivate::removeData(int start, int end)
362 {
362 {
363 if (m_model == 0 || m_series == 0)
363 if (m_model == 0 || m_series == 0)
364 return;
364 return;
365
365
366 int removedCount = end - start + 1;
366 int removedCount = end - start + 1;
367 if (m_count != -1 && start >= m_first + m_count) {
367 if (m_count != -1 && start >= m_first + m_count) {
368 return;
368 return;
369 } else {
369 } else {
370 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
370 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.
371 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.
372 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--) {
373 for (int i = last; i >= first; i--) {
374 m_series->remove(m_series->points().at(i - m_first));
374 m_series->remove(m_series->points().at(i - m_first));
375 }
375 }
376
376
377 if (m_count != -1) {
377 if (m_count != -1) {
378 int itemsAvailable; // check how many are available to be added
378 int itemsAvailable; // check how many are available to be added
379 if (m_orientation == Qt::Vertical)
379 if (m_orientation == Qt::Vertical)
380 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
380 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
381 else
381 else
382 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
382 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.
383 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();
384 int currentSize = m_series->count();
385 if (toBeAdded > 0)
385 if (toBeAdded > 0)
386 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
386 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
387 QPointF point;
387 QPointF point;
388 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
388 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
389 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
389 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
390 m_series->insert(i, point);
390 m_series->insert(i, point);
391 }
391 }
392 }
392 }
393 }
393 }
394 }
394 }
395
395
396 void QXYModelMapperPrivate::initializeXYFromModel()
396 void QXYModelMapperPrivate::initializeXYFromModel()
397 {
397 {
398 if (m_model == 0 || m_series == 0)
398 if (m_model == 0 || m_series == 0)
399 return;
399 return;
400
400
401 blockSeriesSignals();
401 blockSeriesSignals();
402 // clear current content
402 // clear current content
403 m_series->clear();
403 m_series->clear();
404
404
405 // create the initial slices set
405 // create the initial slices set
406 int pointPos = 0;
406 int pointPos = 0;
407 QModelIndex xIndex = xModelIndex(pointPos);
407 QModelIndex xIndex = xModelIndex(pointPos);
408 QModelIndex yIndex = yModelIndex(pointPos);
408 QModelIndex yIndex = yModelIndex(pointPos);
409 while (xIndex.isValid() && yIndex.isValid()) {
409 while (xIndex.isValid() && yIndex.isValid()) {
410 QPointF point;
410 QPointF point;
411 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
411 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
412 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
412 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
413 m_series->append(point);
413 m_series->append(point);
414 pointPos++;
414 pointPos++;
415 xIndex = xModelIndex(pointPos);
415 xIndex = xModelIndex(pointPos);
416 yIndex = yModelIndex(pointPos);
416 yIndex = yModelIndex(pointPos);
417 }
417 }
418 blockSeriesSignals(false);
418 blockSeriesSignals(false);
419 }
419 }
420
420
421 #include "moc_qxymodelmapper.cpp"
421 #include "moc_qxymodelmapper.cpp"
422 #include "moc_qxymodelmapper_p.cpp"
422 #include "moc_qxymodelmapper_p.cpp"
423
423
424 QTCOMMERCIALCHART_END_NAMESPACE
424 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,573 +1,573
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 "customtablemodel.h"
30 #include "customtablemodel.h"
31 #include <QPieSeries>
31 #include <QPieSeries>
32 #include <QVPieModelMapper>
32 #include <QVPieModelMapper>
33 #include <QPieSlice>
33 #include <QPieSlice>
34 #include <QAreaSeries>
34 #include <QAreaSeries>
35 #include <QBarSeries>
35 #include <QBarSeries>
36 #include <QGroupedBarSeries>
36 #include <QGroupedBarSeries>
37 #include <QBarSet>
37 #include <QBarSet>
38 #include <QVBarModelMapper>
38 #include <QVBarModelMapper>
39 #include <QPushButton>
39 #include <QPushButton>
40 #include <QRadioButton>
40 #include <QRadioButton>
41 #include <QLabel>
41 #include <QLabel>
42 #include <QSpinBox>
42 #include <QSpinBox>
43 #include <QTime>
43 #include <QTime>
44 #include <QHeaderView>
44 #include <QHeaderView>
45
45
46 TableWidget::TableWidget(QWidget *parent)
46 TableWidget::TableWidget(QWidget *parent)
47 : QWidget(parent),
47 : QWidget(parent),
48 m_series(0),
48 m_series(0),
49 m_mapper(0),
49 m_mapper(0),
50 m_model(0),
50 m_model(0),
51 m_pieMapper(0),
51 m_pieMapper(0),
52 m_pieMapper2(0)
52 m_pieMapper2(0)
53 // specialPie(0)
53 // specialPie(0)
54 {
54 {
55 setGeometry(1900, 100, 1000, 600);
55 setGeometry(1900, 100, 1000, 600);
56 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
56 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
57 // create simple model for storing data
57 // create simple model for storing data
58 // user's table data model
58 // user's table data model
59 m_model = new CustomTableModel;
59 m_model = new CustomTableModel;
60 m_tableView = new QTableView;
60 m_tableView = new QTableView;
61 m_tableView->setModel(m_model);
61 m_tableView->setModel(m_model);
62 // m_tableView->setMinimumHeight(300);
62 // m_tableView->setMinimumHeight(300);
63 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
63 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
64 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
64 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
65
65
66 m_chart = new QChart;
66 m_chart = new QChart;
67 m_chart->legend()->setVisible(true);
67 m_chart->legend()->setVisible(true);
68 m_chart->setAnimationOptions(QChart::SeriesAnimations);
68 m_chart->setAnimationOptions(QChart::SeriesAnimations);
69 m_chartView = new QChartView(m_chart);
69 m_chartView = new QChartView(m_chart);
70 m_chartView->setRenderHint(QPainter::Antialiasing);
70 m_chartView->setRenderHint(QPainter::Antialiasing);
71 m_chartView->setMinimumSize(640, 480);
71 m_chartView->setMinimumSize(640, 480);
72
72
73 // add, remove data buttons
73 // add, remove data buttons
74 QPushButton* addRowAboveButton = new QPushButton("Add row above");
74 QPushButton* addRowAboveButton = new QPushButton("Add row above");
75 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
75 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
76
76
77 QPushButton* addRowBelowButton = new QPushButton("Add row below");
77 QPushButton* addRowBelowButton = new QPushButton("Add row below");
78 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
78 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
79
79
80 QPushButton* removeRowButton = new QPushButton("Remove row");
80 QPushButton* removeRowButton = new QPushButton("Remove row");
81 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
81 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
82
82
83 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
83 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
84 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
84 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
85
85
86 QPushButton* removeColumnButton = new QPushButton("Remove column");
86 QPushButton* removeColumnButton = new QPushButton("Remove column");
87 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
87 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
88
88
89 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
89 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
90 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
90 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
91
91
92 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
92 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
93 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
93 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
94
94
95 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
95 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
96 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
96 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
97
97
98 QPushButton* xyTestButton = new QPushButton("Append XY point");
98 QPushButton* xyTestButton = new QPushButton("Append XY point");
99 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
99 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
100
100
101
101
102 QLabel *spinBoxLabel = new QLabel("Rows affected:");
102 QLabel *spinBoxLabel = new QLabel("Rows affected:");
103
103
104 // spin box for setting number of affected items (add, remove)
104 // spin box for setting number of affected items (add, remove)
105 m_linesCountSpinBox = new QSpinBox;
105 m_linesCountSpinBox = new QSpinBox;
106 m_linesCountSpinBox->setRange(1, 10);
106 m_linesCountSpinBox->setRange(1, 10);
107 m_linesCountSpinBox->setValue(1);
107 m_linesCountSpinBox->setValue(1);
108
108
109 // buttons layout
109 // buttons layout
110 QVBoxLayout* buttonsLayout = new QVBoxLayout;
110 QVBoxLayout* buttonsLayout = new QVBoxLayout;
111 buttonsLayout->addWidget(spinBoxLabel);
111 buttonsLayout->addWidget(spinBoxLabel);
112 buttonsLayout->addWidget(m_linesCountSpinBox);
112 buttonsLayout->addWidget(m_linesCountSpinBox);
113 // buttonsLayout->addWidget(addRowAboveButton);
113 // buttonsLayout->addWidget(addRowAboveButton);
114 buttonsLayout->addWidget(addRowBelowButton);
114 buttonsLayout->addWidget(addRowBelowButton);
115 buttonsLayout->addWidget(removeRowButton);
115 buttonsLayout->addWidget(removeRowButton);
116 // buttonsLayout->addWidget(addColumnRightButton);
116 // buttonsLayout->addWidget(addColumnRightButton);
117 // buttonsLayout->addWidget(removeColumnButton);
117 // buttonsLayout->addWidget(removeColumnButton);
118 buttonsLayout->addWidget(specialPieButton);
118 buttonsLayout->addWidget(specialPieButton);
119 buttonsLayout->addWidget(specialPieButton2);
119 buttonsLayout->addWidget(specialPieButton2);
120 buttonsLayout->addWidget(specialPieButton3);
120 buttonsLayout->addWidget(specialPieButton3);
121 buttonsLayout->addWidget(xyTestButton);
121 buttonsLayout->addWidget(xyTestButton);
122 buttonsLayout->addStretch();
122 buttonsLayout->addStretch();
123
123
124 // chart type radio buttons
124 // chart type radio buttons
125 m_lineRadioButton = new QRadioButton("Line");
125 m_lineRadioButton = new QRadioButton("Line");
126 m_splineRadioButton = new QRadioButton("Spline");
126 m_splineRadioButton = new QRadioButton("Spline");
127 m_scatterRadioButton = new QRadioButton("Scatter");
127 m_scatterRadioButton = new QRadioButton("Scatter");
128 m_pieRadioButton = new QRadioButton("Pie");
128 m_pieRadioButton = new QRadioButton("Pie");
129 m_areaRadioButton = new QRadioButton("Area");
129 m_areaRadioButton = new QRadioButton("Area");
130 m_barRadioButton = new QRadioButton("Bar");
130 m_barRadioButton = new QRadioButton("Bar");
131
131
132 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
132 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
134 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 m_barRadioButton->setChecked(true);
138 m_barRadioButton->setChecked(true);
139
139
140 // radio buttons layout
140 // radio buttons layout
141 QVBoxLayout* radioLayout = new QVBoxLayout;
141 QVBoxLayout* radioLayout = new QVBoxLayout;
142 radioLayout->addWidget(m_lineRadioButton);
142 radioLayout->addWidget(m_lineRadioButton);
143 radioLayout->addWidget(m_splineRadioButton);
143 radioLayout->addWidget(m_splineRadioButton);
144 radioLayout->addWidget(m_scatterRadioButton);
144 radioLayout->addWidget(m_scatterRadioButton);
145 radioLayout->addWidget(m_pieRadioButton);
145 radioLayout->addWidget(m_pieRadioButton);
146 // radioLayout->addWidget(m_areaRadioButton);
146 // radioLayout->addWidget(m_areaRadioButton);
147 radioLayout->addWidget(m_barRadioButton);
147 radioLayout->addWidget(m_barRadioButton);
148 radioLayout->addStretch();
148 radioLayout->addStretch();
149
149
150 // create main layout
150 // create main layout
151 QGridLayout* mainLayout = new QGridLayout;
151 QGridLayout* mainLayout = new QGridLayout;
152 mainLayout->addLayout(buttonsLayout, 2, 0);
152 mainLayout->addLayout(buttonsLayout, 2, 0);
153 mainLayout->addLayout(radioLayout, 3, 0);
153 mainLayout->addLayout(radioLayout, 3, 0);
154 mainLayout->addWidget(m_tableView, 1, 0);
154 mainLayout->addWidget(m_tableView, 1, 0);
155 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
155 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
156 setLayout(mainLayout);
156 setLayout(mainLayout);
157 m_lineRadioButton->setFocus();
157 m_lineRadioButton->setFocus();
158 }
158 }
159
159
160 void TableWidget::addRowAbove()
160 void TableWidget::addRowAbove()
161 {
161 {
162 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
162 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
163
163
164 }
164 }
165
165
166 void TableWidget::addRowBelow()
166 void TableWidget::addRowBelow()
167 {
167 {
168 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
168 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
169
169
170 }
170 }
171
171
172 void TableWidget::removeRow()
172 void TableWidget::removeRow()
173 {
173 {
174 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
174 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
175 }
175 }
176
176
177 void TableWidget::addColumnRight()
177 void TableWidget::addColumnRight()
178 {
178 {
179 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
179 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
180 }
180 }
181
181
182 void TableWidget::removeColumn()
182 void TableWidget::removeColumn()
183 {
183 {
184 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
184 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
185 }
185 }
186
186
187 void TableWidget::updateChartType(bool toggle)
187 void TableWidget::updateChartType(bool toggle)
188 {
188 {
189 // this if is needed, so that the function is only called once.
189 // this if is needed, so that the function is only called once.
190 // For the radioButton that was enabled.
190 // For the radioButton that was enabled.
191 if (toggle) {
191 if (toggle) {
192 // specialPie = 0;
192 // specialPie = 0;
193 m_chart->removeAllSeries();
193 m_chart->removeAllSeries();
194 m_series = 0;
194 m_series = 0;
195 // m_chart->axisX()->setNiceNumbersEnabled(false);
195 // m_chart->axisX()->setNiceNumbersEnabled(false);
196 // m_chart->axisY()->setNiceNumbersEnabled(false);
196 // m_chart->axisY()->setNiceNumbersEnabled(false);
197 if (m_mapper) {
197 if (m_mapper) {
198 m_mapper->deleteLater();
198 m_mapper->deleteLater();
199 m_mapper = 0;
199 m_mapper = 0;
200 }
200 }
201
201
202 if (m_pieMapper) {
202 if (m_pieMapper) {
203 m_pieMapper->deleteLater();
203 m_pieMapper->deleteLater();
204 m_pieMapper = 0;
204 m_pieMapper = 0;
205 }
205 }
206
206
207 if (m_pieMapper2) {
207 if (m_pieMapper2) {
208 m_pieMapper2->deleteLater();
208 m_pieMapper2->deleteLater();
209 m_pieMapper2 = 0;
209 m_pieMapper2 = 0;
210 }
210 }
211
211
212 // if (m_series) {
212 // if (m_series) {
213 // delete m_series;
213 // delete m_series;
214 // m_series = 0;
214 // m_series = 0;
215 // }
215 // }
216
216
217 // renable axes of the chart (pie hides them)
217 // renable axes of the chart (pie hides them)
218 // x axis
218 // x axis
219 QAxis *axis = m_chart->axisX();
219 QAxis *axis = m_chart->axisX();
220 axis->setAxisVisible(true);
220 axis->setAxisVisible(true);
221 axis->setGridLineVisible(true);
221 axis->setGridLineVisible(true);
222 axis->setLabelsVisible(true);
222 axis->setLabelsVisible(true);
223
223
224 // y axis
224 // y axis
225 axis = m_chart->axisY();
225 axis = m_chart->axisY();
226 axis->setAxisVisible(true);
226 axis->setAxisVisible(true);
227 axis->setGridLineVisible(true);
227 axis->setGridLineVisible(true);
228 axis->setLabelsVisible(true);
228 axis->setLabelsVisible(true);
229
229
230 m_model->clearMapping();
230 m_model->clearMapping();
231
231
232 QString seriesColorHex = "#000000";
232 QString seriesColorHex = "#000000";
233 // QPen pen;
233 // QPen pen;
234 // pen.setWidth(2);
234 // pen.setWidth(2);
235
235
236 if (m_lineRadioButton->isChecked())
236 if (m_lineRadioButton->isChecked())
237 {
237 {
238 m_chart->setAnimationOptions(QChart::NoAnimation);
238 m_chart->setAnimationOptions(QChart::NoAnimation);
239
239
240 // series 1
240 // series 1
241 m_series = new QLineSeries;
241 m_series = new QLineSeries;
242
242
243 m_mapper = new QVXYModelMapper;
243 m_mapper = new QVXYModelMapper;
244 m_mapper->setModel(m_model);
244 m_mapper->setModel(m_model);
245 m_mapper->setSeries(m_series);
245 m_mapper->setSeries(m_series);
246 m_mapper->setXColumn(0);
246 m_mapper->setXColumn(0);
247 m_mapper->setYColumn(1);
247 m_mapper->setYColumn(1);
248 m_mapper->setFirst(3);
248 m_mapper->setFirst(3);
249 m_mapper->setCount(4);
249 m_mapper->setCount(4);
250
250
251 // m_series->setModelMapping(0,1, Qt::Vertical);
251 // m_series->setModelMapping(0,1, Qt::Vertical);
252 // m_series->setModelMappingRange(3, 4);
252 // m_series->setModelMappingRange(3, 4);
253 m_chart->addSeries(m_series);
253 m_chart->addSeries(m_series);
254 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
254 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
255 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
255 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
256
256
257 // // series 2
257 // // series 2
258 // m_series = new QLineSeries;
258 // m_series = new QLineSeries;
259 // m_series->setModel(m_model);
259 // m_series->setModel(m_model);
260
260
261 // mapper = new QXYModelMapper;
261 // mapper = new QXYModelMapper;
262 // mapper->setMapX(3);
262 // mapper->setMapX(3);
263 // mapper->setMapY(4);
263 // mapper->setMapY(4);
264 // // mapper->setFirst(3);
264 // // mapper->setFirst(3);
265 // // mapper->setCount(4);
265 // // mapper->setCount(4);
266 // m_series->setModelMapper(mapper);
266 // m_series->setModelMapper(mapper);
267 // // m_series->setModelMapping(2,3, Qt::Vertical);
267 // // m_series->setModelMapping(2,3, Qt::Vertical);
268 // m_chart->addSeries(m_series);
268 // m_chart->addSeries(m_series);
269 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
269 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
270 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
270 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
271
271
272 // // series 3
272 // // series 3
273 // m_series = new QLineSeries;
273 // m_series = new QLineSeries;
274 // m_series->setModel(m_model);
274 // m_series->setModel(m_model);
275
275
276 // mapper = new QXYModelMapper;
276 // mapper = new QXYModelMapper;
277 // mapper->setMapX(5);
277 // mapper->setMapX(5);
278 // mapper->setMapY(6);
278 // mapper->setMapY(6);
279 // mapper->setFirst(2);
279 // mapper->setFirst(2);
280 // mapper->setCount(-1);
280 // mapper->setCount(-1);
281 // m_series->setModelMapper(mapper);
281 // m_series->setModelMapper(mapper);
282 // // m_series->setModelMapping(4,5, Qt::Vertical);
282 // // m_series->setModelMapping(4,5, Qt::Vertical);
283 // // m_series->setModelMappingRange(2, -1);
283 // // m_series->setModelMappingRange(2, -1);
284 // m_chart->addSeries(m_series);
284 // m_chart->addSeries(m_series);
285 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
285 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
286 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
286 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
287 }
287 }
288 else if (m_splineRadioButton->isChecked())
288 else if (m_splineRadioButton->isChecked())
289 {
289 {
290 m_chart->setAnimationOptions(QChart::NoAnimation);
290 m_chart->setAnimationOptions(QChart::NoAnimation);
291
291
292 // series 1
292 // series 1
293 m_series = new QSplineSeries;
293 m_series = new QSplineSeries;
294 // m_series->setModel(m_model);
294 // m_series->setModel(m_model);
295
295
296 m_mapper = new QVXYModelMapper;
296 m_mapper = new QVXYModelMapper;
297 m_mapper->setSeries(m_series);
297 m_mapper->setSeries(m_series);
298 m_mapper->setModel(m_model);
298 m_mapper->setModel(m_model);
299 m_mapper->setXColumn(0);
299 m_mapper->setXColumn(0);
300 m_mapper->setYColumn(1);
300 m_mapper->setYColumn(1);
301 m_mapper->setFirst(0);
301 m_mapper->setFirst(0);
302 m_mapper->setCount(-1);
302 m_mapper->setCount(-1);
303
303
304 // m_series->setModelMapper(mapper);
304 // m_series->setModelMapper(mapper);
305
305
306 m_chart->addSeries(m_series);
306 m_chart->addSeries(m_series);
307 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
307 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
308 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
308 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
309
309
310 // // series 2
310 // // series 2
311 // m_series = new QSplineSeries;
311 // m_series = new QSplineSeries;
312 // m_series->setModel(m_model);
312 // m_series->setModel(m_model);
313
313
314 // mapper = new QXYModelMapper;
314 // mapper = new QXYModelMapper;
315 // mapper->setMapX(2);
315 // mapper->setMapX(2);
316 // mapper->setMapY(3);
316 // mapper->setMapY(3);
317 // mapper->setFirst(2);
317 // mapper->setFirst(2);
318 // mapper->setCount(4);
318 // mapper->setCount(4);
319
319
320 // m_series->setModelMapper(mapper);
320 // m_series->setModelMapper(mapper);
321
321
322 // m_chart->addSeries(m_series);
322 // m_chart->addSeries(m_series);
323 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
323 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
324 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
324 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
325
325
326 // // series 3
326 // // series 3
327 // m_series = new QSplineSeries;
327 // m_series = new QSplineSeries;
328 // m_series->setModel(m_model);
328 // m_series->setModel(m_model);
329
329
330 // mapper = new QXYModelMapper;
330 // mapper = new QXYModelMapper;
331 // mapper->setMapX(4);
331 // mapper->setMapX(4);
332 // mapper->setMapY(5);
332 // mapper->setMapY(5);
333 // mapper->setFirst(2);
333 // mapper->setFirst(2);
334 // mapper->setCount(-1);
334 // mapper->setCount(-1);
335
335
336 // m_series->setModelMapper(mapper);
336 // m_series->setModelMapper(mapper);
337
337
338 // m_chart->addSeries(m_series);
338 // m_chart->addSeries(m_series);
339 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
339 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
340 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
340 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
341 } else if (m_scatterRadioButton->isChecked())
341 } else if (m_scatterRadioButton->isChecked())
342 {
342 {
343 m_chart->setAnimationOptions(QChart::NoAnimation);
343 m_chart->setAnimationOptions(QChart::NoAnimation);
344
344
345 // series 1
345 // series 1
346 m_series = new QScatterSeries;
346 m_series = new QScatterSeries;
347
347
348 m_mapper = new QVXYModelMapper;
348 m_mapper = new QVXYModelMapper;
349 m_mapper->setSeries(m_series);
349 m_mapper->setSeries(m_series);
350 m_mapper->setModel(m_model);
350 m_mapper->setModel(m_model);
351 m_mapper->setXColumn(0);
351 m_mapper->setXColumn(0);
352 m_mapper->setYColumn(1);
352 m_mapper->setYColumn(1);
353 m_mapper->setFirst(0);
353 m_mapper->setFirst(0);
354 m_mapper->setCount(-1);
354 m_mapper->setCount(-1);
355
355
356 m_chart->addSeries(m_series);
356 m_chart->addSeries(m_series);
357 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
357 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
358 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
358 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
359
359
360 // // series 2
360 // // series 2
361 // m_series = new QScatterSeries;
361 // m_series = new QScatterSeries;
362 // m_series->setModel(m_model);
362 // m_series->setModel(m_model);
363 // m_series->setModelMapping(2,3, Qt::Vertical);
363 // m_series->setModelMapping(2,3, Qt::Vertical);
364 // // m_series->setModelMappingRange(1, 6);
364 // // m_series->setModelMappingRange(1, 6);
365 // // series->setModelMapping(2,3, Qt::Horizontal);
365 // // series->setModelMapping(2,3, Qt::Horizontal);
366 // m_chart->addSeries(m_series);
366 // m_chart->addSeries(m_series);
367
367
368 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
368 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
369 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
369 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
370
370
371 // // series 3
371 // // series 3
372 // m_series = new QScatterSeries;
372 // m_series = new QScatterSeries;
373 // m_series->setModel(m_model);
373 // m_series->setModel(m_model);
374 // m_series->setModelMapping(4,5, Qt::Vertical);
374 // m_series->setModelMapping(4,5, Qt::Vertical);
375 // // series->setModelMapping(4,5, Qt::Horizontal);
375 // // series->setModelMapping(4,5, Qt::Horizontal);
376 // m_chart->addSeries(m_series);
376 // m_chart->addSeries(m_series);
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(4, 0, 2, 1000));
378 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
379 } else if (m_pieRadioButton->isChecked()) {
379 } else if (m_pieRadioButton->isChecked()) {
380 m_chart->setAnimationOptions(QChart::SeriesAnimations);
380 m_chart->setAnimationOptions(QChart::SeriesAnimations);
381
381
382 // pie 1
382 // pie 1
383 m_pieSeries = new QPieSeries;
383 m_pieSeries = new QPieSeries;
384
384
385 m_pieMapper = new QVPieModelMapper;
385 m_pieMapper = new QVPieModelMapper;
386 m_pieMapper->setValuesColumn(1);
386 m_pieMapper->setValuesColumn(1);
387 m_pieMapper->setLabelsColumn(7);
387 m_pieMapper->setLabelsColumn(7);
388 m_pieMapper->setSeries(m_pieSeries);
388 m_pieMapper->setSeries(m_pieSeries);
389 m_pieMapper->setModel(m_model);
389 m_pieMapper->setModel(m_model);
390 m_pieMapper->setFirst(2);
390 m_pieMapper->setFirst(2);
391 // m_pieMapper->setCount(5);
391 // m_pieMapper->setCount(5);
392 // pieSeries->setModelMapper(mapper);
392 // pieSeries->setModelMapper(mapper);
393
393
394 m_pieSeries->setLabelsVisible(true);
394 m_pieSeries->setLabelsVisible(true);
395 m_pieSeries->setPieSize(0.35);
395 m_pieSeries->setPieSize(0.35);
396 m_pieSeries->setHorizontalPosition(0.25);
396 m_pieSeries->setHorizontalPosition(0.25);
397 m_pieSeries->setVerticalPosition(0.35);
397 m_pieSeries->setVerticalPosition(0.35);
398
398
399 m_chart->addSeries(m_pieSeries);
399 m_chart->addSeries(m_pieSeries);
400 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
400 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
401 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
401 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
402
402
403
403
404 // pieSeries->slices().at(0)->setValue(400);
404 // pieSeries->slices().at(0)->setValue(400);
405 // pieSeries->slices().at(0)->setLabel(QString("36"));
405 // pieSeries->slices().at(0)->setLabel(QString("36"));
406
406
407 // pie 2
407 // pie 2
408 m_pieSeries2 = new QPieSeries;
408 m_pieSeries2 = new QPieSeries;
409
409
410 m_pieMapper2 = new QVPieModelMapper;
410 m_pieMapper2 = new QVPieModelMapper;
411 m_pieMapper2->setValuesColumn(0);
411 m_pieMapper2->setValuesColumn(0);
412 m_pieMapper2->setLabelsColumn(7);
412 m_pieMapper2->setLabelsColumn(7);
413 m_pieMapper2->setModel(m_model);
413 m_pieMapper2->setModel(m_model);
414 m_pieMapper2->setSeries(m_pieSeries2);
414 m_pieMapper2->setSeries(m_pieSeries2);
415 m_pieMapper2->setFirst(2);
415 m_pieMapper2->setFirst(2);
416
416
417 m_pieSeries2->setLabelsVisible(true);
417 m_pieSeries2->setLabelsVisible(true);
418 m_pieSeries2->setPieSize(0.35);
418 m_pieSeries2->setPieSize(0.35);
419 m_pieSeries2->setHorizontalPosition(0.75);
419 m_pieSeries2->setHorizontalPosition(0.75);
420 m_pieSeries2->setVerticalPosition(0.65);
420 m_pieSeries2->setVerticalPosition(0.65);
421 m_chart->addSeries(m_pieSeries2);
421 m_chart->addSeries(m_pieSeries2);
422 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
422 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
423 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
423 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
424
424
425 // // pie 3
425 // // pie 3
426 // pieSeries = new QPieSeries;
426 // pieSeries = new QPieSeries;
427 // pieSeries->setModel(m_model);
427 // pieSeries->setModel(m_model);
428 // pieSeries->setModelMapping(2,2, Qt::Vertical);
428 // pieSeries->setModelMapping(2,2, Qt::Vertical);
429 // pieSeries->setLabelsVisible(true);
429 // pieSeries->setLabelsVisible(true);
430 // pieSeries->setPieSize(0.35);
430 // pieSeries->setPieSize(0.35);
431 // pieSeries->setHorizontalPosition(0.5);
431 // pieSeries->setHorizontalPosition(0.5);
432 // pieSeries->setVerticalPosition(0.75);
432 // pieSeries->setVerticalPosition(0.75);
433 // m_chart->addSeries(pieSeries);
433 // m_chart->addSeries(pieSeries);
434 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
434 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
435 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
435 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
436
436
437 // // special pie
437 // // special pie
438 // specialPie = new QPieSeries;
438 // specialPie = new QPieSeries;
439 // specialPie->append(17, "1");
439 // specialPie->append(17, "1");
440 // specialPie->append(45, "2");
440 // specialPie->append(45, "2");
441 // specialPie->append(77, "3");
441 // specialPie->append(77, "3");
442 // specialPie->append(37, "4");
442 // specialPie->append(37, "4");
443 // specialPie->append(27, "5");
443 // specialPie->append(27, "5");
444 // specialPie->append(47, "6");
444 // specialPie->append(47, "6");
445 // specialPie->setPieSize(0.35);
445 // specialPie->setPieSize(0.35);
446 // specialPie->setHorizontalPosition(0.8);
446 // specialPie->setHorizontalPosition(0.8);
447 // specialPie->setVerticalPosition(0.75);
447 // specialPie->setVerticalPosition(0.75);
448 // specialPie->setLabelsVisible(true);
448 // specialPie->setLabelsVisible(true);
449 // m_chart->addSeries(specialPie);
449 // m_chart->addSeries(specialPie);
450 }
450 }
451 // else if (m_areaRadioButton->isChecked())
451 // else if (m_areaRadioButton->isChecked())
452 // {
452 // {
453 // m_chart->setAnimationOptions(QChart::NoAnimation);
453 // m_chart->setAnimationOptions(QChart::NoAnimation);
454
454
455 // QLineSeries* upperLineSeries = new QLineSeries;
455 // QLineSeries* upperLineSeries = new QLineSeries;
456 // upperLineSeries->setModel(m_model);
456 // upperLineSeries->setModel(m_model);
457 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
457 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
458 // // upperLineSeries->setModelMappingRange(1, 5);
458 // // upperLineSeries->setModelMappingRange(1, 5);
459 // QLineSeries* lowerLineSeries = new QLineSeries;
459 // QLineSeries* lowerLineSeries = new QLineSeries;
460 // lowerLineSeries->setModel(m_model);
460 // lowerLineSeries->setModel(m_model);
461 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
461 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
462 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
462 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
463 // m_chart->addSeries(areaSeries);
463 // m_chart->addSeries(areaSeries);
464 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
464 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
465 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
465 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
466 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
466 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
467 // }
467 // }
468 else if (m_barRadioButton->isChecked())
468 else if (m_barRadioButton->isChecked())
469 {
469 {
470 m_chart->setAnimationOptions(QChart::SeriesAnimations);
470 m_chart->setAnimationOptions(QChart::SeriesAnimations);
471
471
472 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
472 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
473 // barSeries->setCategories(QStringList());
473 // barSeries->setCategories(QStringList());
474 // barSeries->setModel(m_model);
474 // barSeries->setModel(m_model);
475 // barSeries->setModelMappingRange(2, 5);
475 // barSeries->setModelMappingRange(2, 5);
476 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
476 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
477
477
478 int first = 3;
478 int first = 3;
479 int count = 4;
479 // int count = 4;
480 QVBarModelMapper *mapper = new QVBarModelMapper;
480 QVBarModelMapper *mapper = new QVBarModelMapper;
481 mapper->setCategoriesSection(5);
481 mapper->setCategoriesSection(5);
482 mapper->setFirstBarSection(2);
482 mapper->setFirstBarSection(2);
483 mapper->setLastBarSection(4);
483 mapper->setLastBarSection(4);
484 mapper->setFirst(first);
484 mapper->setFirst(first);
485 mapper->setCount(count);
485 // mapper->setCount(count);
486 mapper->setSeries(barSeries);
486 mapper->setSeries(barSeries);
487 mapper->setModel(m_model);
487 mapper->setModel(m_model);
488 // barSeries->setModelMapper(mapper);
488 // barSeries->setModelMapper(mapper);
489 m_chart->addSeries(barSeries);
489 m_chart->addSeries(barSeries);
490 QList<QBarSet*> barsets = barSeries->barSets();
490 QList<QBarSet*> barsets = barSeries->barSets();
491 for (int i = 0; i < barsets.count(); i++) {
491 for (int i = 0; i < barsets.count(); i++) {
492 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
492 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
493 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, count));
493 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
494 }
494 }
495 }
495 }
496
496
497
497
498 if (!m_barRadioButton->isChecked()) {
498 if (!m_barRadioButton->isChecked()) {
499 m_chart->axisX()->setRange(0, 500);
499 m_chart->axisX()->setRange(0, 500);
500 m_chart->axisY()->setRange(0, 220);
500 m_chart->axisY()->setRange(0, 220);
501 }
501 }
502 m_chart->legend()->setVisible(true);
502 m_chart->legend()->setVisible(true);
503
503
504 // repaint table view colors
504 // repaint table view colors
505 m_tableView->repaint();
505 m_tableView->repaint();
506 m_tableView->setFocus();
506 m_tableView->setFocus();
507 }
507 }
508 }
508 }
509
509
510 void TableWidget::testPie()
510 void TableWidget::testPie()
511 {
511 {
512 // m_pieMapper->setCount(-1);
512 // m_pieMapper->setCount(-1);
513 QPieSlice *slice = new QPieSlice("Hehe", 145);
513 QPieSlice *slice = new QPieSlice("Hehe", 145);
514 slice->setLabelVisible();
514 slice->setLabelVisible();
515 m_pieSeries->append(slice);
515 m_pieSeries->append(slice);
516
516
517 slice = new QPieSlice("Hoho", 34);
517 slice = new QPieSlice("Hoho", 34);
518 slice->setLabelVisible();
518 slice->setLabelVisible();
519 m_pieSeries->append(slice);
519 m_pieSeries->append(slice);
520 // m_series->modelMapper()->setMapX(4);
520 // m_series->modelMapper()->setMapX(4);
521 // m_tableView->setColumnWidth(10, 250);
521 // m_tableView->setColumnWidth(10, 250);
522 // if (specialPie) {
522 // if (specialPie) {
523 // specialPie->remove(specialPie->slices().at(2));
523 // specialPie->remove(specialPie->slices().at(2));
524 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
524 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
525 // specialPie->append(4, "heloo");
525 // specialPie->append(4, "heloo");
526 // }
526 // }
527 }
527 }
528
528
529 void TableWidget::testPie2()
529 void TableWidget::testPie2()
530 {
530 {
531 QPieSlice *slice;
531 QPieSlice *slice;
532 if (m_pieSeries->count() > 0) {
532 if (m_pieSeries->count() > 0) {
533 slice = m_pieSeries->slices().last();
533 slice = m_pieSeries->slices().last();
534 m_pieSeries->remove(slice);
534 m_pieSeries->remove(slice);
535 }
535 }
536
536
537 if (m_pieSeries->count() > 0) {
537 if (m_pieSeries->count() > 0) {
538 slice = m_pieSeries->slices().first();
538 slice = m_pieSeries->slices().first();
539 m_pieSeries->remove(slice);
539 m_pieSeries->remove(slice);
540 }
540 }
541 }
541 }
542
542
543 void TableWidget::testPie3()
543 void TableWidget::testPie3()
544 {
544 {
545 QPieSlice *slice;
545 QPieSlice *slice;
546 if (m_pieSeries->count() > 0) {
546 if (m_pieSeries->count() > 0) {
547 slice = m_pieSeries->slices().last();
547 slice = m_pieSeries->slices().last();
548 slice->setLabel("Dalej");
548 slice->setLabel("Dalej");
549 slice->setValue(222);
549 slice->setValue(222);
550 }
550 }
551
551
552 if (m_pieSeries->count() > 0) {
552 if (m_pieSeries->count() > 0) {
553 slice = m_pieSeries->slices().first();
553 slice = m_pieSeries->slices().first();
554 slice->setLabel("Prawie");
554 slice->setLabel("Prawie");
555 slice->setValue(111);
555 slice->setValue(111);
556 }
556 }
557 }
557 }
558
558
559 void TableWidget::testXY()
559 void TableWidget::testXY()
560 {
560 {
561 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
561 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
562 // m_series->append(QPointF(150, 75));
562 // m_series->append(QPointF(150, 75));
563 // }
563 // }
564
564
565 if (m_series->count() > 0) {
565 if (m_series->count() > 0) {
566 m_series->remove(m_series->points().last());
566 m_series->remove(m_series->points().last());
567 }
567 }
568 }
568 }
569
569
570 TableWidget::~TableWidget()
570 TableWidget::~TableWidget()
571 {
571 {
572
572
573 }
573 }
General Comments 0
You need to be logged in to leave comments. Login now