##// END OF EJS Templates
Small fixes to piemodelmapper and one more test
Marek Rosa -
r1251:3e42cdbd748d
parent child
Show More
@@ -198,6 +198,26 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
198 return m_model->index(m_labelsIndex, slicePos + m_first);
198 return m_model->index(m_labelsIndex, slicePos + m_first);
199 }
199 }
200
200
201 bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const
202 {
203 if (m_orientation == Qt::Vertical && index.column() == m_labelsIndex)
204 return true;
205 else if (m_orientation == Qt::Horizontal && index.row() == m_labelsIndex)
206 return true;
207
208 return false;
209 }
210
211 bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const
212 {
213 if (m_orientation == Qt::Vertical && index.column() == m_valuesIndex)
214 return true;
215 else if (m_orientation == Qt::Horizontal && index.row() == m_valuesIndex)
216 return true;
217
218 return false;
219 }
220
201 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
221 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
202 {
222 {
203 if (m_seriesSignalsBlock)
223 if (m_seriesSignalsBlock)
@@ -293,7 +313,9 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
293 index = topLeft.sibling(row, column);
313 index = topLeft.sibling(row, column);
294 slice = pieSlice(index);
314 slice = pieSlice(index);
295 if (slice) {
315 if (slice) {
316 if (isValueIndex(index))
296 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
317 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
318 if (isLabelIndex(index))
297 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
319 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
298 }
320 }
299 }
321 }
@@ -360,6 +382,9 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start,
360
382
361 void QPieModelMapperPrivate::insertData(int start, int end)
383 void QPieModelMapperPrivate::insertData(int start, int end)
362 {
384 {
385 if (m_model == 0 || m_series == 0)
386 return;
387
363 if (m_count != -1 && start >= m_first + m_count) {
388 if (m_count != -1 && start >= m_first + m_count) {
364 return;
389 return;
365 } else {
390 } else {
@@ -390,6 +415,9 void QPieModelMapperPrivate::insertData(int start, int end)
390
415
391 void QPieModelMapperPrivate::removeData(int start, int end)
416 void QPieModelMapperPrivate::removeData(int start, int end)
392 {
417 {
418 if (m_model == 0 || m_series == 0)
419 return;
420
393 int removedCount = end - start + 1;
421 int removedCount = end - start + 1;
394 if (m_count != -1 && start >= m_first + m_count) {
422 if (m_count != -1 && start >= m_first + m_count) {
395 return;
423 return;
@@ -38,6 +38,8 public Q_SLOTS:
38
38
39 private:
39 private:
40 QPieSlice* pieSlice(QModelIndex index) const;
40 QPieSlice* pieSlice(QModelIndex index) const;
41 bool isLabelIndex(QModelIndex index) const;
42 bool isValueIndex(QModelIndex index) const;
41 QModelIndex valueModelIndex(int slicePos);
43 QModelIndex valueModelIndex(int slicePos);
42 QModelIndex labelModelIndex(int slicePos);
44 QModelIndex labelModelIndex(int slicePos);
43 void insertData(int start, int end);
45 void insertData(int start, int end);
@@ -30,6 +30,7 class tst_piemodelmapper : public QObject
30 void horizontalMapper();
30 void horizontalMapper();
31 void horizontalMapperCustomMapping_data();
31 void horizontalMapperCustomMapping_data();
32 void horizontalMapperCustomMapping();
32 void horizontalMapperCustomMapping();
33 void seriesUpdated();
33
34
34
35
35 private:
36 private:
@@ -149,7 +150,7 void tst_piemodelmapper::verticalMapperCustomMapping()
149
150
150 QCOMPARE(m_series->count(), expectedCount);
151 QCOMPARE(m_series->count(), expectedCount);
151
152
152 // change values column mappings to invalid
153 // change values column mapping to invalid
153 mapper->setValuesColumn(-1);
154 mapper->setValuesColumn(-1);
154 mapper->setLabelsColumn(1);
155 mapper->setLabelsColumn(1);
155
156
@@ -226,7 +227,7 void tst_piemodelmapper::horizontalMapperCustomMapping()
226
227
227 QCOMPARE(m_series->count(), expectedCount);
228 QCOMPARE(m_series->count(), expectedCount);
228
229
229 // change values column mappings to invalid
230 // change values row mapping to invalid
230 mapper->setValuesRow(-1);
231 mapper->setValuesRow(-1);
231 mapper->setLabelsRow(1);
232 mapper->setLabelsRow(1);
232
233
@@ -236,6 +237,34 void tst_piemodelmapper::horizontalMapperCustomMapping()
236 mapper = 0;
237 mapper = 0;
237 }
238 }
238
239
240 void tst_piemodelmapper::seriesUpdated()
241 {
242 QStandardItemModel *otherModel = new QStandardItemModel;
243 for (int row = 0; row < m_modelRowCount; ++row) {
244 for (int column = 0; column < m_modelColumnCount; column++) {
245 QStandardItem *item = new QStandardItem(row * column);
246 otherModel->setItem(row, column, item);
247 }
248 }
249
250 QVPieModelMapper *mapper = new QVPieModelMapper;
251 mapper->setValuesColumn(0);
252 mapper->setLabelsColumn(1);
253 mapper->setModel(otherModel);
254 mapper->setSeries(m_series);
255 QCOMPARE(m_series->count(), m_modelRowCount);
256
257 m_series->append("1000", 1000);
258 QCOMPARE(m_series->count(), m_modelRowCount + 1);
259
260 m_series->remove(m_series->slices().last());
261 QCOMPARE(m_series->count(), m_modelRowCount);
262
263 otherModel->clear();
264 delete otherModel;
265 otherModel = 0;
266 }
267
239 QTEST_MAIN(tst_piemodelmapper)
268 QTEST_MAIN(tst_piemodelmapper)
240
269
241 #include "tst_qpiemodelmapper.moc"
270 #include "tst_qpiemodelmapper.moc"
@@ -81,13 +81,13 TableWidget::TableWidget(QWidget *parent)
81 QPushButton* removeColumnButton = new QPushButton("Remove column");
81 QPushButton* removeColumnButton = new QPushButton("Remove column");
82 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
82 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
83
83
84 QPushButton* specialPieButton = new QPushButton("Add slices from series");
84 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
85 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
85 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
86
86
87 QPushButton* specialPieButton2 = new QPushButton("Remove slices from series");
87 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
88 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
88 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
89
89
90 QPushButton* specialPieButton3 = new QPushButton("Remove slices from series");
90 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
92
92
93
93
@@ -359,31 +359,35 void TableWidget::updateChartType(bool toggle)
359 // pieSeries->setModelMapper(mapper);
359 // pieSeries->setModelMapper(mapper);
360
360
361 m_pieSeries->setLabelsVisible(true);
361 m_pieSeries->setLabelsVisible(true);
362 m_pieSeries->setPieSize(0.75);
362 m_pieSeries->setPieSize(0.35);
363 // pieSeries->setHorizontalPosition(0.2);
363 m_pieSeries->setHorizontalPosition(0.25);
364 // pieSeries->setVerticalPosition(0.3);
364 m_pieSeries->setVerticalPosition(0.35);
365
365
366 m_chart->addSeries(m_pieSeries);
366 m_chart->addSeries(m_pieSeries);
367 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
367 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
368 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5));
368 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
369
369
370
370
371 // pieSeries->slices().at(0)->setValue(400);
371 // pieSeries->slices().at(0)->setValue(400);
372 // pieSeries->slices().at(0)->setLabel(QString("36"));
372 // pieSeries->slices().at(0)->setLabel(QString("36"));
373
373
374 // // pie 2
374 // pie 2
375 // pieSeries = new QPieSeries;
375 m_pieSeries2 = new QPieSeries;
376 // pieSeries->setModel(m_model);
377
376
378 // pieSeries->setModelMapping(1,1, Qt::Vertical);
377 m_pieMapper = new QVPieModelMapper;
379 // pieSeries->setModelMappingRange(2, -1);
378 m_pieMapper->setValuesColumn(0);
380 // pieSeries->setLabelsVisible(true);
379 m_pieMapper->setLabelsColumn(7);
381 // pieSeries->setPieSize(0.35);
380 m_pieMapper->setSeries(m_pieSeries2);
382 // pieSeries->setHorizontalPosition(0.8);
381 m_pieMapper->setModel(m_model);
383 // pieSeries->setVerticalPosition(0.3);
382 m_pieMapper->setFirst(2);
384 // m_chart->addSeries(pieSeries);
383
385 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
384 m_pieSeries2->setLabelsVisible(true);
386 // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000));
385 m_pieSeries2->setPieSize(0.35);
386 m_pieSeries2->setHorizontalPosition(0.75);
387 m_pieSeries2->setVerticalPosition(0.65);
388 m_chart->addSeries(m_pieSeries2);
389 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
390 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
387
391
388 // // pie 3
392 // // pie 3
389 // pieSeries = new QPieSeries;
393 // pieSeries = new QPieSeries;
@@ -70,6 +70,8 public:
70 QSpinBox* m_linesCountSpinBox;
70 QSpinBox* m_linesCountSpinBox;
71 QVPieModelMapper *m_pieMapper;
71 QVPieModelMapper *m_pieMapper;
72 QPieSeries* m_pieSeries;
72 QPieSeries* m_pieSeries;
73 QVPieModelMapper *m_pieMapper2;
74 QPieSeries* m_pieSeries2;
73 // QPieSeries* specialPie;
75 // QPieSeries* specialPie;
74 };
76 };
75
77
General Comments 0
You need to be logged in to leave comments. Login now