@@ -1,423 +1,428 | |||||
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())); |
|
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())); |
|
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 | // emit updated(); |
|
76 | // emit updated(); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | int QPieModelMapper::count() const |
|
79 | int QPieModelMapper::count() const | |
80 | { |
|
80 | { | |
81 | Q_D(const QPieModelMapper); |
|
81 | Q_D(const QPieModelMapper); | |
82 | return d->m_count; |
|
82 | return d->m_count; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void QPieModelMapper::setCount(int count) |
|
85 | void QPieModelMapper::setCount(int count) | |
86 | { |
|
86 | { | |
87 | Q_D(QPieModelMapper); |
|
87 | Q_D(QPieModelMapper); | |
88 | d->m_count = qMax(count, -1); |
|
88 | d->m_count = qMax(count, -1); | |
89 | d->initializePieFromModel(); |
|
89 | d->initializePieFromModel(); | |
90 | // emit updated(); |
|
90 | // emit updated(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | Qt::Orientation QPieModelMapper::orientation() const |
|
93 | Qt::Orientation QPieModelMapper::orientation() const | |
94 | { |
|
94 | { | |
95 | Q_D(const QPieModelMapper); |
|
95 | Q_D(const QPieModelMapper); | |
96 | return d->m_orientation; |
|
96 | return d->m_orientation; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
99 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
100 | { |
|
100 | { | |
101 | Q_D(QPieModelMapper); |
|
101 | Q_D(QPieModelMapper); | |
102 | d->m_orientation = orientation; |
|
102 | d->m_orientation = orientation; | |
103 | d->initializePieFromModel(); |
|
103 | d->initializePieFromModel(); | |
104 | // emit updated(); |
|
104 | // emit updated(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | int QPieModelMapper::valuesIndex() const |
|
107 | int QPieModelMapper::valuesIndex() const | |
108 | { |
|
108 | { | |
109 | Q_D(const QPieModelMapper); |
|
109 | Q_D(const QPieModelMapper); | |
110 | return d->m_valuesIndex; |
|
110 | return d->m_valuesIndex; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void QPieModelMapper::setValuesIndex(int mapValues) |
|
113 | void QPieModelMapper::setValuesIndex(int mapValues) | |
114 | { |
|
114 | { | |
115 | Q_D(QPieModelMapper); |
|
115 | Q_D(QPieModelMapper); | |
116 | d->m_valuesIndex = mapValues; |
|
116 | d->m_valuesIndex = mapValues; | |
117 | d->initializePieFromModel(); |
|
117 | d->initializePieFromModel(); | |
118 | // emit updated(); |
|
118 | // emit updated(); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | int QPieModelMapper::labelsIndex() const |
|
121 | int QPieModelMapper::labelsIndex() const | |
122 | { |
|
122 | { | |
123 | Q_D(const QPieModelMapper); |
|
123 | Q_D(const QPieModelMapper); | |
124 | return d->m_labelsIndex; |
|
124 | return d->m_labelsIndex; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void QPieModelMapper::setLabelsIndex(int mapLabels) |
|
127 | void QPieModelMapper::setLabelsIndex(int mapLabels) | |
128 | { |
|
128 | { | |
129 | Q_D(QPieModelMapper); |
|
129 | Q_D(QPieModelMapper); | |
130 | d->m_labelsIndex = mapLabels; |
|
130 | d->m_labelsIndex = mapLabels; | |
131 | d->initializePieFromModel(); |
|
131 | d->initializePieFromModel(); | |
132 | // emit updated(); |
|
132 | // emit updated(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void QPieModelMapper::reset() |
|
135 | void QPieModelMapper::reset() | |
136 | { |
|
136 | { | |
137 | Q_D(QPieModelMapper); |
|
137 | Q_D(QPieModelMapper); | |
138 | d->m_first = 0; |
|
138 | d->m_first = 0; | |
139 | d->m_count = -1; |
|
139 | d->m_count = -1; | |
140 | d->m_orientation = Qt::Vertical; |
|
140 | d->m_orientation = Qt::Vertical; | |
141 | d->m_valuesIndex = -1; |
|
141 | d->m_valuesIndex = -1; | |
142 | d->m_labelsIndex = -1; |
|
142 | d->m_labelsIndex = -1; | |
143 | // emit updated(); |
|
143 | // emit updated(); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
147 |
|
147 | |||
148 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
148 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
149 | q_ptr(q) |
|
149 | q_ptr(q) | |
150 | { |
|
150 | { | |
151 | m_series = 0; |
|
151 | m_series = 0; | |
152 | m_model = 0; |
|
152 | m_model = 0; | |
153 | m_first = 0; |
|
153 | m_first = 0; | |
154 | m_count = -1; |
|
154 | m_count = -1; | |
155 | m_orientation = Qt::Vertical; |
|
155 | m_orientation = Qt::Vertical; | |
156 | m_valuesIndex = -1; |
|
156 | m_valuesIndex = -1; | |
157 | m_labelsIndex = -1; |
|
157 | m_labelsIndex = -1; | |
|
158 | m_seriesSignalsBlock = false; | |||
|
159 | m_modelSignalsBlock = false; | |||
|
160 | } | |||
|
161 | ||||
|
162 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |||
|
163 | { | |||
|
164 | m_modelSignalsBlock = block; | |||
|
165 | } | |||
|
166 | ||||
|
167 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |||
|
168 | { | |||
|
169 | m_seriesSignalsBlock = block; | |||
158 | } |
|
170 | } | |
159 |
|
171 | |||
160 |
|
172 | |||
161 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
173 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
162 | { |
|
174 | { | |
163 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { |
|
175 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) { | |
164 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) |
|
176 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) | |
165 | return m_series->slices().at(index.row() - m_first); |
|
177 | return m_series->slices().at(index.row() - m_first); | |
166 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { |
|
178 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) { | |
167 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
179 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
168 | return m_series->slices().at(index.column() - m_first); |
|
180 | return m_series->slices().at(index.column() - m_first); | |
169 | } |
|
181 | } | |
170 | return 0; // This part of model has not been mapped to any slice |
|
182 | return 0; // This part of model has not been mapped to any slice | |
171 | } |
|
183 | } | |
172 |
|
184 | |||
173 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
185 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
174 | { |
|
186 | { | |
175 | if (m_count != -1 && slicePos >= m_count) |
|
187 | if (m_count != -1 && slicePos >= m_count) | |
176 | return QModelIndex(); // invalid |
|
188 | return QModelIndex(); // invalid | |
177 |
|
189 | |||
178 | if (m_orientation == Qt::Vertical) |
|
190 | if (m_orientation == Qt::Vertical) | |
179 | return m_model->index(slicePos + m_first, m_valuesIndex); |
|
191 | return m_model->index(slicePos + m_first, m_valuesIndex); | |
180 | else |
|
192 | else | |
181 | return m_model->index(m_valuesIndex, slicePos + m_first); |
|
193 | return m_model->index(m_valuesIndex, slicePos + m_first); | |
182 | } |
|
194 | } | |
183 |
|
195 | |||
184 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
196 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
185 | { |
|
197 | { | |
186 | if (m_count != -1 && slicePos >= m_count) |
|
198 | if (m_count != -1 && slicePos >= m_count) | |
187 | return QModelIndex(); // invalid |
|
199 | return QModelIndex(); // invalid | |
188 |
|
200 | |||
189 | if (m_orientation == Qt::Vertical) |
|
201 | if (m_orientation == Qt::Vertical) | |
190 | return m_model->index(slicePos + m_first, m_labelsIndex); |
|
202 | return m_model->index(slicePos + m_first, m_labelsIndex); | |
191 | else |
|
203 | else | |
192 | return m_model->index(m_labelsIndex, slicePos + m_first); |
|
204 | return m_model->index(m_labelsIndex, slicePos + m_first); | |
193 | } |
|
205 | } | |
194 |
|
206 | |||
195 | void QPieModelMapperPrivate::slicesAdded() |
|
207 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
196 | { |
|
208 | { | |
197 | // |
|
209 | if (m_seriesSignalsBlock) | |
|
210 | return; | |||
|
211 | ||||
|
212 | if (slices.count() == 0) | |||
|
213 | return; | |||
|
214 | ||||
|
215 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |||
|
216 | if (firstIndex == -1) | |||
|
217 | return; | |||
|
218 | ||||
|
219 | blockModelSignals(); | |||
|
220 | if (m_orientation == Qt::Vertical) | |||
|
221 | m_model->insertRows(firstIndex + m_first, slices.count()); | |||
|
222 | else | |||
|
223 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |||
|
224 | ||||
|
225 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |||
|
226 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |||
|
227 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |||
|
228 | } | |||
|
229 | blockModelSignals(false); | |||
198 | } |
|
230 | } | |
199 |
|
231 | |||
200 | void QPieModelMapperPrivate::slicesRemoved() |
|
232 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
201 | { |
|
233 | { | |
202 | // |
|
234 | if (m_seriesSignalsBlock) | |
|
235 | return; | |||
|
236 | ||||
|
237 | if (slices.count() == 0) | |||
|
238 | return; | |||
|
239 | ||||
|
240 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |||
|
241 | if (firstIndex == -1) | |||
|
242 | return; | |||
|
243 | ||||
|
244 | blockModelSignals(); | |||
|
245 | if (m_orientation == Qt::Vertical) | |||
|
246 | m_model->removeRows(firstIndex + m_first, slices.count()); | |||
|
247 | else | |||
|
248 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |||
|
249 | blockModelSignals(false); | |||
203 | } |
|
250 | } | |
204 |
|
251 | |||
205 | void QPieModelMapperPrivate::sliceChanged() |
|
252 | void QPieModelMapperPrivate::sliceChanged() | |
206 | { |
|
253 | { | |
207 | // |
|
254 | blockModelSignals(); | |
|
255 | blockModelSignals(false); | |||
208 | } |
|
256 | } | |
209 |
|
257 | |||
210 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
258 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
211 | { |
|
259 | { | |
|
260 | if (m_modelSignalsBlock) | |||
|
261 | return; | |||
|
262 | ||||
|
263 | blockSeriesSignals(); | |||
212 | QModelIndex index; |
|
264 | QModelIndex index; | |
213 | QPieSlice *slice; |
|
265 | QPieSlice *slice; | |
214 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
266 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
215 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
267 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
216 | index = topLeft.sibling(row, column); |
|
268 | index = topLeft.sibling(row, column); | |
217 | slice = pieSlice(index); |
|
269 | slice = pieSlice(index); | |
218 | if (slice) { |
|
270 | if (slice) { | |
219 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
271 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
220 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
272 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
221 | } |
|
273 | } | |
222 |
|
||||
223 | // if (m_orientation == Qt::Vertical) |
|
|||
224 | // { |
|
|||
225 | // if ( topLeft.row() >= m_first && (m_count == - 1 || topLeft.row() < m_first + m_count)) { |
|
|||
226 | // if (topLeft.column() == m_valuesIndex) |
|
|||
227 | // m_series->slices().at(topLeft.row() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
|||
228 | // if (topLeft.column() == m_labelsIndex) |
|
|||
229 | // m_series->slices().at(topLeft.row() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
|||
230 | // } |
|
|||
231 | // } |
|
|||
232 | // else |
|
|||
233 | // { |
|
|||
234 | // if (topLeft.column() >= m_first && (m_count == - 1 || topLeft.column() < m_first + m_count)) { |
|
|||
235 | // if (topLeft.row() == m_valuesIndex) |
|
|||
236 | // m_series->slices().at(topLeft.column() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
|||
237 | // if (topLeft.row() == m_labelsIndex) |
|
|||
238 | // m_series->slices().at(topLeft.column() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
|||
239 | // } |
|
|||
240 | // } |
|
|||
241 | } |
|
274 | } | |
242 | } |
|
275 | } | |
|
276 | blockSeriesSignals(false); | |||
243 | } |
|
277 | } | |
244 |
|
278 | |||
245 |
|
279 | |||
246 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
280 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
247 | { |
|
281 | { | |
248 | Q_UNUSED(parent); |
|
282 | Q_UNUSED(parent); | |
|
283 | if (m_modelSignalsBlock) | |||
|
284 | return; | |||
|
285 | ||||
|
286 | blockSeriesSignals(); | |||
249 | if (m_orientation == Qt::Vertical) |
|
287 | if (m_orientation == Qt::Vertical) | |
250 | insertData(start, end); |
|
288 | insertData(start, end); | |
251 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
289 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
252 | initializePieFromModel(); |
|
290 | initializePieFromModel(); | |
|
291 | blockSeriesSignals(false); | |||
253 | } |
|
292 | } | |
254 |
|
293 | |||
255 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
294 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
256 | { |
|
295 | { | |
257 | Q_UNUSED(parent); |
|
296 | Q_UNUSED(parent); | |
|
297 | if (m_modelSignalsBlock) | |||
|
298 | return; | |||
|
299 | ||||
|
300 | blockSeriesSignals(); | |||
258 | if (m_orientation == Qt::Vertical) |
|
301 | if (m_orientation == Qt::Vertical) | |
259 | removeData(start, end); |
|
302 | removeData(start, end); | |
260 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
303 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
261 | initializePieFromModel(); |
|
304 | initializePieFromModel(); | |
|
305 | blockSeriesSignals(false); | |||
262 | } |
|
306 | } | |
263 |
|
307 | |||
264 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
308 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
265 | { |
|
309 | { | |
266 | Q_UNUSED(parent); |
|
310 | Q_UNUSED(parent); | |
|
311 | if (m_modelSignalsBlock) | |||
|
312 | return; | |||
|
313 | ||||
|
314 | blockSeriesSignals(); | |||
267 | if (m_orientation == Qt::Horizontal) |
|
315 | if (m_orientation == Qt::Horizontal) | |
268 | insertData(start, end); |
|
316 | insertData(start, end); | |
269 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
317 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
270 | initializePieFromModel(); |
|
318 | initializePieFromModel(); | |
|
319 | blockSeriesSignals(false); | |||
271 | } |
|
320 | } | |
272 |
|
321 | |||
273 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
322 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
274 | { |
|
323 | { | |
275 | Q_UNUSED(parent); |
|
324 | Q_UNUSED(parent); | |
|
325 | if (m_modelSignalsBlock) | |||
|
326 | return; | |||
|
327 | ||||
|
328 | blockSeriesSignals(); | |||
276 | if (m_orientation == Qt::Horizontal) |
|
329 | if (m_orientation == Qt::Horizontal) | |
277 | removeData(start, end); |
|
330 | removeData(start, end); | |
278 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie |
|
331 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
279 | initializePieFromModel(); |
|
332 | initializePieFromModel(); | |
|
333 | blockSeriesSignals(false); | |||
280 | } |
|
334 | } | |
281 |
|
335 | |||
282 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
336 | void QPieModelMapperPrivate::insertData(int start, int end) | |
283 | { |
|
337 | { | |
284 | if (m_count != -1 && start >= m_first + m_count) { |
|
338 | if (m_count != -1 && start >= m_first + m_count) { | |
285 | return; |
|
339 | return; | |
286 | } else { |
|
340 | } else { | |
287 | int addedCount = end - start + 1; |
|
341 | int addedCount = end - start + 1; | |
288 | if (m_count != -1 && addedCount > m_count) |
|
342 | if (m_count != -1 && addedCount > m_count) | |
289 | addedCount = m_count; |
|
343 | addedCount = m_count; | |
290 | int first = qMax(start, m_first); |
|
344 | int first = qMax(start, m_first); | |
291 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
345 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
292 | for (int i = first; i <= last; i++) { |
|
346 | for (int i = first; i <= last; i++) { | |
293 | QPieSlice *slice = new QPieSlice; |
|
347 | QPieSlice *slice = new QPieSlice; | |
294 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
348 | slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
295 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); |
|
349 | slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString()); | |
296 | // if (m_orientation == Qt::Vertical) { |
|
|||
297 | // slice->setValue(m_model->data(m_model->index(i, m_valuesIndex), Qt::DisplayRole).toDouble()); |
|
|||
298 | // slice->setLabel(m_model->data(m_model->index(i, m_labelsIndex), Qt::DisplayRole).toString()); |
|
|||
299 | // } else { |
|
|||
300 | // slice->setValue(m_model->data(m_model->index(m_valuesIndex, i), Qt::DisplayRole).toDouble()); |
|
|||
301 | // slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i), Qt::DisplayRole).toString()); |
|
|||
302 | // } |
|
|||
303 | slice->setLabelVisible(); |
|
350 | slice->setLabelVisible(); | |
304 | m_series->insert(i - m_first, slice); |
|
351 | m_series->insert(i - m_first, slice); | |
305 | } |
|
352 | } | |
|
353 | ||||
|
354 | // remove excess of slices (abouve m_count) | |||
306 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
355 | if (m_count != -1 && m_series->slices().size() > m_count) | |
307 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) |
|
356 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) | |
308 | m_series->remove(m_series->slices().at(i)); |
|
357 | m_series->remove(m_series->slices().at(i)); | |
309 | } |
|
358 | } | |
310 | } |
|
359 | } | |
311 |
|
360 | |||
312 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
361 | void QPieModelMapperPrivate::removeData(int start, int end) | |
313 | { |
|
362 | { | |
314 | int removedCount = end - start + 1; |
|
363 | int removedCount = end - start + 1; | |
315 | if (m_count != -1 && start >= m_first + m_count) { |
|
364 | if (m_count != -1 && start >= m_first + m_count) { | |
316 | return; |
|
365 | return; | |
317 | } else { |
|
366 | } else { | |
318 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
367 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
319 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
368 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
320 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
369 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
321 | for (int i = last; i >= first; i--) |
|
370 | for (int i = last; i >= first; i--) | |
322 | m_series->remove(m_series->slices().at(i - m_first)); |
|
371 | m_series->remove(m_series->slices().at(i - m_first)); | |
323 |
|
372 | |||
324 | if (m_count != -1) { |
|
373 | if (m_count != -1) { | |
325 | int itemsAvailable; // check how many are available to be added |
|
374 | int itemsAvailable; // check how many are available to be added | |
326 | if (m_orientation == Qt::Vertical) |
|
375 | if (m_orientation == Qt::Vertical) | |
327 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
376 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
328 | else |
|
377 | else | |
329 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
378 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
330 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
379 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
331 | int currentSize = m_series->slices().size(); |
|
380 | int currentSize = m_series->slices().size(); | |
332 | if (toBeAdded > 0) |
|
381 | if (toBeAdded > 0) | |
333 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
382 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
334 | QPieSlice *slice = new QPieSlice; |
|
383 | QPieSlice *slice = new QPieSlice; | |
335 | if (m_orientation == Qt::Vertical) { |
|
384 | if (m_orientation == Qt::Vertical) { | |
336 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); |
|
385 | slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble()); | |
337 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); |
|
386 | slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString()); | |
338 | } else { |
|
387 | } else { | |
339 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); |
|
388 | slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble()); | |
340 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); |
|
389 | slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString()); | |
341 | } |
|
390 | } | |
342 | slice->setLabelVisible(); |
|
391 | slice->setLabelVisible(); | |
343 | m_series->insert(i, slice); |
|
392 | m_series->insert(i, slice); | |
344 | } |
|
393 | } | |
345 | } |
|
394 | } | |
346 | } |
|
395 | } | |
347 | } |
|
396 | } | |
348 |
|
397 | |||
349 | void QPieModelMapperPrivate::initializePieFromModel() |
|
398 | void QPieModelMapperPrivate::initializePieFromModel() | |
350 | { |
|
399 | { | |
351 | if (m_model == 0 || m_series == 0) |
|
400 | if (m_model == 0 || m_series == 0) | |
352 | return; |
|
401 | return; | |
353 |
|
402 | |||
354 | // clear current content |
|
403 | // clear current content | |
355 | m_series->clear(); |
|
404 | m_series->clear(); | |
356 |
|
405 | |||
357 | // check if mappings are set |
|
406 | // check if mappings are set | |
358 | if (m_valuesIndex == -1 || m_labelsIndex == -1) |
|
407 | if (m_valuesIndex == -1 || m_labelsIndex == -1) | |
359 | return; |
|
408 | return; | |
360 |
|
409 | |||
|
410 | blockSeriesSignals(); | |||
361 | // create the initial slices set |
|
411 | // create the initial slices set | |
362 | int slicePos = 0; |
|
412 | int slicePos = 0; | |
363 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
413 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
364 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
414 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
365 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
415 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
366 | m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
416 | m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
367 | slicePos++; |
|
417 | slicePos++; | |
368 | valueIndex = valueModelIndex(slicePos); |
|
418 | valueIndex = valueModelIndex(slicePos); | |
369 | labelIndex = labelModelIndex(slicePos); |
|
419 | labelIndex = labelModelIndex(slicePos); | |
370 | } |
|
420 | } | |
371 |
|
||||
372 | // if (m_orientation == Qt::Vertical) { |
|
|||
373 | // if (m_valuesIndex >= m_model->columnCount() || m_labelsIndex >= m_model->columnCount()) |
|
|||
374 | // return; // mapped columns are not existing |
|
|||
375 |
|
||||
376 | // int sliceCount = 0; |
|
|||
377 | // if(m_count == -1) |
|
|||
378 | // sliceCount = m_model->rowCount() - m_first; |
|
|||
379 | // else |
|
|||
380 | // sliceCount = qMin(m_count, m_model->rowCount() - m_first); |
|
|||
381 | // } else { |
|
|||
382 | // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount()) |
|
|||
383 | // return; // mapped columns are not existing |
|
|||
384 |
|
||||
385 | // int sliceCount = 0; |
|
|||
386 | // if(m_count == -1) |
|
|||
387 | // sliceCount = m_model->columnCount() - m_first; |
|
|||
388 | // else |
|
|||
389 | // sliceCount = qMin(m_count, m_model->columnCount() - m_first); |
|
|||
390 | // } |
|
|||
391 | // for (int i = m_first; i < m_first + sliceCount; i++) |
|
|||
392 | // m_series->append(m_model->data(labelModelIndex(i), Qt::DisplayRole).toString(), m_model->data(valueModelIndex(i), Qt::DisplayRole).toDouble()); |
|
|||
393 | m_series->setLabelsVisible(true); |
|
421 | m_series->setLabelsVisible(true); | |
394 | // // create the initial slices set |
|
422 | blockSeriesSignals(false); | |
395 | // if (m_orientation == Qt::Vertical) { |
|
|||
396 | // if (m_valuesIndex >= m_model->columnCount() || m_labelsIndex >= m_model->columnCount()) |
|
|||
397 | // return; // mapped columns are not existing |
|
|||
398 |
|
||||
399 | // int sliceCount = 0; |
|
|||
400 | // if(m_count == -1) |
|
|||
401 | // sliceCount = m_model->rowCount() - m_first; |
|
|||
402 | // else |
|
|||
403 | // sliceCount = qMin(m_count, m_model->rowCount() - m_first); |
|
|||
404 | // for (int i = m_first; i < m_first + sliceCount; i++) |
|
|||
405 | // m_series->append(m_model->data(m_model->index(i, m_labelsIndex), Qt::DisplayRole).toString(), m_model->data(m_model->index(i, m_valuesIndex), Qt::DisplayRole).toDouble()); |
|
|||
406 | // } else { |
|
|||
407 | // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount()) |
|
|||
408 | // return; // mapped columns are not existing |
|
|||
409 |
|
||||
410 | // int sliceCount = 0; |
|
|||
411 | // if(m_count == -1) |
|
|||
412 | // sliceCount = m_model->columnCount() - m_first; |
|
|||
413 | // else |
|
|||
414 | // sliceCount = qMin(m_count, m_model->columnCount() - m_first); |
|
|||
415 | // for (int i = m_first; i < m_first + sliceCount; i++) |
|
|||
416 | // m_series->append(m_model->data(m_model->index(m_labelsIndex, i), Qt::DisplayRole).toString(), m_model->data(m_model->index(m_valuesIndex, i), Qt::DisplayRole).toDouble()); |
|
|||
417 | // m_series->setLabelsVisible(true); |
|
|||
418 | } |
|
423 | } | |
419 |
|
424 | |||
420 | #include "moc_qpiemodelmapper_p.cpp" |
|
425 | #include "moc_qpiemodelmapper_p.cpp" | |
421 | #include "moc_qpiemodelmapper.cpp" |
|
426 | #include "moc_qpiemodelmapper.cpp" | |
422 |
|
427 | |||
423 | QTCOMMERCIALCHART_END_NAMESPACE |
|
428 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,63 +1,68 | |||||
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(); |
|
32 | void slicesAdded(QList<QPieSlice*> slices); | |
33 | void slicesRemoved(); |
|
33 | void slicesRemoved(QList<QPieSlice*> slices); | |
34 | void sliceChanged(); |
|
34 | void sliceChanged(); | |
35 |
|
35 | |||
36 | void initializePieFromModel(); |
|
36 | void initializePieFromModel(); | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | QPieSlice* pieSlice(QModelIndex index) const; |
|
39 | QPieSlice* pieSlice(QModelIndex index) const; | |
40 | QModelIndex valueModelIndex(int slicePos); |
|
40 | QModelIndex valueModelIndex(int slicePos); | |
41 | QModelIndex labelModelIndex(int slicePos); |
|
41 | QModelIndex labelModelIndex(int slicePos); | |
42 | void insertData(int start, int end); |
|
42 | void insertData(int start, int end); | |
43 | void removeData(int start, int end); |
|
43 | void removeData(int start, int end); | |
44 |
|
44 | |||
|
45 | void blockModelSignals(bool block = true); | |||
|
46 | void blockSeriesSignals(bool block = true); | |||
|
47 | ||||
45 | private: |
|
48 | private: | |
|
49 | bool m_seriesSignalsBlock; | |||
|
50 | bool m_modelSignalsBlock; | |||
46 | QPieSeries *m_series; |
|
51 | QPieSeries *m_series; | |
47 | QAbstractItemModel *m_model; |
|
52 | QAbstractItemModel *m_model; | |
48 | int m_first; |
|
53 | int m_first; | |
49 | int m_count; |
|
54 | int m_count; | |
50 | Qt::Orientation m_orientation; |
|
55 | Qt::Orientation m_orientation; | |
51 | int m_valuesIndex; |
|
56 | int m_valuesIndex; | |
52 | int m_labelsIndex; |
|
57 | int m_labelsIndex; | |
53 |
|
58 | |||
54 | private: |
|
59 | private: | |
55 |
|
60 | |||
56 | QPieModelMapper *q_ptr; |
|
61 | QPieModelMapper *q_ptr; | |
57 | Q_DECLARE_PUBLIC(QPieModelMapper) |
|
62 | Q_DECLARE_PUBLIC(QPieModelMapper) | |
58 | friend class QPieSeriesPrivate; |
|
63 | friend class QPieSeriesPrivate; | |
59 | }; |
|
64 | }; | |
60 |
|
65 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
67 | |||
63 | #endif // QPIEMODELMAPPER_P_H |
|
68 | #endif // QPIEMODELMAPPER_P_H |
@@ -1,474 +1,499 | |||||
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 <QPieModelMapper> |
|
32 | #include <QPieModelMapper> | |
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(" |
|
84 | QPushButton* specialPieButton = new QPushButton("Add slices from series"); | |
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 from series"); | |||
|
88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); | |||
|
89 | ||||
87 |
|
90 | |||
88 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
91 | // QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
89 |
|
92 | |||
90 | // spin box for setting number of affected items (add, remove) |
|
93 | // spin box for setting number of affected items (add, remove) | |
91 | m_linesCountSpinBox = new QSpinBox; |
|
94 | m_linesCountSpinBox = new QSpinBox; | |
92 | m_linesCountSpinBox->setRange(1, 10); |
|
95 | m_linesCountSpinBox->setRange(1, 10); | |
93 | m_linesCountSpinBox->setValue(1); |
|
96 | m_linesCountSpinBox->setValue(1); | |
94 |
|
97 | |||
95 | // buttons layout |
|
98 | // buttons layout | |
96 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
99 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
97 | // buttonsLayout->addWidget(spinBoxLabel); |
|
100 | // buttonsLayout->addWidget(spinBoxLabel); | |
98 | // buttonsLayout->addWidget(m_linesCountSpinBox); |
|
101 | // buttonsLayout->addWidget(m_linesCountSpinBox); | |
99 | // buttonsLayout->addWidget(addRowAboveButton); |
|
102 | // buttonsLayout->addWidget(addRowAboveButton); | |
100 | buttonsLayout->addWidget(addRowBelowButton); |
|
103 | buttonsLayout->addWidget(addRowBelowButton); | |
101 | buttonsLayout->addWidget(removeRowButton); |
|
104 | buttonsLayout->addWidget(removeRowButton); | |
102 | // buttonsLayout->addWidget(addColumnRightButton); |
|
105 | // buttonsLayout->addWidget(addColumnRightButton); | |
103 | // buttonsLayout->addWidget(removeColumnButton); |
|
106 | // buttonsLayout->addWidget(removeColumnButton); | |
104 | buttonsLayout->addWidget(specialPieButton); |
|
107 | buttonsLayout->addWidget(specialPieButton); | |
|
108 | buttonsLayout->addWidget(specialPieButton2); | |||
105 | buttonsLayout->addStretch(); |
|
109 | buttonsLayout->addStretch(); | |
106 |
|
110 | |||
107 | // chart type radio buttons |
|
111 | // chart type radio buttons | |
108 | m_lineRadioButton = new QRadioButton("Line"); |
|
112 | m_lineRadioButton = new QRadioButton("Line"); | |
109 | m_splineRadioButton = new QRadioButton("Spline"); |
|
113 | m_splineRadioButton = new QRadioButton("Spline"); | |
110 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
114 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
111 | m_pieRadioButton = new QRadioButton("Pie"); |
|
115 | m_pieRadioButton = new QRadioButton("Pie"); | |
112 | m_areaRadioButton = new QRadioButton("Area"); |
|
116 | m_areaRadioButton = new QRadioButton("Area"); | |
113 | m_barRadioButton = new QRadioButton("Bar"); |
|
117 | m_barRadioButton = new QRadioButton("Bar"); | |
114 |
|
118 | |||
115 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
119 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
116 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
120 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
117 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
121 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
118 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
122 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
119 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
123 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
120 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
124 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
121 | m_lineRadioButton->setChecked(true); |
|
125 | m_lineRadioButton->setChecked(true); | |
122 |
|
126 | |||
123 | // radio buttons layout |
|
127 | // radio buttons layout | |
124 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
128 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
125 | radioLayout->addWidget(m_lineRadioButton); |
|
129 | radioLayout->addWidget(m_lineRadioButton); | |
126 | radioLayout->addWidget(m_splineRadioButton); |
|
130 | radioLayout->addWidget(m_splineRadioButton); | |
127 | // radioLayout->addWidget(m_scatterRadioButton); |
|
131 | // radioLayout->addWidget(m_scatterRadioButton); | |
128 | radioLayout->addWidget(m_pieRadioButton); |
|
132 | radioLayout->addWidget(m_pieRadioButton); | |
129 | // radioLayout->addWidget(m_areaRadioButton); |
|
133 | // radioLayout->addWidget(m_areaRadioButton); | |
130 | radioLayout->addWidget(m_barRadioButton); |
|
134 | radioLayout->addWidget(m_barRadioButton); | |
131 | radioLayout->addStretch(); |
|
135 | radioLayout->addStretch(); | |
132 |
|
136 | |||
133 | // create main layout |
|
137 | // create main layout | |
134 | QGridLayout* mainLayout = new QGridLayout; |
|
138 | QGridLayout* mainLayout = new QGridLayout; | |
135 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
139 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
136 | mainLayout->addLayout(radioLayout, 3, 0); |
|
140 | mainLayout->addLayout(radioLayout, 3, 0); | |
137 | mainLayout->addWidget(m_tableView, 1, 0); |
|
141 | mainLayout->addWidget(m_tableView, 1, 0); | |
138 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
142 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
139 | setLayout(mainLayout); |
|
143 | setLayout(mainLayout); | |
140 | m_lineRadioButton->setFocus(); |
|
144 | m_lineRadioButton->setFocus(); | |
141 | } |
|
145 | } | |
142 |
|
146 | |||
143 | void TableWidget::addRowAbove() |
|
147 | void TableWidget::addRowAbove() | |
144 | { |
|
148 | { | |
145 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
149 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
146 |
|
150 | |||
147 | } |
|
151 | } | |
148 |
|
152 | |||
149 | void TableWidget::addRowBelow() |
|
153 | void TableWidget::addRowBelow() | |
150 | { |
|
154 | { | |
151 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
155 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
152 |
|
156 | |||
153 | } |
|
157 | } | |
154 |
|
158 | |||
155 | void TableWidget::removeRow() |
|
159 | void TableWidget::removeRow() | |
156 | { |
|
160 | { | |
157 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
161 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
158 | } |
|
162 | } | |
159 |
|
163 | |||
160 | void TableWidget::addColumnRight() |
|
164 | void TableWidget::addColumnRight() | |
161 | { |
|
165 | { | |
162 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
166 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); | |
163 | } |
|
167 | } | |
164 |
|
168 | |||
165 | void TableWidget::removeColumn() |
|
169 | void TableWidget::removeColumn() | |
166 | { |
|
170 | { | |
167 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
171 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); | |
168 | } |
|
172 | } | |
169 |
|
173 | |||
170 | void TableWidget::updateChartType(bool toggle) |
|
174 | void TableWidget::updateChartType(bool toggle) | |
171 | { |
|
175 | { | |
172 | // this if is needed, so that the function is only called once. |
|
176 | // this if is needed, so that the function is only called once. | |
173 | // For the radioButton that was enabled. |
|
177 | // For the radioButton that was enabled. | |
174 | if (toggle) { |
|
178 | if (toggle) { | |
175 | // specialPie = 0; |
|
179 | // specialPie = 0; | |
176 | m_chart->removeAllSeries(); |
|
180 | m_chart->removeAllSeries(); | |
177 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
181 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
178 | // m_chart->axisY()->setNiceNumbersEnabled(false); |
|
182 | // m_chart->axisY()->setNiceNumbersEnabled(false); | |
179 |
|
183 | |||
180 | // // renable axes of the chart (pie hides them) |
|
184 | // // renable axes of the chart (pie hides them) | |
181 | // // x axis |
|
185 | // // x axis | |
182 | // QAxis *axis = m_chart->axisX(); |
|
186 | // QAxis *axis = m_chart->axisX(); | |
183 | // axis->setAxisVisible(true); |
|
187 | // axis->setAxisVisible(true); | |
184 | // axis->setGridLineVisible(true); |
|
188 | // axis->setGridLineVisible(true); | |
185 | // axis->setLabelsVisible(true); |
|
189 | // axis->setLabelsVisible(true); | |
186 |
|
190 | |||
187 | // // y axis |
|
191 | // // y axis | |
188 | // axis = m_chart->axisY(); |
|
192 | // axis = m_chart->axisY(); | |
189 | // axis->setAxisVisible(true); |
|
193 | // axis->setAxisVisible(true); | |
190 | // axis->setGridLineVisible(true); |
|
194 | // axis->setGridLineVisible(true); | |
191 | // axis->setLabelsVisible(true); |
|
195 | // axis->setLabelsVisible(true); | |
192 |
|
196 | |||
193 | // m_model->clearMapping(); |
|
197 | // m_model->clearMapping(); | |
194 |
|
198 | |||
195 | QString seriesColorHex = "#000000"; |
|
199 | QString seriesColorHex = "#000000"; | |
196 | // QPen pen; |
|
200 | // QPen pen; | |
197 | // pen.setWidth(2); |
|
201 | // pen.setWidth(2); | |
198 |
|
202 | |||
199 | if (m_lineRadioButton->isChecked()) |
|
203 | if (m_lineRadioButton->isChecked()) | |
200 | { |
|
204 | { | |
201 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
205 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
202 |
|
206 | |||
203 | // // series 1 |
|
207 | // // series 1 | |
204 | // m_series = new QLineSeries; |
|
208 | // m_series = new QLineSeries; | |
205 | // m_series->setModel(m_model); |
|
209 | // m_series->setModel(m_model); | |
206 |
|
210 | |||
207 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
211 | // QXYModelMapper *mapper = new QXYModelMapper; | |
208 | // mapper->setMapX(0); |
|
212 | // mapper->setMapX(0); | |
209 | // mapper->setMapY(1); |
|
213 | // mapper->setMapY(1); | |
210 | // mapper->setFirst(3); |
|
214 | // mapper->setFirst(3); | |
211 | // mapper->setCount(4); |
|
215 | // mapper->setCount(4); | |
212 | // m_series->setModelMapper(mapper); |
|
216 | // m_series->setModelMapper(mapper); | |
213 | // // m_series->setModelMapping(0,1, Qt::Vertical); |
|
217 | // // m_series->setModelMapping(0,1, Qt::Vertical); | |
214 | // // m_series->setModelMappingRange(3, 4); |
|
218 | // // m_series->setModelMappingRange(3, 4); | |
215 | // m_chart->addSeries(m_series); |
|
219 | // m_chart->addSeries(m_series); | |
216 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
220 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
217 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
221 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
218 |
|
222 | |||
219 | // // series 2 |
|
223 | // // series 2 | |
220 | // m_series = new QLineSeries; |
|
224 | // m_series = new QLineSeries; | |
221 | // m_series->setModel(m_model); |
|
225 | // m_series->setModel(m_model); | |
222 |
|
226 | |||
223 | // mapper = new QXYModelMapper; |
|
227 | // mapper = new QXYModelMapper; | |
224 | // mapper->setMapX(3); |
|
228 | // mapper->setMapX(3); | |
225 | // mapper->setMapY(4); |
|
229 | // mapper->setMapY(4); | |
226 | // // mapper->setFirst(3); |
|
230 | // // mapper->setFirst(3); | |
227 | // // mapper->setCount(4); |
|
231 | // // mapper->setCount(4); | |
228 | // m_series->setModelMapper(mapper); |
|
232 | // m_series->setModelMapper(mapper); | |
229 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
233 | // // m_series->setModelMapping(2,3, Qt::Vertical); | |
230 | // m_chart->addSeries(m_series); |
|
234 | // m_chart->addSeries(m_series); | |
231 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
235 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
232 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
236 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
233 |
|
237 | |||
234 | // // series 3 |
|
238 | // // series 3 | |
235 | // m_series = new QLineSeries; |
|
239 | // m_series = new QLineSeries; | |
236 | // m_series->setModel(m_model); |
|
240 | // m_series->setModel(m_model); | |
237 |
|
241 | |||
238 | // mapper = new QXYModelMapper; |
|
242 | // mapper = new QXYModelMapper; | |
239 | // mapper->setMapX(5); |
|
243 | // mapper->setMapX(5); | |
240 | // mapper->setMapY(6); |
|
244 | // mapper->setMapY(6); | |
241 | // mapper->setFirst(2); |
|
245 | // mapper->setFirst(2); | |
242 | // mapper->setCount(-1); |
|
246 | // mapper->setCount(-1); | |
243 | // m_series->setModelMapper(mapper); |
|
247 | // m_series->setModelMapper(mapper); | |
244 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
248 | // // m_series->setModelMapping(4,5, Qt::Vertical); | |
245 | // // m_series->setModelMappingRange(2, -1); |
|
249 | // // m_series->setModelMappingRange(2, -1); | |
246 | // m_chart->addSeries(m_series); |
|
250 | // m_chart->addSeries(m_series); | |
247 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
251 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
248 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
252 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | |
249 | } |
|
253 | } | |
250 | else if (m_splineRadioButton->isChecked()) |
|
254 | else if (m_splineRadioButton->isChecked()) | |
251 | { |
|
255 | { | |
252 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
256 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
253 |
|
257 | |||
254 | // // series 1 |
|
258 | // // series 1 | |
255 | // m_series = new QSplineSeries; |
|
259 | // m_series = new QSplineSeries; | |
256 | // m_series->setModel(m_model); |
|
260 | // m_series->setModel(m_model); | |
257 |
|
261 | |||
258 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
262 | // QXYModelMapper *mapper = new QXYModelMapper; | |
259 | // mapper->setMapX(0); |
|
263 | // mapper->setMapX(0); | |
260 | // mapper->setMapY(1); |
|
264 | // mapper->setMapY(1); | |
261 | // mapper->setFirst(0); |
|
265 | // mapper->setFirst(0); | |
262 | // mapper->setCount(-1); |
|
266 | // mapper->setCount(-1); | |
263 |
|
267 | |||
264 | // m_series->setModelMapper(mapper); |
|
268 | // m_series->setModelMapper(mapper); | |
265 |
|
269 | |||
266 | // m_chart->addSeries(m_series); |
|
270 | // m_chart->addSeries(m_series); | |
267 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
271 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
268 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
272 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
269 |
|
273 | |||
270 | // // series 2 |
|
274 | // // series 2 | |
271 | // m_series = new QSplineSeries; |
|
275 | // m_series = new QSplineSeries; | |
272 | // m_series->setModel(m_model); |
|
276 | // m_series->setModel(m_model); | |
273 |
|
277 | |||
274 | // mapper = new QXYModelMapper; |
|
278 | // mapper = new QXYModelMapper; | |
275 | // mapper->setMapX(2); |
|
279 | // mapper->setMapX(2); | |
276 | // mapper->setMapY(3); |
|
280 | // mapper->setMapY(3); | |
277 | // mapper->setFirst(2); |
|
281 | // mapper->setFirst(2); | |
278 | // mapper->setCount(4); |
|
282 | // mapper->setCount(4); | |
279 |
|
283 | |||
280 | // m_series->setModelMapper(mapper); |
|
284 | // m_series->setModelMapper(mapper); | |
281 |
|
285 | |||
282 | // m_chart->addSeries(m_series); |
|
286 | // m_chart->addSeries(m_series); | |
283 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
287 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
284 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
288 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
285 |
|
289 | |||
286 | // // series 3 |
|
290 | // // series 3 | |
287 | // m_series = new QSplineSeries; |
|
291 | // m_series = new QSplineSeries; | |
288 | // m_series->setModel(m_model); |
|
292 | // m_series->setModel(m_model); | |
289 |
|
293 | |||
290 | // mapper = new QXYModelMapper; |
|
294 | // mapper = new QXYModelMapper; | |
291 | // mapper->setMapX(4); |
|
295 | // mapper->setMapX(4); | |
292 | // mapper->setMapY(5); |
|
296 | // mapper->setMapY(5); | |
293 | // mapper->setFirst(2); |
|
297 | // mapper->setFirst(2); | |
294 | // mapper->setCount(-1); |
|
298 | // mapper->setCount(-1); | |
295 |
|
299 | |||
296 | // m_series->setModelMapper(mapper); |
|
300 | // m_series->setModelMapper(mapper); | |
297 |
|
301 | |||
298 | // m_chart->addSeries(m_series); |
|
302 | // m_chart->addSeries(m_series); | |
299 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
303 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
300 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
304 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
301 | } |
|
305 | } | |
302 | // else if (m_scatterRadioButton->isChecked()) |
|
306 | // else if (m_scatterRadioButton->isChecked()) | |
303 | // { |
|
307 | // { | |
304 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
308 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
305 |
|
309 | |||
306 | // // series 1 |
|
310 | // // series 1 | |
307 | // m_series = new QScatterSeries; |
|
311 | // m_series = new QScatterSeries; | |
308 | // m_series->setModel(m_model); |
|
312 | // m_series->setModel(m_model); | |
309 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
313 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
310 | // // m_series->setModelMappingRange(2, 0); |
|
314 | // // m_series->setModelMappingRange(2, 0); | |
311 | // // series->setModelMapping(0,1, Qt::Horizontal); |
|
315 | // // series->setModelMapping(0,1, Qt::Horizontal); | |
312 | // m_chart->addSeries(m_series); |
|
316 | // m_chart->addSeries(m_series); | |
313 |
|
317 | |||
314 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
318 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
315 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
319 | // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
316 |
|
320 | |||
317 | // // series 2 |
|
321 | // // series 2 | |
318 | // m_series = new QScatterSeries; |
|
322 | // m_series = new QScatterSeries; | |
319 | // m_series->setModel(m_model); |
|
323 | // m_series->setModel(m_model); | |
320 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
324 | // m_series->setModelMapping(2,3, Qt::Vertical); | |
321 | // // m_series->setModelMappingRange(1, 6); |
|
325 | // // m_series->setModelMappingRange(1, 6); | |
322 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
326 | // // series->setModelMapping(2,3, Qt::Horizontal); | |
323 | // m_chart->addSeries(m_series); |
|
327 | // m_chart->addSeries(m_series); | |
324 |
|
328 | |||
325 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
329 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
326 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
330 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
327 |
|
331 | |||
328 | // // series 3 |
|
332 | // // series 3 | |
329 | // m_series = new QScatterSeries; |
|
333 | // m_series = new QScatterSeries; | |
330 | // m_series->setModel(m_model); |
|
334 | // m_series->setModel(m_model); | |
331 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
335 | // m_series->setModelMapping(4,5, Qt::Vertical); | |
332 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
336 | // // series->setModelMapping(4,5, Qt::Horizontal); | |
333 | // m_chart->addSeries(m_series); |
|
337 | // m_chart->addSeries(m_series); | |
334 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
338 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
335 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
339 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
336 | // } |
|
340 | // } | |
337 | else if (m_pieRadioButton->isChecked()) |
|
341 | else if (m_pieRadioButton->isChecked()) | |
338 | { |
|
342 | { | |
339 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
343 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
340 |
|
344 | |||
341 | // pie 1 |
|
345 | // pie 1 | |
342 |
|
|
346 | m_pieSeries = new QPieSeries; | |
343 |
|
347 | |||
344 | m_pieMapper = new QPieModelMapper; |
|
348 | m_pieMapper = new QPieModelMapper; | |
345 | m_pieMapper->setValuesIndex(1); |
|
349 | m_pieMapper->setValuesIndex(1); | |
346 | m_pieMapper->setLabelsIndex(1); |
|
350 | m_pieMapper->setLabelsIndex(1); | |
347 | m_pieMapper->setSeries(pieSeries); |
|
351 | m_pieMapper->setSeries(m_pieSeries); | |
348 | m_pieMapper->setModel(m_model); |
|
352 | m_pieMapper->setModel(m_model); | |
349 | m_pieMapper->setFirst(2); |
|
353 | m_pieMapper->setFirst(2); | |
350 | m_pieMapper->setCount(5); |
|
354 | // m_pieMapper->setCount(5); | |
351 | // pieSeries->setModelMapper(mapper); |
|
355 | // pieSeries->setModelMapper(mapper); | |
352 |
|
356 | |||
353 | pieSeries->setLabelsVisible(true); |
|
357 | m_pieSeries->setLabelsVisible(true); | |
354 | pieSeries->setPieSize(0.75); |
|
358 | m_pieSeries->setPieSize(0.75); | |
355 | // pieSeries->setHorizontalPosition(0.2); |
|
359 | // pieSeries->setHorizontalPosition(0.2); | |
356 | // pieSeries->setVerticalPosition(0.3); |
|
360 | // pieSeries->setVerticalPosition(0.3); | |
357 |
|
361 | |||
358 | m_chart->addSeries(pieSeries); |
|
362 | m_chart->addSeries(m_pieSeries); | |
359 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
363 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
360 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5)); |
|
364 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 50)); | |
361 |
|
365 | |||
362 |
|
366 | |||
363 | // pieSeries->slices().at(0)->setValue(400); |
|
367 | // pieSeries->slices().at(0)->setValue(400); | |
364 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
368 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
365 |
|
369 | |||
366 | // // pie 2 |
|
370 | // // pie 2 | |
367 | // pieSeries = new QPieSeries; |
|
371 | // pieSeries = new QPieSeries; | |
368 | // pieSeries->setModel(m_model); |
|
372 | // pieSeries->setModel(m_model); | |
369 |
|
373 | |||
370 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
374 | // pieSeries->setModelMapping(1,1, Qt::Vertical); | |
371 | // pieSeries->setModelMappingRange(2, -1); |
|
375 | // pieSeries->setModelMappingRange(2, -1); | |
372 | // pieSeries->setLabelsVisible(true); |
|
376 | // pieSeries->setLabelsVisible(true); | |
373 | // pieSeries->setPieSize(0.35); |
|
377 | // pieSeries->setPieSize(0.35); | |
374 | // pieSeries->setHorizontalPosition(0.8); |
|
378 | // pieSeries->setHorizontalPosition(0.8); | |
375 | // pieSeries->setVerticalPosition(0.3); |
|
379 | // pieSeries->setVerticalPosition(0.3); | |
376 | // m_chart->addSeries(pieSeries); |
|
380 | // m_chart->addSeries(pieSeries); | |
377 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
381 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
378 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
382 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); | |
379 |
|
383 | |||
380 | // // pie 3 |
|
384 | // // pie 3 | |
381 | // pieSeries = new QPieSeries; |
|
385 | // pieSeries = new QPieSeries; | |
382 | // pieSeries->setModel(m_model); |
|
386 | // pieSeries->setModel(m_model); | |
383 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
387 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
384 | // pieSeries->setLabelsVisible(true); |
|
388 | // pieSeries->setLabelsVisible(true); | |
385 | // pieSeries->setPieSize(0.35); |
|
389 | // pieSeries->setPieSize(0.35); | |
386 | // pieSeries->setHorizontalPosition(0.5); |
|
390 | // pieSeries->setHorizontalPosition(0.5); | |
387 | // pieSeries->setVerticalPosition(0.75); |
|
391 | // pieSeries->setVerticalPosition(0.75); | |
388 | // m_chart->addSeries(pieSeries); |
|
392 | // m_chart->addSeries(pieSeries); | |
389 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
393 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
390 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
394 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
391 |
|
395 | |||
392 | // // special pie |
|
396 | // // special pie | |
393 | // specialPie = new QPieSeries; |
|
397 | // specialPie = new QPieSeries; | |
394 | // specialPie->append(17, "1"); |
|
398 | // specialPie->append(17, "1"); | |
395 | // specialPie->append(45, "2"); |
|
399 | // specialPie->append(45, "2"); | |
396 | // specialPie->append(77, "3"); |
|
400 | // specialPie->append(77, "3"); | |
397 | // specialPie->append(37, "4"); |
|
401 | // specialPie->append(37, "4"); | |
398 | // specialPie->append(27, "5"); |
|
402 | // specialPie->append(27, "5"); | |
399 | // specialPie->append(47, "6"); |
|
403 | // specialPie->append(47, "6"); | |
400 | // specialPie->setPieSize(0.35); |
|
404 | // specialPie->setPieSize(0.35); | |
401 | // specialPie->setHorizontalPosition(0.8); |
|
405 | // specialPie->setHorizontalPosition(0.8); | |
402 | // specialPie->setVerticalPosition(0.75); |
|
406 | // specialPie->setVerticalPosition(0.75); | |
403 | // specialPie->setLabelsVisible(true); |
|
407 | // specialPie->setLabelsVisible(true); | |
404 | // m_chart->addSeries(specialPie); |
|
408 | // m_chart->addSeries(specialPie); | |
405 | } |
|
409 | } | |
406 | // else if (m_areaRadioButton->isChecked()) |
|
410 | // else if (m_areaRadioButton->isChecked()) | |
407 | // { |
|
411 | // { | |
408 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
412 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
409 |
|
413 | |||
410 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
414 | // QLineSeries* upperLineSeries = new QLineSeries; | |
411 | // upperLineSeries->setModel(m_model); |
|
415 | // upperLineSeries->setModel(m_model); | |
412 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
416 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
413 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
417 | // // upperLineSeries->setModelMappingRange(1, 5); | |
414 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
418 | // QLineSeries* lowerLineSeries = new QLineSeries; | |
415 | // lowerLineSeries->setModel(m_model); |
|
419 | // lowerLineSeries->setModel(m_model); | |
416 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
420 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
417 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
421 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
418 | // m_chart->addSeries(areaSeries); |
|
422 | // m_chart->addSeries(areaSeries); | |
419 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
423 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
420 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
424 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
421 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
425 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
422 | // } |
|
426 | // } | |
423 | else if (m_barRadioButton->isChecked()) |
|
427 | else if (m_barRadioButton->isChecked()) | |
424 | { |
|
428 | { | |
425 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
429 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
426 |
|
430 | |||
427 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
431 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
428 | // barSeries->setCategories(QStringList()); |
|
432 | // barSeries->setCategories(QStringList()); | |
429 | // barSeries->setModel(m_model); |
|
433 | // barSeries->setModel(m_model); | |
430 | // // barSeries->setModelMappingRange(2, 5); |
|
434 | // // barSeries->setModelMappingRange(2, 5); | |
431 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
435 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
432 |
|
436 | |||
433 | // QBarModelMapper *mapper = new QBarModelMapper; |
|
437 | // QBarModelMapper *mapper = new QBarModelMapper; | |
434 | // mapper->setMapCategories(5); |
|
438 | // mapper->setMapCategories(5); | |
435 | // mapper->setMapBarBottom(2); |
|
439 | // mapper->setMapBarBottom(2); | |
436 | // mapper->setMapBarTop(4); |
|
440 | // mapper->setMapBarTop(4); | |
437 | // barSeries->setModelMapper(mapper); |
|
441 | // barSeries->setModelMapper(mapper); | |
438 | // m_chart->addSeries(barSeries); |
|
442 | // m_chart->addSeries(barSeries); | |
439 | // QList<QBarSet*> barsets = barSeries->barSets(); |
|
443 | // QList<QBarSet*> barsets = barSeries->barSets(); | |
440 | // for (int i = 0; i < barsets.count(); i++) { |
|
444 | // for (int i = 0; i < barsets.count(); i++) { | |
441 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
445 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
442 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); |
|
446 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
443 | // } |
|
447 | // } | |
444 | } |
|
448 | } | |
445 |
|
449 | |||
446 |
|
450 | |||
447 | if (!m_barRadioButton->isChecked()) { |
|
451 | if (!m_barRadioButton->isChecked()) { | |
448 | m_chart->axisX()->setRange(0, 500); |
|
452 | m_chart->axisX()->setRange(0, 500); | |
449 | m_chart->axisY()->setRange(0, 220); |
|
453 | m_chart->axisY()->setRange(0, 220); | |
450 | } |
|
454 | } | |
451 | m_chart->legend()->setVisible(true); |
|
455 | m_chart->legend()->setVisible(true); | |
452 |
|
456 | |||
453 | // repaint table view colors |
|
457 | // repaint table view colors | |
454 | m_tableView->repaint(); |
|
458 | m_tableView->repaint(); | |
455 | m_tableView->setFocus(); |
|
459 | m_tableView->setFocus(); | |
456 | } |
|
460 | } | |
457 | } |
|
461 | } | |
458 |
|
462 | |||
459 | void TableWidget::testPie() |
|
463 | void TableWidget::testPie() | |
460 | { |
|
464 | { | |
461 | m_pieMapper->setCount(-1); |
|
465 | // m_pieMapper->setCount(-1); | |
|
466 | QPieSlice *slice = new QPieSlice("Hehe", 145); | |||
|
467 | slice->setLabelVisible(); | |||
|
468 | m_pieSeries->append(slice); | |||
|
469 | ||||
|
470 | slice = new QPieSlice("Hoho", 34); | |||
|
471 | slice->setLabelVisible(); | |||
|
472 | m_pieSeries->append(slice); | |||
462 | // m_series->modelMapper()->setMapX(4); |
|
473 | // m_series->modelMapper()->setMapX(4); | |
463 | // m_tableView->setColumnWidth(10, 250); |
|
474 | // m_tableView->setColumnWidth(10, 250); | |
464 | // if (specialPie) { |
|
475 | // if (specialPie) { | |
465 | // specialPie->remove(specialPie->slices().at(2)); |
|
476 | // specialPie->remove(specialPie->slices().at(2)); | |
466 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
477 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | |
467 | // specialPie->append(4, "heloo"); |
|
478 | // specialPie->append(4, "heloo"); | |
468 | // } |
|
479 | // } | |
469 | } |
|
480 | } | |
470 |
|
481 | |||
|
482 | void TableWidget::testPie2() | |||
|
483 | { | |||
|
484 | QPieSlice *slice; | |||
|
485 | if (m_pieSeries->count() > 0) { | |||
|
486 | slice = m_pieSeries->slices().last(); | |||
|
487 | m_pieSeries->remove(slice); | |||
|
488 | } | |||
|
489 | ||||
|
490 | if (m_pieSeries->count() > 0) { | |||
|
491 | slice = m_pieSeries->slices().first(); | |||
|
492 | m_pieSeries->remove(slice); | |||
|
493 | } | |||
|
494 | } | |||
|
495 | ||||
471 | TableWidget::~TableWidget() |
|
496 | TableWidget::~TableWidget() | |
472 | { |
|
497 | { | |
473 |
|
498 | |||
474 | } |
|
499 | } |
@@ -1,73 +1,75 | |||||
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 |
|
|
28 | #include <QPieSeries> | |
29 | #include <QPieModelMapper> |
|
29 | #include <QPieModelMapper> | |
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 |
|
56 | |||
56 | private: |
|
57 | private: | |
57 | QChartView* m_chartView; |
|
58 | QChartView* m_chartView; | |
58 | QChart* m_chart; |
|
59 | QChart* m_chart; | |
59 | QXYSeries* m_series; |
|
60 | QXYSeries* m_series; | |
60 | CustomTableModel* m_model; |
|
61 | CustomTableModel* m_model; | |
61 | QTableView* m_tableView; |
|
62 | QTableView* m_tableView; | |
62 | QRadioButton* m_lineRadioButton; |
|
63 | QRadioButton* m_lineRadioButton; | |
63 | QRadioButton* m_splineRadioButton; |
|
64 | QRadioButton* m_splineRadioButton; | |
64 | QRadioButton* m_scatterRadioButton; |
|
65 | QRadioButton* m_scatterRadioButton; | |
65 | QRadioButton* m_pieRadioButton; |
|
66 | QRadioButton* m_pieRadioButton; | |
66 | QRadioButton* m_areaRadioButton; |
|
67 | QRadioButton* m_areaRadioButton; | |
67 | QRadioButton* m_barRadioButton; |
|
68 | QRadioButton* m_barRadioButton; | |
68 | QSpinBox* m_linesCountSpinBox; |
|
69 | QSpinBox* m_linesCountSpinBox; | |
69 | QPieModelMapper *m_pieMapper; |
|
70 | QPieModelMapper *m_pieMapper; | |
|
71 | QPieSeries* m_pieSeries; | |||
70 | // QPieSeries* specialPie; |
|
72 | // QPieSeries* specialPie; | |
71 | }; |
|
73 | }; | |
72 |
|
74 | |||
73 | #endif // TABLEWIDGET_H |
|
75 | #endif // TABLEWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now