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/QVCandlestickModelMapper>
31#include <private/qcandlestickmodelmapper_p.h>
32
33QT_CHARTS_BEGIN_NAMESPACE
34
35/*!
36 \class QVCandlestickModelMapper
37 \since 5.8
38 \inmodule QtCharts
39 \brief The QVCandlestickModelMapper class is a vertical 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 vertical model mapper is used to create a connection
43 between a data model and QCandlestickSeries, so that each column in the data model defines a
44 candlestick item and each row 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, QHCandlestickModelMapper
55*/
56
57/*!
58 \qmltype VCandlestickModelMapper
59 \since QtCharts 2.2
60 \instantiates QVCandlestickModelMapper
61 \inqmlmodule QtCharts
62 \brief Vertical 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 vertical model mapper is used to create a connection
66 between a data model and CandlestickSeries, so that each column in the data model defines a
67 candlestick item and each row 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 columns). Each candlestick item contains data defined by the
79 timestamp, open, high, low, and close rows. The name of an item is defined by the horizontal
80 header of the column.
81 \qml
82 CandlestickSeries {
83 VCandlestickModelMapper {
84 model: myCustomModel // QAbstractItemModel derived implementation
85 timestampRow: 1
86 openRow: 2
87 highRow: 3
88 lowRow: 4
89 closeRow: 5
90 firstSetColumn: 1
91 lastSetColumn: 3
92 }
93 }
94 \endqml
95
96 \sa CandlestickSeries, CandlestickSet, HCandlestickModelMapper
97*/
98
99/*!
100 \qmlproperty QAbstractItemModel VCandlestickModelMapper::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 VCandlestickModelMapper::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 (but it preserves its data).
114*/
115
116/*!
117 \property QVCandlestickModelMapper::timestampRow
118 \brief The row 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 VCandlestickModelMapper::timestampRow
126 The row 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 QVCandlestickModelMapper::openRow
133 \brief The row 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 VCandlestickModelMapper::openRow
141 The row 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 QVCandlestickModelMapper::highRow
148 \brief The row 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 VCandlestickModelMapper::highRow
156 The row 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 QVCandlestickModelMapper::lowRow
163 \brief The row 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 VCandlestickModelMapper::lowRow
171 The row 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 QVCandlestickModelMapper::closeRow
178 \brief The row 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 VCandlestickModelMapper::closeRow
186 The row 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 QVCandlestickModelMapper::firstSetColumn
193 \brief The column 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 VCandlestickModelMapper::firstSetColumn
200 The column 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 QVCandlestickModelMapper::lastSetColumn
206 \brief The column 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 VCandlestickModelMapper::lastSetColumn
213 The column 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 QVCandlestickModelMapper::timestampRowChanged()
219 \brief Emitted when the row of the model that contains timestamp values is changed.
220 \sa timestampRow
221*/
222
223/*!
224 \fn void QVCandlestickModelMapper::openRowChanged()
225 \brief Emitted when the row of the model that contains open values is changed.
226 \sa openRow
227*/
228
229/*!
230 \fn void QVCandlestickModelMapper::highRowChanged()
231 \brief Emitted when the row of the model that contains high values is changed.
232 \sa highRow
233*/
234
235/*!
236 \fn void QVCandlestickModelMapper::lowRowChanged()
237 \brief Emitted when the row of the model that contains low values is changed.
238 \sa lowRow
239*/
240
241/*!
242 \fn void QVCandlestickModelMapper::closeRowChanged()
243 \brief Emitted when the row of the model that contains close values is changed.
244 \sa closeRow
245*/
246
247/*!
248 \fn void QVCandlestickModelMapper::firstSetColumnChanged()
249 \brief Emitted when the column of the model that contains the data of the first item is changed.
250 \sa firstSetColumn
251*/
252
253/*!
254 \fn void QVCandlestickModelMapper::lastSetColumnChanged()
255 \brief Emitted when the column of the model that contains the data of the last item is changed.
256 \sa lastSetColumn
257*/
258
259/*!
260 Constructs a vertical model mapper object which is a child of \a parent.
261*/
262QVCandlestickModelMapper::QVCandlestickModelMapper(QObject *parent)
263 : QCandlestickModelMapper(parent)
264{
265 connect(sender: d_ptr, SIGNAL(timestampChanged()), receiver: this, SIGNAL(timestampRowChanged()));
266 connect(sender: d_ptr, SIGNAL(openChanged()), receiver: this, SIGNAL(openRowChanged()));
267 connect(sender: d_ptr, SIGNAL(highChanged()), receiver: this, SIGNAL(highRowChanged()));
268 connect(sender: d_ptr, SIGNAL(lowChanged()), receiver: this, SIGNAL(lowRowChanged()));
269 connect(sender: d_ptr, SIGNAL(closeChanged()), receiver: this, SIGNAL(closeRowChanged()));
270 connect(sender: d_ptr, SIGNAL(firstSetSectionChanged()), receiver: this, SIGNAL(firstSetColumnChanged()));
271 connect(sender: d_ptr, SIGNAL(lastSetSectionChanged()), receiver: this, SIGNAL(lastSetColumnChanged()));
272}
273
274/*!
275 Returns Qt::Vertical. This means that values of the item are read from columns.
276*/
277Qt::Orientation QVCandlestickModelMapper::orientation() const
278{
279 return Qt::Vertical;
280}
281
282void QVCandlestickModelMapper::setTimestampRow(int timestampRow)
283{
284 QCandlestickModelMapper::setTimestamp(timestampRow);
285}
286
287int QVCandlestickModelMapper::timestampRow() const
288{
289 return QCandlestickModelMapper::timestamp();
290}
291
292void QVCandlestickModelMapper::setOpenRow(int openRow)
293{
294 QCandlestickModelMapper::setOpen(openRow);
295}
296
297int QVCandlestickModelMapper::openRow() const
298{
299 return QCandlestickModelMapper::open();
300}
301
302void QVCandlestickModelMapper::setHighRow(int highRow)
303{
304 QCandlestickModelMapper::setHigh(highRow);
305}
306
307int QVCandlestickModelMapper::highRow() const
308{
309 return QCandlestickModelMapper::high();
310}
311
312void QVCandlestickModelMapper::setLowRow(int lowRow)
313{
314 QCandlestickModelMapper::setLow(lowRow);
315}
316
317int QVCandlestickModelMapper::lowRow() const
318{
319 return QCandlestickModelMapper::low();
320}
321
322void QVCandlestickModelMapper::setCloseRow(int closeRow)
323{
324 QCandlestickModelMapper::setClose(closeRow);
325}
326
327int QVCandlestickModelMapper::closeRow() const
328{
329 return QCandlestickModelMapper::close();
330}
331
332void QVCandlestickModelMapper::setFirstSetColumn(int firstSetColumn)
333{
334 QCandlestickModelMapper::setFirstSetSection(firstSetColumn);
335}
336
337int QVCandlestickModelMapper::firstSetColumn() const
338{
339 return QCandlestickModelMapper::firstSetSection();
340}
341
342void QVCandlestickModelMapper::setLastSetColumn(int lastSetColumn)
343{
344 QCandlestickModelMapper::setLastSetSection(lastSetColumn);
345}
346
347int QVCandlestickModelMapper::lastSetColumn() const
348{
349 return QCandlestickModelMapper::lastSetSection();
350}
351
352QT_CHARTS_END_NAMESPACE
353
354#include "moc_qvcandlestickmodelmapper.cpp"
355

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