@@ -0,0 +1,64 | |||
|
1 | #ifndef QXYMODELMAPPER_P_H | |
|
2 | #define QXYMODELMAPPER_P_H | |
|
3 | ||
|
4 | #include "qxymodelmapper.h" | |
|
5 | #include <QObject> | |
|
6 | ||
|
7 | class QModelIndex; | |
|
8 | class QAbstractItemModel; | |
|
9 | class QPointF; | |
|
10 | ||
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
12 | ||
|
13 | class QXYModelMapper; | |
|
14 | class QXYSeries; | |
|
15 | ||
|
16 | class QXYModelMapperPrivate : public QObject | |
|
17 | { | |
|
18 | Q_OBJECT | |
|
19 | ||
|
20 | public: | |
|
21 | QXYModelMapperPrivate(QXYModelMapper *q); | |
|
22 | ||
|
23 | public Q_SLOTS: | |
|
24 | // for the model | |
|
25 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
26 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
|
27 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
|
28 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |
|
29 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
|
30 | ||
|
31 | // for the series | |
|
32 | void handlePointAdded(int pointPos); | |
|
33 | void handlePointRemoved(int pointPos); | |
|
34 | void handlePointReplaced(int pointPos); | |
|
35 | ||
|
36 | void initializeXYFromModel(); | |
|
37 | ||
|
38 | private: | |
|
39 | QModelIndex xModelIndex(int xPos); | |
|
40 | QModelIndex yModelIndex(int yPos); | |
|
41 | void insertData(int start, int end); | |
|
42 | void removeData(int start, int end); | |
|
43 | void blockModelSignals(bool block = true); | |
|
44 | void blockSeriesSignals(bool block = true); | |
|
45 | ||
|
46 | private: | |
|
47 | QXYSeries *m_series; | |
|
48 | QAbstractItemModel *m_model; | |
|
49 | int m_first; | |
|
50 | int m_count; | |
|
51 | Qt::Orientation m_orientation; | |
|
52 | int m_xSection; | |
|
53 | int m_ySection; | |
|
54 | bool m_seriesSignalsBlock; | |
|
55 | bool m_modelSignalsBlock; | |
|
56 | ||
|
57 | private: | |
|
58 | QXYModelMapper *q_ptr; | |
|
59 | Q_DECLARE_PUBLIC(QXYModelMapper) | |
|
60 | }; | |
|
61 | ||
|
62 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
63 | ||
|
64 | #endif // QXYMODELMAPPER_P_H |
@@ -1,81 +1,383 | |||
|
1 | 1 | #include "qxymodelmapper.h" |
|
2 | #include "qxymodelmapper_p.h" | |
|
3 | #include "qxyseries.h" | |
|
4 | #include <QAbstractItemModel> | |
|
2 | 5 | |
|
3 | 6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 7 | |
|
5 | 8 | QXYModelMapper::QXYModelMapper(QObject *parent): |
|
6 | 9 | QObject(parent), |
|
7 | m_first(0), | |
|
8 | m_count(-1), | |
|
9 | m_orientation(Qt::Vertical), | |
|
10 | m_xSection(-1), | |
|
11 | m_ySection(-1) | |
|
10 | d_ptr(new QXYModelMapperPrivate(this)) | |
|
11 | { | |
|
12 | } | |
|
13 | ||
|
14 | QAbstractItemModel* QXYModelMapper::model() const | |
|
15 | { | |
|
16 | Q_D(const QXYModelMapper); | |
|
17 | return d->m_model; | |
|
18 | } | |
|
19 | ||
|
20 | void QXYModelMapper::setModel(QAbstractItemModel *model) | |
|
21 | { | |
|
22 | if (model == 0) | |
|
23 | return; | |
|
24 | ||
|
25 | Q_D(QXYModelMapper); | |
|
26 | if (d->m_model) { | |
|
27 | disconnect(d->m_model, 0, d, 0); | |
|
28 | } | |
|
29 | ||
|
30 | d->m_model = model; | |
|
31 | d->initializeXYFromModel(); | |
|
32 | // connect signals from the model | |
|
33 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
34 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
|
35 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
|
36 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
|
37 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
38 | } | |
|
39 | ||
|
40 | QXYSeries* QXYModelMapper::series() const | |
|
12 | 41 | { |
|
42 | Q_D(const QXYModelMapper); | |
|
43 | return d->m_series; | |
|
44 | } | |
|
45 | ||
|
46 | void QXYModelMapper::setSeries(QXYSeries *series) | |
|
47 | { | |
|
48 | Q_D(QXYModelMapper); | |
|
49 | if (d->m_series) { | |
|
50 | disconnect(d->m_series, 0, d, 0); | |
|
51 | } | |
|
52 | ||
|
53 | if (series == 0) | |
|
54 | return; | |
|
55 | ||
|
56 | d->m_series = series; | |
|
57 | d->initializeXYFromModel(); | |
|
58 | // connect the signals from the series | |
|
59 | connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); | |
|
60 | connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); | |
|
61 | connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(pointReplaced(int))); | |
|
13 | 62 | } |
|
14 | 63 | |
|
15 | 64 | int QXYModelMapper::first() const |
|
16 | 65 | { |
|
17 | return m_first; | |
|
66 | Q_D(const QXYModelMapper); | |
|
67 | return d->m_first; | |
|
18 | 68 | } |
|
19 | 69 | |
|
20 | 70 | void QXYModelMapper::setFirst(int first) |
|
21 | 71 | { |
|
22 | m_first = qMax(first, 0); | |
|
23 | // emit updated(); | |
|
72 | Q_D(QXYModelMapper); | |
|
73 | d->m_first = qMax(first, 0); | |
|
74 | d->initializeXYFromModel(); | |
|
24 | 75 | } |
|
25 | 76 | |
|
26 | 77 | int QXYModelMapper::count() const |
|
27 | 78 | { |
|
28 | return m_count; | |
|
79 | Q_D(const QXYModelMapper); | |
|
80 | return d->m_count; | |
|
29 | 81 | } |
|
30 | 82 | |
|
31 | 83 | void QXYModelMapper::setCount(int count) |
|
32 | 84 | { |
|
33 | m_count = qMax(count, -1); | |
|
34 | // emit updated(); | |
|
85 | Q_D(QXYModelMapper); | |
|
86 | d->m_count = qMax(count, -1); | |
|
87 | d->initializeXYFromModel(); | |
|
35 | 88 | } |
|
36 | 89 | |
|
37 | 90 | Qt::Orientation QXYModelMapper::orientation() const |
|
38 | 91 | { |
|
39 | return m_orientation; | |
|
92 | Q_D(const QXYModelMapper); | |
|
93 | return d->m_orientation; | |
|
40 | 94 | } |
|
41 | 95 | |
|
42 | 96 | void QXYModelMapper::setOrientation(Qt::Orientation orientation) |
|
43 | 97 | { |
|
44 | m_orientation = orientation; | |
|
45 | // emit updated(); | |
|
98 | Q_D(QXYModelMapper); | |
|
99 | d->m_orientation = orientation; | |
|
100 | d->initializeXYFromModel(); | |
|
46 | 101 | } |
|
47 | 102 | |
|
48 | 103 | int QXYModelMapper::xSection() const |
|
49 | 104 | { |
|
50 | return m_xSection; | |
|
105 | Q_D(const QXYModelMapper); | |
|
106 | return d->m_xSection; | |
|
51 | 107 | } |
|
52 | 108 | |
|
53 | 109 | void QXYModelMapper::setXSection(int xSection) |
|
54 | 110 | { |
|
55 | m_xSection = xSection; | |
|
56 | // emit updated(); | |
|
111 | Q_D(QXYModelMapper); | |
|
112 | d->m_xSection = xSection; | |
|
113 | d->initializeXYFromModel(); | |
|
57 | 114 | } |
|
58 | 115 | |
|
59 | 116 | int QXYModelMapper::ySection() const |
|
60 | 117 | { |
|
61 | return m_ySection; | |
|
118 | Q_D(const QXYModelMapper); | |
|
119 | return d->m_ySection; | |
|
62 | 120 | } |
|
63 | 121 | |
|
64 | 122 | void QXYModelMapper::setYSection(int ySection) |
|
65 | 123 | { |
|
66 | m_ySection = ySection; | |
|
67 | // emit updated(); | |
|
124 | Q_D(QXYModelMapper); | |
|
125 | d->m_ySection = ySection; | |
|
126 | d->initializeXYFromModel(); | |
|
68 | 127 | } |
|
69 | 128 | |
|
70 | 129 | void QXYModelMapper::reset() |
|
71 | 130 | { |
|
72 | m_first = 0; | |
|
73 |
|
|
|
74 | m_orientation = Qt::Vertical; | |
|
75 | m_xSection = -1; | |
|
76 |
|
|
|
131 | Q_D(QXYModelMapper); | |
|
132 | d->m_first = 0; | |
|
133 | d->m_count = -1; | |
|
134 | d->m_orientation = Qt::Vertical; | |
|
135 | d->m_xSection = -1; | |
|
136 | d->m_ySection = -1; | |
|
137 | d->initializeXYFromModel(); | |
|
138 | } | |
|
139 | ||
|
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
141 | ||
|
142 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : | |
|
143 | m_series(0), | |
|
144 | m_model(0), | |
|
145 | m_first(0), | |
|
146 | m_count(-1), | |
|
147 | m_orientation(Qt::Vertical), | |
|
148 | m_xSection(-1), | |
|
149 | m_ySection(-1), | |
|
150 | m_seriesSignalsBlock(false), | |
|
151 | m_modelSignalsBlock(false), | |
|
152 | q_ptr(q) | |
|
153 | { | |
|
154 | } | |
|
155 | ||
|
156 | void QXYModelMapperPrivate::blockModelSignals(bool block) | |
|
157 | { | |
|
158 | m_modelSignalsBlock = block; | |
|
159 | } | |
|
160 | ||
|
161 | void QXYModelMapperPrivate::blockSeriesSignals(bool block) | |
|
162 | { | |
|
163 | m_seriesSignalsBlock = block; | |
|
164 | } | |
|
165 | ||
|
166 | QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos) | |
|
167 | { | |
|
168 | if (m_count != -1 && xPos >= m_count) | |
|
169 | return QModelIndex(); // invalid | |
|
170 | ||
|
171 | if (m_orientation == Qt::Vertical) | |
|
172 | return m_model->index(xPos + m_first, m_xSection); | |
|
173 | else | |
|
174 | return m_model->index(m_xSection, xPos + m_first); | |
|
175 | } | |
|
176 | ||
|
177 | QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos) | |
|
178 | { | |
|
179 | if (m_count != -1 && yPos >= m_count) | |
|
180 | return QModelIndex(); // invalid | |
|
181 | ||
|
182 | if (m_orientation == Qt::Vertical) | |
|
183 | return m_model->index(yPos + m_first, m_ySection); | |
|
184 | else | |
|
185 | return m_model->index(m_ySection, yPos + m_first); | |
|
186 | } | |
|
187 | ||
|
188 | void QXYModelMapperPrivate::handlePointAdded(int pointPos) | |
|
189 | { | |
|
190 | Q_UNUSED(pointPos) | |
|
191 | } | |
|
192 | ||
|
193 | void QXYModelMapperPrivate::handlePointRemoved(int pointPos) | |
|
194 | { | |
|
195 | Q_UNUSED(pointPos) | |
|
196 | } | |
|
197 | ||
|
198 | void QXYModelMapperPrivate::handlePointReplaced(int pointPos) | |
|
199 | { | |
|
200 | Q_UNUSED(pointPos) | |
|
201 | } | |
|
202 | ||
|
203 | void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
204 | { | |
|
205 | if (m_modelSignalsBlock) | |
|
206 | return; | |
|
207 | ||
|
208 | blockSeriesSignals(); | |
|
209 | QModelIndex index; | |
|
210 | QPointF oldPoint; | |
|
211 | QPointF newPoint; | |
|
212 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
|
213 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
|
214 | index = topLeft.sibling(row, column); | |
|
215 | if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) { | |
|
216 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
|
217 | oldPoint = m_series->points().at(index.row() - m_first); | |
|
218 | newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal()); | |
|
219 | newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal()); | |
|
220 | } | |
|
221 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { | |
|
222 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
|
223 | oldPoint = m_series->points().at(index.column() - m_first); | |
|
224 | newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal()); | |
|
225 | newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal()); | |
|
226 | } | |
|
227 | } else { | |
|
228 | continue; | |
|
229 | } | |
|
230 | m_series->replace(oldPoint, newPoint); | |
|
231 | } | |
|
232 | blockSeriesSignals(false); | |
|
233 | } | |
|
234 | } | |
|
235 | ||
|
236 | void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
|
237 | { | |
|
238 | Q_UNUSED(parent); | |
|
239 | if (m_modelSignalsBlock) | |
|
240 | return; | |
|
241 | ||
|
242 | blockSeriesSignals(); | |
|
243 | if (m_orientation == Qt::Vertical) | |
|
244 | insertData(start, end); | |
|
245 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
|
246 | initializeXYFromModel(); | |
|
247 | blockSeriesSignals(false); | |
|
248 | } | |
|
249 | ||
|
250 | void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
|
251 | { | |
|
252 | Q_UNUSED(parent); | |
|
253 | if (m_modelSignalsBlock) | |
|
254 | return; | |
|
255 | ||
|
256 | blockSeriesSignals(); | |
|
257 | if (m_orientation == Qt::Vertical) | |
|
258 | removeData(start, end); | |
|
259 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
|
260 | initializeXYFromModel(); | |
|
261 | blockSeriesSignals(false); | |
|
262 | } | |
|
263 | ||
|
264 | void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
|
265 | { | |
|
266 | Q_UNUSED(parent); | |
|
267 | if (m_modelSignalsBlock) | |
|
268 | return; | |
|
269 | ||
|
270 | blockSeriesSignals(); | |
|
271 | if (m_orientation == Qt::Horizontal) | |
|
272 | insertData(start, end); | |
|
273 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
|
274 | initializeXYFromModel(); | |
|
275 | blockSeriesSignals(false); | |
|
276 | } | |
|
277 | ||
|
278 | void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
|
279 | { | |
|
280 | Q_UNUSED(parent); | |
|
281 | if (m_modelSignalsBlock) | |
|
282 | return; | |
|
283 | ||
|
284 | blockSeriesSignals(); | |
|
285 | if (m_orientation == Qt::Horizontal) | |
|
286 | removeData(start, end); | |
|
287 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
|
288 | initializeXYFromModel(); | |
|
289 | blockSeriesSignals(false); | |
|
290 | } | |
|
291 | ||
|
292 | void QXYModelMapperPrivate::insertData(int start, int end) | |
|
293 | { | |
|
294 | if (m_model == 0 || m_series == 0) | |
|
295 | return; | |
|
296 | ||
|
297 | if (m_count != -1 && start >= m_first + m_count) { | |
|
298 | return; | |
|
299 | } else { | |
|
300 | int addedCount = end - start + 1; | |
|
301 | if (m_count != -1 && addedCount > m_count) | |
|
302 | addedCount = m_count; | |
|
303 | int first = qMax(start, m_first); | |
|
304 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
|
305 | for (int i = first; i <= last; i++) { | |
|
306 | QPointF point; | |
|
307 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
|
308 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
|
309 | m_series->insert(i - m_first, point); | |
|
310 | } | |
|
311 | ||
|
312 | // remove excess of slices (abouve m_count) | |
|
313 | if (m_count != -1 && m_series->points().size() > m_count) | |
|
314 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { | |
|
315 | m_series->remove(m_series->points().at(i)); | |
|
316 | } | |
|
317 | } | |
|
318 | } | |
|
319 | ||
|
320 | void QXYModelMapperPrivate::removeData(int start, int end) | |
|
321 | { | |
|
322 | if (m_model == 0 || m_series == 0) | |
|
323 | return; | |
|
324 | ||
|
325 | int removedCount = end - start + 1; | |
|
326 | if (m_count != -1 && start >= m_first + m_count) { | |
|
327 | return; | |
|
328 | } else { | |
|
329 | int toRemove = qMin(m_series->points().size(), removedCount); // first find how many items can actually be removed | |
|
330 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
|
331 | int last = qMin(first + toRemove - 1, m_series->points().size() + m_first - 1); // get the index of the last item that will be removed. | |
|
332 | for (int i = last; i >= first; i--) { | |
|
333 | m_series->remove(m_series->points().at(i - m_first)); | |
|
334 | } | |
|
335 | ||
|
336 | if (m_count != -1) { | |
|
337 | int itemsAvailable; // check how many are available to be added | |
|
338 | if (m_orientation == Qt::Vertical) | |
|
339 | itemsAvailable = m_model->rowCount() - m_first - m_series->points().size(); | |
|
340 | else | |
|
341 | itemsAvailable = m_model->columnCount() - m_first - m_series->points().size(); | |
|
342 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->points().size()); // add not more items than there is space left to be filled. | |
|
343 | int currentSize = m_series->points().size(); | |
|
344 | if (toBeAdded > 0) | |
|
345 | for (int i = m_series->points().size(); i < currentSize + toBeAdded; i++) { | |
|
346 | QPointF point; | |
|
347 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); | |
|
348 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); | |
|
349 | m_series->insert(i, point); | |
|
350 | } | |
|
351 | } | |
|
352 | } | |
|
353 | } | |
|
354 | ||
|
355 | void QXYModelMapperPrivate::initializeXYFromModel() | |
|
356 | { | |
|
357 | if (m_model == 0 || m_series == 0) | |
|
358 | return; | |
|
359 | ||
|
360 | blockSeriesSignals(); | |
|
361 | // clear current content | |
|
362 | m_series->clear(); | |
|
363 | ||
|
364 | // create the initial slices set | |
|
365 | int pointPos = 0; | |
|
366 | QModelIndex xIndex = xModelIndex(pointPos); | |
|
367 | QModelIndex yIndex = yModelIndex(pointPos); | |
|
368 | while (xIndex.isValid() && yIndex.isValid()) { | |
|
369 | QPointF point; | |
|
370 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); | |
|
371 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); | |
|
372 | m_series->append(point); | |
|
373 | pointPos++; | |
|
374 | xIndex = xModelIndex(pointPos); | |
|
375 | yIndex = yModelIndex(pointPos); | |
|
376 | } | |
|
377 | blockSeriesSignals(false); | |
|
77 | 378 | } |
|
78 | 379 | |
|
79 | 380 | #include "moc_qxymodelmapper.cpp" |
|
381 | #include "moc_qxymodelmapper_p.cpp" | |
|
80 | 382 | |
|
81 | 383 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,57 | |||
|
1 | 1 | #ifndef QXYMODELMAPPER_H |
|
2 | 2 | #define QXYMODELMAPPER_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include <QObject> |
|
6 | 6 | |
|
7 | class QAbstractItemModel; | |
|
8 | ||
|
7 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 10 | |
|
11 | class QXYModelMapperPrivate; | |
|
12 | class QXYSeries; | |
|
13 | ||
|
9 | 14 | class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject |
|
10 | 15 | { |
|
11 | 16 | Q_OBJECT |
|
12 |
Q_PROPERTY( |
|
|
13 | Q_PROPERTY(int ySection READ ySection WRITE setYSection) | |
|
17 | Q_PROPERTY(QXYSeries *series READ series WRITE setSeries) | |
|
18 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) | |
|
14 | 19 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
15 | 20 | Q_PROPERTY(int count READ count WRITE setCount) |
|
16 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) | |
|
17 | 21 | Q_ENUMS(Qt::Orientation) |
|
18 | 22 | |
|
19 | 23 | public: |
|
24 | QAbstractItemModel* model() const; | |
|
25 | void setModel(QAbstractItemModel *model); | |
|
26 | ||
|
27 | QXYSeries* series() const; | |
|
28 | void setSeries(QXYSeries *series); | |
|
29 | ||
|
20 | 30 | int first() const; |
|
21 | 31 | void setFirst(int first); |
|
22 | 32 | |
|
23 | 33 | int count() const; |
|
24 | 34 | void setCount(int count); |
|
25 | 35 | |
|
36 | void reset(); | |
|
37 | ||
|
26 | 38 | protected: |
|
27 | 39 | explicit QXYModelMapper(QObject *parent = 0); |
|
28 | 40 | |
|
29 | 41 | Qt::Orientation orientation() const; |
|
30 | 42 | void setOrientation(Qt::Orientation orientation); |
|
31 | 43 | |
|
32 | 44 | int xSection() const; |
|
33 | 45 | void setXSection(int xSection); |
|
34 | 46 | |
|
35 | 47 | int ySection() const; |
|
36 | 48 | void setYSection(int ySection); |
|
37 | 49 | |
|
38 | void reset(); | |
|
39 | ||
|
40 | Q_SIGNALS: | |
|
41 | void updated(); | |
|
42 | ||
|
43 | private: | |
|
44 | int m_first; | |
|
45 | int m_count; | |
|
46 | Qt::Orientation m_orientation; | |
|
47 | int m_xSection; | |
|
48 | int m_ySection; | |
|
50 | protected: | |
|
51 | QXYModelMapperPrivate * const d_ptr; | |
|
52 | Q_DECLARE_PRIVATE(QXYModelMapper) | |
|
49 | 53 | }; |
|
50 | 54 | |
|
51 | 55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | 56 | |
|
53 | 57 | #endif // QXYMODELMAPPER_H |
@@ -1,322 +1,336 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qxyseries.h" |
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "domain_p.h" |
|
24 | 24 | #include "legendmarker_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \class QXYSeries |
|
30 | 30 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | 31 | */ |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \fn QPen QXYSeries::pen() const |
|
35 | 35 | \brief Returns pen used to draw points for series. |
|
36 | 36 | \sa setPen() |
|
37 | 37 | */ |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \fn QBrush QXYSeries::brush() const |
|
41 | 41 | \brief Returns brush used to draw points for series. |
|
42 | 42 | \sa setBrush() |
|
43 | 43 | */ |
|
44 | 44 | |
|
45 | 45 | /*! |
|
46 | 46 | \fn void QXYSeries::clicked(const QPointF& point) |
|
47 | 47 | \brief Signal is emitted when user clicks the \a point on chart. |
|
48 | 48 | */ |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \fn void QXYSeriesPrivate::pointReplaced(int index) |
|
53 | 53 | \brief \internal \a index |
|
54 | 54 | */ |
|
55 | 55 | |
|
56 | 56 | /*! |
|
57 | 57 | \fn void QXYSeriesPrivate::pointAdded(int index) |
|
58 | 58 | \brief \internal \a index |
|
59 | 59 | */ |
|
60 | 60 | |
|
61 | 61 | /*! |
|
62 | 62 | \fn void QXYSeriesPrivate::pointRemoved(int index) |
|
63 | 63 | \brief \internal \a index |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | \fn void QXYSeriesPrivate::updated() |
|
68 | 68 | \brief \internal |
|
69 | 69 | */ |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | \internal |
|
73 | 73 | |
|
74 | 74 | Constructs empty series object which is a child of \a parent. |
|
75 | 75 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
76 | 76 | */ |
|
77 | 77 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
78 | 78 | { |
|
79 | 79 | |
|
80 | 80 | } |
|
81 | 81 | /*! |
|
82 | 82 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
83 | 83 | and are deleted when mentioned object are destroyed. |
|
84 | 84 | */ |
|
85 | 85 | QXYSeries::~QXYSeries() |
|
86 | 86 | { |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
91 | 91 | */ |
|
92 | 92 | void QXYSeries::append(qreal x,qreal y) |
|
93 | 93 | { |
|
94 | 94 | append(QPointF(x,y)); |
|
95 | 95 | } |
|
96 | 96 | |
|
97 | 97 | /*! |
|
98 | 98 | This is an overloaded function. |
|
99 | 99 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
100 | 100 | */ |
|
101 | 101 | void QXYSeries::append(const QPointF &point) |
|
102 | 102 | { |
|
103 | 103 | Q_D(QXYSeries); |
|
104 | 104 | d->m_points<<point; |
|
105 | 105 | emit d->pointAdded(d->m_points.count()-1); |
|
106 | 106 | } |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | This is an overloaded function. |
|
110 | 110 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
111 | 111 | */ |
|
112 | 112 | void QXYSeries::append(const QList<QPointF> &points) |
|
113 | 113 | { |
|
114 | 114 | foreach(const QPointF& point , points) { |
|
115 | 115 | append(point); |
|
116 | 116 | } |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
121 | 121 | { |
|
122 | 122 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
123 | 123 | } |
|
124 | 124 | |
|
125 | 125 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
126 | 126 | { |
|
127 | 127 | Q_D(QXYSeries); |
|
128 | 128 | int index = d->m_points.indexOf(oldPoint); |
|
129 | 129 | if(index==-1) return; |
|
130 | 130 | d->m_points[index] = newPoint; |
|
131 | 131 | emit d->pointReplaced(index); |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | /*! |
|
135 | 135 | Removes current \a x and \a y value. |
|
136 | 136 | */ |
|
137 | 137 | void QXYSeries::remove(qreal x,qreal y) |
|
138 | 138 | { |
|
139 | 139 | remove(QPointF(x,y)); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | /*! |
|
143 | 143 | Removes current \a point x value. Note \a point y value is ignored. |
|
144 | 144 | */ |
|
145 | 145 | void QXYSeries::remove(const QPointF &point) |
|
146 | 146 | { |
|
147 | 147 | Q_D(QXYSeries); |
|
148 | 148 | int index = d->m_points.indexOf(point); |
|
149 | 149 | if(index==-1) return; |
|
150 | 150 | d->m_points.remove(index); |
|
151 | 151 | emit d->pointRemoved(index); |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | /*! |
|
155 | 155 | Removes all data points from the series. |
|
156 | 156 | */ |
|
157 | 157 | void QXYSeries::removeAll() |
|
158 | 158 | { |
|
159 | 159 | Q_D(QXYSeries); |
|
160 | 160 | foreach(const QPointF& point, d->m_points) { |
|
161 | 161 | remove(point); |
|
162 | 162 | } |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | void QXYSeries::insert(int index, const QPointF &point) | |
|
166 | { | |
|
167 | Q_D(QXYSeries); | |
|
168 | d->m_points.insert(index, point); | |
|
169 | emit d->pointAdded(index); | |
|
170 | } | |
|
171 | ||
|
172 | void QXYSeries::clear() | |
|
173 | { | |
|
174 | Q_D(QXYSeries); | |
|
175 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
|
176 | remove(d->m_points.at(i)); | |
|
177 | } | |
|
178 | ||
|
165 | 179 | /*! |
|
166 | 180 | \internal \a pos |
|
167 | 181 | */ |
|
168 | 182 | QList<QPointF> QXYSeries::points() const |
|
169 | 183 | { |
|
170 | 184 | Q_D(const QXYSeries); |
|
171 | 185 | return d->m_points.toList(); |
|
172 | 186 | } |
|
173 | 187 | |
|
174 | 188 | /*! |
|
175 | 189 | Returns number of data points within series. |
|
176 | 190 | */ |
|
177 | 191 | int QXYSeries::count() const |
|
178 | 192 | { |
|
179 | 193 | Q_D(const QXYSeries); |
|
180 | 194 | return d->m_points.count(); |
|
181 | 195 | } |
|
182 | 196 | |
|
183 | 197 | |
|
184 | 198 | /*! |
|
185 | 199 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
186 | 200 | pen from chart theme is used. |
|
187 | 201 | \sa QChart::setTheme() |
|
188 | 202 | */ |
|
189 | 203 | void QXYSeries::setPen(const QPen &pen) |
|
190 | 204 | { |
|
191 | 205 | Q_D(QXYSeries); |
|
192 | 206 | if (d->m_pen!=pen) { |
|
193 | 207 | d->m_pen = pen; |
|
194 | 208 | emit d->updated(); |
|
195 | 209 | } |
|
196 | 210 | } |
|
197 | 211 | |
|
198 | 212 | QPen QXYSeries::pen() const |
|
199 | 213 | { |
|
200 | 214 | Q_D(const QXYSeries); |
|
201 | 215 | return d->m_pen; |
|
202 | 216 | } |
|
203 | 217 | |
|
204 | 218 | /*! |
|
205 | 219 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
206 | 220 | from chart theme setting is used. |
|
207 | 221 | \sa QChart::setTheme() |
|
208 | 222 | */ |
|
209 | 223 | void QXYSeries::setBrush(const QBrush &brush) |
|
210 | 224 | { |
|
211 | 225 | Q_D(QXYSeries); |
|
212 | 226 | if (d->m_brush!=brush) { |
|
213 | 227 | d->m_brush = brush; |
|
214 | 228 | emit d->updated(); |
|
215 | 229 | } |
|
216 | 230 | } |
|
217 | 231 | |
|
218 | 232 | QBrush QXYSeries::brush() const |
|
219 | 233 | { |
|
220 | 234 | Q_D(const QXYSeries); |
|
221 | 235 | return d->m_brush; |
|
222 | 236 | } |
|
223 | 237 | |
|
224 | 238 | |
|
225 | 239 | /*! |
|
226 | 240 | Sets if data points are \a visible and should be drawn on line. |
|
227 | 241 | */ |
|
228 | 242 | void QXYSeries::setPointsVisible(bool visible) |
|
229 | 243 | { |
|
230 | 244 | Q_D(QXYSeries); |
|
231 | 245 | if (d->m_pointsVisible != visible){ |
|
232 | 246 | d->m_pointsVisible = visible; |
|
233 | 247 | emit d->updated(); |
|
234 | 248 | } |
|
235 | 249 | } |
|
236 | 250 | |
|
237 | 251 | /*! |
|
238 | 252 | Returns true if drawing the data points of the series is enabled. |
|
239 | 253 | */ |
|
240 | 254 | bool QXYSeries::pointsVisible() const |
|
241 | 255 | { |
|
242 | 256 | Q_D(const QXYSeries); |
|
243 | 257 | return d->m_pointsVisible; |
|
244 | 258 | } |
|
245 | 259 | |
|
246 | 260 | |
|
247 | 261 | /*! |
|
248 | 262 | Stream operator for adding a data \a point to the series. |
|
249 | 263 | \sa append() |
|
250 | 264 | */ |
|
251 | 265 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
252 | 266 | { |
|
253 | 267 | append(point); |
|
254 | 268 | return *this; |
|
255 | 269 | } |
|
256 | 270 | |
|
257 | 271 | |
|
258 | 272 | /*! |
|
259 | 273 | Stream operator for adding a list of \a points to the series. |
|
260 | 274 | \sa append() |
|
261 | 275 | */ |
|
262 | 276 | |
|
263 | 277 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
264 | 278 | { |
|
265 | 279 | append(points); |
|
266 | 280 | return *this; |
|
267 | 281 | } |
|
268 | 282 | |
|
269 | 283 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
270 | 284 | |
|
271 | 285 | |
|
272 | 286 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
273 | 287 | QAbstractSeriesPrivate(q), |
|
274 | 288 | m_pointsVisible(false) |
|
275 | 289 | { |
|
276 | 290 | } |
|
277 | 291 | |
|
278 | 292 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
279 | 293 | { |
|
280 | 294 | qreal minX(domain.minX()); |
|
281 | 295 | qreal minY(domain.minY()); |
|
282 | 296 | qreal maxX(domain.maxX()); |
|
283 | 297 | qreal maxY(domain.maxY()); |
|
284 | 298 | int tickXCount(domain.tickXCount()); |
|
285 | 299 | int tickYCount(domain.tickYCount()); |
|
286 | 300 | |
|
287 | 301 | Q_Q(QXYSeries); |
|
288 | 302 | |
|
289 | 303 | const QList<QPointF>& points = q->points(); |
|
290 | 304 | |
|
291 | 305 | |
|
292 | 306 | if(points.isEmpty()){ |
|
293 | 307 | minX=0.0; |
|
294 | 308 | minY=0.0; |
|
295 | 309 | maxX=1.0; |
|
296 | 310 | maxY=1.0; |
|
297 | 311 | } |
|
298 | 312 | |
|
299 | 313 | for (int i = 0; i < points.count(); i++) |
|
300 | 314 | { |
|
301 | 315 | qreal x = points[i].x(); |
|
302 | 316 | qreal y = points[i].y(); |
|
303 | 317 | minX = qMin(minX, x); |
|
304 | 318 | minY = qMin(minY, y); |
|
305 | 319 | maxX = qMax(maxX, x); |
|
306 | 320 | maxY = qMax(maxY, y); |
|
307 | 321 | } |
|
308 | 322 | |
|
309 | 323 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
310 | 324 | } |
|
311 | 325 | |
|
312 | 326 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
313 | 327 | { |
|
314 | 328 | Q_Q(QXYSeries); |
|
315 | 329 | QList<LegendMarker*> list; |
|
316 | 330 | return list << new XYLegendMarker(q,legend); |
|
317 | 331 | } |
|
318 | 332 | |
|
319 | 333 | #include "moc_qxyseries.cpp" |
|
320 | 334 | #include "moc_qxyseries_p.cpp" |
|
321 | 335 | |
|
322 | 336 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,81 +1,83 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QXYSERIES_H |
|
22 | 22 | #define QXYSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <qabstractseries.h> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QBrush> |
|
28 | 28 | |
|
29 | 29 | class QModelIndex; |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class QXYSeriesPrivate; |
|
34 | 34 | class QXYModelMapper; |
|
35 | 35 | |
|
36 | 36 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries |
|
37 | 37 | { |
|
38 | 38 | Q_OBJECT |
|
39 | 39 | |
|
40 | 40 | protected: |
|
41 | 41 | explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); |
|
42 | 42 | ~QXYSeries(); |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | void append(qreal x, qreal y); |
|
46 | 46 | void append(const QPointF &point); |
|
47 | 47 | void append(const QList<QPointF> &points); |
|
48 | 48 | void replace(qreal oldX,qreal oldY,qreal newX,qreal newY); |
|
49 | 49 | void replace(const QPointF &oldPoint,const QPointF &newPoint); |
|
50 | 50 | void remove(qreal x, qreal y); |
|
51 | 51 | void remove(const QPointF &point); |
|
52 | 52 | void removeAll(); |
|
53 | void insert(int index, const QPointF &point); | |
|
54 | void clear(); | |
|
53 | 55 | |
|
54 | 56 | int count() const; |
|
55 | 57 | QList<QPointF> points() const; |
|
56 | 58 | |
|
57 | 59 | QXYSeries& operator << (const QPointF &point); |
|
58 | 60 | QXYSeries& operator << (const QList<QPointF> &points); |
|
59 | 61 | |
|
60 | 62 | void setPen(const QPen &pen); |
|
61 | 63 | QPen pen() const; |
|
62 | 64 | |
|
63 | 65 | void setBrush(const QBrush &brush); |
|
64 | 66 | QBrush brush() const; |
|
65 | 67 | |
|
66 | 68 | void setPointsVisible(bool visible = true); |
|
67 | 69 | bool pointsVisible() const; |
|
68 | 70 | |
|
69 | 71 | Q_SIGNALS: |
|
70 | 72 | void clicked(const QPointF &point); |
|
71 | 73 | |
|
72 | 74 | private: |
|
73 | 75 | Q_DECLARE_PRIVATE(QXYSeries) |
|
74 | 76 | Q_DISABLE_COPY(QXYSeries) |
|
75 | 77 | friend class XYLegendMarker; |
|
76 | 78 | friend class XYChart; |
|
77 | 79 | }; |
|
78 | 80 | |
|
79 | 81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
80 | 82 | |
|
81 | 83 | #endif |
@@ -1,72 +1,69 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QXYSERIES_P_H |
|
31 | 31 | #define QXYSERIES_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QXYSeries; |
|
38 | 38 | |
|
39 | 39 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
40 | 40 | { |
|
41 | 41 | Q_OBJECT |
|
42 | 42 | |
|
43 | 43 | public: |
|
44 | 44 | QXYSeriesPrivate(QXYSeries* q); |
|
45 | 45 | |
|
46 | 46 | void scaleDomain(Domain& domain); |
|
47 | 47 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | 48 | |
|
49 | 49 | Q_SIGNALS: |
|
50 | 50 | void updated(); |
|
51 | 51 | void pointReplaced(int index); |
|
52 | 52 | void pointRemoved(int index); |
|
53 | void pointsRemoved(int start, int end); | |
|
54 | 53 | void pointAdded(int index); |
|
55 | void pointsAdded(int start, int end); | |
|
56 | void reinitialized(); | |
|
57 | 54 | |
|
58 | 55 | protected: |
|
59 | 56 | QVector<QPointF> m_points; |
|
60 | 57 | QPen m_pen; |
|
61 | 58 | QBrush m_brush; |
|
62 | 59 | bool m_pointsVisible; |
|
63 | 60 | |
|
64 | 61 | private: |
|
65 | 62 | Q_DECLARE_PUBLIC(QXYSeries); |
|
66 | 63 | friend class QScatterSeries; |
|
67 | 64 | |
|
68 | 65 | }; |
|
69 | 66 | |
|
70 | 67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | 68 | |
|
72 | 69 | #endif |
@@ -1,21 +1,21 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/xychart.cpp \ |
|
6 | 6 | $$PWD/qxyseries.cpp \ |
|
7 | 7 | $$PWD/qxymodelmapper.cpp \ |
|
8 | 8 | $$PWD/qvxymodelmapper.cpp \ |
|
9 | 9 | $$PWD/qhxymodelmapper.cpp |
|
10 | 10 | |
|
11 | 11 | PRIVATE_HEADERS += \ |
|
12 | 12 | $$PWD/xychart_p.h \ |
|
13 | $$PWD/qxyseries_p.h | |
|
13 | $$PWD/qxyseries_p.h \ | |
|
14 | $$PWD/qxymodelmapper_p.h | |
|
14 | 15 | |
|
15 | 16 | |
|
16 | 17 | PUBLIC_HEADERS += \ |
|
17 | 18 | $$PWD/qxyseries.h \ |
|
18 | 19 | $$PWD/qxymodelmapper.h \ |
|
19 | 20 | $$PWD/qvxymodelmapper.h \ |
|
20 | 21 | $$PWD/qhxymodelmapper.h |
|
21 |
@@ -1,523 +1,524 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tablewidget.h" |
|
22 | 22 | #include <QGridLayout> |
|
23 | 23 | #include <QTableView> |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QStyledItemDelegate> |
|
26 | 26 | #include <QLineSeries> |
|
27 | 27 | #include <QSplineSeries> |
|
28 | 28 | #include <QScatterSeries> |
|
29 | #include <QXYModelMapper> | |
|
29 | #include <QVXYModelMapper> | |
|
30 | 30 | #include "customtablemodel.h" |
|
31 | 31 | #include <QPieSeries> |
|
32 | 32 | #include <QVPieModelMapper> |
|
33 | 33 | #include <QPieSlice> |
|
34 | 34 | #include <QAreaSeries> |
|
35 | 35 | #include <QBarSeries> |
|
36 | 36 | #include <QGroupedBarSeries> |
|
37 | 37 | #include <QBarSet> |
|
38 | 38 | #include <QBarModelMapper> |
|
39 | 39 | #include <QPushButton> |
|
40 | 40 | #include <QRadioButton> |
|
41 | 41 | #include <QLabel> |
|
42 | 42 | #include <QSpinBox> |
|
43 | 43 | #include <QTime> |
|
44 | 44 | #include <QHeaderView> |
|
45 | 45 | |
|
46 | 46 | TableWidget::TableWidget(QWidget *parent) |
|
47 | 47 | : QWidget(parent) |
|
48 | 48 | // specialPie(0) |
|
49 | 49 | { |
|
50 | 50 | setGeometry(1900, 100, 1000, 600); |
|
51 | 51 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
52 | 52 | // create simple model for storing data |
|
53 | 53 | // user's table data model |
|
54 | 54 | m_model = new CustomTableModel; |
|
55 | 55 | m_tableView = new QTableView; |
|
56 | 56 | m_tableView->setModel(m_model); |
|
57 | 57 | // m_tableView->setMinimumHeight(300); |
|
58 | 58 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
59 | 59 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
60 | 60 | |
|
61 | 61 | m_chart = new QChart; |
|
62 | 62 | m_chart->legend()->setVisible(true); |
|
63 | 63 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
64 | 64 | m_chartView = new QChartView(m_chart); |
|
65 | 65 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
66 | 66 | m_chartView->setMinimumSize(640, 480); |
|
67 | 67 | |
|
68 | 68 | // add, remove data buttons |
|
69 | 69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
70 | 70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
71 | 71 | |
|
72 | 72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
73 | 73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
74 | 74 | |
|
75 | 75 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
76 | 76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
77 | 77 | |
|
78 | 78 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
79 | 79 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
80 | 80 | |
|
81 | 81 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
82 | 82 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
83 | 83 | |
|
84 | 84 | QPushButton* specialPieButton = new QPushButton("Add slices using series API"); |
|
85 | 85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
86 | 86 | |
|
87 | 87 | QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API"); |
|
88 | 88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); |
|
89 | 89 | |
|
90 | 90 | QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); |
|
91 | 91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); |
|
92 | 92 | |
|
93 | 93 | |
|
94 |
|
|
|
94 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
|
95 | 95 | |
|
96 | 96 | // spin box for setting number of affected items (add, remove) |
|
97 | 97 | m_linesCountSpinBox = new QSpinBox; |
|
98 | 98 | m_linesCountSpinBox->setRange(1, 10); |
|
99 | 99 | m_linesCountSpinBox->setValue(1); |
|
100 | 100 | |
|
101 | 101 | // buttons layout |
|
102 | 102 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
103 |
|
|
|
104 |
|
|
|
103 | buttonsLayout->addWidget(spinBoxLabel); | |
|
104 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
|
105 | 105 | // buttonsLayout->addWidget(addRowAboveButton); |
|
106 | 106 | buttonsLayout->addWidget(addRowBelowButton); |
|
107 | 107 | buttonsLayout->addWidget(removeRowButton); |
|
108 | 108 | // buttonsLayout->addWidget(addColumnRightButton); |
|
109 | 109 | // buttonsLayout->addWidget(removeColumnButton); |
|
110 | 110 | buttonsLayout->addWidget(specialPieButton); |
|
111 | 111 | buttonsLayout->addWidget(specialPieButton2); |
|
112 | 112 | buttonsLayout->addWidget(specialPieButton3); |
|
113 | 113 | buttonsLayout->addStretch(); |
|
114 | 114 | |
|
115 | 115 | // chart type radio buttons |
|
116 | 116 | m_lineRadioButton = new QRadioButton("Line"); |
|
117 | 117 | m_splineRadioButton = new QRadioButton("Spline"); |
|
118 | 118 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
119 | 119 | m_pieRadioButton = new QRadioButton("Pie"); |
|
120 | 120 | m_areaRadioButton = new QRadioButton("Area"); |
|
121 | 121 | m_barRadioButton = new QRadioButton("Bar"); |
|
122 | 122 | |
|
123 | 123 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
124 | 124 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
125 | 125 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
126 | 126 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
127 | 127 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
128 | 128 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
129 | 129 | m_lineRadioButton->setChecked(true); |
|
130 | 130 | |
|
131 | 131 | // radio buttons layout |
|
132 | 132 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
133 | 133 | radioLayout->addWidget(m_lineRadioButton); |
|
134 | 134 | radioLayout->addWidget(m_splineRadioButton); |
|
135 | 135 | // radioLayout->addWidget(m_scatterRadioButton); |
|
136 | 136 | radioLayout->addWidget(m_pieRadioButton); |
|
137 | 137 | // radioLayout->addWidget(m_areaRadioButton); |
|
138 | 138 | radioLayout->addWidget(m_barRadioButton); |
|
139 | 139 | radioLayout->addStretch(); |
|
140 | 140 | |
|
141 | 141 | // create main layout |
|
142 | 142 | QGridLayout* mainLayout = new QGridLayout; |
|
143 | 143 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
144 | 144 | mainLayout->addLayout(radioLayout, 3, 0); |
|
145 | 145 | mainLayout->addWidget(m_tableView, 1, 0); |
|
146 | 146 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
147 | 147 | setLayout(mainLayout); |
|
148 | 148 | m_lineRadioButton->setFocus(); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void TableWidget::addRowAbove() |
|
152 | 152 | { |
|
153 | 153 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
154 | 154 | |
|
155 | 155 | } |
|
156 | 156 | |
|
157 | 157 | void TableWidget::addRowBelow() |
|
158 | 158 | { |
|
159 | 159 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
160 | 160 | |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | void TableWidget::removeRow() |
|
164 | 164 | { |
|
165 | 165 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void TableWidget::addColumnRight() |
|
169 | 169 | { |
|
170 | 170 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void TableWidget::removeColumn() |
|
174 | 174 | { |
|
175 | 175 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | void TableWidget::updateChartType(bool toggle) |
|
179 | 179 | { |
|
180 | 180 | // this if is needed, so that the function is only called once. |
|
181 | 181 | // For the radioButton that was enabled. |
|
182 | 182 | if (toggle) { |
|
183 | 183 | // specialPie = 0; |
|
184 | 184 | m_chart->removeAllSeries(); |
|
185 | 185 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
186 | 186 | // m_chart->axisY()->setNiceNumbersEnabled(false); |
|
187 | 187 | |
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
188 | // renable axes of the chart (pie hides them) | |
|
189 | // x axis | |
|
190 | QAxis *axis = m_chart->axisX(); | |
|
191 | axis->setAxisVisible(true); | |
|
192 | axis->setGridLineVisible(true); | |
|
193 | axis->setLabelsVisible(true); | |
|
194 | 194 | |
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
195 | // y axis | |
|
196 | axis = m_chart->axisY(); | |
|
197 | axis->setAxisVisible(true); | |
|
198 | axis->setGridLineVisible(true); | |
|
199 | axis->setLabelsVisible(true); | |
|
200 | 200 | |
|
201 |
|
|
|
201 | m_model->clearMapping(); | |
|
202 | 202 | |
|
203 | 203 | QString seriesColorHex = "#000000"; |
|
204 | 204 | // QPen pen; |
|
205 | 205 | // pen.setWidth(2); |
|
206 | 206 | |
|
207 | 207 | if (m_lineRadioButton->isChecked()) |
|
208 | 208 | { |
|
209 | 209 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
210 | 210 | |
|
211 |
|
|
|
212 |
|
|
|
213 | // m_series->setModel(m_model); | |
|
211 | // series 1 | |
|
212 | m_series = new QLineSeries(this); | |
|
214 | 213 | |
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
214 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
|
215 | mapper->setModel(m_model); | |
|
216 | mapper->setSeries(m_series); | |
|
217 | mapper->setXColumn(0); | |
|
218 | mapper->setYColumn(1); | |
|
219 | mapper->setFirst(3); | |
|
219 | 220 | // mapper->setCount(4); |
|
220 | // m_series->setModelMapper(mapper); | |
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
221 | ||
|
222 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
|
223 | // m_series->setModelMappingRange(3, 4); | |
|
224 | m_chart->addSeries(m_series); | |
|
225 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
226 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
|
226 | 227 | |
|
227 | 228 | // // series 2 |
|
228 | 229 | // m_series = new QLineSeries; |
|
229 | 230 | // m_series->setModel(m_model); |
|
230 | 231 | |
|
231 | 232 | // mapper = new QXYModelMapper; |
|
232 | 233 | // mapper->setMapX(3); |
|
233 | 234 | // mapper->setMapY(4); |
|
234 | 235 | // // mapper->setFirst(3); |
|
235 | 236 | // // mapper->setCount(4); |
|
236 | 237 | // m_series->setModelMapper(mapper); |
|
237 | 238 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
238 | 239 | // m_chart->addSeries(m_series); |
|
239 | 240 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
240 | 241 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
241 | 242 | |
|
242 | 243 | // // series 3 |
|
243 | 244 | // m_series = new QLineSeries; |
|
244 | 245 | // m_series->setModel(m_model); |
|
245 | 246 | |
|
246 | 247 | // mapper = new QXYModelMapper; |
|
247 | 248 | // mapper->setMapX(5); |
|
248 | 249 | // mapper->setMapY(6); |
|
249 | 250 | // mapper->setFirst(2); |
|
250 | 251 | // mapper->setCount(-1); |
|
251 | 252 | // m_series->setModelMapper(mapper); |
|
252 | 253 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
253 | 254 | // // m_series->setModelMappingRange(2, -1); |
|
254 | 255 | // m_chart->addSeries(m_series); |
|
255 | 256 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
256 | 257 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
257 | 258 | } |
|
258 | 259 | else if (m_splineRadioButton->isChecked()) |
|
259 | 260 | { |
|
260 | 261 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
261 | 262 | |
|
262 | 263 | // // series 1 |
|
263 | 264 | // m_series = new QSplineSeries; |
|
264 | 265 | // m_series->setModel(m_model); |
|
265 | 266 | |
|
266 | 267 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
267 | 268 | // mapper->setMapX(0); |
|
268 | 269 | // mapper->setMapY(1); |
|
269 | 270 | // mapper->setFirst(0); |
|
270 | 271 | // mapper->setCount(-1); |
|
271 | 272 | |
|
272 | 273 | // m_series->setModelMapper(mapper); |
|
273 | 274 | |
|
274 | 275 | // m_chart->addSeries(m_series); |
|
275 | 276 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
276 | 277 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
277 | 278 | |
|
278 | 279 | // // series 2 |
|
279 | 280 | // m_series = new QSplineSeries; |
|
280 | 281 | // m_series->setModel(m_model); |
|
281 | 282 | |
|
282 | 283 | // mapper = new QXYModelMapper; |
|
283 | 284 | // mapper->setMapX(2); |
|
284 | 285 | // mapper->setMapY(3); |
|
285 | 286 | // mapper->setFirst(2); |
|
286 | 287 | // mapper->setCount(4); |
|
287 | 288 | |
|
288 | 289 | // m_series->setModelMapper(mapper); |
|
289 | 290 | |
|
290 | 291 | // m_chart->addSeries(m_series); |
|
291 | 292 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
292 | 293 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
293 | 294 | |
|
294 | 295 | // // series 3 |
|
295 | 296 | // m_series = new QSplineSeries; |
|
296 | 297 | // m_series->setModel(m_model); |
|
297 | 298 | |
|
298 | 299 | // mapper = new QXYModelMapper; |
|
299 | 300 | // mapper->setMapX(4); |
|
300 | 301 | // mapper->setMapY(5); |
|
301 | 302 | // mapper->setFirst(2); |
|
302 | 303 | // mapper->setCount(-1); |
|
303 | 304 | |
|
304 | 305 | // m_series->setModelMapper(mapper); |
|
305 | 306 | |
|
306 | 307 | // m_chart->addSeries(m_series); |
|
307 | 308 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
308 | 309 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
309 | 310 | } |
|
310 | 311 | // else if (m_scatterRadioButton->isChecked()) |
|
311 | 312 | // { |
|
312 | 313 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
313 | 314 | |
|
314 | 315 | // // series 1 |
|
315 | 316 | // m_series = new QScatterSeries; |
|
316 | 317 | // m_series->setModel(m_model); |
|
317 | 318 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
318 | 319 | // // m_series->setModelMappingRange(2, 0); |
|
319 | 320 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
320 | 321 | // m_chart->addSeries(m_series); |
|
321 | 322 | |
|
322 | 323 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
323 | 324 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
324 | 325 | |
|
325 | 326 | // // series 2 |
|
326 | 327 | // m_series = new QScatterSeries; |
|
327 | 328 | // m_series->setModel(m_model); |
|
328 | 329 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
329 | 330 | // // m_series->setModelMappingRange(1, 6); |
|
330 | 331 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
331 | 332 | // m_chart->addSeries(m_series); |
|
332 | 333 | |
|
333 | 334 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
334 | 335 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
335 | 336 | |
|
336 | 337 | // // series 3 |
|
337 | 338 | // m_series = new QScatterSeries; |
|
338 | 339 | // m_series->setModel(m_model); |
|
339 | 340 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
340 | 341 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
341 | 342 | // m_chart->addSeries(m_series); |
|
342 | 343 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
343 | 344 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
344 | 345 | // } |
|
345 | 346 | else if (m_pieRadioButton->isChecked()) |
|
346 | 347 | { |
|
347 | 348 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
348 | 349 | |
|
349 | 350 | // pie 1 |
|
350 | 351 | m_pieSeries = new QPieSeries; |
|
351 | 352 | |
|
352 | 353 | m_pieMapper = new QVPieModelMapper; |
|
353 | 354 | m_pieMapper->setValuesColumn(1); |
|
354 | 355 | m_pieMapper->setLabelsColumn(7); |
|
355 | 356 | m_pieMapper->setSeries(m_pieSeries); |
|
356 | 357 | m_pieMapper->setModel(m_model); |
|
357 | m_pieMapper->setFirst(2); | |
|
358 | // m_pieMapper->setFirst(2); | |
|
358 | 359 | // m_pieMapper->setCount(5); |
|
359 | 360 | // pieSeries->setModelMapper(mapper); |
|
360 | 361 | |
|
361 | 362 | m_pieSeries->setLabelsVisible(true); |
|
362 | 363 | m_pieSeries->setPieSize(0.35); |
|
363 | 364 | m_pieSeries->setHorizontalPosition(0.25); |
|
364 | 365 | m_pieSeries->setVerticalPosition(0.35); |
|
365 | 366 | |
|
366 | 367 | m_chart->addSeries(m_pieSeries); |
|
367 | 368 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
368 | 369 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); |
|
369 | 370 | |
|
370 | 371 | |
|
371 | 372 | // pieSeries->slices().at(0)->setValue(400); |
|
372 | 373 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
373 | 374 | |
|
374 | 375 | // pie 2 |
|
375 | 376 | m_pieSeries2 = new QPieSeries; |
|
376 | 377 | |
|
377 | 378 | m_pieMapper = new QVPieModelMapper; |
|
378 | 379 | m_pieMapper->setValuesColumn(0); |
|
379 | 380 | m_pieMapper->setLabelsColumn(7); |
|
380 | m_pieMapper->setSeries(m_pieSeries2); | |
|
381 | 381 | m_pieMapper->setModel(m_model); |
|
382 |
m_pieMapper->set |
|
|
382 | m_pieMapper->setSeries(m_pieSeries2); | |
|
383 | // m_pieMapper->setFirst(2); | |
|
383 | 384 | |
|
384 | 385 | m_pieSeries2->setLabelsVisible(true); |
|
385 | 386 | m_pieSeries2->setPieSize(0.35); |
|
386 | 387 | m_pieSeries2->setHorizontalPosition(0.75); |
|
387 | 388 | m_pieSeries2->setVerticalPosition(0.65); |
|
388 | 389 | m_chart->addSeries(m_pieSeries2); |
|
389 | 390 | seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
390 | 391 | m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); |
|
391 | 392 | |
|
392 | 393 | // // pie 3 |
|
393 | 394 | // pieSeries = new QPieSeries; |
|
394 | 395 | // pieSeries->setModel(m_model); |
|
395 | 396 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
396 | 397 | // pieSeries->setLabelsVisible(true); |
|
397 | 398 | // pieSeries->setPieSize(0.35); |
|
398 | 399 | // pieSeries->setHorizontalPosition(0.5); |
|
399 | 400 | // pieSeries->setVerticalPosition(0.75); |
|
400 | 401 | // m_chart->addSeries(pieSeries); |
|
401 | 402 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
402 | 403 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
403 | 404 | |
|
404 | 405 | // // special pie |
|
405 | 406 | // specialPie = new QPieSeries; |
|
406 | 407 | // specialPie->append(17, "1"); |
|
407 | 408 | // specialPie->append(45, "2"); |
|
408 | 409 | // specialPie->append(77, "3"); |
|
409 | 410 | // specialPie->append(37, "4"); |
|
410 | 411 | // specialPie->append(27, "5"); |
|
411 | 412 | // specialPie->append(47, "6"); |
|
412 | 413 | // specialPie->setPieSize(0.35); |
|
413 | 414 | // specialPie->setHorizontalPosition(0.8); |
|
414 | 415 | // specialPie->setVerticalPosition(0.75); |
|
415 | 416 | // specialPie->setLabelsVisible(true); |
|
416 | 417 | // m_chart->addSeries(specialPie); |
|
417 | 418 | } |
|
418 | 419 | // else if (m_areaRadioButton->isChecked()) |
|
419 | 420 | // { |
|
420 | 421 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
421 | 422 | |
|
422 | 423 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
423 | 424 | // upperLineSeries->setModel(m_model); |
|
424 | 425 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
425 | 426 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
426 | 427 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
427 | 428 | // lowerLineSeries->setModel(m_model); |
|
428 | 429 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
429 | 430 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
430 | 431 | // m_chart->addSeries(areaSeries); |
|
431 | 432 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
432 | 433 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
433 | 434 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
434 | 435 | // } |
|
435 | 436 | else if (m_barRadioButton->isChecked()) |
|
436 | 437 | { |
|
437 | 438 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
438 | 439 | |
|
439 | 440 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
440 | 441 | // barSeries->setCategories(QStringList()); |
|
441 | 442 | // barSeries->setModel(m_model); |
|
442 | 443 | // // barSeries->setModelMappingRange(2, 5); |
|
443 | 444 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
444 | 445 | |
|
445 | 446 | // QBarModelMapper *mapper = new QBarModelMapper; |
|
446 | 447 | // mapper->setMapCategories(5); |
|
447 | 448 | // mapper->setMapBarBottom(2); |
|
448 | 449 | // mapper->setMapBarTop(4); |
|
449 | 450 | // barSeries->setModelMapper(mapper); |
|
450 | 451 | // m_chart->addSeries(barSeries); |
|
451 | 452 | // QList<QBarSet*> barsets = barSeries->barSets(); |
|
452 | 453 | // for (int i = 0; i < barsets.count(); i++) { |
|
453 | 454 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
454 | 455 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
455 | 456 | // } |
|
456 | 457 | } |
|
457 | 458 | |
|
458 | 459 | |
|
459 | 460 | if (!m_barRadioButton->isChecked()) { |
|
460 | 461 | m_chart->axisX()->setRange(0, 500); |
|
461 | 462 | m_chart->axisY()->setRange(0, 220); |
|
462 | 463 | } |
|
463 | 464 | m_chart->legend()->setVisible(true); |
|
464 | 465 | |
|
465 | 466 | // repaint table view colors |
|
466 | 467 | m_tableView->repaint(); |
|
467 | 468 | m_tableView->setFocus(); |
|
468 | 469 | } |
|
469 | 470 | } |
|
470 | 471 | |
|
471 | 472 | void TableWidget::testPie() |
|
472 | 473 | { |
|
473 | 474 | // m_pieMapper->setCount(-1); |
|
474 | 475 | QPieSlice *slice = new QPieSlice("Hehe", 145); |
|
475 | 476 | slice->setLabelVisible(); |
|
476 | 477 | m_pieSeries->append(slice); |
|
477 | 478 | |
|
478 | 479 | slice = new QPieSlice("Hoho", 34); |
|
479 | 480 | slice->setLabelVisible(); |
|
480 | 481 | m_pieSeries->append(slice); |
|
481 | 482 | // m_series->modelMapper()->setMapX(4); |
|
482 | 483 | // m_tableView->setColumnWidth(10, 250); |
|
483 | 484 | // if (specialPie) { |
|
484 | 485 | // specialPie->remove(specialPie->slices().at(2)); |
|
485 | 486 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
486 | 487 | // specialPie->append(4, "heloo"); |
|
487 | 488 | // } |
|
488 | 489 | } |
|
489 | 490 | |
|
490 | 491 | void TableWidget::testPie2() |
|
491 | 492 | { |
|
492 | 493 | QPieSlice *slice; |
|
493 | 494 | if (m_pieSeries->count() > 0) { |
|
494 | 495 | slice = m_pieSeries->slices().last(); |
|
495 | 496 | m_pieSeries->remove(slice); |
|
496 | 497 | } |
|
497 | 498 | |
|
498 | 499 | if (m_pieSeries->count() > 0) { |
|
499 | 500 | slice = m_pieSeries->slices().first(); |
|
500 | 501 | m_pieSeries->remove(slice); |
|
501 | 502 | } |
|
502 | 503 | } |
|
503 | 504 | |
|
504 | 505 | void TableWidget::testPie3() |
|
505 | 506 | { |
|
506 | 507 | QPieSlice *slice; |
|
507 | 508 | if (m_pieSeries->count() > 0) { |
|
508 | 509 | slice = m_pieSeries->slices().last(); |
|
509 | 510 | slice->setLabel("Dalej"); |
|
510 | 511 | slice->setValue(222); |
|
511 | 512 | } |
|
512 | 513 | |
|
513 | 514 | if (m_pieSeries->count() > 0) { |
|
514 | 515 | slice = m_pieSeries->slices().first(); |
|
515 | 516 | slice->setLabel("Prawie"); |
|
516 | 517 | slice->setValue(111); |
|
517 | 518 | } |
|
518 | 519 | } |
|
519 | 520 | |
|
520 | 521 | TableWidget::~TableWidget() |
|
521 | 522 | { |
|
522 | 523 | |
|
523 | 524 | } |
General Comments 0
You need to be logged in to leave comments.
Login now