##// END OF EJS Templates
All model related methods and members removed from the series. QML stuff commented out where complaining
Marek Rosa -
r1230:39fc8bad4e45
parent child
Show More
@@ -52,48 +52,47 TableWidget::TableWidget(QWidget *parent)
52 chart->setAnimationOptions(QChart::AllAnimations);
52 chart->setAnimationOptions(QChart::AllAnimations);
53 //! [3]
53 //! [3]
54
54
55 // series 1
55 // // series 1
56 //! [4]
56 // //! [4]
57 QLineSeries *series = new QLineSeries;
57 // QLineSeries *series = new QLineSeries;
58 series->setName("line1");
58 // series->setModel(model);
59 series->setModel(model);
60
59
61 QXYModelMapper *mapper = new QXYModelMapper;
60 // QXYModelMapper *mapper = new QXYModelMapper;
62 mapper->setMapX(0);
61 // mapper->setMapX(0);
63 mapper->setMapY(1);
62 // mapper->setMapY(1);
64 series->setModelMapper(mapper);
63 // series->setModelMapper(mapper);
65 // series->setModelMapping(0, 1, Qt::Vertical);
64 //// series->setModelMapping(0, 1, Qt::Vertical);
66 chart->addSeries(series);
65 // chart->addSeries(series);
67 //! [4]
66 // //! [4]
68
67
69 //! [5]
68 // //! [5]
70 // for storing color hex from the series
69 // // for storing color hex from the series
71 QString seriesColorHex = "#000000";
70 // QString seriesColorHex = "#000000";
72
71
73 // get the color of the series and use it for showing the mapped area
72 // // 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();
73 // seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
75 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
74 // model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
76 //! [5]
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;
78 // // series 2
85 mapper->setMapX(2);
79 // //! [6]
86 mapper->setMapY(3);
80 // series = new QLineSeries;
87 series->setModelMapper(mapper);
81 // series->setModel(model);
88 // series->setModelMapping(2,3, Qt::Vertical);
89 chart->addSeries(series);
90 //! [6]
91
82
92 //! [7]
83 // mapper = new QXYModelMapper;
93 // get the color of the series and use it for showing the mapped area
84 // mapper->setMapX(2);
94 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
85 // mapper->setMapY(3);
95 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
86 // series->setModelMapper(mapper);
96 //! [7]
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 //! [8]
97 //! [8]
99 QChartView *chartView = new QChartView(chart);
98 QChartView *chartView = new QChartView(chart);
@@ -76,7 +76,7 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model)
76 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
76 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
77 bool value(false);
77 bool value(false);
78 if (m) {
78 if (m) {
79 setModel(m);
79 // setModel(m);
80 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
80 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
81 // setModelMapping(0, 1, 1, Qt::Vertical);
81 // setModelMapping(0, 1, 1, Qt::Vertical);
82 } else {
82 } else {
@@ -87,7 +87,7 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model)
87
87
88 DeclarativeTableModel *DeclarativeBarSeries::declarativeModel()
88 DeclarativeTableModel *DeclarativeBarSeries::declarativeModel()
89 {
89 {
90 return qobject_cast<DeclarativeTableModel *>(model());
90 return 0;//qobject_cast<DeclarativeTableModel *>(model());
91 }
91 }
92
92
93 void DeclarativeBarSeries::setBarCategories(QStringList categories)
93 void DeclarativeBarSeries::setBarCategories(QStringList categories)
@@ -128,7 +128,7 bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *mod
128 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
128 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
129 bool value(false);
129 bool value(false);
130 if (m) {
130 if (m) {
131 setModel(m);
131 // setModel(m);
132 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
132 //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical);
133 // setModelMapping(0, 1, 1, Qt::Vertical);
133 // setModelMapping(0, 1, 1, Qt::Vertical);
134 } else {
134 } else {
@@ -139,7 +139,7 bool DeclarativeGroupedBarSeries::setDeclarativeModel(DeclarativeTableModel *mod
139
139
140 DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel()
140 DeclarativeTableModel *DeclarativeGroupedBarSeries::declarativeModel()
141 {
141 {
142 return qobject_cast<DeclarativeTableModel *>(model());
142 return 0; //qobject_cast<DeclarativeTableModel *>(model());
143 }
143 }
144
144
145 void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories)
145 void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories)
@@ -88,7 +88,7 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
88 {
88 {
89 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
89 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
90 if (m) {
90 if (m) {
91 QPieSeries::setModel(m);
91 // QPieSeries::setModel(m);
92 } else {
92 } else {
93 qWarning("DeclarativePieSeries: Illegal model");
93 qWarning("DeclarativePieSeries: Illegal model");
94 }
94 }
@@ -96,7 +96,7 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
96
96
97 DeclarativeTableModel *DeclarativePieSeries::pieModel()
97 DeclarativeTableModel *DeclarativePieSeries::pieModel()
98 {
98 {
99 return qobject_cast<DeclarativeTableModel *>(model());
99 return 0;//qobject_cast<DeclarativeTableModel *>(model());
100 }
100 }
101
101
102 #include "moc_declarativepieseries.cpp"
102 #include "moc_declarativepieseries.cpp"
@@ -38,7 +38,7 DeclarativeXySeries::DeclarativeXySeries()
38 mapper->setFirst(0);
38 mapper->setFirst(0);
39 mapper->setCount(-1);
39 mapper->setCount(-1);
40 mapper->setOrientation(Qt::Vertical);
40 mapper->setOrientation(Qt::Vertical);
41 series->setModelMapper(mapper);
41 // series->setModelMapper(mapper);
42 }
42 }
43
43
44 DeclarativeXySeries::~DeclarativeXySeries()
44 DeclarativeXySeries::~DeclarativeXySeries()
@@ -51,8 +51,8 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model)
51 bool value(false);
51 bool value(false);
52 if (m) {
52 if (m) {
53 // All the inherited objects must be of type QXYSeries, so it is safe to cast
53 // All the inherited objects must be of type QXYSeries, so it is safe to cast
54 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
54 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
55 series->setModel(m);
55 // series->setModel(m);
56 } else {
56 } else {
57 qWarning("DeclarativeXySeries: Illegal model");
57 qWarning("DeclarativeXySeries: Illegal model");
58 }
58 }
@@ -62,8 +62,8 bool DeclarativeXySeries::setDeclarativeModel(DeclarativeTableModel *model)
62 DeclarativeTableModel *DeclarativeXySeries::declarativeModel()
62 DeclarativeTableModel *DeclarativeXySeries::declarativeModel()
63 {
63 {
64 // All the inherited objects must be of type QXYSeries, so it is safe to cast
64 // All the inherited objects must be of type QXYSeries, so it is safe to cast
65 QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
65 // QXYSeries *series = reinterpret_cast<QXYSeries *>(this);
66 return qobject_cast<DeclarativeTableModel *>(series->model());
66 return 0; //qobject_cast<DeclarativeTableModel *>(series->model());
67 }
67 }
68
68
69 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
@@ -207,25 +207,6 bool QAreaSeries::pointsVisible() const
207 return d->m_pointsVisible;
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 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
212 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
@@ -55,9 +55,6 public:
55 void setPointsVisible(bool visible = true);
55 void setPointsVisible(bool visible = true);
56 bool pointsVisible() const;
56 bool pointsVisible() const;
57
57
58 void setModel(QAbstractItemModel* model);
59 QAbstractItemModel* model() const;
60
61 Q_SIGNALS:
58 Q_SIGNALS:
62 void clicked(const QPointF &point);
59 void clicked(const QPointF &point);
63 void selected();
60 void selected();
@@ -28,10 +28,6
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 #include <QAbstractItemModel>
32 #include <QModelIndex>
33 #include <QBarModelMapper>
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
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 Returns the bar categories of the series.
220 Returns the bar categories of the series.
285 */
221 */
286 QBarCategories QBarSeries::categories() const
222 QBarCategories QBarSeries::categories() const
@@ -303,8 +239,7 void QBarSeries::setLabelsVisible(bool visible)
303
239
304 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
240 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
305 QAbstractSeriesPrivate(q),
241 QAbstractSeriesPrivate(q),
306 m_barMargin(0.05), // Default value is 5% of category width
242 m_barMargin(0.05) // Default value is 5% of category width
307 m_mapper(0)
308 {
243 {
309 }
244 }
310
245
@@ -492,112 +427,6 qreal QBarSeriesPrivate::maxCategorySum()
492 return max;
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 void QBarSeriesPrivate::barsetChanged()
430 void QBarSeriesPrivate::barsetChanged()
602 {
431 {
603 emit updatedBars();
432 emit updatedBars();
@@ -24,8 +24,6
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 class QModelIndex;
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
28
31 typedef QStringList QBarCategories;
29 typedef QStringList QBarCategories;
@@ -33,7 +31,6 typedef QStringList QBarCategories;
33 class QBarSet;
31 class QBarSet;
34 class BarCategory;
32 class BarCategory;
35 class QBarSeriesPrivate;
33 class QBarSeriesPrivate;
36 class QBarModelMapper;
37
34
38 // Container for series
35 // Container for series
39 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
36 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
@@ -57,10 +54,6 public:
57
54
58 void setLabelsVisible(bool visible = true);
55 void setLabelsVisible(bool visible = true);
59
56
60 void setModel(QAbstractItemModel *model);
61 void setModelMapper(QBarModelMapper *mapper);
62 QBarModelMapper* modelMapper() const;
63
64 protected:
57 protected:
65 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
58 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
66
59
@@ -6,8 +6,6
6 #include <QStringList>
6 #include <QStringList>
7 #include <QAbstractSeries>
7 #include <QAbstractSeries>
8
8
9 class QModelIndex;
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
10
13 class QBarModelMapper;
11 class QBarModelMapper;
@@ -48,21 +46,12 Q_SIGNALS:
48 void categoriesUpdated();
46 void categoriesUpdated();
49
47
50 private Q_SLOTS:
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 void barsetChanged();
49 void barsetChanged();
57
50
58 protected:
51 protected:
59 QList<QBarSet *> m_barSets;
52 QList<QBarSet *> m_barSets;
60 QBarCategories m_categories;
53 QBarCategories m_categories;
61 qreal m_barMargin;
54 qreal m_barMargin;
62 int m_mapCategories;
63 int m_mapBarBottom;
64 int m_mapBarTop;
65 QBarModelMapper *m_mapper;
66 private:
55 private:
67 Q_DECLARE_PUBLIC(QBarSeries)
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 int QPieModelMapper::first() const
65 int QPieModelMapper::first() const
16 {
66 {
17 Q_D(const QPieModelMapper);
67 Q_D(const QPieModelMapper);
@@ -22,6 +72,7 void QPieModelMapper::setFirst(int first)
22 {
72 {
23 Q_D(QPieModelMapper);
73 Q_D(QPieModelMapper);
24 d->m_first = qMax(first, 0);
74 d->m_first = qMax(first, 0);
75 d->initializePieFromModel();
25 // emit updated();
76 // emit updated();
26 }
77 }
27
78
@@ -35,6 +86,7 void QPieModelMapper::setCount(int count)
35 {
86 {
36 Q_D(QPieModelMapper);
87 Q_D(QPieModelMapper);
37 d->m_count = qMax(count, -1);
88 d->m_count = qMax(count, -1);
89 d->initializePieFromModel();
38 // emit updated();
90 // emit updated();
39 }
91 }
40
92
@@ -48,32 +100,35 void QPieModelMapper::setOrientation(Qt::Orientation orientation)
48 {
100 {
49 Q_D(QPieModelMapper);
101 Q_D(QPieModelMapper);
50 d->m_orientation = orientation;
102 d->m_orientation = orientation;
103 d->initializePieFromModel();
51 // emit updated();
104 // emit updated();
52 }
105 }
53
106
54 int QPieModelMapper::mapValues() const
107 int QPieModelMapper::valuesIndex() const
55 {
108 {
56 Q_D(const QPieModelMapper);
109 Q_D(const QPieModelMapper);
57 return d->m_mapValues;
110 return d->m_valuesIndex;
58 }
111 }
59
112
60 void QPieModelMapper::setMapValues(int mapValues)
113 void QPieModelMapper::setValuesIndex(int mapValues)
61 {
114 {
62 Q_D(QPieModelMapper);
115 Q_D(QPieModelMapper);
63 d->m_mapValues = mapValues;
116 d->m_valuesIndex = mapValues;
117 d->initializePieFromModel();
64 // emit updated();
118 // emit updated();
65 }
119 }
66
120
67 int QPieModelMapper::mapLabels() const
121 int QPieModelMapper::labelsIndex() const
68 {
122 {
69 Q_D(const QPieModelMapper);
123 Q_D(const QPieModelMapper);
70 return d->m_mapLabels;
124 return d->m_labelsIndex;
71 }
125 }
72
126
73 void QPieModelMapper::setMapLabels(int mapLabels)
127 void QPieModelMapper::setLabelsIndex(int mapLabels)
74 {
128 {
75 Q_D(QPieModelMapper);
129 Q_D(QPieModelMapper);
76 d->m_mapLabels = mapLabels;
130 d->m_labelsIndex = mapLabels;
131 d->initializePieFromModel();
77 // emit updated();
132 // emit updated();
78 }
133 }
79
134
@@ -83,8 +138,8 void QPieModelMapper::reset()
83 d->m_first = 0;
138 d->m_first = 0;
84 d->m_count = -1;
139 d->m_count = -1;
85 d->m_orientation = Qt::Vertical;
140 d->m_orientation = Qt::Vertical;
86 d->m_mapValues = -1;
141 d->m_valuesIndex = -1;
87 d->m_mapLabels = -1;
142 d->m_labelsIndex = -1;
88 // emit updated();
143 // emit updated();
89 }
144 }
90
145
@@ -93,38 +148,48 void QPieModelMapper::reset()
93 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
148 QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) :
94 q_ptr(q)
149 q_ptr(q)
95 {
150 {
151 m_series = 0;
152 m_model = 0;
96 m_first = 0;
153 m_first = 0;
97 m_count = -1;
154 m_count = -1;
98 m_orientation = Qt::Vertical;
155 m_orientation = Qt::Vertical;
99 m_mapValues = -1;
156 m_valuesIndex = -1;
100 m_mapLabels = -1;
157 m_labelsIndex = -1;
101 }
158 }
102
159
103 int QPieModelMapperPrivate::getSliceIndex()
104 {
105
160
106 // invalid
161 QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const
107 return -1;
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 void QPieModelMapperPrivate::setModel(QAbstractItemModel *model)
173 QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos)
111 {
174 {
112 if (model == 0)
175 if (m_count != -1 && slicePos >= m_count)
113 return;
176 return QModelIndex(); // invalid
114
177
115 if(m_model)
178 if (m_orientation == Qt::Vertical)
116 {
179 return m_model->index(slicePos + m_first, m_valuesIndex);
117 // disconnect signals from old model
180 else
118 disconnect(m_model, 0, this, 0);
181 return m_model->index(m_valuesIndex, slicePos + m_first);
119 }
182 }
120
183
121 m_model = model;
184 QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos)
122 // connect signals from the model
185 {
123 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex)));
186 if (m_count != -1 && slicePos >= m_count)
124 connect(m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelRowsAdded(QModelIndex,int,int)));
187 return QModelIndex(); // invalid
125 connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelRowsRemoved(QModelIndex,int,int)));
188
126 connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelColumnsAdded(QModelIndex,int,int)));
189 if (m_orientation == Qt::Vertical)
127 connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
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 void QPieModelMapperPrivate::slicesAdded()
195 void QPieModelMapperPrivate::slicesAdded()
@@ -144,151 +209,168 void QPieModelMapperPrivate::sliceChanged()
144
209
145 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
210 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
146 {
211 {
212 QModelIndex index;
213 QPieSlice *slice;
147 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
214 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
148 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
215 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
149 if (m_orientation == Qt::Vertical)
216 index = topLeft.sibling(row, column);
150 {
217 slice = pieSlice(index);
151 if ( topLeft.row() >= m_first && (m_count == - 1 || topLeft.row() < m_first + m_count)) {
218 if (slice) {
152 if (topLeft.column() == m_mapValues)
219 slice->setValue(m_model->data(index, Qt::DisplayRole).toReal());
153 m_series->slices().at(topLeft.row() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
220 slice->setLabel(m_model->data(index, Qt::DisplayRole).toString());
154 if (topLeft.column() == m_mapLabels)
155 m_series->slices().at(topLeft.row() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
156 }
157 }
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);
249 if (m_orientation == Qt::Vertical)
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)
256 {
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();
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();
271 }
272
273 void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
274 {
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();
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();
158 else
328 else
159 {
329 itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
160 if (topLeft.column() >= m_first && (m_count == - 1 || topLeft.column() < m_first + m_count)) {
330 int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled.
161 if (topLeft.row() == m_mapValues)
331 int currentSize = m_series->slices().size();
162 m_series->slices().at(topLeft.column() - m_first)->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble());
332 if (toBeAdded > 0)
163 if (topLeft.row() == m_mapLabels)
333 for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) {
164 m_series->slices().at(topLeft.column() - m_first)->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString());
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);
165 }
344 }
166 }
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)
354 // clear current content
173 //{
355 m_series->clear();
174 // Q_UNUSED(parent);
356
175 // if (m_mapper->orientation() == Qt::Vertical)
357 // check if mappings are set
176 // insertData(start, end);
358 if (m_valuesIndex == -1 || m_labelsIndex == -1)
177 // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
359 return;
178 // initializePieFromModel();
360
179 //}
361 // create the initial slices set
180
362 int slicePos = 0;
181 //void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
363 QModelIndex valueIndex = valueModelIndex(slicePos);
182 //{
364 QModelIndex labelIndex = labelModelIndex(slicePos);
183 // Q_UNUSED(parent);
365 while (valueIndex.isValid() && labelIndex.isValid()) {
184 // if (m_mapper->orientation() == Qt::Vertical)
366 m_series->append(m_model->data(labelIndex, Qt::DisplayRole).toString(), m_model->data(valueIndex, Qt::DisplayRole).toDouble());
185 // removeData(start, end);
367 slicePos++;
186 // else if (start <= m_mapValues || start <= m_mapLabels) // if the changes affect the map - reinitialize the pie
368 valueIndex = valueModelIndex(slicePos);
187 // initializePieFromModel();
369 labelIndex = labelModelIndex(slicePos);
188 //}
370 }
189
371
190 //void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
372 // if (m_orientation == Qt::Vertical) {
191 //{
373 // if (m_valuesIndex >= m_model->columnCount() || m_labelsIndex >= m_model->columnCount())
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 //}
198
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 //}
207
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());
224 // } else {
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 //}
236
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();
254 // else
255 // itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size();
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 // }
273 //}
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
289 // // create the initial slices set
290 // if (m_mapper->orientation() == Qt::Vertical) {
291 // if (m_mapValues >= m_model->columnCount() || m_mapLabels >= m_model->columnCount())
292 // return; // mapped columns are not existing
374 // return; // mapped columns are not existing
293
375
294 // int sliceCount = 0;
376 // int sliceCount = 0;
@@ -296,10 +378,8 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
296 // sliceCount = m_model->rowCount() - m_first;
378 // sliceCount = m_model->rowCount() - m_first;
297 // else
379 // else
298 // sliceCount = qMin(m_count, m_model->rowCount() - m_first);
380 // sliceCount = qMin(m_count, m_model->rowCount() - m_first);
299 // for (int i = m_first; i < m_first + sliceCount; i++)
300 // q->append(m_model->data(m_model->index(i, m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, m_mapLabels), Qt::DisplayRole).toString());
301 // } else {
381 // } else {
302 // if (m_mapValues >= m_model->rowCount() || m_mapLabels >= m_model->rowCount())
382 // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount())
303 // return; // mapped columns are not existing
383 // return; // mapped columns are not existing
304
384
305 // int sliceCount = 0;
385 // int sliceCount = 0;
@@ -307,11 +387,35 void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex botto
307 // sliceCount = m_model->columnCount() - m_first;
387 // sliceCount = m_model->columnCount() - m_first;
308 // else
388 // else
309 // sliceCount = qMin(m_count, m_model->columnCount() - m_first);
389 // sliceCount = qMin(m_count, m_model->columnCount() - m_first);
310 // for (int i = m_first; i < m_first + sliceCount; i++)
311 // q->append(m_model->data(m_model->index(m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(m_mapLabels, i), Qt::DisplayRole).toString());
312 // }
390 // }
313 // q->setLabelsVisible(true);
391 // for (int i = m_first; i < m_first + sliceCount; i++)
314 //}
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);
394 // // create the initial slices set
395 // if (m_orientation == Qt::Vertical) {
396 // if (m_valuesIndex >= m_model->columnCount() || m_labelsIndex >= m_model->columnCount())
397 // return; // mapped columns are not existing
398
399 // int sliceCount = 0;
400 // if(m_count == -1)
401 // sliceCount = m_model->rowCount() - m_first;
402 // else
403 // sliceCount = qMin(m_count, m_model->rowCount() - m_first);
404 // for (int i = m_first; i < m_first + sliceCount; i++)
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());
406 // } else {
407 // if (m_valuesIndex >= m_model->rowCount() || m_labelsIndex >= m_model->rowCount())
408 // return; // mapped columns are not existing
409
410 // int sliceCount = 0;
411 // if(m_count == -1)
412 // sliceCount = m_model->columnCount() - m_first;
413 // else
414 // sliceCount = qMin(m_count, m_model->columnCount() - m_first);
415 // for (int i = m_first; i < m_first + sliceCount; i++)
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 #include "moc_qpiemodelmapper_p.cpp"
420 #include "moc_qpiemodelmapper_p.cpp"
317 #include "moc_qpiemodelmapper.cpp"
421 #include "moc_qpiemodelmapper.cpp"
@@ -4,15 +4,18
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6
6
7 class QAbstractItemModel;
8
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
10
9 class QPieModelMapperPrivate;
11 class QPieModelMapperPrivate;
12 class QPieSeries;
10
13
11 class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject
14 class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject
12 {
15 {
13 Q_OBJECT
16 Q_OBJECT
14 Q_PROPERTY(int mapValues READ mapValues WRITE setMapValues)
17 Q_PROPERTY(int valuesIndex READ valuesIndex WRITE setValuesIndex)
15 Q_PROPERTY(int mapLabels READ mapLabels WRITE setMapLabels)
18 Q_PROPERTY(int labelsIndex READ labelsIndex WRITE setLabelsIndex)
16 Q_PROPERTY(int first READ first WRITE setFirst)
19 Q_PROPERTY(int first READ first WRITE setFirst)
17 Q_PROPERTY(int count READ count WRITE setCount)
20 Q_PROPERTY(int count READ count WRITE setCount)
18 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
21 Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
@@ -21,8 +24,11 class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject
21 public:
24 public:
22 QPieModelMapper(QObject *parent = 0);
25 QPieModelMapper(QObject *parent = 0);
23
26
24 // QAbstractItemModel* model() const;
27 QAbstractItemModel* model() const;
25 // void setModel(QAbstractItemModel *model);
28 void setModel(QAbstractItemModel *model);
29
30 QPieSeries* series() const;
31 void setSeries(QPieSeries *series);
26
32
27 int first() const;
33 int first() const;
28 void setFirst(int first);
34 void setFirst(int first);
@@ -33,18 +39,17 public:
33 Qt::Orientation orientation() const;
39 Qt::Orientation orientation() const;
34 void setOrientation(Qt::Orientation orientation);
40 void setOrientation(Qt::Orientation orientation);
35
41
36 int mapValues() const;
42 int valuesIndex() const;
37 void setMapValues(int mapValues);
43 void setValuesIndex(int valuesIndex);
38
44
39 int mapLabels() const;
45 int labelsIndex() const;
40 void setMapLabels(int mapLabels);
46 void setLabelsIndex(int labelsIndex);
41
47
42 void reset();
48 void reset();
43
49
44 private:
50 private:
45 QScopedPointer<QPieModelMapperPrivate> d_ptr;
51 QScopedPointer<QPieModelMapperPrivate> d_ptr;
46 Q_DECLARE_PRIVATE(QPieModelMapper)
52 Q_DECLARE_PRIVATE(QPieModelMapper)
47 friend class QPieSeriesPrivate;
48 };
53 };
49
54
50 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
@@ -11,6 +11,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QPieModelMapper;
12 class QPieModelMapper;
13 class QPieSeries;
13 class QPieSeries;
14 class QPieSlice;
14
15
15 class QPieModelMapperPrivate : public QObject
16 class QPieModelMapperPrivate : public QObject
16 {
17 {
@@ -22,32 +23,36 public:
22 public Q_SLOTS:
23 public Q_SLOTS:
23 // for the model
24 // for the model
24 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
25 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
25 // void modelRowsAdded(QModelIndex parent, int start, int end);
26 void modelRowsAdded(QModelIndex parent, int start, int end);
26 // void modelRowsRemoved(QModelIndex parent, int start, int end);
27 void modelRowsRemoved(QModelIndex parent, int start, int end);
27 // void modelColumnsAdded(QModelIndex parent, int start, int end);
28 void modelColumnsAdded(QModelIndex parent, int start, int end);
28 // void modelColumnsRemoved(QModelIndex parent, int start, int end);
29 void modelColumnsRemoved(QModelIndex parent, int start, int end);
29
30
30 // for the series
31 // for the series
31 void slicesAdded();
32 void slicesAdded();
32 void slicesRemoved();
33 void slicesRemoved();
33 void sliceChanged();
34 void sliceChanged();
34
35
35 private:
36 void initializePieFromModel();
36 void setModel(QAbstractItemModel *model);
37
37
38 private:
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 private:
45 private:
46 QPieSeries *m_series;
47 QAbstractItemModel *m_model;
42 int m_first;
48 int m_first;
43 int m_count;
49 int m_count;
44 Qt::Orientation m_orientation;
50 Qt::Orientation m_orientation;
45 int m_mapValues;
51 int m_valuesIndex;
46 int m_mapLabels;
52 int m_labelsIndex;
47
53
48 private:
54 private:
49 QPieSeries *m_series;
55
50 QAbstractItemModel *m_model;
51 QPieModelMapper *q_ptr;
56 QPieModelMapper *q_ptr;
52 Q_DECLARE_PUBLIC(QPieModelMapper)
57 Q_DECLARE_PUBLIC(QPieModelMapper)
53 friend class QPieSeriesPrivate;
58 friend class QPieSeriesPrivate;
@@ -26,9 +26,6
26 #include "charttheme_p.h"
26 #include "charttheme_p.h"
27 #include "chartanimator_p.h"
27 #include "chartanimator_p.h"
28 #include "legendmarker_p.h"
28 #include "legendmarker_p.h"
29 #include <QAbstractItemModel>
30 #include "qpiemodelmapper.h"
31 #include "qpiemodelmapper_p.h"
32
29
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
31
@@ -463,65 +460,7 qreal QPieSeries::sum() const
463 \sa QPieSlice::hovered()
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 m_pieRelativeSize(0.7),
472 m_pieRelativeSize(0.7),
534 m_pieStartAngle(0),
473 m_pieStartAngle(0),
535 m_pieEndAngle(360),
474 m_pieEndAngle(360),
536 m_sum(0),
475 m_sum(0)
537 m_model(0),
538 m_mapper(0)
539 {
476 {
540
541 }
477 }
542
478
543 QPieSeriesPrivate::~QPieSeriesPrivate()
479 QPieSeriesPrivate::~QPieSeriesPrivate()
544 {
480 {
545
546 }
481 }
547
482
548 void QPieSeriesPrivate::updateDerivativeData()
483 void QPieSeriesPrivate::updateDerivativeData()
@@ -665,21 +600,6 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
665 return markers;
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 #include "moc_qpieseries.cpp"
603 #include "moc_qpieseries.cpp"
684 #include "moc_qpieseries_p.cpp"
604 #include "moc_qpieseries_p.cpp"
685
605
@@ -26,7 +26,6
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 class QPieSeriesPrivate;
27 class QPieSeriesPrivate;
28 class QPieSlice;
28 class QPieSlice;
29 class QPieModelMapper;
30
29
31 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
32 {
31 {
@@ -38,7 +37,6 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QAbstractSeries
38 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
37 Q_PROPERTY(qreal endAngle READ pieEndAngle WRITE setPieEndAngle)
39 Q_PROPERTY(int count READ count)
38 Q_PROPERTY(int count READ count)
40 Q_PROPERTY(qreal sum READ sum)
39 Q_PROPERTY(qreal sum READ sum)
41 Q_PROPERTY(QPieModelMapper *modelMapper READ modelMapper)
42
40
43 public:
41 public:
44 explicit QPieSeries(QObject *parent = 0);
42 explicit QPieSeries(QObject *parent = 0);
@@ -75,10 +73,6 public:
75
73
76 void setLabelsVisible(bool visible = true);
74 void setLabelsVisible(bool visible = true);
77
75
78 void setModel(QAbstractItemModel* model);
79 void setModelMapper(QPieModelMapper *mapper);
80 QPieModelMapper* modelMapper() const;
81
82 Q_SIGNALS:
76 Q_SIGNALS:
83 void added(QList<QPieSlice*> slices);
77 void added(QList<QPieSlice*> slices);
84 void removed(QList<QPieSlice*> slices);
78 void removed(QList<QPieSlice*> slices);
@@ -24,11 +24,8
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qabstractseries_p.h"
25 #include "qabstractseries_p.h"
26
26
27 class QModelIndex;
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QLegendPrivate;
28 class QLegendPrivate;
31 class QPieModelMapper;
32
29
33 class QPieSeriesPrivate : public QAbstractSeriesPrivate
30 class QPieSeriesPrivate : public QAbstractSeriesPrivate
34 {
31 {
@@ -54,19 +51,8 public Q_SLOTS:
54 void sliceChanged();
51 void sliceChanged();
55 void sliceClicked();
52 void sliceClicked();
56 void sliceHovered(bool state);
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 bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0);
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 public:
56 public:
71 QList<QPieSlice*> m_slices;
57 QList<QPieSlice*> m_slices;
72 qreal m_pieRelativeHorPos;
58 qreal m_pieRelativeHorPos;
@@ -76,10 +62,6 public:
76 qreal m_pieEndAngle;
62 qreal m_pieEndAngle;
77 qreal m_sum;
63 qreal m_sum;
78
64
79 // model
80 QAbstractItemModel *m_model;
81 QPieModelMapper *m_mapper;
82
83 private:
65 private:
84 friend class QLegendPrivate;
66 friend class QLegendPrivate;
85 Q_DECLARE_PUBLIC(QPieSeries)
67 Q_DECLARE_PUBLIC(QPieSeries)
@@ -96,14 +96,6 QAbstractSeries::~QAbstractSeries()
96 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
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 void QAbstractSeries::setName(const QString& name)
99 void QAbstractSeries::setName(const QString& name)
108 {
100 {
109 d_ptr->m_name = name;
101 d_ptr->m_name = name;
@@ -122,7 +114,6 QString QAbstractSeries::name() const
122
114
123 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
115 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
124 q_ptr(q),
116 q_ptr(q),
125 m_model(0),
126 m_dataset(0)
117 m_dataset(0)
127 {
118 {
128 }
119 }
@@ -25,13 +25,10
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27
27
28 class QAbstractItemModel;
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
29
32 class QAbstractSeriesPrivate;
30 class QAbstractSeriesPrivate;
33 class QChart;
31 class QChart;
34 //class QModelMapper;
35
32
36 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject
37 {
34 {
@@ -58,8 +55,6 protected:
58 public:
55 public:
59 ~QAbstractSeries();
56 ~QAbstractSeries();
60 virtual SeriesType type() const = 0;
57 virtual SeriesType type() const = 0;
61 virtual void setModel(QAbstractItemModel *model) = 0;
62 QAbstractItemModel* model() const;
63 void setName(const QString& name);
58 void setName(const QString& name);
64 QString name() const;
59 QString name() const;
65 QChart* chart() const;
60 QChart* chart() const;
@@ -32,8 +32,6
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34
34
35 class QAbstractItemModel;
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
36
39 class Domain;
37 class Domain;
@@ -42,7 +40,6 class Chart;
42 class LegendMarker;
40 class LegendMarker;
43 class QLegend;
41 class QLegend;
44 class ChartDataSet;
42 class ChartDataSet;
45 //class QModelMapper;
46
43
47 class QAbstractSeriesPrivate : public QObject
44 class QAbstractSeriesPrivate : public QObject
48 {
45 {
@@ -57,12 +54,7 public:
57
54
58 protected:
55 protected:
59 QAbstractSeries *q_ptr;
56 QAbstractSeries *q_ptr;
60 QAbstractItemModel *m_model;
61 // QModelMapper *m_mapper;
62 ChartDataSet *m_dataset;
57 ChartDataSet *m_dataset;
63 // int m_mapFirst;
64 // int m_mapCount;
65 // Qt::Orientation m_mapOrientation;
66 QString m_name;
58 QString m_name;
67
59
68 friend class QAbstractSeries;
60 friend class QAbstractSeries;
@@ -24,7 +24,6
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include <QAbstractItemModel>
28
27
29 /*!
28 /*!
30 \class QSplineSeries
29 \class QSplineSeries
@@ -75,22 +74,6 QAbstractSeries::SeriesType QSplineSeries::type() const
75 return QAbstractSeries::SeriesTypeSpline;
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 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
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 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
205 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
253 {
206 {
254 Q_Q(QSplineSeries);
207 Q_Q(QSplineSeries);
@@ -40,9 +40,6 public:
40 ~QSplineSeries();
40 ~QSplineSeries();
41 QAbstractSeries::SeriesType type() const;
41 QAbstractSeries::SeriesType type() const;
42
42
43 void setModel(QAbstractItemModel *model);
44 void setModelMapper(QXYModelMapper *mapper);
45
46 private:
43 private:
47 Q_DECLARE_PRIVATE(QSplineSeries)
44 Q_DECLARE_PRIVATE(QSplineSeries)
48 Q_DISABLE_COPY(QSplineSeries)
45 Q_DISABLE_COPY(QSplineSeries)
@@ -47,13 +47,6 public:
47 public Q_SLOTS:
47 public Q_SLOTS:
48 void updateControlPoints();
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 private:
50 private:
58 void calculateControlPoints();
51 void calculateControlPoints();
59 QVector<qreal> firstControlPoints(const QVector<qreal>& vector);
52 QVector<qreal> firstControlPoints(const QVector<qreal>& vector);
@@ -22,8 +22,6
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25 #include <QAbstractItemModel>
26 #include "qxymodelmapper.h"
27
25
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
27
@@ -169,38 +167,8 void QXYSeries::removeAll()
169 */
167 */
170 QList<QPointF> QXYSeries::points() const
168 QList<QPointF> QXYSeries::points() const
171 {
169 {
172 // Q_ASSERT(false);
173 Q_D(const QXYSeries);
170 Q_D(const QXYSeries);
174 if (d->m_model && d->m_mapper) {
171 return d->m_points.toList();
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 return d->m_points.toList();
203 }
204 }
172 }
205
173
206 /*!
174 /*!
@@ -209,31 +177,6 QList<QPointF> QXYSeries::points() const
209 int QXYSeries::count() const
177 int QXYSeries::count() const
210 {
178 {
211 Q_D(const QXYSeries);
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 return d->m_points.count();
180 return d->m_points.count();
238 }
181 }
239
182
@@ -323,73 +266,11 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
323 return *this;
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) : QAbstractSeriesPrivate(q),
272 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
392 m_mapper(0),
273 QAbstractSeriesPrivate(q),
393 m_pointsVisible(false)
274 m_pointsVisible(false)
394 {
275 {
395 }
276 }
@@ -435,78 +316,6 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
435 return list << new XYLegendMarker(q,legend);
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 #include "moc_qxyseries.cpp"
319 #include "moc_qxyseries.cpp"
511 #include "moc_qxyseries_p.cpp"
320 #include "moc_qxyseries_p.cpp"
512
321
@@ -36,7 +36,6 class QXYModelMapper;
36 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
36 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QAbstractSeries
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(QXYModelMapper *modelMapper READ modelMapper)
40
39
41 protected:
40 protected:
42 explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0);
41 explicit QXYSeries(QXYSeriesPrivate &d,QObject *parent = 0);
@@ -67,10 +66,6 public:
67 void setPointsVisible(bool visible = true);
66 void setPointsVisible(bool visible = true);
68 bool pointsVisible() const;
67 bool pointsVisible() const;
69
68
70 void setModel(QAbstractItemModel *model);
71 virtual void setModelMapper(QXYModelMapper *mapper);
72 QXYModelMapper* modelMapper() const;
73
74 Q_SIGNALS:
69 Q_SIGNALS:
75 void clicked(const QPointF &point);
70 void clicked(const QPointF &point);
76
71
@@ -35,7 +35,6
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QXYSeries;
37 class QXYSeries;
38 class QXYModelMapper;
39
38
40 class QXYSeriesPrivate: public QAbstractSeriesPrivate
39 class QXYSeriesPrivate: public QAbstractSeriesPrivate
41 {
40 {
@@ -47,18 +46,6 public:
47 void scaleDomain(Domain& domain);
46 void scaleDomain(Domain& domain);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
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 Q_SIGNALS:
49 Q_SIGNALS:
63 void updated();
50 void updated();
64 void pointReplaced(int index);
51 void pointReplaced(int index);
@@ -70,10 +57,8 Q_SIGNALS:
70
57
71 protected:
58 protected:
72 QVector<QPointF> m_points;
59 QVector<QPointF> m_points;
73
74 QPen m_pen;
60 QPen m_pen;
75 QBrush m_brush;
61 QBrush m_brush;
76 QXYModelMapper* m_mapper;
77 bool m_pointsVisible;
62 bool m_pointsVisible;
78
63
79 private:
64 private:
@@ -41,9 +41,7 m_animation(0)
41 {
41 {
42 QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
42 QObject::connect(series->d_func(),SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
43 QObject::connect(series->d_func(),SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
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 QObject::connect(series->d_func(),SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
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 QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized()));
45 QObject::connect(series->d_func(),SIGNAL(reinitialized()),this,SLOT(handleReinitialized()));
48 QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF)));
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 void XYChart::handlePointAdded(int index)
123 void XYChart::handlePointAdded(int index)
126 {
124 {
127 if (m_series->model() == 0) {
125 Q_ASSERT(index<m_series->count());
128 Q_ASSERT(index<m_series->count());
126 Q_ASSERT(index>=0);
129 Q_ASSERT(index>=0);
130 }
131
132 QVector<QPointF> points = m_points;
127 QVector<QPointF> points = m_points;
133 QPointF point;
128 QPointF point;
134 point = calculateGeometryPoint(index);
129 point = calculateGeometryPoint(index);
@@ -141,42 +136,10 void XYChart::handlePointAdded(int index)
141 updateChart(m_points,points,index);
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 void XYChart::handlePointRemoved(int index)
139 void XYChart::handlePointRemoved(int index)
175 {
140 {
176 if (m_series->model() == 0) {
141 Q_ASSERT(index<m_series->count() + 1);
177 Q_ASSERT(index<m_series->count() + 1);
142 Q_ASSERT(index>=0);
178 Q_ASSERT(index>=0);
179 }
180 QVector<QPointF> points = m_points;
143 QVector<QPointF> points = m_points;
181 points.remove(index);
144 points.remove(index);
182
145
@@ -187,57 +150,6 void XYChart::handlePointRemoved(int index)
187 updateChart(m_points,points,index);
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 void XYChart::handlePointReplaced(int index)
153 void XYChart::handlePointReplaced(int index)
242 {
154 {
243 Q_ASSERT(index<m_series->count());
155 Q_ASSERT(index<m_series->count());
@@ -53,9 +53,7 public:
53
53
54 public Q_SLOTS:
54 public Q_SLOTS:
55 void handlePointAdded(int index);
55 void handlePointAdded(int index);
56 void handlePointsAdded(int start, int end);
57 void handlePointRemoved(int index);
56 void handlePointRemoved(int index);
58 void handlePointsRemoved(int start, int end);
59 void handlePointReplaced(int index);
57 void handlePointReplaced(int index);
60 void handleReinitialized();
58 void handleReinitialized();
61 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
59 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
@@ -49,7 +49,6 private slots:
49 void mouseclicked();
49 void mouseclicked();
50 void mousehovered_data();
50 void mousehovered_data();
51 void mousehovered();
51 void mousehovered();
52 void model();
53
52
54 private:
53 private:
55 QGroupedBarSeries* m_barseries;
54 QGroupedBarSeries* m_barseries;
@@ -338,65 +337,6 void tst_QGroupedBarSeries::mousehovered()
338 QVERIFY(seriesSpyArg.at(1).toBool() == false);
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 QTEST_MAIN(tst_QGroupedBarSeries)
340 QTEST_MAIN(tst_QGroupedBarSeries)
401
341
402 #include "tst_qgroupedbarseries.moc"
342 #include "tst_qgroupedbarseries.moc"
@@ -76,14 +76,6 class tst_QLineSeries : public QObject
76 void replace_chart();
76 void replace_chart();
77 void replace_chart_animation_data();
77 void replace_chart_animation_data();
78 void replace_chart_animation();
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 private:
79 private:
88 void append_data();
80 void append_data();
89 void count_data();
81 void count_data();
@@ -453,189 +445,6 void tst_QLineSeries::replace_chart_animation()
453 replace_chart();
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 QTEST_MAIN(tst_QLineSeries)
448 QTEST_MAIN(tst_QLineSeries)
640
449
641 #include "tst_qlineseries.moc"
450 #include "tst_qlineseries.moc"
@@ -49,9 +49,6 private slots:
49 void calculatedValues();
49 void calculatedValues();
50 void clickedSignal();
50 void clickedSignal();
51 void hoverSignal();
51 void hoverSignal();
52 void model();
53 void modelCustomMap();
54 void modelUpdate();
55
52
56 private:
53 private:
57 void verifyCalculatedData(const QPieSeries &series, bool *ok);
54 void verifyCalculatedData(const QPieSeries &series, bool *ok);
@@ -342,157 +339,6 void tst_qpieseries::hoverSignal()
342 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
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 QTEST_MAIN(tst_qpieseries)
342 QTEST_MAIN(tst_qpieseries)
497
343
498 #include "tst_qpieseries.moc"
344 #include "tst_qpieseries.moc"
@@ -101,7 +101,7 TableWidget::TableWidget(QWidget *parent)
101 buttonsLayout->addWidget(removeRowButton);
101 buttonsLayout->addWidget(removeRowButton);
102 // buttonsLayout->addWidget(addColumnRightButton);
102 // buttonsLayout->addWidget(addColumnRightButton);
103 // buttonsLayout->addWidget(removeColumnButton);
103 // buttonsLayout->addWidget(removeColumnButton);
104 buttonsLayout->addWidget(specialPieButton);
104 buttonsLayout->addWidget(specialPieButton);
105 buttonsLayout->addStretch();
105 buttonsLayout->addStretch();
106
106
107 // chart type radio buttons
107 // chart type radio buttons
@@ -123,7 +123,7 TableWidget::TableWidget(QWidget *parent)
123 // radio buttons layout
123 // radio buttons layout
124 QVBoxLayout* radioLayout = new QVBoxLayout;
124 QVBoxLayout* radioLayout = new QVBoxLayout;
125 radioLayout->addWidget(m_lineRadioButton);
125 radioLayout->addWidget(m_lineRadioButton);
126 radioLayout->addWidget(m_splineRadioButton);
126 radioLayout->addWidget(m_splineRadioButton);
127 // radioLayout->addWidget(m_scatterRadioButton);
127 // radioLayout->addWidget(m_scatterRadioButton);
128 radioLayout->addWidget(m_pieRadioButton);
128 radioLayout->addWidget(m_pieRadioButton);
129 // radioLayout->addWidget(m_areaRadioButton);
129 // radioLayout->addWidget(m_areaRadioButton);
@@ -133,7 +133,7 TableWidget::TableWidget(QWidget *parent)
133 // create main layout
133 // create main layout
134 QGridLayout* mainLayout = new QGridLayout;
134 QGridLayout* mainLayout = new QGridLayout;
135 mainLayout->addLayout(buttonsLayout, 2, 0);
135 mainLayout->addLayout(buttonsLayout, 2, 0);
136 mainLayout->addLayout(radioLayout, 3, 0);
136 mainLayout->addLayout(radioLayout, 3, 0);
137 mainLayout->addWidget(m_tableView, 1, 0);
137 mainLayout->addWidget(m_tableView, 1, 0);
138 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
138 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
139 setLayout(mainLayout);
139 setLayout(mainLayout);
@@ -174,130 +174,130 void TableWidget::updateChartType(bool toggle)
174 if (toggle) {
174 if (toggle) {
175 // specialPie = 0;
175 // specialPie = 0;
176 m_chart->removeAllSeries();
176 m_chart->removeAllSeries();
177 m_chart->axisX()->setNiceNumbersEnabled(false);
177 // m_chart->axisX()->setNiceNumbersEnabled(false);
178 m_chart->axisY()->setNiceNumbersEnabled(false);
178 // m_chart->axisY()->setNiceNumbersEnabled(false);
179
179
180 // renable axes of the chart (pie hides them)
180 // // renable axes of the chart (pie hides them)
181 // x axis
181 // // x axis
182 QAxis *axis = m_chart->axisX();
182 // QAxis *axis = m_chart->axisX();
183 axis->setAxisVisible(true);
183 // axis->setAxisVisible(true);
184 axis->setGridLineVisible(true);
184 // axis->setGridLineVisible(true);
185 axis->setLabelsVisible(true);
185 // axis->setLabelsVisible(true);
186
186
187 // y axis
187 // // y axis
188 axis = m_chart->axisY();
188 // axis = m_chart->axisY();
189 axis->setAxisVisible(true);
189 // axis->setAxisVisible(true);
190 axis->setGridLineVisible(true);
190 // axis->setGridLineVisible(true);
191 axis->setLabelsVisible(true);
191 // axis->setLabelsVisible(true);
192
192
193 m_model->clearMapping();
193 // m_model->clearMapping();
194
194
195 QString seriesColorHex = "#000000";
195 QString seriesColorHex = "#000000";
196 QPen pen;
196 // QPen pen;
197 pen.setWidth(2);
197 // pen.setWidth(2);
198
198
199 if (m_lineRadioButton->isChecked())
199 if (m_lineRadioButton->isChecked())
200 {
200 {
201 m_chart->setAnimationOptions(QChart::NoAnimation);
201 // m_chart->setAnimationOptions(QChart::NoAnimation);
202
202
203 // series 1
203 // // series 1
204 m_series = new QLineSeries;
204 // m_series = new QLineSeries;
205 m_series->setModel(m_model);
205 // m_series->setModel(m_model);
206
206
207 QXYModelMapper *mapper = new QXYModelMapper;
207 // QXYModelMapper *mapper = new QXYModelMapper;
208 mapper->setMapX(0);
208 // mapper->setMapX(0);
209 mapper->setMapY(1);
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);
226 // mapper->setFirst(3);
210 // mapper->setFirst(3);
227 // mapper->setCount(4);
211 // mapper->setCount(4);
228 m_series->setModelMapper(mapper);
212 // m_series->setModelMapper(mapper);
229 // m_series->setModelMapping(2,3, Qt::Vertical);
213 // // m_series->setModelMapping(0,1, Qt::Vertical);
230 m_chart->addSeries(m_series);
214 // // m_series->setModelMappingRange(3, 4);
231 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
215 // m_chart->addSeries(m_series);
232 m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
216 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
233
217 // m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
234 // series 3
218
235 m_series = new QLineSeries;
219 // // series 2
236 m_series->setModel(m_model);
220 // m_series = new QLineSeries;
237
221 // m_series->setModel(m_model);
238 mapper = new QXYModelMapper;
222
239 mapper->setMapX(5);
223 // mapper = new QXYModelMapper;
240 mapper->setMapY(6);
224 // mapper->setMapX(3);
241 mapper->setFirst(2);
225 // mapper->setMapY(4);
242 mapper->setCount(-1);
226 // // mapper->setFirst(3);
243 m_series->setModelMapper(mapper);
227 // // mapper->setCount(4);
244 // m_series->setModelMapping(4,5, Qt::Vertical);
228 // m_series->setModelMapper(mapper);
245 // m_series->setModelMappingRange(2, -1);
229 // // m_series->setModelMapping(2,3, Qt::Vertical);
246 m_chart->addSeries(m_series);
230 // m_chart->addSeries(m_series);
247 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
231 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
248 m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
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 else if (m_splineRadioButton->isChecked())
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
254 // // series 1
255 m_series = new QSplineSeries;
255 // m_series = new QSplineSeries;
256 m_series->setModel(m_model);
256 // m_series->setModel(m_model);
257
257
258 QXYModelMapper *mapper = new QXYModelMapper;
258 // QXYModelMapper *mapper = new QXYModelMapper;
259 mapper->setMapX(0);
259 // mapper->setMapX(0);
260 mapper->setMapY(1);
260 // mapper->setMapY(1);
261 mapper->setFirst(0);
261 // mapper->setFirst(0);
262 mapper->setCount(-1);
262 // mapper->setCount(-1);
263
263
264 m_series->setModelMapper(mapper);
264 // m_series->setModelMapper(mapper);
265
265
266 m_chart->addSeries(m_series);
266 // m_chart->addSeries(m_series);
267 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
267 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
268 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
268 // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
269
269
270 // series 2
270 // // series 2
271 m_series = new QSplineSeries;
271 // m_series = new QSplineSeries;
272 m_series->setModel(m_model);
272 // m_series->setModel(m_model);
273
273
274 mapper = new QXYModelMapper;
274 // mapper = new QXYModelMapper;
275 mapper->setMapX(2);
275 // mapper->setMapX(2);
276 mapper->setMapY(3);
276 // mapper->setMapY(3);
277 mapper->setFirst(2);
277 // mapper->setFirst(2);
278 mapper->setCount(4);
278 // mapper->setCount(4);
279
279
280 m_series->setModelMapper(mapper);
280 // m_series->setModelMapper(mapper);
281
281
282 m_chart->addSeries(m_series);
282 // m_chart->addSeries(m_series);
283 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
283 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
284 m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
284 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
285
285
286 // series 3
286 // // series 3
287 m_series = new QSplineSeries;
287 // m_series = new QSplineSeries;
288 m_series->setModel(m_model);
288 // m_series->setModel(m_model);
289
289
290 mapper = new QXYModelMapper;
290 // mapper = new QXYModelMapper;
291 mapper->setMapX(4);
291 // mapper->setMapX(4);
292 mapper->setMapY(5);
292 // mapper->setMapY(5);
293 mapper->setFirst(2);
293 // mapper->setFirst(2);
294 mapper->setCount(-1);
294 // mapper->setCount(-1);
295
295
296 m_series->setModelMapper(mapper);
296 // m_series->setModelMapper(mapper);
297
297
298 m_chart->addSeries(m_series);
298 // m_chart->addSeries(m_series);
299 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
299 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
300 m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
300 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
301 }
301 }
302 // else if (m_scatterRadioButton->isChecked())
302 // else if (m_scatterRadioButton->isChecked())
303 // {
303 // {
@@ -334,74 +334,75 void TableWidget::updateChartType(bool toggle)
334 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
334 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
335 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
335 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
336 // }
336 // }
337 else if (m_pieRadioButton->isChecked())
337 else if (m_pieRadioButton->isChecked())
338 {
338 {
339 m_chart->setAnimationOptions(QChart::SeriesAnimations);
339 m_chart->setAnimationOptions(QChart::SeriesAnimations);
340
340
341 // pie 1
341 // pie 1
342 QPieSeries* pieSeries = new QPieSeries;
342 QPieSeries* pieSeries = new QPieSeries;
343 pieSeries->setModel(m_model);
343
344
344 m_pieMapper = new QPieModelMapper;
345 QPieModelMapper *mapper = pieSeries->modelMapper();//new QPieModelMapper;
345 m_pieMapper->setValuesIndex(1);
346 mapper->setMapValues(1);
346 m_pieMapper->setLabelsIndex(1);
347 mapper->setMapLabels(0);
347 m_pieMapper->setSeries(pieSeries);
348 mapper->setFirst(2);
348 m_pieMapper->setModel(m_model);
349 mapper->setCount(5);
349 m_pieMapper->setFirst(2);
350 // pieSeries->setModelMapper(mapper);
350 m_pieMapper->setCount(5);
351
351 // pieSeries->setModelMapper(mapper);
352 pieSeries->setLabelsVisible(true);
352
353 pieSeries->setPieSize(0.75);
353 pieSeries->setLabelsVisible(true);
354 // pieSeries->setHorizontalPosition(0.2);
354 pieSeries->setPieSize(0.75);
355 // pieSeries->setVerticalPosition(0.3);
355 // pieSeries->setHorizontalPosition(0.2);
356
356 // pieSeries->setVerticalPosition(0.3);
357 m_chart->addSeries(pieSeries);
357
358 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
358 m_chart->addSeries(pieSeries);
359 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5));
359 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
360
360 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5));
361
361
362 pieSeries->slices().at(0)->setValue(400);
362
363 pieSeries->slices().at(0)->setLabel(QString("36"));
363 // pieSeries->slices().at(0)->setValue(400);
364
364 // pieSeries->slices().at(0)->setLabel(QString("36"));
365 // // pie 2
365
366 // pieSeries = new QPieSeries;
366 // // pie 2
367 // pieSeries->setModel(m_model);
367 // pieSeries = new QPieSeries;
368
368 // pieSeries->setModel(m_model);
369 // pieSeries->setModelMapping(1,1, Qt::Vertical);
369
370 // pieSeries->setModelMappingRange(2, -1);
370 // pieSeries->setModelMapping(1,1, Qt::Vertical);
371 // pieSeries->setLabelsVisible(true);
371 // pieSeries->setModelMappingRange(2, -1);
372 // pieSeries->setPieSize(0.35);
372 // pieSeries->setLabelsVisible(true);
373 // pieSeries->setHorizontalPosition(0.8);
373 // pieSeries->setPieSize(0.35);
374 // pieSeries->setVerticalPosition(0.3);
374 // pieSeries->setHorizontalPosition(0.8);
375 // m_chart->addSeries(pieSeries);
375 // pieSeries->setVerticalPosition(0.3);
376 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
376 // m_chart->addSeries(pieSeries);
377 // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000));
377 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
378
378 // m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 1000));
379 // // pie 3
379
380 // pieSeries = new QPieSeries;
380 // // pie 3
381 // pieSeries->setModel(m_model);
381 // pieSeries = new QPieSeries;
382 // pieSeries->setModelMapping(2,2, Qt::Vertical);
382 // pieSeries->setModel(m_model);
383 // pieSeries->setLabelsVisible(true);
383 // pieSeries->setModelMapping(2,2, Qt::Vertical);
384 // pieSeries->setPieSize(0.35);
384 // pieSeries->setLabelsVisible(true);
385 // pieSeries->setHorizontalPosition(0.5);
385 // pieSeries->setPieSize(0.35);
386 // pieSeries->setVerticalPosition(0.75);
386 // pieSeries->setHorizontalPosition(0.5);
387 // m_chart->addSeries(pieSeries);
387 // pieSeries->setVerticalPosition(0.75);
388 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
388 // m_chart->addSeries(pieSeries);
389 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
389 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
390
390 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
391 // // special pie
391
392 // specialPie = new QPieSeries;
392 // // special pie
393 // specialPie->append(17, "1");
393 // specialPie = new QPieSeries;
394 // specialPie->append(45, "2");
394 // specialPie->append(17, "1");
395 // specialPie->append(77, "3");
395 // specialPie->append(45, "2");
396 // specialPie->append(37, "4");
396 // specialPie->append(77, "3");
397 // specialPie->append(27, "5");
397 // specialPie->append(37, "4");
398 // specialPie->append(47, "6");
398 // specialPie->append(27, "5");
399 // specialPie->setPieSize(0.35);
399 // specialPie->append(47, "6");
400 // specialPie->setHorizontalPosition(0.8);
400 // specialPie->setPieSize(0.35);
401 // specialPie->setVerticalPosition(0.75);
401 // specialPie->setHorizontalPosition(0.8);
402 // specialPie->setLabelsVisible(true);
402 // specialPie->setVerticalPosition(0.75);
403 // m_chart->addSeries(specialPie);
403 // specialPie->setLabelsVisible(true);
404 }
404 // m_chart->addSeries(specialPie);
405 }
405 // else if (m_areaRadioButton->isChecked())
406 // else if (m_areaRadioButton->isChecked())
406 // {
407 // {
407 // m_chart->setAnimationOptions(QChart::NoAnimation);
408 // m_chart->setAnimationOptions(QChart::NoAnimation);
@@ -419,34 +420,34 void TableWidget::updateChartType(bool toggle)
419 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
420 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
420 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
421 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
421 // }
422 // }
422 else if (m_barRadioButton->isChecked())
423 else if (m_barRadioButton->isChecked())
423 {
424 {
424 m_chart->setAnimationOptions(QChart::SeriesAnimations);
425 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
425
426
426 QGroupedBarSeries* barSeries = new QGroupedBarSeries();
427 // QGroupedBarSeries* barSeries = new QGroupedBarSeries();
427 barSeries->setCategories(QStringList());
428 // barSeries->setCategories(QStringList());
428 barSeries->setModel(m_model);
429 // barSeries->setModel(m_model);
429 // barSeries->setModelMappingRange(2, 5);
430 // // barSeries->setModelMappingRange(2, 5);
430 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
431 //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
431
432
432 QBarModelMapper *mapper = new QBarModelMapper;
433 // QBarModelMapper *mapper = new QBarModelMapper;
433 mapper->setMapCategories(5);
434 // mapper->setMapCategories(5);
434 mapper->setMapBarBottom(2);
435 // mapper->setMapBarBottom(2);
435 mapper->setMapBarTop(4);
436 // mapper->setMapBarTop(4);
436 barSeries->setModelMapper(mapper);
437 // barSeries->setModelMapper(mapper);
437 m_chart->addSeries(barSeries);
438 // m_chart->addSeries(barSeries);
438 QList<QBarSet*> barsets = barSeries->barSets();
439 // QList<QBarSet*> barsets = barSeries->barSets();
439 for (int i = 0; i < barsets.count(); i++) {
440 // for (int i = 0; i < barsets.count(); i++) {
440 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
441 // 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 // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000));
442 }
443 // }
443 }
444 }
444
445
445
446
446 if (!m_barRadioButton->isChecked()) {
447 if (!m_barRadioButton->isChecked()) {
447 m_chart->axisX()->setRange(0, 500);
448 m_chart->axisX()->setRange(0, 500);
448 m_chart->axisY()->setRange(0, 220);
449 m_chart->axisY()->setRange(0, 220);
449 }
450 }
450 m_chart->legend()->setVisible(true);
451 m_chart->legend()->setVisible(true);
451
452
452 // repaint table view colors
453 // repaint table view colors
@@ -457,8 +458,9 void TableWidget::updateChartType(bool toggle)
457
458
458 void TableWidget::testPie()
459 void TableWidget::testPie()
459 {
460 {
460 // m_series->modelMapper()->setMapX(4);
461 m_pieMapper->setCount(-1);
461 // m_tableView->setColumnWidth(10, 250);
462 // m_series->modelMapper()->setMapX(4);
463 // m_tableView->setColumnWidth(10, 250);
462 // if (specialPie) {
464 // if (specialPie) {
463 // specialPie->remove(specialPie->slices().at(2));
465 // specialPie->remove(specialPie->slices().at(2));
464 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
466 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
@@ -26,6 +26,7
26 #include "qchartview.h"
26 #include "qchartview.h"
27 //#include "qxyseries.h"
27 //#include "qxyseries.h"
28 //#include <QPieSeries>
28 //#include <QPieSeries>
29 #include <QPieModelMapper>
29
30
30 class CustomTableModel;
31 class CustomTableModel;
31 class QTableView;
32 class QTableView;
@@ -65,6 +66,7 public:
65 QRadioButton* m_areaRadioButton;
66 QRadioButton* m_areaRadioButton;
66 QRadioButton* m_barRadioButton;
67 QRadioButton* m_barRadioButton;
67 QSpinBox* m_linesCountSpinBox;
68 QSpinBox* m_linesCountSpinBox;
69 QPieModelMapper *m_pieMapper;
68 // QPieSeries* specialPie;
70 // QPieSeries* specialPie;
69 };
71 };
70
72
General Comments 0
You need to be logged in to leave comments. Login now