| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #include <QtCharts/QVBoxPlotModelMapper> | 
| 5 |  | 
| 6 | QT_BEGIN_NAMESPACE | 
| 7 |  | 
| 8 | /*! | 
| 9 |     \class QVBoxPlotModelMapper | 
| 10 |     \inmodule QtCharts | 
| 11 |     \brief The QVBoxPlotModelMapper is a vertical model mapper for box plot | 
| 12 |     series. | 
| 13 |  | 
| 14 |     Model mappers enable using a data model derived from the QAbstractItemModel class | 
| 15 |     as a data source for a chart. A vertical model mapper is used to create a connection | 
| 16 |     between a data model and a QBoxPlotSeries object, so that each column in the data model | 
| 17 |     defines a box-and-whiskers item and each row maps to the range and three median | 
| 18 |     values of the box-and-whiskers item. | 
| 19 |  | 
| 20 |     Both model and series properties can be used to manipulate the data. The model mapper | 
| 21 |     keeps the series and the data model in sync. | 
| 22 |  | 
| 23 |     The model mapper ensures that all the bar box-and-whiskers items in the box plot | 
| 24 |     series have equal sizes. Therefore, adding or removing a value from a box-and-whiskers | 
| 25 |     item causes the same change to be made in all the box-and-whiskers items in the | 
| 26 |     box plot series. | 
| 27 |  | 
| 28 |     \sa QHBoxPlotModelMapper | 
| 29 | */ | 
| 30 | /*! | 
| 31 |     \qmltype VBoxPlotModelMapper | 
| 32 |     \nativetype QVBoxPlotModelMapper | 
| 33 |     \inqmlmodule QtCharts | 
| 34 |  | 
| 35 |     \brief Vertical model mapper for box plot series. | 
| 36 |  | 
| 37 |     The VBoxPlotModelMapper type enables using a data model derived from the QAbstractItemModel | 
| 38 |     class as a data source for a chart. A vertical model mapper is used to create a connection | 
| 39 |     between a data model and a BoxPlotSeries type, so that each column in the data model | 
| 40 |     defines a box-and-whiskers item and each row maps to the range and three median values of | 
| 41 |     the box-and-whiskers item. | 
| 42 |  | 
| 43 |     Both model and series properties can be used to manipulate the data. The model mapper | 
| 44 |     keeps the series and the data model in sync. | 
| 45 |  | 
| 46 |     The model mapper ensures that all the bar box-and-whiskers items in the box plot | 
| 47 |     series have equal sizes. Therefore, adding or removing a value from a box-and-whiskers | 
| 48 |     item causes the same change to be made in all the box-and-whiskers items in the | 
| 49 |     box plot series. | 
| 50 |  | 
| 51 |     The following QML code snippet creates a box plot series with three box-and-whiskers items | 
| 52 |     (assuming the model has at least four columns). Each box-and-whiskers item contains | 
| 53 |     data starting from row 1. The name of an item is defined by the column header. | 
| 54 |     \code | 
| 55 |         BoxPlotSeries { | 
| 56 |             VBoxPlotModelMapper { | 
| 57 |                 model: myCustomModel // QAbstractItemModel derived implementation | 
| 58 |                 firstBoxSetColumn: 1 | 
| 59 |                 lastBoxSetColumn: 3 | 
| 60 |                 firstRow: 1 | 
| 61 |             } | 
| 62 |         } | 
| 63 |     \endcode | 
| 64 |  | 
| 65 |    \sa HBoxPlotModelMapper | 
| 66 | */ | 
| 67 |  | 
| 68 | /*! | 
| 69 |     \property QVBoxPlotModelMapper::series | 
| 70 |     \brief The box plot series that is used by the mapper. | 
| 71 |  | 
| 72 |     All the data in the series is discarded when it is set to the mapper. | 
| 73 |     When a new series is specified, the old series is disconnected (but it | 
| 74 |     preserves its data). | 
| 75 | */ | 
| 76 | /*! | 
| 77 |     \qmlproperty AbstractBarSeries VBoxPlotModelMapper::series | 
| 78 |     The box plot series that is used by the mapper. | 
| 79 |  | 
| 80 |     All the data in the series is discarded when it is set to the mapper. | 
| 81 |     When a new series is specified, the old series is disconnected (but it | 
| 82 |     preserves its data). | 
| 83 | */ | 
| 84 |  | 
| 85 | /*! | 
| 86 |     \property QVBoxPlotModelMapper::model | 
| 87 |     \brief The model that is used by the mapper. | 
| 88 | */ | 
| 89 | /*! | 
| 90 |     \qmlproperty SomeModel VBoxPlotModelMapper::model | 
| 91 |     The data model that is used by the mapper. You need to implement the model | 
| 92 |     and expose it to QML. | 
| 93 |  | 
| 94 |     \note The model has to support adding and removing rows or columns and | 
| 95 |     modifying the data in the cells. | 
| 96 | */ | 
| 97 |  | 
| 98 | /*! | 
| 99 |     \property QVBoxPlotModelMapper::firstBoxSetColumn | 
| 100 |     \brief The column of the model that is used as the data source for the first | 
| 101 |     box-and-whiskers item. | 
| 102 |  | 
| 103 |     The default value is -1 (invalid mapping). | 
| 104 | */ | 
| 105 | /*! | 
| 106 |     \qmlproperty int VBoxPlotModelMapper::firstBoxSetColumn | 
| 107 |     The column of the model that is used as the data source for the first | 
| 108 |     box-and-whiskers item. The default value is -1 (invalid mapping). | 
| 109 | */ | 
| 110 |  | 
| 111 | /*! | 
| 112 |     \property QVBoxPlotModelMapper::lastBoxSetColumn | 
| 113 |     \brief The column of the model that is used as the data source for the last | 
| 114 |     box-and-whiskers item. | 
| 115 |  | 
| 116 |     The default value is -1 (invalid mapping). | 
| 117 | */ | 
| 118 | /*! | 
| 119 |     \qmlproperty int VBoxPlotModelMapper::lastBoxSetColumn | 
| 120 |     The column of the model that is used as the data source for the last | 
| 121 |     box-and-whiskers item. The default value is -1 (invalid mapping). | 
| 122 | */ | 
| 123 |  | 
| 124 | /*! | 
| 125 |     \property QVBoxPlotModelMapper::firstRow | 
| 126 |     \brief The row of the model that contains the first values of the | 
| 127 |     box-and-whiskers items in the box plot series. | 
| 128 |  | 
| 129 |     The minimum and default value is 0. | 
| 130 | */ | 
| 131 | /*! | 
| 132 |     \qmlproperty int VBoxPlotModelMapper::firstRow | 
| 133 |     The row of the model that contains the first values of the | 
| 134 |     box-and-whiskers items in the box plot series. | 
| 135 |  | 
| 136 |     The default value is 0. | 
| 137 | */ | 
| 138 |  | 
| 139 | /*! | 
| 140 |     \property QVBoxPlotModelMapper::rowCount | 
| 141 |     \brief The number of rows of the model that are mapped as the data for the | 
| 142 |     box plot series. | 
| 143 |  | 
| 144 |     The minimum and default value is  -1 (number limited to the number of | 
| 145 |     columns in the model). | 
| 146 | */ | 
| 147 | /*! | 
| 148 |     \qmlproperty int VBoxPlotModelMapper::rowCount | 
| 149 |     The number of rows of the model that are mapped as the data for | 
| 150 |     the box plot series. | 
| 151 |  | 
| 152 |     The default value is  -1 (number limited to the number of | 
| 153 |     columns in the model). | 
| 154 | */ | 
| 155 |  | 
| 156 | /*! | 
| 157 |     \fn void QVBoxPlotModelMapper::seriesReplaced() | 
| 158 |  | 
| 159 |     This signal is emitted when the series that the mapper is connected to | 
| 160 |     changes. | 
| 161 | */ | 
| 162 |  | 
| 163 | /*! | 
| 164 |     \fn void QVBoxPlotModelMapper::modelReplaced() | 
| 165 |  | 
| 166 |     This signal is emitted when the model that the mapper is connected to | 
| 167 |     changes. | 
| 168 | */ | 
| 169 |  | 
| 170 | /*! | 
| 171 |     \fn void QVBoxPlotModelMapper::firstBoxSetColumnChanged() | 
| 172 |     This signal is emitted when the first box-and-whiskers item column changes. | 
| 173 | */ | 
| 174 |  | 
| 175 | /*! | 
| 176 |     \fn void QVBoxPlotModelMapper::lastBoxSetColumnChanged() | 
| 177 |     This signal is emitted when the last box-and-whiskers item column changes. | 
| 178 | */ | 
| 179 |  | 
| 180 | /*! | 
| 181 |     \fn void QVBoxPlotModelMapper::firstRowChanged() | 
| 182 |     This signal is emitted when the first row changes. | 
| 183 | */ | 
| 184 |  | 
| 185 | /*! | 
| 186 |     \fn void QVBoxPlotModelMapper::rowCountChanged() | 
| 187 |     This signal is emitted when the number of rows changes. | 
| 188 | */ | 
| 189 |  | 
| 190 | /*! | 
| 191 |     Constructs a mapper object that is a child of \a parent. | 
| 192 | */ | 
| 193 | QVBoxPlotModelMapper::QVBoxPlotModelMapper(QObject *parent) : | 
| 194 |     QBoxPlotModelMapper(parent) | 
| 195 | { | 
| 196 |     QBoxPlotModelMapper::setOrientation(Qt::Vertical); | 
| 197 | } | 
| 198 |  | 
| 199 | QAbstractItemModel *QVBoxPlotModelMapper::model() const | 
| 200 | { | 
| 201 |     return QBoxPlotModelMapper::model(); | 
| 202 | } | 
| 203 |  | 
| 204 | void QVBoxPlotModelMapper::setModel(QAbstractItemModel *model) | 
| 205 | { | 
| 206 |     if (model != QBoxPlotModelMapper::model()) { | 
| 207 |         QBoxPlotModelMapper::setModel(model); | 
| 208 |         emit modelReplaced(); | 
| 209 |     } | 
| 210 | } | 
| 211 |  | 
| 212 | QBoxPlotSeries *QVBoxPlotModelMapper::series() const | 
| 213 | { | 
| 214 |     return QBoxPlotModelMapper::series(); | 
| 215 | } | 
| 216 |  | 
| 217 | void QVBoxPlotModelMapper::setSeries(QBoxPlotSeries *series) | 
| 218 | { | 
| 219 |     if (series != QBoxPlotModelMapper::series()) { | 
| 220 |         QBoxPlotModelMapper::setSeries(series); | 
| 221 |         emit seriesReplaced(); | 
| 222 |     } | 
| 223 | } | 
| 224 |  | 
| 225 | int QVBoxPlotModelMapper::firstBoxSetColumn() const | 
| 226 | { | 
| 227 |     return QBoxPlotModelMapper::firstBoxSetSection(); | 
| 228 | } | 
| 229 |  | 
| 230 | void QVBoxPlotModelMapper::setFirstBoxSetColumn(int firstBoxSetColumn) | 
| 231 | { | 
| 232 |     if (firstBoxSetColumn != firstBoxSetSection()) { | 
| 233 |         QBoxPlotModelMapper::setFirstBoxSetSection(firstBoxSetColumn); | 
| 234 |         emit firstBoxSetColumnChanged(); | 
| 235 |     } | 
| 236 | } | 
| 237 |  | 
| 238 | int QVBoxPlotModelMapper::lastBoxSetColumn() const | 
| 239 | { | 
| 240 |     return QBoxPlotModelMapper::lastBoxSetSection(); | 
| 241 | } | 
| 242 |  | 
| 243 | void QVBoxPlotModelMapper::setLastBoxSetColumn(int lastBoxSetColumn) | 
| 244 | { | 
| 245 |     if (lastBoxSetColumn != lastBoxSetSection()) { | 
| 246 |         QBoxPlotModelMapper::setLastBoxSetSection(lastBoxSetColumn); | 
| 247 |         emit lastBoxSetColumnChanged(); | 
| 248 |     } | 
| 249 | } | 
| 250 |  | 
| 251 | int QVBoxPlotModelMapper::firstRow() const | 
| 252 | { | 
| 253 |     return QBoxPlotModelMapper::first(); | 
| 254 | } | 
| 255 |  | 
| 256 | void QVBoxPlotModelMapper::setFirstRow(int firstRow) | 
| 257 | { | 
| 258 |     if (firstRow != first()) { | 
| 259 |         QBoxPlotModelMapper::setFirst(firstRow); | 
| 260 |         emit firstRowChanged(); | 
| 261 |     } | 
| 262 | } | 
| 263 |  | 
| 264 | int QVBoxPlotModelMapper::rowCount() const | 
| 265 | { | 
| 266 |     return QBoxPlotModelMapper::count(); | 
| 267 | } | 
| 268 |  | 
| 269 | void QVBoxPlotModelMapper::setRowCount(int rowCount) | 
| 270 | { | 
| 271 |     if (rowCount != count()) { | 
| 272 |         QBoxPlotModelMapper::setCount(rowCount); | 
| 273 |         emit rowCountChanged(); | 
| 274 |     } | 
| 275 | } | 
| 276 |  | 
| 277 | QT_END_NAMESPACE | 
| 278 |  | 
| 279 | #include "moc_qvboxplotmodelmapper.cpp" | 
| 280 |  |