##// END OF EJS Templates
Added Vertical and Horizontal QXYModelMapper
Marek Rosa -
r1252:4e92004ccd6b
parent child
Show More
@@ -0,0 +1,32
1 #include "qhxymodelmapper.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
7 {
8 }
9
10 int QHXYModelMapper::xRow() const
11 {
12 return QXYModelMapper::xSection();
13 }
14
15 void QHXYModelMapper::setXRow(int xRow)
16 {
17 return QXYModelMapper::setXSection(xRow);
18 }
19
20 int QHXYModelMapper::yRow() const
21 {
22 return QXYModelMapper::ySection();
23 }
24
25 void QHXYModelMapper::setYRow(int yRow)
26 {
27 return QXYModelMapper::setYSection(yRow);
28 }
29
30 #include "moc_qhxymodelmapper.cpp"
31
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,27
1 #ifndef QHXYMODELMAPPER_H
2 #define QHXYMODELMAPPER_H
3
4 #include <QXYModelMapper>
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8 class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper
9 {
10 Q_OBJECT
11 Q_PROPERTY(int xRow READ xRow WRITE setXRow)
12 Q_PROPERTY(int yRow READ yRow WRITE setYRow)
13
14 public:
15 explicit QHXYModelMapper(QObject *parent = 0);
16
17 int xRow() const;
18 void setXRow(int xRow);
19
20 int yRow() const;
21 void setYRow(int yRow);
22
23 };
24
25 QTCOMMERCIALCHART_END_NAMESPACE
26
27 #endif // QHXYMODELMAPPER_H
@@ -0,0 +1,32
1 #include "qvxymodelmapper.h"
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
5 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
7 {
8 }
9
10 int QVXYModelMapper::xColumn() const
11 {
12 return QXYModelMapper::xSection();
13 }
14
15 void QVXYModelMapper::setXColumn(int xColumn)
16 {
17 return QXYModelMapper::setXSection(xColumn);
18 }
19
20 int QVXYModelMapper::yColumn() const
21 {
22 return QXYModelMapper::ySection();
23 }
24
25 void QVXYModelMapper::setYColumn(int yColumn)
26 {
27 return QXYModelMapper::setYSection(yColumn);
28 }
29
30 #include "moc_qvxymodelmapper.cpp"
31
32 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,27
1 #ifndef QVXYMODELMAPPER_H
2 #define QVXYMODELMAPPER_H
3
4 #include <QXYModelMapper>
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
8 class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper
9 {
10 Q_OBJECT
11 Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn)
12 Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn)
13
14 public:
15 explicit QVXYModelMapper(QObject *parent = 0);
16
17 int xColumn() const;
18 void setXColumn(int xColumn);
19
20 int yColumn() const;
21 void setYColumn(int yColumn);
22
23 };
24
25 QTCOMMERCIALCHART_END_NAMESPACE
26
27 #endif // QVXYMODELMAPPER_H
@@ -1,111 +1,112
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "declarativemodel.h"
22 22 #include <qdeclarativelist.h>
23 23 #include <QDebug>
24 24
25 25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 26
27 27
28 28 ////////////// Table model row ///////////////////
29 29
30 30 DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent)
31 31 : QObject(parent)
32 32 {
33 33 }
34 34
35 35 QVariantList DeclarativeTableModelElement::values()
36 36 {
37 37 return m_values;
38 38 }
39 39
40 40 void DeclarativeTableModelElement::setValues(QVariantList values)
41 41 {
42 42 m_values = values;
43 43 }
44 44
45 45 ////////////// Table model ///////////////////
46 46
47 47 DeclarativeTableModel::DeclarativeTableModel(QObject *parent) :
48 48 ChartTableModel(parent)
49 49 {
50 50 }
51 51
52 52 void DeclarativeTableModel::classBegin()
53 53 {
54 54 }
55 55
56 56 void DeclarativeTableModel::componentComplete()
57 57 {
58 58 foreach (QObject *child, children()) {
59 59 if (qobject_cast<DeclarativeTableModelElement *>(child)) {
60 60 append(qobject_cast<DeclarativeTableModelElement *>(child)->values());
61 61 }
62 62 }
63 63 }
64 64
65 65 QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren()
66 66 {
67 67 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild);
68 68 }
69 69
70 70 void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list,
71 71 QObject *child)
72 72 {
73 73 // childs are added in componentComplete instead
74 74 Q_UNUSED(list)
75 75 Q_UNUSED(child)
76 76 }
77 77
78 78 void DeclarativeTableModel::append(QVariantList values)
79 79 {
80 80 // qDebug() << "DeclarativeTableModel::append:" << values;
81 81
82 82 while (columnCount() < values.count())
83 83 insertColumn(columnCount());
84 84
85 85 insertRow(rowCount());
86 86
87 87 QModelIndex beginIndex = QModelIndex();
88 88 QModelIndex endIndex = QModelIndex();
89 89 for (int i(0); i < values.count(); i++) {
90 90 QModelIndex modelIndex = createIndex(rowCount() - 1, i);
91 91 if (i == 0)
92 92 beginIndex = modelIndex;
93 93 if (i == (values.count() - 1))
94 94 endIndex = modelIndex;
95 95 setData(modelIndex, values.at(i));
96 96 }
97 97 dataChanged(beginIndex, endIndex);
98 98 }
99 99
100 100 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point)
101 101 {
102 102 // qDebug() << "DeclarativeTableModel::appendPoint:" << point;
103 103 QVariantList values;
104 values.insert(mapper->mapX(), point->x());
105 values.insert(mapper->mapY(), point->y());
104 // TODO: XYModelMapper implementation has change, this code has to be updated.
105 // values.insert(mapper->mapX(), point->x());
106 // values.insert(mapper->mapY(), point->y());
106 107 append(values);
107 108 }
108 109
109 110 #include "moc_declarativemodel.cpp"
110 111
111 112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,85 +1,87
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 //#include "DeclarativeXySeries.h"
22 22 #include "declarativexyseries.h"
23 23 #include "declarativechart.h"
24 24 #include <QXYSeries>
25 25 #include <QXYModelMapper>
26 26 #include <QDeclarativeListProperty>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 DeclarativeXySeries::DeclarativeXySeries()
31 31 {
32 // TODO: XYModelMapper implementation has changed, this code has to be updated
33
32 34 // All the inherited objects must be of type QXYSeries, so it is safe to cast
33 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
34 // TODO: mapper should be available on the series by default
35 QXYModelMapper *mapper = new QXYModelMapper(series);
36 mapper->setMapX(0);
37 mapper->setMapY(1);
38 mapper->setFirst(0);
39 mapper->setCount(-1);
40 mapper->setOrientation(Qt::Vertical);
35 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
36 // // TODO: mapper should be available on the series by default
37 // QXYModelMapper *mapper = new QXYModelMapper(series);
38 // mapper->setMapX(0);
39 // mapper->setMapY(1);
40 // mapper->setFirst(0);
41 // mapper->setCount(-1);
42 // mapper->setOrientation(Qt::Vertical);
41 43 // series->setModelMapper(mapper);
42 44 }
43 45
44 46 DeclarativeXySeries::~DeclarativeXySeries()
45 47 {
46 48 }
47 49
48 50 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model)
49 51 {
50 52 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
51 53 bool value(false);
52 54 if (m) {
53 55 // All the inherited objects must be of type QXYSeries, so it is safe to cast
54 56 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
55 57 // series->setModel(m);
56 58 } else {
57 59 qWarning("DeclarativeXySeries: Illegal model");
58 60 }
59 61 return value;
60 62 }
61 63
62 64 DeclarativeTableModel *DeclarativeXySeries::declarativeModel()
63 65 {
64 66 // All the inherited objects must be of type QXYSeries, so it is safe to cast
65 67 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
66 68 return 0; //qobject_cast<DeclarativeTableModel *>(series->model());
67 69 }
68 70
69 71 QColor DeclarativeXySeries::color()
70 72 {
71 73 // All the inherited objects must be of type QXYSeries, so it is safe to cast
72 74 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
73 75 return series->pen().color();
74 76 }
75 77
76 78 void DeclarativeXySeries::setColor(QColor color)
77 79 {
78 80 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
79 81 QPen pen = series->pen();
80 82 pen.setColor(color);
81 83 series->setPen(pen);
82 84 }
83 85
84 86
85 87 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,493 +1,492
1 1 #include "qpiemodelmapper_p.h"
2 2 #include "qpiemodelmapper.h"
3 3 #include "qpieseries.h"
4 4 #include "qpieslice.h"
5 5 #include <QAbstractItemModel>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 QPieModelMapper::QPieModelMapper(QObject *parent) :
10 10 QObject(parent),
11 11 d_ptr(new QPieModelMapperPrivate(this))
12 12 {
13 13 }
14 14
15 15 QAbstractItemModel* QPieModelMapper::model() const
16 16 {
17 17 Q_D(const QPieModelMapper);
18 18 return d->m_model;
19 19 }
20 20
21 21 void QPieModelMapper::setModel(QAbstractItemModel *model)
22 22 {
23 23 if (model == 0)
24 24 return;
25 25
26 26 Q_D(QPieModelMapper);
27 27 if (d->m_model) {
28 28 disconnect(d->m_model, 0, d, 0);
29 29 }
30 30
31 31 d->m_model = model;
32 32 d->initializePieFromModel();
33 33 // connect signals from the model
34 34 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
35 35 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
36 36 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
37 37 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
38 38 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
39 39 }
40 40
41 41 QPieSeries* QPieModelMapper::series() const
42 42 {
43 43 Q_D(const QPieModelMapper);
44 44 return d->m_series;
45 45 }
46 46
47 47 void QPieModelMapper::setSeries(QPieSeries *series)
48 48 {
49 if (series == 0)
50 return;
51
52 49 Q_D(QPieModelMapper);
53 50 if (d->m_series) {
54 51 disconnect(d->m_series, 0, d, 0);
55 52 }
56 53
54 if (series == 0)
55 return;
56
57 57 d->m_series = series;
58 58 d->initializePieFromModel();
59 59 // connect the signals from the series
60 60 connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>)));
61 61 connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>)));
62 // connect(d->m_model, SIGNAL(), d, SLOT());
63 62 }
64 63
65 64 int QPieModelMapper::first() const
66 65 {
67 66 Q_D(const QPieModelMapper);
68 67 return d->m_first;
69 68 }
70 69
71 70 void QPieModelMapper::setFirst(int first)
72 71 {
73 72 Q_D(QPieModelMapper);
74 73 d->m_first = qMax(first, 0);
75 74 d->initializePieFromModel();
76 75 }
77 76
78 77 int QPieModelMapper::count() const
79 78 {
80 79 Q_D(const QPieModelMapper);
81 80 return d->m_count;
82 81 }
83 82
84 83 void QPieModelMapper::setCount(int count)
85 84 {
86 85 Q_D(QPieModelMapper);
87 86 d->m_count = qMax(count, -1);
88 87 d->initializePieFromModel();
89 88 }
90 89
91 90 Qt::Orientation QPieModelMapper::orientation() const
92 91 {
93 92 Q_D(const QPieModelMapper);
94 93 return d->m_orientation;
95 94 }
96 95
97 96 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
98 97 {
99 98 Q_D(QPieModelMapper);
100 99 d->m_orientation = orientation;
101 100 d->initializePieFromModel();
102 101 }
103 102
104 103 int QPieModelMapper::valuesIndex() const
105 104 {
106 105 Q_D(const QPieModelMapper);
107 106 return d->m_valuesIndex;
108 107 }
109 108
110 109 void QPieModelMapper::setValuesIndex(int valuesIndex)
111 110 {
112 111 Q_D(QPieModelMapper);
113 112 d->m_valuesIndex = qMax(-1, valuesIndex);
114 113 d->initializePieFromModel();
115 114 }
116 115
117 116 int QPieModelMapper::labelsIndex() const
118 117 {
119 118 Q_D(const QPieModelMapper);
120 119 return d->m_labelsIndex;
121 120 }
122 121
123 122 void QPieModelMapper::setLabelsIndex(int labelsIndex)
124 123 {
125 124 Q_D(QPieModelMapper);
126 125 d->m_labelsIndex = qMax(-1, labelsIndex);
127 126 d->initializePieFromModel();
128 127 }
129 128
130 129 void QPieModelMapper::reset()
131 130 {
132 131 Q_D(QPieModelMapper);
133 132 d->m_first = 0;
134 133 d->m_count = -1;
135 134 d->m_orientation = Qt::Vertical;
136 135 d->m_valuesIndex = -1;
137 136 d->m_labelsIndex = -1;
138 137 }
139 138
140 139 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141 140
142 141 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
143 142 m_series(0),
144 143 m_model(0),
145 144 m_first(0),
146 145 m_count(-1),
147 146 m_orientation(Qt::Vertical),
148 147 m_valuesIndex(-1),
149 148 m_labelsIndex(-1),
150 149 m_seriesSignalsBlock(false),
151 150 m_modelSignalsBlock(false),
152 151 q_ptr(q)
153 152 {
154 153 }
155 154
156 155 void QPieModelMapperPrivate::blockModelSignals(bool block)
157 156 {
158 157 m_modelSignalsBlock = block;
159 158 }
160 159
161 160 void QPieModelMapperPrivate::blockSeriesSignals(bool block)
162 161 {
163 162 m_seriesSignalsBlock = block;
164 163 }
165 164
166 165
167 166 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
168 167 {
169 168 if (m_orientation == Qt::Vertical && (index.column() == m_valuesIndex || index.column() == m_labelsIndex)) {
170 169 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
171 170 return m_series->slices().at(index.row() - m_first);
172 171 } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesIndex || index.row() == m_labelsIndex)) {
173 172 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
174 173 return m_series->slices().at(index.column() - m_first);
175 174 }
176 175 return 0; // This part of model has not been mapped to any slice
177 176 }
178 177
179 178 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
180 179 {
181 180 if (m_count != -1 && slicePos >= m_count)
182 181 return QModelIndex(); // invalid
183 182
184 183 if (m_orientation == Qt::Vertical)
185 184 return m_model->index(slicePos + m_first, m_valuesIndex);
186 185 else
187 186 return m_model->index(m_valuesIndex, slicePos + m_first);
188 187 }
189 188
190 189 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
191 190 {
192 191 if (m_count != -1 && slicePos >= m_count)
193 192 return QModelIndex(); // invalid
194 193
195 194 if (m_orientation == Qt::Vertical)
196 195 return m_model->index(slicePos + m_first, m_labelsIndex);
197 196 else
198 197 return m_model->index(m_labelsIndex, slicePos + m_first);
199 198 }
200 199
201 200 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
202 201 {
203 202 if (m_orientation == Qt::Vertical && index.column() == m_labelsIndex)
204 203 return true;
205 204 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsIndex)
206 205 return true;
207 206
208 207 return false;
209 208 }
210 209
211 210 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
212 211 {
213 212 if (m_orientation == Qt::Vertical && index.column() == m_valuesIndex)
214 213 return true;
215 214 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesIndex)
216 215 return true;
217 216
218 217 return false;
219 218 }
220 219
221 220 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
222 221 {
223 222 if (m_seriesSignalsBlock)
224 223 return;
225 224
226 225 if (slices.count() == 0)
227 226 return;
228 227
229 228 int firstIndex = m_series->slices().indexOf(slices.at(0));
230 229 if (firstIndex == -1)
231 230 return;
232 231
233 232 if (m_count != -1)
234 233 m_count += slices.count();
235 234
236 235 for (int i = firstIndex; i < firstIndex + slices.count(); i++) {
237 236 m_slices.insert(i, slices.at(i - firstIndex));
238 237 connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
239 238 connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
240 239 }
241 240
242 241 blockModelSignals();
243 242 if (m_orientation == Qt::Vertical)
244 243 m_model->insertRows(firstIndex + m_first, slices.count());
245 244 else
246 245 m_model->insertColumns(firstIndex + m_first, slices.count());
247 246
248 247 for(int i = firstIndex; i < firstIndex + slices.count(); i++) {
249 248 m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value());
250 249 m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label());
251 250 }
252 251 blockModelSignals(false);
253 252 }
254 253
255 254 void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices)
256 255 {
257 256 if (m_seriesSignalsBlock)
258 257 return;
259 258
260 259 if (slices.count() == 0)
261 260 return;
262 261
263 262 int firstIndex = m_slices.indexOf(slices.at(0));
264 263 if (firstIndex == -1)
265 264 return;
266 265
267 266 if (m_count != -1)
268 267 m_count -= slices.count();
269 268
270 269 for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--)
271 270 m_slices.removeAt(i);
272 271
273 272 blockModelSignals();
274 273 if (m_orientation == Qt::Vertical)
275 274 m_model->removeRows(firstIndex + m_first, slices.count());
276 275 else
277 276 m_model->removeColumns(firstIndex + m_first, slices.count());
278 277 blockModelSignals(false);
279 278 }
280 279
281 280 void QPieModelMapperPrivate::sliceLabelChanged()
282 281 {
283 282 if (m_seriesSignalsBlock)
284 283 return;
285 284
286 285 blockModelSignals();
287 286 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
288 287 m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label());
289 288 blockModelSignals(false);
290 289 }
291 290
292 291 void QPieModelMapperPrivate::sliceValueChanged()
293 292 {
294 293 if (m_seriesSignalsBlock)
295 294 return;
296 295
297 296 blockModelSignals();
298 297 QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender());
299 298 m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value());
300 299 blockModelSignals(false);
301 300 }
302 301
303 302 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
304 303 {
305 304 if (m_modelSignalsBlock)
306 305 return;
307 306
308 307 blockSeriesSignals();
309 308 QModelIndex index;
310 309 QPieSlice *slice;
311 310 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
312 311 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
313 312 index = topLeft.sibling(row, column);
314 313 slice = pieSlice(index);
315 314 if (slice) {
316 315 if (isValueIndex(index))
317 316 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
318 317 if (isLabelIndex(index))
319 318 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
320 319 }
321 320 }
322 321 }
323 322 blockSeriesSignals(false);
324 323 }
325 324
326 325
327 326 void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
328 327 {
329 328 Q_UNUSED(parent);
330 329 if (m_modelSignalsBlock)
331 330 return;
332 331
333 332 blockSeriesSignals();
334 333 if (m_orientation == Qt::Vertical)
335 334 insertData(start, end);
336 335 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
337 336 initializePieFromModel();
338 337 blockSeriesSignals(false);
339 338 }
340 339
341 340 void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
342 341 {
343 342 Q_UNUSED(parent);
344 343 if (m_modelSignalsBlock)
345 344 return;
346 345
347 346 blockSeriesSignals();
348 347 if (m_orientation == Qt::Vertical)
349 348 removeData(start, end);
350 349 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
351 350 initializePieFromModel();
352 351 blockSeriesSignals(false);
353 352 }
354 353
355 354 void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
356 355 {
357 356 Q_UNUSED(parent);
358 357 if (m_modelSignalsBlock)
359 358 return;
360 359
361 360 blockSeriesSignals();
362 361 if (m_orientation == Qt::Horizontal)
363 362 insertData(start, end);
364 363 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
365 364 initializePieFromModel();
366 365 blockSeriesSignals(false);
367 366 }
368 367
369 368 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
370 369 {
371 370 Q_UNUSED(parent);
372 371 if (m_modelSignalsBlock)
373 372 return;
374 373
375 374 blockSeriesSignals();
376 375 if (m_orientation == Qt::Horizontal)
377 376 removeData(start, end);
378 377 else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie
379 378 initializePieFromModel();
380 379 blockSeriesSignals(false);
381 380 }
382 381
383 382 void QPieModelMapperPrivate::insertData(int start, int end)
384 383 {
385 384 if (m_model == 0 || m_series == 0)
386 385 return;
387 386
388 387 if (m_count != -1 && start >= m_first + m_count) {
389 388 return;
390 389 } else {
391 390 int addedCount = end - start + 1;
392 391 if (m_count != -1 && addedCount > m_count)
393 392 addedCount = m_count;
394 393 int first = qMax(start, m_first);
395 394 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
396 395 for (int i = first; i <= last; i++) {
397 396 QPieSlice *slice = new QPieSlice;
398 397 slice->setValue(m_model->data(valueModelIndex(i - m_first), Qt::DisplayRole).toDouble());
399 398 slice->setLabel(m_model->data(labelModelIndex(i - m_first), Qt::DisplayRole).toString());
400 399 slice->setLabelVisible();
401 400 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
402 401 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
403 402 m_series->insert(i - m_first, slice);
404 403 m_slices.insert(i - m_first, slice);
405 404 }
406 405
407 406 // remove excess of slices (abouve m_count)
408 407 if (m_count != -1 && m_series->slices().size() > m_count)
409 408 for (int i = m_series->slices().size() - 1; i >= m_count; i--) {
410 409 m_series->remove(m_series->slices().at(i));
411 410 m_slices.removeAt(i);
412 411 }
413 412 }
414 413 }
415 414
416 415 void QPieModelMapperPrivate::removeData(int start, int end)
417 416 {
418 417 if (m_model == 0 || m_series == 0)
419 418 return;
420 419
421 420 int removedCount = end - start + 1;
422 421 if (m_count != -1 && start >= m_first + m_count) {
423 422 return;
424 423 } else {
425 424 int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed
426 425 int first = qMax(start, m_first); // get the index of the first item that will be removed.
427 426 int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed.
428 427 for (int i = last; i >= first; i--) {
429 428 m_series->remove(m_series->slices().at(i - m_first));
430 429 m_slices.removeAt(i - m_first);
431 430 }
432 431
433 432 if (m_count != -1) {
434 433 int itemsAvailable; // check how many are available to be added
435 434 if (m_orientation == Qt::Vertical)
436 435 itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size();
437 436 else
438 437 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
439 438 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
440 439 int currentSize = m_series->slices().size();
441 440 if (toBeAdded > 0)
442 441 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
443 442 QPieSlice *slice = new QPieSlice;
444 443 if (m_orientation == Qt::Vertical) {
445 444 slice->setValue(m_model->data(m_model->index(i + m_first, m_valuesIndex), Qt::DisplayRole).toDouble());
446 445 slice->setLabel(m_model->data(m_model->index(i + m_first, m_labelsIndex), Qt::DisplayRole).toString());
447 446 } else {
448 447 slice->setValue(m_model->data(m_model->index(m_valuesIndex, i + m_first), Qt::DisplayRole).toDouble());
449 448 slice->setLabel(m_model->data(m_model->index(m_labelsIndex, i + m_first), Qt::DisplayRole).toString());
450 449 }
451 450 slice->setLabelVisible();
452 451 m_series->insert(i, slice);
453 452 m_slices.insert(i, slice);
454 453 }
455 454 }
456 455 }
457 456 }
458 457
459 458 void QPieModelMapperPrivate::initializePieFromModel()
460 459 {
461 460 if (m_model == 0 || m_series == 0)
462 461 return;
463 462
464 463 blockSeriesSignals();
465 464 // clear current content
466 465 m_series->clear();
467 466 m_slices.clear();
468 467
469 468 // create the initial slices set
470 469 int slicePos = 0;
471 470 QModelIndex valueIndex = valueModelIndex(slicePos);
472 471 QModelIndex labelIndex = labelModelIndex(slicePos);
473 472 while (valueIndex.isValid() && labelIndex.isValid()) {
474 473 QPieSlice *slice = new QPieSlice;
475 474 slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString());
476 475 slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble());
477 476 connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged()));
478 477 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
479 478 m_series->append(slice);
480 479 m_slices.append(slice);
481 480 // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
482 481 slicePos++;
483 482 valueIndex = valueModelIndex(slicePos);
484 483 labelIndex = labelModelIndex(slicePos);
485 484 }
486 485 m_series->setLabelsVisible(true);
487 486 blockSeriesSignals(false);
488 487 }
489 488
490 489 #include "moc_qpiemodelmapper_p.cpp"
491 490 #include "moc_qpiemodelmapper.cpp"
492 491
493 492 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,81 +1,81
1 1 #include "qxymodelmapper.h"
2 2
3 3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4 4
5 5 QXYModelMapper::QXYModelMapper(QObject *parent):
6 6 QObject(parent),
7 7 m_first(0),
8 8 m_count(-1),
9 9 m_orientation(Qt::Vertical),
10 m_mapX(-1),
11 m_mapY(-1)
10 m_xSection(-1),
11 m_ySection(-1)
12 12 {
13 13 }
14 14
15 15 int QXYModelMapper::first() const
16 16 {
17 17 return m_first;
18 18 }
19 19
20 20 void QXYModelMapper::setFirst(int first)
21 21 {
22 22 m_first = qMax(first, 0);
23 emit updated();
23 // emit updated();
24 24 }
25 25
26 26 int QXYModelMapper::count() const
27 27 {
28 28 return m_count;
29 29 }
30 30
31 31 void QXYModelMapper::setCount(int count)
32 32 {
33 33 m_count = qMax(count, -1);
34 emit updated();
34 // emit updated();
35 35 }
36 36
37 37 Qt::Orientation QXYModelMapper::orientation() const
38 38 {
39 39 return m_orientation;
40 40 }
41 41
42 42 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
43 43 {
44 44 m_orientation = orientation;
45 emit updated();
45 // emit updated();
46 46 }
47 47
48 int QXYModelMapper::mapX() const
48 int QXYModelMapper::xSection() const
49 49 {
50 return m_mapX;
50 return m_xSection;
51 51 }
52 52
53 void QXYModelMapper::setMapX(int mapX)
53 void QXYModelMapper::setXSection(int xSection)
54 54 {
55 m_mapX = mapX;
56 emit updated();
55 m_xSection = xSection;
56 // emit updated();
57 57 }
58 58
59 int QXYModelMapper::mapY() const
59 int QXYModelMapper::ySection() const
60 60 {
61 return m_mapY;
61 return m_ySection;
62 62 }
63 63
64 void QXYModelMapper::setMapY(int mapY)
64 void QXYModelMapper::setYSection(int ySection)
65 65 {
66 m_mapY = mapY;
67 emit updated();
66 m_ySection = ySection;
67 // emit updated();
68 68 }
69 69
70 70 void QXYModelMapper::reset()
71 71 {
72 72 m_first = 0;
73 73 m_count = -1;
74 74 m_orientation = Qt::Vertical;
75 m_mapX = -1;
76 m_mapY = -1;
75 m_xSection = -1;
76 m_ySection = -1;
77 77 }
78 78
79 79 #include "moc_qxymodelmapper.cpp"
80 80
81 81 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,53
1 1 #ifndef QXYMODELMAPPER_H
2 2 #define QXYMODELMAPPER_H
3 3
4 4 #include "qchartglobal.h"
5 5 #include <QObject>
6 6
7 7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 8
9 9 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
10 10 {
11 11 Q_OBJECT
12 Q_PROPERTY(int mapX READ mapX WRITE setMapX)
13 Q_PROPERTY(int mapY READ mapY WRITE setMapY)
12 Q_PROPERTY(int xSection READ xSection WRITE setXSection)
13 Q_PROPERTY(int ySection READ ySection WRITE setYSection)
14 14 Q_PROPERTY(int first READ first WRITE setFirst)
15 15 Q_PROPERTY(int count READ count WRITE setCount)
16 16 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
17 17 Q_ENUMS(Qt::Orientation)
18 18
19 19 public:
20 explicit QXYModelMapper(QObject *parent = 0);
21
22 20 int first() const;
23 21 void setFirst(int first);
24 22
25 23 int count() const;
26 24 void setCount(int count);
27 25
26 protected:
27 explicit QXYModelMapper(QObject *parent = 0);
28
28 29 Qt::Orientation orientation() const;
29 30 void setOrientation(Qt::Orientation orientation);
30 31
31 int mapX() const;
32 void setMapX(int mapX);
32 int xSection() const;
33 void setXSection(int xSection);
33 34
34 int mapY() const;
35 void setMapY(int mapY);
35 int ySection() const;
36 void setYSection(int ySection);
36 37
37 38 void reset();
38 39
39 40 Q_SIGNALS:
40 41 void updated();
41 42
42 43 private:
43 44 int m_first;
44 45 int m_count;
45 46 Qt::Orientation m_orientation;
46 int m_mapX;
47 int m_mapY;
47 int m_xSection;
48 int m_ySection;
48 49 };
49 50
50 51 QTCOMMERCIALCHART_END_NAMESPACE
51 52
52 53 #endif // QXYMODELMAPPER_H
@@ -1,16 +1,21
1 1 INCLUDEPATH += $$PWD
2 2 DEPENDPATH += $$PWD
3 3
4 4 SOURCES += \
5 5 $$PWD/xychart.cpp \
6 6 $$PWD/qxyseries.cpp \
7 $$PWD/qxymodelmapper.cpp
7 $$PWD/qxymodelmapper.cpp \
8 $$PWD/qvxymodelmapper.cpp \
9 $$PWD/qhxymodelmapper.cpp
8 10
9 11 PRIVATE_HEADERS += \
10 12 $$PWD/xychart_p.h \
11 13 $$PWD/qxyseries_p.h
12 14
13 15
14 16 PUBLIC_HEADERS += \
15 17 $$PWD/qxyseries.h \
16 $$PWD/qxymodelmapper.h
18 $$PWD/qxymodelmapper.h \
19 $$PWD/qvxymodelmapper.h \
20 $$PWD/qhxymodelmapper.h
21
@@ -1,270 +1,273
1 1 #include <QtCore/QString>
2 2 #include <QtTest/QtTest>
3 3
4 4 #include <qchart.h>
5 5 #include <qchartview.h>
6 6 #include <qpieseries.h>
7 7 #include <qvpiemodelmapper.h>
8 8 #include <qhpiemodelmapper.h>
9 9 #include <QStandardItemModel>
10 10
11 11 QTCOMMERCIALCHART_USE_NAMESPACE
12 12
13 13 class tst_piemodelmapper : public QObject
14 14 {
15 15 Q_OBJECT
16 16
17 17 public:
18 18 tst_piemodelmapper();
19 19
20 20 private Q_SLOTS:
21 21 void initTestCase();
22 22 void cleanupTestCase();
23 23 void init();
24 24 void cleanup();
25 25 void verticalMapper_data();
26 26 void verticalMapper();
27 27 void verticalMapperCustomMapping_data();
28 28 void verticalMapperCustomMapping();
29 29 void horizontalMapper_data();
30 30 void horizontalMapper();
31 31 void horizontalMapperCustomMapping_data();
32 32 void horizontalMapperCustomMapping();
33 33 void seriesUpdated();
34 34
35 35
36 36 private:
37 37 QStandardItemModel *m_model;
38 38 int m_modelRowCount;
39 39 int m_modelColumnCount;
40 40
41 41 QPieSeries *m_series;
42 42 QChart *m_chart;
43 43 };
44 44
45 45 tst_piemodelmapper::tst_piemodelmapper():
46 46 m_model(0),
47 47 m_modelRowCount(10),
48 48 m_modelColumnCount(8)
49 49 {
50 50 }
51 51
52 52 void tst_piemodelmapper::init()
53 53 {
54 54 m_series = new QPieSeries;
55 55 m_chart->addSeries(m_series);
56 56 }
57 57
58 58 void tst_piemodelmapper::cleanup()
59 59 {
60 60 m_chart->removeSeries(m_series);
61 61 delete m_series;
62 62 m_series = 0;
63 63 }
64 64
65 65 void tst_piemodelmapper::initTestCase()
66 66 {
67 67 m_chart = new QChart;
68 68 QChartView *chartView = new QChartView(m_chart);
69 69 chartView->show();
70 70
71 71 m_model = new QStandardItemModel(this);
72 72 for (int row = 0; row < m_modelRowCount; ++row) {
73 73 for (int column = 0; column < m_modelColumnCount; column++) {
74 74 QStandardItem *item = new QStandardItem(row * column);
75 75 m_model->setItem(row, column, item);
76 76 }
77 77 }
78 78 }
79 79
80 80 void tst_piemodelmapper::cleanupTestCase()
81 81 {
82 82 m_model->clear();
83 83 }
84 84
85 85 void tst_piemodelmapper::verticalMapper_data()
86 86 {
87 87 QTest::addColumn<int>("valuesColumn");
88 88 QTest::addColumn<int>("labelsColumn");
89 89 QTest::addColumn<int>("expectedCount");
90 90 QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount;
91 91 QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount;
92 92 QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0;
93 93 QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0;
94 94 QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0;
95 95 }
96 96
97 97 void tst_piemodelmapper::verticalMapper()
98 98 {
99 99 QFETCH(int, valuesColumn);
100 100 QFETCH(int, labelsColumn);
101 101 QFETCH(int, expectedCount);
102 102
103 103 QVPieModelMapper *mapper = new QVPieModelMapper;
104 104 mapper->setValuesColumn(valuesColumn);
105 105 mapper->setLabelsColumn(labelsColumn);
106 106 mapper->setModel(m_model);
107 107 mapper->setSeries(m_series);
108 108
109 109 QCOMPARE(m_series->count(), expectedCount);
110 110 QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn));
111 111 QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn));
112 112
113 113 delete mapper;
114 114 mapper = 0;
115 115 }
116 116
117 117 void tst_piemodelmapper::verticalMapperCustomMapping_data()
118 118 {
119 119 QTest::addColumn<int>("first");
120 120 QTest::addColumn<int>("countLimit");
121 121 QTest::addColumn<int>("expectedCount");
122 122 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount;
123 123 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3;
124 124 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount);
125 125 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3);
126 126 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0;
127 127 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0;
128 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;
129 129 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount;
130 130 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount;
131 131 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount;
132 132
133 133 }
134 134
135 135 void tst_piemodelmapper::verticalMapperCustomMapping()
136 136 {
137 137 QFETCH(int, first);
138 138 QFETCH(int, countLimit);
139 139 QFETCH(int, expectedCount);
140 140
141 141 QCOMPARE(m_series->count(), 0);
142 142
143 143 QVPieModelMapper *mapper = new QVPieModelMapper;
144 144 mapper->setValuesColumn(0);
145 145 mapper->setLabelsColumn(1);
146 146 mapper->setModel(m_model);
147 147 mapper->setSeries(m_series);
148 148 mapper->setFirst(first);
149 149 mapper->setCount(countLimit);
150 150
151 151 QCOMPARE(m_series->count(), expectedCount);
152 152
153 153 // change values column mapping to invalid
154 154 mapper->setValuesColumn(-1);
155 155 mapper->setLabelsColumn(1);
156 156
157 157 QCOMPARE(m_series->count(), 0);
158 158
159 159 delete mapper;
160 160 mapper = 0;
161 161 }
162 162
163 163 void tst_piemodelmapper::horizontalMapper_data()
164 164 {
165 165 QTest::addColumn<int>("valuesRow");
166 166 QTest::addColumn<int>("labelsRow");
167 167 QTest::addColumn<int>("expectedCount");
168 168 QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount;
169 169 QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount;
170 170 QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0;
171 171 QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0;
172 172 QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0;
173 173 }
174 174
175 175 void tst_piemodelmapper::horizontalMapper()
176 176 {
177 177 QFETCH(int, valuesRow);
178 178 QFETCH(int, labelsRow);
179 179 QFETCH(int, expectedCount);
180 180
181 181 QHPieModelMapper *mapper = new QHPieModelMapper;
182 182 mapper->setValuesRow(valuesRow);
183 183 mapper->setLabelsRow(labelsRow);
184 184 mapper->setModel(m_model);
185 185 mapper->setSeries(m_series);
186 186
187 187 QCOMPARE(m_series->count(), expectedCount);
188 188 QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow));
189 189 QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow));
190 190
191 191 delete mapper;
192 192 mapper = 0;
193 193 }
194 194
195 195 void tst_piemodelmapper::horizontalMapperCustomMapping_data()
196 196 {
197 197 QTest::addColumn<int>("first");
198 198 QTest::addColumn<int>("countLimit");
199 199 QTest::addColumn<int>("expectedCount");
200 200 QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount;
201 201 QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3;
202 202 QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount);
203 203 QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3);
204 204 QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0;
205 205 QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0;
206 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;
207 207 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount;
208 208 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount;
209 209 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount;
210 210 }
211 211
212 212 void tst_piemodelmapper::horizontalMapperCustomMapping()
213 213 {
214 214 QFETCH(int, first);
215 215 QFETCH(int, countLimit);
216 216 QFETCH(int, expectedCount);
217 217
218 218 QCOMPARE(m_series->count(), 0);
219 219
220 220 QHPieModelMapper *mapper = new QHPieModelMapper;
221 221 mapper->setValuesRow(0);
222 222 mapper->setLabelsRow(1);
223 223 mapper->setModel(m_model);
224 224 mapper->setSeries(m_series);
225 225 mapper->setFirst(first);
226 226 mapper->setCount(countLimit);
227 227
228 228 QCOMPARE(m_series->count(), expectedCount);
229 229
230 230 // change values row mapping to invalid
231 231 mapper->setValuesRow(-1);
232 232 mapper->setLabelsRow(1);
233 233
234 234 QCOMPARE(m_series->count(), 0);
235 235
236 236 delete mapper;
237 237 mapper = 0;
238 238 }
239 239
240 240 void tst_piemodelmapper::seriesUpdated()
241 241 {
242 242 QStandardItemModel *otherModel = new QStandardItemModel;
243 243 for (int row = 0; row < m_modelRowCount; ++row) {
244 244 for (int column = 0; column < m_modelColumnCount; column++) {
245 245 QStandardItem *item = new QStandardItem(row * column);
246 246 otherModel->setItem(row, column, item);
247 247 }
248 248 }
249 249
250 250 QVPieModelMapper *mapper = new QVPieModelMapper;
251 251 mapper->setValuesColumn(0);
252 252 mapper->setLabelsColumn(1);
253 253 mapper->setModel(otherModel);
254 254 mapper->setSeries(m_series);
255 255 QCOMPARE(m_series->count(), m_modelRowCount);
256 QCOMPARE(mapper->count(), -1);
256 257
257 258 m_series->append("1000", 1000);
258 259 QCOMPARE(m_series->count(), m_modelRowCount + 1);
260 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
259 261
260 262 m_series->remove(m_series->slices().last());
261 263 QCOMPARE(m_series->count(), m_modelRowCount);
264 QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model
262 265
263 266 otherModel->clear();
264 267 delete otherModel;
265 268 otherModel = 0;
266 269 }
267 270
268 271 QTEST_MAIN(tst_piemodelmapper)
269 272
270 273 #include "tst_qpiemodelmapper.moc"
General Comments 0
You need to be logged in to leave comments. Login now