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/QHXYModelMapper>
31
32QT_CHARTS_BEGIN_NAMESPACE
33
34/*!
35 \class QHXYModelMapper
36 \inmodule QtCharts
37 \brief The QHXYModelMapper class is a horizontal 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 horizontal 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 rows for the coordinates and holds the data
44 points for the XYSeries as columns. 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 QVXYModelMapper, QXYSeries, {Model Data Example}
51*/
52/*!
53 \qmltype HXYModelMapper
54 \instantiates QHXYModelMapper
55 \inqmlmodule QtCharts
56
57 \brief A horizontal 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 horizontal 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 rows for the coordinates and holds the data
63 points for the XYSeries as columns. 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 VXYModelMapper, XYSeries, {Model Data Example}
70*/
71
72/*!
73 \property QHXYModelMapper::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 HXYModelMapper::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 QHXYModelMapper::model
89 \brief The model that is used by the mapper.
90*/
91/*!
92 \qmlproperty SomeModel HXYModelMapper::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 QHXYModelMapper::xRow
102 \brief The row of the model that contains the x-coordinates of the data
103 points.
104
105 The default value is -1 (invalid mapping).
106*/
107/*!
108 \qmlproperty int HXYModelMapper::xRow
109 The row of the model that contains the x-coordinates of the data points.
110 The default value is -1 (invalid mapping).
111*/
112
113/*!
114 \property QHXYModelMapper::yRow
115 \brief The row of the model that contains the y-coordinates of the data
116 points.
117
118 The default value is -1 (invalid mapping).
119*/
120/*!
121 \qmlproperty int HXYModelMapper::yRow
122 The row of the model that contains the y-coordinates of the data points.
123
124 The default value is -1 (invalid mapping).
125*/
126
127/*!
128 \property QHXYModelMapper::firstColumn
129 \brief The column of the model that contains the data for the first point of the series.
130
131 The minimum and default value is 0.
132*/
133/*!
134 \qmlproperty int HXYModelMapper::firstColumn
135 The column 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 QHXYModelMapper::columnCount
141 \brief The number of columns 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 columns in the model).
145*/
146/*!
147 \qmlproperty int HXYModelMapper::columnCount
148 The number of columns of the model that are mapped as the data for series.
149 The default value is -1 (the number is limited by the number of columns in
150 the model).
151*/
152
153/*!
154 \fn void QHXYModelMapper::seriesReplaced()
155
156 This signal is emitted when the series that the mapper is connected to
157 changes.
158*/
159
160/*!
161 \fn void QHXYModelMapper::modelReplaced()
162
163 This signal is emitted when the model that the mapper is connected to
164 changes.
165*/
166
167/*!
168 \fn void QHXYModelMapper::xRowChanged()
169
170 This signal is emitted when the row that contains the x-coordinates of data
171 points changes.
172*/
173
174/*!
175 \fn void QHXYModelMapper::yRowChanged()
176
177 This signal is emitted when the row that contains the y-coordinates of data
178 points changes.
179*/
180
181/*!
182 \fn void QHXYModelMapper::firstColumnChanged()
183 This signal is emitted when the first column changes.
184*/
185
186/*!
187 \fn void QHXYModelMapper::columnCountChanged()
188 This signal is emitted when the number of columns changes.
189*/
190
191/*!
192 Constructs a mapper object that is a child of \a parent.
193*/
194QHXYModelMapper::QHXYModelMapper(QObject *parent) :
195 QXYModelMapper(parent)
196{
197 QXYModelMapper::setOrientation(Qt::Horizontal);
198}
199
200QAbstractItemModel *QHXYModelMapper::model() const
201{
202 return QXYModelMapper::model();
203}
204
205void QHXYModelMapper::setModel(QAbstractItemModel *model)
206{
207 if (model != QXYModelMapper::model()) {
208 QXYModelMapper::setModel(model);
209 emit modelReplaced();
210 }
211}
212
213QXYSeries *QHXYModelMapper::series() const
214{
215 return QXYModelMapper::series();
216}
217
218void QHXYModelMapper::setSeries(QXYSeries *series)
219{
220 if (series != QXYModelMapper::series()) {
221 QXYModelMapper::setSeries(series);
222 emit seriesReplaced();
223 }
224}
225
226int QHXYModelMapper::xRow() const
227{
228 return QXYModelMapper::xSection();
229}
230
231void QHXYModelMapper::setXRow(int xRow)
232{
233 if (xRow != xSection()) {
234 QXYModelMapper::setXSection(xRow);
235 emit xRowChanged();
236 }
237}
238
239int QHXYModelMapper::yRow() const
240{
241 return QXYModelMapper::ySection();
242}
243
244void QHXYModelMapper::setYRow(int yRow)
245{
246 if (yRow != ySection()) {
247 QXYModelMapper::setYSection(yRow);
248 emit yRowChanged();
249 }
250}
251
252int QHXYModelMapper::firstColumn() const
253{
254 return first();
255}
256
257void QHXYModelMapper::setFirstColumn(int firstColumn)
258{
259 if (firstColumn != first()) {
260 setFirst(firstColumn);
261 emit firstColumnChanged();
262 }
263}
264
265int QHXYModelMapper::columnCount() const
266{
267 return count();
268}
269
270void QHXYModelMapper::setColumnCount(int columnCount)
271{
272 if (columnCount != count()) {
273 setCount(columnCount);
274 emit columnCountChanged();
275 }
276}
277
278QT_CHARTS_END_NAMESPACE
279
280#include "moc_qhxymodelmapper.cpp"
281

source code of qtcharts/src/charts/xychart/qhxymodelmapper.cpp