| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qitemmodelsurfacedataproxy_p.h" |
| 5 | #include "surfaceitemmodelhandler_p.h" |
| 6 | #include "qgraphs3dlogging_p.h" |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | /*! |
| 11 | * \class QItemModelSurfaceDataProxy |
| 12 | * \inmodule QtGraphs |
| 13 | * \ingroup graphs_3D |
| 14 | * \brief Proxy class for presenting data in item models with Q3DSurfaceWidgetItem. |
| 15 | * |
| 16 | * QItemModelSurfaceDataProxy allows you to use QAbstractItemModel derived |
| 17 | * models as a data source for Q3DSurfaceWidgetItem. It uses the defined mappings to map |
| 18 | * data from the model to rows, columns, and surface points of Q3DSurfaceWidgetItem graph. |
| 19 | * |
| 20 | * Data is resolved asynchronously whenever the mapping or the model changes. |
| 21 | * QSurfaceDataProxy::arrayReset() is emitted when the data has been resolved. |
| 22 | * However, when useModelCategories property is set to \c true, single item |
| 23 | * changes are resolved synchronously, unless the same frame also contains a |
| 24 | * change that causes the whole model to be resolved. |
| 25 | * |
| 26 | * Mappings can be used in the following ways: |
| 27 | * |
| 28 | * \list |
| 29 | * \li If useModelCategories property is set to \c true, this proxy will map rows and |
| 30 | * columns of QAbstractItemModel to rows and columns of Q3DSurfaceWidgetItem, and uses the value returned for |
| 31 | * Qt::DisplayRole as Y-position by default. Row and column headers are used for Z-position and |
| 32 | * X-position by default, if they can be converted to floats. Otherwise row and column indices |
| 33 | * are used. |
| 34 | * The Y-position role to be used can be redefined if Qt::DisplayRole is not suitable. |
| 35 | * The Z-position and X-position roles to be used can be redefined if the headers or indices |
| 36 | * are not suitable. |
| 37 | * |
| 38 | * \li For models that do not have data already neatly sorted into rows and columns, such as |
| 39 | * QAbstractListModel based models, you can define a role from the model to map for each of the |
| 40 | * row, column and Y-position. |
| 41 | * |
| 42 | * \li If you do not want to include all data contained in the model, or the autogenerated rows and |
| 43 | * columns are not ordered as you wish, you can specify which rows and columns should be included |
| 44 | * and in which order by defining an explicit list of categories for either or both of rows and |
| 45 | * columns. |
| 46 | * \endlist |
| 47 | * |
| 48 | * For example, assume that you have a custom QAbstractItemModel storing surface topography data. |
| 49 | * Each item in the model has the roles "longitude", "latitude", and "height". |
| 50 | * The item model already contains the data properly sorted so that longitudes and latitudes are |
| 51 | * first encountered in correct order, which enables us to utilize the row and column category |
| 52 | * autogeneration. |
| 53 | * You could do the following to display the data in a surface graph: |
| 54 | * |
| 55 | * \snippet doc_src_qtgraphs.cpp surfacemodelproxy |
| 56 | * |
| 57 | * If the fields of the model do not contain the data in the exact format you |
| 58 | * need, you can specify a search pattern regular expression and a replace rule |
| 59 | * for each role to get the value in a format you need. For more information on how |
| 60 | * the replacement using regular expressions works, see QString::replace(const |
| 61 | * QRegularExpression &rx, const QString &after) function documentation. Note |
| 62 | * that using regular expressions has an impact on the performance, so it's more |
| 63 | * efficient to utilize item models where doing search and replace is not |
| 64 | * necessary to get the desired values. |
| 65 | * |
| 66 | * For example about using the search patterns in conjunction with the roles, |
| 67 | * see ItemModelBarDataProxy usage in \l{Simple Bar Graph}. |
| 68 | * |
| 69 | * \sa {Qt Graphs Data Handling with 3D} |
| 70 | */ |
| 71 | |
| 72 | /*! |
| 73 | * \qmltype ItemModelSurfaceDataProxy |
| 74 | * \inqmlmodule QtGraphs |
| 75 | * \ingroup graphs_qml_3D |
| 76 | * \nativetype QItemModelSurfaceDataProxy |
| 77 | * \inherits SurfaceDataProxy |
| 78 | * \brief Proxy class for presenting data in item models with Surface3D. |
| 79 | * |
| 80 | * This type allows you to use \c AbstractItemModel derived models as a data |
| 81 | * source for Surface3D. |
| 82 | * |
| 83 | * Data is resolved asynchronously whenever the mapping or the model changes. |
| 84 | * |
| 85 | * For ItemModelSurfaceDataProxy enums, see |
| 86 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior}. |
| 87 | * |
| 88 | * For more details, see QItemModelSurfaceDataProxy documentation. |
| 89 | * |
| 90 | * Usage example: |
| 91 | * |
| 92 | * \snippet doc_src_qmlgraphs.cpp 9 |
| 93 | * |
| 94 | * \sa SurfaceDataProxy, {Qt Graphs Data Handling with 3D} |
| 95 | */ |
| 96 | |
| 97 | /*! |
| 98 | * \qmlproperty model ItemModelSurfaceDataProxy::itemModel |
| 99 | * The item model used as a data source for Surface3D. |
| 100 | */ |
| 101 | |
| 102 | /*! |
| 103 | * \qmlproperty string ItemModelSurfaceDataProxy::rowRole |
| 104 | * The item model role to map to the row category. |
| 105 | * In addition to defining which row the data belongs to, the value indicated by |
| 106 | * the row role is also set as the Z-coordinate value of QSurfaceDataItem when the |
| 107 | * model data is resolved, unless a separate z position role is also defined. |
| 108 | */ |
| 109 | |
| 110 | /*! |
| 111 | * \qmlproperty string ItemModelSurfaceDataProxy::columnRole |
| 112 | * The item model role to map to the column category. |
| 113 | * In addition to defining which column the data belongs to, the value indicated |
| 114 | * by the column role is also set as the X-coordinate value of QSurfaceDataItem |
| 115 | * when the model data is resolved, unless a separate x position role is also |
| 116 | * defined. |
| 117 | */ |
| 118 | |
| 119 | /*! |
| 120 | * \qmlproperty string ItemModelSurfaceDataProxy::xPosRole |
| 121 | * The item model role to map to the X position. If this role is not defined, |
| 122 | * columnRole is used to determine the X-coordinate value of the resolved \c |
| 123 | * QSurfaceDataItem items. |
| 124 | */ |
| 125 | |
| 126 | /*! |
| 127 | * \qmlproperty string ItemModelSurfaceDataProxy::yPosRole |
| 128 | * The item model role to map to the Y position. |
| 129 | */ |
| 130 | |
| 131 | /*! |
| 132 | * \qmlproperty string ItemModelSurfaceDataProxy::zPosRole |
| 133 | * The item model role to map to the Z position. If this role is not defined, |
| 134 | * rowRole is used to determine the Z-coordinate value of the resolved |
| 135 | * \c QSurfaceDataItem items. |
| 136 | */ |
| 137 | |
| 138 | /*! |
| 139 | * \qmlproperty list<String> ItemModelSurfaceDataProxy::rowCategories |
| 140 | * The row categories of the mapping. Only items with row roles that are found |
| 141 | * in this list are included when data is resolved. The rows are ordered in the |
| 142 | * same order as they are in this list. |
| 143 | */ |
| 144 | |
| 145 | /*! |
| 146 | * \qmlproperty list<String> ItemModelSurfaceDataProxy::columnCategories |
| 147 | * The column categories of the mapping. Only items with column roles that are |
| 148 | * found in this list are included when data is resolved. The columns are |
| 149 | * ordered in the same order as they are in this list. |
| 150 | */ |
| 151 | |
| 152 | /*! |
| 153 | * \qmlproperty bool ItemModelSurfaceDataProxy::useModelCategories |
| 154 | * When set to \c true, the mapping ignores row and column roles and categories, |
| 155 | * and uses the rows and columns from the model instead. Defaults to \c{false}. |
| 156 | */ |
| 157 | |
| 158 | /*! |
| 159 | * \qmlproperty bool ItemModelSurfaceDataProxy::autoRowCategories |
| 160 | * When set to \c true, the mapping ignores any explicitly set row categories |
| 161 | * and overwrites them with automatically generated ones whenever the |
| 162 | * data from the model is resolved. Proxy minimum and maximum row values are |
| 163 | * also autogenerated from the data when this is set to \c true. Defaults to |
| 164 | * \c{true}. |
| 165 | */ |
| 166 | |
| 167 | /*! |
| 168 | * \qmlproperty bool ItemModelSurfaceDataProxy::autoColumnCategories |
| 169 | * When set to \c true, the mapping ignores any explicitly set column categories |
| 170 | * and overwrites them with automatically generated ones whenever the |
| 171 | * data from the model is resolved. Proxy minimum and maximum column values are |
| 172 | * also autogenerated from the data when this is set to \c true. Defaults to |
| 173 | * \c{true}. |
| 174 | */ |
| 175 | |
| 176 | /*! |
| 177 | * \qmlproperty regExp ItemModelSurfaceDataProxy::rowRolePattern |
| 178 | * |
| 179 | * When set, a search and replace is done on the value mapped by the row role |
| 180 | * before it is used as a row category. This property specifies the regular |
| 181 | * expression to find the portion of the mapped value to replace, and the |
| 182 | * rowRoleReplace property contains the replacement string. |
| 183 | * |
| 184 | * \sa rowRole, rowRoleReplace |
| 185 | */ |
| 186 | |
| 187 | /*! |
| 188 | * \qmlproperty regExp ItemModelSurfaceDataProxy::columnRolePattern |
| 189 | * |
| 190 | * When set, a search and replace is done on the value mapped by the column role |
| 191 | * before it is used as a column category. This property specifies the regular |
| 192 | * expression to find the portion of the mapped value to replace, and the |
| 193 | * columnRoleReplace property contains the replacement string. |
| 194 | * |
| 195 | * \sa columnRole, columnRoleReplace |
| 196 | */ |
| 197 | |
| 198 | /*! |
| 199 | * \qmlproperty regExp ItemModelSurfaceDataProxy::xPosRolePattern |
| 200 | * |
| 201 | * When set, a search and replace is done on the value mapped by the x-position |
| 202 | * role before it is used as an item position value. This property specifies |
| 203 | * the regular expression to find the portion of the mapped value to replace, and |
| 204 | * the xPosRoleReplace property contains the replacement string. |
| 205 | * |
| 206 | * \sa xPosRole, xPosRoleReplace |
| 207 | */ |
| 208 | |
| 209 | /*! |
| 210 | * \qmlproperty regExp ItemModelSurfaceDataProxy::yPosRolePattern |
| 211 | * |
| 212 | * When set, a search and replace is done on the value mapped by the y-position |
| 213 | * role before it is used as an item position value. This property specifies |
| 214 | * the regular expression to find the portion of the mapped value to replace, and |
| 215 | * the yPosRoleReplace property contains the replacement string. |
| 216 | * |
| 217 | * \sa yPosRole, yPosRoleReplace |
| 218 | */ |
| 219 | |
| 220 | /*! |
| 221 | * \qmlproperty regExp ItemModelSurfaceDataProxy::zPosRolePattern |
| 222 | * |
| 223 | * When set, a search and replace is done on the value mapped by the z-position |
| 224 | * role before it is used as an item position value. This property specifies |
| 225 | * the regular expression to find the portion of the mapped value to replace, and |
| 226 | * the zPosRoleReplace property contains the replacement string. |
| 227 | * |
| 228 | * \sa zPosRole, zPosRoleReplace |
| 229 | */ |
| 230 | |
| 231 | /*! |
| 232 | * \qmlproperty string ItemModelSurfaceDataProxy::rowRoleReplace |
| 233 | * |
| 234 | * The replacement content to be used in conjunction with rowRolePattern. |
| 235 | * Defaults to an empty string. For more information on how the search and |
| 236 | * replace using regular expressions works, see the |
| 237 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 238 | * function documentation. |
| 239 | * |
| 240 | * \sa rowRole, rowRolePattern |
| 241 | */ |
| 242 | |
| 243 | /*! |
| 244 | * \qmlproperty string ItemModelSurfaceDataProxy::columnRoleReplace |
| 245 | * |
| 246 | * The replacement content to be used in conjunction with columnRolePattern. |
| 247 | * Defaults to an empty string. For more information on how the search and |
| 248 | * replace using regular expressions works, see the |
| 249 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 250 | * function documentation. |
| 251 | * |
| 252 | * \sa columnRole, columnRolePattern |
| 253 | */ |
| 254 | |
| 255 | /*! |
| 256 | * \qmlproperty string ItemModelSurfaceDataProxy::xPosRoleReplace |
| 257 | * |
| 258 | * The replacement content to be used in conjunction with xPosRolePattern. |
| 259 | * Defaults to an empty string. For more information on how the search and |
| 260 | * replace using regular expressions works, see the |
| 261 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 262 | * function documentation. |
| 263 | * |
| 264 | * \sa xPosRole, xPosRolePattern |
| 265 | */ |
| 266 | |
| 267 | /*! |
| 268 | * \qmlproperty string ItemModelSurfaceDataProxy::yPosRoleReplace |
| 269 | * |
| 270 | * The replacement content to be used in conjunction with yPosRolePattern. |
| 271 | * Defaults to an empty string. For more information on how the search and |
| 272 | * replace using regular expressions works, see the |
| 273 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 274 | * function documentation. |
| 275 | * |
| 276 | * \sa yPosRole, yPosRolePattern |
| 277 | */ |
| 278 | |
| 279 | /*! |
| 280 | * \qmlproperty string ItemModelSurfaceDataProxy::zPosRoleReplace |
| 281 | * |
| 282 | * The replacement content to be used in conjunction with zPosRolePattern. |
| 283 | * Defaults to an empty string. For more information on how the search and |
| 284 | * replace using regular expressions works, see the |
| 285 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 286 | * function documentation. |
| 287 | * |
| 288 | * \sa zPosRole, zPosRolePattern |
| 289 | */ |
| 290 | |
| 291 | /*! |
| 292 | * \qmlproperty enumeration ItemModelSurfaceDataProxy::multiMatchBehavior |
| 293 | * Defines how multiple matches for each row/column combination are handled. |
| 294 | * Defaults to |
| 295 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior::Last} |
| 296 | * {ItemModelSurfaceDataProxy.MultiMatchBehavior.Last}. |
| 297 | * |
| 298 | * For example, you might have an item model with timestamped data taken at |
| 299 | * irregular intervals and you want to visualize an average position of data |
| 300 | * items on each hour with a surface graph. This can be done by specifying row |
| 301 | * and column categories so that each surface point represents an hour, and |
| 302 | * setting multiMatchBehavior to |
| 303 | * \l{QItemModelSurfaceDataProxy::MultiMatchBehavior::Average} |
| 304 | * {ItemModelSurfaceDataProxy.MultiMatchBehavior.Average}. |
| 305 | */ |
| 306 | |
| 307 | /*! |
| 308 | \qmlsignal ItemModelSurfaceDataProxy::itemModelChanged(model itemModel) |
| 309 | |
| 310 | This signal is emitted when itemModel changes to \a itemModel. |
| 311 | */ |
| 312 | |
| 313 | /*! |
| 314 | \qmlsignal ItemModelSurfaceDataProxy::rowRoleChanged(string role) |
| 315 | |
| 316 | This signal is emitted when rowRole changes to \a role. |
| 317 | */ |
| 318 | |
| 319 | /*! |
| 320 | \qmlsignal ItemModelSurfaceDataProxy::columnRoleChanged(string role) |
| 321 | |
| 322 | This signal is emitted when columnRole changes to \a role. |
| 323 | */ |
| 324 | |
| 325 | /*! |
| 326 | \qmlsignal ItemModelSurfaceDataProxy::xPosRoleChanged(string role) |
| 327 | |
| 328 | This signal is emitted when xPosRole changes to \a role. |
| 329 | */ |
| 330 | |
| 331 | /*! |
| 332 | \qmlsignal ItemModelSurfaceDataProxy::yPosRoleChanged(string role) |
| 333 | |
| 334 | This signal is emitted when yPosRole changes to \a role. |
| 335 | */ |
| 336 | |
| 337 | /*! |
| 338 | \qmlsignal ItemModelSurfaceDataProxy::zPosRoleChanged(string role) |
| 339 | |
| 340 | This signal is emitted when zPosRole changes to \a role. |
| 341 | */ |
| 342 | |
| 343 | /*! |
| 344 | \qmlsignal ItemModelSurfaceDataProxy::rowCategoriesChanged() |
| 345 | |
| 346 | This signal is emitted when rowCategories changes. |
| 347 | */ |
| 348 | |
| 349 | /*! |
| 350 | \qmlsignal ItemModelSurfaceDataProxy::columnCategoriesChanged() |
| 351 | |
| 352 | This signal is emitted when columnCategories changes. |
| 353 | */ |
| 354 | |
| 355 | /*! |
| 356 | \qmlsignal ItemModelSurfaceDataProxy::useModelCategoriesChanged(bool enable) |
| 357 | |
| 358 | This signal is emitted when useModelCategories changes to \a enable. |
| 359 | */ |
| 360 | |
| 361 | /*! |
| 362 | \qmlsignal ItemModelSurfaceDataProxy::autoRowCategoriesChanged(bool enable) |
| 363 | |
| 364 | This signal is emitted when autoRowCategories changes to \a enable. |
| 365 | */ |
| 366 | |
| 367 | /*! |
| 368 | \qmlsignal ItemModelSurfaceDataProxy::autoColumnCategoriesChanged(bool enable) |
| 369 | |
| 370 | This signal is emitted when autoColumnCategories changes to \a enable. |
| 371 | */ |
| 372 | |
| 373 | /*! |
| 374 | \qmlsignal ItemModelSurfaceDataProxy::rowRolePatternChanged(regExp pattern) |
| 375 | |
| 376 | This signal is emitted when rowRolePattern changes to \a pattern. |
| 377 | */ |
| 378 | |
| 379 | /*! |
| 380 | \qmlsignal ItemModelSurfaceDataProxy::columnRolePatternChanged(regExp pattern) |
| 381 | |
| 382 | This signal is emitted when columnRolePattern changes to \a pattern. |
| 383 | */ |
| 384 | |
| 385 | /*! |
| 386 | \qmlsignal ItemModelSurfaceDataProxy::xPosRolePatternChanged(regExp pattern) |
| 387 | |
| 388 | This signal is emitted when xPosRolePattern changes to \a pattern. |
| 389 | */ |
| 390 | |
| 391 | /*! |
| 392 | \qmlsignal ItemModelSurfaceDataProxy::yPosRolePatternChanged(regExp pattern) |
| 393 | |
| 394 | This signal is emitted when yPosRolePattern changes to \a pattern. |
| 395 | */ |
| 396 | |
| 397 | /*! |
| 398 | \qmlsignal ItemModelSurfaceDataProxy::zPosRolePatternChanged(regExp pattern) |
| 399 | |
| 400 | This signal is emitted when zPosRolePattern changes to \a pattern. |
| 401 | */ |
| 402 | |
| 403 | /*! |
| 404 | \qmlsignal ItemModelSurfaceDataProxy::rowRoleReplaceChanged(string replace) |
| 405 | |
| 406 | This signal is emitted when rowRoleReplace changes to \a replace. |
| 407 | */ |
| 408 | |
| 409 | /*! |
| 410 | \qmlsignal ItemModelSurfaceDataProxy::columnRoleReplaceChanged(string replace) |
| 411 | |
| 412 | This signal is emitted when columnRoleReplace changes to \a replace. |
| 413 | */ |
| 414 | |
| 415 | /*! |
| 416 | \qmlsignal ItemModelSurfaceDataProxy::xPosRoleReplaceChanged(string replace) |
| 417 | |
| 418 | This signal is emitted when xPosRoleReplace changes to \a replace. |
| 419 | */ |
| 420 | |
| 421 | /*! |
| 422 | \qmlsignal ItemModelSurfaceDataProxy::yPosRoleReplaceChanged(string replace) |
| 423 | |
| 424 | This signal is emitted when yPosRoleReplace changes to \a replace. |
| 425 | */ |
| 426 | |
| 427 | /*! |
| 428 | \qmlsignal ItemModelSurfaceDataProxy::zPosRoleReplaceChanged(string replace) |
| 429 | |
| 430 | This signal is emitted when zPosRoleReplace changes to \a replace. |
| 431 | */ |
| 432 | |
| 433 | /*! |
| 434 | \qmlsignal ItemModelSurfaceDataProxy::multiMatchBehaviorChanged(enumeration behavior) |
| 435 | |
| 436 | This signal is emitted when multiMatchBehavior changes to \a behavior. |
| 437 | */ |
| 438 | |
| 439 | /*! |
| 440 | * \enum QItemModelSurfaceDataProxy::MultiMatchBehavior |
| 441 | * |
| 442 | * Behavior types for QItemModelSurfaceDataProxy::multiMatchBehavior property. |
| 443 | * |
| 444 | * \value First |
| 445 | * The position values are taken from the first item in the item model that matches |
| 446 | * each row/column combination. |
| 447 | * \value Last |
| 448 | * The position values are taken from the last item in the item model that matches |
| 449 | * each row/column combination. |
| 450 | * \value Average |
| 451 | * The position values from all items matching each row/column combination are |
| 452 | * averaged together and the averages are used as the surface point position. |
| 453 | * \value CumulativeY |
| 454 | * For X and Z values this acts just like \c{Average}, but Y values are added together |
| 455 | * instead of averaged and the total is used as the surface point Y position. |
| 456 | */ |
| 457 | |
| 458 | /*! |
| 459 | * Constructs QItemModelSurfaceDataProxy with an optional \a parent. |
| 460 | */ |
| 461 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QObject *parent) |
| 462 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 463 | { |
| 464 | Q_D(QItemModelSurfaceDataProxy); |
| 465 | d->connectItemModelHandler(); |
| 466 | } |
| 467 | |
| 468 | /*! |
| 469 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 470 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 471 | * models are owned by other controls. |
| 472 | */ |
| 473 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 474 | QObject *parent) |
| 475 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 476 | { |
| 477 | Q_D(QItemModelSurfaceDataProxy); |
| 478 | d->m_itemModelHandler->setItemModel(itemModel); |
| 479 | d->connectItemModelHandler(); |
| 480 | } |
| 481 | |
| 482 | /*! |
| 483 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 484 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 485 | * models are owned by other controls. The yPosRole role is set to \a yPosRole. |
| 486 | * This constructor is meant to be used with models that have data properly |
| 487 | * sorted in rows and columns already, so it also sets useModelCategories |
| 488 | * property to \c true. |
| 489 | */ |
| 490 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 491 | const QString &yPosRole, |
| 492 | QObject *parent) |
| 493 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 494 | { |
| 495 | Q_D(QItemModelSurfaceDataProxy); |
| 496 | d->m_itemModelHandler->setItemModel(itemModel); |
| 497 | d->m_yPosRole = yPosRole; |
| 498 | d->m_useModelCategories = true; |
| 499 | d->connectItemModelHandler(); |
| 500 | } |
| 501 | |
| 502 | /*! |
| 503 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 504 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 505 | * models are owned by other controls. The role mappings are set with \a rowRole, |
| 506 | * \a columnRole, and \a yPosRole. The zPosRole and the xPosRole are |
| 507 | * set to \a rowRole and \a columnRole, respectively. |
| 508 | */ |
| 509 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 510 | const QString &rowRole, |
| 511 | const QString &columnRole, |
| 512 | const QString &yPosRole, |
| 513 | QObject *parent) |
| 514 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 515 | { |
| 516 | Q_D(QItemModelSurfaceDataProxy); |
| 517 | d->m_itemModelHandler->setItemModel(itemModel); |
| 518 | d->m_rowRole = rowRole; |
| 519 | d->m_columnRole = columnRole; |
| 520 | d->m_xPosRole = columnRole; |
| 521 | d->m_yPosRole = yPosRole; |
| 522 | d->m_zPosRole = rowRole; |
| 523 | d->connectItemModelHandler(); |
| 524 | } |
| 525 | |
| 526 | /*! |
| 527 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 528 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 529 | * models are owned by other controls. The role mappings are set with \a rowRole, |
| 530 | * \a columnRole, \a xPosRole, \a yPosRole, and \a zPosRole. |
| 531 | */ |
| 532 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 533 | const QString &rowRole, |
| 534 | const QString &columnRole, |
| 535 | const QString &xPosRole, |
| 536 | const QString &yPosRole, |
| 537 | const QString &zPosRole, |
| 538 | QObject *parent) |
| 539 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 540 | { |
| 541 | Q_D(QItemModelSurfaceDataProxy); |
| 542 | d->m_itemModelHandler->setItemModel(itemModel); |
| 543 | d->m_rowRole = rowRole; |
| 544 | d->m_columnRole = columnRole; |
| 545 | d->m_xPosRole = xPosRole; |
| 546 | d->m_yPosRole = yPosRole; |
| 547 | d->m_zPosRole = zPosRole; |
| 548 | d->connectItemModelHandler(); |
| 549 | } |
| 550 | |
| 551 | /*! |
| 552 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 553 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 554 | * models are owned by other controls. The role mappings are set with \a rowRole, |
| 555 | * \a columnRole, and \a yPosRole. The zPosRole and the xPosRole are |
| 556 | * set to \a rowRole and \a columnRole, respectively. Row and column categories |
| 557 | * are set with \a rowCategories and \a columnCategories. This constructor also |
| 558 | * sets autoRowCategories and autoColumnCategories to false. |
| 559 | */ |
| 560 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 561 | const QString &rowRole, |
| 562 | const QString &columnRole, |
| 563 | const QString &yPosRole, |
| 564 | const QStringList &rowCategories, |
| 565 | const QStringList &columnCategories, |
| 566 | QObject *parent) |
| 567 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 568 | { |
| 569 | Q_D(QItemModelSurfaceDataProxy); |
| 570 | d->m_itemModelHandler->setItemModel(itemModel); |
| 571 | d->m_rowRole = rowRole; |
| 572 | d->m_columnRole = columnRole; |
| 573 | d->m_xPosRole = columnRole; |
| 574 | d->m_yPosRole = yPosRole; |
| 575 | d->m_zPosRole = rowRole; |
| 576 | d->m_rowCategories = rowCategories; |
| 577 | d->m_columnCategories = columnCategories; |
| 578 | d->m_autoRowCategories = false; |
| 579 | d->m_autoColumnCategories = false; |
| 580 | d->connectItemModelHandler(); |
| 581 | } |
| 582 | |
| 583 | /*! |
| 584 | * Constructs QItemModelSurfaceDataProxy with \a itemModel and an optional \a parent. |
| 585 | * The proxy doesn't take ownership of the \a itemModel, as typically item |
| 586 | * models are owned by other controls. The role mappings are set with \a rowRole, |
| 587 | * \a columnRole, \a xPosRole, \a yPosRole, and \a zPosRole. Row and |
| 588 | * column categories are set with \a rowCategories and \a columnCategories. This |
| 589 | * constructor also sets autoRowCategories and autoColumnCategories to false. |
| 590 | */ |
| 591 | QItemModelSurfaceDataProxy::QItemModelSurfaceDataProxy(QAbstractItemModel *itemModel, |
| 592 | const QString &rowRole, |
| 593 | const QString &columnRole, |
| 594 | const QString &xPosRole, |
| 595 | const QString &yPosRole, |
| 596 | const QString &zPosRole, |
| 597 | const QStringList &rowCategories, |
| 598 | const QStringList &columnCategories, |
| 599 | QObject *parent) |
| 600 | : QSurfaceDataProxy(*(new QItemModelSurfaceDataProxyPrivate(this)), parent) |
| 601 | { |
| 602 | Q_D(QItemModelSurfaceDataProxy); |
| 603 | d->m_itemModelHandler->setItemModel(itemModel); |
| 604 | d->m_rowRole = rowRole; |
| 605 | d->m_columnRole = columnRole; |
| 606 | d->m_xPosRole = xPosRole; |
| 607 | d->m_yPosRole = yPosRole; |
| 608 | d->m_zPosRole = zPosRole; |
| 609 | d->m_rowCategories = rowCategories; |
| 610 | d->m_columnCategories = columnCategories; |
| 611 | d->m_autoRowCategories = false; |
| 612 | d->m_autoColumnCategories = false; |
| 613 | d->connectItemModelHandler(); |
| 614 | } |
| 615 | |
| 616 | /*! |
| 617 | * Destroys QItemModelSurfaceDataProxy. |
| 618 | */ |
| 619 | QItemModelSurfaceDataProxy::~QItemModelSurfaceDataProxy() {} |
| 620 | |
| 621 | /*! |
| 622 | * \property QItemModelSurfaceDataProxy::itemModel |
| 623 | * |
| 624 | * \brief The item model used as a data source for the 3D surface. |
| 625 | */ |
| 626 | |
| 627 | /*! |
| 628 | * Sets the item model to \a itemModel. Does not take ownership of the model, |
| 629 | * but does connect to it to listen for changes. |
| 630 | */ |
| 631 | void QItemModelSurfaceDataProxy::setItemModel(QAbstractItemModel *itemModel) |
| 632 | { |
| 633 | Q_D(QItemModelSurfaceDataProxy); |
| 634 | d->m_itemModelHandler->setItemModel(itemModel); |
| 635 | } |
| 636 | |
| 637 | QAbstractItemModel *QItemModelSurfaceDataProxy::itemModel() const |
| 638 | { |
| 639 | Q_D(const QItemModelSurfaceDataProxy); |
| 640 | return d->m_itemModelHandler->itemModel(); |
| 641 | } |
| 642 | |
| 643 | /*! |
| 644 | * \property QItemModelSurfaceDataProxy::rowRole |
| 645 | * |
| 646 | * \brief The item model role to map to the row category. |
| 647 | * |
| 648 | * In addition to defining which row the data belongs to, the value indicated by |
| 649 | * the row role is also set as the Z-coordinate value of QSurfaceDataItem when |
| 650 | * model data is resolved, unless a separate z-position role is also defined. |
| 651 | */ |
| 652 | void QItemModelSurfaceDataProxy::setRowRole(const QString &role) |
| 653 | { |
| 654 | Q_D(QItemModelSurfaceDataProxy); |
| 655 | if (d->m_rowRole == role) { |
| 656 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 657 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(role)); |
| 658 | return; |
| 659 | } |
| 660 | d->m_rowRole = role; |
| 661 | emit rowRoleChanged(role); |
| 662 | } |
| 663 | |
| 664 | QString QItemModelSurfaceDataProxy::rowRole() const |
| 665 | { |
| 666 | Q_D(const QItemModelSurfaceDataProxy); |
| 667 | return d->m_rowRole; |
| 668 | } |
| 669 | |
| 670 | /*! |
| 671 | * \property QItemModelSurfaceDataProxy::columnRole |
| 672 | * |
| 673 | * \brief The item model role to map to the column category. |
| 674 | * |
| 675 | * In addition to defining which column the data belongs to, the value indicated |
| 676 | * by the column role is also set as the X-coordinate value of QSurfaceDataItem |
| 677 | * when model data is resolved, unless a separate x-position role is also |
| 678 | * defined. |
| 679 | */ |
| 680 | void QItemModelSurfaceDataProxy::setColumnRole(const QString &role) |
| 681 | { |
| 682 | Q_D(QItemModelSurfaceDataProxy); |
| 683 | if (d->m_columnRole == role) { |
| 684 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 685 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(role)); |
| 686 | return; |
| 687 | } |
| 688 | d->m_columnRole = role; |
| 689 | emit columnRoleChanged(role); |
| 690 | } |
| 691 | |
| 692 | QString QItemModelSurfaceDataProxy::columnRole() const |
| 693 | { |
| 694 | Q_D(const QItemModelSurfaceDataProxy); |
| 695 | return d->m_columnRole; |
| 696 | } |
| 697 | |
| 698 | /*! |
| 699 | * \property QItemModelSurfaceDataProxy::xPosRole |
| 700 | * |
| 701 | * \brief The item model role to map to the X position. |
| 702 | * |
| 703 | * If this role is not defined, columnRole is used to determine the X-coordinate |
| 704 | * value of the resolved \l{QSurfaceDataItem} objects. |
| 705 | */ |
| 706 | void QItemModelSurfaceDataProxy::setXPosRole(const QString &role) |
| 707 | { |
| 708 | Q_D(QItemModelSurfaceDataProxy); |
| 709 | if (d->m_xPosRole == role) { |
| 710 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 711 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(role)); |
| 712 | return; |
| 713 | } |
| 714 | d->m_xPosRole = role; |
| 715 | emit xPosRoleChanged(role); |
| 716 | } |
| 717 | |
| 718 | QString QItemModelSurfaceDataProxy::xPosRole() const |
| 719 | { |
| 720 | Q_D(const QItemModelSurfaceDataProxy); |
| 721 | return d->m_xPosRole; |
| 722 | } |
| 723 | |
| 724 | /*! |
| 725 | * \property QItemModelSurfaceDataProxy::yPosRole |
| 726 | * |
| 727 | * \brief The item model role to map to the Y position. |
| 728 | */ |
| 729 | void QItemModelSurfaceDataProxy::setYPosRole(const QString &role) |
| 730 | { |
| 731 | Q_D(QItemModelSurfaceDataProxy); |
| 732 | if (d->m_yPosRole == role) { |
| 733 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 734 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(role)); |
| 735 | return; |
| 736 | } |
| 737 | d->m_yPosRole = role; |
| 738 | emit yPosRoleChanged(role); |
| 739 | } |
| 740 | |
| 741 | QString QItemModelSurfaceDataProxy::yPosRole() const |
| 742 | { |
| 743 | Q_D(const QItemModelSurfaceDataProxy); |
| 744 | return d->m_yPosRole; |
| 745 | } |
| 746 | |
| 747 | /*! |
| 748 | * \property QItemModelSurfaceDataProxy::zPosRole |
| 749 | * |
| 750 | * \brief The item model role to map to the Z position. |
| 751 | * |
| 752 | * If this role is not defined, rowRole is used to determine the Z-coordinate |
| 753 | * value of resolved \l{QSurfaceDataItem} objects. |
| 754 | */ |
| 755 | void QItemModelSurfaceDataProxy::setZPosRole(const QString &role) |
| 756 | { |
| 757 | Q_D(QItemModelSurfaceDataProxy); |
| 758 | if (d->m_zPosRole == role) { |
| 759 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 760 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(role)); |
| 761 | return; |
| 762 | } |
| 763 | d->m_zPosRole = role; |
| 764 | emit zPosRoleChanged(role); |
| 765 | } |
| 766 | |
| 767 | QString QItemModelSurfaceDataProxy::zPosRole() const |
| 768 | { |
| 769 | Q_D(const QItemModelSurfaceDataProxy); |
| 770 | return d->m_zPosRole; |
| 771 | } |
| 772 | |
| 773 | /*! |
| 774 | * \property QItemModelSurfaceDataProxy::rowCategories |
| 775 | * |
| 776 | * \brief The row categories for the mapping. |
| 777 | */ |
| 778 | void QItemModelSurfaceDataProxy::setRowCategories(const QStringList &categories) |
| 779 | { |
| 780 | Q_D(QItemModelSurfaceDataProxy); |
| 781 | if (d->m_rowCategories == categories) { |
| 782 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 783 | << "value is already set to:" << categories; |
| 784 | return; |
| 785 | } |
| 786 | d->m_rowCategories = categories; |
| 787 | emit rowCategoriesChanged(); |
| 788 | } |
| 789 | |
| 790 | QStringList QItemModelSurfaceDataProxy::rowCategories() const |
| 791 | { |
| 792 | Q_D(const QItemModelSurfaceDataProxy); |
| 793 | return d->m_rowCategories; |
| 794 | } |
| 795 | |
| 796 | /*! |
| 797 | * \property QItemModelSurfaceDataProxy::columnCategories |
| 798 | * |
| 799 | * \brief The column categories for the mapping. |
| 800 | */ |
| 801 | void QItemModelSurfaceDataProxy::setColumnCategories(const QStringList &categories) |
| 802 | { |
| 803 | Q_D(QItemModelSurfaceDataProxy); |
| 804 | if (d->m_columnCategories == categories) { |
| 805 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 806 | << "value is already set to:" << categories; |
| 807 | return; |
| 808 | } |
| 809 | d->m_columnCategories = categories; |
| 810 | emit columnCategoriesChanged(); |
| 811 | } |
| 812 | |
| 813 | QStringList QItemModelSurfaceDataProxy::columnCategories() const |
| 814 | { |
| 815 | Q_D(const QItemModelSurfaceDataProxy); |
| 816 | return d->m_columnCategories; |
| 817 | } |
| 818 | |
| 819 | /*! |
| 820 | * \property QItemModelSurfaceDataProxy::useModelCategories |
| 821 | * |
| 822 | * \brief Whether row and column roles and categories are used for mapping. |
| 823 | * |
| 824 | * When set to \c true, the mapping ignores row and column roles and categories, |
| 825 | * and uses the rows and columns from the model instead. Defaults to \c{false}. |
| 826 | */ |
| 827 | void QItemModelSurfaceDataProxy::setUseModelCategories(bool enable) |
| 828 | { |
| 829 | Q_D(QItemModelSurfaceDataProxy); |
| 830 | if (d->m_useModelCategories == enable) { |
| 831 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 832 | << "value is already set to:" << enable; |
| 833 | return; |
| 834 | } |
| 835 | d->m_useModelCategories = enable; |
| 836 | emit useModelCategoriesChanged(enable); |
| 837 | } |
| 838 | |
| 839 | bool QItemModelSurfaceDataProxy::useModelCategories() const |
| 840 | { |
| 841 | Q_D(const QItemModelSurfaceDataProxy); |
| 842 | return d->m_useModelCategories; |
| 843 | } |
| 844 | |
| 845 | /*! |
| 846 | * \property QItemModelSurfaceDataProxy::autoRowCategories |
| 847 | * |
| 848 | * \brief Whether row categories are generated automatically. |
| 849 | * |
| 850 | * When set to \c true, the mapping ignores any explicitly set row categories |
| 851 | * and overwrites them with automatically generated ones whenever the |
| 852 | * data from the model is resolved. Defaults to \c{true}. |
| 853 | */ |
| 854 | void QItemModelSurfaceDataProxy::setAutoRowCategories(bool enable) |
| 855 | { |
| 856 | Q_D(QItemModelSurfaceDataProxy); |
| 857 | if (d->m_autoRowCategories == enable) { |
| 858 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 859 | << "value is already set to:" << enable; |
| 860 | return; |
| 861 | } |
| 862 | d->m_autoRowCategories = enable; |
| 863 | emit autoRowCategoriesChanged(enable); |
| 864 | } |
| 865 | |
| 866 | bool QItemModelSurfaceDataProxy::autoRowCategories() const |
| 867 | { |
| 868 | Q_D(const QItemModelSurfaceDataProxy); |
| 869 | return d->m_autoRowCategories; |
| 870 | } |
| 871 | |
| 872 | /*! |
| 873 | * \property QItemModelSurfaceDataProxy::autoColumnCategories |
| 874 | * |
| 875 | * \brief Whether column categories are generated automatically. |
| 876 | * |
| 877 | * When set to \c true, the mapping ignores any explicitly set column categories |
| 878 | * and overwrites them with automatically generated ones whenever the |
| 879 | * data from the model is resolved. Defaults to \c{true}. |
| 880 | */ |
| 881 | void QItemModelSurfaceDataProxy::setAutoColumnCategories(bool enable) |
| 882 | { |
| 883 | Q_D(QItemModelSurfaceDataProxy); |
| 884 | if (d->m_autoColumnCategories == enable) { |
| 885 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 886 | << "value is already set to:" << enable; |
| 887 | return; |
| 888 | } |
| 889 | d->m_autoColumnCategories = enable; |
| 890 | emit autoColumnCategoriesChanged(enable); |
| 891 | } |
| 892 | |
| 893 | bool QItemModelSurfaceDataProxy::autoColumnCategories() const |
| 894 | { |
| 895 | Q_D(const QItemModelSurfaceDataProxy); |
| 896 | return d->m_autoColumnCategories; |
| 897 | } |
| 898 | |
| 899 | /*! |
| 900 | * Changes \a rowRole, \a columnRole, \a xPosRole, \a yPosRole, \a zPosRole, |
| 901 | * \a rowCategories and \a columnCategories to the mapping. |
| 902 | */ |
| 903 | void QItemModelSurfaceDataProxy::remap(const QString &rowRole, |
| 904 | const QString &columnRole, |
| 905 | const QString &xPosRole, |
| 906 | const QString &yPosRole, |
| 907 | const QString &zPosRole, |
| 908 | const QStringList &rowCategories, |
| 909 | const QStringList &columnCategories) |
| 910 | { |
| 911 | setRowRole(rowRole); |
| 912 | setColumnRole(columnRole); |
| 913 | setXPosRole(xPosRole); |
| 914 | setYPosRole(yPosRole); |
| 915 | setZPosRole(zPosRole); |
| 916 | setRowCategories(rowCategories); |
| 917 | setColumnCategories(columnCategories); |
| 918 | } |
| 919 | |
| 920 | /*! |
| 921 | * Returns the index of the specified \a category in the row categories list. |
| 922 | * If the row categories list is empty, -1 is returned. |
| 923 | * \note If the automatic row categories generation is in use, this method will |
| 924 | * not return a valid index before the data in the model is resolved for the |
| 925 | * first time. |
| 926 | */ |
| 927 | qsizetype QItemModelSurfaceDataProxy::rowCategoryIndex(const QString &category) |
| 928 | { |
| 929 | Q_D(QItemModelSurfaceDataProxy); |
| 930 | return d->m_rowCategories.indexOf(str: category); |
| 931 | } |
| 932 | |
| 933 | /*! |
| 934 | * Returns the index of the specified \a category in the column categories list. |
| 935 | * If the category is not found, -1 is returned. |
| 936 | * \note If the automatic column categories generation is in use, this method |
| 937 | * will not return a valid index before the data in the model is resolved for |
| 938 | * the first time. |
| 939 | */ |
| 940 | qsizetype QItemModelSurfaceDataProxy::columnCategoryIndex(const QString &category) |
| 941 | { |
| 942 | Q_D(QItemModelSurfaceDataProxy); |
| 943 | return d->m_columnCategories.indexOf(str: category); |
| 944 | } |
| 945 | |
| 946 | /*! |
| 947 | * \property QItemModelSurfaceDataProxy::rowRolePattern |
| 948 | * |
| 949 | * \brief Whether a search and replace is performed on the value mapped by the |
| 950 | * row role before it is used as a row category. |
| 951 | * |
| 952 | * This property specifies the regular expression to find the portion of the |
| 953 | * mapped value to replace and the rowRoleReplace property contains the |
| 954 | * replacement string. |
| 955 | * |
| 956 | * \sa rowRole, rowRoleReplace |
| 957 | */ |
| 958 | void QItemModelSurfaceDataProxy::setRowRolePattern(const QRegularExpression &pattern) |
| 959 | { |
| 960 | Q_D(QItemModelSurfaceDataProxy); |
| 961 | if (d->m_rowRolePattern == pattern) { |
| 962 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 963 | << "value is already set to:" << pattern; |
| 964 | return; |
| 965 | } |
| 966 | d->m_rowRolePattern = pattern; |
| 967 | emit rowRolePatternChanged(pattern); |
| 968 | } |
| 969 | |
| 970 | QRegularExpression QItemModelSurfaceDataProxy::rowRolePattern() const |
| 971 | { |
| 972 | Q_D(const QItemModelSurfaceDataProxy); |
| 973 | return d->m_rowRolePattern; |
| 974 | } |
| 975 | |
| 976 | /*! |
| 977 | * \property QItemModelSurfaceDataProxy::columnRolePattern |
| 978 | * |
| 979 | * \brief Whether a search and replace is done on the value mapped by the column |
| 980 | * role before it is used as a column category. |
| 981 | * |
| 982 | * This property specifies the regular expression to find the portion of the |
| 983 | * mapped value to replace and the columnRoleReplace property contains the |
| 984 | * replacement string. |
| 985 | * |
| 986 | * \sa columnRole, columnRoleReplace |
| 987 | */ |
| 988 | void QItemModelSurfaceDataProxy::setColumnRolePattern(const QRegularExpression &pattern) |
| 989 | { |
| 990 | Q_D(QItemModelSurfaceDataProxy); |
| 991 | if (d->m_columnRolePattern == pattern) { |
| 992 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 993 | << "value is already set to:" << pattern; |
| 994 | return; |
| 995 | } |
| 996 | d->m_columnRolePattern = pattern; |
| 997 | emit columnRolePatternChanged(pattern); |
| 998 | } |
| 999 | |
| 1000 | QRegularExpression QItemModelSurfaceDataProxy::columnRolePattern() const |
| 1001 | { |
| 1002 | Q_D(const QItemModelSurfaceDataProxy); |
| 1003 | return d->m_columnRolePattern; |
| 1004 | } |
| 1005 | |
| 1006 | /*! |
| 1007 | * \property QItemModelSurfaceDataProxy::xPosRolePattern |
| 1008 | * |
| 1009 | * \brief Whether a search and replace is done on the value mapped by the x |
| 1010 | * position role before it is used as an item position value. |
| 1011 | * |
| 1012 | * This property specifies the regular expression to find the portion of the |
| 1013 | * mapped value to replace and the xPosRoleReplace property contains the |
| 1014 | * replacement string. |
| 1015 | * |
| 1016 | * \sa xPosRole, xPosRoleReplace |
| 1017 | */ |
| 1018 | void QItemModelSurfaceDataProxy::setXPosRolePattern(const QRegularExpression &pattern) |
| 1019 | { |
| 1020 | Q_D(QItemModelSurfaceDataProxy); |
| 1021 | if (d->m_xPosRolePattern == pattern) { |
| 1022 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 1023 | << "value is already set to:" << pattern; |
| 1024 | return; |
| 1025 | } |
| 1026 | d->m_xPosRolePattern = pattern; |
| 1027 | emit xPosRolePatternChanged(pattern); |
| 1028 | } |
| 1029 | |
| 1030 | QRegularExpression QItemModelSurfaceDataProxy::xPosRolePattern() const |
| 1031 | { |
| 1032 | Q_D(const QItemModelSurfaceDataProxy); |
| 1033 | return d->m_xPosRolePattern; |
| 1034 | } |
| 1035 | |
| 1036 | /*! |
| 1037 | * \property QItemModelSurfaceDataProxy::yPosRolePattern |
| 1038 | * |
| 1039 | * \brief Whether a search and replace is done on the value mapped by the y |
| 1040 | * position role before it is used as an item position value. |
| 1041 | * |
| 1042 | * This property specifies the regular expression to find the portion of the |
| 1043 | * mapped value to replace and the yPosRoleReplace property contains the |
| 1044 | * replacement string. |
| 1045 | * |
| 1046 | * \sa yPosRole, yPosRoleReplace |
| 1047 | */ |
| 1048 | void QItemModelSurfaceDataProxy::setYPosRolePattern(const QRegularExpression &pattern) |
| 1049 | { |
| 1050 | Q_D(QItemModelSurfaceDataProxy); |
| 1051 | if (d->m_yPosRolePattern == pattern) { |
| 1052 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 1053 | << "value is already set to:" << pattern; |
| 1054 | return; |
| 1055 | } |
| 1056 | d->m_yPosRolePattern = pattern; |
| 1057 | emit yPosRolePatternChanged(pattern); |
| 1058 | } |
| 1059 | |
| 1060 | QRegularExpression QItemModelSurfaceDataProxy::yPosRolePattern() const |
| 1061 | { |
| 1062 | Q_D(const QItemModelSurfaceDataProxy); |
| 1063 | return d->m_yPosRolePattern; |
| 1064 | } |
| 1065 | |
| 1066 | /*! |
| 1067 | * \property QItemModelSurfaceDataProxy::zPosRolePattern |
| 1068 | * |
| 1069 | * \brief Whether a search and replace is done on the value mapped by the z |
| 1070 | * position role before it is used as an item position value. |
| 1071 | * |
| 1072 | * This property specifies the regular expression to find the portion of the |
| 1073 | * mapped value to replace and the zPosRoleReplace property contains the |
| 1074 | * replacement string. |
| 1075 | * |
| 1076 | * \sa zPosRole, zPosRoleReplace |
| 1077 | */ |
| 1078 | void QItemModelSurfaceDataProxy::setZPosRolePattern(const QRegularExpression &pattern) |
| 1079 | { |
| 1080 | Q_D(QItemModelSurfaceDataProxy); |
| 1081 | if (d->m_zPosRolePattern == pattern) { |
| 1082 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 1083 | << "value is already set to:" << pattern; |
| 1084 | return; |
| 1085 | } |
| 1086 | d->m_zPosRolePattern = pattern; |
| 1087 | emit zPosRolePatternChanged(pattern); |
| 1088 | } |
| 1089 | |
| 1090 | QRegularExpression QItemModelSurfaceDataProxy::zPosRolePattern() const |
| 1091 | { |
| 1092 | Q_D(const QItemModelSurfaceDataProxy); |
| 1093 | return d->m_zPosRolePattern; |
| 1094 | } |
| 1095 | |
| 1096 | /*! |
| 1097 | * \property QItemModelSurfaceDataProxy::rowRoleReplace |
| 1098 | * |
| 1099 | * \brief The replacement content to be used in conjunction with the row role |
| 1100 | * pattern. |
| 1101 | * |
| 1102 | * Defaults to an empty string. For more information on how the search and |
| 1103 | * replace using regular expressions works, see QString::replace(const |
| 1104 | * QRegularExpression &rx, const QString &after) function documentation. |
| 1105 | * |
| 1106 | * \sa rowRole, rowRolePattern |
| 1107 | */ |
| 1108 | void QItemModelSurfaceDataProxy::setRowRoleReplace(const QString &replace) |
| 1109 | { |
| 1110 | Q_D(QItemModelSurfaceDataProxy); |
| 1111 | if (d->m_rowRoleReplace == replace) { |
| 1112 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 1113 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(replace)); |
| 1114 | return; |
| 1115 | } |
| 1116 | d->m_rowRoleReplace = replace; |
| 1117 | emit rowRoleReplaceChanged(replace); |
| 1118 | } |
| 1119 | |
| 1120 | QString QItemModelSurfaceDataProxy::rowRoleReplace() const |
| 1121 | { |
| 1122 | Q_D(const QItemModelSurfaceDataProxy); |
| 1123 | return d->m_rowRoleReplace; |
| 1124 | } |
| 1125 | |
| 1126 | /*! |
| 1127 | * \property QItemModelSurfaceDataProxy::columnRoleReplace |
| 1128 | * |
| 1129 | * \brief The replacement content to be used in conjunction with a column role |
| 1130 | * pattern. |
| 1131 | * |
| 1132 | * Defaults to an empty string. For more information on how the search and |
| 1133 | * replace using regular expressions works, see the |
| 1134 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 1135 | * function documentation. |
| 1136 | * |
| 1137 | * \sa columnRole, columnRolePattern |
| 1138 | */ |
| 1139 | void QItemModelSurfaceDataProxy::setColumnRoleReplace(const QString &replace) |
| 1140 | { |
| 1141 | Q_D(QItemModelSurfaceDataProxy); |
| 1142 | if (d->m_columnRoleReplace == replace) { |
| 1143 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 1144 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(replace)); |
| 1145 | return; |
| 1146 | } |
| 1147 | d->m_columnRoleReplace = replace; |
| 1148 | emit columnRoleReplaceChanged(replace); |
| 1149 | } |
| 1150 | |
| 1151 | QString QItemModelSurfaceDataProxy::columnRoleReplace() const |
| 1152 | { |
| 1153 | Q_D(const QItemModelSurfaceDataProxy); |
| 1154 | return d->m_columnRoleReplace; |
| 1155 | } |
| 1156 | |
| 1157 | /*! |
| 1158 | * \property QItemModelSurfaceDataProxy::xPosRoleReplace |
| 1159 | * |
| 1160 | * \brief The replacement content to be used in conjunction with an x position role |
| 1161 | * pattern. |
| 1162 | * |
| 1163 | * Defaults to an empty string. For more information on how the search and |
| 1164 | * replace using regular expressions works, see the |
| 1165 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 1166 | * function documentation. |
| 1167 | * |
| 1168 | * \sa xPosRole, xPosRolePattern |
| 1169 | */ |
| 1170 | void QItemModelSurfaceDataProxy::setXPosRoleReplace(const QString &replace) |
| 1171 | { |
| 1172 | Q_D(QItemModelSurfaceDataProxy); |
| 1173 | if (d->m_xPosRoleReplace == replace) { |
| 1174 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 1175 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(replace)); |
| 1176 | return; |
| 1177 | } |
| 1178 | d->m_xPosRoleReplace = replace; |
| 1179 | emit xPosRoleReplaceChanged(replace); |
| 1180 | } |
| 1181 | |
| 1182 | QString QItemModelSurfaceDataProxy::xPosRoleReplace() const |
| 1183 | { |
| 1184 | Q_D(const QItemModelSurfaceDataProxy); |
| 1185 | return d->m_xPosRoleReplace; |
| 1186 | } |
| 1187 | |
| 1188 | /*! |
| 1189 | * \property QItemModelSurfaceDataProxy::yPosRoleReplace |
| 1190 | * |
| 1191 | * \brief The replacement content to be used in conjunction with an y position role |
| 1192 | * pattern. |
| 1193 | * |
| 1194 | * Defaults to an empty string. For more information on how the search and |
| 1195 | * replace using regular expressions works, see the |
| 1196 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 1197 | * function documentation. |
| 1198 | * |
| 1199 | * \sa yPosRole, yPosRolePattern |
| 1200 | */ |
| 1201 | void QItemModelSurfaceDataProxy::setYPosRoleReplace(const QString &replace) |
| 1202 | { |
| 1203 | Q_D(QItemModelSurfaceDataProxy); |
| 1204 | if (d->m_yPosRoleReplace == replace) { |
| 1205 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 1206 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(replace)); |
| 1207 | return; |
| 1208 | } |
| 1209 | d->m_yPosRoleReplace = replace; |
| 1210 | emit yPosRoleReplaceChanged(replace); |
| 1211 | } |
| 1212 | |
| 1213 | QString QItemModelSurfaceDataProxy::yPosRoleReplace() const |
| 1214 | { |
| 1215 | Q_D(const QItemModelSurfaceDataProxy); |
| 1216 | return d->m_yPosRoleReplace; |
| 1217 | } |
| 1218 | |
| 1219 | /*! |
| 1220 | * \property QItemModelSurfaceDataProxy::zPosRoleReplace |
| 1221 | * |
| 1222 | * \brief The replacement content to be used in conjunction with a z position role |
| 1223 | * pattern. |
| 1224 | * |
| 1225 | * Defaults to an empty string. For more information on how the search and |
| 1226 | * replace using regular expressions works, see the |
| 1227 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 1228 | * function documentation. |
| 1229 | * |
| 1230 | * \sa zPosRole, zPosRolePattern |
| 1231 | */ |
| 1232 | void QItemModelSurfaceDataProxy::setZPosRoleReplace(const QString &replace) |
| 1233 | { |
| 1234 | Q_D(QItemModelSurfaceDataProxy); |
| 1235 | if (d->m_zPosRoleReplace == replace) { |
| 1236 | qCDebug(lcProperties3D, "%s value is already set to: %s" , |
| 1237 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(replace)); |
| 1238 | return; |
| 1239 | } |
| 1240 | d->m_zPosRoleReplace = replace; |
| 1241 | emit zPosRoleReplaceChanged(replace); |
| 1242 | } |
| 1243 | |
| 1244 | QString QItemModelSurfaceDataProxy::zPosRoleReplace() const |
| 1245 | { |
| 1246 | Q_D(const QItemModelSurfaceDataProxy); |
| 1247 | return d->m_zPosRoleReplace; |
| 1248 | } |
| 1249 | |
| 1250 | /*! |
| 1251 | * \property QItemModelSurfaceDataProxy::multiMatchBehavior |
| 1252 | * |
| 1253 | * \brief How multiple matches for each row/column combination are handled. |
| 1254 | * |
| 1255 | * Defaults to Last. |
| 1256 | * |
| 1257 | * For example, you might have an item model with timestamped data taken at |
| 1258 | * irregular intervals and you want to visualize an average position of data |
| 1259 | * items on each hour with a surface graph. This can be done by specifying row |
| 1260 | * and column categories so that each surface point represents an hour, and |
| 1261 | * setting this property to Average. |
| 1262 | */ |
| 1263 | |
| 1264 | void QItemModelSurfaceDataProxy::setMultiMatchBehavior( |
| 1265 | QItemModelSurfaceDataProxy::MultiMatchBehavior behavior) |
| 1266 | { |
| 1267 | Q_D(QItemModelSurfaceDataProxy); |
| 1268 | if (d->m_multiMatchBehavior == behavior) { |
| 1269 | qCDebug(lcProperties3D) << __FUNCTION__ |
| 1270 | << "value is already set to:" << behavior; |
| 1271 | } |
| 1272 | d->m_multiMatchBehavior = behavior; |
| 1273 | emit multiMatchBehaviorChanged(behavior); |
| 1274 | } |
| 1275 | |
| 1276 | QItemModelSurfaceDataProxy::MultiMatchBehavior QItemModelSurfaceDataProxy::multiMatchBehavior() const |
| 1277 | { |
| 1278 | Q_D(const QItemModelSurfaceDataProxy); |
| 1279 | return d->m_multiMatchBehavior; |
| 1280 | } |
| 1281 | |
| 1282 | // QItemModelSurfaceDataProxyPrivate |
| 1283 | |
| 1284 | QItemModelSurfaceDataProxyPrivate::QItemModelSurfaceDataProxyPrivate(QItemModelSurfaceDataProxy *q) |
| 1285 | : m_itemModelHandler(new SurfaceItemModelHandler(q)) |
| 1286 | , m_useModelCategories(false) |
| 1287 | , m_autoRowCategories(true) |
| 1288 | , m_autoColumnCategories(true) |
| 1289 | , m_multiMatchBehavior(QItemModelSurfaceDataProxy::MultiMatchBehavior::Last) |
| 1290 | {} |
| 1291 | |
| 1292 | QItemModelSurfaceDataProxyPrivate::~QItemModelSurfaceDataProxyPrivate() |
| 1293 | { |
| 1294 | delete m_itemModelHandler; |
| 1295 | } |
| 1296 | |
| 1297 | void QItemModelSurfaceDataProxyPrivate::connectItemModelHandler() |
| 1298 | { |
| 1299 | Q_Q(QItemModelSurfaceDataProxy); |
| 1300 | QObject::connect(sender: m_itemModelHandler, |
| 1301 | signal: &SurfaceItemModelHandler::itemModelChanged, |
| 1302 | context: q, |
| 1303 | slot: &QItemModelSurfaceDataProxy::itemModelChanged); |
| 1304 | QObject::connect(sender: q, |
| 1305 | signal: &QItemModelSurfaceDataProxy::rowRoleChanged, |
| 1306 | context: m_itemModelHandler, |
| 1307 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1308 | QObject::connect(sender: q, |
| 1309 | signal: &QItemModelSurfaceDataProxy::columnRoleChanged, |
| 1310 | context: m_itemModelHandler, |
| 1311 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1312 | QObject::connect(sender: q, |
| 1313 | signal: &QItemModelSurfaceDataProxy::xPosRoleChanged, |
| 1314 | context: m_itemModelHandler, |
| 1315 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1316 | QObject::connect(sender: q, |
| 1317 | signal: &QItemModelSurfaceDataProxy::yPosRoleChanged, |
| 1318 | context: m_itemModelHandler, |
| 1319 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1320 | QObject::connect(sender: q, |
| 1321 | signal: &QItemModelSurfaceDataProxy::zPosRoleChanged, |
| 1322 | context: m_itemModelHandler, |
| 1323 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1324 | QObject::connect(sender: q, |
| 1325 | signal: &QItemModelSurfaceDataProxy::rowCategoriesChanged, |
| 1326 | context: m_itemModelHandler, |
| 1327 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1328 | QObject::connect(sender: q, |
| 1329 | signal: &QItemModelSurfaceDataProxy::columnCategoriesChanged, |
| 1330 | context: m_itemModelHandler, |
| 1331 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1332 | QObject::connect(sender: q, |
| 1333 | signal: &QItemModelSurfaceDataProxy::useModelCategoriesChanged, |
| 1334 | context: m_itemModelHandler, |
| 1335 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1336 | QObject::connect(sender: q, |
| 1337 | signal: &QItemModelSurfaceDataProxy::autoRowCategoriesChanged, |
| 1338 | context: m_itemModelHandler, |
| 1339 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1340 | QObject::connect(sender: q, |
| 1341 | signal: &QItemModelSurfaceDataProxy::autoColumnCategoriesChanged, |
| 1342 | context: m_itemModelHandler, |
| 1343 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1344 | QObject::connect(sender: q, |
| 1345 | signal: &QItemModelSurfaceDataProxy::rowRolePatternChanged, |
| 1346 | context: m_itemModelHandler, |
| 1347 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1348 | QObject::connect(sender: q, |
| 1349 | signal: &QItemModelSurfaceDataProxy::columnRolePatternChanged, |
| 1350 | context: m_itemModelHandler, |
| 1351 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1352 | QObject::connect(sender: q, |
| 1353 | signal: &QItemModelSurfaceDataProxy::xPosRolePatternChanged, |
| 1354 | context: m_itemModelHandler, |
| 1355 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1356 | QObject::connect(sender: q, |
| 1357 | signal: &QItemModelSurfaceDataProxy::yPosRolePatternChanged, |
| 1358 | context: m_itemModelHandler, |
| 1359 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1360 | QObject::connect(sender: q, |
| 1361 | signal: &QItemModelSurfaceDataProxy::zPosRolePatternChanged, |
| 1362 | context: m_itemModelHandler, |
| 1363 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1364 | QObject::connect(sender: q, |
| 1365 | signal: &QItemModelSurfaceDataProxy::rowRoleReplaceChanged, |
| 1366 | context: m_itemModelHandler, |
| 1367 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1368 | QObject::connect(sender: q, |
| 1369 | signal: &QItemModelSurfaceDataProxy::columnRoleReplaceChanged, |
| 1370 | context: m_itemModelHandler, |
| 1371 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1372 | QObject::connect(sender: q, |
| 1373 | signal: &QItemModelSurfaceDataProxy::xPosRoleReplaceChanged, |
| 1374 | context: m_itemModelHandler, |
| 1375 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1376 | QObject::connect(sender: q, |
| 1377 | signal: &QItemModelSurfaceDataProxy::yPosRoleReplaceChanged, |
| 1378 | context: m_itemModelHandler, |
| 1379 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1380 | QObject::connect(sender: q, |
| 1381 | signal: &QItemModelSurfaceDataProxy::zPosRoleReplaceChanged, |
| 1382 | context: m_itemModelHandler, |
| 1383 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1384 | QObject::connect(sender: q, |
| 1385 | signal: &QItemModelSurfaceDataProxy::multiMatchBehaviorChanged, |
| 1386 | context: m_itemModelHandler, |
| 1387 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 1388 | } |
| 1389 | |
| 1390 | QT_END_NAMESPACE |
| 1391 | |