##// 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 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 221 void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices)
202 222 {
203 223 if (m_seriesSignalsBlock)
@@ -293,8 +313,10 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
293 313 index = topLeft.sibling(row, column);
294 314 slice = pieSlice(index);
295 315 if (slice) {
296 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
297 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
316 if (isValueIndex(index))
317 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
318 if (isLabelIndex(index))
319 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
298 320 }
299 321 }
300 322 }
@@ -360,6 +382,9 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start,
360 382
361 383 void QPieModelMapperPrivate::insertData(int start, int end)
362 384 {
385 if (m_model == 0 || m_series == 0)
386 return;
387
363 388 if (m_count != -1 && start >= m_first + m_count) {
364 389 return;
365 390 } else {
@@ -390,6 +415,9 void QPieModelMapperPrivate::insertData(int start, int end)
390 415
391 416 void QPieModelMapperPrivate::removeData(int start, int end)
392 417 {
418 if (m_model == 0 || m_series == 0)
419 return;
420
393 421 int removedCount = end - start + 1;
394 422 if (m_count != -1 && start >= m_first + m_count) {
395 423 return;
@@ -450,7 +478,7 void QPieModelMapperPrivate::initializePieFromModel()
450 478 connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged()));
451 479 m_series->append(slice);
452 480 m_slices.append(slice);
453 // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
481 // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
454 482 slicePos++;
455 483 valueIndex = valueModelIndex(slicePos);
456 484 labelIndex = labelModelIndex(slicePos);
@@ -38,6 +38,8 public Q_SLOTS:
38 38
39 39 private:
40 40 QPieSlice* pieSlice(QModelIndex index) const;
41 bool isLabelIndex(QModelIndex index) const;
42 bool isValueIndex(QModelIndex index) const;
41 43 QModelIndex valueModelIndex(int slicePos);
42 44 QModelIndex labelModelIndex(int slicePos);
43 45 void insertData(int start, int end);
@@ -30,6 +30,7 class tst_piemodelmapper : public QObject
30 30 void horizontalMapper();
31 31 void horizontalMapperCustomMapping_data();
32 32 void horizontalMapperCustomMapping();
33 void seriesUpdated();
33 34
34 35
35 36 private:
@@ -149,7 +150,7 void tst_piemodelmapper::verticalMapperCustomMapping()
149 150
150 151 QCOMPARE(m_series->count(), expectedCount);
151 152
152 // change values column mappings to invalid
153 // change values column mapping to invalid
153 154 mapper->setValuesColumn(-1);
154 155 mapper->setLabelsColumn(1);
155 156
@@ -226,7 +227,7 void tst_piemodelmapper::horizontalMapperCustomMapping()
226 227
227 228 QCOMPARE(m_series->count(), expectedCount);
228 229
229 // change values column mappings to invalid
230 // change values row mapping to invalid
230 231 mapper->setValuesRow(-1);
231 232 mapper->setLabelsRow(1);
232 233
@@ -236,6 +237,34 void tst_piemodelmapper::horizontalMapperCustomMapping()
236 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 268 QTEST_MAIN(tst_piemodelmapper)
240 269
241 270 #include "tst_qpiemodelmapper.moc"
@@ -81,13 +81,13 TableWidget::TableWidget(QWidget *parent)
81 81 QPushButton* removeColumnButton = new QPushButton("Remove column");
82 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 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 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 91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
92 92
93 93
@@ -355,35 +355,39 void TableWidget::updateChartType(bool toggle)
355 355 m_pieMapper->setSeries(m_pieSeries);
356 356 m_pieMapper->setModel(m_model);
357 357 m_pieMapper->setFirst(2);
358 // m_pieMapper->setCount(5);
358 // m_pieMapper->setCount(5);
359 359 // pieSeries->setModelMapper(mapper);
360 360
361 361 m_pieSeries->setLabelsVisible(true);
362 m_pieSeries->setPieSize(0.75);
363 // pieSeries->setHorizontalPosition(0.2);
364 // pieSeries->setVerticalPosition(0.3);
362 m_pieSeries->setPieSize(0.35);
363 m_pieSeries->setHorizontalPosition(0.25);
364 m_pieSeries->setVerticalPosition(0.35);
365 365
366 366 m_chart->addSeries(m_pieSeries);
367 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 371 // pieSeries->slices().at(0)->setValue(400);
372 372 // pieSeries->slices().at(0)->setLabel(QString("36"));
373 373
374 // // pie 2
375 // pieSeries = new QPieSeries;
376 // pieSeries->setModel(m_model);
374 // pie 2
375 m_pieSeries2 = new QPieSeries;
377 376
378 // pieSeries->setModelMapping(1,1, Qt::Vertical);
379 // pieSeries->setModelMappingRange(2, -1);
380 // pieSeries->setLabelsVisible(true);
381 // pieSeries->setPieSize(0.35);
382 // pieSeries->setHorizontalPosition(0.8);
383 // pieSeries->setVerticalPosition(0.3);
384 // m_chart->addSeries(pieSeries);
385 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
386 // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000));
377 m_pieMapper = new QVPieModelMapper;
378 m_pieMapper->setValuesColumn(0);
379 m_pieMapper->setLabelsColumn(7);
380 m_pieMapper->setSeries(m_pieSeries2);
381 m_pieMapper->setModel(m_model);
382 m_pieMapper->setFirst(2);
383
384 m_pieSeries2->setLabelsVisible(true);
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 392 // // pie 3
389 393 // pieSeries = new QPieSeries;
@@ -70,6 +70,8 public:
70 70 QSpinBox* m_linesCountSpinBox;
71 71 QVPieModelMapper *m_pieMapper;
72 72 QPieSeries* m_pieSeries;
73 QVPieModelMapper *m_pieMapper2;
74 QPieSeries* m_pieSeries2;
73 75 // QPieSeries* specialPie;
74 76 };
75 77
General Comments 0
You need to be logged in to leave comments. Login now