@@ -1,232 +1,232 | |||||
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 "qhxymodelmapper.h" |
|
21 | #include "qhxymodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHXYModelMapper |
|
26 | \class QHXYModelMapper | |
27 | \mainclass |
|
27 | \mainclass | |
28 |
|
28 | |||
29 | 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. | |
30 | Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
30 | Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. | |
31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. | |
32 | 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. | |
33 | */ |
|
33 | */ | |
34 | /*! |
|
34 | /*! | |
35 | \qmlclass HXYModelMapper QHXYModelMapper |
|
35 | \qmlclass HXYModelMapper QHXYModelMapper | |
36 |
|
36 | |||
37 | HXYModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
37 | HXYModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
38 | for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data. |
|
38 | for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data. | |
39 | HXYModelMapper keeps the series and the model in sync. |
|
39 | HXYModelMapper keeps the series and the model in sync. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QHXYModelMapper::series |
|
43 | \property QHXYModelMapper::series | |
44 | \brief Defines the QXYSeries object that is used by the mapper. |
|
44 | \brief Defines the QXYSeries object that is used by the mapper. | |
45 | All the data in the series is discarded when it is set to the mapper. |
|
45 | All the data in the series is discarded when it is set to the mapper. | |
46 | When new series is specified the old series is disconnected (it preserves its data) |
|
46 | When new series is specified the old series is disconnected (it preserves its data) | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlproperty XYSeries HXYModelMapper::series |
|
49 | \qmlproperty XYSeries HXYModelMapper::series | |
50 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to |
|
50 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to | |
51 | the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
51 | the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \property QHXYModelMapper::model |
|
55 | \property QHXYModelMapper::model | |
56 | \brief Defines the model that is used by the mapper. |
|
56 | \brief Defines the model that is used by the mapper. | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty SomeModel HXYModelMapper::model |
|
59 | \qmlproperty SomeModel HXYModelMapper::model | |
60 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
60 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
61 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
61 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
62 | and modifying the data of the cells. |
|
62 | and modifying the data of the cells. | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | \property QHXYModelMapper::xRow |
|
66 | \property QHXYModelMapper::xRow | |
67 | \brief Defines which row of the model is kept in sync with the x values of the QXYSeries |
|
67 | \brief Defines which row of the model is kept in sync with the x values of the QXYSeries | |
68 | Default value is: -1 (invalid mapping) |
|
68 | Default value is: -1 (invalid mapping) | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty int HXYModelMapper::xRow |
|
71 | \qmlproperty int HXYModelMapper::xRow | |
72 | Defines which row of the model is kept in sync with the x values of the series. Default value is -1 (invalid |
|
72 | Defines which row of the model is kept in sync with the x values of the series. Default value is -1 (invalid | |
73 | mapping). |
|
73 | mapping). | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QHXYModelMapper::yRow |
|
77 | \property QHXYModelMapper::yRow | |
78 | \brief Defines which row of the model is kept in sync with the y values of the QXYSeries |
|
78 | \brief Defines which row of the model is kept in sync with the y values of the QXYSeries | |
79 | Default value is: -1 (invalid mapping) |
|
79 | Default value is: -1 (invalid mapping) | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty int HXYModelMapper::yRow |
|
82 | \qmlproperty int HXYModelMapper::yRow | |
83 | Defines which row of the model is kept in sync with the y values of the series. Default value is -1 |
|
83 | Defines which row of the model is kept in sync with the y values of the series. Default value is -1 | |
84 | (invalid mapping). |
|
84 | (invalid mapping). | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QHXYModelMapper::firstColumn |
|
88 | \property QHXYModelMapper::firstColumn | |
89 | \brief Defines which column of the model contains the data for the first point of the series. |
|
89 | \brief Defines which column of the model contains the data for the first point of the series. | |
90 | Minimal and default value is: 0 |
|
90 | Minimal and default value is: 0 | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty int HXYModelMapper::firstColumn |
|
93 | \qmlproperty int HXYModelMapper::firstColumn | |
94 | Defines which column of the model contains the data for the first point of the series. |
|
94 | Defines which column of the model contains the data for the first point of the series. | |
95 | The default value is 0. |
|
95 | The default value is 0. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \property QHXYModelMapper::columnCount |
|
99 | \property QHXYModelMapper::columnCount | |
100 | \brief Defines the number of columns of the model that are mapped as the data for series |
|
100 | \brief Defines the number of columns of the model that are mapped as the data for series | |
101 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
101 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
102 | */ |
|
102 | */ | |
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty int HXYModelMapper::columnCount |
|
104 | \qmlproperty int HXYModelMapper::columnCount | |
105 | Defines the number of columns of the model that are mapped as the data for series. The default value is |
|
105 | Defines the number of columns of the model that are mapped as the data for series. The default value is | |
106 | -1 (count limited by the number of columns in the model) |
|
106 | -1 (count limited by the number of columns in the model) | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QHXYModelMapper::seriesReplaced() |
|
110 | \fn void QHXYModelMapper::seriesReplaced() | |
111 |
|
111 | |||
112 | Emitted when the series to which mapper is connected to has changed. |
|
112 | Emitted when the series to which mapper is connected to has changed. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \fn void QHXYModelMapper::modelReplaced() |
|
116 | \fn void QHXYModelMapper::modelReplaced() | |
117 |
|
117 | |||
118 | Emitted when the model to which mapper is connected to has changed. |
|
118 | Emitted when the model to which mapper is connected to has changed. | |
119 | */ |
|
119 | */ | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | \fn void QHXYModelMapper::xRowChanged() |
|
122 | \fn void QHXYModelMapper::xRowChanged() | |
123 |
|
123 | |||
124 | Emitted when the xRow has changed. |
|
124 | Emitted when the xRow has changed. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QHXYModelMapper::yRowChanged() |
|
128 | \fn void QHXYModelMapper::yRowChanged() | |
129 |
|
129 | |||
130 | Emitted when the yRow has changed. |
|
130 | Emitted when the yRow has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QHXYModelMapper::firstColumnChanged() |
|
134 | \fn void QHXYModelMapper::firstColumnChanged() | |
135 | Emitted when the firstColumn has changed. |
|
135 | Emitted when the firstColumn has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QHXYModelMapper::columnCountChanged() |
|
139 | \fn void QHXYModelMapper::columnCountChanged() | |
140 | Emitted when the columnCount has changed. |
|
140 | Emitted when the columnCount has changed. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | Constructs a mapper object which is a child of \a parent. |
|
144 | Constructs a mapper object which is a child of \a parent. | |
145 | */ |
|
145 | */ | |
146 | QHXYModelMapper::QHXYModelMapper(QObject *parent) : |
|
146 | QHXYModelMapper::QHXYModelMapper(QObject *parent) : | |
147 | QXYModelMapper(parent) |
|
147 | QXYModelMapper(parent) | |
148 | { |
|
148 | { | |
149 | QXYModelMapper::setOrientation(Qt::Horizontal); |
|
149 | QXYModelMapper::setOrientation(Qt::Horizontal); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QAbstractItemModel* QHXYModelMapper::model() const |
|
152 | QAbstractItemModel* QHXYModelMapper::model() const | |
153 | { |
|
153 | { | |
154 | return QXYModelMapper::model(); |
|
154 | return QXYModelMapper::model(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QHXYModelMapper::setModel(QAbstractItemModel *model) |
|
157 | void QHXYModelMapper::setModel(QAbstractItemModel *model) | |
158 | { |
|
158 | { | |
159 | if (model != QXYModelMapper::model()) { |
|
159 | if (model != QXYModelMapper::model()) { | |
160 | QXYModelMapper::setModel(model); |
|
160 | QXYModelMapper::setModel(model); | |
161 | emit modelReplaced(); |
|
161 | emit modelReplaced(); | |
162 | } |
|
162 | } | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | QXYSeries* QHXYModelMapper::series() const |
|
165 | QXYSeries* QHXYModelMapper::series() const | |
166 | { |
|
166 | { | |
167 | return QXYModelMapper::series(); |
|
167 | return QXYModelMapper::series(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void QHXYModelMapper::setSeries(QXYSeries *series) |
|
170 | void QHXYModelMapper::setSeries(QXYSeries *series) | |
171 | { |
|
171 | { | |
172 | if (series != QXYModelMapper::series()) { |
|
172 | if (series != QXYModelMapper::series()) { | |
173 | QXYModelMapper::setSeries(series); |
|
173 | QXYModelMapper::setSeries(series); | |
174 | emit seriesReplaced(); |
|
174 | emit seriesReplaced(); | |
175 | } |
|
175 | } | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | int QHXYModelMapper::xRow() const |
|
178 | int QHXYModelMapper::xRow() const | |
179 | { |
|
179 | { | |
180 | return QXYModelMapper::xSection(); |
|
180 | return QXYModelMapper::xSection(); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void QHXYModelMapper::setXRow(int xRow) |
|
183 | void QHXYModelMapper::setXRow(int xRow) | |
184 | { |
|
184 | { | |
185 | if (xRow != xSection()) { |
|
185 | if (xRow != xSection()) { | |
186 | QXYModelMapper::setXSection(xRow); |
|
186 | QXYModelMapper::setXSection(xRow); | |
187 | emit xRowChanged(); |
|
187 | emit xRowChanged(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | int QHXYModelMapper::yRow() const |
|
191 | int QHXYModelMapper::yRow() const | |
192 | { |
|
192 | { | |
193 | return QXYModelMapper::ySection(); |
|
193 | return QXYModelMapper::ySection(); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void QHXYModelMapper::setYRow(int yRow) |
|
196 | void QHXYModelMapper::setYRow(int yRow) | |
197 | { |
|
197 | { | |
198 | if (yRow != ySection()) { |
|
198 | if (yRow != ySection()) { | |
199 | QXYModelMapper::setYSection(yRow); |
|
199 | QXYModelMapper::setYSection(yRow); | |
200 | emit yRowChanged(); |
|
200 | emit yRowChanged(); | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | int QHXYModelMapper::firstColumn() const |
|
204 | int QHXYModelMapper::firstColumn() const | |
205 | { |
|
205 | { | |
206 | return first(); |
|
206 | return first(); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void QHXYModelMapper::setFirstColumn(int firstColumn) |
|
209 | void QHXYModelMapper::setFirstColumn(int firstColumn) | |
210 | { |
|
210 | { | |
211 | if (firstColumn != first()) { |
|
211 | if (firstColumn != first()) { | |
212 | setFirst(firstColumn); |
|
212 | setFirst(firstColumn); | |
213 | emit firstColumnChanged(); |
|
213 | emit firstColumnChanged(); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | int QHXYModelMapper::columnCount() const |
|
217 | int QHXYModelMapper::columnCount() const | |
218 | { |
|
218 | { | |
219 | return count(); |
|
219 | return count(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void QHXYModelMapper::setColumnCount(int columnCount) |
|
222 | void QHXYModelMapper::setColumnCount(int columnCount) | |
223 | { |
|
223 | { | |
224 | if (columnCount != count()) { |
|
224 | if (columnCount != count()) { | |
225 | setCount(columnCount); |
|
225 | setCount(columnCount); | |
226 |
emit |
|
226 | emit columnCountChanged(); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | #include "moc_qhxymodelmapper.cpp" |
|
230 | #include "moc_qhxymodelmapper.cpp" | |
231 |
|
231 | |||
232 | QTCOMMERCIALCHART_END_NAMESPACE |
|
232 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,232 +1,232 | |||||
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 "qvxymodelmapper.h" |
|
21 | #include "qvxymodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVXYModelMapper |
|
26 | \class QVXYModelMapper | |
27 | \mainclass |
|
27 | \mainclass | |
28 |
|
28 | |||
29 | 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. | |
30 | Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. |
|
30 | Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object. | |
31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. |
|
31 | It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync. | |
32 | 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. | |
33 | */ |
|
33 | */ | |
34 | /*! |
|
34 | /*! | |
35 | \qmlclass VXYModelMapper QHXYModelMapper |
|
35 | \qmlclass VXYModelMapper QHXYModelMapper | |
36 |
|
36 | |||
37 | VXYModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
37 | VXYModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
38 | for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data. |
|
38 | for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data. | |
39 | VYModelMapper keeps the series and the model in sync. |
|
39 | VYModelMapper keeps the series and the model in sync. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \property QVXYModelMapper::series |
|
43 | \property QVXYModelMapper::series | |
44 | \brief Defines the QXYSeries object that is used by the mapper. |
|
44 | \brief Defines the QXYSeries object that is used by the mapper. | |
45 | All the data in the series is discarded when it is set to the mapper. |
|
45 | All the data in the series is discarded when it is set to the mapper. | |
46 | When new series is specified the old series is disconnected (it preserves its data) |
|
46 | When new series is specified the old series is disconnected (it preserves its data) | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlproperty XYSeries VXYModelMapper::series |
|
49 | \qmlproperty XYSeries VXYModelMapper::series | |
50 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to |
|
50 | Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to | |
51 | the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
51 | the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \property QVXYModelMapper::model |
|
55 | \property QVXYModelMapper::model | |
56 | \brief Defines the model that is used by the mapper. |
|
56 | \brief Defines the model that is used by the mapper. | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlproperty SomeModel VXYModelMapper::model |
|
59 | \qmlproperty SomeModel VXYModelMapper::model | |
60 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
60 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
61 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
61 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
62 | and modifying the data of the cells. |
|
62 | and modifying the data of the cells. | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | \property QVXYModelMapper::xColumn |
|
66 | \property QVXYModelMapper::xColumn | |
67 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries |
|
67 | \brief Defines which column of the model is kept in sync with the x values of QXYSeries | |
68 | Default value is: -1 (invalid mapping) |
|
68 | Default value is: -1 (invalid mapping) | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty int VXYModelMapper::xColumn |
|
71 | \qmlproperty int VXYModelMapper::xColumn | |
72 | Defines which column of the model is kept in sync with the x values of the series. Default value is -1 (invalid |
|
72 | Defines which column of the model is kept in sync with the x values of the series. Default value is -1 (invalid | |
73 | mapping). |
|
73 | mapping). | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QVXYModelMapper::yColumn |
|
77 | \property QVXYModelMapper::yColumn | |
78 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries |
|
78 | \brief Defines which column of the model is kept in sync with the y values of QXYSeries | |
79 | Default value is: -1 (invalid mapping) |
|
79 | Default value is: -1 (invalid mapping) | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty int VXYModelMapper::yColumn |
|
82 | \qmlproperty int VXYModelMapper::yColumn | |
83 | Defines which column of the model is kept in sync with the y values of the series. Default value is -1 (invalid |
|
83 | Defines which column of the model is kept in sync with the y values of the series. Default value is -1 (invalid | |
84 | mapping). |
|
84 | mapping). | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QVXYModelMapper::firstRow |
|
88 | \property QVXYModelMapper::firstRow | |
89 | \brief Defines which row of the model contains the data for the first point of the series. |
|
89 | \brief Defines which row of the model contains the data for the first point of the series. | |
90 | Minimal and default value is: 0 |
|
90 | Minimal and default value is: 0 | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty int VXYModelMapper::firstRow |
|
93 | \qmlproperty int VXYModelMapper::firstRow | |
94 | Defines which row of the model contains the data for the first point of the series. |
|
94 | Defines which row of the model contains the data for the first point of the series. | |
95 | The default value is 0. |
|
95 | The default value is 0. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \property QVXYModelMapper::rowCount |
|
99 | \property QVXYModelMapper::rowCount | |
100 | \brief Defines the number of rows of the model that are mapped as the data for series |
|
100 | \brief Defines the number of rows of the model that are mapped as the data for series | |
101 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
101 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
102 | */ |
|
102 | */ | |
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty int VXYModelMapper::columnCount |
|
104 | \qmlproperty int VXYModelMapper::columnCount | |
105 | Defines the number of rows of the model that are mapped as the data for series. The default value is |
|
105 | Defines the number of rows of the model that are mapped as the data for series. The default value is | |
106 | -1 (count limited by the number of rows in the model). |
|
106 | -1 (count limited by the number of rows in the model). | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QVXYModelMapper::seriesReplaced() |
|
110 | \fn void QVXYModelMapper::seriesReplaced() | |
111 |
|
111 | |||
112 | Emitted when the series to which mapper is connected to has changed. |
|
112 | Emitted when the series to which mapper is connected to has changed. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \fn void QVXYModelMapper::modelReplaced() |
|
116 | \fn void QVXYModelMapper::modelReplaced() | |
117 |
|
117 | |||
118 | Emitted when the model to which mapper is connected to has changed. |
|
118 | Emitted when the model to which mapper is connected to has changed. | |
119 | */ |
|
119 | */ | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | \fn void QVXYModelMapper::xColumnChanged() |
|
122 | \fn void QVXYModelMapper::xColumnChanged() | |
123 |
|
123 | |||
124 | Emitted when the xColumn has changed. |
|
124 | Emitted when the xColumn has changed. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QVXYModelMapper::yColumnChanged() |
|
128 | \fn void QVXYModelMapper::yColumnChanged() | |
129 |
|
129 | |||
130 | Emitted when the yColumn has changed. |
|
130 | Emitted when the yColumn has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QVXYModelMapper::firstRowChanged() |
|
134 | \fn void QVXYModelMapper::firstRowChanged() | |
135 | Emitted when the firstRow has changed. |
|
135 | Emitted when the firstRow has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QVXYModelMapper::rowCountChanged() |
|
139 | \fn void QVXYModelMapper::rowCountChanged() | |
140 | Emitted when the rowCount has changed. |
|
140 | Emitted when the rowCount has changed. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | Constructs a mapper object which is a child of \a parent. |
|
144 | Constructs a mapper object which is a child of \a parent. | |
145 | */ |
|
145 | */ | |
146 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : |
|
146 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : | |
147 | QXYModelMapper(parent) |
|
147 | QXYModelMapper(parent) | |
148 | { |
|
148 | { | |
149 | QXYModelMapper::setOrientation(Qt::Vertical); |
|
149 | QXYModelMapper::setOrientation(Qt::Vertical); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | QAbstractItemModel* QVXYModelMapper::model() const |
|
152 | QAbstractItemModel* QVXYModelMapper::model() const | |
153 | { |
|
153 | { | |
154 | return QXYModelMapper::model(); |
|
154 | return QXYModelMapper::model(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void QVXYModelMapper::setModel(QAbstractItemModel *model) |
|
157 | void QVXYModelMapper::setModel(QAbstractItemModel *model) | |
158 | { |
|
158 | { | |
159 | if (model != QXYModelMapper::model()) { |
|
159 | if (model != QXYModelMapper::model()) { | |
160 | QXYModelMapper::setModel(model); |
|
160 | QXYModelMapper::setModel(model); | |
161 | emit modelReplaced(); |
|
161 | emit modelReplaced(); | |
162 | } |
|
162 | } | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | QXYSeries* QVXYModelMapper::series() const |
|
165 | QXYSeries* QVXYModelMapper::series() const | |
166 | { |
|
166 | { | |
167 | return QXYModelMapper::series(); |
|
167 | return QXYModelMapper::series(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void QVXYModelMapper::setSeries(QXYSeries *series) |
|
170 | void QVXYModelMapper::setSeries(QXYSeries *series) | |
171 | { |
|
171 | { | |
172 | if (series != QXYModelMapper::series()) { |
|
172 | if (series != QXYModelMapper::series()) { | |
173 | QXYModelMapper::setSeries(series); |
|
173 | QXYModelMapper::setSeries(series); | |
174 | emit seriesReplaced(); |
|
174 | emit seriesReplaced(); | |
175 | } |
|
175 | } | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | int QVXYModelMapper::xColumn() const |
|
178 | int QVXYModelMapper::xColumn() const | |
179 | { |
|
179 | { | |
180 | return QXYModelMapper::xSection(); |
|
180 | return QXYModelMapper::xSection(); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void QVXYModelMapper::setXColumn(int xColumn) |
|
183 | void QVXYModelMapper::setXColumn(int xColumn) | |
184 | { |
|
184 | { | |
185 | if (xColumn != xSection()) { |
|
185 | if (xColumn != xSection()) { | |
186 | QXYModelMapper::setXSection(xColumn); |
|
186 | QXYModelMapper::setXSection(xColumn); | |
187 | emit xColumnChanged(); |
|
187 | emit xColumnChanged(); | |
188 | } |
|
188 | } | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | int QVXYModelMapper::yColumn() const |
|
191 | int QVXYModelMapper::yColumn() const | |
192 | { |
|
192 | { | |
193 | return QXYModelMapper::ySection(); |
|
193 | return QXYModelMapper::ySection(); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void QVXYModelMapper::setYColumn(int yColumn) |
|
196 | void QVXYModelMapper::setYColumn(int yColumn) | |
197 | { |
|
197 | { | |
198 | if (yColumn != ySection()) { |
|
198 | if (yColumn != ySection()) { | |
199 | QXYModelMapper::setYSection(yColumn); |
|
199 | QXYModelMapper::setYSection(yColumn); | |
200 | emit yColumnChanged(); |
|
200 | emit yColumnChanged(); | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | int QVXYModelMapper::firstRow() const |
|
204 | int QVXYModelMapper::firstRow() const | |
205 | { |
|
205 | { | |
206 | return first(); |
|
206 | return first(); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void QVXYModelMapper::setFirstRow(int firstRow) |
|
209 | void QVXYModelMapper::setFirstRow(int firstRow) | |
210 | { |
|
210 | { | |
211 | if (firstRow != first()) { |
|
211 | if (firstRow != first()) { | |
212 | setFirst(firstRow); |
|
212 | setFirst(firstRow); | |
213 | emit firstRowChanged(); |
|
213 | emit firstRowChanged(); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | int QVXYModelMapper::rowCount() const |
|
217 | int QVXYModelMapper::rowCount() const | |
218 | { |
|
218 | { | |
219 | return count(); |
|
219 | return count(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void QVXYModelMapper::setRowCount(int rowCount) |
|
222 | void QVXYModelMapper::setRowCount(int rowCount) | |
223 | { |
|
223 | { | |
224 | if (rowCount != count()) { |
|
224 | if (rowCount != count()) { | |
225 | setCount(rowCount); |
|
225 | setCount(rowCount); | |
226 |
emit |
|
226 | emit rowCountChanged(); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | #include "moc_qvxymodelmapper.cpp" |
|
230 | #include "moc_qvxymodelmapper.cpp" | |
231 |
|
231 | |||
232 | QTCOMMERCIALCHART_END_NAMESPACE |
|
232 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,529 +1,584 | |||||
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 <QtCore/QString> |
|
21 | #include <QtCore/QString> | |
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 |
|
23 | |||
24 | #include <qchart.h> |
|
24 | #include <qchart.h> | |
25 | #include <qchartview.h> |
|
25 | #include <qchartview.h> | |
26 | #include <qxyseries.h> |
|
26 | #include <qxyseries.h> | |
27 | #include <qlineseries.h> |
|
27 | #include <qlineseries.h> | |
28 | #include <qvxymodelmapper.h> |
|
28 | #include <qvxymodelmapper.h> | |
29 | #include <qhxymodelmapper.h> |
|
29 | #include <qhxymodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qxymodelmapper : public QObject |
|
34 | class tst_qxymodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qxymodelmapper(); |
|
39 | tst_qxymodelmapper(); | |
40 | void createVerticalMapper(); |
|
40 | void createVerticalMapper(); | |
41 | void createHorizontalMapper(); |
|
41 | void createHorizontalMapper(); | |
42 |
|
42 | |||
43 | private Q_SLOTS: |
|
43 | private Q_SLOTS: | |
44 | void initTestCase(); |
|
44 | void initTestCase(); | |
45 | void cleanupTestCase(); |
|
45 | void cleanupTestCase(); | |
46 | void init(); |
|
46 | void init(); | |
47 | void cleanup(); |
|
47 | void cleanup(); | |
48 | void verticalMapper_data(); |
|
48 | void verticalMapper_data(); | |
49 | void verticalMapper(); |
|
49 | void verticalMapper(); | |
50 | void verticalMapperCustomMapping_data(); |
|
50 | void verticalMapperCustomMapping_data(); | |
51 | void verticalMapperCustomMapping(); |
|
51 | void verticalMapperCustomMapping(); | |
52 | void horizontalMapper_data(); |
|
52 | void horizontalMapper_data(); | |
53 | void horizontalMapper(); |
|
53 | void horizontalMapper(); | |
54 | void horizontalMapperCustomMapping_data(); |
|
54 | void horizontalMapperCustomMapping_data(); | |
55 | void horizontalMapperCustomMapping(); |
|
55 | void horizontalMapperCustomMapping(); | |
56 | void seriesUpdated(); |
|
56 | void seriesUpdated(); | |
57 | void verticalModelInsertRows(); |
|
57 | void verticalModelInsertRows(); | |
58 | void verticalModelRemoveRows(); |
|
58 | void verticalModelRemoveRows(); | |
59 | void verticalModelInsertColumns(); |
|
59 | void verticalModelInsertColumns(); | |
60 | void verticalModelRemoveColumns(); |
|
60 | void verticalModelRemoveColumns(); | |
61 | void horizontalModelInsertRows(); |
|
61 | void horizontalModelInsertRows(); | |
62 | void horizontalModelRemoveRows(); |
|
62 | void horizontalModelRemoveRows(); | |
63 | void horizontalModelInsertColumns(); |
|
63 | void horizontalModelInsertColumns(); | |
64 | void horizontalModelRemoveColumns(); |
|
64 | void horizontalModelRemoveColumns(); | |
65 | void modelUpdateCell(); |
|
65 | void modelUpdateCell(); | |
|
66 | void verticalMapperSignals(); | |||
|
67 | void horizontalMapperSignals(); | |||
66 |
|
68 | |||
67 | private: |
|
69 | private: | |
68 | QStandardItemModel *m_model; |
|
70 | QStandardItemModel *m_model; | |
69 | int m_modelRowCount; |
|
71 | int m_modelRowCount; | |
70 | int m_modelColumnCount; |
|
72 | int m_modelColumnCount; | |
71 |
|
73 | |||
72 | QHXYModelMapper *m_hMapper; |
|
74 | QHXYModelMapper *m_hMapper; | |
73 | QVXYModelMapper *m_vMapper; |
|
75 | QVXYModelMapper *m_vMapper; | |
74 |
|
76 | |||
75 | QXYSeries *m_series; |
|
77 | QXYSeries *m_series; | |
76 | QChart *m_chart; |
|
78 | QChart *m_chart; | |
77 | }; |
|
79 | }; | |
78 |
|
80 | |||
79 | tst_qxymodelmapper::tst_qxymodelmapper(): |
|
81 | tst_qxymodelmapper::tst_qxymodelmapper(): | |
80 | m_model(0), |
|
82 | m_model(0), | |
81 | m_modelRowCount(10), |
|
83 | m_modelRowCount(10), | |
82 | m_modelColumnCount(8), |
|
84 | m_modelColumnCount(8), | |
83 | m_hMapper(0), |
|
85 | m_hMapper(0), | |
84 | m_vMapper(0), |
|
86 | m_vMapper(0), | |
85 | m_series(0), |
|
87 | m_series(0), | |
86 | m_chart(0) |
|
88 | m_chart(0) | |
87 | { |
|
89 | { | |
88 | } |
|
90 | } | |
89 |
|
91 | |||
90 | void tst_qxymodelmapper::createVerticalMapper() |
|
92 | void tst_qxymodelmapper::createVerticalMapper() | |
91 | { |
|
93 | { | |
92 | m_vMapper = new QVXYModelMapper; |
|
94 | m_vMapper = new QVXYModelMapper; | |
93 | QVERIFY(m_vMapper->model() == 0); |
|
95 | QVERIFY(m_vMapper->model() == 0); | |
94 | m_vMapper->setXColumn(0); |
|
96 | m_vMapper->setXColumn(0); | |
95 | m_vMapper->setYColumn(1); |
|
97 | m_vMapper->setYColumn(1); | |
96 | m_vMapper->setModel(m_model); |
|
98 | m_vMapper->setModel(m_model); | |
97 | m_vMapper->setSeries(m_series); |
|
99 | m_vMapper->setSeries(m_series); | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | void tst_qxymodelmapper::createHorizontalMapper() |
|
102 | void tst_qxymodelmapper::createHorizontalMapper() | |
101 | { |
|
103 | { | |
102 | m_hMapper = new QHXYModelMapper; |
|
104 | m_hMapper = new QHXYModelMapper; | |
103 | QVERIFY(m_hMapper->model() == 0); |
|
105 | QVERIFY(m_hMapper->model() == 0); | |
104 | m_hMapper->setXRow(0); |
|
106 | m_hMapper->setXRow(0); | |
105 | m_hMapper->setYRow(1); |
|
107 | m_hMapper->setYRow(1); | |
106 | m_hMapper->setModel(m_model); |
|
108 | m_hMapper->setModel(m_model); | |
107 | m_hMapper->setSeries(m_series); |
|
109 | m_hMapper->setSeries(m_series); | |
108 | } |
|
110 | } | |
109 |
|
111 | |||
110 | void tst_qxymodelmapper::init() |
|
112 | void tst_qxymodelmapper::init() | |
111 | { |
|
113 | { | |
112 | m_series = new QLineSeries; |
|
114 | m_series = new QLineSeries; | |
113 | m_chart->addSeries(m_series); |
|
115 | m_chart->addSeries(m_series); | |
114 |
|
116 | |||
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
117 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | |
116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
118 | for (int row = 0; row < m_modelRowCount; ++row) { | |
117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
119 | for (int column = 0; column < m_modelColumnCount; column++) { | |
118 | m_model->setData(m_model->index(row, column), row * column); |
|
120 | m_model->setData(m_model->index(row, column), row * column); | |
119 | } |
|
121 | } | |
120 | } |
|
122 | } | |
121 | } |
|
123 | } | |
122 |
|
124 | |||
123 | void tst_qxymodelmapper::cleanup() |
|
125 | void tst_qxymodelmapper::cleanup() | |
124 | { |
|
126 | { | |
125 | m_chart->removeSeries(m_series); |
|
127 | m_chart->removeSeries(m_series); | |
126 | m_series->deleteLater(); |
|
128 | m_series->deleteLater(); | |
127 | m_series = 0; |
|
129 | m_series = 0; | |
128 |
|
130 | |||
129 | m_model->clear(); |
|
131 | m_model->clear(); | |
130 | m_model->deleteLater(); |
|
132 | m_model->deleteLater(); | |
131 | m_model = 0; |
|
133 | m_model = 0; | |
132 |
|
134 | |||
133 | if (m_vMapper) { |
|
135 | if (m_vMapper) { | |
134 | m_vMapper->deleteLater(); |
|
136 | m_vMapper->deleteLater(); | |
135 | m_vMapper = 0; |
|
137 | m_vMapper = 0; | |
136 | } |
|
138 | } | |
137 |
|
139 | |||
138 | if (m_hMapper) { |
|
140 | if (m_hMapper) { | |
139 | m_hMapper->deleteLater(); |
|
141 | m_hMapper->deleteLater(); | |
140 | m_hMapper = 0; |
|
142 | m_hMapper = 0; | |
141 | } |
|
143 | } | |
142 | } |
|
144 | } | |
143 |
|
145 | |||
144 | void tst_qxymodelmapper::initTestCase() |
|
146 | void tst_qxymodelmapper::initTestCase() | |
145 | { |
|
147 | { | |
146 | m_chart = new QChart; |
|
148 | m_chart = new QChart; | |
147 | QChartView *chartView = new QChartView(m_chart); |
|
149 | QChartView *chartView = new QChartView(m_chart); | |
148 | chartView->show(); |
|
150 | chartView->show(); | |
149 | } |
|
151 | } | |
150 |
|
152 | |||
151 | void tst_qxymodelmapper::cleanupTestCase() |
|
153 | void tst_qxymodelmapper::cleanupTestCase() | |
152 | { |
|
154 | { | |
153 | // |
|
155 | // | |
154 | } |
|
156 | } | |
155 |
|
157 | |||
156 | void tst_qxymodelmapper::verticalMapper_data() |
|
158 | void tst_qxymodelmapper::verticalMapper_data() | |
157 | { |
|
159 | { | |
158 | QTest::addColumn<int>("xColumn"); |
|
160 | QTest::addColumn<int>("xColumn"); | |
159 | QTest::addColumn<int>("yColumn"); |
|
161 | QTest::addColumn<int>("yColumn"); | |
160 | QTest::addColumn<int>("expectedCount"); |
|
162 | QTest::addColumn<int>("expectedCount"); | |
161 | QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount; |
|
163 | QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount; | |
162 | QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount; |
|
164 | QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount; | |
163 | QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0; |
|
165 | QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0; | |
164 | QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0; |
|
166 | QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0; | |
165 | QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0; |
|
167 | QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0; | |
166 | } |
|
168 | } | |
167 |
|
169 | |||
168 | void tst_qxymodelmapper::verticalMapper() |
|
170 | void tst_qxymodelmapper::verticalMapper() | |
169 | { |
|
171 | { | |
170 | QFETCH(int, xColumn); |
|
172 | QFETCH(int, xColumn); | |
171 | QFETCH(int, yColumn); |
|
173 | QFETCH(int, yColumn); | |
172 | QFETCH(int, expectedCount); |
|
174 | QFETCH(int, expectedCount); | |
173 |
|
175 | |||
174 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
176 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
175 | QVERIFY(mapper->model() == 0); |
|
177 | QVERIFY(mapper->model() == 0); | |
176 |
|
178 | |||
177 | mapper->setXColumn(xColumn); |
|
179 | mapper->setXColumn(xColumn); | |
178 | mapper->setYColumn(yColumn); |
|
180 | mapper->setYColumn(yColumn); | |
179 | mapper->setModel(m_model); |
|
181 | mapper->setModel(m_model); | |
180 | mapper->setSeries(m_series); |
|
182 | mapper->setSeries(m_series); | |
181 |
|
183 | |||
182 | QCOMPARE(m_series->count(), expectedCount); |
|
184 | QCOMPARE(m_series->count(), expectedCount); | |
183 | QCOMPARE(mapper->xColumn(), qMax(-1, xColumn)); |
|
185 | QCOMPARE(mapper->xColumn(), qMax(-1, xColumn)); | |
184 | QCOMPARE(mapper->yColumn(), qMax(-1, yColumn)); |
|
186 | QCOMPARE(mapper->yColumn(), qMax(-1, yColumn)); | |
185 |
|
187 | |||
186 | delete mapper; |
|
188 | delete mapper; | |
187 | mapper = 0; |
|
189 | mapper = 0; | |
188 | } |
|
190 | } | |
189 |
|
191 | |||
190 | void tst_qxymodelmapper::verticalMapperCustomMapping_data() |
|
192 | void tst_qxymodelmapper::verticalMapperCustomMapping_data() | |
191 | { |
|
193 | { | |
192 | QTest::addColumn<int>("first"); |
|
194 | QTest::addColumn<int>("first"); | |
193 | QTest::addColumn<int>("countLimit"); |
|
195 | QTest::addColumn<int>("countLimit"); | |
194 | QTest::addColumn<int>("expectedCount"); |
|
196 | QTest::addColumn<int>("expectedCount"); | |
195 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; |
|
197 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |
196 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; |
|
198 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |
197 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); |
|
199 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |
198 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); |
|
200 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |
199 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; |
|
201 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |
200 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; |
|
202 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |
201 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; |
|
203 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; | |
202 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; |
|
204 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |
203 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; |
|
205 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |
204 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; |
|
206 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |
205 |
|
207 | |||
206 | } |
|
208 | } | |
207 |
|
209 | |||
208 | void tst_qxymodelmapper::verticalMapperCustomMapping() |
|
210 | void tst_qxymodelmapper::verticalMapperCustomMapping() | |
209 | { |
|
211 | { | |
210 | QFETCH(int, first); |
|
212 | QFETCH(int, first); | |
211 | QFETCH(int, countLimit); |
|
213 | QFETCH(int, countLimit); | |
212 | QFETCH(int, expectedCount); |
|
214 | QFETCH(int, expectedCount); | |
213 |
|
215 | |||
214 | QCOMPARE(m_series->count(), 0); |
|
216 | QCOMPARE(m_series->count(), 0); | |
215 |
|
217 | |||
216 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
218 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
217 | mapper->setXColumn(0); |
|
219 | mapper->setXColumn(0); | |
218 | mapper->setYColumn(1); |
|
220 | mapper->setYColumn(1); | |
219 | mapper->setModel(m_model); |
|
221 | mapper->setModel(m_model); | |
220 | mapper->setSeries(m_series); |
|
222 | mapper->setSeries(m_series); | |
221 | mapper->setFirstRow(first); |
|
223 | mapper->setFirstRow(first); | |
222 | mapper->setRowCount(countLimit); |
|
224 | mapper->setRowCount(countLimit); | |
223 |
|
225 | |||
224 | QCOMPARE(m_series->count(), expectedCount); |
|
226 | QCOMPARE(m_series->count(), expectedCount); | |
225 |
|
227 | |||
226 | // change values column mapping to invalid |
|
228 | // change values column mapping to invalid | |
227 | mapper->setXColumn(-1); |
|
229 | mapper->setXColumn(-1); | |
228 | mapper->setYColumn(1); |
|
230 | mapper->setYColumn(1); | |
229 |
|
231 | |||
230 | QCOMPARE(m_series->count(), 0); |
|
232 | QCOMPARE(m_series->count(), 0); | |
231 |
|
233 | |||
232 | delete mapper; |
|
234 | delete mapper; | |
233 | mapper = 0; |
|
235 | mapper = 0; | |
234 | } |
|
236 | } | |
235 |
|
237 | |||
236 | void tst_qxymodelmapper::horizontalMapper_data() |
|
238 | void tst_qxymodelmapper::horizontalMapper_data() | |
237 | { |
|
239 | { | |
238 | QTest::addColumn<int>("xRow"); |
|
240 | QTest::addColumn<int>("xRow"); | |
239 | QTest::addColumn<int>("yRow"); |
|
241 | QTest::addColumn<int>("yRow"); | |
240 | QTest::addColumn<int>("expectedCount"); |
|
242 | QTest::addColumn<int>("expectedCount"); | |
241 | QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount; |
|
243 | QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount; | |
242 | QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount; |
|
244 | QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount; | |
243 | QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0; |
|
245 | QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0; | |
244 | QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0; |
|
246 | QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0; | |
245 | QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0; |
|
247 | QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0; | |
246 | } |
|
248 | } | |
247 |
|
249 | |||
248 | void tst_qxymodelmapper::horizontalMapper() |
|
250 | void tst_qxymodelmapper::horizontalMapper() | |
249 | { |
|
251 | { | |
250 | QFETCH(int, xRow); |
|
252 | QFETCH(int, xRow); | |
251 | QFETCH(int, yRow); |
|
253 | QFETCH(int, yRow); | |
252 | QFETCH(int, expectedCount); |
|
254 | QFETCH(int, expectedCount); | |
253 |
|
255 | |||
254 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
256 | QHXYModelMapper *mapper = new QHXYModelMapper; | |
255 | mapper->setXRow(xRow); |
|
257 | mapper->setXRow(xRow); | |
256 | mapper->setYRow(yRow); |
|
258 | mapper->setYRow(yRow); | |
257 | mapper->setModel(m_model); |
|
259 | mapper->setModel(m_model); | |
258 | mapper->setSeries(m_series); |
|
260 | mapper->setSeries(m_series); | |
259 |
|
261 | |||
260 | QCOMPARE(m_series->count(), expectedCount); |
|
262 | QCOMPARE(m_series->count(), expectedCount); | |
261 | QCOMPARE(mapper->xRow(), qMax(-1, xRow)); |
|
263 | QCOMPARE(mapper->xRow(), qMax(-1, xRow)); | |
262 | QCOMPARE(mapper->yRow(), qMax(-1, yRow)); |
|
264 | QCOMPARE(mapper->yRow(), qMax(-1, yRow)); | |
263 |
|
265 | |||
264 | delete mapper; |
|
266 | delete mapper; | |
265 | mapper = 0; |
|
267 | mapper = 0; | |
266 | } |
|
268 | } | |
267 |
|
269 | |||
268 | void tst_qxymodelmapper::horizontalMapperCustomMapping_data() |
|
270 | void tst_qxymodelmapper::horizontalMapperCustomMapping_data() | |
269 | { |
|
271 | { | |
270 | QTest::addColumn<int>("first"); |
|
272 | QTest::addColumn<int>("first"); | |
271 | QTest::addColumn<int>("countLimit"); |
|
273 | QTest::addColumn<int>("countLimit"); | |
272 | QTest::addColumn<int>("expectedCount"); |
|
274 | QTest::addColumn<int>("expectedCount"); | |
273 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; |
|
275 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |
274 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; |
|
276 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |
275 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); |
|
277 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |
276 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); |
|
278 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |
277 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; |
|
279 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |
278 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; |
|
280 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |
279 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; |
|
281 | QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; | |
280 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; |
|
282 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |
281 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; |
|
283 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |
282 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; |
|
284 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |
283 | } |
|
285 | } | |
284 |
|
286 | |||
285 | void tst_qxymodelmapper::horizontalMapperCustomMapping() |
|
287 | void tst_qxymodelmapper::horizontalMapperCustomMapping() | |
286 | { |
|
288 | { | |
287 | QFETCH(int, first); |
|
289 | QFETCH(int, first); | |
288 | QFETCH(int, countLimit); |
|
290 | QFETCH(int, countLimit); | |
289 | QFETCH(int, expectedCount); |
|
291 | QFETCH(int, expectedCount); | |
290 |
|
292 | |||
291 | QCOMPARE(m_series->count(), 0); |
|
293 | QCOMPARE(m_series->count(), 0); | |
292 |
|
294 | |||
293 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
295 | QHXYModelMapper *mapper = new QHXYModelMapper; | |
294 | mapper->setXRow(0); |
|
296 | mapper->setXRow(0); | |
295 | mapper->setYRow(1); |
|
297 | mapper->setYRow(1); | |
296 | mapper->setModel(m_model); |
|
298 | mapper->setModel(m_model); | |
297 | mapper->setSeries(m_series); |
|
299 | mapper->setSeries(m_series); | |
298 | mapper->setFirstColumn(first); |
|
300 | mapper->setFirstColumn(first); | |
299 | mapper->setColumnCount(countLimit); |
|
301 | mapper->setColumnCount(countLimit); | |
300 |
|
302 | |||
301 | QCOMPARE(m_series->count(), expectedCount); |
|
303 | QCOMPARE(m_series->count(), expectedCount); | |
302 |
|
304 | |||
303 | // change values row mapping to invalid |
|
305 | // change values row mapping to invalid | |
304 | mapper->setXRow(-1); |
|
306 | mapper->setXRow(-1); | |
305 | mapper->setYRow(1); |
|
307 | mapper->setYRow(1); | |
306 |
|
308 | |||
307 | QCOMPARE(m_series->count(), 0); |
|
309 | QCOMPARE(m_series->count(), 0); | |
308 |
|
310 | |||
309 | delete mapper; |
|
311 | delete mapper; | |
310 | mapper = 0; |
|
312 | mapper = 0; | |
311 | } |
|
313 | } | |
312 |
|
314 | |||
313 | void tst_qxymodelmapper::seriesUpdated() |
|
315 | void tst_qxymodelmapper::seriesUpdated() | |
314 | { |
|
316 | { | |
315 | // setup the mapper |
|
317 | // setup the mapper | |
316 | createVerticalMapper(); |
|
318 | createVerticalMapper(); | |
317 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
319 | QCOMPARE(m_series->count(), m_modelRowCount); | |
318 | QCOMPARE(m_vMapper->rowCount(), -1); |
|
320 | QCOMPARE(m_vMapper->rowCount(), -1); | |
319 |
|
321 | |||
320 | m_series->append(QPointF(100, 100)); |
|
322 | m_series->append(QPointF(100, 100)); | |
321 | QCOMPARE(m_series->count(), m_modelRowCount + 1); |
|
323 | QCOMPARE(m_series->count(), m_modelRowCount + 1); | |
322 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
324 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
323 |
|
325 | |||
324 | m_series->remove(m_series->points().last()); |
|
326 | m_series->remove(m_series->points().last()); | |
325 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
327 | QCOMPARE(m_series->count(), m_modelRowCount); | |
326 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
328 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | |
327 |
|
329 | |||
328 | m_series->replace(m_series->points().first(), QPointF(25.0, 75.0)); |
|
330 | m_series->replace(m_series->points().first(), QPointF(25.0, 75.0)); | |
329 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); |
|
331 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); | |
330 | QCOMPARE(m_model->data(m_model->index(0, 1)).toReal(), 75.0); |
|
332 | QCOMPARE(m_model->data(m_model->index(0, 1)).toReal(), 75.0); | |
331 | } |
|
333 | } | |
332 |
|
334 | |||
333 | void tst_qxymodelmapper::verticalModelInsertRows() |
|
335 | void tst_qxymodelmapper::verticalModelInsertRows() | |
334 | { |
|
336 | { | |
335 | // setup the mapper |
|
337 | // setup the mapper | |
336 | createVerticalMapper(); |
|
338 | createVerticalMapper(); | |
337 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
339 | QCOMPARE(m_series->count(), m_modelRowCount); | |
338 | QVERIFY(m_vMapper->model() != 0); |
|
340 | QVERIFY(m_vMapper->model() != 0); | |
339 |
|
341 | |||
340 | int insertCount = 4; |
|
342 | int insertCount = 4; | |
341 | m_model->insertRows(3, insertCount); |
|
343 | m_model->insertRows(3, insertCount); | |
342 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); |
|
344 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); | |
343 |
|
345 | |||
344 | int first = 3; |
|
346 | int first = 3; | |
345 | m_vMapper->setFirstRow(3); |
|
347 | m_vMapper->setFirstRow(3); | |
346 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); |
|
348 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); | |
347 |
|
349 | |||
348 | m_model->insertRows(3, insertCount); |
|
350 | m_model->insertRows(3, insertCount); | |
349 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); |
|
351 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); | |
350 |
|
352 | |||
351 | int countLimit = 6; |
|
353 | int countLimit = 6; | |
352 | m_vMapper->setRowCount(countLimit); |
|
354 | m_vMapper->setRowCount(countLimit); | |
353 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
355 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | |
354 |
|
356 | |||
355 | m_model->insertRows(3, insertCount); |
|
357 | m_model->insertRows(3, insertCount); | |
356 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
358 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | |
357 |
|
359 | |||
358 | m_vMapper->setFirstRow(0); |
|
360 | m_vMapper->setFirstRow(0); | |
359 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
361 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | |
360 |
|
362 | |||
361 | m_vMapper->setRowCount(-1); |
|
363 | m_vMapper->setRowCount(-1); | |
362 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); |
|
364 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); | |
363 | } |
|
365 | } | |
364 |
|
366 | |||
365 | void tst_qxymodelmapper::verticalModelRemoveRows() |
|
367 | void tst_qxymodelmapper::verticalModelRemoveRows() | |
366 | { |
|
368 | { | |
367 | // setup the mapper |
|
369 | // setup the mapper | |
368 | createVerticalMapper(); |
|
370 | createVerticalMapper(); | |
369 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
371 | QCOMPARE(m_series->count(), m_modelRowCount); | |
370 | QVERIFY(m_vMapper->model() != 0); |
|
372 | QVERIFY(m_vMapper->model() != 0); | |
371 |
|
373 | |||
372 | int removeCount = 2; |
|
374 | int removeCount = 2; | |
373 | m_model->removeRows(1, removeCount); |
|
375 | m_model->removeRows(1, removeCount); | |
374 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); |
|
376 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); | |
375 |
|
377 | |||
376 | int first = 1; |
|
378 | int first = 1; | |
377 | m_vMapper->setFirstRow(first); |
|
379 | m_vMapper->setFirstRow(first); | |
378 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); |
|
380 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); | |
379 |
|
381 | |||
380 | m_model->removeRows(1, removeCount); |
|
382 | m_model->removeRows(1, removeCount); | |
381 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); |
|
383 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); | |
382 |
|
384 | |||
383 | int countLimit = 3; |
|
385 | int countLimit = 3; | |
384 | m_vMapper->setRowCount(countLimit); |
|
386 | m_vMapper->setRowCount(countLimit); | |
385 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
387 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | |
386 |
|
388 | |||
387 | m_model->removeRows(1, removeCount); |
|
389 | m_model->removeRows(1, removeCount); | |
388 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
390 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | |
389 |
|
391 | |||
390 | m_vMapper->setFirstRow(0); |
|
392 | m_vMapper->setFirstRow(0); | |
391 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
393 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | |
392 |
|
394 | |||
393 | m_vMapper->setRowCount(-1); |
|
395 | m_vMapper->setRowCount(-1); | |
394 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); |
|
396 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); | |
395 | } |
|
397 | } | |
396 |
|
398 | |||
397 | void tst_qxymodelmapper::verticalModelInsertColumns() |
|
399 | void tst_qxymodelmapper::verticalModelInsertColumns() | |
398 | { |
|
400 | { | |
399 | // setup the mapper |
|
401 | // setup the mapper | |
400 | createVerticalMapper(); |
|
402 | createVerticalMapper(); | |
401 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
403 | QCOMPARE(m_series->count(), m_modelRowCount); | |
402 | QVERIFY(m_vMapper->model() != 0); |
|
404 | QVERIFY(m_vMapper->model() != 0); | |
403 |
|
405 | |||
404 | int insertCount = 4; |
|
406 | int insertCount = 4; | |
405 | m_model->insertColumns(3, insertCount); |
|
407 | m_model->insertColumns(3, insertCount); | |
406 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
408 | QCOMPARE(m_series->count(), m_modelRowCount); | |
407 | } |
|
409 | } | |
408 |
|
410 | |||
409 | void tst_qxymodelmapper::verticalModelRemoveColumns() |
|
411 | void tst_qxymodelmapper::verticalModelRemoveColumns() | |
410 | { |
|
412 | { | |
411 | // setup the mapper |
|
413 | // setup the mapper | |
412 | createVerticalMapper(); |
|
414 | createVerticalMapper(); | |
413 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
415 | QCOMPARE(m_series->count(), m_modelRowCount); | |
414 | QVERIFY(m_vMapper->model() != 0); |
|
416 | QVERIFY(m_vMapper->model() != 0); | |
415 |
|
417 | |||
416 | int removeCount = m_modelColumnCount - 2; |
|
418 | int removeCount = m_modelColumnCount - 2; | |
417 | m_model->removeColumns(0, removeCount); |
|
419 | m_model->removeColumns(0, removeCount); | |
418 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
420 | QCOMPARE(m_series->count(), m_modelRowCount); | |
419 |
|
421 | |||
420 | // leave only one column |
|
422 | // leave only one column | |
421 | m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); |
|
423 | m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); | |
422 | QCOMPARE(m_series->count(), 0); |
|
424 | QCOMPARE(m_series->count(), 0); | |
423 | } |
|
425 | } | |
424 |
|
426 | |||
425 | void tst_qxymodelmapper::horizontalModelInsertRows() |
|
427 | void tst_qxymodelmapper::horizontalModelInsertRows() | |
426 | { |
|
428 | { | |
427 | // setup the mapper |
|
429 | // setup the mapper | |
428 | createHorizontalMapper(); |
|
430 | createHorizontalMapper(); | |
429 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
431 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
430 | QVERIFY(m_hMapper->model() != 0); |
|
432 | QVERIFY(m_hMapper->model() != 0); | |
431 |
|
433 | |||
432 | int insertCount = 4; |
|
434 | int insertCount = 4; | |
433 | m_model->insertRows(3, insertCount); |
|
435 | m_model->insertRows(3, insertCount); | |
434 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
436 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
435 | } |
|
437 | } | |
436 |
|
438 | |||
437 | void tst_qxymodelmapper::horizontalModelRemoveRows() |
|
439 | void tst_qxymodelmapper::horizontalModelRemoveRows() | |
438 | { |
|
440 | { | |
439 | // setup the mapper |
|
441 | // setup the mapper | |
440 | createHorizontalMapper(); |
|
442 | createHorizontalMapper(); | |
441 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
443 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
442 | QVERIFY(m_hMapper->model() != 0); |
|
444 | QVERIFY(m_hMapper->model() != 0); | |
443 |
|
445 | |||
444 | int removeCount = m_modelRowCount - 2; |
|
446 | int removeCount = m_modelRowCount - 2; | |
445 | m_model->removeRows(0, removeCount); |
|
447 | m_model->removeRows(0, removeCount); | |
446 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
448 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
447 |
|
449 | |||
448 | // leave only one column |
|
450 | // leave only one column | |
449 | m_model->removeRows(0, m_modelRowCount - removeCount - 1); |
|
451 | m_model->removeRows(0, m_modelRowCount - removeCount - 1); | |
450 | QCOMPARE(m_series->count(), 0); |
|
452 | QCOMPARE(m_series->count(), 0); | |
451 | } |
|
453 | } | |
452 |
|
454 | |||
453 | void tst_qxymodelmapper::horizontalModelInsertColumns() |
|
455 | void tst_qxymodelmapper::horizontalModelInsertColumns() | |
454 | { |
|
456 | { | |
455 | // setup the mapper |
|
457 | // setup the mapper | |
456 | createHorizontalMapper(); |
|
458 | createHorizontalMapper(); | |
457 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
459 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
458 | QVERIFY(m_hMapper->model() != 0); |
|
460 | QVERIFY(m_hMapper->model() != 0); | |
459 |
|
461 | |||
460 | int insertCount = 4; |
|
462 | int insertCount = 4; | |
461 | m_model->insertColumns(3, insertCount); |
|
463 | m_model->insertColumns(3, insertCount); | |
462 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); |
|
464 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); | |
463 |
|
465 | |||
464 | int first = 3; |
|
466 | int first = 3; | |
465 | m_hMapper->setFirstColumn(3); |
|
467 | m_hMapper->setFirstColumn(3); | |
466 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); |
|
468 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); | |
467 |
|
469 | |||
468 | m_model->insertColumns(3, insertCount); |
|
470 | m_model->insertColumns(3, insertCount); | |
469 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); |
|
471 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); | |
470 |
|
472 | |||
471 | int countLimit = 6; |
|
473 | int countLimit = 6; | |
472 | m_hMapper->setColumnCount(countLimit); |
|
474 | m_hMapper->setColumnCount(countLimit); | |
473 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
475 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | |
474 |
|
476 | |||
475 | m_model->insertColumns(3, insertCount); |
|
477 | m_model->insertColumns(3, insertCount); | |
476 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
478 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | |
477 |
|
479 | |||
478 | m_hMapper->setFirstColumn(0); |
|
480 | m_hMapper->setFirstColumn(0); | |
479 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
481 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | |
480 |
|
482 | |||
481 | m_hMapper->setColumnCount(-1); |
|
483 | m_hMapper->setColumnCount(-1); | |
482 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); |
|
484 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); | |
483 | } |
|
485 | } | |
484 |
|
486 | |||
485 | void tst_qxymodelmapper::horizontalModelRemoveColumns() |
|
487 | void tst_qxymodelmapper::horizontalModelRemoveColumns() | |
486 | { |
|
488 | { | |
487 | // setup the mapper |
|
489 | // setup the mapper | |
488 | createHorizontalMapper(); |
|
490 | createHorizontalMapper(); | |
489 | QCOMPARE(m_series->count(), m_modelColumnCount); |
|
491 | QCOMPARE(m_series->count(), m_modelColumnCount); | |
490 | QVERIFY(m_hMapper->model() != 0); |
|
492 | QVERIFY(m_hMapper->model() != 0); | |
491 |
|
493 | |||
492 | int removeCount = 2; |
|
494 | int removeCount = 2; | |
493 | m_model->removeColumns(1, removeCount); |
|
495 | m_model->removeColumns(1, removeCount); | |
494 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); |
|
496 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); | |
495 |
|
497 | |||
496 | int first = 1; |
|
498 | int first = 1; | |
497 | m_hMapper->setFirstColumn(first); |
|
499 | m_hMapper->setFirstColumn(first); | |
498 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); |
|
500 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); | |
499 |
|
501 | |||
500 | m_model->removeColumns(1, removeCount); |
|
502 | m_model->removeColumns(1, removeCount); | |
501 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); |
|
503 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); | |
502 |
|
504 | |||
503 | int countLimit = 3; |
|
505 | int countLimit = 3; | |
504 | m_hMapper->setColumnCount(countLimit); |
|
506 | m_hMapper->setColumnCount(countLimit); | |
505 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
507 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | |
506 |
|
508 | |||
507 | m_model->removeColumns(1, removeCount); |
|
509 | m_model->removeColumns(1, removeCount); | |
508 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
510 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | |
509 |
|
511 | |||
510 | m_hMapper->setFirstColumn(0); |
|
512 | m_hMapper->setFirstColumn(0); | |
511 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
513 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | |
512 |
|
514 | |||
513 | m_hMapper->setColumnCount(-1); |
|
515 | m_hMapper->setColumnCount(-1); | |
514 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); |
|
516 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); | |
515 | } |
|
517 | } | |
516 |
|
518 | |||
517 | void tst_qxymodelmapper::modelUpdateCell() |
|
519 | void tst_qxymodelmapper::modelUpdateCell() | |
518 | { |
|
520 | { | |
519 | // setup the mapper |
|
521 | // setup the mapper | |
520 | createVerticalMapper(); |
|
522 | createVerticalMapper(); | |
521 |
|
523 | |||
522 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
524 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | |
523 | QCOMPARE(m_series->points().at(1).x(), 44.0); |
|
525 | QCOMPARE(m_series->points().at(1).x(), 44.0); | |
524 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
526 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | |
525 | } |
|
527 | } | |
526 |
|
528 | |||
|
529 | void tst_qxymodelmapper::verticalMapperSignals() | |||
|
530 | { | |||
|
531 | QVXYModelMapper *mapper = new QVXYModelMapper; | |||
|
532 | ||||
|
533 | QSignalSpy spy0(mapper, SIGNAL(firstRowChanged())); | |||
|
534 | QSignalSpy spy1(mapper, SIGNAL(rowCountChanged())); | |||
|
535 | QSignalSpy spy2(mapper, SIGNAL(xColumnChanged())); | |||
|
536 | QSignalSpy spy3(mapper, SIGNAL(yColumnChanged())); | |||
|
537 | QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); | |||
|
538 | QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); | |||
|
539 | ||||
|
540 | mapper->setXColumn(0); | |||
|
541 | mapper->setYColumn(1); | |||
|
542 | mapper->setModel(m_model); | |||
|
543 | mapper->setSeries(m_series); | |||
|
544 | mapper->setFirstRow(1); | |||
|
545 | mapper->setRowCount(5); | |||
|
546 | ||||
|
547 | QCOMPARE(spy0.count(), 1); | |||
|
548 | QCOMPARE(spy1.count(), 1); | |||
|
549 | QCOMPARE(spy2.count(), 1); | |||
|
550 | QCOMPARE(spy3.count(), 1); | |||
|
551 | QCOMPARE(spy4.count(), 1); | |||
|
552 | QCOMPARE(spy5.count(), 1); | |||
|
553 | ||||
|
554 | } | |||
|
555 | ||||
|
556 | void tst_qxymodelmapper::horizontalMapperSignals() | |||
|
557 | { | |||
|
558 | QHXYModelMapper *mapper = new QHXYModelMapper; | |||
|
559 | ||||
|
560 | QSignalSpy spy0(mapper, SIGNAL(firstColumnChanged())); | |||
|
561 | QSignalSpy spy1(mapper, SIGNAL(columnCountChanged())); | |||
|
562 | QSignalSpy spy2(mapper, SIGNAL(xRowChanged())); | |||
|
563 | QSignalSpy spy3(mapper, SIGNAL(yRowChanged())); | |||
|
564 | QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); | |||
|
565 | QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); | |||
|
566 | ||||
|
567 | mapper->setXRow(0); | |||
|
568 | mapper->setYRow(1); | |||
|
569 | mapper->setModel(m_model); | |||
|
570 | mapper->setSeries(m_series); | |||
|
571 | mapper->setFirstColumn(1); | |||
|
572 | mapper->setColumnCount(5); | |||
|
573 | ||||
|
574 | QCOMPARE(spy0.count(), 1); | |||
|
575 | QCOMPARE(spy1.count(), 1); | |||
|
576 | QCOMPARE(spy2.count(), 1); | |||
|
577 | QCOMPARE(spy3.count(), 1); | |||
|
578 | QCOMPARE(spy4.count(), 1); | |||
|
579 | QCOMPARE(spy5.count(), 1); | |||
|
580 | } | |||
|
581 | ||||
527 | QTEST_MAIN(tst_qxymodelmapper) |
|
582 | QTEST_MAIN(tst_qxymodelmapper) | |
528 |
|
583 | |||
529 | #include "tst_qxymodelmapper.moc" |
|
584 | #include "tst_qxymodelmapper.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now