1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtCharts/QVXYModelMapper> |
31 | |
32 | QT_CHARTS_BEGIN_NAMESPACE |
33 | |
34 | /*! |
35 | \class QVXYModelMapper |
36 | \inmodule QtCharts |
37 | \brief The QVXYModelMapper class is a vertical model mapper for line, |
38 | spline, and scatter series. |
39 | |
40 | Model mappers enable using a data model derived from the QAbstractItemModel |
41 | class as a data source for a chart. A vertical model mapper is used to |
42 | create a connection between a line, spline, or scatter series and the data |
43 | model that has \e X and \e Y columns for the coordinates and holds the data |
44 | points for the XYSeries as rows. A \e TableModel is a natural choice |
45 | for the model. |
46 | |
47 | Both model and series properties can be used to manipulate the data. The |
48 | model mapper keeps the series and the data model in sync. |
49 | |
50 | \sa QHXYModelMapper, QXYSeries, {Model Data Example} |
51 | */ |
52 | /*! |
53 | \qmltype VXYModelMapper |
54 | \instantiates QVXYModelMapper |
55 | \inqmlmodule QtCharts |
56 | |
57 | \brief A vertical model mapper for XYSeries. |
58 | |
59 | Model mappers enable using a data model derived from the QAbstractItemModel |
60 | class as a data source for a chart. A vertical model mapper is used to |
61 | create a connection between a line, spline, or scatter series and the data |
62 | model that has \e X and \e Y columns for the coordinates and holds the data |
63 | points for the XYSeries as rows. A \e TableModel is a natural choice |
64 | for the model. |
65 | |
66 | Both model and series properties can be used to manipulate the data. The |
67 | model mapper keeps the series and the data model in sync. |
68 | |
69 | \sa HXYModelMapper, XYSeries, {Model Data Example} |
70 | */ |
71 | |
72 | /*! |
73 | \property QVXYModelMapper::series |
74 | \brief The series that is used by the mapper. |
75 | |
76 | All the data in the series is discarded when it is set to the mapper. |
77 | When a new series is specified, the old series is disconnected (but it |
78 | preserves its data). |
79 | */ |
80 | /*! |
81 | \qmlproperty XYSeries VXYModelMapper::series |
82 | The series that is used by the mapper. All the data in the series is |
83 | discarded when it is set to the mapper. When a new series is specified, the |
84 | old series is disconnected (but it preserves its data). |
85 | */ |
86 | |
87 | /*! |
88 | \property QVXYModelMapper::model |
89 | \brief The model that is used by the mapper. |
90 | */ |
91 | /*! |
92 | \qmlproperty SomeModel VXYModelMapper::model |
93 | The data model that is used by the mapper. You need to implement the model |
94 | and expose it to QML. |
95 | |
96 | \note The model has to support adding and removing rows or columns and |
97 | modifying the data in the cells. |
98 | */ |
99 | |
100 | /*! |
101 | \property QVXYModelMapper::xColumn |
102 | \brief The column of the model that contains the x-coordinates of data |
103 | points. |
104 | |
105 | The default value is -1 (invalid mapping). |
106 | */ |
107 | /*! |
108 | \qmlproperty int VXYModelMapper::xColumn |
109 | The column of the model that contains the x-coordinates of data points. |
110 | The default value is -1 (invalid mapping). |
111 | */ |
112 | |
113 | /*! |
114 | \property QVXYModelMapper::yColumn |
115 | \brief The column of the model that contains the y-coordinates of data |
116 | points. |
117 | |
118 | The default value is -1 (invalid mapping). |
119 | */ |
120 | /*! |
121 | \qmlproperty int VXYModelMapper::yColumn |
122 | The column of the model that contains the y-coordinates of data points. |
123 | The default value is -1 (invalid mapping). |
124 | */ |
125 | |
126 | /*! |
127 | \property QVXYModelMapper::firstRow |
128 | \brief The row of the model that contains the data for the first point |
129 | of the series. |
130 | |
131 | The minimum and default value is 0. |
132 | */ |
133 | /*! |
134 | \qmlproperty int VXYModelMapper::firstRow |
135 | The row of the model that contains the data for the first point of the series. |
136 | The default value is 0. |
137 | */ |
138 | |
139 | /*! |
140 | \property QVXYModelMapper::rowCount |
141 | \brief The number of rows of the model that are mapped as the data for series. |
142 | |
143 | The minimum and default value is -1 (the number is limited by the number of |
144 | rows in the model). |
145 | */ |
146 | /*! |
147 | \qmlproperty int VXYModelMapper::rowCount |
148 | The number of rows of the model that are mapped as the data for series. The default value is |
149 | -1 (the number is limited by the number of rows in the model). |
150 | */ |
151 | |
152 | /*! |
153 | \fn void QVXYModelMapper::seriesReplaced() |
154 | |
155 | This signal is emitted when the series that the mapper is connected to changes. |
156 | */ |
157 | |
158 | /*! |
159 | \fn void QVXYModelMapper::modelReplaced() |
160 | |
161 | This signal is emitted when the model that the mapper is connected to changes. |
162 | */ |
163 | |
164 | /*! |
165 | \fn void QVXYModelMapper::xColumnChanged() |
166 | |
167 | This signal is emitted when the column that contains the x-coordinates of |
168 | data points changes. |
169 | */ |
170 | |
171 | /*! |
172 | \fn void QVXYModelMapper::yColumnChanged() |
173 | |
174 | This signal is emitted when the column that contains the y-coordinates of |
175 | data points changes. |
176 | */ |
177 | |
178 | /*! |
179 | \fn void QVXYModelMapper::firstRowChanged() |
180 | This signal is emitted when the first row changes. |
181 | */ |
182 | |
183 | /*! |
184 | \fn void QVXYModelMapper::rowCountChanged() |
185 | This signal is emitted when the number of rows changes. |
186 | */ |
187 | |
188 | /*! |
189 | Constructs a mapper object that is a child of \a parent. |
190 | */ |
191 | QVXYModelMapper::QVXYModelMapper(QObject *parent) : |
192 | QXYModelMapper(parent) |
193 | { |
194 | QXYModelMapper::setOrientation(Qt::Vertical); |
195 | } |
196 | |
197 | QAbstractItemModel *QVXYModelMapper::model() const |
198 | { |
199 | return QXYModelMapper::model(); |
200 | } |
201 | |
202 | void QVXYModelMapper::setModel(QAbstractItemModel *model) |
203 | { |
204 | if (model != QXYModelMapper::model()) { |
205 | QXYModelMapper::setModel(model); |
206 | emit modelReplaced(); |
207 | } |
208 | } |
209 | |
210 | QXYSeries *QVXYModelMapper::series() const |
211 | { |
212 | return QXYModelMapper::series(); |
213 | } |
214 | |
215 | void QVXYModelMapper::setSeries(QXYSeries *series) |
216 | { |
217 | if (series != QXYModelMapper::series()) { |
218 | QXYModelMapper::setSeries(series); |
219 | emit seriesReplaced(); |
220 | } |
221 | } |
222 | |
223 | int QVXYModelMapper::xColumn() const |
224 | { |
225 | return QXYModelMapper::xSection(); |
226 | } |
227 | |
228 | void QVXYModelMapper::setXColumn(int xColumn) |
229 | { |
230 | if (xColumn != xSection()) { |
231 | QXYModelMapper::setXSection(xColumn); |
232 | emit xColumnChanged(); |
233 | } |
234 | } |
235 | |
236 | int QVXYModelMapper::yColumn() const |
237 | { |
238 | return QXYModelMapper::ySection(); |
239 | } |
240 | |
241 | void QVXYModelMapper::setYColumn(int yColumn) |
242 | { |
243 | if (yColumn != ySection()) { |
244 | QXYModelMapper::setYSection(yColumn); |
245 | emit yColumnChanged(); |
246 | } |
247 | } |
248 | |
249 | int QVXYModelMapper::firstRow() const |
250 | { |
251 | return first(); |
252 | } |
253 | |
254 | void QVXYModelMapper::setFirstRow(int firstRow) |
255 | { |
256 | if (firstRow != first()) { |
257 | setFirst(firstRow); |
258 | emit firstRowChanged(); |
259 | } |
260 | } |
261 | |
262 | int QVXYModelMapper::rowCount() const |
263 | { |
264 | return count(); |
265 | } |
266 | |
267 | void QVXYModelMapper::setRowCount(int rowCount) |
268 | { |
269 | if (rowCount != count()) { |
270 | setCount(rowCount); |
271 | emit rowCountChanged(); |
272 | } |
273 | } |
274 | |
275 | QT_CHARTS_END_NAMESPACE |
276 | |
277 | #include "moc_qvxymodelmapper.cpp" |
278 | |