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