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/QHCandlestickModelMapper>
31#include <private/qcandlestickmodelmapper_p.h>
32
33QT_CHARTS_BEGIN_NAMESPACE
34
35/*!
36 \class QHCandlestickModelMapper
37 \since 5.8
38 \inmodule QtCharts
39 \brief The QHCandlestickModelMapper class is a horizontal model mapper for a candlestick series.
40
41 Model mappers enable using a data model derived from the QAbstractItemModel class
42 as a data source for a chart. A horizontal model mapper is used to create a connection
43 between a data model and QCandlestickSeries, so that each row in the data model defines a
44 candlestick item and each column maps to the open, high, low, close, and timestamp values
45 of the candlestick item.
46
47 Both model and candlestick series properties can be used to manipulate the data. The model
48 mapper keeps the candlestick series and the data model in sync.
49
50 The model mapper ensures that all the candlestick items in the candlestick series have equal
51 sizes. Therefore, adding or removing a value from a candlestick item causes the same change to
52 be made in all the candlestick items in the candlestick series.
53
54 \sa QCandlestickSeries, QCandlestickSet, QVCandlestickModelMapper
55*/
56
57/*!
58 \qmltype HCandlestickModelMapper
59 \since QtCharts 2.2
60 \instantiates QHCandlestickModelMapper
61 \inqmlmodule QtCharts
62 \brief Horizontal model mapper for a candlestick series.
63
64 Model mappers enable using a data model derived from the QAbstractItemModel class
65 as a data source for a chart. A horizontal model mapper is used to create a connection
66 between a data model and CandlestickSeries, so that each row in the data model defines a
67 candlestick item and each column maps to the open, high, low, close, and timestamp values
68 of the candlestick item.
69
70 Both model and candlestick series properties can be used to manipulate the data. The model
71 mapper keeps the candlestick series and the data model in sync.
72
73 The model mapper ensures that all the candlestick items in the candlestick series have equal
74 sizes. Therefore, adding or removing a value from a candlestick item causes the same change to
75 be made in all the candlestick items in the candlestick series.
76
77 The following QML example creates a candlestick series with three candlestick items (assuming
78 the model has at least four rows). Each candlestick item contains data defined by the timestamp,
79 open, high, low, and close columns. The name of an item is defined by the vertical header of
80 the row.
81 \qml
82 CandlestickSeries {
83 HCandlestickModelMapper {
84 model: myCustomModel // QAbstractItemModel derived implementation
85 timestampColumn: 1
86 openColumn: 2
87 highColumn: 3
88 lowColumn: 4
89 closeColumn: 5
90 firstSetRow: 1
91 lastSetRow: 3
92 }
93 }
94 \endqml
95
96 \sa CandlestickSeries, CandlestickSet, VCandlestickModelMapper
97*/
98
99/*!
100 \qmlproperty QAbstractItemModel HCandlestickModelMapper::model
101 The QAbstractItemModel-based model that is used by the mapper. The model must be
102 implemented and exposed to QML.
103
104 \note The model used must support adding and removing rows or columns and modifying the data of
105 the cells.
106*/
107
108/*!
109 \qmlproperty CandlestickSeries HCandlestickModelMapper::series
110 The CandlestickSeries based object that is used by the mapper.
111
112 All the data in the series is discarded when it is set to the mapper. When a new series is
113 specified, the old series is disconnected (preserving its data).
114*/
115
116/*!
117 \property QHCandlestickModelMapper::timestampColumn
118 \brief The column of the model that contains the timestamp values of the
119 candlestick items in the series.
120
121 The default value is -1 (invalid mapping).
122*/
123
124/*!
125 \qmlproperty int HCandlestickModelMapper::timestampColumn
126 The column of the model that contains the timestamp values of the
127 candlestick items in the series. The default value is -1
128 (invalid mapping).
129*/
130
131/*!
132 \property QHCandlestickModelMapper::openColumn
133 \brief The column of the model that contains the open values of the
134 candlestick items in the series.
135
136 The default value is -1 (invalid mapping).
137*/
138
139/*!
140 \qmlproperty int HCandlestickModelMapper::openColumn
141 The column of the model that contains the open values of the
142 candlestick items in the series. The default value is -1
143 (invalid mapping).
144*/
145
146/*!
147 \property QHCandlestickModelMapper::highColumn
148 \brief The column of the model that contains the high values of the
149 candlestick items in the series.
150
151 The default value is -1 (invalid mapping).
152*/
153
154/*!
155 \qmlproperty int HCandlestickModelMapper::highColumn
156 The column of the model that contains the high values of the
157 candlestick items in the series. The default value is -1
158 (invalid mapping).
159*/
160
161/*!
162 \property QHCandlestickModelMapper::lowColumn
163 \brief The column of the model that contains the low values of the
164 candlestick items in the series.
165
166 The default value is -1 (invalid mapping).
167*/
168
169/*!
170 \qmlproperty int HCandlestickModelMapper::lowColumn
171 The column of the model that contains the low values of the
172 candlestick items in the series. The default value is -1
173 (invalid mapping).
174*/
175
176/*!
177 \property QHCandlestickModelMapper::closeColumn
178 \brief The column of the model that contains the close values of the
179 candlestick items in the series.
180
181 The default value is -1 (invalid mapping).
182*/
183
184/*!
185 \qmlproperty int HCandlestickModelMapper::closeColumn
186 The column of the model that contains the close values of the
187 candlestick items in the series. The default value is -1
188 (invalid mapping).
189*/
190
191/*!
192 \property QHCandlestickModelMapper::firstSetRow
193 \brief The row of the model that is used as the data source for the first item.
194
195 The default value is -1 (invalid mapping).
196*/
197
198/*!
199 \qmlproperty int HCandlestickModelMapper::firstSetRow
200 The row of the model that is used as the data source for the first item.
201 The default value is -1 (invalid mapping).
202*/
203
204/*!
205 \property QHCandlestickModelMapper::lastSetRow
206 \brief The row of the model that is used as the data source for the last item.
207
208 The default value is -1 (invalid mapping).
209*/
210
211/*!
212 \qmlproperty int HCandlestickModelMapper::lastSetRow
213 The row of the model that is used as the data source for the last item.
214 The default value is -1 (invalid mapping).
215*/
216
217/*!
218 \fn void QHCandlestickModelMapper::timestampColumnChanged()
219 \brief Emitted when the column of the model that contains timestamp values is changed
220 \sa timestampColumn
221*/
222
223/*!
224 \fn void QHCandlestickModelMapper::openColumnChanged()
225 \brief Emitted when the column of the model that contains open values is changed.
226 \sa openColumn
227*/
228/*!
229 \fn void QHCandlestickModelMapper::highColumnChanged()
230 \brief Emitted when the column of the model that contains high values is changed.
231 \sa highColumn
232*/
233
234/*!
235 \fn void QHCandlestickModelMapper::lowColumnChanged()
236 \brief Emitted when the column of the model that contains low values is changed.
237 \sa lowColumn
238*/
239
240/*!
241 \fn void QHCandlestickModelMapper::closeColumnChanged()
242 \brief Emitted when the column of the model that contains close values is changed.
243 \sa closeColumn
244*/
245
246/*!
247 \fn void QHCandlestickModelMapper::firstSetRowChanged()
248 \brief Emitted when the row of the model that contains the data of the first item is changed.
249 \sa firstSetRow
250*/
251
252/*!
253 \fn void QHCandlestickModelMapper::lastSetRowChanged()
254 \brief Emitted when the row of the model that contains the data of the last item is changed.
255 \sa lastSetRow
256*/
257
258/*!
259 Constructs a horizontal model mapper object which is a child of \a parent.
260*/
261QHCandlestickModelMapper::QHCandlestickModelMapper(QObject *parent)
262 : QCandlestickModelMapper(parent)
263{
264 connect(sender: d_ptr, SIGNAL(timestampChanged()), receiver: this, SIGNAL(timestampColumnChanged()));
265 connect(sender: d_ptr, SIGNAL(openChanged()), receiver: this, SIGNAL(openColumnChanged()));
266 connect(sender: d_ptr, SIGNAL(highChanged()), receiver: this, SIGNAL(highColumnChanged()));
267 connect(sender: d_ptr, SIGNAL(lowChanged()), receiver: this, SIGNAL(lowColumnChanged()));
268 connect(sender: d_ptr, SIGNAL(closeChanged()), receiver: this, SIGNAL(closeColumnChanged()));
269 connect(sender: d_ptr, SIGNAL(firstSetSectionChanged()), receiver: this, SIGNAL(firstSetRowChanged()));
270 connect(sender: d_ptr, SIGNAL(lastSetSectionChanged()), receiver: this, SIGNAL(lastSetRowChanged()));
271}
272
273/*!
274 Returns Qt::Horizontal. This means that values of the item are read from rows.
275*/
276Qt::Orientation QHCandlestickModelMapper::orientation() const
277{
278 return Qt::Horizontal;
279}
280
281void QHCandlestickModelMapper::setTimestampColumn(int timestampColumn)
282{
283 QCandlestickModelMapper::setTimestamp(timestampColumn);
284}
285
286int QHCandlestickModelMapper::timestampColumn() const
287{
288 return QCandlestickModelMapper::timestamp();
289}
290
291void QHCandlestickModelMapper::setOpenColumn(int openColumn)
292{
293 QCandlestickModelMapper::setOpen(openColumn);
294}
295
296int QHCandlestickModelMapper::openColumn() const
297{
298 return QCandlestickModelMapper::open();
299}
300
301void QHCandlestickModelMapper::setHighColumn(int highColumn)
302{
303 QCandlestickModelMapper::setHigh(highColumn);
304}
305
306int QHCandlestickModelMapper::highColumn() const
307{
308 return QCandlestickModelMapper::high();
309}
310
311void QHCandlestickModelMapper::setLowColumn(int lowColumn)
312{
313 QCandlestickModelMapper::setLow(lowColumn);
314}
315
316int QHCandlestickModelMapper::lowColumn() const
317{
318 return QCandlestickModelMapper::low();
319}
320
321void QHCandlestickModelMapper::setCloseColumn(int closeColumn)
322{
323 QCandlestickModelMapper::setClose(closeColumn);
324}
325
326int QHCandlestickModelMapper::closeColumn() const
327{
328 return QCandlestickModelMapper::close();
329}
330
331void QHCandlestickModelMapper::setFirstSetRow(int firstSetRow)
332{
333 QCandlestickModelMapper::setFirstSetSection(firstSetRow);
334}
335
336int QHCandlestickModelMapper::firstSetRow() const
337{
338 return QCandlestickModelMapper::firstSetSection();
339}
340
341void QHCandlestickModelMapper::setLastSetRow(int lastSetRow)
342{
343 QCandlestickModelMapper::setLastSetSection(lastSetRow);
344}
345
346int QHCandlestickModelMapper::lastSetRow() const
347{
348 return QCandlestickModelMapper::lastSetSection();
349}
350
351QT_CHARTS_END_NAMESPACE
352
353#include "moc_qhcandlestickmodelmapper.cpp"
354

source code of qtcharts/src/charts/candlestickchart/qhcandlestickmodelmapper.cpp