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