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