1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtCharts/QVXYModelMapper>
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QVXYModelMapper
10 \inmodule QtCharts
11 \brief The QVXYModelMapper class is a vertical model mapper for line,
12 spline, and scatter series.
13
14 Model mappers enable using a data model derived from the QAbstractItemModel
15 class as a data source for a chart. A vertical model mapper is used to
16 create a connection between a line, spline, or scatter series and the data
17 model that has \e X and \e Y columns for the coordinates and holds the data
18 points for the XYSeries as rows. A \e TableModel is a natural choice
19 for the model.
20
21 Both model and series properties can be used to manipulate the data. The
22 model mapper keeps the series and the data model in sync.
23
24 \sa QHXYModelMapper, QXYSeries, {Charts with Widgets Gallery}
25*/
26/*!
27 \qmltype VXYModelMapper
28 \instantiates QVXYModelMapper
29 \inqmlmodule QtCharts
30
31 \brief A vertical model mapper for XYSeries.
32
33 Model mappers enable using a data model derived from the QAbstractItemModel
34 class as a data source for a chart. A vertical model mapper is used to
35 create a connection between a line, spline, or scatter series and the data
36 model that has \e X and \e Y columns for the coordinates and holds the data
37 points for the XYSeries as rows. A \e TableModel is a natural choice
38 for the model.
39
40 Both model and series properties can be used to manipulate the data. The
41 model mapper keeps the series and the data model in sync.
42
43 \sa HXYModelMapper, XYSeries, {Charts with Widgets Gallery}
44*/
45
46/*!
47 \property QVXYModelMapper::series
48 \brief The series that is used by the mapper.
49
50 All the data in the series is discarded when it is set to the mapper.
51 When a new series is specified, the old series is disconnected (but it
52 preserves its data).
53*/
54/*!
55 \qmlproperty XYSeries VXYModelMapper::series
56 The series that is used by the mapper. All the data in the series is
57 discarded when it is set to the mapper. When a new series is specified, the
58 old series is disconnected (but it preserves its data).
59*/
60
61/*!
62 \property QVXYModelMapper::model
63 \brief The model that is used by the mapper.
64*/
65/*!
66 \qmlproperty SomeModel VXYModelMapper::model
67 The data model that is used by the mapper. You need to implement the model
68 and expose it to QML.
69
70 \note The model has to support adding and removing rows or columns and
71 modifying the data in the cells.
72*/
73
74/*!
75 \property QVXYModelMapper::xColumn
76 \brief The column of the model that contains the x-coordinates of data
77 points.
78
79 The default value is -1 (invalid mapping).
80*/
81/*!
82 \qmlproperty int VXYModelMapper::xColumn
83 The column of the model that contains the x-coordinates of data points.
84 The default value is -1 (invalid mapping).
85*/
86
87/*!
88 \property QVXYModelMapper::yColumn
89 \brief The column of the model that contains the y-coordinates of data
90 points.
91
92 The default value is -1 (invalid mapping).
93*/
94/*!
95 \qmlproperty int VXYModelMapper::yColumn
96 The column of the model that contains the y-coordinates of data points.
97 The default value is -1 (invalid mapping).
98*/
99
100/*!
101 \property QVXYModelMapper::firstRow
102 \brief The row of the model that contains the data for the first point
103 of the series.
104
105 The minimum and default value is 0.
106*/
107/*!
108 \qmlproperty int VXYModelMapper::firstRow
109 The row of the model that contains the data for the first point of the series.
110 The default value is 0.
111*/
112
113/*!
114 \property QVXYModelMapper::rowCount
115 \brief The number of rows of the model that are mapped as the data for series.
116
117 The minimum and default value is -1 (the number is limited by the number of
118 rows in the model).
119*/
120/*!
121 \qmlproperty int VXYModelMapper::rowCount
122 The number of rows of the model that are mapped as the data for series. The default value is
123 -1 (the number is limited by the number of rows in the model).
124*/
125
126/*!
127 \fn void QVXYModelMapper::seriesReplaced()
128
129 This signal is emitted when the series that the mapper is connected to changes.
130*/
131
132/*!
133 \fn void QVXYModelMapper::modelReplaced()
134
135 This signal is emitted when the model that the mapper is connected to changes.
136*/
137
138/*!
139 \fn void QVXYModelMapper::xColumnChanged()
140
141 This signal is emitted when the column that contains the x-coordinates of
142 data points changes.
143*/
144
145/*!
146 \fn void QVXYModelMapper::yColumnChanged()
147
148 This signal is emitted when the column that contains the y-coordinates of
149 data points changes.
150*/
151
152/*!
153 \fn void QVXYModelMapper::firstRowChanged()
154 This signal is emitted when the first row changes.
155*/
156
157/*!
158 \fn void QVXYModelMapper::rowCountChanged()
159 This signal is emitted when the number of rows changes.
160*/
161
162/*!
163 Constructs a mapper object that is a child of \a parent.
164*/
165QVXYModelMapper::QVXYModelMapper(QObject *parent) :
166 QXYModelMapper(parent)
167{
168 QXYModelMapper::setOrientation(Qt::Vertical);
169}
170
171QAbstractItemModel *QVXYModelMapper::model() const
172{
173 return QXYModelMapper::model();
174}
175
176void QVXYModelMapper::setModel(QAbstractItemModel *model)
177{
178 if (model != QXYModelMapper::model()) {
179 QXYModelMapper::setModel(model);
180 emit modelReplaced();
181 }
182}
183
184QXYSeries *QVXYModelMapper::series() const
185{
186 return QXYModelMapper::series();
187}
188
189void QVXYModelMapper::setSeries(QXYSeries *series)
190{
191 if (series != QXYModelMapper::series()) {
192 QXYModelMapper::setSeries(series);
193 emit seriesReplaced();
194 }
195}
196
197int QVXYModelMapper::xColumn() const
198{
199 return QXYModelMapper::xSection();
200}
201
202void QVXYModelMapper::setXColumn(int xColumn)
203{
204 if (xColumn != xSection()) {
205 QXYModelMapper::setXSection(xColumn);
206 emit xColumnChanged();
207 }
208}
209
210int QVXYModelMapper::yColumn() const
211{
212 return QXYModelMapper::ySection();
213}
214
215void QVXYModelMapper::setYColumn(int yColumn)
216{
217 if (yColumn != ySection()) {
218 QXYModelMapper::setYSection(yColumn);
219 emit yColumnChanged();
220 }
221}
222
223int QVXYModelMapper::firstRow() const
224{
225 return first();
226}
227
228void QVXYModelMapper::setFirstRow(int firstRow)
229{
230 if (firstRow != first()) {
231 setFirst(firstRow);
232 emit firstRowChanged();
233 }
234}
235
236int QVXYModelMapper::rowCount() const
237{
238 return count();
239}
240
241void QVXYModelMapper::setRowCount(int rowCount)
242{
243 if (rowCount != count()) {
244 setCount(rowCount);
245 emit rowCountChanged();
246 }
247}
248
249QT_END_NAMESPACE
250
251#include "moc_qvxymodelmapper.cpp"
252

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