@@ -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,8 +313,10 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) { | |
296 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
316 | if (isValueIndex(index)) | |
297 |
slice->set |
|
317 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
|
318 | if (isLabelIndex(index)) | |||
|
319 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |||
298 | } |
|
320 | } | |
299 | } |
|
321 | } | |
300 | } |
|
322 | } | |
@@ -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; | |
@@ -450,7 +478,7 void QPieModelMapperPrivate::initializePieFromModel() | |||||
450 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
478 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
451 | m_series->append(slice); |
|
479 | m_series->append(slice); | |
452 | m_slices.append(slice); |
|
480 | m_slices.append(slice); | |
453 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
481 | // m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
454 | slicePos++; |
|
482 | slicePos++; | |
455 | valueIndex = valueModelIndex(slicePos); |
|
483 | valueIndex = valueModelIndex(slicePos); | |
456 | labelIndex = labelModelIndex(slicePos); |
|
484 | labelIndex = labelModelIndex(slicePos); |
@@ -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 mapping |
|
153 | // change values column mapping to invalid | |
153 | mapper->setValuesColumn(-1); |
|
154 | mapper->setValuesColumn(-1); | |
154 | mapper->setLabelsColumn(1); |
|
155 | mapper->setLabelsColumn(1); | |
155 |
|
156 | |||
@@ -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 |
|
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 |
|
84 | QPushButton* specialPieButton = new QPushButton("Add slices using series API"); | |
85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
85 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); | |
86 |
|
86 | |||
87 |
QPushButton* specialPieButton2 = new QPushButton("Remove slices |
|
87 | QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API"); | |
88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); |
|
88 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); | |
89 |
|
89 | |||
90 |
QPushButton* specialPieButton3 = new QPushButton(" |
|
90 | QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); | |
91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); |
|
91 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); | |
92 |
|
92 | |||
93 |
|
93 | |||
@@ -355,35 +355,39 void TableWidget::updateChartType(bool toggle) | |||||
355 | m_pieMapper->setSeries(m_pieSeries); |
|
355 | m_pieMapper->setSeries(m_pieSeries); | |
356 | m_pieMapper->setModel(m_model); |
|
356 | m_pieMapper->setModel(m_model); | |
357 | m_pieMapper->setFirst(2); |
|
357 | m_pieMapper->setFirst(2); | |
358 | // m_pieMapper->setCount(5); |
|
358 | // m_pieMapper->setCount(5); | |
359 | // pieSeries->setModelMapper(mapper); |
|
359 | // pieSeries->setModelMapper(mapper); | |
360 |
|
360 | |||
361 | m_pieSeries->setLabelsVisible(true); |
|
361 | m_pieSeries->setLabelsVisible(true); | |
362 |
m_pieSeries->setPieSize(0. |
|
362 | m_pieSeries->setPieSize(0.35); | |
363 |
|
|
363 | m_pieSeries->setHorizontalPosition(0.25); | |
364 |
|
|
364 | m_pieSeries->setVerticalPosition(0.35); | |
365 |
|
365 | |||
366 | m_chart->addSeries(m_pieSeries); |
|
366 | m_chart->addSeries(m_pieSeries); | |
367 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
367 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
368 |
m_model->addMapping(seriesColorHex, QRect( |
|
368 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | // pieSeries->slices().at(0)->setValue(400); |
|
371 | // pieSeries->slices().at(0)->setValue(400); | |
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
372 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
373 |
|
373 | |||
374 |
|
|
374 | // pie 2 | |
375 |
|
|
375 | m_pieSeries2 = new QPieSeries; | |
376 | // pieSeries->setModel(m_model); |
|
|||
377 |
|
376 | |||
378 | // pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
377 | m_pieMapper = new QVPieModelMapper; | |
379 | // pieSeries->setModelMappingRange(2, -1); |
|
378 | m_pieMapper->setValuesColumn(0); | |
380 |
|
|
379 | m_pieMapper->setLabelsColumn(7); | |
381 | // pieSeries->setPieSize(0.35); |
|
380 | m_pieMapper->setSeries(m_pieSeries2); | |
382 | // pieSeries->setHorizontalPosition(0.8); |
|
381 | m_pieMapper->setModel(m_model); | |
383 | // pieSeries->setVerticalPosition(0.3); |
|
382 | m_pieMapper->setFirst(2); | |
384 | // m_chart->addSeries(pieSeries); |
|
383 | ||
385 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
384 | m_pieSeries2->setLabelsVisible(true); | |
386 | // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000)); |
|
385 | m_pieSeries2->setPieSize(0.35); | |
|
386 | m_pieSeries2->setHorizontalPosition(0.75); | |||
|
387 | m_pieSeries2->setVerticalPosition(0.65); | |||
|
388 | m_chart->addSeries(m_pieSeries2); | |||
|
389 | seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
390 | m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); | |||
387 |
|
391 | |||
388 | // // pie 3 |
|
392 | // // pie 3 | |
389 | // pieSeries = new QPieSeries; |
|
393 | // pieSeries = new QPieSeries; |
@@ -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