1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtCharts/QHXYModelMapper>
5
6QT_BEGIN_NAMESPACE
7
8/*!
9 \class QHXYModelMapper
10 \inmodule QtCharts
11 \brief The QHXYModelMapper class is a horizontal 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 horizontal 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 rows for the coordinates and holds the data
18 points for the XYSeries as columns. 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 QVXYModelMapper, QXYSeries, {Charts with Widgets Gallery}
25*/
26/*!
27 \qmltype HXYModelMapper
28 \instantiates QHXYModelMapper
29 \inqmlmodule QtCharts
30
31 \brief A horizontal 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 horizontal 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 rows for the coordinates and holds the data
37 points for the XYSeries as columns. 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 VXYModelMapper, XYSeries, {Charts with Widgets Gallery}
44*/
45
46/*!
47 \property QHXYModelMapper::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 HXYModelMapper::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 QHXYModelMapper::model
63 \brief The model that is used by the mapper.
64*/
65/*!
66 \qmlproperty SomeModel HXYModelMapper::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 QHXYModelMapper::xRow
76 \brief The row of the model that contains the x-coordinates of the data
77 points.
78
79 The default value is -1 (invalid mapping).
80*/
81/*!
82 \qmlproperty int HXYModelMapper::xRow
83 The row of the model that contains the x-coordinates of the data points.
84 The default value is -1 (invalid mapping).
85*/
86
87/*!
88 \property QHXYModelMapper::yRow
89 \brief The row of the model that contains the y-coordinates of the data
90 points.
91
92 The default value is -1 (invalid mapping).
93*/
94/*!
95 \qmlproperty int HXYModelMapper::yRow
96 The row of the model that contains the y-coordinates of the data points.
97
98 The default value is -1 (invalid mapping).
99*/
100
101/*!
102 \property QHXYModelMapper::firstColumn
103 \brief The column of the model that contains the data for the first point of the series.
104
105 The minimum and default value is 0.
106*/
107/*!
108 \qmlproperty int HXYModelMapper::firstColumn
109 The column 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 QHXYModelMapper::columnCount
115 \brief The number of columns 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 columns in the model).
119*/
120/*!
121 \qmlproperty int HXYModelMapper::columnCount
122 The number of columns of the model that are mapped as the data for series.
123 The default value is -1 (the number is limited by the number of columns in
124 the model).
125*/
126
127/*!
128 \fn void QHXYModelMapper::seriesReplaced()
129
130 This signal is emitted when the series that the mapper is connected to
131 changes.
132*/
133
134/*!
135 \fn void QHXYModelMapper::modelReplaced()
136
137 This signal is emitted when the model that the mapper is connected to
138 changes.
139*/
140
141/*!
142 \fn void QHXYModelMapper::xRowChanged()
143
144 This signal is emitted when the row that contains the x-coordinates of data
145 points changes.
146*/
147
148/*!
149 \fn void QHXYModelMapper::yRowChanged()
150
151 This signal is emitted when the row that contains the y-coordinates of data
152 points changes.
153*/
154
155/*!
156 \fn void QHXYModelMapper::firstColumnChanged()
157 This signal is emitted when the first column changes.
158*/
159
160/*!
161 \fn void QHXYModelMapper::columnCountChanged()
162 This signal is emitted when the number of columns changes.
163*/
164
165/*!
166 Constructs a mapper object that is a child of \a parent.
167*/
168QHXYModelMapper::QHXYModelMapper(QObject *parent) :
169 QXYModelMapper(parent)
170{
171 QXYModelMapper::setOrientation(Qt::Horizontal);
172}
173
174QAbstractItemModel *QHXYModelMapper::model() const
175{
176 return QXYModelMapper::model();
177}
178
179void QHXYModelMapper::setModel(QAbstractItemModel *model)
180{
181 if (model != QXYModelMapper::model()) {
182 QXYModelMapper::setModel(model);
183 emit modelReplaced();
184 }
185}
186
187QXYSeries *QHXYModelMapper::series() const
188{
189 return QXYModelMapper::series();
190}
191
192void QHXYModelMapper::setSeries(QXYSeries *series)
193{
194 if (series != QXYModelMapper::series()) {
195 QXYModelMapper::setSeries(series);
196 emit seriesReplaced();
197 }
198}
199
200int QHXYModelMapper::xRow() const
201{
202 return QXYModelMapper::xSection();
203}
204
205void QHXYModelMapper::setXRow(int xRow)
206{
207 if (xRow != xSection()) {
208 QXYModelMapper::setXSection(xRow);
209 emit xRowChanged();
210 }
211}
212
213int QHXYModelMapper::yRow() const
214{
215 return QXYModelMapper::ySection();
216}
217
218void QHXYModelMapper::setYRow(int yRow)
219{
220 if (yRow != ySection()) {
221 QXYModelMapper::setYSection(yRow);
222 emit yRowChanged();
223 }
224}
225
226int QHXYModelMapper::firstColumn() const
227{
228 return first();
229}
230
231void QHXYModelMapper::setFirstColumn(int firstColumn)
232{
233 if (firstColumn != first()) {
234 setFirst(firstColumn);
235 emit firstColumnChanged();
236 }
237}
238
239int QHXYModelMapper::columnCount() const
240{
241 return count();
242}
243
244void QHXYModelMapper::setColumnCount(int columnCount)
245{
246 if (columnCount != count()) {
247 setCount(columnCount);
248 emit columnCountChanged();
249 }
250}
251
252QT_END_NAMESPACE
253
254#include "moc_qhxymodelmapper.cpp"
255

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