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

source code of qtgraphs/src/graphs3d/data/qitemmodelscatterdataproxy.cpp