@@ -1,465 +1,493 | |||||
1 | #include "qpiemodelmapper_p.h" |
|
1 | #include "qpiemodelmapper_p.h" | |
2 | #include "qpiemodelmapper.h" |
|
2 | #include "qpiemodelmapper.h" | |
3 | #include "qpieseries.h" |
|
3 | #include "qpieseries.h" | |
4 | #include "qpieslice.h" |
|
4 | #include "qpieslice.h" | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | QPieModelMapper::QPieModelMapper(QObject *parent) : |
|
9 | QPieModelMapper::QPieModelMapper(QObject *parent) : | |
10 | QObject(parent), |
|
10 | QObject(parent), | |
11 | d_ptr(new QPieModelMapperPrivate(this)) |
|
11 | d_ptr(new QPieModelMapperPrivate(this)) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | QAbstractItemModel* QPieModelMapper::model() const |
|
15 | QAbstractItemModel* QPieModelMapper::model() const | |
16 | { |
|
16 | { | |
17 | Q_D(const QPieModelMapper); |
|
17 | Q_D(const QPieModelMapper); | |
18 | return d->m_model; |
|
18 | return d->m_model; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
21 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
22 | { |
|
22 | { | |
23 | if (model == 0) |
|
23 | if (model == 0) | |
24 | return; |
|
24 | return; | |
25 |
|
25 | |||
26 | Q_D(QPieModelMapper); |
|
26 | Q_D(QPieModelMapper); | |
27 | if (d->m_model) { |
|
27 | if (d->m_model) { | |
28 | disconnect(d->m_model, 0, d, 0); |
|
28 | disconnect(d->m_model, 0, d, 0); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | d->m_model = model; |
|
31 | d->m_model = model; | |
32 | d->initializePieFromModel(); |
|
32 | d->initializePieFromModel(); | |
33 | // connect signals from the model |
|
33 | // connect signals from the model | |
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QPieSeries* QPieModelMapper::series() const |
|
41 | QPieSeries* QPieModelMapper::series() const | |
42 | { |
|
42 | { | |
43 | Q_D(const QPieModelMapper); |
|
43 | Q_D(const QPieModelMapper); | |
44 | return d->m_series; |
|
44 | return d->m_series; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
47 | void QPieModelMapper::setSeries(QPieSeries *series) | |
48 | { |
|
48 | { | |
49 | if (series == 0) |
|
49 | if (series == 0) | |
50 | return; |
|
50 | return; | |
51 |
|
51 | |||
52 | Q_D(QPieModelMapper); |
|
52 | Q_D(QPieModelMapper); | |
53 | if (d->m_series) { |
|
53 | if (d->m_series) { | |
54 | disconnect(d->m_series, 0, d, 0); |
|
54 | disconnect(d->m_series, 0, d, 0); | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | d->m_series = series; |
|
57 | d->m_series = series; | |
58 | d->initializePieFromModel(); |
|
58 | d->initializePieFromModel(); | |
59 | // connect the signals from the series |
|
59 | // connect the signals from the series | |
60 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
60 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); | |
61 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
61 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); | |
62 | // connect(d->m_model, SIGNAL(), d, SLOT()); |
|
62 | // connect(d->m_model, SIGNAL(), d, SLOT()); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QPieModelMapper::first() const |
|
65 | int QPieModelMapper::first() const | |
66 | { |
|
66 | { | |
67 | Q_D(const QPieModelMapper); |
|
67 | Q_D(const QPieModelMapper); | |
68 | return d->m_first; |
|
68 | return d->m_first; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void QPieModelMapper::setFirst(int first) |
|
71 | void QPieModelMapper::setFirst(int first) | |
72 | { |
|
72 | { | |
73 | Q_D(QPieModelMapper); |
|
73 | Q_D(QPieModelMapper); | |
74 | d->m_first = qMax(first, 0); |
|
74 | d->m_first = qMax(first, 0); | |
75 | d->initializePieFromModel(); |
|
75 | d->initializePieFromModel(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | int QPieModelMapper::count() const |
|
78 | int QPieModelMapper::count() const | |
79 | { |
|
79 | { | |
80 | Q_D(const QPieModelMapper); |
|
80 | Q_D(const QPieModelMapper); | |
81 | return d->m_count; |
|
81 | return d->m_count; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void QPieModelMapper::setCount(int count) |
|
84 | void QPieModelMapper::setCount(int count) | |
85 | { |
|
85 | { | |
86 | Q_D(QPieModelMapper); |
|
86 | Q_D(QPieModelMapper); | |
87 | d->m_count = qMax(count, -1); |
|
87 | d->m_count = qMax(count, -1); | |
88 | d->initializePieFromModel(); |
|
88 | d->initializePieFromModel(); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | Qt::Orientation QPieModelMapper::orientation() const |
|
91 | Qt::Orientation QPieModelMapper::orientation() const | |
92 | { |
|
92 | { | |
93 | Q_D(const QPieModelMapper); |
|
93 | Q_D(const QPieModelMapper); | |
94 | return d->m_orientation; |
|
94 | return d->m_orientation; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
97 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
98 | { |
|
98 | { | |
99 | Q_D(QPieModelMapper); |
|
99 | Q_D(QPieModelMapper); | |
100 | d->m_orientation = orientation; |
|
100 | d->m_orientation = orientation; | |
101 | d->initializePieFromModel(); |
|
101 | d->initializePieFromModel(); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | int QPieModelMapper::valuesIndex() const |
|
104 | int QPieModelMapper::valuesIndex() const | |
105 | { |
|
105 | { | |
106 | Q_D(const QPieModelMapper); |
|
106 | Q_D(const QPieModelMapper); | |
107 | return d->m_valuesIndex; |
|
107 | return d->m_valuesIndex; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void QPieModelMapper::setValuesIndex(int valuesIndex) |
|
110 | void QPieModelMapper::setValuesIndex(int valuesIndex) | |
111 | { |
|
111 | { | |
112 | Q_D(QPieModelMapper); |
|
112 | Q_D(QPieModelMapper); | |
113 | d->m_valuesIndex = qMax(-1, valuesIndex); |
|
113 | d->m_valuesIndex = qMax(-1, valuesIndex); | |
114 | d->initializePieFromModel(); |
|
114 | d->initializePieFromModel(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | int QPieModelMapper::labelsIndex() const |
|
117 | int QPieModelMapper::labelsIndex() const | |
118 | { |
|
118 | { | |
119 | Q_D(const QPieModelMapper); |
|
119 | Q_D(const QPieModelMapper); | |
120 | return d->m_labelsIndex; |
|
120 | return d->m_labelsIndex; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void QPieModelMapper::setLabelsIndex(int labelsIndex) |
|
123 | void QPieModelMapper::setLabelsIndex(int labelsIndex) | |
124 | { |
|
124 | { | |
125 | Q_D(QPieModelMapper); |
|
125 | Q_D(QPieModelMapper); | |
126 | d->m_labelsIndex = qMax(-1, labelsIndex); |
|
126 | d->m_labelsIndex = qMax(-1, labelsIndex); | |
127 | d->initializePieFromModel(); |
|
127 | d->initializePieFromModel(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void QPieModelMapper::reset() |
|
130 | void QPieModelMapper::reset() | |
131 | { |
|
131 | { | |
132 | Q_D(QPieModelMapper); |
|
132 | Q_D(QPieModelMapper); | |
133 | d->m_first = 0; |
|
133 | d->m_first = 0; | |
134 | d->m_count = -1; |
|
134 | d->m_count = -1; | |
135 | d->m_orientation = Qt::Vertical; |
|
135 | d->m_orientation = Qt::Vertical; | |
136 | d->m_valuesIndex = -1; |
|
136 | d->m_valuesIndex = -1; | |
137 | d->m_labelsIndex = -1; |
|
137 | d->m_labelsIndex = -1; | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
141 |
|
141 | |||
142 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
142 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
143 | m_series(0), |
|
143 | m_series(0), | |
144 | m_model(0), |
|
144 | m_model(0), | |
145 | m_first(0), |
|
145 | m_first(0), | |
146 | m_count(-1), |
|
146 | m_count(-1), | |
147 | m_orientation(Qt::Vertical), |
|
147 | m_orientation(Qt::Vertical), | |
148 | m_valuesIndex(-1), |
|
148 | m_valuesIndex(-1), | |
149 | m_labelsIndex(-1), |
|
149 | m_labelsIndex(-1), | |
150 | m_seriesSignalsBlock(false), |
|
150 | m_seriesSignalsBlock(false), | |
151 | m_modelSignalsBlock(false), |
|
151 | m_modelSignalsBlock(false), | |
152 | q_ptr(q) |
|
152 | q_ptr(q) | |
153 | { |
|
153 | { | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
156 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |
157 | { |
|
157 | { | |
158 | m_modelSignalsBlock = block; |
|
158 | m_modelSignalsBlock = block; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
161 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |
162 | { |
|
162 | { | |
163 | m_seriesSignalsBlock = block; |
|
163 | m_seriesSignalsBlock = block; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
167 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
168 | { |
|
168 | { | |
169 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { |
|
169 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { | |
170 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) |
|
170 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) | |
171 | return m_series->slices().at(index.row() - m_first); |
|
171 | return m_series->slices().at(index.row() - m_first); | |
172 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { |
|
172 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { | |
173 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
173 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
174 | return m_series->slices().at(index.column() - m_first); |
|
174 | return m_series->slices().at(index.column() - m_first); | |
175 | } |
|
175 | } | |
176 | return 0; // This part of model has not been mapped to any slice |
|
176 | return 0; // This part of model has not been mapped to any slice | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
179 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
180 | { |
|
180 | { | |
181 | if (m_count != -1 && slicePos >= m_count) |
|
181 | if (m_count != -1 && slicePos >= m_count) | |
182 | return QModelIndex(); // invalid |
|
182 | return QModelIndex(); // invalid | |
183 |
|
183 | |||
184 | if (m_orientation == Qt::Vertical) |
|
184 | if (m_orientation == Qt::Vertical) | |
185 | return m_model->index(slicePos + m_first, m_valuesIndex); |
|
185 | return m_model->index(slicePos + m_first, m_valuesIndex); | |
186 | else |
|
186 | else | |
187 | return m_model->index(m_valuesIndex, slicePos + m_first); |
|
187 | return m_model->index(m_valuesIndex, slicePos + m_first); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
190 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
191 | { |
|
191 | { | |
192 | if (m_count != -1 && slicePos >= m_count) |
|
192 | if (m_count != -1 && slicePos >= m_count) | |
193 | return QModelIndex(); // invalid |
|
193 | return QModelIndex(); // invalid | |
194 |
|
194 | |||
195 | if (m_orientation == Qt::Vertical) |
|
195 | if (m_orientation == Qt::Vertical) | |
196 | return m_model->index(slicePos + m_first, m_labelsIndex); |
|
196 | return m_model->index(slicePos + m_first, m_labelsIndex); | |
197 | else |
|
197 | else | |
198 | return m_model->index(m_labelsIndex, slicePos + m_first); |
|
198 | return m_model->index(m_labelsIndex, slicePos + m_first); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
|
201 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const | |||
|
202 | { | |||
|
203 | if (m_orientation == Qt::Vertical && index.column() == m_labelsIndex) | |||
|
204 | return true; | |||
|
205 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsIndex) | |||
|
206 | return true; | |||
|
207 | ||||
|
208 | return false; | |||
|
209 | } | |||
|
210 | ||||
|
211 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const | |||
|
212 | { | |||
|
213 | if (m_orientation == Qt::Vertical && index.column() == m_valuesIndex) | |||
|
214 | return true; | |||
|
215 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesIndex) | |||
|
216 | return true; | |||
|
217 | ||||
|
218 | return false; | |||
|
219 | } | |||
|
220 | ||||
201 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) |
|
221 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
202 | { |
|
222 | { | |
203 | if (m_seriesSignalsBlock) |
|
223 | if (m_seriesSignalsBlock) | |
204 | return; |
|
224 | return; | |
205 |
|
225 | |||
206 | if (slices.count() == 0) |
|
226 | if (slices.count() == 0) | |
207 | return; |
|
227 | return; | |
208 |
|
228 | |||
209 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
229 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |
210 | if (firstIndex == -1) |
|
230 | if (firstIndex == -1) | |
211 | return; |
|
231 | return; | |
212 |
|
232 | |||
213 | if (m_count != -1) |
|
233 | if (m_count != -1) | |
214 | m_count += slices.count(); |
|
234 | m_count += slices.count(); | |
215 |
|
235 | |||
216 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
236 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
217 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
237 | m_slices.insert(i, slices.at(i - firstIndex)); | |
218 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
238 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
219 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
239 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
220 | } |
|
240 | } | |
221 |
|
241 | |||
222 | blockModelSignals(); |
|
242 | blockModelSignals(); | |
223 | if (m_orientation == Qt::Vertical) |
|
243 | if (m_orientation == Qt::Vertical) | |
224 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
244 | m_model->insertRows(firstIndex + m_first, slices.count()); | |
225 | else |
|
245 | else | |
226 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
246 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |
227 |
|
247 | |||
228 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
248 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
229 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
249 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |
230 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
250 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |
231 | } |
|
251 | } | |
232 | blockModelSignals(false); |
|
252 | blockModelSignals(false); | |
233 | } |
|
253 | } | |
234 |
|
254 | |||
235 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) |
|
255 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
236 | { |
|
256 | { | |
237 | if (m_seriesSignalsBlock) |
|
257 | if (m_seriesSignalsBlock) | |
238 | return; |
|
258 | return; | |
239 |
|
259 | |||
240 | if (slices.count() == 0) |
|
260 | if (slices.count() == 0) | |
241 | return; |
|
261 | return; | |
242 |
|
262 | |||
243 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
263 | int firstIndex = m_slices.indexOf(slices.at(0)); | |
244 | if (firstIndex == -1) |
|
264 | if (firstIndex == -1) | |
245 | return; |
|
265 | return; | |
246 |
|
266 | |||
247 | if (m_count != -1) |
|
267 | if (m_count != -1) | |
248 | m_count -= slices.count(); |
|
268 | m_count -= slices.count(); | |
249 |
|
269 | |||
250 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
270 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) | |
251 | m_slices.removeAt(i); |
|
271 | m_slices.removeAt(i); | |
252 |
|
272 | |||
253 | blockModelSignals(); |
|
273 | blockModelSignals(); | |
254 | if (m_orientation == Qt::Vertical) |
|
274 | if (m_orientation == Qt::Vertical) | |
255 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
275 | m_model->removeRows(firstIndex + m_first, slices.count()); | |
256 | else |
|
276 | else | |
257 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
277 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |
258 | blockModelSignals(false); |
|
278 | blockModelSignals(false); | |
259 | } |
|
279 | } | |
260 |
|
280 | |||
261 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
281 | void QPieModelMapperPrivate::sliceLabelChanged() | |
262 | { |
|
282 | { | |
263 | if (m_seriesSignalsBlock) |
|
283 | if (m_seriesSignalsBlock) | |
264 | return; |
|
284 | return; | |
265 |
|
285 | |||
266 | blockModelSignals(); |
|
286 | blockModelSignals(); | |
267 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
287 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
268 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
288 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); | |
269 | blockModelSignals(false); |
|
289 | blockModelSignals(false); | |
270 | } |
|
290 | } | |
271 |
|
291 | |||
272 | void QPieModelMapperPrivate::sliceValueChanged() |
|
292 | void QPieModelMapperPrivate::sliceValueChanged() | |
273 | { |
|
293 | { | |
274 | if (m_seriesSignalsBlock) |
|
294 | if (m_seriesSignalsBlock) | |
275 | return; |
|
295 | return; | |
276 |
|
296 | |||
277 | blockModelSignals(); |
|
297 | blockModelSignals(); | |
278 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
298 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
279 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
299 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); | |
280 | blockModelSignals(false); |
|
300 | blockModelSignals(false); | |
281 | } |
|
301 | } | |
282 |
|
302 | |||
283 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
303 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
284 | { |
|
304 | { | |
285 | if (m_modelSignalsBlock) |
|
305 | if (m_modelSignalsBlock) | |
286 | return; |
|
306 | return; | |
287 |
|
307 | |||
288 | blockSeriesSignals(); |
|
308 | blockSeriesSignals(); | |
289 | QModelIndex index; |
|
309 | QModelIndex index; | |
290 | QPieSlice *slice; |
|
310 | QPieSlice *slice; | |
291 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
311 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
292 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
312 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
293 | index = topLeft.sibling(row, column); |
|
313 | index = topLeft.sibling(row, column); | |
294 | slice = pieSlice(index); |
|
314 | slice = pieSlice(index); | |
295 | if (slice) { |
|
315 | if (slice) { | |
296 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
316 | if (isValueIndex(index)) | |
297 |
slice->set |
|
317 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
|
318 | if (isLabelIndex(index)) | |||
|
319 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |||
298 | } |
|
320 | } | |
299 | } |
|
321 | } | |
300 | } |
|
322 | } | |
301 | blockSeriesSignals(false); |
|
323 | blockSeriesSignals(false); | |
302 | } |
|
324 | } | |
303 |
|
325 | |||
304 |
|
326 | |||
305 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
327 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
306 | { |
|
328 | { | |
307 | Q_UNUSED(parent); |
|
329 | Q_UNUSED(parent); | |
308 | if (m_modelSignalsBlock) |
|
330 | if (m_modelSignalsBlock) | |
309 | return; |
|
331 | return; | |
310 |
|
332 | |||
311 | blockSeriesSignals(); |
|
333 | blockSeriesSignals(); | |
312 | if (m_orientation == Qt::Vertical) |
|
334 | if (m_orientation == Qt::Vertical) | |
313 | insertData(start, end); |
|
335 | insertData(start, end); | |
314 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
336 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
315 | initializePieFromModel(); |
|
337 | initializePieFromModel(); | |
316 | blockSeriesSignals(false); |
|
338 | blockSeriesSignals(false); | |
317 | } |
|
339 | } | |
318 |
|
340 | |||
319 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
341 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
320 | { |
|
342 | { | |
321 | Q_UNUSED(parent); |
|
343 | Q_UNUSED(parent); | |
322 | if (m_modelSignalsBlock) |
|
344 | if (m_modelSignalsBlock) | |
323 | return; |
|
345 | return; | |
324 |
|
346 | |||
325 | blockSeriesSignals(); |
|
347 | blockSeriesSignals(); | |
326 | if (m_orientation == Qt::Vertical) |
|
348 | if (m_orientation == Qt::Vertical) | |
327 | removeData(start, end); |
|
349 | removeData(start, end); | |
328 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
350 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
329 | initializePieFromModel(); |
|
351 | initializePieFromModel(); | |
330 | blockSeriesSignals(false); |
|
352 | blockSeriesSignals(false); | |
331 | } |
|
353 | } | |
332 |
|
354 | |||
333 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
355 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
334 | { |
|
356 | { | |
335 | Q_UNUSED(parent); |
|
357 | Q_UNUSED(parent); | |
336 | if (m_modelSignalsBlock) |
|
358 | if (m_modelSignalsBlock) | |
337 | return; |
|
359 | return; | |
338 |
|
360 | |||
339 | blockSeriesSignals(); |
|
361 | blockSeriesSignals(); | |
340 | if (m_orientation == Qt::Horizontal) |
|
362 | if (m_orientation == Qt::Horizontal) | |
341 | insertData(start, end); |
|
363 | insertData(start, end); | |
342 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
364 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
343 | initializePieFromModel(); |
|
365 | initializePieFromModel(); | |
344 | blockSeriesSignals(false); |
|
366 | blockSeriesSignals(false); | |
345 | } |
|
367 | } | |
346 |
|
368 | |||
347 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
369 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
348 | { |
|
370 | { | |
349 | Q_UNUSED(parent); |
|
371 | Q_UNUSED(parent); | |
350 | if (m_modelSignalsBlock) |
|
372 | if (m_modelSignalsBlock) | |
351 | return; |
|
373 | return; | |
352 |
|
374 | |||
353 | blockSeriesSignals(); |
|
375 | blockSeriesSignals(); | |
354 | if (m_orientation == Qt::Horizontal) |
|
376 | if (m_orientation == Qt::Horizontal) | |
355 | removeData(start, end); |
|
377 | removeData(start, end); | |
356 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
378 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
357 | initializePieFromModel(); |
|
379 | initializePieFromModel(); | |
358 | blockSeriesSignals(false); |
|
380 | blockSeriesSignals(false); | |
359 | } |
|
381 | } | |
360 |
|
382 | |||
361 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
383 | void QPieModelMapperPrivate::insertData(int start, int end) | |
362 | { |
|
384 | { | |
|
385 | if (m_model == 0 || m_series == 0) | |||
|
386 | return; | |||
|
387 | ||||
363 | if (m_count != -1 && start >= m_first + m_count) { |
|
388 | if (m_count != -1 && start >= m_first + m_count) { | |
364 | return; |
|
389 | return; | |
365 | } else { |
|
390 | } else { | |
366 | int addedCount = end - start + 1; |
|
391 | int addedCount = end - start + 1; | |
367 | if (m_count != -1 && addedCount > m_count) |
|
392 | if (m_count != -1 && addedCount > m_count) | |
368 | addedCount = m_count; |
|
393 | addedCount = m_count; | |
369 | int first = qMax(start, m_first); |
|
394 | int first = qMax(start, m_first); | |
370 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
395 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
371 | for (int i = first; i <= last; i++) { |
|
396 | for (int i = first; i <= last; i++) { | |
372 | QPieSlice *slice = new QPieSlice; |
|
397 | QPieSlice *slice = new QPieSlice; | |
373 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
398 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
374 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); |
|
399 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); | |
375 | slice->setLabelVisible(); |
|
400 | slice->setLabelVisible(); | |
376 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
401 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
377 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
402 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
378 | m_series->insert(i - m_first, slice); |
|
403 | m_series->insert(i - m_first, slice); | |
379 | m_slices.insert(i - m_first, slice); |
|
404 | m_slices.insert(i - m_first, slice); | |
380 | } |
|
405 | } | |
381 |
|
406 | |||
382 | // remove excess of slices (abouve m_count) |
|
407 | // remove excess of slices (abouve m_count) | |
383 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
408 | if (m_count != -1 && m_series->slices().size() > m_count) | |
384 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
409 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { | |
385 | m_series->remove(m_series->slices().at(i)); |
|
410 | m_series->remove(m_series->slices().at(i)); | |
386 | m_slices.removeAt(i); |
|
411 | m_slices.removeAt(i); | |
387 | } |
|
412 | } | |
388 | } |
|
413 | } | |
389 | } |
|
414 | } | |
390 |
|
415 | |||
391 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
416 | void QPieModelMapperPrivate::removeData(int start, int end) | |
392 | { |
|
417 | { | |
|
418 | if (m_model == 0 || m_series == 0) | |||
|
419 | return; | |||
|
420 | ||||
393 | int removedCount = end - start + 1; |
|
421 | int removedCount = end - start + 1; | |
394 | if (m_count != -1 && start >= m_first + m_count) { |
|
422 | if (m_count != -1 && start >= m_first + m_count) { | |
395 | return; |
|
423 | return; | |
396 | } else { |
|
424 | } else { | |
397 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
425 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
398 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
426 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
399 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
427 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
400 | for (int i = last; i >= first; i--) { |
|
428 | for (int i = last; i >= first; i--) { | |
401 | m_series->remove(m_series->slices().at(i - m_first)); |
|
429 | m_series->remove(m_series->slices().at(i - m_first)); | |
402 | m_slices.removeAt(i - m_first); |
|
430 | m_slices.removeAt(i - m_first); | |
403 | } |
|
431 | } | |
404 |
|
432 | |||
405 | if (m_count != -1) { |
|
433 | if (m_count != -1) { | |
406 | int itemsAvailable; // check how many are available to be added |
|
434 | int itemsAvailable; // check how many are available to be added | |
407 | if (m_orientation == Qt::Vertical) |
|
435 | if (m_orientation == Qt::Vertical) | |
408 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
436 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
409 | else |
|
437 | else | |
410 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
438 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
411 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
439 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
412 | int currentSize = m_series->slices().size(); |
|
440 | int currentSize = m_series->slices().size(); | |
413 | if (toBeAdded > 0) |
|
441 | if (toBeAdded > 0) | |
414 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
442 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
415 | QPieSlice *slice = new QPieSlice; |
|
443 | QPieSlice *slice = new QPieSlice; | |
416 | if (m_orientation == Qt::Vertical) { |
|
444 | if (m_orientation == Qt::Vertical) { | |
417 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); |
|
445 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); | |
418 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); |
|
446 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); | |
419 | } else { |
|
447 | } else { | |
420 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); |
|
448 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); | |
421 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); |
|
449 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); | |
422 | } |
|
450 | } | |
423 | slice->setLabelVisible(); |
|
451 | slice->setLabelVisible(); | |
424 | m_series->insert(i, slice); |
|
452 | m_series->insert(i, slice); | |
425 | m_slices.insert(i, slice); |
|
453 | m_slices.insert(i, slice); | |
426 | } |
|
454 | } | |
427 | } |
|
455 | } | |
428 | } |
|
456 | } | |
429 | } |
|
457 | } | |
430 |
|
458 | |||
431 | void QPieModelMapperPrivate::initializePieFromModel() |
|
459 | void QPieModelMapperPrivate::initializePieFromModel() | |
432 | { |
|
460 | { | |
433 | if (m_model == 0 || m_series == 0) |
|
461 | if (m_model == 0 || m_series == 0) | |
434 | return; |
|
462 | return; | |
435 |
|
463 | |||
436 | blockSeriesSignals(); |
|
464 | blockSeriesSignals(); | |
437 | // clear current content |
|
465 | // clear current content | |
438 | m_series->clear(); |
|
466 | m_series->clear(); | |
439 | m_slices.clear(); |
|
467 | m_slices.clear(); | |
440 |
|
468 | |||
441 | // create the initial slices set |
|
469 | // create the initial slices set | |
442 | int slicePos = 0; |
|
470 | int slicePos = 0; | |
443 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
471 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
444 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
472 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
445 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
473 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
446 | QPieSlice *slice = new QPieSlice; |
|
474 | QPieSlice *slice = new QPieSlice; | |
447 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
475 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
448 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
476 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
449 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
477 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
450 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
478 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
451 | m_series->append(slice); |
|
479 | m_series->append(slice); | |
452 | m_slices.append(slice); |
|
480 | m_slices.append(slice); | |
453 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
481 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
454 | slicePos++; |
|
482 | slicePos++; | |
455 | valueIndex = valueModelIndex(slicePos); |
|
483 | valueIndex = valueModelIndex(slicePos); | |
456 | labelIndex = labelModelIndex(slicePos); |
|
484 | labelIndex = labelModelIndex(slicePos); | |
457 | } |
|
485 | } | |
458 | m_series->setLabelsVisible(true); |
|
486 | m_series->setLabelsVisible(true); | |
459 | blockSeriesSignals(false); |
|
487 | blockSeriesSignals(false); | |
460 | } |
|
488 | } | |
461 |
|
489 | |||
462 | #include "moc_qpiemodelmapper_p.cpp" |
|
490 | #include "moc_qpiemodelmapper_p.cpp" | |
463 | #include "moc_qpiemodelmapper.cpp" |
|
491 | #include "moc_qpiemodelmapper.cpp" | |
464 |
|
492 | |||
465 | QTCOMMERCIALCHART_END_NAMESPACE |
|
493 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,70 +1,72 | |||||
1 | #ifndef QPIEMODELMAPPER_P_H |
|
1 | #ifndef QPIEMODELMAPPER_P_H | |
2 | #define QPIEMODELMAPPER_P_H |
|
2 | #define QPIEMODELMAPPER_P_H | |
3 |
|
3 | |||
4 | #include "qpiemodelmapper.h" |
|
4 | #include "qpiemodelmapper.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 |
|
6 | |||
7 | class QModelIndex; |
|
7 | class QModelIndex; | |
8 | class QAbstractItemModel; |
|
8 | class QAbstractItemModel; | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QPieModelMapper; |
|
12 | class QPieModelMapper; | |
13 | class QPieSeries; |
|
13 | class QPieSeries; | |
14 | class QPieSlice; |
|
14 | class QPieSlice; | |
15 |
|
15 | |||
16 | class QPieModelMapperPrivate : public QObject |
|
16 | class QPieModelMapperPrivate : public QObject | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 |
|
19 | |||
20 | public: |
|
20 | public: | |
21 | QPieModelMapperPrivate(QPieModelMapper *q); |
|
21 | QPieModelMapperPrivate(QPieModelMapper *q); | |
22 |
|
22 | |||
23 | public Q_SLOTS: |
|
23 | public Q_SLOTS: | |
24 | // for the model |
|
24 | // for the model | |
25 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
25 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
26 | void modelRowsAdded(QModelIndex parent, int start, int end); |
|
26 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
27 | void modelRowsRemoved(QModelIndex parent, int start, int end); |
|
27 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
28 | void modelColumnsAdded(QModelIndex parent, int start, int end); |
|
28 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |
29 | void modelColumnsRemoved(QModelIndex parent, int start, int end); |
|
29 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
30 |
|
30 | |||
31 | // for the series |
|
31 | // for the series | |
32 | void slicesAdded(QList<QPieSlice*> slices); |
|
32 | void slicesAdded(QList<QPieSlice*> slices); | |
33 | void slicesRemoved(QList<QPieSlice*> slices); |
|
33 | void slicesRemoved(QList<QPieSlice*> slices); | |
34 | void sliceLabelChanged(); |
|
34 | void sliceLabelChanged(); | |
35 | void sliceValueChanged(); |
|
35 | void sliceValueChanged(); | |
36 |
|
36 | |||
37 | void initializePieFromModel(); |
|
37 | void initializePieFromModel(); | |
38 |
|
38 | |||
39 | private: |
|
39 | private: | |
40 | QPieSlice* pieSlice(QModelIndex index) const; |
|
40 | QPieSlice* pieSlice(QModelIndex index) const; | |
|
41 | bool isLabelIndex(QModelIndex index) const; | |||
|
42 | bool isValueIndex(QModelIndex index) const; | |||
41 | QModelIndex valueModelIndex(int slicePos); |
|
43 | QModelIndex valueModelIndex(int slicePos); | |
42 | QModelIndex labelModelIndex(int slicePos); |
|
44 | QModelIndex labelModelIndex(int slicePos); | |
43 | void insertData(int start, int end); |
|
45 | void insertData(int start, int end); | |
44 | void removeData(int start, int end); |
|
46 | void removeData(int start, int end); | |
45 |
|
47 | |||
46 | void blockModelSignals(bool block = true); |
|
48 | void blockModelSignals(bool block = true); | |
47 | void blockSeriesSignals(bool block = true); |
|
49 | void blockSeriesSignals(bool block = true); | |
48 |
|
50 | |||
49 | private: |
|
51 | private: | |
50 | QPieSeries *m_series; |
|
52 | QPieSeries *m_series; | |
51 | QList<QPieSlice*> m_slices; |
|
53 | QList<QPieSlice*> m_slices; | |
52 | QAbstractItemModel *m_model; |
|
54 | QAbstractItemModel *m_model; | |
53 | int m_first; |
|
55 | int m_first; | |
54 | int m_count; |
|
56 | int m_count; | |
55 | Qt::Orientation m_orientation; |
|
57 | Qt::Orientation m_orientation; | |
56 | int m_valuesIndex; |
|
58 | int m_valuesIndex; | |
57 | int m_labelsIndex; |
|
59 | int m_labelsIndex; | |
58 | bool m_seriesSignalsBlock; |
|
60 | bool m_seriesSignalsBlock; | |
59 | bool m_modelSignalsBlock; |
|
61 | bool m_modelSignalsBlock; | |
60 |
|
62 | |||
61 | private: |
|
63 | private: | |
62 |
|
64 | |||
63 | QPieModelMapper *q_ptr; |
|
65 | QPieModelMapper *q_ptr; | |
64 | Q_DECLARE_PUBLIC(QPieModelMapper) |
|
66 | Q_DECLARE_PUBLIC(QPieModelMapper) | |
65 | friend class QPieSeriesPrivate; |
|
67 | friend class QPieSeriesPrivate; | |
66 | }; |
|
68 | }; | |
67 |
|
69 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
71 | |||
70 | #endif // QPIEMODELMAPPER_P_H |
|
72 | #endif // QPIEMODELMAPPER_P_H |
@@ -1,241 +1,270 | |||||
1 | #include <QtCore/QString> |
|
1 | #include <QtCore/QString> | |
2 | #include <QtTest/QtTest> |
|
2 | #include <QtTest/QtTest> | |
3 |
|
3 | |||
4 | #include <qchart.h> |
|
4 | #include <qchart.h> | |
5 | #include <qchartview.h> |
|
5 | #include <qchartview.h> | |
6 | #include <qpieseries.h> |
|
6 | #include <qpieseries.h> | |
7 | #include <qvpiemodelmapper.h> |
|
7 | #include <qvpiemodelmapper.h> | |
8 | #include <qhpiemodelmapper.h> |
|
8 | #include <qhpiemodelmapper.h> | |
9 | #include <QStandardItemModel> |
|
9 | #include <QStandardItemModel> | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
11 | QTCOMMERCIALCHART_USE_NAMESPACE | |
12 |
|
12 | |||
13 | class tst_piemodelmapper : public QObject |
|
13 | class tst_piemodelmapper : public QObject | |
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | tst_piemodelmapper(); |
|
18 | tst_piemodelmapper(); | |
19 |
|
19 | |||
20 | private Q_SLOTS: |
|
20 | private Q_SLOTS: | |
21 | void initTestCase(); |
|
21 | void initTestCase(); | |
22 | void cleanupTestCase(); |
|
22 | void cleanupTestCase(); | |
23 | void init(); |
|
23 | void init(); | |
24 | void cleanup(); |
|
24 | void cleanup(); | |
25 | void verticalMapper_data(); |
|
25 | void verticalMapper_data(); | |
26 | void verticalMapper(); |
|
26 | void verticalMapper(); | |
27 | void verticalMapperCustomMapping_data(); |
|
27 | void verticalMapperCustomMapping_data(); | |
28 | void verticalMapperCustomMapping(); |
|
28 | void verticalMapperCustomMapping(); | |
29 | void horizontalMapper_data(); |
|
29 | void horizontalMapper_data(); | |
30 | void horizontalMapper(); |
|
30 | void horizontalMapper(); | |
31 | void horizontalMapperCustomMapping_data(); |
|
31 | void horizontalMapperCustomMapping_data(); | |
32 | void horizontalMapperCustomMapping(); |
|
32 | void horizontalMapperCustomMapping(); | |
|
33 | void seriesUpdated(); | |||
33 |
|
34 | |||
34 |
|
35 | |||
35 | private: |
|
36 | private: | |
36 | QStandardItemModel *m_model; |
|
37 | QStandardItemModel *m_model; | |
37 | int m_modelRowCount; |
|
38 | int m_modelRowCount; | |
38 | int m_modelColumnCount; |
|
39 | int m_modelColumnCount; | |
39 |
|
40 | |||
40 | QPieSeries *m_series; |
|
41 | QPieSeries *m_series; | |
41 | QChart *m_chart; |
|
42 | QChart *m_chart; | |
42 | }; |
|
43 | }; | |
43 |
|
44 | |||
44 | tst_piemodelmapper::tst_piemodelmapper(): |
|
45 | tst_piemodelmapper::tst_piemodelmapper(): | |
45 | m_model(0), |
|
46 | m_model(0), | |
46 | m_modelRowCount(10), |
|
47 | m_modelRowCount(10), | |
47 | m_modelColumnCount(8) |
|
48 | m_modelColumnCount(8) | |
48 | { |
|
49 | { | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | void tst_piemodelmapper::init() |
|
52 | void tst_piemodelmapper::init() | |
52 | { |
|
53 | { | |
53 | m_series = new QPieSeries; |
|
54 | m_series = new QPieSeries; | |
54 | m_chart->addSeries(m_series); |
|
55 | m_chart->addSeries(m_series); | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | void tst_piemodelmapper::cleanup() |
|
58 | void tst_piemodelmapper::cleanup() | |
58 | { |
|
59 | { | |
59 | m_chart->removeSeries(m_series); |
|
60 | m_chart->removeSeries(m_series); | |
60 | delete m_series; |
|
61 | delete m_series; | |
61 | m_series = 0; |
|
62 | m_series = 0; | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | void tst_piemodelmapper::initTestCase() |
|
65 | void tst_piemodelmapper::initTestCase() | |
65 | { |
|
66 | { | |
66 | m_chart = new QChart; |
|
67 | m_chart = new QChart; | |
67 | QChartView *chartView = new QChartView(m_chart); |
|
68 | QChartView *chartView = new QChartView(m_chart); | |
68 | chartView->show(); |
|
69 | chartView->show(); | |
69 |
|
70 | |||
70 | m_model = new QStandardItemModel(this); |
|
71 | m_model = new QStandardItemModel(this); | |
71 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
72 | for (int row = 0; row < m_modelRowCount; ++row) { | |
72 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
73 | for (int column = 0; column < m_modelColumnCount; column++) { | |
73 | QStandardItem *item = new QStandardItem(row * column); |
|
74 | QStandardItem *item = new QStandardItem(row * column); | |
74 | m_model->setItem(row, column, item); |
|
75 | m_model->setItem(row, column, item); | |
75 | } |
|
76 | } | |
76 | } |
|
77 | } | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | void tst_piemodelmapper::cleanupTestCase() |
|
80 | void tst_piemodelmapper::cleanupTestCase() | |
80 | { |
|
81 | { | |
81 | m_model->clear(); |
|
82 | m_model->clear(); | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | void tst_piemodelmapper::verticalMapper_data() |
|
85 | void tst_piemodelmapper::verticalMapper_data() | |
85 | { |
|
86 | { | |
86 | QTest::addColumn<int>("valuesColumn"); |
|
87 | QTest::addColumn<int>("valuesColumn"); | |
87 | QTest::addColumn<int>("labelsColumn"); |
|
88 | QTest::addColumn<int>("labelsColumn"); | |
88 | QTest::addColumn<int>("expectedCount"); |
|
89 | QTest::addColumn<int>("expectedCount"); | |
89 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; |
|
90 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; | |
90 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; |
|
91 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; | |
91 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; |
|
92 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; | |
92 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; |
|
93 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; | |
93 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0; |
|
94 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0; | |
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | void tst_piemodelmapper::verticalMapper() |
|
97 | void tst_piemodelmapper::verticalMapper() | |
97 | { |
|
98 | { | |
98 | QFETCH(int, valuesColumn); |
|
99 | QFETCH(int, valuesColumn); | |
99 | QFETCH(int, labelsColumn); |
|
100 | QFETCH(int, labelsColumn); | |
100 | QFETCH(int, expectedCount); |
|
101 | QFETCH(int, expectedCount); | |
101 |
|
102 | |||
102 | QVPieModelMapper *mapper = new QVPieModelMapper; |
|
103 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
103 | mapper->setValuesColumn(valuesColumn); |
|
104 | mapper->setValuesColumn(valuesColumn); | |
104 | mapper->setLabelsColumn(labelsColumn); |
|
105 | mapper->setLabelsColumn(labelsColumn); | |
105 | mapper->setModel(m_model); |
|
106 | mapper->setModel(m_model); | |
106 | mapper->setSeries(m_series); |
|
107 | mapper->setSeries(m_series); | |
107 |
|
108 | |||
108 | QCOMPARE(m_series->count(), expectedCount); |
|
109 | QCOMPARE(m_series->count(), expectedCount); | |
109 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); |
|
110 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); | |
110 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); |
|
111 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); | |
111 |
|
112 | |||
112 | delete mapper; |
|
113 | delete mapper; | |
113 | mapper = 0; |
|
114 | mapper = 0; | |
114 | } |
|
115 | } | |
115 |
|
116 | |||
116 | void tst_piemodelmapper::verticalMapperCustomMapping_data() |
|
117 | void tst_piemodelmapper::verticalMapperCustomMapping_data() | |
117 | { |
|
118 | { | |
118 | QTest::addColumn<int>("first"); |
|
119 | QTest::addColumn<int>("first"); | |
119 | QTest::addColumn<int>("countLimit"); |
|
120 | QTest::addColumn<int>("countLimit"); | |
120 | QTest::addColumn<int>("expectedCount"); |
|
121 | QTest::addColumn<int>("expectedCount"); | |
121 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; |
|
122 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |
122 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; |
|
123 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |
123 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); |
|
124 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |
124 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); |
|
125 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |
125 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; |
|
126 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |
126 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; |
|
127 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |
127 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; |
|
128 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; | |
128 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; |
|
129 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |
129 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; |
|
130 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |
130 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; |
|
131 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |
131 |
|
132 | |||
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | void tst_piemodelmapper::verticalMapperCustomMapping() |
|
135 | void tst_piemodelmapper::verticalMapperCustomMapping() | |
135 | { |
|
136 | { | |
136 | QFETCH(int, first); |
|
137 | QFETCH(int, first); | |
137 | QFETCH(int, countLimit); |
|
138 | QFETCH(int, countLimit); | |
138 | QFETCH(int, expectedCount); |
|
139 | QFETCH(int, expectedCount); | |
139 |
|
140 | |||
140 | QCOMPARE(m_series->count(), 0); |
|
141 | QCOMPARE(m_series->count(), 0); | |
141 |
|
142 | |||
142 | QVPieModelMapper *mapper = new QVPieModelMapper; |
|
143 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
143 | mapper->setValuesColumn(0); |
|
144 | mapper->setValuesColumn(0); | |
144 | mapper->setLabelsColumn(1); |
|
145 | mapper->setLabelsColumn(1); | |
145 | mapper->setModel(m_model); |
|
146 | mapper->setModel(m_model); | |
146 | mapper->setSeries(m_series); |
|
147 | mapper->setSeries(m_series); | |
147 | mapper->setFirst(first); |
|
148 | mapper->setFirst(first); | |
148 | mapper->setCount(countLimit); |
|
149 | mapper->setCount(countLimit); | |
149 |
|
150 | |||
150 | QCOMPARE(m_series->count(), expectedCount); |
|
151 | QCOMPARE(m_series->count(), expectedCount); | |
151 |
|
152 | |||
152 |
// change values column mapping |
|
153 | // change values column mapping to invalid | |
153 | mapper->setValuesColumn(-1); |
|
154 | mapper->setValuesColumn(-1); | |
154 | mapper->setLabelsColumn(1); |
|
155 | mapper->setLabelsColumn(1); | |
155 |
|
156 | |||
156 | QCOMPARE(m_series->count(), 0); |
|
157 | QCOMPARE(m_series->count(), 0); | |
157 |
|
158 | |||
158 | delete mapper; |
|
159 | delete mapper; | |
159 | mapper = 0; |
|
160 | mapper = 0; | |
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 | void tst_piemodelmapper::horizontalMapper_data() |
|
163 | void tst_piemodelmapper::horizontalMapper_data() | |
163 | { |
|
164 | { | |
164 | QTest::addColumn<int>("valuesRow"); |
|
165 | QTest::addColumn<int>("valuesRow"); | |
165 | QTest::addColumn<int>("labelsRow"); |
|
166 | QTest::addColumn<int>("labelsRow"); | |
166 | QTest::addColumn<int>("expectedCount"); |
|
167 | QTest::addColumn<int>("expectedCount"); | |
167 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; |
|
168 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; | |
168 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; |
|
169 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; | |
169 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; |
|
170 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; | |
170 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; |
|
171 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; | |
171 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; |
|
172 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; | |
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 | void tst_piemodelmapper::horizontalMapper() |
|
175 | void tst_piemodelmapper::horizontalMapper() | |
175 | { |
|
176 | { | |
176 | QFETCH(int, valuesRow); |
|
177 | QFETCH(int, valuesRow); | |
177 | QFETCH(int, labelsRow); |
|
178 | QFETCH(int, labelsRow); | |
178 | QFETCH(int, expectedCount); |
|
179 | QFETCH(int, expectedCount); | |
179 |
|
180 | |||
180 | QHPieModelMapper *mapper = new QHPieModelMapper; |
|
181 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
181 | mapper->setValuesRow(valuesRow); |
|
182 | mapper->setValuesRow(valuesRow); | |
182 | mapper->setLabelsRow(labelsRow); |
|
183 | mapper->setLabelsRow(labelsRow); | |
183 | mapper->setModel(m_model); |
|
184 | mapper->setModel(m_model); | |
184 | mapper->setSeries(m_series); |
|
185 | mapper->setSeries(m_series); | |
185 |
|
186 | |||
186 | QCOMPARE(m_series->count(), expectedCount); |
|
187 | QCOMPARE(m_series->count(), expectedCount); | |
187 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); |
|
188 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); | |
188 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); |
|
189 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); | |
189 |
|
190 | |||
190 | delete mapper; |
|
191 | delete mapper; | |
191 | mapper = 0; |
|
192 | mapper = 0; | |
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | void tst_piemodelmapper::horizontalMapperCustomMapping_data() |
|
195 | void tst_piemodelmapper::horizontalMapperCustomMapping_data() | |
195 | { |
|
196 | { | |
196 | QTest::addColumn<int>("first"); |
|
197 | QTest::addColumn<int>("first"); | |
197 | QTest::addColumn<int>("countLimit"); |
|
198 | QTest::addColumn<int>("countLimit"); | |
198 | QTest::addColumn<int>("expectedCount"); |
|
199 | QTest::addColumn<int>("expectedCount"); | |
199 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; |
|
200 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |
200 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; |
|
201 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |
201 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); |
|
202 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |
202 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); |
|
203 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |
203 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; |
|
204 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |
204 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; |
|
205 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |
205 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; |
|
206 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; | |
206 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; |
|
207 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |
207 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; |
|
208 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |
208 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; |
|
209 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | void tst_piemodelmapper::horizontalMapperCustomMapping() |
|
212 | void tst_piemodelmapper::horizontalMapperCustomMapping() | |
212 | { |
|
213 | { | |
213 | QFETCH(int, first); |
|
214 | QFETCH(int, first); | |
214 | QFETCH(int, countLimit); |
|
215 | QFETCH(int, countLimit); | |
215 | QFETCH(int, expectedCount); |
|
216 | QFETCH(int, expectedCount); | |
216 |
|
217 | |||
217 | QCOMPARE(m_series->count(), 0); |
|
218 | QCOMPARE(m_series->count(), 0); | |
218 |
|
219 | |||
219 | QHPieModelMapper *mapper = new QHPieModelMapper; |
|
220 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
220 | mapper->setValuesRow(0); |
|
221 | mapper->setValuesRow(0); | |
221 | mapper->setLabelsRow(1); |
|
222 | mapper->setLabelsRow(1); | |
222 | mapper->setModel(m_model); |
|
223 | mapper->setModel(m_model); | |
223 | mapper->setSeries(m_series); |
|
224 | mapper->setSeries(m_series); | |
224 | mapper->setFirst(first); |
|
225 | mapper->setFirst(first); | |
225 | mapper->setCount(countLimit); |
|
226 | mapper->setCount(countLimit); | |
226 |
|
227 | |||
227 | QCOMPARE(m_series->count(), expectedCount); |
|
228 | QCOMPARE(m_series->count(), expectedCount); | |
228 |
|
229 | |||
229 |
// change values |
|
230 | // change values row mapping to invalid | |
230 | mapper->setValuesRow(-1); |
|
231 | mapper->setValuesRow(-1); | |
231 | mapper->setLabelsRow(1); |
|
232 | mapper->setLabelsRow(1); | |
232 |
|
233 | |||
233 | QCOMPARE(m_series->count(), 0); |
|
234 | QCOMPARE(m_series->count(), 0); | |
234 |
|
235 | |||
235 | delete mapper; |
|
236 | delete mapper; | |
236 | mapper = 0; |
|
237 | mapper = 0; | |
237 | } |
|
238 | } | |
238 |
|
239 | |||
|
240 | void tst_piemodelmapper::seriesUpdated() | |||
|
241 | { | |||
|
242 | QStandardItemModel *otherModel = new QStandardItemModel; | |||
|
243 | for (int row = 0; row < m_modelRowCount; ++row) { | |||
|
244 | for (int column = 0; column < m_modelColumnCount; column++) { | |||
|
245 | QStandardItem *item = new QStandardItem(row * column); | |||
|
246 | otherModel->setItem(row, column, item); | |||
|
247 | } | |||
|
248 | } | |||
|
249 | ||||
|
250 | QVPieModelMapper *mapper = new QVPieModelMapper; | |||
|
251 | mapper->setValuesColumn(0); | |||
|
252 | mapper->setLabelsColumn(1); | |||
|
253 | mapper->setModel(otherModel); | |||
|
254 | mapper->setSeries(m_series); | |||
|
255 | QCOMPARE(m_series->count(), m_modelRowCount); | |||
|
256 | ||||
|
257 | m_series->append("1000", 1000); | |||
|
258 | QCOMPARE(m_series->count(), m_modelRowCount + 1); | |||
|
259 | ||||
|
260 | m_series->remove(m_series->slices().last()); | |||
|
261 | QCOMPARE(m_series->count(), m_modelRowCount); | |||
|
262 | ||||
|
263 | otherModel->clear(); | |||
|
264 | delete otherModel; | |||
|
265 | otherModel = 0; | |||
|
266 | } | |||
|
267 | ||||
239 | QTEST_MAIN(tst_piemodelmapper) |
|
268 | QTEST_MAIN(tst_piemodelmapper) | |
240 |
|
269 | |||
241 | #include "tst_qpiemodelmapper.moc" |
|
270 | #include "tst_qpiemodelmapper.moc" |
@@ -1,519 +1,523 | |||||
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 <QXYModelMapper> | |
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 |
|
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 |
|
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(" |
|
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 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
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 | // buttonsLayout->addWidget(spinBoxLabel); |
|
103 | // buttonsLayout->addWidget(spinBoxLabel); | |
104 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
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 | // // renable axes of the chart (pie hides them) |
|
188 | // // renable axes of the chart (pie hides them) | |
189 | // // x axis |
|
189 | // // x axis | |
190 | // QAxis *axis = m_chart->axisX(); |
|
190 | // QAxis *axis = m_chart->axisX(); | |
191 | // axis->setAxisVisible(true); |
|
191 | // axis->setAxisVisible(true); | |
192 | // axis->setGridLineVisible(true); |
|
192 | // axis->setGridLineVisible(true); | |
193 | // axis->setLabelsVisible(true); |
|
193 | // axis->setLabelsVisible(true); | |
194 |
|
194 | |||
195 | // // y axis |
|
195 | // // y axis | |
196 | // axis = m_chart->axisY(); |
|
196 | // axis = m_chart->axisY(); | |
197 | // axis->setAxisVisible(true); |
|
197 | // axis->setAxisVisible(true); | |
198 | // axis->setGridLineVisible(true); |
|
198 | // axis->setGridLineVisible(true); | |
199 | // axis->setLabelsVisible(true); |
|
199 | // axis->setLabelsVisible(true); | |
200 |
|
200 | |||
201 | // m_model->clearMapping(); |
|
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 | // // series 1 |
|
211 | // // series 1 | |
212 | // m_series = new QLineSeries; |
|
212 | // m_series = new QLineSeries; | |
213 | // m_series->setModel(m_model); |
|
213 | // m_series->setModel(m_model); | |
214 |
|
214 | |||
215 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
215 | // QXYModelMapper *mapper = new QXYModelMapper; | |
216 | // mapper->setMapX(0); |
|
216 | // mapper->setMapX(0); | |
217 | // mapper->setMapY(1); |
|
217 | // mapper->setMapY(1); | |
218 | // mapper->setFirst(3); |
|
218 | // mapper->setFirst(3); | |
219 | // mapper->setCount(4); |
|
219 | // mapper->setCount(4); | |
220 | // m_series->setModelMapper(mapper); |
|
220 | // m_series->setModelMapper(mapper); | |
221 | // // m_series->setModelMapping(0,1, Qt::Vertical); |
|
221 | // // m_series->setModelMapping(0,1, Qt::Vertical); | |
222 | // // m_series->setModelMappingRange(3, 4); |
|
222 | // // m_series->setModelMappingRange(3, 4); | |
223 | // m_chart->addSeries(m_series); |
|
223 | // m_chart->addSeries(m_series); | |
224 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
224 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
225 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
225 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
226 |
|
226 | |||
227 | // // series 2 |
|
227 | // // series 2 | |
228 | // m_series = new QLineSeries; |
|
228 | // m_series = new QLineSeries; | |
229 | // m_series->setModel(m_model); |
|
229 | // m_series->setModel(m_model); | |
230 |
|
230 | |||
231 | // mapper = new QXYModelMapper; |
|
231 | // mapper = new QXYModelMapper; | |
232 | // mapper->setMapX(3); |
|
232 | // mapper->setMapX(3); | |
233 | // mapper->setMapY(4); |
|
233 | // mapper->setMapY(4); | |
234 | // // mapper->setFirst(3); |
|
234 | // // mapper->setFirst(3); | |
235 | // // mapper->setCount(4); |
|
235 | // // mapper->setCount(4); | |
236 | // m_series->setModelMapper(mapper); |
|
236 | // m_series->setModelMapper(mapper); | |
237 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
237 | // // m_series->setModelMapping(2,3, Qt::Vertical); | |
238 | // m_chart->addSeries(m_series); |
|
238 | // m_chart->addSeries(m_series); | |
239 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
239 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
240 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
240 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
241 |
|
241 | |||
242 | // // series 3 |
|
242 | // // series 3 | |
243 | // m_series = new QLineSeries; |
|
243 | // m_series = new QLineSeries; | |
244 | // m_series->setModel(m_model); |
|
244 | // m_series->setModel(m_model); | |
245 |
|
245 | |||
246 | // mapper = new QXYModelMapper; |
|
246 | // mapper = new QXYModelMapper; | |
247 | // mapper->setMapX(5); |
|
247 | // mapper->setMapX(5); | |
248 | // mapper->setMapY(6); |
|
248 | // mapper->setMapY(6); | |
249 | // mapper->setFirst(2); |
|
249 | // mapper->setFirst(2); | |
250 | // mapper->setCount(-1); |
|
250 | // mapper->setCount(-1); | |
251 | // m_series->setModelMapper(mapper); |
|
251 | // m_series->setModelMapper(mapper); | |
252 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
252 | // // m_series->setModelMapping(4,5, Qt::Vertical); | |
253 | // // m_series->setModelMappingRange(2, -1); |
|
253 | // // m_series->setModelMappingRange(2, -1); | |
254 | // m_chart->addSeries(m_series); |
|
254 | // m_chart->addSeries(m_series); | |
255 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
255 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
256 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
256 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | |
257 | } |
|
257 | } | |
258 | else if (m_splineRadioButton->isChecked()) |
|
258 | else if (m_splineRadioButton->isChecked()) | |
259 | { |
|
259 | { | |
260 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
260 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
261 |
|
261 | |||
262 | // // series 1 |
|
262 | // // series 1 | |
263 | // m_series = new QSplineSeries; |
|
263 | // m_series = new QSplineSeries; | |
264 | // m_series->setModel(m_model); |
|
264 | // m_series->setModel(m_model); | |
265 |
|
265 | |||
266 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
266 | // QXYModelMapper *mapper = new QXYModelMapper; | |
267 | // mapper->setMapX(0); |
|
267 | // mapper->setMapX(0); | |
268 | // mapper->setMapY(1); |
|
268 | // mapper->setMapY(1); | |
269 | // mapper->setFirst(0); |
|
269 | // mapper->setFirst(0); | |
270 | // mapper->setCount(-1); |
|
270 | // mapper->setCount(-1); | |
271 |
|
271 | |||
272 | // m_series->setModelMapper(mapper); |
|
272 | // m_series->setModelMapper(mapper); | |
273 |
|
273 | |||
274 | // m_chart->addSeries(m_series); |
|
274 | // m_chart->addSeries(m_series); | |
275 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
275 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
276 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
276 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
277 |
|
277 | |||
278 | // // series 2 |
|
278 | // // series 2 | |
279 | // m_series = new QSplineSeries; |
|
279 | // m_series = new QSplineSeries; | |
280 | // m_series->setModel(m_model); |
|
280 | // m_series->setModel(m_model); | |
281 |
|
281 | |||
282 | // mapper = new QXYModelMapper; |
|
282 | // mapper = new QXYModelMapper; | |
283 | // mapper->setMapX(2); |
|
283 | // mapper->setMapX(2); | |
284 | // mapper->setMapY(3); |
|
284 | // mapper->setMapY(3); | |
285 | // mapper->setFirst(2); |
|
285 | // mapper->setFirst(2); | |
286 | // mapper->setCount(4); |
|
286 | // mapper->setCount(4); | |
287 |
|
287 | |||
288 | // m_series->setModelMapper(mapper); |
|
288 | // m_series->setModelMapper(mapper); | |
289 |
|
289 | |||
290 | // m_chart->addSeries(m_series); |
|
290 | // m_chart->addSeries(m_series); | |
291 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
291 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
292 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
292 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
293 |
|
293 | |||
294 | // // series 3 |
|
294 | // // series 3 | |
295 | // m_series = new QSplineSeries; |
|
295 | // m_series = new QSplineSeries; | |
296 | // m_series->setModel(m_model); |
|
296 | // m_series->setModel(m_model); | |
297 |
|
297 | |||
298 | // mapper = new QXYModelMapper; |
|
298 | // mapper = new QXYModelMapper; | |
299 | // mapper->setMapX(4); |
|
299 | // mapper->setMapX(4); | |
300 | // mapper->setMapY(5); |
|
300 | // mapper->setMapY(5); | |
301 | // mapper->setFirst(2); |
|
301 | // mapper->setFirst(2); | |
302 | // mapper->setCount(-1); |
|
302 | // mapper->setCount(-1); | |
303 |
|
303 | |||
304 | // m_series->setModelMapper(mapper); |
|
304 | // m_series->setModelMapper(mapper); | |
305 |
|
305 | |||
306 | // m_chart->addSeries(m_series); |
|
306 | // m_chart->addSeries(m_series); | |
307 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
307 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
308 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
308 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
309 | } |
|
309 | } | |
310 | // else if (m_scatterRadioButton->isChecked()) |
|
310 | // else if (m_scatterRadioButton->isChecked()) | |
311 | // { |
|
311 | // { | |
312 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
312 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
313 |
|
313 | |||
314 | // // series 1 |
|
314 | // // series 1 | |
315 | // m_series = new QScatterSeries; |
|
315 | // m_series = new QScatterSeries; | |
316 | // m_series->setModel(m_model); |
|
316 | // m_series->setModel(m_model); | |
317 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
317 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
318 | // // m_series->setModelMappingRange(2, 0); |
|
318 | // // m_series->setModelMappingRange(2, 0); | |
319 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
319 | // // series->setModelMapping(0,1, Qt::Horizontal); | |
320 | // m_chart->addSeries(m_series); |
|
320 | // m_chart->addSeries(m_series); | |
321 |
|
321 | |||
322 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
322 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
323 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
323 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
324 |
|
324 | |||
325 | // // series 2 |
|
325 | // // series 2 | |
326 | // m_series = new QScatterSeries; |
|
326 | // m_series = new QScatterSeries; | |
327 | // m_series->setModel(m_model); |
|
327 | // m_series->setModel(m_model); | |
328 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
328 | // m_series->setModelMapping(2,3, Qt::Vertical); | |
329 | // // m_series->setModelMappingRange(1, 6); |
|
329 | // // m_series->setModelMappingRange(1, 6); | |
330 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
330 | // // series->setModelMapping(2,3, Qt::Horizontal); | |
331 | // m_chart->addSeries(m_series); |
|
331 | // m_chart->addSeries(m_series); | |
332 |
|
332 | |||
333 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
333 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
334 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
334 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
335 |
|
335 | |||
336 | // // series 3 |
|
336 | // // series 3 | |
337 | // m_series = new QScatterSeries; |
|
337 | // m_series = new QScatterSeries; | |
338 | // m_series->setModel(m_model); |
|
338 | // m_series->setModel(m_model); | |
339 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
339 | // m_series->setModelMapping(4,5, Qt::Vertical); | |
340 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
340 | // // series->setModelMapping(4,5, Qt::Horizontal); | |
341 | // m_chart->addSeries(m_series); |
|
341 | // m_chart->addSeries(m_series); | |
342 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
342 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
343 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
343 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
344 | // } |
|
344 | // } | |
345 | else if (m_pieRadioButton->isChecked()) |
|
345 | else if (m_pieRadioButton->isChecked()) | |
346 | { |
|
346 | { | |
347 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
347 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
348 |
|
348 | |||
349 | // pie 1 |
|
349 | // pie 1 | |
350 | m_pieSeries = new QPieSeries; |
|
350 | m_pieSeries = new QPieSeries; | |
351 |
|
351 | |||
352 | m_pieMapper = new QVPieModelMapper; |
|
352 | m_pieMapper = new QVPieModelMapper; | |
353 | m_pieMapper->setValuesColumn(1); |
|
353 | m_pieMapper->setValuesColumn(1); | |
354 | m_pieMapper->setLabelsColumn(7); |
|
354 | m_pieMapper->setLabelsColumn(7); | |
355 | m_pieMapper->setSeries(m_pieSeries); |
|
355 | m_pieMapper->setSeries(m_pieSeries); | |
356 | m_pieMapper->setModel(m_model); |
|
356 | m_pieMapper->setModel(m_model); | |
357 | m_pieMapper->setFirst(2); |
|
357 | m_pieMapper->setFirst(2); | |
358 | // m_pieMapper->setCount(5); |
|
358 | // m_pieMapper->setCount(5); | |
359 | // pieSeries->setModelMapper(mapper); |
|
359 | // pieSeries->setModelMapper(mapper); | |
360 |
|
360 | |||
361 | m_pieSeries->setLabelsVisible(true); |
|
361 | m_pieSeries->setLabelsVisible(true); | |
362 |
m_pieSeries->setPieSize(0. |
|
362 | m_pieSeries->setPieSize(0.35); | |
363 |
|
|
363 | m_pieSeries->setHorizontalPosition(0.25); | |
364 |
|
|
364 | m_pieSeries->setVerticalPosition(0.35); | |
365 |
|
365 | |||
366 | m_chart->addSeries(m_pieSeries); |
|
366 | 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(); |
|
367 | 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( |
|
368 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | // pieSeries->slices().at(0)->setValue(400); |
|
371 | // pieSeries->slices().at(0)->setValue(400); | |
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
373 |
|
373 | |||
374 |
|
|
374 | // pie 2 | |
375 |
|
|
375 | m_pieSeries2 = new QPieSeries; | |
376 | // pieSeries->setModel(m_model); |
|
|||
377 |
|
376 | |||
378 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
377 | m_pieMapper = new QVPieModelMapper; | |
379 | // pieSeries->setModelMappingRange(2, -1); |
|
378 | m_pieMapper->setValuesColumn(0); | |
380 |
|
|
379 | m_pieMapper->setLabelsColumn(7); | |
381 | // pieSeries->setPieSize(0.35); |
|
380 | m_pieMapper->setSeries(m_pieSeries2); | |
382 | // pieSeries->setHorizontalPosition(0.8); |
|
381 | m_pieMapper->setModel(m_model); | |
383 | // pieSeries->setVerticalPosition(0.3); |
|
382 | m_pieMapper->setFirst(2); | |
384 | // m_chart->addSeries(pieSeries); |
|
383 | ||
385 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
384 | m_pieSeries2->setLabelsVisible(true); | |
386 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
385 | m_pieSeries2->setPieSize(0.35); | |
|
386 | m_pieSeries2->setHorizontalPosition(0.75); | |||
|
387 | m_pieSeries2->setVerticalPosition(0.65); | |||
|
388 | 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 | m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); | |||
387 |
|
391 | |||
388 | // // pie 3 |
|
392 | // // pie 3 | |
389 | // pieSeries = new QPieSeries; |
|
393 | // pieSeries = new QPieSeries; | |
390 | // pieSeries->setModel(m_model); |
|
394 | // pieSeries->setModel(m_model); | |
391 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
395 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
392 | // pieSeries->setLabelsVisible(true); |
|
396 | // pieSeries->setLabelsVisible(true); | |
393 | // pieSeries->setPieSize(0.35); |
|
397 | // pieSeries->setPieSize(0.35); | |
394 | // pieSeries->setHorizontalPosition(0.5); |
|
398 | // pieSeries->setHorizontalPosition(0.5); | |
395 | // pieSeries->setVerticalPosition(0.75); |
|
399 | // pieSeries->setVerticalPosition(0.75); | |
396 | // m_chart->addSeries(pieSeries); |
|
400 | // m_chart->addSeries(pieSeries); | |
397 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
401 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
398 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
402 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
399 |
|
403 | |||
400 | // // special pie |
|
404 | // // special pie | |
401 | // specialPie = new QPieSeries; |
|
405 | // specialPie = new QPieSeries; | |
402 | // specialPie->append(17, "1"); |
|
406 | // specialPie->append(17, "1"); | |
403 | // specialPie->append(45, "2"); |
|
407 | // specialPie->append(45, "2"); | |
404 | // specialPie->append(77, "3"); |
|
408 | // specialPie->append(77, "3"); | |
405 | // specialPie->append(37, "4"); |
|
409 | // specialPie->append(37, "4"); | |
406 | // specialPie->append(27, "5"); |
|
410 | // specialPie->append(27, "5"); | |
407 | // specialPie->append(47, "6"); |
|
411 | // specialPie->append(47, "6"); | |
408 | // specialPie->setPieSize(0.35); |
|
412 | // specialPie->setPieSize(0.35); | |
409 | // specialPie->setHorizontalPosition(0.8); |
|
413 | // specialPie->setHorizontalPosition(0.8); | |
410 | // specialPie->setVerticalPosition(0.75); |
|
414 | // specialPie->setVerticalPosition(0.75); | |
411 | // specialPie->setLabelsVisible(true); |
|
415 | // specialPie->setLabelsVisible(true); | |
412 | // m_chart->addSeries(specialPie); |
|
416 | // m_chart->addSeries(specialPie); | |
413 | } |
|
417 | } | |
414 | // else if (m_areaRadioButton->isChecked()) |
|
418 | // else if (m_areaRadioButton->isChecked()) | |
415 | // { |
|
419 | // { | |
416 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
420 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
417 |
|
421 | |||
418 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
422 | // QLineSeries* upperLineSeries = new QLineSeries; | |
419 | // upperLineSeries->setModel(m_model); |
|
423 | // upperLineSeries->setModel(m_model); | |
420 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
424 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
421 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
425 | // // upperLineSeries->setModelMappingRange(1, 5); | |
422 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
426 | // QLineSeries* lowerLineSeries = new QLineSeries; | |
423 | // lowerLineSeries->setModel(m_model); |
|
427 | // lowerLineSeries->setModel(m_model); | |
424 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
428 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
425 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
429 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
426 | // m_chart->addSeries(areaSeries); |
|
430 | // m_chart->addSeries(areaSeries); | |
427 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
431 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
428 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
432 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
429 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
433 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
430 | // } |
|
434 | // } | |
431 | else if (m_barRadioButton->isChecked()) |
|
435 | else if (m_barRadioButton->isChecked()) | |
432 | { |
|
436 | { | |
433 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
437 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
434 |
|
438 | |||
435 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
439 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
436 | // barSeries->setCategories(QStringList()); |
|
440 | // barSeries->setCategories(QStringList()); | |
437 | // barSeries->setModel(m_model); |
|
441 | // barSeries->setModel(m_model); | |
438 | // // barSeries->setModelMappingRange(2, 5); |
|
442 | // // barSeries->setModelMappingRange(2, 5); | |
439 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
443 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
440 |
|
444 | |||
441 | // QBarModelMapper *mapper = new QBarModelMapper; |
|
445 | // QBarModelMapper *mapper = new QBarModelMapper; | |
442 | // mapper->setMapCategories(5); |
|
446 | // mapper->setMapCategories(5); | |
443 | // mapper->setMapBarBottom(2); |
|
447 | // mapper->setMapBarBottom(2); | |
444 | // mapper->setMapBarTop(4); |
|
448 | // mapper->setMapBarTop(4); | |
445 | // barSeries->setModelMapper(mapper); |
|
449 | // barSeries->setModelMapper(mapper); | |
446 | // m_chart->addSeries(barSeries); |
|
450 | // m_chart->addSeries(barSeries); | |
447 | // QList<QBarSet*> barsets = barSeries->barSets(); |
|
451 | // QList<QBarSet*> barsets = barSeries->barSets(); | |
448 | // for (int i = 0; i < barsets.count(); i++) { |
|
452 | // for (int i = 0; i < barsets.count(); i++) { | |
449 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
453 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
450 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
454 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
451 | // } |
|
455 | // } | |
452 | } |
|
456 | } | |
453 |
|
457 | |||
454 |
|
458 | |||
455 | if (!m_barRadioButton->isChecked()) { |
|
459 | if (!m_barRadioButton->isChecked()) { | |
456 | m_chart->axisX()->setRange(0, 500); |
|
460 | m_chart->axisX()->setRange(0, 500); | |
457 | m_chart->axisY()->setRange(0, 220); |
|
461 | m_chart->axisY()->setRange(0, 220); | |
458 | } |
|
462 | } | |
459 | m_chart->legend()->setVisible(true); |
|
463 | m_chart->legend()->setVisible(true); | |
460 |
|
464 | |||
461 | // repaint table view colors |
|
465 | // repaint table view colors | |
462 | m_tableView->repaint(); |
|
466 | m_tableView->repaint(); | |
463 | m_tableView->setFocus(); |
|
467 | m_tableView->setFocus(); | |
464 | } |
|
468 | } | |
465 | } |
|
469 | } | |
466 |
|
470 | |||
467 | void TableWidget::testPie() |
|
471 | void TableWidget::testPie() | |
468 | { |
|
472 | { | |
469 | // m_pieMapper->setCount(-1); |
|
473 | // m_pieMapper->setCount(-1); | |
470 | QPieSlice *slice = new QPieSlice("Hehe", 145); |
|
474 | QPieSlice *slice = new QPieSlice("Hehe", 145); | |
471 | slice->setLabelVisible(); |
|
475 | slice->setLabelVisible(); | |
472 | m_pieSeries->append(slice); |
|
476 | m_pieSeries->append(slice); | |
473 |
|
477 | |||
474 | slice = new QPieSlice("Hoho", 34); |
|
478 | slice = new QPieSlice("Hoho", 34); | |
475 | slice->setLabelVisible(); |
|
479 | slice->setLabelVisible(); | |
476 | m_pieSeries->append(slice); |
|
480 | m_pieSeries->append(slice); | |
477 | // m_series->modelMapper()->setMapX(4); |
|
481 | // m_series->modelMapper()->setMapX(4); | |
478 | // m_tableView->setColumnWidth(10, 250); |
|
482 | // m_tableView->setColumnWidth(10, 250); | |
479 | // if (specialPie) { |
|
483 | // if (specialPie) { | |
480 | // specialPie->remove(specialPie->slices().at(2)); |
|
484 | // specialPie->remove(specialPie->slices().at(2)); | |
481 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
485 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | |
482 | // specialPie->append(4, "heloo"); |
|
486 | // specialPie->append(4, "heloo"); | |
483 | // } |
|
487 | // } | |
484 | } |
|
488 | } | |
485 |
|
489 | |||
486 | void TableWidget::testPie2() |
|
490 | void TableWidget::testPie2() | |
487 | { |
|
491 | { | |
488 | QPieSlice *slice; |
|
492 | QPieSlice *slice; | |
489 | if (m_pieSeries->count() > 0) { |
|
493 | if (m_pieSeries->count() > 0) { | |
490 | slice = m_pieSeries->slices().last(); |
|
494 | slice = m_pieSeries->slices().last(); | |
491 | m_pieSeries->remove(slice); |
|
495 | m_pieSeries->remove(slice); | |
492 | } |
|
496 | } | |
493 |
|
497 | |||
494 | if (m_pieSeries->count() > 0) { |
|
498 | if (m_pieSeries->count() > 0) { | |
495 | slice = m_pieSeries->slices().first(); |
|
499 | slice = m_pieSeries->slices().first(); | |
496 | m_pieSeries->remove(slice); |
|
500 | m_pieSeries->remove(slice); | |
497 | } |
|
501 | } | |
498 | } |
|
502 | } | |
499 |
|
503 | |||
500 | void TableWidget::testPie3() |
|
504 | void TableWidget::testPie3() | |
501 | { |
|
505 | { | |
502 | QPieSlice *slice; |
|
506 | QPieSlice *slice; | |
503 | if (m_pieSeries->count() > 0) { |
|
507 | if (m_pieSeries->count() > 0) { | |
504 | slice = m_pieSeries->slices().last(); |
|
508 | slice = m_pieSeries->slices().last(); | |
505 | slice->setLabel("Dalej"); |
|
509 | slice->setLabel("Dalej"); | |
506 | slice->setValue(222); |
|
510 | slice->setValue(222); | |
507 | } |
|
511 | } | |
508 |
|
512 | |||
509 | if (m_pieSeries->count() > 0) { |
|
513 | if (m_pieSeries->count() > 0) { | |
510 | slice = m_pieSeries->slices().first(); |
|
514 | slice = m_pieSeries->slices().first(); | |
511 | slice->setLabel("Prawie"); |
|
515 | slice->setLabel("Prawie"); | |
512 | slice->setValue(111); |
|
516 | slice->setValue(111); | |
513 | } |
|
517 | } | |
514 | } |
|
518 | } | |
515 |
|
519 | |||
516 | TableWidget::~TableWidget() |
|
520 | TableWidget::~TableWidget() | |
517 | { |
|
521 | { | |
518 |
|
522 | |||
519 | } |
|
523 | } |
@@ -1,76 +1,78 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef TABLEWIDGET_H |
|
21 | #ifndef TABLEWIDGET_H | |
22 | #define TABLEWIDGET_H |
|
22 | #define TABLEWIDGET_H | |
23 |
|
23 | |||
24 | #include <QtGui/QWidget> |
|
24 | #include <QtGui/QWidget> | |
25 | //#include <QChartGlobal> |
|
25 | //#include <QChartGlobal> | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
27 | //#include "qxyseries.h" |
|
27 | //#include "qxyseries.h" | |
28 | #include <QPieSeries> |
|
28 | #include <QPieSeries> | |
29 | #include <QVPieModelMapper> |
|
29 | #include <QVPieModelMapper> | |
30 |
|
30 | |||
31 | class CustomTableModel; |
|
31 | class CustomTableModel; | |
32 | class QTableView; |
|
32 | class QTableView; | |
33 | class QRadioButton; |
|
33 | class QRadioButton; | |
34 | class QSpinBox; |
|
34 | class QSpinBox; | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
37 | |||
38 | class TableWidget : public QWidget |
|
38 | class TableWidget : public QWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 |
|
41 | |||
42 | public: |
|
42 | public: | |
43 | TableWidget(QWidget *parent = 0); |
|
43 | TableWidget(QWidget *parent = 0); | |
44 | ~TableWidget(); |
|
44 | ~TableWidget(); | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | public slots: |
|
47 | public slots: | |
48 | void addRowAbove(); |
|
48 | void addRowAbove(); | |
49 | void addRowBelow(); |
|
49 | void addRowBelow(); | |
50 | void removeRow(); |
|
50 | void removeRow(); | |
51 | void addColumnRight(); |
|
51 | void addColumnRight(); | |
52 | void removeColumn(); |
|
52 | void removeColumn(); | |
53 | void updateChartType(bool toggle); |
|
53 | void updateChartType(bool toggle); | |
54 | void testPie(); |
|
54 | void testPie(); | |
55 | void testPie2(); |
|
55 | void testPie2(); | |
56 | void testPie3(); |
|
56 | void testPie3(); | |
57 |
|
57 | |||
58 | private: |
|
58 | private: | |
59 | QChartView* m_chartView; |
|
59 | QChartView* m_chartView; | |
60 | QChart* m_chart; |
|
60 | QChart* m_chart; | |
61 | QXYSeries* m_series; |
|
61 | QXYSeries* m_series; | |
62 | CustomTableModel* m_model; |
|
62 | CustomTableModel* m_model; | |
63 | QTableView* m_tableView; |
|
63 | QTableView* m_tableView; | |
64 | QRadioButton* m_lineRadioButton; |
|
64 | QRadioButton* m_lineRadioButton; | |
65 | QRadioButton* m_splineRadioButton; |
|
65 | QRadioButton* m_splineRadioButton; | |
66 | QRadioButton* m_scatterRadioButton; |
|
66 | QRadioButton* m_scatterRadioButton; | |
67 | QRadioButton* m_pieRadioButton; |
|
67 | QRadioButton* m_pieRadioButton; | |
68 | QRadioButton* m_areaRadioButton; |
|
68 | QRadioButton* m_areaRadioButton; | |
69 | QRadioButton* m_barRadioButton; |
|
69 | QRadioButton* m_barRadioButton; | |
70 | QSpinBox* m_linesCountSpinBox; |
|
70 | QSpinBox* m_linesCountSpinBox; | |
71 | QVPieModelMapper *m_pieMapper; |
|
71 | QVPieModelMapper *m_pieMapper; | |
72 | QPieSeries* m_pieSeries; |
|
72 | QPieSeries* m_pieSeries; | |
|
73 | QVPieModelMapper *m_pieMapper2; | |||
|
74 | QPieSeries* m_pieSeries2; | |||
73 | // QPieSeries* specialPie; |
|
75 | // QPieSeries* specialPie; | |
74 | }; |
|
76 | }; | |
75 |
|
77 | |||
76 | #endif // TABLEWIDGET_H |
|
78 | #endif // TABLEWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now