@@ -1,95 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qhpiemodelmapper.h" |
|
21 | #include "qhpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHPieModelMapper |
|
26 | \class QHPieModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. |
|
31 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. | |
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. |
|
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. | |
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \property QHPieModelMapper::valuesRow |
|
37 | \property QHPieModelMapper::valuesRow | |
38 | \brief Defines which row of the model is kept in sync with the values of the pie's slices |
|
38 | \brief Defines which row of the model is kept in sync with the values of the pie's slices | |
39 |
|
39 | |||
40 | Default value is: -1 (invalid mapping) |
|
40 | Default value is: -1 (invalid mapping) | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QHPieModelMapper::labelsRow |
|
44 | \property QHPieModelMapper::labelsRow | |
45 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices |
|
45 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices | |
46 |
|
46 | |||
47 | Default value is: -1 (invalid mapping) |
|
47 | Default value is: -1 (invalid mapping) | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | Constructs a mapper object which is a child of \a parent. |
|
51 | Constructs a mapper object which is a child of \a parent. | |
52 | */ |
|
52 | */ | |
53 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : |
|
53 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : | |
54 | QPieModelMapper(parent) |
|
54 | QPieModelMapper(parent) | |
55 | { |
|
55 | { | |
56 | QPieModelMapper::setOrientation(Qt::Horizontal); |
|
56 | QPieModelMapper::setOrientation(Qt::Horizontal); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | Returns which row of the model is kept in sync with the values of the pie's slices |
|
60 | Returns which row of the model is kept in sync with the values of the pie's slices | |
61 | */ |
|
61 | */ | |
62 | int QHPieModelMapper::valuesRow() const |
|
62 | int QHPieModelMapper::valuesRow() const | |
63 | { |
|
63 | { | |
64 | return QPieModelMapper::valuesSection(); |
|
64 | return QPieModelMapper::valuesSection(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Sets the model row that is kept in sync with the pie slices values. |
|
68 | Sets the model row that is kept in sync with the pie slices values. | |
69 | Parameter \a valuesRow specifies the row of the model. |
|
69 | Parameter \a valuesRow specifies the row of the model. | |
70 | */ |
|
70 | */ | |
71 | void QHPieModelMapper::setValuesRow(int valuesRow) |
|
71 | void QHPieModelMapper::setValuesRow(int valuesRow) | |
72 | { |
|
72 | { | |
|
73 | if (valuesRow != valuesSection()) { | |||
73 | QPieModelMapper::setValuesSection(valuesRow); |
|
74 | QPieModelMapper::setValuesSection(valuesRow); | |
|
75 | emit valuesRowChanged(); | |||
|
76 | } | |||
74 | } |
|
77 | } | |
75 |
|
78 | |||
76 | /*! |
|
79 | /*! | |
77 | Returns which row of the model is kept in sync with the labels of the pie's slices |
|
80 | Returns which row of the model is kept in sync with the labels of the pie's slices | |
78 | */ |
|
81 | */ | |
79 | int QHPieModelMapper::labelsRow() const |
|
82 | int QHPieModelMapper::labelsRow() const | |
80 | { |
|
83 | { | |
81 | return QPieModelMapper::labelsSection(); |
|
84 | return QPieModelMapper::labelsSection(); | |
82 | } |
|
85 | } | |
83 |
|
86 | |||
84 | /*! |
|
87 | /*! | |
85 | Sets the model row that is kept in sync with the pie's slices labels. |
|
88 | Sets the model row that is kept in sync with the pie's slices labels. | |
86 | Parameter \a labelsRow specifies the row of the model. |
|
89 | Parameter \a labelsRow specifies the row of the model. | |
87 | */ |
|
90 | */ | |
88 | void QHPieModelMapper::setLabelsRow(int labelsRow) |
|
91 | void QHPieModelMapper::setLabelsRow(int labelsRow) | |
89 | { |
|
92 | { | |
|
93 | if (labelsRow != labelsSection()) { | |||
90 | QPieModelMapper::setLabelsSection(labelsRow); |
|
94 | QPieModelMapper::setLabelsSection(labelsRow); | |
|
95 | emit labelsRowChanged(); | |||
|
96 | } | |||
91 | } |
|
97 | } | |
92 |
|
98 | |||
93 | #include "moc_qhpiemodelmapper.cpp" |
|
99 | #include "moc_qhpiemodelmapper.cpp" | |
94 |
|
100 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QHPIEMODELMAPPER_H |
|
21 | #ifndef QHPIEMODELMAPPER_H | |
22 | #define QHPIEMODELMAPPER_H |
|
22 | #define QHPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qpiemodelmapper.h" |
|
24 | #include "qpiemodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QHPieModelMapper : public QPieModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow) |
|
31 | Q_PROPERTY(int valuesRow READ valuesRow WRITE setValuesRow NOTIFY valuesRowChanged) | |
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow) |
|
32 | Q_PROPERTY(int labelsRow READ labelsRow WRITE setLabelsRow NOTIFY labelsRowChanged) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QHPieModelMapper(QObject *parent = 0); |
|
35 | explicit QHPieModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int valuesRow() const; |
|
37 | int valuesRow() const; | |
38 | void setValuesRow(int valuesRow); |
|
38 | void setValuesRow(int valuesRow); | |
39 |
|
39 | |||
40 | int labelsRow() const; |
|
40 | int labelsRow() const; | |
41 | void setLabelsRow(int labelsRow); |
|
41 | void setLabelsRow(int labelsRow); | |
|
42 | ||||
|
43 | Q_SIGNALS: | |||
|
44 | void valuesRowChanged(); | |||
|
45 | void labelsRowChanged(); | |||
42 | }; |
|
46 | }; | |
43 |
|
47 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
49 | |||
46 | #endif // QHPIEMODELMAPPER_H |
|
50 | #endif // QHPIEMODELMAPPER_H |
@@ -1,593 +1,605 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpiemodelmapper_p.h" |
|
21 | #include "qpiemodelmapper_p.h" | |
22 | #include "qpiemodelmapper.h" |
|
22 | #include "qpiemodelmapper.h" | |
23 | #include "qpieseries.h" |
|
23 | #include "qpieseries.h" | |
24 | #include "qpieslice.h" |
|
24 | #include "qpieslice.h" | |
25 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QPieModelMapper |
|
30 | \class QPieModelMapper | |
31 | \brief part of QtCommercial chart API. |
|
31 | \brief part of QtCommercial chart API. | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
34 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
35 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. |
|
35 | The instance of this class cannot be created directly. QHPieModelMapper of QVPieModelMapper should be used instead. This class is used to create a connection between QPieSeries and QAbstractItemModel derived model object. | |
36 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. |
|
36 | It is possible to use both QAbstractItemModel and QPieSeries model API. QPieModelMapper makes sure that Pie and the model are kept in sync. | |
37 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
37 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \property QPieModelMapper::series |
|
41 | \property QPieModelMapper::series | |
42 | \brief Defines the QPieSeries object that is used by the mapper. |
|
42 | \brief Defines the QPieSeries object that is used by the mapper. | |
43 |
|
43 | |||
44 | All the data in the series is discarded when it is set to the mapper. |
|
44 | All the data in the series is discarded when it is set to the mapper. | |
45 | When new series is specified the old series is disconnected (it preserves its data) |
|
45 | When new series is specified the old series is disconnected (it preserves its data) | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \property QPieModelMapper::model |
|
49 | \property QPieModelMapper::model | |
50 | \brief Defines the model that is used by the mapper. |
|
50 | \brief Defines the model that is used by the mapper. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \property QPieModelMapper::first |
|
54 | \property QPieModelMapper::first | |
55 | \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie |
|
55 | \brief Defines which item of the model's row/column should be mapped as the value/label of the first slice of the pie | |
56 |
|
56 | |||
57 | Minimal and default value is: 0 |
|
57 | Minimal and default value is: 0 | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QPieModelMapper::count |
|
61 | \property QPieModelMapper::count | |
62 | \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. |
|
62 | \brief Defines the number of rows/columns of the model that are mapped as the data for the pie. | |
63 |
|
63 | |||
64 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
64 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Constructs a mapper object which is a child of \a parent. |
|
68 | Constructs a mapper object which is a child of \a parent. | |
69 | */ |
|
69 | */ | |
70 | QPieModelMapper::QPieModelMapper(QObject *parent) : |
|
70 | QPieModelMapper::QPieModelMapper(QObject *parent) : | |
71 | QObject(parent), |
|
71 | QObject(parent), | |
72 | d_ptr(new QPieModelMapperPrivate(this)) |
|
72 | d_ptr(new QPieModelMapperPrivate(this)) | |
73 | { |
|
73 | { | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | QAbstractItemModel* QPieModelMapper::model() const |
|
76 | QAbstractItemModel* QPieModelMapper::model() const | |
77 | { |
|
77 | { | |
78 | Q_D(const QPieModelMapper); |
|
78 | Q_D(const QPieModelMapper); | |
79 | return d->m_model; |
|
79 | return d->m_model; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void QPieModelMapper::setModel(QAbstractItemModel *model) |
|
82 | void QPieModelMapper::setModel(QAbstractItemModel *model) | |
83 | { |
|
83 | { | |
84 | if (model == 0) |
|
84 | if (model == 0) | |
85 | return; |
|
85 | return; | |
86 |
|
86 | |||
87 | Q_D(QPieModelMapper); |
|
87 | Q_D(QPieModelMapper); | |
88 | if (d->m_model) { |
|
88 | if (d->m_model) { | |
89 | disconnect(d->m_model, 0, d, 0); |
|
89 | disconnect(d->m_model, 0, d, 0); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | d->m_model = model; |
|
92 | d->m_model = model; | |
93 | d->initializePieFromModel(); |
|
93 | d->initializePieFromModel(); | |
94 | // connect signals from the model |
|
94 | // connect signals from the model | |
95 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
95 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
96 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
96 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
97 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
97 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
98 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
98 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
99 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
99 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
|
100 | ||||
|
101 | emit modelReplaced(); | |||
100 | } |
|
102 | } | |
101 |
|
103 | |||
102 | QPieSeries* QPieModelMapper::series() const |
|
104 | QPieSeries* QPieModelMapper::series() const | |
103 | { |
|
105 | { | |
104 | Q_D(const QPieModelMapper); |
|
106 | Q_D(const QPieModelMapper); | |
105 | return d->m_series; |
|
107 | return d->m_series; | |
106 | } |
|
108 | } | |
107 |
|
109 | |||
108 | void QPieModelMapper::setSeries(QPieSeries *series) |
|
110 | void QPieModelMapper::setSeries(QPieSeries *series) | |
109 | { |
|
111 | { | |
110 | Q_D(QPieModelMapper); |
|
112 | Q_D(QPieModelMapper); | |
111 | if (d->m_series) { |
|
113 | if (d->m_series) { | |
112 | disconnect(d->m_series, 0, d, 0); |
|
114 | disconnect(d->m_series, 0, d, 0); | |
113 | } |
|
115 | } | |
114 |
|
116 | |||
115 | if (series == 0) |
|
117 | if (series == 0) | |
116 | return; |
|
118 | return; | |
117 |
|
119 | |||
118 | d->m_series = series; |
|
120 | d->m_series = series; | |
119 | d->initializePieFromModel(); |
|
121 | d->initializePieFromModel(); | |
120 | // connect the signals from the series |
|
122 | // connect the signals from the series | |
121 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); |
|
123 | connect(d->m_series, SIGNAL(added(QList<QPieSlice*>)), d, SLOT(slicesAdded(QList<QPieSlice*>))); | |
122 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); |
|
124 | connect(d->m_series, SIGNAL(removed(QList<QPieSlice*>)), d, SLOT(slicesRemoved(QList<QPieSlice*>))); | |
|
125 | ||||
|
126 | emit seriesReplaced(); | |||
123 | } |
|
127 | } | |
124 |
|
128 | |||
125 | int QPieModelMapper::first() const |
|
129 | int QPieModelMapper::first() const | |
126 | { |
|
130 | { | |
127 | Q_D(const QPieModelMapper); |
|
131 | Q_D(const QPieModelMapper); | |
128 | return d->m_first; |
|
132 | return d->m_first; | |
129 | } |
|
133 | } | |
130 |
|
134 | |||
131 | void QPieModelMapper::setFirst(int first) |
|
135 | void QPieModelMapper::setFirst(int first) | |
132 | { |
|
136 | { | |
133 | Q_D(QPieModelMapper); |
|
137 | Q_D(QPieModelMapper); | |
|
138 | if (first != d->m_first) { | |||
134 | d->m_first = qMax(first, 0); |
|
139 | d->m_first = qMax(first, 0); | |
135 | d->initializePieFromModel(); |
|
140 | d->initializePieFromModel(); | |
|
141 | ||||
|
142 | emit firstChanged(); | |||
|
143 | } | |||
136 | } |
|
144 | } | |
137 |
|
145 | |||
138 | int QPieModelMapper::count() const |
|
146 | int QPieModelMapper::count() const | |
139 | { |
|
147 | { | |
140 | Q_D(const QPieModelMapper); |
|
148 | Q_D(const QPieModelMapper); | |
141 | return d->m_count; |
|
149 | return d->m_count; | |
142 | } |
|
150 | } | |
143 |
|
151 | |||
144 | void QPieModelMapper::setCount(int count) |
|
152 | void QPieModelMapper::setCount(int count) | |
145 | { |
|
153 | { | |
146 | Q_D(QPieModelMapper); |
|
154 | Q_D(QPieModelMapper); | |
|
155 | if (count != d->m_count) { | |||
147 | d->m_count = qMax(count, -1); |
|
156 | d->m_count = qMax(count, -1); | |
148 | d->initializePieFromModel(); |
|
157 | d->initializePieFromModel(); | |
|
158 | ||||
|
159 | emit countChanged(); | |||
|
160 | } | |||
149 | } |
|
161 | } | |
150 |
|
162 | |||
151 | /*! |
|
163 | /*! | |
152 | Returns the orientation that is used when QPieModelMapper accesses the model. |
|
164 | Returns the orientation that is used when QPieModelMapper accesses the model. | |
153 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
165 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
154 | or from columns (Qt::Vertical) |
|
166 | or from columns (Qt::Vertical) | |
155 | */ |
|
167 | */ | |
156 | Qt::Orientation QPieModelMapper::orientation() const |
|
168 | Qt::Orientation QPieModelMapper::orientation() const | |
157 | { |
|
169 | { | |
158 | Q_D(const QPieModelMapper); |
|
170 | Q_D(const QPieModelMapper); | |
159 | return d->m_orientation; |
|
171 | return d->m_orientation; | |
160 | } |
|
172 | } | |
161 |
|
173 | |||
162 | /*! |
|
174 | /*! | |
163 | Returns the \a orientation that is used when QPieModelMapper accesses the model. |
|
175 | Returns the \a orientation that is used when QPieModelMapper accesses the model. | |
164 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) |
|
176 | This mean whether the consecutive values/labels of the pie are read from row (Qt::Horizontal) | |
165 | or from columns (Qt::Vertical) |
|
177 | or from columns (Qt::Vertical) | |
166 | */ |
|
178 | */ | |
167 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) |
|
179 | void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |
168 | { |
|
180 | { | |
169 | Q_D(QPieModelMapper); |
|
181 | Q_D(QPieModelMapper); | |
170 | d->m_orientation = orientation; |
|
182 | d->m_orientation = orientation; | |
171 | d->initializePieFromModel(); |
|
183 | d->initializePieFromModel(); | |
172 | } |
|
184 | } | |
173 |
|
185 | |||
174 | /*! |
|
186 | /*! | |
175 | Returns which section of the model is kept in sync with the values of the pie's slices |
|
187 | Returns which section of the model is kept in sync with the values of the pie's slices | |
176 | */ |
|
188 | */ | |
177 | int QPieModelMapper::valuesSection() const |
|
189 | int QPieModelMapper::valuesSection() const | |
178 | { |
|
190 | { | |
179 | Q_D(const QPieModelMapper); |
|
191 | Q_D(const QPieModelMapper); | |
180 | return d->m_valuesSection; |
|
192 | return d->m_valuesSection; | |
181 | } |
|
193 | } | |
182 |
|
194 | |||
183 | /*! |
|
195 | /*! | |
184 | Sets the model section that is kept in sync with the pie slices values. |
|
196 | Sets the model section that is kept in sync with the pie slices values. | |
185 | Parameter \a valuesSection specifies the section of the model. |
|
197 | Parameter \a valuesSection specifies the section of the model. | |
186 | */ |
|
198 | */ | |
187 | void QPieModelMapper::setValuesSection(int valuesSection) |
|
199 | void QPieModelMapper::setValuesSection(int valuesSection) | |
188 | { |
|
200 | { | |
189 | Q_D(QPieModelMapper); |
|
201 | Q_D(QPieModelMapper); | |
190 | d->m_valuesSection = qMax(-1, valuesSection); |
|
202 | d->m_valuesSection = qMax(-1, valuesSection); | |
191 | d->initializePieFromModel(); |
|
203 | d->initializePieFromModel(); | |
192 | } |
|
204 | } | |
193 |
|
205 | |||
194 | /*! |
|
206 | /*! | |
195 | Returns which section of the model is kept in sync with the labels of the pie's slices |
|
207 | Returns which section of the model is kept in sync with the labels of the pie's slices | |
196 | */ |
|
208 | */ | |
197 | int QPieModelMapper::labelsSection() const |
|
209 | int QPieModelMapper::labelsSection() const | |
198 | { |
|
210 | { | |
199 | Q_D(const QPieModelMapper); |
|
211 | Q_D(const QPieModelMapper); | |
200 | return d->m_labelsSection; |
|
212 | return d->m_labelsSection; | |
201 | } |
|
213 | } | |
202 |
|
214 | |||
203 | /*! |
|
215 | /*! | |
204 | Sets the model section that is kept in sync with the pie slices labels. |
|
216 | Sets the model section that is kept in sync with the pie slices labels. | |
205 | Parameter \a labelsSection specifies the section of the model. |
|
217 | Parameter \a labelsSection specifies the section of the model. | |
206 | */ |
|
218 | */ | |
207 | void QPieModelMapper::setLabelsSection(int labelsSection) |
|
219 | void QPieModelMapper::setLabelsSection(int labelsSection) | |
208 | { |
|
220 | { | |
209 | Q_D(QPieModelMapper); |
|
221 | Q_D(QPieModelMapper); | |
210 | d->m_labelsSection = qMax(-1, labelsSection); |
|
222 | d->m_labelsSection = qMax(-1, labelsSection); | |
211 | d->initializePieFromModel(); |
|
223 | d->initializePieFromModel(); | |
212 | } |
|
224 | } | |
213 |
|
225 | |||
214 | /*! |
|
226 | /*! | |
215 | Resets the QPieModelMapper to the default state. |
|
227 | Resets the QPieModelMapper to the default state. | |
216 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; |
|
228 | first: 0; count: -1; valuesSection: -1; labelsSection: -1; | |
217 | */ |
|
229 | */ | |
218 | void QPieModelMapper::reset() |
|
230 | void QPieModelMapper::reset() | |
219 | { |
|
231 | { | |
220 | Q_D(QPieModelMapper); |
|
232 | Q_D(QPieModelMapper); | |
221 | d->m_first = 0; |
|
233 | d->m_first = 0; | |
222 | d->m_count = -1; |
|
234 | d->m_count = -1; | |
223 | d->m_valuesSection = -1; |
|
235 | d->m_valuesSection = -1; | |
224 | d->m_labelsSection = -1; |
|
236 | d->m_labelsSection = -1; | |
225 | } |
|
237 | } | |
226 |
|
238 | |||
227 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
239 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
228 |
|
240 | |||
229 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : |
|
241 | QPieModelMapperPrivate::QPieModelMapperPrivate(QPieModelMapper *q) : | |
230 | m_series(0), |
|
242 | m_series(0), | |
231 | m_model(0), |
|
243 | m_model(0), | |
232 | m_first(0), |
|
244 | m_first(0), | |
233 | m_count(-1), |
|
245 | m_count(-1), | |
234 | m_orientation(Qt::Vertical), |
|
246 | m_orientation(Qt::Vertical), | |
235 | m_valuesSection(-1), |
|
247 | m_valuesSection(-1), | |
236 | m_labelsSection(-1), |
|
248 | m_labelsSection(-1), | |
237 | m_seriesSignalsBlock(false), |
|
249 | m_seriesSignalsBlock(false), | |
238 | m_modelSignalsBlock(false), |
|
250 | m_modelSignalsBlock(false), | |
239 | q_ptr(q) |
|
251 | q_ptr(q) | |
240 | { |
|
252 | { | |
241 | } |
|
253 | } | |
242 |
|
254 | |||
243 | void QPieModelMapperPrivate::blockModelSignals(bool block) |
|
255 | void QPieModelMapperPrivate::blockModelSignals(bool block) | |
244 | { |
|
256 | { | |
245 | m_modelSignalsBlock = block; |
|
257 | m_modelSignalsBlock = block; | |
246 | } |
|
258 | } | |
247 |
|
259 | |||
248 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) |
|
260 | void QPieModelMapperPrivate::blockSeriesSignals(bool block) | |
249 | { |
|
261 | { | |
250 | m_seriesSignalsBlock = block; |
|
262 | m_seriesSignalsBlock = block; | |
251 | } |
|
263 | } | |
252 |
|
264 | |||
253 |
|
265 | |||
254 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const |
|
266 | QPieSlice* QPieModelMapperPrivate::pieSlice(QModelIndex index) const | |
255 | { |
|
267 | { | |
256 | if (!index.isValid()) |
|
268 | if (!index.isValid()) | |
257 | return 0; // index is invalid |
|
269 | return 0; // index is invalid | |
258 |
|
270 | |||
259 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { |
|
271 | if (m_orientation == Qt::Vertical && (index.column() == m_valuesSection || index.column() == m_labelsSection)) { | |
260 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
272 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
261 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
273 | if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
262 | return m_series->slices().at(index.row() - m_first); |
|
274 | return m_series->slices().at(index.row() - m_first); | |
263 | else |
|
275 | else | |
264 | return 0; |
|
276 | return 0; | |
265 | } |
|
277 | } | |
266 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { |
|
278 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_valuesSection || index.row() == m_labelsSection)) { | |
267 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
279 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
268 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) |
|
280 | if (m_model->index(m_valuesSection, index.column()).isValid() && m_model->index(m_labelsSection, index.column()).isValid()) | |
269 | return m_series->slices().at(index.column() - m_first); |
|
281 | return m_series->slices().at(index.column() - m_first); | |
270 | else |
|
282 | else | |
271 | return 0; |
|
283 | return 0; | |
272 | } |
|
284 | } | |
273 | } |
|
285 | } | |
274 | return 0; // This part of model has not been mapped to any slice |
|
286 | return 0; // This part of model has not been mapped to any slice | |
275 | } |
|
287 | } | |
276 |
|
288 | |||
277 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) |
|
289 | QModelIndex QPieModelMapperPrivate::valueModelIndex(int slicePos) | |
278 | { |
|
290 | { | |
279 | if (m_count != -1 && slicePos >= m_count) |
|
291 | if (m_count != -1 && slicePos >= m_count) | |
280 | return QModelIndex(); // invalid |
|
292 | return QModelIndex(); // invalid | |
281 |
|
293 | |||
282 | if (m_orientation == Qt::Vertical) |
|
294 | if (m_orientation == Qt::Vertical) | |
283 | return m_model->index(slicePos + m_first, m_valuesSection); |
|
295 | return m_model->index(slicePos + m_first, m_valuesSection); | |
284 | else |
|
296 | else | |
285 | return m_model->index(m_valuesSection, slicePos + m_first); |
|
297 | return m_model->index(m_valuesSection, slicePos + m_first); | |
286 | } |
|
298 | } | |
287 |
|
299 | |||
288 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) |
|
300 | QModelIndex QPieModelMapperPrivate::labelModelIndex(int slicePos) | |
289 | { |
|
301 | { | |
290 | if (m_count != -1 && slicePos >= m_count) |
|
302 | if (m_count != -1 && slicePos >= m_count) | |
291 | return QModelIndex(); // invalid |
|
303 | return QModelIndex(); // invalid | |
292 |
|
304 | |||
293 | if (m_orientation == Qt::Vertical) |
|
305 | if (m_orientation == Qt::Vertical) | |
294 | return m_model->index(slicePos + m_first, m_labelsSection); |
|
306 | return m_model->index(slicePos + m_first, m_labelsSection); | |
295 | else |
|
307 | else | |
296 | return m_model->index(m_labelsSection, slicePos + m_first); |
|
308 | return m_model->index(m_labelsSection, slicePos + m_first); | |
297 | } |
|
309 | } | |
298 |
|
310 | |||
299 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const |
|
311 | bool QPieModelMapperPrivate::isLabelIndex(QModelIndex index) const | |
300 | { |
|
312 | { | |
301 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) |
|
313 | if (m_orientation == Qt::Vertical && index.column() == m_labelsSection) | |
302 | return true; |
|
314 | return true; | |
303 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) |
|
315 | else if (m_orientation == Qt::Horizontal && index.row() == m_labelsSection) | |
304 | return true; |
|
316 | return true; | |
305 |
|
317 | |||
306 | return false; |
|
318 | return false; | |
307 | } |
|
319 | } | |
308 |
|
320 | |||
309 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const |
|
321 | bool QPieModelMapperPrivate::isValueIndex(QModelIndex index) const | |
310 | { |
|
322 | { | |
311 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) |
|
323 | if (m_orientation == Qt::Vertical && index.column() == m_valuesSection) | |
312 | return true; |
|
324 | return true; | |
313 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) |
|
325 | else if (m_orientation == Qt::Horizontal && index.row() == m_valuesSection) | |
314 | return true; |
|
326 | return true; | |
315 |
|
327 | |||
316 | return false; |
|
328 | return false; | |
317 | } |
|
329 | } | |
318 |
|
330 | |||
319 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) |
|
331 | void QPieModelMapperPrivate::slicesAdded(QList<QPieSlice*> slices) | |
320 | { |
|
332 | { | |
321 | if (m_seriesSignalsBlock) |
|
333 | if (m_seriesSignalsBlock) | |
322 | return; |
|
334 | return; | |
323 |
|
335 | |||
324 | if (slices.count() == 0) |
|
336 | if (slices.count() == 0) | |
325 | return; |
|
337 | return; | |
326 |
|
338 | |||
327 | int firstIndex = m_series->slices().indexOf(slices.at(0)); |
|
339 | int firstIndex = m_series->slices().indexOf(slices.at(0)); | |
328 | if (firstIndex == -1) |
|
340 | if (firstIndex == -1) | |
329 | return; |
|
341 | return; | |
330 |
|
342 | |||
331 | if (m_count != -1) |
|
343 | if (m_count != -1) | |
332 | m_count += slices.count(); |
|
344 | m_count += slices.count(); | |
333 |
|
345 | |||
334 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
346 | for (int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
335 | m_slices.insert(i, slices.at(i - firstIndex)); |
|
347 | m_slices.insert(i, slices.at(i - firstIndex)); | |
336 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
348 | connect(slices.at(i - firstIndex), SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
337 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
349 | connect(slices.at(i - firstIndex), SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
338 | } |
|
350 | } | |
339 |
|
351 | |||
340 | blockModelSignals(); |
|
352 | blockModelSignals(); | |
341 | if (m_orientation == Qt::Vertical) |
|
353 | if (m_orientation == Qt::Vertical) | |
342 | m_model->insertRows(firstIndex + m_first, slices.count()); |
|
354 | m_model->insertRows(firstIndex + m_first, slices.count()); | |
343 | else |
|
355 | else | |
344 | m_model->insertColumns(firstIndex + m_first, slices.count()); |
|
356 | m_model->insertColumns(firstIndex + m_first, slices.count()); | |
345 |
|
357 | |||
346 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { |
|
358 | for(int i = firstIndex; i < firstIndex + slices.count(); i++) { | |
347 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); |
|
359 | m_model->setData(valueModelIndex(i), slices.at(i - firstIndex)->value()); | |
348 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); |
|
360 | m_model->setData(labelModelIndex(i), slices.at(i - firstIndex)->label()); | |
349 | } |
|
361 | } | |
350 | blockModelSignals(false); |
|
362 | blockModelSignals(false); | |
351 | } |
|
363 | } | |
352 |
|
364 | |||
353 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) |
|
365 | void QPieModelMapperPrivate::slicesRemoved(QList<QPieSlice*> slices) | |
354 | { |
|
366 | { | |
355 | if (m_seriesSignalsBlock) |
|
367 | if (m_seriesSignalsBlock) | |
356 | return; |
|
368 | return; | |
357 |
|
369 | |||
358 | if (slices.count() == 0) |
|
370 | if (slices.count() == 0) | |
359 | return; |
|
371 | return; | |
360 |
|
372 | |||
361 | int firstIndex = m_slices.indexOf(slices.at(0)); |
|
373 | int firstIndex = m_slices.indexOf(slices.at(0)); | |
362 | if (firstIndex == -1) |
|
374 | if (firstIndex == -1) | |
363 | return; |
|
375 | return; | |
364 |
|
376 | |||
365 | if (m_count != -1) |
|
377 | if (m_count != -1) | |
366 | m_count -= slices.count(); |
|
378 | m_count -= slices.count(); | |
367 |
|
379 | |||
368 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) |
|
380 | for (int i = firstIndex + slices.count() - 1; i >= firstIndex; i--) | |
369 | m_slices.removeAt(i); |
|
381 | m_slices.removeAt(i); | |
370 |
|
382 | |||
371 | blockModelSignals(); |
|
383 | blockModelSignals(); | |
372 | if (m_orientation == Qt::Vertical) |
|
384 | if (m_orientation == Qt::Vertical) | |
373 | m_model->removeRows(firstIndex + m_first, slices.count()); |
|
385 | m_model->removeRows(firstIndex + m_first, slices.count()); | |
374 | else |
|
386 | else | |
375 | m_model->removeColumns(firstIndex + m_first, slices.count()); |
|
387 | m_model->removeColumns(firstIndex + m_first, slices.count()); | |
376 | blockModelSignals(false); |
|
388 | blockModelSignals(false); | |
377 | } |
|
389 | } | |
378 |
|
390 | |||
379 | void QPieModelMapperPrivate::sliceLabelChanged() |
|
391 | void QPieModelMapperPrivate::sliceLabelChanged() | |
380 | { |
|
392 | { | |
381 | if (m_seriesSignalsBlock) |
|
393 | if (m_seriesSignalsBlock) | |
382 | return; |
|
394 | return; | |
383 |
|
395 | |||
384 | blockModelSignals(); |
|
396 | blockModelSignals(); | |
385 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
397 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
386 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); |
|
398 | m_model->setData(labelModelIndex(m_series->slices().indexOf(slice)), slice->label()); | |
387 | blockModelSignals(false); |
|
399 | blockModelSignals(false); | |
388 | } |
|
400 | } | |
389 |
|
401 | |||
390 | void QPieModelMapperPrivate::sliceValueChanged() |
|
402 | void QPieModelMapperPrivate::sliceValueChanged() | |
391 | { |
|
403 | { | |
392 | if (m_seriesSignalsBlock) |
|
404 | if (m_seriesSignalsBlock) | |
393 | return; |
|
405 | return; | |
394 |
|
406 | |||
395 | blockModelSignals(); |
|
407 | blockModelSignals(); | |
396 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); |
|
408 | QPieSlice *slice = qobject_cast<QPieSlice *>(QObject::sender()); | |
397 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); |
|
409 | m_model->setData(valueModelIndex(m_series->slices().indexOf(slice)), slice->value()); | |
398 | blockModelSignals(false); |
|
410 | blockModelSignals(false); | |
399 | } |
|
411 | } | |
400 |
|
412 | |||
401 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
413 | void QPieModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
402 | { |
|
414 | { | |
403 | if (m_model == 0 || m_series == 0) |
|
415 | if (m_model == 0 || m_series == 0) | |
404 | return; |
|
416 | return; | |
405 |
|
417 | |||
406 | if (m_modelSignalsBlock) |
|
418 | if (m_modelSignalsBlock) | |
407 | return; |
|
419 | return; | |
408 |
|
420 | |||
409 | blockSeriesSignals(); |
|
421 | blockSeriesSignals(); | |
410 | QModelIndex index; |
|
422 | QModelIndex index; | |
411 | QPieSlice *slice; |
|
423 | QPieSlice *slice; | |
412 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
424 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
413 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
425 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
414 | index = topLeft.sibling(row, column); |
|
426 | index = topLeft.sibling(row, column); | |
415 | slice = pieSlice(index); |
|
427 | slice = pieSlice(index); | |
416 | if (slice) { |
|
428 | if (slice) { | |
417 | if (isValueIndex(index)) |
|
429 | if (isValueIndex(index)) | |
418 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); |
|
430 | slice->setValue(m_model->data(index, Qt::DisplayRole).toReal()); | |
419 | if (isLabelIndex(index)) |
|
431 | if (isLabelIndex(index)) | |
420 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); |
|
432 | slice->setLabel(m_model->data(index, Qt::DisplayRole).toString()); | |
421 | } |
|
433 | } | |
422 | } |
|
434 | } | |
423 | } |
|
435 | } | |
424 | blockSeriesSignals(false); |
|
436 | blockSeriesSignals(false); | |
425 | } |
|
437 | } | |
426 |
|
438 | |||
427 |
|
439 | |||
428 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
440 | void QPieModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
429 | { |
|
441 | { | |
430 | Q_UNUSED(parent); |
|
442 | Q_UNUSED(parent); | |
431 | if (m_modelSignalsBlock) |
|
443 | if (m_modelSignalsBlock) | |
432 | return; |
|
444 | return; | |
433 |
|
445 | |||
434 | blockSeriesSignals(); |
|
446 | blockSeriesSignals(); | |
435 | if (m_orientation == Qt::Vertical) |
|
447 | if (m_orientation == Qt::Vertical) | |
436 | insertData(start, end); |
|
448 | insertData(start, end); | |
437 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
449 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
438 | initializePieFromModel(); |
|
450 | initializePieFromModel(); | |
439 | blockSeriesSignals(false); |
|
451 | blockSeriesSignals(false); | |
440 | } |
|
452 | } | |
441 |
|
453 | |||
442 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
454 | void QPieModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
443 | { |
|
455 | { | |
444 | Q_UNUSED(parent); |
|
456 | Q_UNUSED(parent); | |
445 | if (m_modelSignalsBlock) |
|
457 | if (m_modelSignalsBlock) | |
446 | return; |
|
458 | return; | |
447 |
|
459 | |||
448 | blockSeriesSignals(); |
|
460 | blockSeriesSignals(); | |
449 | if (m_orientation == Qt::Vertical) |
|
461 | if (m_orientation == Qt::Vertical) | |
450 | removeData(start, end); |
|
462 | removeData(start, end); | |
451 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
463 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
452 | initializePieFromModel(); |
|
464 | initializePieFromModel(); | |
453 | blockSeriesSignals(false); |
|
465 | blockSeriesSignals(false); | |
454 | } |
|
466 | } | |
455 |
|
467 | |||
456 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
468 | void QPieModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
457 | { |
|
469 | { | |
458 | Q_UNUSED(parent); |
|
470 | Q_UNUSED(parent); | |
459 | if (m_modelSignalsBlock) |
|
471 | if (m_modelSignalsBlock) | |
460 | return; |
|
472 | return; | |
461 |
|
473 | |||
462 | blockSeriesSignals(); |
|
474 | blockSeriesSignals(); | |
463 | if (m_orientation == Qt::Horizontal) |
|
475 | if (m_orientation == Qt::Horizontal) | |
464 | insertData(start, end); |
|
476 | insertData(start, end); | |
465 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
477 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
466 | initializePieFromModel(); |
|
478 | initializePieFromModel(); | |
467 | blockSeriesSignals(false); |
|
479 | blockSeriesSignals(false); | |
468 | } |
|
480 | } | |
469 |
|
481 | |||
470 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
482 | void QPieModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
471 | { |
|
483 | { | |
472 | Q_UNUSED(parent); |
|
484 | Q_UNUSED(parent); | |
473 | if (m_modelSignalsBlock) |
|
485 | if (m_modelSignalsBlock) | |
474 | return; |
|
486 | return; | |
475 |
|
487 | |||
476 | blockSeriesSignals(); |
|
488 | blockSeriesSignals(); | |
477 | if (m_orientation == Qt::Horizontal) |
|
489 | if (m_orientation == Qt::Horizontal) | |
478 | removeData(start, end); |
|
490 | removeData(start, end); | |
479 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie |
|
491 | else if (start <= m_valuesSection || start <= m_labelsSection) // if the changes affect the map - reinitialize the pie | |
480 | initializePieFromModel(); |
|
492 | initializePieFromModel(); | |
481 | blockSeriesSignals(false); |
|
493 | blockSeriesSignals(false); | |
482 | } |
|
494 | } | |
483 |
|
495 | |||
484 | void QPieModelMapperPrivate::insertData(int start, int end) |
|
496 | void QPieModelMapperPrivate::insertData(int start, int end) | |
485 | { |
|
497 | { | |
486 | if (m_model == 0 || m_series == 0) |
|
498 | if (m_model == 0 || m_series == 0) | |
487 | return; |
|
499 | return; | |
488 |
|
500 | |||
489 | if (m_count != -1 && start >= m_first + m_count) { |
|
501 | if (m_count != -1 && start >= m_first + m_count) { | |
490 | return; |
|
502 | return; | |
491 | } else { |
|
503 | } else { | |
492 | int addedCount = end - start + 1; |
|
504 | int addedCount = end - start + 1; | |
493 | if (m_count != -1 && addedCount > m_count) |
|
505 | if (m_count != -1 && addedCount > m_count) | |
494 | addedCount = m_count; |
|
506 | addedCount = m_count; | |
495 | int first = qMax(start, m_first); |
|
507 | int first = qMax(start, m_first); | |
496 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
508 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
497 | for (int i = first; i <= last; i++) { |
|
509 | for (int i = first; i <= last; i++) { | |
498 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
510 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
499 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
511 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
500 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
512 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
501 | QPieSlice *slice = new QPieSlice; |
|
513 | QPieSlice *slice = new QPieSlice; | |
502 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
514 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
503 |
slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
515 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
504 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
516 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
505 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
517 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
506 | m_series->insert(i - m_first, slice); |
|
518 | m_series->insert(i - m_first, slice); | |
507 | m_slices.insert(i - m_first, slice); |
|
519 | m_slices.insert(i - m_first, slice); | |
508 | } |
|
520 | } | |
509 | } |
|
521 | } | |
510 |
|
522 | |||
511 | // remove excess of slices (abouve m_count) |
|
523 | // remove excess of slices (abouve m_count) | |
512 | if (m_count != -1 && m_series->slices().size() > m_count) |
|
524 | if (m_count != -1 && m_series->slices().size() > m_count) | |
513 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { |
|
525 | for (int i = m_series->slices().size() - 1; i >= m_count; i--) { | |
514 | m_series->remove(m_series->slices().at(i)); |
|
526 | m_series->remove(m_series->slices().at(i)); | |
515 | m_slices.removeAt(i); |
|
527 | m_slices.removeAt(i); | |
516 | } |
|
528 | } | |
517 | } |
|
529 | } | |
518 | } |
|
530 | } | |
519 |
|
531 | |||
520 | void QPieModelMapperPrivate::removeData(int start, int end) |
|
532 | void QPieModelMapperPrivate::removeData(int start, int end) | |
521 | { |
|
533 | { | |
522 | if (m_model == 0 || m_series == 0) |
|
534 | if (m_model == 0 || m_series == 0) | |
523 | return; |
|
535 | return; | |
524 |
|
536 | |||
525 | int removedCount = end - start + 1; |
|
537 | int removedCount = end - start + 1; | |
526 | if (m_count != -1 && start >= m_first + m_count) { |
|
538 | if (m_count != -1 && start >= m_first + m_count) { | |
527 | return; |
|
539 | return; | |
528 | } else { |
|
540 | } else { | |
529 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed |
|
541 | int toRemove = qMin(m_series->slices().size(), removedCount); // first find how many items can actually be removed | |
530 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
542 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
531 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. |
|
543 | int last = qMin(first + toRemove - 1, m_series->slices().size() + m_first - 1); // get the index of the last item that will be removed. | |
532 | for (int i = last; i >= first; i--) { |
|
544 | for (int i = last; i >= first; i--) { | |
533 | m_series->remove(m_series->slices().at(i - m_first)); |
|
545 | m_series->remove(m_series->slices().at(i - m_first)); | |
534 | m_slices.removeAt(i - m_first); |
|
546 | m_slices.removeAt(i - m_first); | |
535 | } |
|
547 | } | |
536 |
|
548 | |||
537 | if (m_count != -1) { |
|
549 | if (m_count != -1) { | |
538 | int itemsAvailable; // check how many are available to be added |
|
550 | int itemsAvailable; // check how many are available to be added | |
539 | if (m_orientation == Qt::Vertical) |
|
551 | if (m_orientation == Qt::Vertical) | |
540 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); |
|
552 | itemsAvailable = m_model->rowCount() - m_first - m_series->slices().size(); | |
541 | else |
|
553 | else | |
542 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); |
|
554 | itemsAvailable = m_model->columnCount() - m_first - m_series->slices().size(); | |
543 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. |
|
555 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->slices().size()); // add not more items than there is space left to be filled. | |
544 | int currentSize = m_series->slices().size(); |
|
556 | int currentSize = m_series->slices().size(); | |
545 | if (toBeAdded > 0) |
|
557 | if (toBeAdded > 0) | |
546 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { |
|
558 | for (int i = m_series->slices().size(); i < currentSize + toBeAdded; i++) { | |
547 | QModelIndex valueIndex = valueModelIndex(i - m_first); |
|
559 | QModelIndex valueIndex = valueModelIndex(i - m_first); | |
548 | QModelIndex labelIndex = labelModelIndex(i - m_first); |
|
560 | QModelIndex labelIndex = labelModelIndex(i - m_first); | |
549 | if (valueIndex.isValid() && labelIndex.isValid()) { |
|
561 | if (valueIndex.isValid() && labelIndex.isValid()) { | |
550 | QPieSlice *slice = new QPieSlice; |
|
562 | QPieSlice *slice = new QPieSlice; | |
551 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
563 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
552 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
564 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
553 | m_series->insert(i, slice); |
|
565 | m_series->insert(i, slice); | |
554 | m_slices.insert(i, slice); |
|
566 | m_slices.insert(i, slice); | |
555 | } |
|
567 | } | |
556 | } |
|
568 | } | |
557 | } |
|
569 | } | |
558 | } |
|
570 | } | |
559 | } |
|
571 | } | |
560 |
|
572 | |||
561 | void QPieModelMapperPrivate::initializePieFromModel() |
|
573 | void QPieModelMapperPrivate::initializePieFromModel() | |
562 | { |
|
574 | { | |
563 | if (m_model == 0 || m_series == 0) |
|
575 | if (m_model == 0 || m_series == 0) | |
564 | return; |
|
576 | return; | |
565 |
|
577 | |||
566 | blockSeriesSignals(); |
|
578 | blockSeriesSignals(); | |
567 | // clear current content |
|
579 | // clear current content | |
568 | m_series->clear(); |
|
580 | m_series->clear(); | |
569 | m_slices.clear(); |
|
581 | m_slices.clear(); | |
570 |
|
582 | |||
571 | // create the initial slices set |
|
583 | // create the initial slices set | |
572 | int slicePos = 0; |
|
584 | int slicePos = 0; | |
573 | QModelIndex valueIndex = valueModelIndex(slicePos); |
|
585 | QModelIndex valueIndex = valueModelIndex(slicePos); | |
574 | QModelIndex labelIndex = labelModelIndex(slicePos); |
|
586 | QModelIndex labelIndex = labelModelIndex(slicePos); | |
575 | while (valueIndex.isValid() && labelIndex.isValid()) { |
|
587 | while (valueIndex.isValid() && labelIndex.isValid()) { | |
576 | QPieSlice *slice = new QPieSlice; |
|
588 | QPieSlice *slice = new QPieSlice; | |
577 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); |
|
589 | slice->setLabel(m_model->data(labelIndex, Qt::DisplayRole).toString()); | |
578 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); |
|
590 | slice->setValue(m_model->data(valueIndex, Qt::DisplayRole).toDouble()); | |
579 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); |
|
591 | connect(slice, SIGNAL(labelChanged()), this, SLOT(sliceLabelChanged())); | |
580 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); |
|
592 | connect(slice, SIGNAL(valueChanged()), this, SLOT(sliceValueChanged())); | |
581 | m_series->append(slice); |
|
593 | m_series->append(slice); | |
582 | m_slices.append(slice); |
|
594 | m_slices.append(slice); | |
583 | slicePos++; |
|
595 | slicePos++; | |
584 | valueIndex = valueModelIndex(slicePos); |
|
596 | valueIndex = valueModelIndex(slicePos); | |
585 | labelIndex = labelModelIndex(slicePos); |
|
597 | labelIndex = labelModelIndex(slicePos); | |
586 |
} |
|
598 | } | |
587 | blockSeriesSignals(false); |
|
599 | blockSeriesSignals(false); | |
588 | } |
|
600 | } | |
589 |
|
601 | |||
590 | #include "moc_qpiemodelmapper_p.cpp" |
|
602 | #include "moc_qpiemodelmapper_p.cpp" | |
591 | #include "moc_qpiemodelmapper.cpp" |
|
603 | #include "moc_qpiemodelmapper.cpp" | |
592 |
|
604 | |||
593 | QTCOMMERCIALCHART_END_NAMESPACE |
|
605 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,84 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QPIEMODELMAPPER_H |
|
21 | #ifndef QPIEMODELMAPPER_H | |
22 | #define QPIEMODELMAPPER_H |
|
22 | #define QPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 |
|
26 | |||
27 | class QAbstractItemModel; |
|
27 | class QAbstractItemModel; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QPieModelMapperPrivate; |
|
31 | class QPieModelMapperPrivate; | |
32 | class QPieSeries; |
|
32 | class QPieSeries; | |
33 |
|
33 | |||
34 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QPieModelMapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries) |
|
37 | Q_PROPERTY(QPieSeries *series READ series WRITE setSeries NOTIFY seriesReplaced) | |
38 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) |
|
38 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced) | |
39 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
39 | Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged) | |
40 | Q_PROPERTY(int count READ count WRITE setCount) |
|
40 | Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged) | |
41 | Q_ENUMS(Qt::Orientation) |
|
41 | Q_ENUMS(Qt::Orientation) | |
42 |
|
42 | |||
43 | protected: |
|
43 | protected: | |
44 | QPieModelMapper(QObject *parent = 0); |
|
44 | QPieModelMapper(QObject *parent = 0); | |
45 |
|
45 | |||
46 | public: |
|
46 | public: | |
47 | QAbstractItemModel* model() const; |
|
47 | QAbstractItemModel* model() const; | |
48 | void setModel(QAbstractItemModel *model); |
|
48 | void setModel(QAbstractItemModel *model); | |
49 |
|
49 | |||
50 | QPieSeries* series() const; |
|
50 | QPieSeries* series() const; | |
51 | void setSeries(QPieSeries *series); |
|
51 | void setSeries(QPieSeries *series); | |
52 |
|
52 | |||
53 | int first() const; |
|
53 | int first() const; | |
54 | void setFirst(int first); |
|
54 | void setFirst(int first); | |
55 |
|
55 | |||
56 | int count() const; |
|
56 | int count() const; | |
57 | void setCount(int count); |
|
57 | void setCount(int count); | |
58 |
|
58 | |||
59 | void reset(); |
|
59 | void reset(); | |
60 |
|
60 | |||
61 | protected: |
|
61 | protected: | |
62 | int valuesSection() const; |
|
62 | int valuesSection() const; | |
63 | void setValuesSection(int valuesSection); |
|
63 | void setValuesSection(int valuesSection); | |
64 |
|
64 | |||
65 | int labelsSection() const; |
|
65 | int labelsSection() const; | |
66 | void setLabelsSection(int labelsSection); |
|
66 | void setLabelsSection(int labelsSection); | |
67 |
|
67 | |||
68 | Qt::Orientation orientation() const; |
|
68 | Qt::Orientation orientation() const; | |
69 | void setOrientation(Qt::Orientation orientation); |
|
69 | void setOrientation(Qt::Orientation orientation); | |
70 |
|
70 | |||
|
71 | Q_SIGNALS: | |||
|
72 | void seriesReplaced(); | |||
|
73 | void modelReplaced(); | |||
|
74 | void firstChanged(); | |||
|
75 | void countChanged(); | |||
|
76 | ||||
71 | protected: |
|
77 | protected: | |
72 | QPieModelMapperPrivate * const d_ptr; |
|
78 | QPieModelMapperPrivate * const d_ptr; | |
73 | Q_DECLARE_PRIVATE(QPieModelMapper) |
|
79 | Q_DECLARE_PRIVATE(QPieModelMapper) | |
74 | }; |
|
80 | }; | |
75 |
|
81 | |||
76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
82 | QTCOMMERCIALCHART_END_NAMESPACE | |
77 |
|
83 | |||
78 | #endif // QPIEMODELMAPPER_H |
|
84 | #endif // QPIEMODELMAPPER_H |
@@ -1,95 +1,101 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvpiemodelmapper.h" |
|
21 | #include "qvpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVPieModelMapper |
|
26 | \class QVPieModelMapper | |
27 | \brief part of QtCommercial chart API. |
|
27 | \brief part of QtCommercial chart API. | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. |
|
31 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. | |
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. |
|
32 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. | |
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
33 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \property QVPieModelMapper::valuesColumn |
|
37 | \property QVPieModelMapper::valuesColumn | |
38 | \brief Defines which column of the model is kept in sync with the values of the pie's slices |
|
38 | \brief Defines which column of the model is kept in sync with the values of the pie's slices | |
39 |
|
39 | |||
40 | Default value is: -1 (invalid mapping) |
|
40 | Default value is: -1 (invalid mapping) | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \property QVPieModelMapper::labelsColumn |
|
44 | \property QVPieModelMapper::labelsColumn | |
45 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices |
|
45 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices | |
46 |
|
46 | |||
47 | Default value is: -1 (invalid mapping) |
|
47 | Default value is: -1 (invalid mapping) | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | Constructs a mapper object which is a child of \a parent. |
|
51 | Constructs a mapper object which is a child of \a parent. | |
52 | */ |
|
52 | */ | |
53 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : |
|
53 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : | |
54 | QPieModelMapper(parent) |
|
54 | QPieModelMapper(parent) | |
55 | { |
|
55 | { | |
56 | QPieModelMapper::setOrientation(Qt::Vertical); |
|
56 | QPieModelMapper::setOrientation(Qt::Vertical); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | Returns which column of the model is kept in sync with the values of the pie's slices |
|
60 | Returns which column of the model is kept in sync with the values of the pie's slices | |
61 | */ |
|
61 | */ | |
62 | int QVPieModelMapper::valuesColumn() const |
|
62 | int QVPieModelMapper::valuesColumn() const | |
63 | { |
|
63 | { | |
64 | return QPieModelMapper::valuesSection(); |
|
64 | return QPieModelMapper::valuesSection(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Sets the model column that is kept in sync with the pie slices values. |
|
68 | Sets the model column that is kept in sync with the pie slices values. | |
69 | Parameter \a valuesColumn specifies the row of the model. |
|
69 | Parameter \a valuesColumn specifies the row of the model. | |
70 | */ |
|
70 | */ | |
71 | void QVPieModelMapper::setValuesColumn(int valuesColumn) |
|
71 | void QVPieModelMapper::setValuesColumn(int valuesColumn) | |
72 | { |
|
72 | { | |
|
73 | if (valuesColumn != valuesSection()) { | |||
73 | QPieModelMapper::setValuesSection(valuesColumn); |
|
74 | QPieModelMapper::setValuesSection(valuesColumn); | |
|
75 | emit valuesColumnChanged(); | |||
|
76 | } | |||
74 | } |
|
77 | } | |
75 |
|
78 | |||
76 | /*! |
|
79 | /*! | |
77 | Returns which column of the model is kept in sync with the labels of the pie's slices |
|
80 | Returns which column of the model is kept in sync with the labels of the pie's slices | |
78 | */ |
|
81 | */ | |
79 | int QVPieModelMapper::labelsColumn() const |
|
82 | int QVPieModelMapper::labelsColumn() const | |
80 | { |
|
83 | { | |
81 | return QPieModelMapper::labelsSection(); |
|
84 | return QPieModelMapper::labelsSection(); | |
82 | } |
|
85 | } | |
83 |
|
86 | |||
84 | /*! |
|
87 | /*! | |
85 | Sets the model column that is kept in sync with the pie's slices labels. |
|
88 | Sets the model column that is kept in sync with the pie's slices labels. | |
86 | Parameter \a labelsColumn specifies the row of the model. |
|
89 | Parameter \a labelsColumn specifies the row of the model. | |
87 | */ |
|
90 | */ | |
88 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) |
|
91 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) | |
89 | { |
|
92 | { | |
|
93 | if (labelsColumn != labelsSection()) { | |||
90 | QPieModelMapper::setLabelsSection(labelsColumn); |
|
94 | QPieModelMapper::setLabelsSection(labelsColumn); | |
|
95 | emit labelsColumnChanged(); | |||
|
96 | } | |||
91 | } |
|
97 | } | |
92 |
|
98 | |||
93 | #include "moc_qvpiemodelmapper.cpp" |
|
99 | #include "moc_qvpiemodelmapper.cpp" | |
94 |
|
100 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,46 +1,50 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QVPIEMODELMAPPER_H |
|
21 | #ifndef QVPIEMODELMAPPER_H | |
22 | #define QVPIEMODELMAPPER_H |
|
22 | #define QVPIEMODELMAPPER_H | |
23 |
|
23 | |||
24 | #include "qpiemodelmapper.h" |
|
24 | #include "qpiemodelmapper.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper |
|
28 | class QTCOMMERCIALCHART_EXPORT QVPieModelMapper : public QPieModelMapper | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn) |
|
31 | Q_PROPERTY(int valuesColumn READ valuesColumn WRITE setValuesColumn NOTIFY valuesColumnChanged) | |
32 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn) |
|
32 | Q_PROPERTY(int labelsColumn READ labelsColumn WRITE setLabelsColumn NOTIFY labelsColumnChanged) | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QVPieModelMapper(QObject *parent = 0); |
|
35 | explicit QVPieModelMapper(QObject *parent = 0); | |
36 |
|
36 | |||
37 | int valuesColumn() const; |
|
37 | int valuesColumn() const; | |
38 | void setValuesColumn(int valuesColumn); |
|
38 | void setValuesColumn(int valuesColumn); | |
39 |
|
39 | |||
40 | int labelsColumn() const; |
|
40 | int labelsColumn() const; | |
41 | void setLabelsColumn(int labelsColumn); |
|
41 | void setLabelsColumn(int labelsColumn); | |
|
42 | ||||
|
43 | Q_SIGNALS: | |||
|
44 | void valuesColumnChanged(); | |||
|
45 | void labelsColumnChanged(); | |||
42 | }; |
|
46 | }; | |
43 |
|
47 | |||
44 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
45 |
|
49 | |||
46 | #endif // QVPIEMODELMAPPER_H |
|
50 | #endif // QVPIEMODELMAPPER_H |
General Comments 0
You need to be logged in to leave comments.
Login now