@@ -52,48 +52,47 TableWidget::TableWidget(QWidget *parent) | |||
|
52 | 52 | chart->setAnimationOptions(QChart::AllAnimations); |
|
53 | 53 | //! [3] |
|
54 | 54 | |
|
55 | // series 1 | |
|
56 | //! [4] | |
|
57 | QLineSeries *series = new QLineSeries; | |
|
58 |
series->set |
|
|
59 | series->setModel(model); | |
|
55 | // // series 1 | |
|
56 | // //! [4] | |
|
57 | // QLineSeries *series = new QLineSeries; | |
|
58 | // series->setModel(model); | |
|
60 | 59 | |
|
61 | QXYModelMapper *mapper = new QXYModelMapper; | |
|
62 | mapper->setMapX(0); | |
|
63 | mapper->setMapY(1); | |
|
64 | series->setModelMapper(mapper); | |
|
65 | // series->setModelMapping(0, 1, Qt::Vertical); | |
|
66 | chart->addSeries(series); | |
|
67 | //! [4] | |
|
60 | // QXYModelMapper *mapper = new QXYModelMapper; | |
|
61 | // mapper->setMapX(0); | |
|
62 | // mapper->setMapY(1); | |
|
63 | // series->setModelMapper(mapper); | |
|
64 | //// series->setModelMapping(0, 1, Qt::Vertical); | |
|
65 | // chart->addSeries(series); | |
|
66 | // //! [4] | |
|
68 | 67 | |
|
69 | //! [5] | |
|
70 | // for storing color hex from the series | |
|
71 | QString seriesColorHex = "#000000"; | |
|
68 | // //! [5] | |
|
69 | // // for storing color hex from the series | |
|
70 | // QString seriesColorHex = "#000000"; | |
|
72 | 71 | |
|
73 | // get the color of the series and use it for showing the mapped area | |
|
74 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
75 | model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); | |
|
76 | //! [5] | |
|
72 | // // get the color of the series and use it for showing the mapped area | |
|
73 | // seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
74 | // model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); | |
|
75 | // //! [5] | |
|
77 | 76 | |
|
78 | // series 2 | |
|
79 | //! [6] | |
|
80 | series = new QLineSeries; | |
|
81 | series->setName("line2"); | |
|
82 | series->setModel(model); | |
|
83 | 77 | |
|
84 | mapper = new QXYModelMapper; | |
|
85 | mapper->setMapX(2); | |
|
86 | mapper->setMapY(3); | |
|
87 |
series->setModel |
|
|
88 | // series->setModelMapping(2,3, Qt::Vertical); | |
|
89 | chart->addSeries(series); | |
|
90 | //! [6] | |
|
78 | // // series 2 | |
|
79 | // //! [6] | |
|
80 | // series = new QLineSeries; | |
|
81 | // series->setModel(model); | |
|
91 | 82 | |
|
92 | //! [7] | |
|
93 | // get the color of the series and use it for showing the mapped area | |
|
94 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
95 | model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); | |
|
96 | //! [7] | |
|
83 | // mapper = new QXYModelMapper; | |
|
84 | // mapper->setMapX(2); | |
|
85 | // mapper->setMapY(3); | |
|
86 | // series->setModelMapper(mapper); | |
|
87 | //// series->setModelMapping(2,3, Qt::Vertical); | |
|
88 | // chart->addSeries(series); | |
|
89 | // //! [6] | |
|
90 | ||
|
91 | // //! [7] | |
|
92 | // // get the color of the series and use it for showing the mapped area | |
|
93 | // seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
94 | // model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); | |
|
95 | // //! [7] | |
|
97 | 96 | |
|
98 | 97 | //! [8] |
|
99 | 98 | QChartView *chartView = new QChartView(chart); |
@@ -76,7 +76,7 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) | |||
|
76 | 76 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
77 | 77 | bool value(false); |
|
78 | 78 | if (m) { |
|
79 | setModel(m); | |
|
79 | // setModel(m); | |
|
80 | 80 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
81 | 81 | // setModelMapping(0, 1, 1, Qt::Vertical); |
|
82 | 82 | } else { |
@@ -87,7 +87,7 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model) | |||
|
87 | 87 | |
|
88 | 88 | DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() |
|
89 | 89 | { |
|
90 |
return |
|
|
90 | return 0;//qobject_cast<DeclarativeTableModel *>(model()); | |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
@@ -128,7 +128,7 bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *mod | |||
|
128 | 128 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
129 | 129 | bool value(false); |
|
130 | 130 | if (m) { |
|
131 | setModel(m); | |
|
131 | // setModel(m); | |
|
132 | 132 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
133 | 133 | // setModelMapping(0, 1, 1, Qt::Vertical); |
|
134 | 134 | } else { |
@@ -139,7 +139,7 bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *mod | |||
|
139 | 139 | |
|
140 | 140 | DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel() |
|
141 | 141 | { |
|
142 |
return |
|
|
142 | return 0; //qobject_cast<DeclarativeTableModel *>(model()); | |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) |
@@ -88,7 +88,7 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) | |||
|
88 | 88 | { |
|
89 | 89 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
90 | 90 | if (m) { |
|
91 | QPieSeries::setModel(m); | |
|
91 | // QPieSeries::setModel(m); | |
|
92 | 92 | } else { |
|
93 | 93 | qWarning("DeclarativePieSeries: Illegal model"); |
|
94 | 94 | } |
@@ -96,7 +96,7 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) | |||
|
96 | 96 | |
|
97 | 97 | DeclarativeTableModel *DeclarativePieSeries::pieModel() |
|
98 | 98 | { |
|
99 |
return |
|
|
99 | return 0;//qobject_cast<DeclarativeTableModel *>(model()); | |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | #include "moc_declarativepieseries.cpp" |
@@ -38,7 +38,7 DeclarativeXySeries::DeclarativeXySeries() | |||
|
38 | 38 | mapper->setFirst(0); |
|
39 | 39 | mapper->setCount(-1); |
|
40 | 40 | mapper->setOrientation(Qt::Vertical); |
|
41 | series->setModelMapper(mapper); | |
|
41 | // series->setModelMapper(mapper); | |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | DeclarativeXySeries::~DeclarativeXySeries() |
@@ -51,8 +51,8 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model) | |||
|
51 | 51 | bool value(false); |
|
52 | 52 | if (m) { |
|
53 | 53 | // All the inherited objects must be of type QXYSeries, so it is safe to cast |
|
54 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
|
55 | series->setModel(m); | |
|
54 | // QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
|
55 | // series->setModel(m); | |
|
56 | 56 | } else { |
|
57 | 57 | qWarning("DeclarativeXySeries: Illegal model"); |
|
58 | 58 | } |
@@ -62,8 +62,8 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model) | |||
|
62 | 62 | DeclarativeTableModel *DeclarativeXySeries::declarativeModel() |
|
63 | 63 | { |
|
64 | 64 | // All the inherited objects must be of type QXYSeries, so it is safe to cast |
|
65 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
|
66 |
return |
|
|
65 | // QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
|
66 | return 0; //qobject_cast<DeclarativeTableModel *>(series->model()); | |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -207,25 +207,6 bool QAreaSeries::pointsVisible() const | |||
|
207 | 207 | return d->m_pointsVisible; |
|
208 | 208 | } |
|
209 | 209 | |
|
210 | /*! | |
|
211 | Does nothing at present. Paremeter \a model is not used. Always returns false. | |
|
212 | To set the model for area series set the models for upperSeries, lowerSeries | |
|
213 | */ | |
|
214 | void QAreaSeries::setModel(QAbstractItemModel* model) | |
|
215 | { | |
|
216 | Q_UNUSED(model); | |
|
217 | qWarning()<<"Not implemented"; | |
|
218 | } | |
|
219 | ||
|
220 | /*! | |
|
221 | Does nothing at present. Always returns 0; | |
|
222 | To get the model set for area series call upperSeries->model(), lowerSeries->model() | |
|
223 | */ | |
|
224 | QAbstractItemModel* QAreaSeries::model() const | |
|
225 | { | |
|
226 | return 0; | |
|
227 | } | |
|
228 | ||
|
229 | 210 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
230 | 211 | |
|
231 | 212 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
@@ -55,9 +55,6 public: | |||
|
55 | 55 | void setPointsVisible(bool visible = true); |
|
56 | 56 | bool pointsVisible() const; |
|
57 | 57 | |
|
58 | void setModel(QAbstractItemModel* model); | |
|
59 | QAbstractItemModel* model() const; | |
|
60 | ||
|
61 | 58 | Q_SIGNALS: |
|
62 | 59 | void clicked(const QPointF &point); |
|
63 | 60 | void selected(); |
@@ -28,10 +28,6 | |||
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | |
|
31 | #include <QAbstractItemModel> | |
|
32 | #include <QModelIndex> | |
|
33 | #include <QBarModelMapper> | |
|
34 | ||
|
35 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 32 | |
|
37 | 33 | /*! |
@@ -221,66 +217,6 QList<QBarSet*> QBarSeries::barSets() const | |||
|
221 | 217 | } |
|
222 | 218 | |
|
223 | 219 | /*! |
|
224 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
|
225 | Sets the \a model to be used as a data source | |
|
226 | */ | |
|
227 | void QBarSeries::setModel(QAbstractItemModel *model) | |
|
228 | { | |
|
229 | Q_D(QBarSeries); | |
|
230 | // disconnect signals from old model | |
|
231 | if(d->m_model) | |
|
232 | { | |
|
233 | disconnect(d->m_model, 0, this, 0); | |
|
234 | } | |
|
235 | ||
|
236 | // set new model | |
|
237 | if(model) | |
|
238 | { | |
|
239 | d->m_model = model; | |
|
240 | ||
|
241 | // connect the signals | |
|
242 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
243 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
244 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
245 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
|
246 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
|
247 | ||
|
248 | if (d->m_mapper) | |
|
249 | d->initializeDataFromModel(); | |
|
250 | } | |
|
251 | else | |
|
252 | { | |
|
253 | d->m_model = 0; | |
|
254 | } | |
|
255 | } | |
|
256 | ||
|
257 | void QBarSeries::setModelMapper(QBarModelMapper *mapper) | |
|
258 | { | |
|
259 | Q_D(QBarSeries); | |
|
260 | // disconnect signals from old mapper | |
|
261 | if (d->m_mapper) { | |
|
262 | QObject::disconnect(d->m_mapper, 0, this, 0); | |
|
263 | } | |
|
264 | ||
|
265 | if (mapper) { | |
|
266 | d->m_mapper = mapper; | |
|
267 | // connect the signal from the mapper | |
|
268 | connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializeDataFromModel())); | |
|
269 | ||
|
270 | if (d->m_model) | |
|
271 | d->initializeDataFromModel(); | |
|
272 | } else { | |
|
273 | d->m_mapper = 0; | |
|
274 | } | |
|
275 | } | |
|
276 | ||
|
277 | QBarModelMapper* QBarSeries::modelMapper() const | |
|
278 | { | |
|
279 | Q_D(const QBarSeries); | |
|
280 | return d->m_mapper; | |
|
281 | } | |
|
282 | ||
|
283 | /*! | |
|
284 | 220 | Returns the bar categories of the series. |
|
285 | 221 | */ |
|
286 | 222 | QBarCategories QBarSeries::categories() const |
@@ -303,8 +239,7 void QBarSeries::setLabelsVisible(bool visible) | |||
|
303 | 239 | |
|
304 | 240 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
305 | 241 | QAbstractSeriesPrivate(q), |
|
306 |
m_barMargin(0.05) |
|
|
307 | m_mapper(0) | |
|
242 | m_barMargin(0.05) // Default value is 5% of category width | |
|
308 | 243 | { |
|
309 | 244 | } |
|
310 | 245 | |
@@ -492,112 +427,6 qreal QBarSeriesPrivate::maxCategorySum() | |||
|
492 | 427 | return max; |
|
493 | 428 | } |
|
494 | 429 | |
|
495 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
496 | { | |
|
497 | if (m_model == 0 || m_mapper == 0) | |
|
498 | return; | |
|
499 | ||
|
500 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
|
501 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
|
502 | if (m_mapper->orientation() == Qt::Vertical) | |
|
503 | { | |
|
504 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
505 | if ( row >= m_mapper->first() && (m_mapper->count() == - 1 || row < m_mapper->first() + m_mapper->count())) { | |
|
506 | if (column >= m_mapper->mapBarBottom() && column <= m_mapper->mapBarTop()) | |
|
507 | barsetAt(column - m_mapper->mapBarBottom())->replace(row - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
508 | // if (column == m_mapper->mapCategories());// TODO: | |
|
509 | } | |
|
510 | } | |
|
511 | else | |
|
512 | { | |
|
513 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
|
514 | if (column >= m_mapper->first() && (m_mapper->count() == - 1 || column < m_mapper->first() + m_mapper->count())) { | |
|
515 | if (row >= m_mapper->mapBarBottom() && row <= m_mapper->mapBarTop()) | |
|
516 | barsetAt(row - m_mapper->mapBarBottom())->replace(column - m_mapper->first(), m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
517 | // if (row == m_mapper->mapCategories());// TODO: | |
|
518 | } | |
|
519 | } | |
|
520 | } | |
|
521 | } | |
|
522 | } | |
|
523 | ||
|
524 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
|
525 | { | |
|
526 | Q_UNUSED(parent); | |
|
527 | Q_UNUSED(start); | |
|
528 | Q_UNUSED(end); | |
|
529 | initializeDataFromModel(); | |
|
530 | } | |
|
531 | ||
|
532 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
|
533 | { | |
|
534 | Q_UNUSED(parent); | |
|
535 | Q_UNUSED(start); | |
|
536 | Q_UNUSED(end); | |
|
537 | initializeDataFromModel(); | |
|
538 | } | |
|
539 | ||
|
540 | void QBarSeriesPrivate::initializeDataFromModel() | |
|
541 | { | |
|
542 | Q_Q(QBarSeries); | |
|
543 | ||
|
544 | // create the initial bars | |
|
545 | m_categories.clear(); | |
|
546 | m_barSets.clear(); | |
|
547 | ||
|
548 | if (m_model == 0 || m_mapper == 0) | |
|
549 | return; | |
|
550 | ||
|
551 | // check if mappings are set | |
|
552 | if (m_mapper->mapBarBottom() == -1 || m_mapper->mapBarTop() == -1 || m_mapper->mapCategories() == -1) | |
|
553 | return; | |
|
554 | ||
|
555 | // emit restructuredBars(); | |
|
556 | if (m_mapper->orientation() == Qt::Vertical) { | |
|
557 | if (m_mapCategories >= m_model->columnCount()) | |
|
558 | return; | |
|
559 | int rowCount = 0; | |
|
560 | if(m_mapper->count() == -1) | |
|
561 | rowCount = m_model->rowCount() - m_mapper->first(); | |
|
562 | else | |
|
563 | rowCount = qMin(m_mapper->count(), m_model->rowCount() - m_mapper->first()); | |
|
564 | for (int k = m_mapper->first(); k < m_mapper->first() + rowCount; k++) { | |
|
565 | m_categories << m_model->data(m_model->index(k, m_mapper->mapCategories()), Qt::DisplayRole).toString(); | |
|
566 | } | |
|
567 | ||
|
568 | int lastAvailableBarSet = qMin(m_model->columnCount() - 1, m_mapper->mapBarTop()); | |
|
569 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { | |
|
570 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { | |
|
571 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); | |
|
572 | for(int m = m_mapper->first(); m < m_mapper->first() + rowCount; m++) | |
|
573 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
|
574 | q->append(barSet); | |
|
575 | } | |
|
576 | } else { | |
|
577 | if (m_mapCategories >= m_model->rowCount()) | |
|
578 | return; | |
|
579 | int columnCount = 0; | |
|
580 | if(m_mapper->count() == -1) | |
|
581 | columnCount = m_model->columnCount() - m_mapper->first(); | |
|
582 | else | |
|
583 | columnCount = qMin(m_mapper->count(), m_model->columnCount() - m_mapper->first()); | |
|
584 | for (int k = m_mapper->first(); k < m_mapper->first() + columnCount; k++) { | |
|
585 | m_categories << m_model->data(m_model->index(m_mapper->mapCategories(), k), Qt::DisplayRole).toString(); | |
|
586 | } | |
|
587 | ||
|
588 | int lastAvailableBarSet = qMin(m_model->rowCount() - 1, m_mapper->mapBarTop()); | |
|
589 | for (int i = m_mapper->mapBarBottom(); i <= lastAvailableBarSet; i++) { | |
|
590 | // for (int i = m_mapper->mapBarBottom(); i <= m_mapper->mapBarTop(); i++) { | |
|
591 | QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); | |
|
592 | for(int m = m_mapper->first(); m < m_mapper->first() + columnCount; m++) | |
|
593 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
|
594 | q->append(barSet); | |
|
595 | } | |
|
596 | } | |
|
597 | emit restructuredBars(); | |
|
598 | // emit updatedBars(); | |
|
599 | } | |
|
600 | ||
|
601 | 430 | void QBarSeriesPrivate::barsetChanged() |
|
602 | 431 | { |
|
603 | 432 | emit updatedBars(); |
@@ -24,8 +24,6 | |||
|
24 | 24 | #include <qabstractseries.h> |
|
25 | 25 | #include <QStringList> |
|
26 | 26 | |
|
27 | class QModelIndex; | |
|
28 | ||
|
29 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 28 | |
|
31 | 29 | typedef QStringList QBarCategories; |
@@ -33,7 +31,6 typedef QStringList QBarCategories; | |||
|
33 | 31 | class QBarSet; |
|
34 | 32 | class BarCategory; |
|
35 | 33 | class QBarSeriesPrivate; |
|
36 | class QBarModelMapper; | |
|
37 | 34 | |
|
38 | 35 | // Container for series |
|
39 | 36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
@@ -57,10 +54,6 public: | |||
|
57 | 54 | |
|
58 | 55 | void setLabelsVisible(bool visible = true); |
|
59 | 56 | |
|
60 | void setModel(QAbstractItemModel *model); | |
|
61 | void setModelMapper(QBarModelMapper *mapper); | |
|
62 | QBarModelMapper* modelMapper() const; | |
|
63 | ||
|
64 | 57 | protected: |
|
65 | 58 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
66 | 59 |
@@ -6,8 +6,6 | |||
|
6 | 6 | #include <QStringList> |
|
7 | 7 | #include <QAbstractSeries> |
|
8 | 8 | |
|
9 | class QModelIndex; | |
|
10 | ||
|
11 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 10 | |
|
13 | 11 | class QBarModelMapper; |
@@ -48,21 +46,12 Q_SIGNALS: | |||
|
48 | 46 | void categoriesUpdated(); |
|
49 | 47 | |
|
50 | 48 | private Q_SLOTS: |
|
51 | // slots for updating bars when data in model changes | |
|
52 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
53 | void modelDataAdded(QModelIndex parent, int start, int end); | |
|
54 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
|
55 | void initializeDataFromModel(); | |
|
56 | 49 | void barsetChanged(); |
|
57 | 50 | |
|
58 | 51 | protected: |
|
59 | 52 | QList<QBarSet *> m_barSets; |
|
60 | 53 | QBarCategories m_categories; |
|
61 | 54 | qreal m_barMargin; |
|
62 | int m_mapCategories; | |
|
63 | int m_mapBarBottom; | |
|
64 | int m_mapBarTop; | |
|
65 | QBarModelMapper *m_mapper; | |
|
66 | 55 | private: |
|
67 | 56 | Q_DECLARE_PUBLIC(QBarSeries) |
|
68 | 57 | }; |
@@ -12,6 +12,56 QPieModelMapper::QPieModelMapper(QObject *parent) : | |||
|
12 | 12 | { |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | QAbstractItemModel* QPieModelMapper::model() const | |
|
16 | { | |
|
17 | Q_D(const QPieModelMapper); | |
|
18 | return d->m_model; | |
|
19 | } | |
|
20 | ||
|
21 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
|
22 | { | |
|
23 | if (model == 0) | |
|
24 | return; | |
|
25 | ||
|
26 | Q_D(QPieModelMapper); | |
|
27 | if (d->m_model) { | |
|
28 | disconnect(d->m_model, 0, d, 0); | |
|
29 | } | |
|
30 | ||
|
31 | d->m_model = model; | |
|
32 | d->initializePieFromModel(); | |
|
33 | // connect signals from the model | |
|
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))); | |
|
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))); | |
|
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
39 | } | |
|
40 | ||
|
41 | QPieSeries* QPieModelMapper::series() const | |
|
42 | { | |
|
43 | Q_D(const QPieModelMapper); | |
|
44 | return d->m_series; | |
|
45 | } | |
|
46 | ||
|
47 | void QPieModelMapper::setSeries(QPieSeries *series) | |
|
48 | { | |
|
49 | if (series == 0) | |
|
50 | return; | |
|
51 | ||
|
52 | Q_D(QPieModelMapper); | |
|
53 | if (d->m_series) { | |
|
54 | disconnect(d->m_series, 0, d, 0); | |
|
55 | } | |
|
56 | ||
|
57 | d->m_series = series; | |
|
58 | d->initializePieFromModel(); | |
|
59 | // connect the signals from the series | |
|
60 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded())); | |
|
61 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved())); | |
|
62 | // connect(d->m_model, SIGNAL(), d, SLOT()); | |
|
63 | } | |
|
64 | ||
|
15 | 65 | int QPieModelMapper::first() const |
|
16 | 66 | { |
|
17 | 67 | Q_D(const QPieModelMapper); |
@@ -22,6 +72,7 void QPieModelMapper::setFirst(int first) | |||
|
22 | 72 | { |
|
23 | 73 | Q_D(QPieModelMapper); |
|
24 | 74 | d->m_first = qMax(first, 0); |
|
75 | d->initializePieFromModel(); | |
|
25 | 76 | // emit updated(); |
|
26 | 77 | } |
|
27 | 78 | |
@@ -35,6 +86,7 void QPieModelMapper::setCount(int count) | |||
|
35 | 86 | { |
|
36 | 87 | Q_D(QPieModelMapper); |
|
37 | 88 | d->m_count = qMax(count, -1); |
|
89 | d->initializePieFromModel(); | |
|
38 | 90 | // emit updated(); |
|
39 | 91 | } |
|
40 | 92 | |
@@ -48,32 +100,35 void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |||
|
48 | 100 | { |
|
49 | 101 | Q_D(QPieModelMapper); |
|
50 | 102 | d->m_orientation = orientation; |
|
103 | d->initializePieFromModel(); | |
|
51 | 104 | // emit updated(); |
|
52 | 105 | } |
|
53 | 106 | |
|
54 |
int QPieModelMapper:: |
|
|
107 | int QPieModelMapper::valuesIndex() const | |
|
55 | 108 | { |
|
56 | 109 | Q_D(const QPieModelMapper); |
|
57 |
return d->m_ |
|
|
110 | return d->m_valuesIndex; | |
|
58 | 111 | } |
|
59 | 112 | |
|
60 |
void QPieModelMapper::set |
|
|
113 | void QPieModelMapper::setValuesIndex(int mapValues) | |
|
61 | 114 | { |
|
62 | 115 | Q_D(QPieModelMapper); |
|
63 |
d->m_ |
|
|
116 | d->m_valuesIndex = mapValues; | |
|
117 | d->initializePieFromModel(); | |
|
64 | 118 | // emit updated(); |
|
65 | 119 | } |
|
66 | 120 | |
|
67 |
int QPieModelMapper:: |
|
|
121 | int QPieModelMapper::labelsIndex() const | |
|
68 | 122 | { |
|
69 | 123 | Q_D(const QPieModelMapper); |
|
70 |
return d->m_ |
|
|
124 | return d->m_labelsIndex; | |
|
71 | 125 | } |
|
72 | 126 | |
|
73 |
void QPieModelMapper::set |
|
|
127 | void QPieModelMapper::setLabelsIndex(int mapLabels) | |
|
74 | 128 | { |
|
75 | 129 | Q_D(QPieModelMapper); |
|
76 |
d->m_ |
|
|
130 | d->m_labelsIndex = mapLabels; | |
|
131 | d->initializePieFromModel(); | |
|
77 | 132 | // emit updated(); |
|
78 | 133 | } |
|
79 | 134 | |
@@ -83,8 +138,8 void QPieModelMapper::reset() | |||
|
83 | 138 | d->m_first = 0; |
|
84 | 139 | d->m_count = -1; |
|
85 | 140 | d->m_orientation = Qt::Vertical; |
|
86 |
d->m_ |
|
|
87 |
d->m_ |
|
|
141 | d->m_valuesIndex = -1; | |
|
142 | d->m_labelsIndex = -1; | |
|
88 | 143 | // emit updated(); |
|
89 | 144 | } |
|
90 | 145 | |
@@ -93,38 +148,48 void QPieModelMapper::reset() | |||
|
93 | 148 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
94 | 149 | q_ptr(q) |
|
95 | 150 | { |
|
151 | m_series = 0; | |
|
152 | m_model = 0; | |
|
96 | 153 | m_first = 0; |
|
97 | 154 | m_count = -1; |
|
98 | 155 | m_orientation = Qt::Vertical; |
|
99 |
m_ |
|
|
100 |
m_ |
|
|
156 | m_valuesIndex = -1; | |
|
157 | m_labelsIndex = -1; | |
|
101 | 158 | } |
|
102 | 159 | |
|
103 | int QPieModelMapperPrivate::getSliceIndex() | |
|
104 | { | |
|
105 | 160 | |
|
106 | // invalid | |
|
107 | return -1; | |
|
161 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
|
162 | { | |
|
163 | 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)) | |
|
165 | return m_series->slices().at(index.row() - m_first); | |
|
166 | } 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)) | |
|
168 | return m_series->slices().at(index.column() - m_first); | |
|
169 | } | |
|
170 | return 0; // This part of model has not been mapped to any slice | |
|
108 | 171 | } |
|
109 | 172 | |
|
110 |
|
|
|
173 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
|
111 | 174 | { |
|
112 | if (model == 0) | |
|
113 | return; | |
|
175 | if (m_count != -1 && slicePos >= m_count) | |
|
176 | return QModelIndex(); // invalid | |
|
114 | 177 | |
|
115 | if(m_model) | |
|
116 | { | |
|
117 | // disconnect signals from old model | |
|
118 | disconnect(m_model, 0, this, 0); | |
|
178 | if (m_orientation == Qt::Vertical) | |
|
179 | return m_model->index(slicePos + m_first, m_valuesIndex); | |
|
180 | else | |
|
181 | return m_model->index(m_valuesIndex, slicePos + m_first); | |
|
119 | 182 | } |
|
120 | 183 | |
|
121 | m_model = model; | |
|
122 | // connect signals from the model | |
|
123 | connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
124 | connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
|
125 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
|
126 | connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
|
127 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
184 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
|
185 | { | |
|
186 | if (m_count != -1 && slicePos >= m_count) | |
|
187 | return QModelIndex(); // invalid | |
|
188 | ||
|
189 | if (m_orientation == Qt::Vertical) | |
|
190 | return m_model->index(slicePos + m_first, m_labelsIndex); | |
|
191 | else | |
|
192 | return m_model->index(m_labelsIndex, slicePos + m_first); | |
|
128 | 193 | } |
|
129 | 194 | |
|
130 | 195 | void QPieModelMapperPrivate::slicesAdded() |
@@ -144,151 +209,191 void QPieModelMapperPrivate::sliceChanged() | |||
|
144 | 209 | |
|
145 | 210 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
146 | 211 | { |
|
212 | QModelIndex index; | |
|
213 | QPieSlice *slice; | |
|
147 | 214 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
148 | 215 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
216 | index = topLeft.sibling(row, column); | |
|
217 | slice = pieSlice(index); | |
|
218 | if (slice) { | |
|
219 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
|
220 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
|
221 | } | |
|
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 | } | |
|
242 | } | |
|
243 | } | |
|
244 | ||
|
245 | ||
|
246 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
|
247 | { | |
|
248 | Q_UNUSED(parent); | |
|
149 | 249 |
|
|
250 | insertData(start, end); | |
|
251 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
|
252 | initializePieFromModel(); | |
|
253 | } | |
|
254 | ||
|
255 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
|
150 | 256 | { |
|
151 | if ( topLeft.row() >= m_first && (m_count == - 1 || topLeft.row() < m_first + m_count)) { | |
|
152 | if (topLeft.column() == m_mapValues) | |
|
153 | m_series->slices().at(topLeft.row() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
154 | if (topLeft.column() == m_mapLabels) | |
|
155 | m_series->slices().at(topLeft.row() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
257 | Q_UNUSED(parent); | |
|
258 | if (m_orientation == Qt::Vertical) | |
|
259 | removeData(start, end); | |
|
260 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
|
261 | initializePieFromModel(); | |
|
156 | 262 | } |
|
263 | ||
|
264 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
|
265 | { | |
|
266 | Q_UNUSED(parent); | |
|
267 | if (m_orientation == Qt::Horizontal) | |
|
268 | insertData(start, end); | |
|
269 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
|
270 | initializePieFromModel(); | |
|
157 | 271 | } |
|
158 | else | |
|
272 | ||
|
273 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
|
159 | 274 | { |
|
160 | if (topLeft.column() >= m_first && (m_count == - 1 || topLeft.column() < m_first + m_count)) { | |
|
161 | if (topLeft.row() == m_mapValues) | |
|
162 | m_series->slices().at(topLeft.column() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
|
163 | if (topLeft.row() == m_mapLabels) | |
|
164 | m_series->slices().at(topLeft.column() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
|
275 | Q_UNUSED(parent); | |
|
276 | if (m_orientation == Qt::Horizontal) | |
|
277 | removeData(start, end); | |
|
278 | else if (start <= m_valuesIndex || start <= m_labelsIndex) // if the changes affect the map - reinitialize the pie | |
|
279 | initializePieFromModel(); | |
|
165 | 280 | } |
|
281 | ||
|
282 | void QPieModelMapperPrivate::insertData(int start, int end) | |
|
283 | { | |
|
284 | if (m_count != -1 && start >= m_first + m_count) { | |
|
285 | return; | |
|
286 | } else { | |
|
287 | int addedCount = end - start + 1; | |
|
288 | if (m_count != -1 && addedCount > m_count) | |
|
289 | addedCount = m_count; | |
|
290 | 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); | |
|
292 | for (int i = first; i <= last; i++) { | |
|
293 | QPieSlice *slice = new QPieSlice; | |
|
294 | 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()); | |
|
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(); | |
|
304 | m_series->insert(i - m_first, slice); | |
|
305 | } | |
|
306 | if (m_count != -1 && m_series->slices().size() > m_count) | |
|
307 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) | |
|
308 | m_series->remove(m_series->slices().at(i)); | |
|
309 | } | |
|
310 | } | |
|
311 | ||
|
312 | void QPieModelMapperPrivate::removeData(int start, int end) | |
|
313 | { | |
|
314 | int removedCount = end - start + 1; | |
|
315 | if (m_count != -1 && start >= m_first + m_count) { | |
|
316 | return; | |
|
317 | } else { | |
|
318 | 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. | |
|
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. | |
|
321 | for (int i = last; i >= first; i--) | |
|
322 | m_series->remove(m_series->slices().at(i - m_first)); | |
|
323 | ||
|
324 | if (m_count != -1) { | |
|
325 | int itemsAvailable; // check how many are available to be added | |
|
326 | if (m_orientation == Qt::Vertical) | |
|
327 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
|
328 | else | |
|
329 | 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. | |
|
331 | int currentSize = m_series->slices().size(); | |
|
332 | if (toBeAdded > 0) | |
|
333 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
|
334 | QPieSlice *slice = new QPieSlice; | |
|
335 | if (m_orientation == Qt::Vertical) { | |
|
336 | 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()); | |
|
338 | } else { | |
|
339 | 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()); | |
|
341 | } | |
|
342 | slice->setLabelVisible(); | |
|
343 | m_series->insert(i, slice); | |
|
166 | 344 | } |
|
167 | 345 | } |
|
168 | 346 | } |
|
169 | 347 | } |
|
170 | 348 | |
|
349 | void QPieModelMapperPrivate::initializePieFromModel() | |
|
350 | { | |
|
351 | if (m_model == 0 || m_series == 0) | |
|
352 | return; | |
|
171 | 353 | |
|
172 | //void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
|
173 | //{ | |
|
174 | // Q_UNUSED(parent); | |
|
175 | // if (m_mapper->orientation() == Qt::Vertical) | |
|
176 | // insertData(start, end); | |
|
177 | // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie | |
|
178 | // initializePieFromModel(); | |
|
179 | //} | |
|
354 | // clear current content | |
|
355 | m_series->clear(); | |
|
180 | 356 | |
|
181 | //void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
|
182 | //{ | |
|
183 | // Q_UNUSED(parent); | |
|
184 | // if (m_mapper->orientation() == Qt::Vertical) | |
|
185 | // removeData(start, end); | |
|
186 | // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie | |
|
187 | // initializePieFromModel(); | |
|
188 | //} | |
|
357 | // check if mappings are set | |
|
358 | if (m_valuesIndex == -1 || m_labelsIndex == -1) | |
|
359 | return; | |
|
189 | 360 | |
|
190 | //void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
|
191 | //{ | |
|
192 | // Q_UNUSED(parent); | |
|
193 | // if (m_mapper->orientation() == Qt::Horizontal) | |
|
194 | // insertData(start, end); | |
|
195 | // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie | |
|
196 | // initializePieFromModel(); | |
|
197 | //} | |
|
361 | // create the initial slices set | |
|
362 | int slicePos = 0; | |
|
363 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
|
364 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
|
365 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
|
366 | m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
|
367 | slicePos++; | |
|
368 | valueIndex = valueModelIndex(slicePos); | |
|
369 | labelIndex = labelModelIndex(slicePos); | |
|
370 | } | |
|
198 | 371 | |
|
199 | //void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
|
200 | //{ | |
|
201 | // Q_UNUSED(parent); | |
|
202 | // if (m_mapper->orientation() == Qt::Horizontal) | |
|
203 | // removeData(start, end); | |
|
204 | // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie | |
|
205 | // initializePieFromModel(); | |
|
206 | //} | |
|
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 | |
|
207 | 375 | |
|
208 | //void QPieModelMapperPrivate::insertData(int start, int end) | |
|
209 | //{ | |
|
210 | // Q_Q(QPieSeries); | |
|
211 | // if (m_count != -1 && start >= m_first + m_count) { | |
|
212 | // return; | |
|
213 | // } else { | |
|
214 | // int addedCount = end - start + 1; | |
|
215 | // if (m_count != -1 && addedCount > m_count) | |
|
216 | // addedCount = m_count; | |
|
217 | // int first = qMax(start, m_first); | |
|
218 | // int last = qMin(first + addedCount - 1, m_mapper->orientation() == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
|
219 | // for (int i = first; i <= last; i++) { | |
|
220 | // QPieSlice *slice = new QPieSlice; | |
|
221 | // if (m_mapper->orientation() == Qt::Vertical) { | |
|
222 | // slice->setValue(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble()); | |
|
223 | // slice->setLabel(m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString()); | |
|
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); | |
|
224 | 381 |
// |
|
225 | // slice->setValue(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble()); | |
|
226 | // slice->setLabel(m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString()); | |
|
227 | // } | |
|
228 | // slice->setLabelVisible(); | |
|
229 | // q->insert(i - m_first, slice); | |
|
230 | // } | |
|
231 | // if (m_count != -1 && m_series->slices().size() > m_count) | |
|
232 | // for (int i = m_series->slices().size() - 1; i >= m_count; i--) | |
|
233 | // q->remove(q->slices().at(i)); | |
|
234 | // } | |
|
235 | //} | |
|
382 | // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount()) | |
|
383 | // return; // mapped columns are not existing | |
|
236 | 384 | |
|
237 | //void QPieModelMapperPrivate::removeData(int start, int end) | |
|
238 | //{ | |
|
239 | // Q_Q(QPieSeries); | |
|
240 | // int removedCount = end - start + 1; | |
|
241 | // if (m_count != -1 && start >= m_first + m_count) { | |
|
242 | // return; | |
|
243 | // } else { | |
|
244 | // int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
|
245 | // int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
|
246 | // int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
|
247 | // for (int i = last; i >= first; i--) | |
|
248 | // q->remove(q->slices().at(i - m_first)); | |
|
249 | ||
|
250 | // if (m_count != -1) { | |
|
251 | // int itemsAvailable; // check how many are available to be added | |
|
252 | // if (m_mapper->orientation() == Qt::Vertical) | |
|
253 | // itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
|
385 | // int sliceCount = 0; | |
|
386 | // if(m_count == -1) | |
|
387 | // sliceCount = m_model->columnCount() - m_first; | |
|
254 | 388 |
// |
|
255 |
// |
|
|
256 | // int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
|
257 | // int currentSize = m_series->slices().size(); | |
|
258 | // if (toBeAdded > 0) | |
|
259 | // for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
|
260 | // QPieSlice *slice = new QPieSlice; | |
|
261 | // if (m_mapper->orientation() == Qt::Vertical) { | |
|
262 | // slice->setValue(m_model->data(m_model->index(i + m_first, m_mapValues), Qt::DisplayRole).toDouble()); | |
|
263 | // slice->setLabel(m_model->data(m_model->index(i + m_first, m_mapLabels), Qt::DisplayRole).toString()); | |
|
264 | // } else { | |
|
265 | // slice->setValue(m_model->data(m_model->index(m_mapValues, i + m_first), Qt::DisplayRole).toDouble()); | |
|
266 | // slice->setLabel(m_model->data(m_model->index(m_mapLabels, i + m_first), Qt::DisplayRole).toString()); | |
|
267 | // } | |
|
268 | // slice->setLabelVisible(); | |
|
269 | // q->insert(i, slice); | |
|
270 | // } | |
|
271 | // } | |
|
272 | // } | |
|
389 | // sliceCount = qMin(m_count, m_model->columnCount() - m_first); | |
|
273 | 390 | //} |
|
274 | ||
|
275 | //void QPieModelMapperPrivate::initializePieFromModel() | |
|
276 | //{ | |
|
277 | // Q_Q(QPieSeries); | |
|
278 | ||
|
279 | // // clear current content | |
|
280 | // q->clear(); | |
|
281 | ||
|
282 | // if (m_model == 0 || m_mapper == 0) | |
|
283 | // return; | |
|
284 | ||
|
285 | // // check if mappings are set | |
|
286 | // if (m_mapValues == -1 || m_mapLabels == -1) | |
|
287 | // return; | |
|
288 | ||
|
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); | |
|
289 | 394 | // // create the initial slices set |
|
290 |
// if (m_ |
|
|
291 |
// if (m_ |
|
|
395 | // if (m_orientation == Qt::Vertical) { | |
|
396 | // if (m_valuesIndex >= m_model->columnCount() || m_labelsIndex >= m_model->columnCount()) | |
|
292 | 397 | // return; // mapped columns are not existing |
|
293 | 398 | |
|
294 | 399 | // int sliceCount = 0; |
@@ -297,9 +402,9 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto | |||
|
297 | 402 | // else |
|
298 | 403 | // sliceCount = qMin(m_count, m_model->rowCount() - m_first); |
|
299 | 404 | // for (int i = m_first; i < m_first + sliceCount; i++) |
|
300 |
// |
|
|
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()); | |
|
301 | 406 | // } else { |
|
302 |
// if (m_ |
|
|
407 | // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount()) | |
|
303 | 408 | // return; // mapped columns are not existing |
|
304 | 409 | |
|
305 | 410 | // int sliceCount = 0; |
@@ -308,10 +413,9 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto | |||
|
308 | 413 | // else |
|
309 | 414 | // sliceCount = qMin(m_count, m_model->columnCount() - m_first); |
|
310 | 415 | // for (int i = m_first; i < m_first + sliceCount; i++) |
|
311 |
// |
|
|
312 | // } | |
|
313 | // q->setLabelsVisible(true); | |
|
314 | //} | |
|
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 | } | |
|
315 | 419 | |
|
316 | 420 | #include "moc_qpiemodelmapper_p.cpp" |
|
317 | 421 | #include "moc_qpiemodelmapper.cpp" |
@@ -4,15 +4,18 | |||
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include <QObject> |
|
6 | 6 | |
|
7 | class QAbstractItemModel; | |
|
8 | ||
|
7 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 10 | |
|
9 | 11 | class QPieModelMapperPrivate; |
|
12 | class QPieSeries; | |
|
10 | 13 | |
|
11 | 14 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject |
|
12 | 15 | { |
|
13 | 16 | Q_OBJECT |
|
14 |
Q_PROPERTY(int |
|
|
15 |
Q_PROPERTY(int |
|
|
17 | Q_PROPERTY(int valuesIndex READ valuesIndex WRITE setValuesIndex) | |
|
18 | Q_PROPERTY(int labelsIndex READ labelsIndex WRITE setLabelsIndex) | |
|
16 | 19 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
17 | 20 | Q_PROPERTY(int count READ count WRITE setCount) |
|
18 | 21 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) |
@@ -21,8 +24,11 class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject | |||
|
21 | 24 | public: |
|
22 | 25 | QPieModelMapper(QObject *parent = 0); |
|
23 | 26 | |
|
24 |
|
|
|
25 |
|
|
|
27 | QAbstractItemModel* model() const; | |
|
28 | void setModel(QAbstractItemModel *model); | |
|
29 | ||
|
30 | QPieSeries* series() const; | |
|
31 | void setSeries(QPieSeries *series); | |
|
26 | 32 | |
|
27 | 33 | int first() const; |
|
28 | 34 | void setFirst(int first); |
@@ -33,18 +39,17 public: | |||
|
33 | 39 | Qt::Orientation orientation() const; |
|
34 | 40 | void setOrientation(Qt::Orientation orientation); |
|
35 | 41 | |
|
36 |
int |
|
|
37 |
void set |
|
|
42 | int valuesIndex() const; | |
|
43 | void setValuesIndex(int valuesIndex); | |
|
38 | 44 | |
|
39 |
int |
|
|
40 |
void set |
|
|
45 | int labelsIndex() const; | |
|
46 | void setLabelsIndex(int labelsIndex); | |
|
41 | 47 | |
|
42 | 48 | void reset(); |
|
43 | 49 | |
|
44 | 50 | private: |
|
45 | 51 | QScopedPointer<QPieModelMapperPrivate> d_ptr; |
|
46 | 52 | Q_DECLARE_PRIVATE(QPieModelMapper) |
|
47 | friend class QPieSeriesPrivate; | |
|
48 | 53 | }; |
|
49 | 54 | |
|
50 | 55 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -11,6 +11,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
11 | 11 | |
|
12 | 12 | class QPieModelMapper; |
|
13 | 13 | class QPieSeries; |
|
14 | class QPieSlice; | |
|
14 | 15 | |
|
15 | 16 | class QPieModelMapperPrivate : public QObject |
|
16 | 17 | { |
@@ -22,32 +23,36 public: | |||
|
22 | 23 | public Q_SLOTS: |
|
23 | 24 | // for the model |
|
24 | 25 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
26 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
|
27 | void modelRowsRemoved(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 | 30 | |
|
30 | 31 | // for the series |
|
31 | 32 | void slicesAdded(); |
|
32 | 33 | void slicesRemoved(); |
|
33 | 34 | void sliceChanged(); |
|
34 | 35 | |
|
35 | private: | |
|
36 | void setModel(QAbstractItemModel *model); | |
|
36 | void initializePieFromModel(); | |
|
37 | 37 | |
|
38 | 38 | private: |
|
39 | int getSliceIndex(); | |
|
39 | QPieSlice* pieSlice(QModelIndex index) const; | |
|
40 | QModelIndex valueModelIndex(int slicePos); | |
|
41 | QModelIndex labelModelIndex(int slicePos); | |
|
42 | void insertData(int start, int end); | |
|
43 | void removeData(int start, int end); | |
|
40 | 44 | |
|
41 | 45 | private: |
|
46 | QPieSeries *m_series; | |
|
47 | QAbstractItemModel *m_model; | |
|
42 | 48 | int m_first; |
|
43 | 49 | int m_count; |
|
44 | 50 | Qt::Orientation m_orientation; |
|
45 |
int m_ |
|
|
46 |
int m_ |
|
|
51 | int m_valuesIndex; | |
|
52 | int m_labelsIndex; | |
|
47 | 53 | |
|
48 | 54 | private: |
|
49 | QPieSeries *m_series; | |
|
50 | QAbstractItemModel *m_model; | |
|
55 | ||
|
51 | 56 | QPieModelMapper *q_ptr; |
|
52 | 57 | Q_DECLARE_PUBLIC(QPieModelMapper) |
|
53 | 58 | friend class QPieSeriesPrivate; |
@@ -26,9 +26,6 | |||
|
26 | 26 | #include "charttheme_p.h" |
|
27 | 27 | #include "chartanimator_p.h" |
|
28 | 28 | #include "legendmarker_p.h" |
|
29 | #include <QAbstractItemModel> | |
|
30 | #include "qpiemodelmapper.h" | |
|
31 | #include "qpiemodelmapper_p.h" | |
|
32 | 29 | |
|
33 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 31 | |
@@ -463,65 +460,7 qreal QPieSeries::sum() const | |||
|
463 | 460 | \sa QPieSlice::hovered() |
|
464 | 461 | */ |
|
465 | 462 | |
|
466 | /*! | |
|
467 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
|
468 | Sets the \a model to be used as a data source | |
|
469 | */ | |
|
470 | void QPieSeries::setModel(QAbstractItemModel* model) | |
|
471 | { | |
|
472 | Q_D(QPieSeries); | |
|
473 | d->setModel(model); | |
|
474 | // // disconnect signals from old model | |
|
475 | // if(d->m_model) | |
|
476 | // { | |
|
477 | // disconnect(d->m_model, 0, this, 0); | |
|
478 | // } | |
|
479 | ||
|
480 | // // set new model | |
|
481 | // if(model) | |
|
482 | // { | |
|
483 | // d->m_model = model; | |
|
484 | // // connect signals from the model | |
|
485 | //// connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
486 | //// connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
|
487 | //// connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
|
488 | //// connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
|
489 | //// connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
490 | ||
|
491 | //// if (d->m_mapper) | |
|
492 | //// d->initializePieFromModel(); | |
|
493 | // } | |
|
494 | // else | |
|
495 | // { | |
|
496 | // d->m_model = 0; | |
|
497 | // } | |
|
498 | } | |
|
499 | ||
|
500 | void QPieSeries::setModelMapper(QPieModelMapper *mapper) | |
|
501 | { | |
|
502 | Q_D(QPieSeries); | |
|
503 | // disconnect signals from old mapper | |
|
504 | if (d->m_mapper) { | |
|
505 | QObject::disconnect(d->m_mapper, 0, this, 0); | |
|
506 | } | |
|
507 | ||
|
508 | if (mapper) { | |
|
509 | d->m_mapper = mapper; | |
|
510 | // connect the signal from the mapper | |
|
511 | // connect(d->m_mapper, SIGNAL(updated()), d, SLOT(initializePieFromModel())); | |
|
512 | ||
|
513 | // if (d->m_model) | |
|
514 | // d->initializePieFromModel(); | |
|
515 | } else { | |
|
516 | d->m_mapper = 0; | |
|
517 | } | |
|
518 | } | |
|
519 | 463 | |
|
520 | QPieModelMapper* QPieSeries::modelMapper() const | |
|
521 | { | |
|
522 | Q_D(const QPieSeries); | |
|
523 | return d->m_mapper; | |
|
524 | } | |
|
525 | 464 | |
|
526 | 465 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
527 | 466 | |
@@ -533,16 +472,12 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |||
|
533 | 472 | m_pieRelativeSize(0.7), |
|
534 | 473 | m_pieStartAngle(0), |
|
535 | 474 | m_pieEndAngle(360), |
|
536 |
m_sum(0) |
|
|
537 | m_model(0), | |
|
538 | m_mapper(0) | |
|
475 | m_sum(0) | |
|
539 | 476 | { |
|
540 | ||
|
541 | 477 | } |
|
542 | 478 | |
|
543 | 479 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
544 | 480 | { |
|
545 | ||
|
546 | 481 | } |
|
547 | 482 | |
|
548 | 483 | void QPieSeriesPrivate::updateDerivativeData() |
@@ -665,21 +600,6 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
665 | 600 | return markers; |
|
666 | 601 | } |
|
667 | 602 | |
|
668 | void QPieSeriesPrivate::setModel(QAbstractItemModel* model) | |
|
669 | { | |
|
670 | Q_Q(QPieSeries); | |
|
671 | QPieModelMapperPrivate *mapperPrivate = m_mapper->d_func(); | |
|
672 | mapperPrivate->setModel(model); | |
|
673 | if(mapperPrivate->m_series != q) | |
|
674 | { | |
|
675 | disconnect(mapperPrivate->m_series, 0, mapperPrivate, 0); | |
|
676 | mapperPrivate->m_series = q; | |
|
677 | connect(this, SIGNAL(added(QList<QPieSlice*>)), mapperPrivate, SLOT(slicesAdded())); | |
|
678 | connect(this, SIGNAL(removed(QList<QPieSlice*>)), mapperPrivate, SLOT(slicesRemoved())); | |
|
679 | connect(this, SIGNAL(modified()), mapperPrivate, SLOT(sliceChanged())); | |
|
680 | } | |
|
681 | } | |
|
682 | ||
|
683 | 603 | #include "moc_qpieseries.cpp" |
|
684 | 604 | #include "moc_qpieseries_p.cpp" |
|
685 | 605 |
@@ -26,7 +26,6 | |||
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | class QPieSeriesPrivate; |
|
28 | 28 | class QPieSlice; |
|
29 | class QPieModelMapper; | |
|
30 | 29 | |
|
31 | 30 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries |
|
32 | 31 | { |
@@ -38,7 +37,6 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries | |||
|
38 | 37 | Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle) |
|
39 | 38 | Q_PROPERTY(int count READ count) |
|
40 | 39 | Q_PROPERTY(qreal sum READ sum) |
|
41 | Q_PROPERTY(QPieModelMapper *modelMapper READ modelMapper) | |
|
42 | 40 | |
|
43 | 41 | public: |
|
44 | 42 | explicit QPieSeries(QObject *parent = 0); |
@@ -75,10 +73,6 public: | |||
|
75 | 73 | |
|
76 | 74 | void setLabelsVisible(bool visible = true); |
|
77 | 75 | |
|
78 | void setModel(QAbstractItemModel* model); | |
|
79 | void setModelMapper(QPieModelMapper *mapper); | |
|
80 | QPieModelMapper* modelMapper() const; | |
|
81 | ||
|
82 | 76 | Q_SIGNALS: |
|
83 | 77 | void added(QList<QPieSlice*> slices); |
|
84 | 78 | void removed(QList<QPieSlice*> slices); |
@@ -24,11 +24,8 | |||
|
24 | 24 | #include "qpieseries.h" |
|
25 | 25 | #include "qabstractseries_p.h" |
|
26 | 26 | |
|
27 | class QModelIndex; | |
|
28 | ||
|
29 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 28 | class QLegendPrivate; |
|
31 | class QPieModelMapper; | |
|
32 | 29 | |
|
33 | 30 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
34 | 31 | { |
@@ -54,19 +51,8 public Q_SLOTS: | |||
|
54 | 51 | void sliceChanged(); |
|
55 | 52 | void sliceClicked(); |
|
56 | 53 | void sliceHovered(bool state); |
|
57 | // void initializePieFromModel(); | |
|
58 | // void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
59 | // void modelRowsAdded(QModelIndex parent, int start, int end); | |
|
60 | // void modelRowsRemoved(QModelIndex parent, int start, int end); | |
|
61 | // void modelColumnsAdded(QModelIndex parent, int start, int end); | |
|
62 | // void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
|
63 | 54 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); |
|
64 | 55 | |
|
65 | private: | |
|
66 | void setModel(QAbstractItemModel *model); | |
|
67 | // void insertData(int start, int end); | |
|
68 | // void removeData(int start, int end); | |
|
69 | ||
|
70 | 56 | public: |
|
71 | 57 | QList<QPieSlice*> m_slices; |
|
72 | 58 | qreal m_pieRelativeHorPos; |
@@ -76,10 +62,6 public: | |||
|
76 | 62 | qreal m_pieEndAngle; |
|
77 | 63 | qreal m_sum; |
|
78 | 64 | |
|
79 | // model | |
|
80 | QAbstractItemModel *m_model; | |
|
81 | QPieModelMapper *m_mapper; | |
|
82 | ||
|
83 | 65 | private: |
|
84 | 66 | friend class QLegendPrivate; |
|
85 | 67 | Q_DECLARE_PUBLIC(QPieSeries) |
@@ -96,14 +96,6 QAbstractSeries::~QAbstractSeries() | |||
|
96 | 96 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | /*! | |
|
100 | \brief Returns the pointer to the model that is used as the series data source | |
|
101 | */ | |
|
102 | QAbstractItemModel* QAbstractSeries::model() const | |
|
103 | { | |
|
104 | return d_ptr->m_model; | |
|
105 | } | |
|
106 | ||
|
107 | 99 | void QAbstractSeries::setName(const QString& name) |
|
108 | 100 | { |
|
109 | 101 | d_ptr->m_name = name; |
@@ -122,7 +114,6 QString QAbstractSeries::name() const | |||
|
122 | 114 | |
|
123 | 115 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
124 | 116 | q_ptr(q), |
|
125 | m_model(0), | |
|
126 | 117 | m_dataset(0) |
|
127 | 118 | { |
|
128 | 119 | } |
@@ -25,13 +25,10 | |||
|
25 | 25 | #include <QObject> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | |
|
28 | class QAbstractItemModel; | |
|
29 | ||
|
30 | 28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 29 | |
|
32 | 30 | class QAbstractSeriesPrivate; |
|
33 | 31 | class QChart; |
|
34 | //class QModelMapper; | |
|
35 | 32 | |
|
36 | 33 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
37 | 34 | { |
@@ -58,8 +55,6 protected: | |||
|
58 | 55 | public: |
|
59 | 56 | ~QAbstractSeries(); |
|
60 | 57 | virtual SeriesType type() const = 0; |
|
61 | virtual void setModel(QAbstractItemModel *model) = 0; | |
|
62 | QAbstractItemModel* model() const; | |
|
63 | 58 | void setName(const QString& name); |
|
64 | 59 | QString name() const; |
|
65 | 60 | QChart* chart() const; |
@@ -32,8 +32,6 | |||
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries.h" |
|
34 | 34 | |
|
35 | class QAbstractItemModel; | |
|
36 | ||
|
37 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 36 | |
|
39 | 37 | class Domain; |
@@ -42,7 +40,6 class Chart; | |||
|
42 | 40 | class LegendMarker; |
|
43 | 41 | class QLegend; |
|
44 | 42 | class ChartDataSet; |
|
45 | //class QModelMapper; | |
|
46 | 43 | |
|
47 | 44 | class QAbstractSeriesPrivate : public QObject |
|
48 | 45 | { |
@@ -57,12 +54,7 public: | |||
|
57 | 54 | |
|
58 | 55 | protected: |
|
59 | 56 | QAbstractSeries *q_ptr; |
|
60 | QAbstractItemModel *m_model; | |
|
61 | // QModelMapper *m_mapper; | |
|
62 | 57 | ChartDataSet *m_dataset; |
|
63 | // int m_mapFirst; | |
|
64 | // int m_mapCount; | |
|
65 | // Qt::Orientation m_mapOrientation; | |
|
66 | 58 | QString m_name; |
|
67 | 59 | |
|
68 | 60 | friend class QAbstractSeries; |
@@ -24,7 +24,6 | |||
|
24 | 24 | #include "chartdataset_p.h" |
|
25 | 25 | #include "charttheme_p.h" |
|
26 | 26 | #include "chartanimator_p.h" |
|
27 | #include <QAbstractItemModel> | |
|
28 | 27 | |
|
29 | 28 | /*! |
|
30 | 29 | \class QSplineSeries |
@@ -75,22 +74,6 QAbstractSeries::SeriesType QSplineSeries::type() const | |||
|
75 | 74 | return QAbstractSeries::SeriesTypeSpline; |
|
76 | 75 | } |
|
77 | 76 | |
|
78 | void QSplineSeries::setModel(QAbstractItemModel *model) | |
|
79 | { | |
|
80 | Q_D(QSplineSeries); | |
|
81 | QXYSeries::setModel(model); | |
|
82 | if (d->m_model && d->m_mapper) | |
|
83 | d->updateControlPoints(); | |
|
84 | } | |
|
85 | ||
|
86 | void QSplineSeries::setModelMapper(QXYModelMapper *mapper) | |
|
87 | { | |
|
88 | Q_D(QSplineSeries); | |
|
89 | QXYSeries::setModelMapper(mapper); | |
|
90 | if (d->m_model && d->m_mapper) | |
|
91 | d->updateControlPoints(); | |
|
92 | } | |
|
93 | ||
|
94 | 77 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
95 | 78 | |
|
96 | 79 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q) |
@@ -219,36 +202,6 void QSplineSeriesPrivate::updateControlPoints() | |||
|
219 | 202 | } |
|
220 | 203 | } |
|
221 | 204 | |
|
222 | void QSplineSeriesPrivate::mappingUpdated() | |
|
223 | { | |
|
224 | updateControlPoints(); | |
|
225 | emit updated(); | |
|
226 | } | |
|
227 | ||
|
228 | void QSplineSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
|
229 | { | |
|
230 | updateControlPoints(); | |
|
231 | QXYSeriesPrivate::modelRowsAdded(parent, start, end); | |
|
232 | } | |
|
233 | ||
|
234 | void QSplineSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
|
235 | { | |
|
236 | updateControlPoints(); | |
|
237 | QXYSeriesPrivate::modelRowsRemoved(parent, start, end); | |
|
238 | } | |
|
239 | ||
|
240 | void QSplineSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
|
241 | { | |
|
242 | updateControlPoints(); | |
|
243 | QXYSeriesPrivate::modelColumnsAdded(parent, start, end); | |
|
244 | } | |
|
245 | ||
|
246 | void QSplineSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
|
247 | { | |
|
248 | updateControlPoints(); | |
|
249 | QXYSeriesPrivate::modelColumnsRemoved(parent, start, end); | |
|
250 | } | |
|
251 | ||
|
252 | 205 | Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
253 | 206 | { |
|
254 | 207 | Q_Q(QSplineSeries); |
@@ -40,9 +40,6 public: | |||
|
40 | 40 | ~QSplineSeries(); |
|
41 | 41 | QAbstractSeries::SeriesType type() const; |
|
42 | 42 | |
|
43 | void setModel(QAbstractItemModel *model); | |
|
44 | void setModelMapper(QXYModelMapper *mapper); | |
|
45 | ||
|
46 | 43 | private: |
|
47 | 44 | Q_DECLARE_PRIVATE(QSplineSeries) |
|
48 | 45 | Q_DISABLE_COPY(QSplineSeries) |
@@ -47,13 +47,6 public: | |||
|
47 | 47 | public Q_SLOTS: |
|
48 | 48 | void updateControlPoints(); |
|
49 | 49 | |
|
50 | protected Q_SLOTS: | |
|
51 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
|
52 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
|
53 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |
|
54 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
|
55 | void mappingUpdated(); | |
|
56 | ||
|
57 | 50 | private: |
|
58 | 51 | void calculateControlPoints(); |
|
59 | 52 | QVector<qreal> firstControlPoints(const QVector<qreal>& vector); |
@@ -22,8 +22,6 | |||
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "domain_p.h" |
|
24 | 24 | #include "legendmarker_p.h" |
|
25 | #include <QAbstractItemModel> | |
|
26 | #include "qxymodelmapper.h" | |
|
27 | 25 | |
|
28 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | 27 | |
@@ -169,39 +167,9 void QXYSeries::removeAll() | |||
|
169 | 167 | */ |
|
170 | 168 | QList<QPointF> QXYSeries::points() const |
|
171 | 169 | { |
|
172 | // Q_ASSERT(false); | |
|
173 | 170 | Q_D(const QXYSeries); |
|
174 | if (d->m_model && d->m_mapper) { | |
|
175 | QList<QPointF> result; | |
|
176 | if (d->m_mapper->orientation() == Qt::Vertical){ | |
|
177 | // consecutive data is read from model's column | |
|
178 | if (d->m_mapper->mapX() >= d->m_model->columnCount() || d->m_mapper->mapY() >= d->m_model->columnCount()) | |
|
179 | return result; // mapped columns are not existing | |
|
180 | ||
|
181 | for(int i = d->m_mapper->first(); i< d->m_mapper->first() + count(); ++i) { | |
|
182 | qreal x = d->m_model->data(d->m_model->index(i, d->m_mapper->mapX()), Qt::DisplayRole).toReal(); | |
|
183 | qreal y = d->m_model->data(d->m_model->index(i, d->m_mapper->mapY()), Qt::DisplayRole).toReal(); | |
|
184 | result << QPointF(x,y); | |
|
185 | } | |
|
186 | return result; | |
|
187 | } | |
|
188 | else{ | |
|
189 | // consecutive data is read from model's row | |
|
190 | if (d->m_mapper->mapX() >= d->m_model->rowCount() || d->m_mapper->mapY() >= d->m_model->rowCount()) | |
|
191 | return result; // mapped rows are not existing | |
|
192 | ||
|
193 | for(int i = d->m_mapper->first(); i< d->m_mapper->first() + count(); ++i) { | |
|
194 | qreal x = d->m_model->data(d->m_model->index(d->m_mapper->mapX(), i), Qt::DisplayRole).toReal(); | |
|
195 | qreal y = d->m_model->data(d->m_model->index(d->m_mapper->mapY(), i), Qt::DisplayRole).toReal(); | |
|
196 | result << QPointF(x,y); | |
|
197 | } | |
|
198 | return result; | |
|
199 | } | |
|
200 | } else { | |
|
201 | // model is not specified, return the data from series' internal data store | |
|
202 | 171 |
|
|
203 | 172 | } |
|
204 | } | |
|
205 | 173 | |
|
206 | 174 | /*! |
|
207 | 175 | Returns number of data points within series. |
@@ -209,31 +177,6 QList<QPointF> QXYSeries::points() const | |||
|
209 | 177 | int QXYSeries::count() const |
|
210 | 178 | { |
|
211 | 179 | Q_D(const QXYSeries); |
|
212 | ||
|
213 | if (d->m_model && d->m_mapper) { | |
|
214 | ||
|
215 | if (d->m_mapper->orientation() == Qt::Vertical) { | |
|
216 | // data is in a column. Return the number of mapped items if the model's column have enough items | |
|
217 | // or the number of items that can be mapped | |
|
218 | if (d->m_mapper->mapX() >= d->m_model->columnCount() || d->m_mapper->mapY() >= d->m_model->columnCount()) | |
|
219 | return 0; // mapped columns are not existing | |
|
220 | else if (d->m_mapper->count() != -1) | |
|
221 | return qMin(d->m_mapper->count(), qMax(d->m_model->rowCount() - d->m_mapper->first(), 0)); | |
|
222 | else | |
|
223 | return qMax(d->m_model->rowCount() - d->m_mapper->first(), 0); | |
|
224 | } else { | |
|
225 | // data is in a row. Return the number of mapped items if the model's row have enough items | |
|
226 | // or the number of items that can be mapped | |
|
227 | if (d->m_mapper->mapX() >= d->m_model->rowCount() || d->m_mapper->mapY() >= d->m_model->rowCount()) | |
|
228 | return 0; // mapped rows are not existing | |
|
229 | else if (d->m_mapper->count() != -1) | |
|
230 | return qMin(d->m_mapper->count(), qMax(d->m_model->columnCount() - d->m_mapper->first(), 0)); | |
|
231 | else | |
|
232 | return qMax(d->m_model->columnCount() - d->m_mapper->first(), 0); | |
|
233 | } | |
|
234 | } | |
|
235 | ||
|
236 | // model is not specified, return the number of points in the series internal data store | |
|
237 | 180 | return d->m_points.count(); |
|
238 | 181 | } |
|
239 | 182 | |
@@ -323,73 +266,11 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) | |||
|
323 | 266 | return *this; |
|
324 | 267 | } |
|
325 | 268 | |
|
326 | /*! | |
|
327 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) | |
|
328 | Sets the \a model to be used as a data source | |
|
329 | \sa setModelMapping() | |
|
330 | */ | |
|
331 | void QXYSeries::setModel(QAbstractItemModel *model) | |
|
332 | { | |
|
333 | Q_D(QXYSeries); | |
|
334 | // disconnect signals from old model | |
|
335 | if (d->m_model) { | |
|
336 | QObject::disconnect(d->m_model, 0, this, 0); | |
|
337 | } | |
|
338 | ||
|
339 | // set new model | |
|
340 | if (model) { | |
|
341 | d->m_model = model; | |
|
342 | emit d->reinitialized(); | |
|
343 | ||
|
344 | // connect signals from the model | |
|
345 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
|
346 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
|
347 | connect(d->m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
|
348 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
|
349 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
350 | } else { | |
|
351 | d->m_model = 0; | |
|
352 | } | |
|
353 | } | |
|
354 | ||
|
355 | void QXYSeries::setModelMapper(QXYModelMapper *mapper) | |
|
356 | { | |
|
357 | Q_D(QXYSeries); | |
|
358 | // disconnect signals from old mapper | |
|
359 | if (d->m_mapper) { | |
|
360 | QObject::disconnect(d->m_mapper, 0, this, 0); | |
|
361 | } | |
|
362 | ||
|
363 | if (mapper) { | |
|
364 | d->m_mapper = mapper; | |
|
365 | emit d->reinitialized(); | |
|
366 | ||
|
367 | // connect the signal from the mapper | |
|
368 | connect(d->m_mapper, SIGNAL(updated()), d, SLOT(mappingUpdated())); | |
|
369 | } else { | |
|
370 | d->m_mapper = 0; | |
|
371 | } | |
|
372 | } | |
|
373 | ||
|
374 | QXYModelMapper* QXYSeries::modelMapper() const | |
|
375 | { | |
|
376 | Q_D(const QXYSeries); | |
|
377 | return d->m_mapper; | |
|
378 | } | |
|
379 | ||
|
380 | /*! | |
|
381 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used | |
|
382 | as a data source for y coordinate. The \a orientation parameter specifies whether the data | |
|
383 | is in columns or in rows. | |
|
384 | \sa setModel() | |
|
385 | */ | |
|
386 | ||
|
387 | ||
|
388 | 269 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
389 | 270 | |
|
390 | 271 | |
|
391 |
QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
|
392 | m_mapper(0), | |
|
272 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : | |
|
273 | QAbstractSeriesPrivate(q), | |
|
393 | 274 | m_pointsVisible(false) |
|
394 | 275 | { |
|
395 | 276 | } |
@@ -435,78 +316,6 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
435 | 316 | return list << new XYLegendMarker(q,legend); |
|
436 | 317 | } |
|
437 | 318 | |
|
438 | void QXYSeriesPrivate::mappingUpdated() | |
|
439 | { | |
|
440 | if (m_model) | |
|
441 | emit reinitialized(); | |
|
442 | } | |
|
443 | ||
|
444 | void QXYSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
|
445 | { | |
|
446 | if (m_mapper) { | |
|
447 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
|
448 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
|
449 | if (m_mapper->orientation() == Qt::Vertical) { | |
|
450 | if ((column == m_mapper->mapX() || column == m_mapper->mapY()) // modified item is in a mapped column | |
|
451 | && row >= m_mapper->first() // modfied item in not before first item | |
|
452 | && (m_mapper->count() == -1 || row < m_mapper->first() + m_mapper->count())) // map is not limited or item lays before the end of map | |
|
453 | emit pointReplaced(row - m_mapper->first()); | |
|
454 | } else { | |
|
455 | if ((row == m_mapper->mapX() || row == m_mapper->mapY()) // modified item is in a mapped row | |
|
456 | && column >= m_mapper->first() // modfied item in not before first item | |
|
457 | && (m_mapper->count() == -1 || column < m_mapper->first() + m_mapper->count())) // map is not limited or item lays before the end of map | |
|
458 | emit pointReplaced(column - m_mapper->first()); | |
|
459 | } | |
|
460 | } | |
|
461 | } | |
|
462 | } | |
|
463 | } | |
|
464 | ||
|
465 | ||
|
466 | void QXYSeriesPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
|
467 | { | |
|
468 | Q_UNUSED(parent); | |
|
469 | if (m_mapper) { | |
|
470 | if (m_mapper->orientation() == Qt::Vertical) | |
|
471 | emit pointsAdded(start, end); | |
|
472 | else if (start <= m_mapper->mapX() || start <= m_mapper->mapY()) | |
|
473 | emit reinitialized(); | |
|
474 | } | |
|
475 | } | |
|
476 | ||
|
477 | void QXYSeriesPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
|
478 | { | |
|
479 | Q_UNUSED(parent); | |
|
480 | if (m_mapper) { | |
|
481 | if (m_mapper->orientation() == Qt::Vertical) | |
|
482 | emit pointsRemoved(start, end); | |
|
483 | else if (start <= m_mapper->mapX() || start <= m_mapper->mapY()) | |
|
484 | emit reinitialized(); | |
|
485 | } | |
|
486 | } | |
|
487 | ||
|
488 | void QXYSeriesPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
|
489 | { | |
|
490 | Q_UNUSED(parent); | |
|
491 | if (m_mapper) { | |
|
492 | if (m_mapper->orientation() == Qt::Horizontal) | |
|
493 | emit pointsAdded(start, end); | |
|
494 | else if (start <= m_mapper->mapX() || start <= m_mapper->mapY()) | |
|
495 | emit reinitialized(); | |
|
496 | } | |
|
497 | } | |
|
498 | ||
|
499 | void QXYSeriesPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
|
500 | { | |
|
501 | Q_UNUSED(parent); | |
|
502 | if (m_mapper) { | |
|
503 | if (m_mapper->orientation() == Qt::Horizontal) | |
|
504 | emit pointsRemoved(start, end); | |
|
505 | else if (start <= m_mapper->mapX() || start <= m_mapper->mapY()) | |
|
506 | emit reinitialized(); | |
|
507 | } | |
|
508 | } | |
|
509 | ||
|
510 | 319 | #include "moc_qxyseries.cpp" |
|
511 | 320 | #include "moc_qxyseries_p.cpp" |
|
512 | 321 |
@@ -36,7 +36,6 class QXYModelMapper; | |||
|
36 | 36 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries |
|
37 | 37 | { |
|
38 | 38 | Q_OBJECT |
|
39 | Q_PROPERTY(QXYModelMapper *modelMapper READ modelMapper) | |
|
40 | 39 | |
|
41 | 40 | protected: |
|
42 | 41 | explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0); |
@@ -67,10 +66,6 public: | |||
|
67 | 66 | void setPointsVisible(bool visible = true); |
|
68 | 67 | bool pointsVisible() const; |
|
69 | 68 | |
|
70 | void setModel(QAbstractItemModel *model); | |
|
71 | virtual void setModelMapper(QXYModelMapper *mapper); | |
|
72 | QXYModelMapper* modelMapper() const; | |
|
73 | ||
|
74 | 69 | Q_SIGNALS: |
|
75 | 70 | void clicked(const QPointF &point); |
|
76 | 71 |
@@ -35,7 +35,6 | |||
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QXYSeries; |
|
38 | class QXYModelMapper; | |
|
39 | 38 | |
|
40 | 39 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
41 | 40 | { |
@@ -47,18 +46,6 public: | |||
|
47 | 46 | void scaleDomain(Domain& domain); |
|
48 | 47 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
49 | 48 | |
|
50 | protected Q_SLOTS: | |
|
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
|
52 | virtual void modelRowsAdded(QModelIndex parent, int start, int end); | |
|
53 | virtual void modelRowsRemoved(QModelIndex parent, int start, int end); | |
|
54 | virtual void modelColumnsAdded(QModelIndex parent, int start, int end); | |
|
55 | virtual void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
|
56 | virtual void mappingUpdated(); | |
|
57 | ||
|
58 | private: | |
|
59 | void insertData(int start, int end); | |
|
60 | void removeData(int start, int end); | |
|
61 | ||
|
62 | 49 | Q_SIGNALS: |
|
63 | 50 | void updated(); |
|
64 | 51 | void pointReplaced(int index); |
@@ -70,10 +57,8 Q_SIGNALS: | |||
|
70 | 57 | |
|
71 | 58 | protected: |
|
72 | 59 | QVector<QPointF> m_points; |
|
73 | ||
|
74 | 60 | QPen m_pen; |
|
75 | 61 | QBrush m_brush; |
|
76 | QXYModelMapper* m_mapper; | |
|
77 | 62 | bool m_pointsVisible; |
|
78 | 63 | |
|
79 | 64 | private: |
@@ -41,9 +41,7 m_animation(0) | |||
|
41 | 41 | { |
|
42 | 42 | QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); |
|
43 | 43 | QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); |
|
44 | QObject::connect(series->d_func(),SIGNAL(pointsAdded(int, int)),this,SLOT(handlePointsAdded(int, int))); | |
|
45 | 44 | QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); |
|
46 | QObject::connect(series->d_func(),SIGNAL(pointsRemoved(int, int)),this,SLOT(handlePointsRemoved(int, int))); | |
|
47 | 45 | QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized())); |
|
48 | 46 | QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF))); |
|
49 | 47 | } |
@@ -124,11 +122,8 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoin | |||
|
124 | 122 | |
|
125 | 123 | void XYChart::handlePointAdded(int index) |
|
126 | 124 | { |
|
127 | if (m_series->model() == 0) { | |
|
128 | 125 |
|
|
129 | 126 |
|
|
130 | } | |
|
131 | ||
|
132 | 127 | QVector<QPointF> points = m_points; |
|
133 | 128 | QPointF point; |
|
134 | 129 | point = calculateGeometryPoint(index); |
@@ -141,42 +136,10 void XYChart::handlePointAdded(int index) | |||
|
141 | 136 | updateChart(m_points,points,index); |
|
142 | 137 | } |
|
143 | 138 | |
|
144 | void XYChart::handlePointsAdded(int start, int end) | |
|
145 | { | |
|
146 | if (m_series->model() == 0) { | |
|
147 | for (int i = start; i <= end; i++) | |
|
148 | handlePointAdded(i); | |
|
149 | } | |
|
150 | else { | |
|
151 | int mapFirst = m_series->modelMapper()->first(); | |
|
152 | int mapCount = m_series->modelMapper()->count(); | |
|
153 | if (mapCount != -1 && start >= mapFirst + mapCount) { | |
|
154 | return; | |
|
155 | } | |
|
156 | else { | |
|
157 | int addedCount = end - start + 1; | |
|
158 | if (mapCount != -1 && addedCount > mapCount) | |
|
159 | addedCount = mapCount; | |
|
160 | int first = qMax(start, mapFirst); // get the index of the first item that will be added | |
|
161 | int last = qMin(first + addedCount - 1, mapCount + mapFirst - 1);// get the index of the last item that will be added | |
|
162 | for (int i = first; i <= last; i++) { | |
|
163 | handlePointAdded(i - mapFirst); | |
|
164 | } | |
|
165 | // the map is limited therefore the items that are now outside the map | |
|
166 | // need to be removed from the drawn points | |
|
167 | if (mapCount != -1 && m_points.size() > mapCount) | |
|
168 | for (int i = m_points.size() - 1; i >= mapCount; i--) | |
|
169 | handlePointRemoved(i); | |
|
170 | } | |
|
171 | } | |
|
172 | } | |
|
173 | ||
|
174 | 139 | void XYChart::handlePointRemoved(int index) |
|
175 | 140 | { |
|
176 | if (m_series->model() == 0) { | |
|
177 | 141 |
|
|
178 | 142 |
|
|
179 | } | |
|
180 | 143 | QVector<QPointF> points = m_points; |
|
181 | 144 | points.remove(index); |
|
182 | 145 | |
@@ -187,57 +150,6 void XYChart::handlePointRemoved(int index) | |||
|
187 | 150 | updateChart(m_points,points,index); |
|
188 | 151 | } |
|
189 | 152 | |
|
190 | void XYChart::handlePointsRemoved(int start, int end) | |
|
191 | { | |
|
192 | Q_UNUSED(start) | |
|
193 | Q_UNUSED(end) | |
|
194 | if (m_series->model() == 0) { | |
|
195 | for (int i = end; i >= start; i--) | |
|
196 | handlePointRemoved(i); | |
|
197 | } | |
|
198 | else { | |
|
199 | // series uses model as a data source | |
|
200 | int mapFirst = m_series->modelMapper()->first(); | |
|
201 | int mapCount = m_series->modelMapper()->count(); | |
|
202 | int removedCount = end - start + 1; | |
|
203 | if (mapCount != -1 && start >= mapFirst + mapCount) { | |
|
204 | return; | |
|
205 | } | |
|
206 | else { | |
|
207 | int toRemove = qMin(m_points.size(), removedCount); // first find how many items can actually be removed | |
|
208 | int first = qMax(start, mapFirst);// get the index of the first item that will be removed. | |
|
209 | int last = qMin(first + toRemove - 1, m_points.size() + mapFirst - 1);// get the index of the last item that will be removed. | |
|
210 | if (last - first == 0) { | |
|
211 | for (int i = last; i >= first; i--) { | |
|
212 | handlePointRemoved(i - mapFirst); | |
|
213 | ||
|
214 | } | |
|
215 | } | |
|
216 | else { | |
|
217 | QVector<QPointF> points = m_points; | |
|
218 | for (int i = last; i >= first; i--) | |
|
219 | points.remove(i - mapFirst); | |
|
220 | setGeometryPoints(points); | |
|
221 | updateGeometry(); | |
|
222 | } | |
|
223 | if (mapCount != -1) { | |
|
224 | int itemsAvailable; // check how many are available to be added | |
|
225 | if (m_series->modelMapper()->orientation() == Qt::Vertical) | |
|
226 | itemsAvailable = m_series->model()->rowCount() - mapFirst - m_points.size(); | |
|
227 | else | |
|
228 | itemsAvailable = m_series->model()->columnCount() - mapFirst - m_points.size(); | |
|
229 | int toBeAdded = qMin(itemsAvailable, mapCount - m_points.size());// add not more items than there is space left to be filled. | |
|
230 | int currentSize = m_points.size(); | |
|
231 | if (toBeAdded > 0) | |
|
232 | for (int i = m_points.size(); i < currentSize + toBeAdded; i++) { | |
|
233 | handlePointAdded(i); | |
|
234 | } | |
|
235 | } | |
|
236 | } | |
|
237 | } | |
|
238 | ||
|
239 | } | |
|
240 | ||
|
241 | 153 | void XYChart::handlePointReplaced(int index) |
|
242 | 154 | { |
|
243 | 155 | Q_ASSERT(index<m_series->count()); |
@@ -53,9 +53,7 public: | |||
|
53 | 53 | |
|
54 | 54 | public Q_SLOTS: |
|
55 | 55 | void handlePointAdded(int index); |
|
56 | void handlePointsAdded(int start, int end); | |
|
57 | 56 | void handlePointRemoved(int index); |
|
58 | void handlePointsRemoved(int start, int end); | |
|
59 | 57 | void handlePointReplaced(int index); |
|
60 | 58 | void handleReinitialized(); |
|
61 | 59 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
@@ -49,7 +49,6 private slots: | |||
|
49 | 49 | void mouseclicked(); |
|
50 | 50 | void mousehovered_data(); |
|
51 | 51 | void mousehovered(); |
|
52 | void model(); | |
|
53 | 52 | |
|
54 | 53 | private: |
|
55 | 54 | QGroupedBarSeries* m_barseries; |
@@ -338,65 +337,6 void tst_QGroupedBarSeries::mousehovered() | |||
|
338 | 337 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
339 | 338 | } |
|
340 | 339 | |
|
341 | void tst_QGroupedBarSeries::model() | |
|
342 | { | |
|
343 | QGroupedBarSeries *series = new QGroupedBarSeries; | |
|
344 | QChart *chart = new QChart; | |
|
345 | chart->addSeries(series); | |
|
346 | QChartView *chartView = new QChartView(chart); | |
|
347 | chartView->show(); | |
|
348 | ||
|
349 | int rowCount = 12; | |
|
350 | int columnCount = 5; | |
|
351 | QStandardItemModel *stdModel = new QStandardItemModel(rowCount, columnCount); | |
|
352 | series->setModel(stdModel); | |
|
353 | QVERIFY2((series->model()) == stdModel, "Model should be stdModel"); | |
|
354 | ||
|
355 | ||
|
356 | for (int row = 0; row < rowCount; ++row) { | |
|
357 | for (int column = 0; column < columnCount; column++) { | |
|
358 | QStandardItem *item = new QStandardItem(row * column); | |
|
359 | stdModel->setItem(row, column, item); | |
|
360 | } | |
|
361 | } | |
|
362 | ||
|
363 | // data has been added to the model, but mapper is not set the number of slices should still be 0 | |
|
364 | QVERIFY2(series->barsetCount() == 0, "Mapper has not been set, so the number of slices should be 0"); | |
|
365 | ||
|
366 | // set the mapper | |
|
367 | QBarModelMapper *mapper = new QBarModelMapper; | |
|
368 | mapper->setMapCategories(0); | |
|
369 | mapper->setMapBarBottom(1); | |
|
370 | mapper->setMapBarTop(3); | |
|
371 | series->setModelMapper(mapper); // this should cause the Pie to get initialized from the model, since there is now both the model and the mapper defined | |
|
372 | QCOMPARE(series->barsetCount(), 3); | |
|
373 | ||
|
374 | // set the mappings to be outside of the model | |
|
375 | mapper->setMapBarBottom(6); | |
|
376 | mapper->setMapBarTop(7); | |
|
377 | QCOMPARE(series->barsetCount(), 0); // Mappings are invalid, so the number of slices should be 0 | |
|
378 | ||
|
379 | // set back to correct ones | |
|
380 | mapper->setMapBarBottom(1); | |
|
381 | mapper->setMapBarTop(3); | |
|
382 | QCOMPARE(series->barsetCount(), 3); | |
|
383 | ||
|
384 | // reset the mappings | |
|
385 | mapper->reset(); | |
|
386 | QCOMPARE(series->barsetCount(), 0); // Mappings have been reset and are invalid, so the number of slices should be 0 | |
|
387 | ||
|
388 | // unset the model and the mapper | |
|
389 | series->setModel(0); | |
|
390 | series->setModelMapper(0); | |
|
391 | QVERIFY(series->model() == 0); // Model should be unset | |
|
392 | QVERIFY(series->modelMapper() == 0); // Model mapper should be unset | |
|
393 | } | |
|
394 | ||
|
395 | /* | |
|
396 | bool setModel(QAbstractItemModel *model); | |
|
397 | void setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
|
398 | void setModelMappingRange(int first, int count = -1); | |
|
399 | */ | |
|
400 | 340 | QTEST_MAIN(tst_QGroupedBarSeries) |
|
401 | 341 | |
|
402 | 342 | #include "tst_qgroupedbarseries.moc" |
@@ -76,14 +76,6 class tst_QLineSeries : public QObject | |||
|
76 | 76 | void replace_chart(); |
|
77 | 77 | void replace_chart_animation_data(); |
|
78 | 78 | void replace_chart_animation(); |
|
79 | void setModel_data(); | |
|
80 | void setModel(); | |
|
81 | void setModelMapping_data(); | |
|
82 | void setModelMapping(); | |
|
83 | void setModelMappingRange_data(); | |
|
84 | void setModelMappingRange(); | |
|
85 | void modelUpdated(); | |
|
86 | void modelUpdatedCustomMapping(); | |
|
87 | 79 | private: |
|
88 | 80 | void append_data(); |
|
89 | 81 | void count_data(); |
@@ -453,189 +445,6 void tst_QLineSeries::replace_chart_animation() | |||
|
453 | 445 | replace_chart(); |
|
454 | 446 | } |
|
455 | 447 | |
|
456 | void tst_QLineSeries::setModel_data() | |
|
457 | { | |
|
458 | ||
|
459 | } | |
|
460 | ||
|
461 | void tst_QLineSeries::setModel() | |
|
462 | { | |
|
463 | QLineSeries series; | |
|
464 | series.setModel(0); | |
|
465 | QVERIFY2(series.model() == 0, "Model should be unset"); | |
|
466 | ||
|
467 | QStandardItemModel *stdModel = new QStandardItemModel(); | |
|
468 | series.setModel(stdModel); | |
|
469 | QVERIFY2((series.model()) == stdModel, "Model should be stdModel"); | |
|
470 | ||
|
471 | // unset the model | |
|
472 | series.setModel(0); | |
|
473 | QVERIFY2(series.model() == 0, "Model should be unset"); | |
|
474 | ||
|
475 | } | |
|
476 | ||
|
477 | Q_DECLARE_METATYPE(Qt::Orientation) | |
|
478 | void tst_QLineSeries::setModelMapping_data() | |
|
479 | { | |
|
480 | QTest::addColumn<int>("modelX"); | |
|
481 | QTest::addColumn<int>("modelY"); | |
|
482 | QTest::addColumn<Qt::Orientation>("orientation"); | |
|
483 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; | |
|
484 | QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; | |
|
485 | QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; | |
|
486 | ||
|
487 | QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; | |
|
488 | QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; | |
|
489 | QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; | |
|
490 | } | |
|
491 | ||
|
492 | void tst_QLineSeries::setModelMapping() | |
|
493 | { | |
|
494 | // QSKIP("Model mapping has been rewriten, test case needs update", SkipAll); | |
|
495 | ||
|
496 | QFETCH(int, modelX); | |
|
497 | QFETCH(int, modelY); | |
|
498 | QFETCH(Qt::Orientation, orientation); | |
|
499 | ||
|
500 | QLineSeries series; | |
|
501 | ||
|
502 | QXYModelMapper *mapper = new QXYModelMapper; | |
|
503 | mapper->setMapX(modelX); | |
|
504 | mapper->setMapY(modelY); | |
|
505 | mapper->setOrientation(orientation); | |
|
506 | ||
|
507 | QCOMPARE(mapper->mapX(), modelX); | |
|
508 | QCOMPARE(mapper->mapY(), modelY); | |
|
509 | QCOMPARE(mapper->orientation(), orientation); | |
|
510 | // QVERIFY2(mapper->orientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | |
|
511 | ||
|
512 | // series.setModelMapper(mapper); | |
|
513 | // // now let us set the model | |
|
514 | // series.setModel(new QStandardItemModel()); | |
|
515 | // series.setModelMapping(modelX, modelY, orientation); | |
|
516 | // QCOMPARE(series.mapX(), modelX); | |
|
517 | // QCOMPARE(series.mapY(), modelY); | |
|
518 | // QVERIFY2(series.mapOrientation() == orientation, "not good"); | |
|
519 | ||
|
520 | // // now let us remove the model, the values should go back to default ones. | |
|
521 | // series.setModel(0); | |
|
522 | // QCOMPARE(series.mapX(), -1); | |
|
523 | // QCOMPARE(series.mapY(), -1); | |
|
524 | // QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | |
|
525 | } | |
|
526 | ||
|
527 | void tst_QLineSeries::setModelMappingRange_data() | |
|
528 | { | |
|
529 | QTest::addColumn<int>("first"); | |
|
530 | QTest::addColumn<int>("count"); | |
|
531 | QTest::newRow("first: 0, count: unlimited") << 0 << -1; | |
|
532 | QTest::newRow("first: 0, count: 5") << 0 << 5; | |
|
533 | QTest::newRow("first: 3, count: unlimited") << 3 << -1; | |
|
534 | QTest::newRow("first: 3, count: 5") << 3 << 5; | |
|
535 | QTest::newRow("first: -3, count: 5") << -3 << 5; | |
|
536 | QTest::newRow("first: 3, count: -5") << 3 << -5; | |
|
537 | QTest::newRow("first: -3, count: -5") << 3 << -5; | |
|
538 | QTest::newRow("first: -3, count: 0") << -3 << 0; | |
|
539 | QTest::newRow("first: 0, count: -5") << 0 << -5; | |
|
540 | QTest::newRow("first: 0, count: 0") << 0 << 0; | |
|
541 | } | |
|
542 | ||
|
543 | void tst_QLineSeries::setModelMappingRange() | |
|
544 | { | |
|
545 | // QSKIP("Model mapping has been rewriten, test case needs update", SkipAll); | |
|
546 | ||
|
547 | QFETCH(int, first); | |
|
548 | QFETCH(int, count); | |
|
549 | QLineSeries series; | |
|
550 | ||
|
551 | QXYModelMapper *mapper = new QXYModelMapper; | |
|
552 | mapper->setMapX(0); | |
|
553 | mapper->setMapY(1); | |
|
554 | mapper->setFirst(first); | |
|
555 | mapper->setCount(count); | |
|
556 | ||
|
557 | QCOMPARE(mapper->first(), qMax(first, 0)); // regardles of what value was used in setFirst function, first should not be less than 0 | |
|
558 | QCOMPARE(mapper->count(), qMax(count, -1)); // regardles of what value was used setCount function, count should not be less than -1 | |
|
559 | ||
|
560 | QStandardItemModel *model = new QStandardItemModel(0, 2); | |
|
561 | series.setModel(model); | |
|
562 | series.setModelMapper(mapper); | |
|
563 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | |
|
564 | ||
|
565 | for (int row = 0; row < 3; ++row) { | |
|
566 | for (int column = 0; column < 2; column++) { | |
|
567 | QStandardItem *item = new QStandardItem(row * column); | |
|
568 | model->setItem(row, column, item); | |
|
569 | } | |
|
570 | } | |
|
571 | if (qMax(count, -1) != -1) | |
|
572 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0"); | |
|
573 | else | |
|
574 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | |
|
575 | ||
|
576 | // let's add few more rows to the model | |
|
577 | for (int row = 0; row < 10; ++row) { | |
|
578 | QList<QStandardItem *> newRow; | |
|
579 | for (int column = 0; column < 2; column++) { | |
|
580 | newRow.append(new QStandardItem(row * column)); | |
|
581 | } | |
|
582 | model->appendRow(newRow); | |
|
583 | } | |
|
584 | if (qMax(count, -1) != -1) | |
|
585 | QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0"); | |
|
586 | else | |
|
587 | QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | |
|
588 | ||
|
589 | // unset the model, values should be default | |
|
590 | series.setModel(0); | |
|
591 | // QCOMPARE(series.mapFirst(), 0); | |
|
592 | // QCOMPARE(series.mapCount(), -1); | |
|
593 | QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | |
|
594 | } | |
|
595 | ||
|
596 | void tst_QLineSeries::modelUpdated() | |
|
597 | { | |
|
598 | QSKIP("Model mapping has been rewriten, test case needs update", SkipAll); | |
|
599 | ||
|
600 | // QStandardItemModel *model = new QStandardItemModel; | |
|
601 | // for (int row = 0; row < 10; ++row) { | |
|
602 | // QList<QStandardItem *> newRow; | |
|
603 | // for (int column = 0; column < 2; column++) { | |
|
604 | // newRow.append(new QStandardItem(row * column)); | |
|
605 | // } | |
|
606 | // model->appendRow(newRow); | |
|
607 | // } | |
|
608 | ||
|
609 | // QLineSeries series; | |
|
610 | // series.setModel(model); | |
|
611 | // series.setModelMapping(0, 1); | |
|
612 | ||
|
613 | // model->setData(model->index(3, 1), 34); | |
|
614 | // // check that the update data is correctly taken from the model | |
|
615 | // QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34)); | |
|
616 | } | |
|
617 | ||
|
618 | void tst_QLineSeries::modelUpdatedCustomMapping() | |
|
619 | { | |
|
620 | QSKIP("Model mapping has been rewriten, test case needs update", SkipAll); | |
|
621 | // QStandardItemModel *model = new QStandardItemModel; | |
|
622 | // for (int row = 0; row < 10; ++row) { | |
|
623 | // QList<QStandardItem *> newRow; | |
|
624 | // for (int column = 0; column < 2; column++) { | |
|
625 | // newRow.append(new QStandardItem(row * column)); | |
|
626 | // } | |
|
627 | // model->appendRow(newRow); | |
|
628 | // } | |
|
629 | ||
|
630 | // QLineSeries series; | |
|
631 | // series.setModel(model); | |
|
632 | // series.setModelMapping(0, 1); | |
|
633 | // series.setModelMappingRange(3, 4); | |
|
634 | ||
|
635 | // model->setData(model->index(3, 1), 34); | |
|
636 | // QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34)); | |
|
637 | } | |
|
638 | ||
|
639 | 448 | QTEST_MAIN(tst_QLineSeries) |
|
640 | 449 | |
|
641 | 450 | #include "tst_qlineseries.moc" |
@@ -49,9 +49,6 private slots: | |||
|
49 | 49 | void calculatedValues(); |
|
50 | 50 | void clickedSignal(); |
|
51 | 51 | void hoverSignal(); |
|
52 | void model(); | |
|
53 | void modelCustomMap(); | |
|
54 | void modelUpdate(); | |
|
55 | 52 | |
|
56 | 53 | private: |
|
57 | 54 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
@@ -342,157 +339,6 void tst_qpieseries::hoverSignal() | |||
|
342 | 339 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); |
|
343 | 340 | } |
|
344 | 341 | |
|
345 | void tst_qpieseries::model() | |
|
346 | { | |
|
347 | QSKIP("Needs to be checked again. Model implementation changed", SkipAll); | |
|
348 | ||
|
349 | QPieSeries *series = new QPieSeries; | |
|
350 | QChart *chart = new QChart; | |
|
351 | chart->addSeries(series); | |
|
352 | QChartView *chartView = new QChartView(chart); | |
|
353 | chartView->show(); | |
|
354 | ||
|
355 | QStandardItemModel *stdModel = new QStandardItemModel(0, 2); | |
|
356 | series->setModel(stdModel); | |
|
357 | ||
|
358 | int rowCount = 3; | |
|
359 | for (int row = 0; row < rowCount; ++row) { | |
|
360 | for (int column = 0; column < 2; column++) { | |
|
361 | QStandardItem *item = new QStandardItem(row * column); | |
|
362 | stdModel->setItem(row, column, item); | |
|
363 | } | |
|
364 | } | |
|
365 | ||
|
366 | // data has been added to the model, but mapper is not set the number of slices should still be 0 | |
|
367 | QVERIFY2(series->slices().count() == 0, "Mapper has not been set, so the number of slices should be 0"); | |
|
368 | ||
|
369 | // set the mapper | |
|
370 | QPieModelMapper *mapper = series->modelMapper();//new QPieModelMapper; | |
|
371 | mapper->setMapValues(0); | |
|
372 | mapper->setMapLabels(0); | |
|
373 | // series->setModelMapper(mapper); // this should cause the Pie to get initialized from the model, since there is now both the model and the mapper defined | |
|
374 | QCOMPARE(series->slices().count(), rowCount); | |
|
375 | ||
|
376 | // set the mappings to be outside of the model | |
|
377 | mapper->setMapLabels(5); | |
|
378 | mapper->setMapValues(4); | |
|
379 | QCOMPARE(series->slices().count(), 0); // Mappings are invalid, so the number of slices should be 0 | |
|
380 | ||
|
381 | // set back to correct ones | |
|
382 | mapper->setMapValues(0); | |
|
383 | mapper->setMapLabels(0); | |
|
384 | QCOMPARE(series->slices().count(), rowCount); | |
|
385 | ||
|
386 | // reset the mappings | |
|
387 | mapper->reset(); | |
|
388 | QCOMPARE(series->slices().count(), 0); // Mappings have been reset and are invalid, so the number of slices should be 0 | |
|
389 | ||
|
390 | // unset the model and the mapper | |
|
391 | series->setModel(0); | |
|
392 | // series->setModelMapper(0); | |
|
393 | QVERIFY(series->model() == 0); // Model should be unset | |
|
394 | // QVERIFY(series->modelMapper() == 0); // Model mapper should be unset | |
|
395 | } | |
|
396 | ||
|
397 | void tst_qpieseries::modelCustomMap() | |
|
398 | { | |
|
399 | QSKIP("Needs to be checked again. Model implementation changed", SkipAll); | |
|
400 | ||
|
401 | int rowCount = 12; | |
|
402 | int columnCount = 3; | |
|
403 | QStandardItemModel *stdModel = new QStandardItemModel(0, 3); | |
|
404 | for (int row = 0; row < rowCount; ++row) { | |
|
405 | for (int column = 0; column < 2; column++) { | |
|
406 | QStandardItem *item = new QStandardItem(row * column); | |
|
407 | stdModel->setItem(row, column, item); | |
|
408 | } | |
|
409 | } | |
|
410 | ||
|
411 | QPieSeries *series = new QPieSeries; | |
|
412 | QChart *chart = new QChart; | |
|
413 | chart->addSeries(series); | |
|
414 | QChartView *chartView = new QChartView(chart); | |
|
415 | chartView->show(); | |
|
416 | series->setModel(stdModel); | |
|
417 | ||
|
418 | QPieModelMapper *mapper = series->modelMapper();//new QPieModelMapper; | |
|
419 | mapper->setMapValues(0); | |
|
420 | mapper->setMapLabels(0); | |
|
421 | // series->setModelMapper(mapper); | |
|
422 | QCOMPARE(series->slices().count(), rowCount); | |
|
423 | ||
|
424 | // lets change the orientation to horizontal | |
|
425 | mapper->setOrientation(Qt::Horizontal); | |
|
426 | QCOMPARE(series->slices().count(), columnCount); | |
|
427 | ||
|
428 | // change it back to vertical | |
|
429 | mapper->setOrientation(Qt::Vertical); | |
|
430 | QCOMPARE(series->slices().count(), rowCount); | |
|
431 | ||
|
432 | // lets customize the mapping | |
|
433 | int first = 3; | |
|
434 | mapper->setFirst(first); | |
|
435 | QCOMPARE(series->slices().count(), rowCount - first); | |
|
436 | int count = 7; | |
|
437 | mapper->setCount(count); | |
|
438 | QCOMPARE(series->slices().count(), count); | |
|
439 | first = 9; | |
|
440 | mapper->setFirst(first); | |
|
441 | QCOMPARE(series->slices().count(), qMin(count, rowCount - first)); | |
|
442 | } | |
|
443 | ||
|
444 | void tst_qpieseries::modelUpdate() | |
|
445 | { | |
|
446 | QSKIP("Needs to be checked again. Model implementation changed", SkipAll); | |
|
447 | ||
|
448 | int rowCount = 12; | |
|
449 | int columnCount = 7; | |
|
450 | QStandardItemModel *stdModel = new QStandardItemModel(rowCount, columnCount); | |
|
451 | for (int row = 0; row < rowCount; ++row) { | |
|
452 | for (int column = 0; column < columnCount; column++) { | |
|
453 | QStandardItem *item = new QStandardItem(row * column); | |
|
454 | stdModel->setItem(row, column, item); | |
|
455 | } | |
|
456 | } | |
|
457 | ||
|
458 | QPieSeries *series = new QPieSeries; | |
|
459 | QChart *chart = new QChart; | |
|
460 | chart->addSeries(series); | |
|
461 | QChartView *chartView = new QChartView(chart); | |
|
462 | chartView->show(); | |
|
463 | series->setModel(stdModel); | |
|
464 | ||
|
465 | QPieModelMapper *mapper = series->modelMapper();//new QPieModelMapper; | |
|
466 | mapper->setMapValues(0); | |
|
467 | mapper->setMapLabels(0); | |
|
468 | // series->setModelMapper(mapper); | |
|
469 | ||
|
470 | stdModel->insertRows(3, 5); | |
|
471 | QCOMPARE(series->slices().count(), rowCount + 5); | |
|
472 | ||
|
473 | stdModel->removeRows(10, 5); | |
|
474 | QCOMPARE(series->slices().count(), rowCount); | |
|
475 | ||
|
476 | // limit the number of slices taken from the model to 12 | |
|
477 | mapper->setCount(rowCount); | |
|
478 | stdModel->insertRows(3, 5); | |
|
479 | QCOMPARE(series->slices().count(), rowCount); | |
|
480 | ||
|
481 | stdModel->removeRows(0, 10); | |
|
482 | QCOMPARE(series->slices().count(), rowCount - 5); | |
|
483 | ||
|
484 | // change the orientation to horizontal | |
|
485 | mapper->setOrientation(Qt::Horizontal); | |
|
486 | QCOMPARE(series->slices().count(), columnCount); | |
|
487 | ||
|
488 | stdModel->insertColumns(3, 10); | |
|
489 | QCOMPARE(series->slices().count(), rowCount); // count is limited to rowCount (12) | |
|
490 | ||
|
491 | stdModel->removeColumns(5, 10); | |
|
492 | QCOMPARE(series->slices().count(), columnCount); | |
|
493 | ||
|
494 | } | |
|
495 | ||
|
496 | 342 | QTEST_MAIN(tst_qpieseries) |
|
497 | 343 | |
|
498 | 344 | #include "tst_qpieseries.moc" |
@@ -174,130 +174,130 void TableWidget::updateChartType(bool toggle) | |||
|
174 | 174 | if (toggle) { |
|
175 | 175 | // specialPie = 0; |
|
176 | 176 | m_chart->removeAllSeries(); |
|
177 | m_chart->axisX()->setNiceNumbersEnabled(false); | |
|
178 | m_chart->axisY()->setNiceNumbersEnabled(false); | |
|
177 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
|
178 | // m_chart->axisY()->setNiceNumbersEnabled(false); | |
|
179 | 179 | |
|
180 | // renable axes of the chart (pie hides them) | |
|
181 | // x axis | |
|
182 | QAxis *axis = m_chart->axisX(); | |
|
183 | axis->setAxisVisible(true); | |
|
184 | axis->setGridLineVisible(true); | |
|
185 | axis->setLabelsVisible(true); | |
|
180 | // // renable axes of the chart (pie hides them) | |
|
181 | // // x axis | |
|
182 | // QAxis *axis = m_chart->axisX(); | |
|
183 | // axis->setAxisVisible(true); | |
|
184 | // axis->setGridLineVisible(true); | |
|
185 | // axis->setLabelsVisible(true); | |
|
186 | 186 | |
|
187 | // y axis | |
|
188 | axis = m_chart->axisY(); | |
|
189 | axis->setAxisVisible(true); | |
|
190 | axis->setGridLineVisible(true); | |
|
191 | axis->setLabelsVisible(true); | |
|
187 | // // y axis | |
|
188 | // axis = m_chart->axisY(); | |
|
189 | // axis->setAxisVisible(true); | |
|
190 | // axis->setGridLineVisible(true); | |
|
191 | // axis->setLabelsVisible(true); | |
|
192 | 192 | |
|
193 | m_model->clearMapping(); | |
|
193 | // m_model->clearMapping(); | |
|
194 | 194 | |
|
195 | 195 | QString seriesColorHex = "#000000"; |
|
196 | QPen pen; | |
|
197 | pen.setWidth(2); | |
|
196 | // QPen pen; | |
|
197 | // pen.setWidth(2); | |
|
198 | 198 | |
|
199 | 199 | if (m_lineRadioButton->isChecked()) |
|
200 | 200 | { |
|
201 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
|
202 | ||
|
203 | // series 1 | |
|
204 | m_series = new QLineSeries; | |
|
205 | m_series->setModel(m_model); | |
|
206 | ||
|
207 | QXYModelMapper *mapper = new QXYModelMapper; | |
|
208 | mapper->setMapX(0); | |
|
209 | mapper->setMapY(1); | |
|
210 | mapper->setFirst(3); | |
|
211 | mapper->setCount(4); | |
|
212 | m_series->setModelMapper(mapper); | |
|
213 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
|
214 | // m_series->setModelMappingRange(3, 4); | |
|
215 | m_chart->addSeries(m_series); | |
|
216 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
217 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
|
218 | ||
|
219 | // series 2 | |
|
220 | m_series = new QLineSeries; | |
|
221 | m_series->setModel(m_model); | |
|
222 | ||
|
223 | mapper = new QXYModelMapper; | |
|
224 | mapper->setMapX(3); | |
|
225 | mapper->setMapY(4); | |
|
201 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
|
202 | ||
|
203 | // // series 1 | |
|
204 | // m_series = new QLineSeries; | |
|
205 | // m_series->setModel(m_model); | |
|
206 | ||
|
207 | // QXYModelMapper *mapper = new QXYModelMapper; | |
|
208 | // mapper->setMapX(0); | |
|
209 | // mapper->setMapY(1); | |
|
226 | 210 | // mapper->setFirst(3); |
|
227 | 211 | // mapper->setCount(4); |
|
228 | m_series->setModelMapper(mapper); | |
|
229 |
// m_series->setModelMapping( |
|
|
230 | m_chart->addSeries(m_series); | |
|
231 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
232 | m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
|
233 | ||
|
234 | // series 3 | |
|
235 | m_series = new QLineSeries; | |
|
236 | m_series->setModel(m_model); | |
|
237 | ||
|
238 | mapper = new QXYModelMapper; | |
|
239 | mapper->setMapX(5); | |
|
240 |
mapper->setMap |
|
|
241 |
mapper->set |
|
|
242 | mapper->setCount(-1); | |
|
243 | m_series->setModelMapper(mapper); | |
|
244 |
// m_series->setModelMapp |
|
|
245 |
// m_series->setModelMapping |
|
|
246 | m_chart->addSeries(m_series); | |
|
247 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
248 |
m_model->addMapping(seriesColorHex, QRect( |
|
|
212 | // m_series->setModelMapper(mapper); | |
|
213 | // // m_series->setModelMapping(0,1, Qt::Vertical); | |
|
214 | // // m_series->setModelMappingRange(3, 4); | |
|
215 | // m_chart->addSeries(m_series); | |
|
216 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
217 | // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
|
218 | ||
|
219 | // // series 2 | |
|
220 | // m_series = new QLineSeries; | |
|
221 | // m_series->setModel(m_model); | |
|
222 | ||
|
223 | // mapper = new QXYModelMapper; | |
|
224 | // mapper->setMapX(3); | |
|
225 | // mapper->setMapY(4); | |
|
226 | // // mapper->setFirst(3); | |
|
227 | // // mapper->setCount(4); | |
|
228 | // m_series->setModelMapper(mapper); | |
|
229 | // // m_series->setModelMapping(2,3, Qt::Vertical); | |
|
230 | // m_chart->addSeries(m_series); | |
|
231 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
232 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
|
233 | ||
|
234 | // // series 3 | |
|
235 | // m_series = new QLineSeries; | |
|
236 | // m_series->setModel(m_model); | |
|
237 | ||
|
238 | // mapper = new QXYModelMapper; | |
|
239 | // mapper->setMapX(5); | |
|
240 | // mapper->setMapY(6); | |
|
241 | // mapper->setFirst(2); | |
|
242 | // mapper->setCount(-1); | |
|
243 | // m_series->setModelMapper(mapper); | |
|
244 | // // m_series->setModelMapping(4,5, Qt::Vertical); | |
|
245 | // // m_series->setModelMappingRange(2, -1); | |
|
246 | // m_chart->addSeries(m_series); | |
|
247 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
248 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | |
|
249 | 249 | } |
|
250 | 250 | else if (m_splineRadioButton->isChecked()) |
|
251 | 251 | { |
|
252 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
|
252 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
|
253 | 253 | |
|
254 | // series 1 | |
|
255 | m_series = new QSplineSeries; | |
|
256 | m_series->setModel(m_model); | |
|
254 | // // series 1 | |
|
255 | // m_series = new QSplineSeries; | |
|
256 | // m_series->setModel(m_model); | |
|
257 | 257 | |
|
258 | QXYModelMapper *mapper = new QXYModelMapper; | |
|
259 | mapper->setMapX(0); | |
|
260 | mapper->setMapY(1); | |
|
261 | mapper->setFirst(0); | |
|
262 | mapper->setCount(-1); | |
|
258 | // QXYModelMapper *mapper = new QXYModelMapper; | |
|
259 | // mapper->setMapX(0); | |
|
260 | // mapper->setMapY(1); | |
|
261 | // mapper->setFirst(0); | |
|
262 | // mapper->setCount(-1); | |
|
263 | 263 | |
|
264 | m_series->setModelMapper(mapper); | |
|
264 | // m_series->setModelMapper(mapper); | |
|
265 | 265 | |
|
266 | m_chart->addSeries(m_series); | |
|
267 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
268 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
|
266 | // m_chart->addSeries(m_series); | |
|
267 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
268 | // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
|
269 | 269 | |
|
270 | // series 2 | |
|
271 | m_series = new QSplineSeries; | |
|
272 | m_series->setModel(m_model); | |
|
270 | // // series 2 | |
|
271 | // m_series = new QSplineSeries; | |
|
272 | // m_series->setModel(m_model); | |
|
273 | 273 | |
|
274 | mapper = new QXYModelMapper; | |
|
275 | mapper->setMapX(2); | |
|
276 | mapper->setMapY(3); | |
|
277 | mapper->setFirst(2); | |
|
278 | mapper->setCount(4); | |
|
274 | // mapper = new QXYModelMapper; | |
|
275 | // mapper->setMapX(2); | |
|
276 | // mapper->setMapY(3); | |
|
277 | // mapper->setFirst(2); | |
|
278 | // mapper->setCount(4); | |
|
279 | 279 | |
|
280 | m_series->setModelMapper(mapper); | |
|
280 | // m_series->setModelMapper(mapper); | |
|
281 | 281 | |
|
282 | m_chart->addSeries(m_series); | |
|
283 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
284 | m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
|
282 | // m_chart->addSeries(m_series); | |
|
283 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
284 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
|
285 | 285 | |
|
286 | // series 3 | |
|
287 | m_series = new QSplineSeries; | |
|
288 | m_series->setModel(m_model); | |
|
286 | // // series 3 | |
|
287 | // m_series = new QSplineSeries; | |
|
288 | // m_series->setModel(m_model); | |
|
289 | 289 | |
|
290 | mapper = new QXYModelMapper; | |
|
291 | mapper->setMapX(4); | |
|
292 | mapper->setMapY(5); | |
|
293 | mapper->setFirst(2); | |
|
294 | mapper->setCount(-1); | |
|
290 | // mapper = new QXYModelMapper; | |
|
291 | // mapper->setMapX(4); | |
|
292 | // mapper->setMapY(5); | |
|
293 | // mapper->setFirst(2); | |
|
294 | // mapper->setCount(-1); | |
|
295 | 295 | |
|
296 | m_series->setModelMapper(mapper); | |
|
296 | // m_series->setModelMapper(mapper); | |
|
297 | 297 | |
|
298 | m_chart->addSeries(m_series); | |
|
299 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
300 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
|
298 | // m_chart->addSeries(m_series); | |
|
299 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
|
300 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
|
301 | 301 | } |
|
302 | 302 | // else if (m_scatterRadioButton->isChecked()) |
|
303 | 303 | // { |
@@ -340,13 +340,14 void TableWidget::updateChartType(bool toggle) | |||
|
340 | 340 | |
|
341 | 341 |
|
|
342 | 342 |
|
|
343 | pieSeries->setModel(m_model); | |
|
344 | 343 | |
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
|
349 |
|
|
|
344 | m_pieMapper = new QPieModelMapper; | |
|
345 | m_pieMapper->setValuesIndex(1); | |
|
346 | m_pieMapper->setLabelsIndex(1); | |
|
347 | m_pieMapper->setSeries(pieSeries); | |
|
348 | m_pieMapper->setModel(m_model); | |
|
349 | m_pieMapper->setFirst(2); | |
|
350 | m_pieMapper->setCount(5); | |
|
350 | 351 | // pieSeries->setModelMapper(mapper); |
|
351 | 352 | |
|
352 | 353 |
|
@@ -359,8 +360,8 void TableWidget::updateChartType(bool toggle) | |||
|
359 | 360 |
|
|
360 | 361 | |
|
361 | 362 | |
|
362 | pieSeries->slices().at(0)->setValue(400); | |
|
363 | pieSeries->slices().at(0)->setLabel(QString("36")); | |
|
363 | // pieSeries->slices().at(0)->setValue(400); | |
|
364 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
|
364 | 365 | |
|
365 | 366 | // // pie 2 |
|
366 | 367 | // pieSeries = new QPieSeries; |
@@ -421,25 +422,25 void TableWidget::updateChartType(bool toggle) | |||
|
421 | 422 | // } |
|
422 | 423 |
|
|
423 | 424 |
|
|
424 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
|
425 | ||
|
426 | QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
|
427 | barSeries->setCategories(QStringList()); | |
|
428 | barSeries->setModel(m_model); | |
|
429 | // barSeries->setModelMappingRange(2, 5); | |
|
430 | // barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
|
431 | ||
|
432 | QBarModelMapper *mapper = new QBarModelMapper; | |
|
433 | mapper->setMapCategories(5); | |
|
434 | mapper->setMapBarBottom(2); | |
|
435 | mapper->setMapBarTop(4); | |
|
436 | barSeries->setModelMapper(mapper); | |
|
437 | m_chart->addSeries(barSeries); | |
|
438 | QList<QBarSet*> barsets = barSeries->barSets(); | |
|
439 | for (int i = 0; i < barsets.count(); i++) { | |
|
440 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
441 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
|
442 | } | |
|
425 | // m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
|
426 | ||
|
427 | // QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
|
428 | // barSeries->setCategories(QStringList()); | |
|
429 | // barSeries->setModel(m_model); | |
|
430 | // // barSeries->setModelMappingRange(2, 5); | |
|
431 | //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
|
432 | ||
|
433 | // QBarModelMapper *mapper = new QBarModelMapper; | |
|
434 | // mapper->setMapCategories(5); | |
|
435 | // mapper->setMapBarBottom(2); | |
|
436 | // mapper->setMapBarTop(4); | |
|
437 | // barSeries->setModelMapper(mapper); | |
|
438 | // m_chart->addSeries(barSeries); | |
|
439 | // QList<QBarSet*> barsets = barSeries->barSets(); | |
|
440 | // for (int i = 0; i < barsets.count(); i++) { | |
|
441 | // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
|
442 | // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |
|
443 | // } | |
|
443 | 444 |
|
|
444 | 445 | |
|
445 | 446 | |
@@ -457,6 +458,7 void TableWidget::updateChartType(bool toggle) | |||
|
457 | 458 | |
|
458 | 459 | void TableWidget::testPie() |
|
459 | 460 | { |
|
461 | m_pieMapper->setCount(-1); | |
|
460 | 462 | // m_series->modelMapper()->setMapX(4); |
|
461 | 463 | // m_tableView->setColumnWidth(10, 250); |
|
462 | 464 | // if (specialPie) { |
@@ -26,6 +26,7 | |||
|
26 | 26 | #include "qchartview.h" |
|
27 | 27 | //#include "qxyseries.h" |
|
28 | 28 | //#include <QPieSeries> |
|
29 | #include <QPieModelMapper> | |
|
29 | 30 | |
|
30 | 31 | class CustomTableModel; |
|
31 | 32 | class QTableView; |
@@ -65,6 +66,7 public: | |||
|
65 | 66 | QRadioButton* m_areaRadioButton; |
|
66 | 67 | QRadioButton* m_barRadioButton; |
|
67 | 68 | QSpinBox* m_linesCountSpinBox; |
|
69 | QPieModelMapper *m_pieMapper; | |
|
68 | 70 | // QPieSeries* specialPie; |
|
69 | 71 | }; |
|
70 | 72 |
General Comments 0
You need to be logged in to leave comments.
Login now