| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qitemmodelscatterdataproxy_p.h" |
| 5 | #include "scatteritemmodelhandler_p.h" |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | /*! |
| 10 | * \class QItemModelScatterDataProxy |
| 11 | * \inmodule QtGraphs |
| 12 | * \ingroup graphs_3D |
| 13 | * \brief Proxy class for presenting data in item models with Q3DScatterWidgetItem. |
| 14 | * |
| 15 | * QItemModelScatterDataProxy allows you to use QAbstractItemModel derived |
| 16 | * models as a data source for Q3DScatterWidgetItem. It maps roles of QAbstractItemModel |
| 17 | * to the XYZ-values of Q3DScatterWidgetItem points. |
| 18 | * |
| 19 | * The data is resolved asynchronously whenever the mapping or the model |
| 20 | * changes. QScatterDataProxy::arrayReset() is emitted when the data has been |
| 21 | * resolved. However, inserts, removes, and single data item changes after the |
| 22 | * model initialization are resolved synchronously, unless the same frame also |
| 23 | * contains a change that causes the whole model to be resolved. |
| 24 | * |
| 25 | * Mapping ignores rows and columns of the QAbstractItemModel and treats |
| 26 | * all items equally. It requires the model to provide roles for the data items |
| 27 | * that can be mapped to X, Y, and Z-values for the scatter points. |
| 28 | * |
| 29 | * For example, assume that you have a custom QAbstractItemModel for storing |
| 30 | * various measurements done on material samples, providing data for roles such |
| 31 | * as "density", "hardness", and "conductivity". You could visualize these |
| 32 | * properties on a scatter graph using this proxy: |
| 33 | * |
| 34 | * \snippet doc_src_qtgraphs.cpp scattermodelproxy |
| 35 | * |
| 36 | * If the fields of the model do not contain the data in the exact format you |
| 37 | * need, you can specify a search pattern regular expression and a replace rule |
| 38 | * for each role to get the value in a format you need. For more information on |
| 39 | * how the replacement using regular expressions works, see the |
| 40 | * QString::replace(const QRegularExpression &rx, const QString &after) |
| 41 | * function documentation. Note that using regular expressions has an impact on |
| 42 | * performance, so it's more efficient to utilize item models where doing search |
| 43 | * and replace is not necessary to get the desired values. |
| 44 | * |
| 45 | * For example about using the search patterns in conjunction with the roles, |
| 46 | * see ItemModelBarDataProxy usage in \l{Simple Bar Graph}. |
| 47 | * |
| 48 | * \sa {Qt Graphs Data Handling with 3D} |
| 49 | */ |
| 50 | |
| 51 | /*! |
| 52 | * \qmltype ItemModelScatterDataProxy |
| 53 | * \inqmlmodule QtGraphs |
| 54 | * \ingroup graphs_qml_3D |
| 55 | * \nativetype QItemModelScatterDataProxy |
| 56 | * \inherits ScatterDataProxy |
| 57 | * \brief Proxy class for presenting data in item models with Scatter3D. |
| 58 | * |
| 59 | * This type allows you to use AbstractItemModel derived models as a data source |
| 60 | * for Scatter3D. |
| 61 | * |
| 62 | * The data is resolved asynchronously whenever the mapping or the model |
| 63 | * changes. QScatterDataProxy::arrayReset() is emitted when the data has been |
| 64 | * resolved. |
| 65 | * |
| 66 | * For more details, see QItemModelScatterDataProxy documentation. |
| 67 | * |
| 68 | * Usage example: |
| 69 | * |
| 70 | * \snippet doc_src_qmlgraphs.cpp 8 |
| 71 | * |
| 72 | * \sa ScatterDataProxy, {Qt Graphs Data Handling with 3D} |
| 73 | */ |
| 74 | |
| 75 | /*! |
| 76 | * \qmlproperty model ItemModelScatterDataProxy::itemModel |
| 77 | * The item model to use as a data source for Scatter3D. |
| 78 | */ |
| 79 | |
| 80 | /*! |
| 81 | * \qmlproperty string ItemModelScatterDataProxy::xPosRole |
| 82 | * The item model role to map into the X position. |
| 83 | */ |
| 84 | |
| 85 | /*! |
| 86 | * \qmlproperty string ItemModelScatterDataProxy::yPosRole |
| 87 | * The item model role to map into the Y position. |
| 88 | */ |
| 89 | |
| 90 | /*! |
| 91 | * \qmlproperty string ItemModelScatterDataProxy::zPosRole |
| 92 | * The item model role to map into the Z position. |
| 93 | */ |
| 94 | |
| 95 | /*! |
| 96 | * \qmlproperty string ItemModelScatterDataProxy::rotationRole |
| 97 | * |
| 98 | * The item model role to map into item rotation. |
| 99 | * The model may supply the value for rotation as either variant that is |
| 100 | * directly convertible to \l [QtQuick] quaternion, or as one of the string |
| 101 | * representations: \c{"scalar,x,y,z"} or \c{"@angle,x,y,z"}. The first format |
| 102 | * will construct the \l [QtQuick] quaternion directly with given values, and |
| 103 | * the second one will construct the \l [QtQuick] quaternion using |
| 104 | * QQuaternion::fromAxisAndAngle() method. |
| 105 | */ |
| 106 | |
| 107 | /*! |
| 108 | * \qmlproperty regExp ItemModelScatterDataProxy::xPosRolePattern |
| 109 | * |
| 110 | * When set, a search and replace is done on the value mapped by the x-position |
| 111 | * role before it is used as |
| 112 | * an item position value. This property specifies the regular expression to |
| 113 | * find the portion of the mapped value to replace, and xPosRoleReplace property |
| 114 | * contains the replacement string. |
| 115 | * |
| 116 | * \sa xPosRole, xPosRoleReplace |
| 117 | */ |
| 118 | |
| 119 | /*! |
| 120 | * \qmlproperty regExp ItemModelScatterDataProxy::yPosRolePattern |
| 121 | * |
| 122 | * When set, a search and replace is done on the value mapped by the y-position |
| 123 | * role before it is used as |
| 124 | * an item position value. This property specifies the regular expression to |
| 125 | * find the portion of the mapped value to replace, and yPosRoleReplace property |
| 126 | * contains the replacement string. |
| 127 | * |
| 128 | * \sa yPosRole, yPosRoleReplace |
| 129 | */ |
| 130 | |
| 131 | /*! |
| 132 | * \qmlproperty regExp ItemModelScatterDataProxy::zPosRolePattern |
| 133 | * |
| 134 | * When set, a search and replace is done on the value mapped by the z-position |
| 135 | * role before it is used as |
| 136 | * an item position value. This property specifies the regular expression to |
| 137 | * find the portion of the mapped value to replace, and zPosRoleReplace property |
| 138 | * contains the replacement string. |
| 139 | * |
| 140 | * \sa zPosRole, zPosRoleReplace |
| 141 | */ |
| 142 | |
| 143 | /*! |
| 144 | * \qmlproperty regExp ItemModelScatterDataProxy::rotationRolePattern |
| 145 | * When set, a search and replace is done on the value mapped by the rotation |
| 146 | * role before it is used |
| 147 | * as item rotation. This property specifies the regular expression to find the |
| 148 | * portion of the mapped value to replace, and rotationRoleReplace property |
| 149 | * contains the replacement string. |
| 150 | * |
| 151 | * \sa rotationRole, rotationRoleReplace |
| 152 | */ |
| 153 | |
| 154 | /*! |
| 155 | * \qmlproperty string ItemModelScatterDataProxy::xPosRoleReplace |
| 156 | * |
| 157 | * This property defines the replacement content to be used in conjunction with |
| 158 | * xPosRolePattern. Defaults to an empty string. For more information on how the |
| 159 | * search and replace using regular expressions works, see |
| 160 | * the QString::replace(const QRegularExpression &rx, const QString &after) |
| 161 | * function documentation. |
| 162 | * |
| 163 | * \sa xPosRole, xPosRolePattern |
| 164 | */ |
| 165 | |
| 166 | /*! |
| 167 | * \qmlproperty string ItemModelScatterDataProxy::yPosRoleReplace |
| 168 | * |
| 169 | * This property defines the replacement content to be used in conjunction with |
| 170 | * yPosRolePattern. Defaults to an empty string. For more information on how the |
| 171 | * search and replace using regular expressions works, see |
| 172 | * the QString::replace(const QRegularExpression &rx, const QString &after) |
| 173 | * function documentation. |
| 174 | * |
| 175 | * \sa yPosRole, yPosRolePattern |
| 176 | */ |
| 177 | |
| 178 | /*! |
| 179 | * \qmlproperty string ItemModelScatterDataProxy::zPosRoleReplace |
| 180 | * |
| 181 | * This property defines the replacement content to be used in conjunction with |
| 182 | * zPosRolePattern. Defaults to an empty string. For more information on how the |
| 183 | * search and replace using regular expressions works, see |
| 184 | * the QString::replace(const QRegularExpression &rx, const QString &after) |
| 185 | * function documentation. |
| 186 | * |
| 187 | * \sa zPosRole, zPosRolePattern |
| 188 | */ |
| 189 | |
| 190 | /*! |
| 191 | * \qmlproperty string ItemModelScatterDataProxy::rotationRoleReplace |
| 192 | * This property defines the replacement content to be used in conjunction with |
| 193 | * rotationRolePattern. Defaults to an empty string. For more information on how |
| 194 | * the search and replace using regular expressions works, see |
| 195 | * the QString::replace(const QRegularExpression &rx, const QString &after) |
| 196 | * function documentation. |
| 197 | * |
| 198 | * \sa rotationRole, rotationRolePattern |
| 199 | */ |
| 200 | |
| 201 | /*! |
| 202 | \qmlsignal ItemModelScatterDataProxy::itemModelChanged(model itemModel) |
| 203 | |
| 204 | This signal is emitted when itemModel changes to \a itemModel. |
| 205 | */ |
| 206 | |
| 207 | /*! |
| 208 | \qmlsignal ItemModelScatterDataProxy::xPosRoleChanged(string role) |
| 209 | |
| 210 | This signal is emitted when xPosRole changes to \a role. |
| 211 | */ |
| 212 | |
| 213 | /*! |
| 214 | \qmlsignal ItemModelScatterDataProxy::yPosRoleChanged(string role) |
| 215 | |
| 216 | This signal is emitted when yPosRole changes to \a role. |
| 217 | */ |
| 218 | |
| 219 | /*! |
| 220 | \qmlsignal ItemModelScatterDataProxy::zPosRoleChanged(string role) |
| 221 | |
| 222 | This signal is emitted when zPosRole changes to \a role. |
| 223 | */ |
| 224 | |
| 225 | /*! |
| 226 | \qmlsignal ItemModelScatterDataProxy::rotationRoleChanged(string role) |
| 227 | |
| 228 | This signal is emitted when rotationRole changes to \a role. |
| 229 | */ |
| 230 | |
| 231 | /*! |
| 232 | \qmlsignal ItemModelScatterDataProxy::xPosRolePatternChanged(regExp pattern) |
| 233 | |
| 234 | This signal is emitted when xPosRolePattern changes to \a pattern. |
| 235 | */ |
| 236 | |
| 237 | /*! |
| 238 | \qmlsignal ItemModelScatterDataProxy::yPosRolePatternChanged(regExp pattern) |
| 239 | |
| 240 | This signal is emitted when yPosRolePattern changes to \a pattern. |
| 241 | */ |
| 242 | |
| 243 | /*! |
| 244 | \qmlsignal ItemModelScatterDataProxy::zPosRolePatternChanged(regExp pattern) |
| 245 | |
| 246 | This signal is emitted when zPosRolePattern changes to \a pattern. |
| 247 | */ |
| 248 | |
| 249 | /*! |
| 250 | \qmlsignal ItemModelScatterDataProxy::rotationRolePatternChanged(regExp pattern) |
| 251 | |
| 252 | This signal is emitted when rotationRolePattern changes to \a pattern. |
| 253 | */ |
| 254 | |
| 255 | /*! |
| 256 | \qmlsignal ItemModelScatterDataProxy::rotationRoleReplaceChanged(string replace) |
| 257 | |
| 258 | This signal is emitted when rotationRoleReplace changes to \a replace. |
| 259 | */ |
| 260 | |
| 261 | /*! |
| 262 | \qmlsignal ItemModelScatterDataProxy::xPosRoleReplaceChanged(string replace) |
| 263 | |
| 264 | This signal is emitted when xPosRoleReplace changes to \a replace. |
| 265 | */ |
| 266 | |
| 267 | /*! |
| 268 | \qmlsignal ItemModelScatterDataProxy::yPosRoleReplaceChanged(string replace) |
| 269 | |
| 270 | This signal is emitted when yPosRoleReplace changes to \a replace. |
| 271 | */ |
| 272 | |
| 273 | /*! |
| 274 | \qmlsignal ItemModelScatterDataProxy::zPosRoleReplaceChanged(string replace) |
| 275 | |
| 276 | This signal is emitted when zPosRoleReplace changes to \a replace. |
| 277 | */ |
| 278 | |
| 279 | /*! |
| 280 | * Constructs QItemModelScatterDataProxy with optional \a parent. |
| 281 | */ |
| 282 | QItemModelScatterDataProxy::QItemModelScatterDataProxy(QObject *parent) |
| 283 | : QScatterDataProxy(*(new QItemModelScatterDataProxyPrivate(this)), parent) |
| 284 | { |
| 285 | Q_D(QItemModelScatterDataProxy); |
| 286 | d->connectItemModelHandler(); |
| 287 | } |
| 288 | |
| 289 | /*! |
| 290 | * Constructs QItemModelScatterDataProxy with \a itemModel and an optional \a |
| 291 | * parent. Proxy doesn't take ownership of the \a itemModel, as typically item |
| 292 | * models are owned by other controls. |
| 293 | */ |
| 294 | QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, |
| 295 | QObject *parent) |
| 296 | : QScatterDataProxy(*(new QItemModelScatterDataProxyPrivate(this)), parent) |
| 297 | { |
| 298 | Q_D(QItemModelScatterDataProxy); |
| 299 | d->m_itemModelHandler->setItemModel(itemModel); |
| 300 | d->connectItemModelHandler(); |
| 301 | } |
| 302 | |
| 303 | /*! |
| 304 | * Constructs QItemModelScatterDataProxy with \a itemModel and an optional |
| 305 | * \a parent. The proxy doesn't take ownership of the \a itemModel, as item |
| 306 | * models are typically owned by other controls. The xPosRole property is set |
| 307 | * to \a xPosRole, the yPosRole property to \a yPosRole, and the zPosRole |
| 308 | * property to \a zPosRole. |
| 309 | */ |
| 310 | QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, |
| 311 | const QString &xPosRole, |
| 312 | const QString &yPosRole, |
| 313 | const QString &zPosRole, |
| 314 | QObject *parent) |
| 315 | : QScatterDataProxy(*(new QItemModelScatterDataProxyPrivate(this)), parent) |
| 316 | { |
| 317 | Q_D(QItemModelScatterDataProxy); |
| 318 | d->m_itemModelHandler->setItemModel(itemModel); |
| 319 | d->m_xPosRole = xPosRole; |
| 320 | d->m_yPosRole = yPosRole; |
| 321 | d->m_zPosRole = zPosRole; |
| 322 | d->connectItemModelHandler(); |
| 323 | } |
| 324 | |
| 325 | /*! |
| 326 | * Constructs QItemModelScatterDataProxy with \a itemModel and an optional \a |
| 327 | * parent. The proxy doesn't take ownership of the \a itemModel, as item models |
| 328 | * are typically owned by other controls. The xPosRole property is set to \a |
| 329 | * xPosRole, the yPosRole property to \a yPosRole, the zPosRole property to \a |
| 330 | * zPosRole, and the rotationRole property to \a rotationRole. |
| 331 | */ |
| 332 | QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, |
| 333 | const QString &xPosRole, |
| 334 | const QString &yPosRole, |
| 335 | const QString &zPosRole, |
| 336 | const QString &rotationRole, |
| 337 | QObject *parent) |
| 338 | : QScatterDataProxy(*(new QItemModelScatterDataProxyPrivate(this)), parent) |
| 339 | { |
| 340 | Q_D(QItemModelScatterDataProxy); |
| 341 | d->m_itemModelHandler->setItemModel(itemModel); |
| 342 | d->m_xPosRole = xPosRole; |
| 343 | d->m_yPosRole = yPosRole; |
| 344 | d->m_zPosRole = zPosRole; |
| 345 | d->m_rotationRole = rotationRole; |
| 346 | d->connectItemModelHandler(); |
| 347 | } |
| 348 | |
| 349 | /*! |
| 350 | * Destroys QItemModelScatterDataProxy. |
| 351 | */ |
| 352 | QItemModelScatterDataProxy::~QItemModelScatterDataProxy() {} |
| 353 | |
| 354 | /*! |
| 355 | * \property QItemModelScatterDataProxy::itemModel |
| 356 | * |
| 357 | * \brief The item model to use as a data source for a 3D scatter series. |
| 358 | */ |
| 359 | |
| 360 | /*! |
| 361 | * Sets \a itemModel as the item model for Q3DScatterWidgetItem. Does not take |
| 362 | * ownership of the model, but does connect to it to listen for changes. |
| 363 | */ |
| 364 | void QItemModelScatterDataProxy::setItemModel(QAbstractItemModel *itemModel) |
| 365 | { |
| 366 | Q_D(QItemModelScatterDataProxy); |
| 367 | d->m_itemModelHandler->setItemModel(itemModel); |
| 368 | } |
| 369 | |
| 370 | QAbstractItemModel *QItemModelScatterDataProxy::itemModel() const |
| 371 | { |
| 372 | Q_D(const QItemModelScatterDataProxy); |
| 373 | return d->m_itemModelHandler->itemModel(); |
| 374 | } |
| 375 | |
| 376 | /*! |
| 377 | * \property QItemModelScatterDataProxy::xPosRole |
| 378 | * |
| 379 | * \brief The item model role to map into the X position. |
| 380 | */ |
| 381 | void QItemModelScatterDataProxy::setXPosRole(const QString &role) |
| 382 | { |
| 383 | Q_D(QItemModelScatterDataProxy); |
| 384 | if (d->m_xPosRole != role) { |
| 385 | d->m_xPosRole = role; |
| 386 | emit xPosRoleChanged(role); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | QString QItemModelScatterDataProxy::xPosRole() const |
| 391 | { |
| 392 | Q_D(const QItemModelScatterDataProxy); |
| 393 | return d->m_xPosRole; |
| 394 | } |
| 395 | |
| 396 | /*! |
| 397 | * \property QItemModelScatterDataProxy::yPosRole |
| 398 | * |
| 399 | * \brief The item model role to map into the Y position. |
| 400 | */ |
| 401 | void QItemModelScatterDataProxy::setYPosRole(const QString &role) |
| 402 | { |
| 403 | Q_D(QItemModelScatterDataProxy); |
| 404 | if (d->m_yPosRole != role) { |
| 405 | d->m_yPosRole = role; |
| 406 | emit yPosRoleChanged(role); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | QString QItemModelScatterDataProxy::yPosRole() const |
| 411 | { |
| 412 | Q_D(const QItemModelScatterDataProxy); |
| 413 | return d->m_yPosRole; |
| 414 | } |
| 415 | |
| 416 | /*! |
| 417 | * \property QItemModelScatterDataProxy::zPosRole |
| 418 | * |
| 419 | * \brief The item model role to map into the Z position. |
| 420 | */ |
| 421 | void QItemModelScatterDataProxy::setZPosRole(const QString &role) |
| 422 | { |
| 423 | Q_D(QItemModelScatterDataProxy); |
| 424 | if (d->m_zPosRole != role) { |
| 425 | d->m_zPosRole = role; |
| 426 | emit zPosRoleChanged(role); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | QString QItemModelScatterDataProxy::zPosRole() const |
| 431 | { |
| 432 | Q_D(const QItemModelScatterDataProxy); |
| 433 | return d->m_zPosRole; |
| 434 | } |
| 435 | |
| 436 | /*! |
| 437 | * \property QItemModelScatterDataProxy::rotationRole |
| 438 | * |
| 439 | * \brief The item model role to map into item rotation. |
| 440 | * |
| 441 | * The model may supply the value for rotation as either a variant that is |
| 442 | * directly convertible to QQuaternion or as one of the string representations: |
| 443 | * \c{"scalar,x,y,z"} or \c{"@angle,x,y,z"}. The first will construct the |
| 444 | * quaternion directly with the given values, and the second one will construct |
| 445 | * the quaternion using the QQuaternion::fromAxisAndAngle() method. |
| 446 | */ |
| 447 | void QItemModelScatterDataProxy::setRotationRole(const QString &role) |
| 448 | { |
| 449 | Q_D(QItemModelScatterDataProxy); |
| 450 | if (d->m_rotationRole != role) { |
| 451 | d->m_rotationRole = role; |
| 452 | emit rotationRoleChanged(role); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | QString QItemModelScatterDataProxy::rotationRole() const |
| 457 | { |
| 458 | Q_D(const QItemModelScatterDataProxy); |
| 459 | return d->m_rotationRole; |
| 460 | } |
| 461 | |
| 462 | /*! |
| 463 | * \property QItemModelScatterDataProxy::xPosRolePattern |
| 464 | * |
| 465 | * \brief Whether search and replace is done on the value mapped by the x |
| 466 | * position role before it is used as an item position value. |
| 467 | * |
| 468 | * This property specifies the regular expression to find the portion of the |
| 469 | * mapped value to replace and xPosRoleReplace property contains the replacement |
| 470 | * string. |
| 471 | * |
| 472 | * \sa xPosRole, xPosRoleReplace |
| 473 | */ |
| 474 | void QItemModelScatterDataProxy::setXPosRolePattern(const QRegularExpression &pattern) |
| 475 | { |
| 476 | Q_D(QItemModelScatterDataProxy); |
| 477 | if (d->m_xPosRolePattern != pattern) { |
| 478 | d->m_xPosRolePattern = pattern; |
| 479 | emit xPosRolePatternChanged(pattern); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | QRegularExpression QItemModelScatterDataProxy::xPosRolePattern() const |
| 484 | { |
| 485 | Q_D(const QItemModelScatterDataProxy); |
| 486 | return d->m_xPosRolePattern; |
| 487 | } |
| 488 | |
| 489 | /*! |
| 490 | * \property QItemModelScatterDataProxy::yPosRolePattern |
| 491 | * |
| 492 | * \brief Whether a search and replace is done on the value mapped by the |
| 493 | * y position role before it is used as an item position value. |
| 494 | * |
| 495 | * This property specifies the regular expression to find the portion of the |
| 496 | * mapped value to replace and yPosRoleReplace property contains the replacement |
| 497 | * string. |
| 498 | * |
| 499 | * \sa yPosRole, yPosRoleReplace |
| 500 | */ |
| 501 | void QItemModelScatterDataProxy::setYPosRolePattern(const QRegularExpression &pattern) |
| 502 | { |
| 503 | Q_D(QItemModelScatterDataProxy); |
| 504 | if (d->m_yPosRolePattern != pattern) { |
| 505 | d->m_yPosRolePattern = pattern; |
| 506 | emit yPosRolePatternChanged(pattern); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | QRegularExpression QItemModelScatterDataProxy::yPosRolePattern() const |
| 511 | { |
| 512 | Q_D(const QItemModelScatterDataProxy); |
| 513 | return d->m_yPosRolePattern; |
| 514 | } |
| 515 | |
| 516 | /*! |
| 517 | * \property QItemModelScatterDataProxy::zPosRolePattern |
| 518 | * |
| 519 | * \brief Whether a search and replace is done on the value mapped by the z |
| 520 | * position role before it is used as an item position value. |
| 521 | * |
| 522 | * This property specifies the regular expression to find the portion of the |
| 523 | * mapped value to replace and zPosRoleReplace property contains the replacement |
| 524 | * string. |
| 525 | * |
| 526 | * \sa zPosRole, zPosRoleReplace |
| 527 | */ |
| 528 | void QItemModelScatterDataProxy::setZPosRolePattern(const QRegularExpression &pattern) |
| 529 | { |
| 530 | Q_D(QItemModelScatterDataProxy); |
| 531 | if (d->m_zPosRolePattern != pattern) { |
| 532 | d->m_zPosRolePattern = pattern; |
| 533 | emit zPosRolePatternChanged(pattern); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | QRegularExpression QItemModelScatterDataProxy::zPosRolePattern() const |
| 538 | { |
| 539 | Q_D(const QItemModelScatterDataProxy); |
| 540 | return d->m_zPosRolePattern; |
| 541 | } |
| 542 | |
| 543 | /*! |
| 544 | * \property QItemModelScatterDataProxy::rotationRolePattern |
| 545 | * |
| 546 | * \brief Whether a search and replace is done on the value mapped by the |
| 547 | * rotation role before it is used as item rotation. |
| 548 | * |
| 549 | * This property specifies the regular expression to find the portion |
| 550 | * of the mapped value to replace and rotationRoleReplace property contains the |
| 551 | * replacement string. |
| 552 | * |
| 553 | * \sa rotationRole, rotationRoleReplace |
| 554 | */ |
| 555 | void QItemModelScatterDataProxy::setRotationRolePattern(const QRegularExpression &pattern) |
| 556 | { |
| 557 | Q_D(QItemModelScatterDataProxy); |
| 558 | if (d->m_rotationRolePattern != pattern) { |
| 559 | d->m_rotationRolePattern = pattern; |
| 560 | emit rotationRolePatternChanged(pattern); |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | QRegularExpression QItemModelScatterDataProxy::rotationRolePattern() const |
| 565 | { |
| 566 | Q_D(const QItemModelScatterDataProxy); |
| 567 | return d->m_rotationRolePattern; |
| 568 | } |
| 569 | |
| 570 | /*! |
| 571 | * \property QItemModelScatterDataProxy::xPosRoleReplace |
| 572 | * |
| 573 | * \brief The replace content to be used in conjunction with the x position role |
| 574 | * pattern. |
| 575 | * |
| 576 | * Defaults to an empty string. For more information on how the search and |
| 577 | * replace using regular expressions works, see QString::replace(const |
| 578 | * QRegularExpression &rx, const QString &after) function documentation. |
| 579 | * |
| 580 | * \sa xPosRole, xPosRolePattern |
| 581 | */ |
| 582 | void QItemModelScatterDataProxy::setXPosRoleReplace(const QString &replace) |
| 583 | { |
| 584 | Q_D(QItemModelScatterDataProxy); |
| 585 | if (d->m_xPosRoleReplace != replace) { |
| 586 | d->m_xPosRoleReplace = replace; |
| 587 | emit xPosRoleReplaceChanged(replace); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | QString QItemModelScatterDataProxy::xPosRoleReplace() const |
| 592 | { |
| 593 | Q_D(const QItemModelScatterDataProxy); |
| 594 | return d->m_xPosRoleReplace; |
| 595 | } |
| 596 | |
| 597 | /*! |
| 598 | * \property QItemModelScatterDataProxy::yPosRoleReplace |
| 599 | * |
| 600 | * \brief The replace content to be used in conjunction with the y position role |
| 601 | * pattern. |
| 602 | * |
| 603 | * Defaults to an empty string. For more information on how the search and |
| 604 | * replace using regular expressions works, see QString::replace(const |
| 605 | * QRegularExpression &rx, const QString &after) function documentation. |
| 606 | * |
| 607 | * \sa yPosRole, yPosRolePattern |
| 608 | */ |
| 609 | void QItemModelScatterDataProxy::setYPosRoleReplace(const QString &replace) |
| 610 | { |
| 611 | Q_D(QItemModelScatterDataProxy); |
| 612 | if (d->m_yPosRoleReplace != replace) { |
| 613 | d->m_yPosRoleReplace = replace; |
| 614 | emit yPosRoleReplaceChanged(replace); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | QString QItemModelScatterDataProxy::yPosRoleReplace() const |
| 619 | { |
| 620 | Q_D(const QItemModelScatterDataProxy); |
| 621 | return d->m_yPosRoleReplace; |
| 622 | } |
| 623 | |
| 624 | /*! |
| 625 | * \property QItemModelScatterDataProxy::zPosRoleReplace |
| 626 | * |
| 627 | * \brief The replace content to be used in conjunction with the z position role |
| 628 | * pattern. |
| 629 | * |
| 630 | * Defaults to an empty string. For more information on how the search and |
| 631 | * replace using regular expressions works, see QString::replace(const |
| 632 | * QRegularExpression &rx, const QString &after) function documentation. |
| 633 | * |
| 634 | * \sa zPosRole, zPosRolePattern |
| 635 | */ |
| 636 | void QItemModelScatterDataProxy::setZPosRoleReplace(const QString &replace) |
| 637 | { |
| 638 | Q_D(QItemModelScatterDataProxy); |
| 639 | if (d->m_zPosRoleReplace != replace) { |
| 640 | d->m_zPosRoleReplace = replace; |
| 641 | emit zPosRoleReplaceChanged(replace); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | QString QItemModelScatterDataProxy::zPosRoleReplace() const |
| 646 | { |
| 647 | Q_D(const QItemModelScatterDataProxy); |
| 648 | return d->m_zPosRoleReplace; |
| 649 | } |
| 650 | |
| 651 | /*! |
| 652 | * \property QItemModelScatterDataProxy::rotationRoleReplace |
| 653 | * |
| 654 | * \brief The replace content to be used in conjunction with the rotation role |
| 655 | * pattern. |
| 656 | * |
| 657 | * Defaults to an empty string. For more information on how the search and |
| 658 | * replace using regular expressions works, see QString::replace(const |
| 659 | * QRegularExpression &rx, const QString &after) function documentation. |
| 660 | * |
| 661 | * \sa rotationRole, rotationRolePattern |
| 662 | */ |
| 663 | void QItemModelScatterDataProxy::setRotationRoleReplace(const QString &replace) |
| 664 | { |
| 665 | Q_D(QItemModelScatterDataProxy); |
| 666 | if (d->m_rotationRoleReplace != replace) { |
| 667 | d->m_rotationRoleReplace = replace; |
| 668 | emit rotationRoleReplaceChanged(replace); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | QString QItemModelScatterDataProxy::rotationRoleReplace() const |
| 673 | { |
| 674 | Q_D(const QItemModelScatterDataProxy); |
| 675 | return d->m_rotationRoleReplace; |
| 676 | } |
| 677 | |
| 678 | /*! |
| 679 | * Changes \a xPosRole, \a yPosRole, \a zPosRole, and \a rotationRole mapping. |
| 680 | */ |
| 681 | void QItemModelScatterDataProxy::remap(const QString &xPosRole, |
| 682 | const QString &yPosRole, |
| 683 | const QString &zPosRole, |
| 684 | const QString &rotationRole) |
| 685 | { |
| 686 | setXPosRole(xPosRole); |
| 687 | setYPosRole(yPosRole); |
| 688 | setZPosRole(zPosRole); |
| 689 | setRotationRole(rotationRole); |
| 690 | } |
| 691 | |
| 692 | // QItemModelScatterDataProxyPrivate |
| 693 | |
| 694 | QItemModelScatterDataProxyPrivate::QItemModelScatterDataProxyPrivate(QItemModelScatterDataProxy *q) |
| 695 | : m_itemModelHandler(new ScatterItemModelHandler(q)) |
| 696 | {} |
| 697 | |
| 698 | QItemModelScatterDataProxyPrivate::~QItemModelScatterDataProxyPrivate() |
| 699 | { |
| 700 | delete m_itemModelHandler; |
| 701 | } |
| 702 | |
| 703 | void QItemModelScatterDataProxyPrivate::connectItemModelHandler() |
| 704 | { |
| 705 | Q_Q(QItemModelScatterDataProxy); |
| 706 | QObject::connect(sender: m_itemModelHandler, |
| 707 | signal: &ScatterItemModelHandler::itemModelChanged, |
| 708 | context: q, |
| 709 | slot: &QItemModelScatterDataProxy::itemModelChanged); |
| 710 | QObject::connect(sender: q, |
| 711 | signal: &QItemModelScatterDataProxy::xPosRoleChanged, |
| 712 | context: m_itemModelHandler, |
| 713 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 714 | QObject::connect(sender: q, |
| 715 | signal: &QItemModelScatterDataProxy::yPosRoleChanged, |
| 716 | context: m_itemModelHandler, |
| 717 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 718 | QObject::connect(sender: q, |
| 719 | signal: &QItemModelScatterDataProxy::zPosRoleChanged, |
| 720 | context: m_itemModelHandler, |
| 721 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 722 | QObject::connect(sender: q, |
| 723 | signal: &QItemModelScatterDataProxy::rotationRoleChanged, |
| 724 | context: m_itemModelHandler, |
| 725 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 726 | QObject::connect(sender: q, |
| 727 | signal: &QItemModelScatterDataProxy::xPosRolePatternChanged, |
| 728 | context: m_itemModelHandler, |
| 729 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 730 | QObject::connect(sender: q, |
| 731 | signal: &QItemModelScatterDataProxy::yPosRolePatternChanged, |
| 732 | context: m_itemModelHandler, |
| 733 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 734 | QObject::connect(sender: q, |
| 735 | signal: &QItemModelScatterDataProxy::zPosRolePatternChanged, |
| 736 | context: m_itemModelHandler, |
| 737 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 738 | QObject::connect(sender: q, |
| 739 | signal: &QItemModelScatterDataProxy::rotationRolePatternChanged, |
| 740 | context: m_itemModelHandler, |
| 741 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 742 | QObject::connect(sender: q, |
| 743 | signal: &QItemModelScatterDataProxy::xPosRoleReplaceChanged, |
| 744 | context: m_itemModelHandler, |
| 745 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 746 | QObject::connect(sender: q, |
| 747 | signal: &QItemModelScatterDataProxy::yPosRoleReplaceChanged, |
| 748 | context: m_itemModelHandler, |
| 749 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 750 | QObject::connect(sender: q, |
| 751 | signal: &QItemModelScatterDataProxy::zPosRoleReplaceChanged, |
| 752 | context: m_itemModelHandler, |
| 753 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 754 | QObject::connect(sender: q, |
| 755 | signal: &QItemModelScatterDataProxy::rotationRoleReplaceChanged, |
| 756 | context: m_itemModelHandler, |
| 757 | slot: &AbstractItemModelHandler::handleMappingChanged); |
| 758 | } |
| 759 | |
| 760 | QT_END_NAMESPACE |
| 761 | |