| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #include <QtCharts/QHCandlestickModelMapper> | 
| 5 | #include <private/qcandlestickmodelmapper_p.h> | 
| 6 |  | 
| 7 | QT_BEGIN_NAMESPACE | 
| 8 |  | 
| 9 | /*! | 
| 10 |     \class QHCandlestickModelMapper | 
| 11 |     \since 5.8 | 
| 12 |     \inmodule QtCharts | 
| 13 |     \brief The QHCandlestickModelMapper class is a horizontal 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 horizontal model mapper is used to create a connection | 
| 17 |     between a data model and QCandlestickSeries, so that each row in the data model defines a | 
| 18 |     candlestick item and each column 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, QVCandlestickModelMapper | 
| 29 | */ | 
| 30 |  | 
| 31 | /*! | 
| 32 |     \qmltype HCandlestickModelMapper | 
| 33 |     \since QtCharts 2.2 | 
| 34 |     \nativetype QHCandlestickModelMapper | 
| 35 |     \inqmlmodule QtCharts | 
| 36 |     \brief Horizontal 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 horizontal model mapper is used to create a connection | 
| 40 |     between a data model and CandlestickSeries, so that each row in the data model defines a | 
| 41 |     candlestick item and each column 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 rows). Each candlestick item contains data defined by the timestamp, | 
| 53 |     open, high, low, and close columns. The name of an item is defined by the vertical header of | 
| 54 |     the row. | 
| 55 |     \qml | 
| 56 |         CandlestickSeries { | 
| 57 |             HCandlestickModelMapper { | 
| 58 |                 model: myCustomModel // QAbstractItemModel derived implementation | 
| 59 |                 timestampColumn: 1 | 
| 60 |                 openColumn: 2 | 
| 61 |                 highColumn: 3 | 
| 62 |                 lowColumn: 4 | 
| 63 |                 closeColumn: 5 | 
| 64 |                 firstSetRow: 1 | 
| 65 |                 lastSetRow: 3 | 
| 66 |             } | 
| 67 |         } | 
| 68 |     \endqml | 
| 69 |  | 
| 70 |     \sa CandlestickSeries, CandlestickSet, VCandlestickModelMapper | 
| 71 | */ | 
| 72 |  | 
| 73 | /*! | 
| 74 |     \qmlproperty QAbstractItemModel HCandlestickModelMapper::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 HCandlestickModelMapper::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 (preserving its data). | 
| 88 | */ | 
| 89 |  | 
| 90 | /*! | 
| 91 |     \property QHCandlestickModelMapper::timestampColumn | 
| 92 |     \brief The column 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 HCandlestickModelMapper::timestampColumn | 
| 100 |     The column 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 QHCandlestickModelMapper::openColumn | 
| 107 |     \brief The column 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 HCandlestickModelMapper::openColumn | 
| 115 |     The column 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 QHCandlestickModelMapper::highColumn | 
| 122 |     \brief The column 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 HCandlestickModelMapper::highColumn | 
| 130 |     The column 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 QHCandlestickModelMapper::lowColumn | 
| 137 |     \brief The column 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 HCandlestickModelMapper::lowColumn | 
| 145 |     The column 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 QHCandlestickModelMapper::closeColumn | 
| 152 |     \brief The column 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 HCandlestickModelMapper::closeColumn | 
| 160 |     The column 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 QHCandlestickModelMapper::firstSetRow | 
| 167 |     \brief The row 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 HCandlestickModelMapper::firstSetRow | 
| 174 |     The row 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 QHCandlestickModelMapper::lastSetRow | 
| 180 |     \brief The row 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 HCandlestickModelMapper::lastSetRow | 
| 187 |     The row 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 QHCandlestickModelMapper::timestampColumnChanged() | 
| 193 |     \brief Emitted when the column of the model that contains timestamp values is changed | 
| 194 |     \sa timestampColumn | 
| 195 | */ | 
| 196 |  | 
| 197 | /*! | 
| 198 |     \fn void QHCandlestickModelMapper::openColumnChanged() | 
| 199 |     \brief Emitted when the column of the model that contains open values is changed. | 
| 200 |     \sa openColumn | 
| 201 | */ | 
| 202 | /*! | 
| 203 |     \fn void QHCandlestickModelMapper::highColumnChanged() | 
| 204 |     \brief Emitted when the column of the model that contains high values is changed. | 
| 205 |     \sa highColumn | 
| 206 | */ | 
| 207 |  | 
| 208 | /*! | 
| 209 |     \fn void QHCandlestickModelMapper::lowColumnChanged() | 
| 210 |     \brief Emitted when the column of the model that contains low values is changed. | 
| 211 |     \sa lowColumn | 
| 212 | */ | 
| 213 |  | 
| 214 | /*! | 
| 215 |     \fn void QHCandlestickModelMapper::closeColumnChanged() | 
| 216 |     \brief Emitted when the column of the model that contains close values is changed. | 
| 217 |     \sa closeColumn | 
| 218 | */ | 
| 219 |  | 
| 220 | /*! | 
| 221 |     \fn void QHCandlestickModelMapper::firstSetRowChanged() | 
| 222 |     \brief Emitted when the row of the model that contains the data of the first item is changed. | 
| 223 |     \sa firstSetRow | 
| 224 | */ | 
| 225 |  | 
| 226 | /*! | 
| 227 |     \fn void QHCandlestickModelMapper::lastSetRowChanged() | 
| 228 |     \brief Emitted when the row of the model that contains the data of the last item is changed. | 
| 229 |     \sa lastSetRow | 
| 230 | */ | 
| 231 |  | 
| 232 | /*! | 
| 233 |     Constructs a horizontal model mapper object which is a child of \a parent. | 
| 234 | */ | 
| 235 | QHCandlestickModelMapper::QHCandlestickModelMapper(QObject *parent) | 
| 236 |     : QCandlestickModelMapper(parent) | 
| 237 | { | 
| 238 |     connect(sender: d_ptr, SIGNAL(timestampChanged()), receiver: this, SIGNAL(timestampColumnChanged())); | 
| 239 |     connect(sender: d_ptr, SIGNAL(openChanged()), receiver: this, SIGNAL(openColumnChanged())); | 
| 240 |     connect(sender: d_ptr, SIGNAL(highChanged()), receiver: this, SIGNAL(highColumnChanged())); | 
| 241 |     connect(sender: d_ptr, SIGNAL(lowChanged()), receiver: this, SIGNAL(lowColumnChanged())); | 
| 242 |     connect(sender: d_ptr, SIGNAL(closeChanged()), receiver: this, SIGNAL(closeColumnChanged())); | 
| 243 |     connect(sender: d_ptr, SIGNAL(firstSetSectionChanged()), receiver: this, SIGNAL(firstSetRowChanged())); | 
| 244 |     connect(sender: d_ptr, SIGNAL(lastSetSectionChanged()), receiver: this, SIGNAL(lastSetRowChanged())); | 
| 245 | } | 
| 246 |  | 
| 247 | /*! | 
| 248 |     Returns Qt::Horizontal. This means that values of the item are read from rows. | 
| 249 | */ | 
| 250 | Qt::Orientation QHCandlestickModelMapper::orientation() const | 
| 251 | { | 
| 252 |     return Qt::Horizontal; | 
| 253 | } | 
| 254 |  | 
| 255 | void QHCandlestickModelMapper::setTimestampColumn(int timestampColumn) | 
| 256 | { | 
| 257 |     QCandlestickModelMapper::setTimestamp(timestampColumn); | 
| 258 | } | 
| 259 |  | 
| 260 | int QHCandlestickModelMapper::timestampColumn() const | 
| 261 | { | 
| 262 |     return QCandlestickModelMapper::timestamp(); | 
| 263 | } | 
| 264 |  | 
| 265 | void QHCandlestickModelMapper::setOpenColumn(int openColumn) | 
| 266 | { | 
| 267 |     QCandlestickModelMapper::setOpen(openColumn); | 
| 268 | } | 
| 269 |  | 
| 270 | int QHCandlestickModelMapper::openColumn() const | 
| 271 | { | 
| 272 |     return QCandlestickModelMapper::open(); | 
| 273 | } | 
| 274 |  | 
| 275 | void QHCandlestickModelMapper::setHighColumn(int highColumn) | 
| 276 | { | 
| 277 |     QCandlestickModelMapper::setHigh(highColumn); | 
| 278 | } | 
| 279 |  | 
| 280 | int QHCandlestickModelMapper::highColumn() const | 
| 281 | { | 
| 282 |     return QCandlestickModelMapper::high(); | 
| 283 | } | 
| 284 |  | 
| 285 | void QHCandlestickModelMapper::setLowColumn(int lowColumn) | 
| 286 | { | 
| 287 |     QCandlestickModelMapper::setLow(lowColumn); | 
| 288 | } | 
| 289 |  | 
| 290 | int QHCandlestickModelMapper::lowColumn() const | 
| 291 | { | 
| 292 |     return QCandlestickModelMapper::low(); | 
| 293 | } | 
| 294 |  | 
| 295 | void QHCandlestickModelMapper::setCloseColumn(int closeColumn) | 
| 296 | { | 
| 297 |     QCandlestickModelMapper::setClose(closeColumn); | 
| 298 | } | 
| 299 |  | 
| 300 | int QHCandlestickModelMapper::closeColumn() const | 
| 301 | { | 
| 302 |     return QCandlestickModelMapper::close(); | 
| 303 | } | 
| 304 |  | 
| 305 | void QHCandlestickModelMapper::setFirstSetRow(int firstSetRow) | 
| 306 | { | 
| 307 |     QCandlestickModelMapper::setFirstSetSection(firstSetRow); | 
| 308 | } | 
| 309 |  | 
| 310 | int QHCandlestickModelMapper::firstSetRow() const | 
| 311 | { | 
| 312 |     return QCandlestickModelMapper::firstSetSection(); | 
| 313 | } | 
| 314 |  | 
| 315 | void QHCandlestickModelMapper::setLastSetRow(int lastSetRow) | 
| 316 | { | 
| 317 |     QCandlestickModelMapper::setLastSetSection(lastSetRow); | 
| 318 | } | 
| 319 |  | 
| 320 | int QHCandlestickModelMapper::lastSetRow() const | 
| 321 | { | 
| 322 |     return QCandlestickModelMapper::lastSetSection(); | 
| 323 | } | 
| 324 |  | 
| 325 | QT_END_NAMESPACE | 
| 326 |  | 
| 327 | #include "moc_qhcandlestickmodelmapper.cpp" | 
| 328 |  |