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