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