diff options
author | Sakaria Pouke <[email protected]> | 2025-05-27 16:30:25 +0300 |
---|---|---|
committer | Sami Varanka <[email protected]> | 2025-05-30 16:50:09 +0000 |
commit | 65f74386ef747a1ac6c0d223191cc20aa2feb718 (patch) | |
tree | ad8cfcea0ba39b74aea0126d3f831ca134fe37f4 /src/graphs3d/data/qitemmodelscatterdataproxy.cpp | |
parent | c1ccb5b83439203dcebe093ebb475d642d5b2973 (diff) |
Also update ItemModelScatterDataProxy and ScatterItemModelHandler.
Added manual test for vector fields.
Fixes: QTBUG-134242
Task-number: QTBUG-134558
Change-Id: Ie4f128419ea176d1b8e0f8e874f447ce7fb35b39
Reviewed-by: Sami Varanka <[email protected]>
Diffstat (limited to 'src/graphs3d/data/qitemmodelscatterdataproxy.cpp')
-rw-r--r-- | src/graphs3d/data/qitemmodelscatterdataproxy.cpp | 171 |
1 files changed, 169 insertions, 2 deletions
diff --git a/src/graphs3d/data/qitemmodelscatterdataproxy.cpp b/src/graphs3d/data/qitemmodelscatterdataproxy.cpp index 064a6c37..1e19b692 100644 --- a/src/graphs3d/data/qitemmodelscatterdataproxy.cpp +++ b/src/graphs3d/data/qitemmodelscatterdataproxy.cpp @@ -106,6 +106,14 @@ QT_BEGIN_NAMESPACE */ /*! + * \qmlproperty string ItemModelScatterDataProxy::scaleRole + * + * The model may supply the value for scale as either a variant that is + * \c{"x,y,z"}. The first will construct the + * vector3d directly with the given values. + */ + +/*! * \qmlproperty regExp ItemModelScatterDataProxy::xPosRolePattern * * When set, a search and replace is done on the value mapped by the x-position @@ -153,6 +161,17 @@ QT_BEGIN_NAMESPACE */ /*! + * \qmlproperty regExp ItemModelScatterDataProxy::scaleRolePattern + * When set, a search and replace is done on the value mapped by the scale + * role before it is used + * as item scale. This property specifies the regular expression to find the + * portion of the mapped value to replace, and scaleRoleReplace property + * contains the replacement string. + * + * \sa scaleRole, scaleRoleReplace + */ + +/*! * \qmlproperty string ItemModelScatterDataProxy::xPosRoleReplace * * This property defines the replacement content to be used in conjunction with @@ -200,6 +219,17 @@ QT_BEGIN_NAMESPACE */ /*! + * \qmlproperty string ItemModelScatterDataProxy::scaleRoleReplace + * This property defines the replacement content to be used in conjunction with + * scaleRolePattern. Defaults to an empty string. For more information on how + * the search and replace using regular expressions works, see + * the QString::replace(const QRegularExpression &rx, const QString &after) + * function documentation. + * + * \sa scaleRole, scaleRolePattern + */ + +/*! \qmlsignal ItemModelScatterDataProxy::itemModelChanged(model itemModel) This signal is emitted when itemModel changes to \a itemModel. @@ -230,6 +260,12 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlsignal ItemModelScatterDataProxy::scaleRoleChanged(string role) + + This signal is emitted when scaleRole changes to \a role. +*/ + +/*! \qmlsignal ItemModelScatterDataProxy::xPosRolePatternChanged(regExp pattern) This signal is emitted when xPosRolePattern changes to \a pattern. @@ -254,12 +290,24 @@ QT_BEGIN_NAMESPACE */ /*! + \qmlsignal ItemModelScatterDataProxy::scaleRolePatternChanged(regExp pattern) + + This signal is emitted when scaleRolePattern changes to \a pattern. +*/ + +/*! \qmlsignal ItemModelScatterDataProxy::rotationRoleReplaceChanged(string replace) This signal is emitted when rotationRoleReplace changes to \a replace. */ /*! + \qmlsignal ItemModelScatterDataProxy::scaleRoleReplaceChanged(string replace) + + This signal is emitted when scaleRoleReplace changes to \a replace. +*/ + +/*! \qmlsignal ItemModelScatterDataProxy::xPosRoleReplaceChanged(string replace) This signal is emitted when xPosRoleReplace changes to \a replace. @@ -348,6 +396,33 @@ QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemM } /*! + * Constructs QItemModelScatterDataProxy with \a itemModel and an optional \a + * parent. The proxy doesn't take ownership of the \a itemModel, as item models + * are typically owned by other controls. The xPosRole property is set to \a + * xPosRole, the yPosRole property to \a yPosRole, the zPosRole property to \a + * zPosRole, the rotation property to \a rotationRole, and the scale role + * property to \a scaleRole. + */ +QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, + const QString &xPosRole, + const QString &yPosRole, + const QString &zPosRole, + const QString &rotationRole, + const QString &scaleRole, + QObject *parent) + : QScatterDataProxy(*(new QItemModelScatterDataProxyPrivate(this)), parent) +{ + Q_D(QItemModelScatterDataProxy); + d->m_itemModelHandler->setItemModel(itemModel); + d->m_xPosRole = xPosRole; + d->m_yPosRole = yPosRole; + d->m_zPosRole = zPosRole; + d->m_rotationRole = rotationRole; + d->m_scaleRole = scaleRole; + d->connectItemModelHandler(); +} + +/*! * Destroys QItemModelScatterDataProxy. */ QItemModelScatterDataProxy::~QItemModelScatterDataProxy() {} @@ -473,6 +548,30 @@ QString QItemModelScatterDataProxy::rotationRole() const } /*! + * \property QItemModelScatterDataProxy::scaleRole + * + * \brief The item model role to map into item scale. + * + * The model may supply the value for scale as either a variant that is + * \c{"x,y,z"}. The first will construct the + * vector3d directly with the given values. + */ +void QItemModelScatterDataProxy::setScaleRole(const QString &role) +{ + Q_D(QItemModelScatterDataProxy); + if (d->m_scaleRole != role) { + d->m_scaleRole = role; + emit scaleRoleChanged(role); + } +} + +QString QItemModelScatterDataProxy::scaleRole() const +{ + Q_D(const QItemModelScatterDataProxy); + return d->m_scaleRole; +} + +/*! * \property QItemModelScatterDataProxy::xPosRolePattern * * \brief Whether search and replace is done on the value mapped by the x @@ -593,6 +692,33 @@ QRegularExpression QItemModelScatterDataProxy::rotationRolePattern() const } /*! + * \property QItemModelScatterDataProxy::scaleRolePattern + * + * \brief Whether a search and replace is done on the value mapped by the + * scale role before it is used as item scale. + * + * This property specifies the regular expression to find the portion + * of the mapped value to replace and scaleRoleReplace property contains the + * replacement string. + * + * \sa scaleRole, scaleRoleReplace + */ +void QItemModelScatterDataProxy::setScaleRolePattern(const QRegularExpression &pattern) +{ + Q_D(QItemModelScatterDataProxy); + if (d->m_scaleRolePattern != pattern) { + d->m_scaleRolePattern = pattern; + emit scaleRolePatternChanged(pattern); + } +} + +QRegularExpression QItemModelScatterDataProxy::scaleRolePattern() const +{ + Q_D(const QItemModelScatterDataProxy); + return d->m_scaleRolePattern; +} + +/*! * \property QItemModelScatterDataProxy::xPosRoleReplace * * \brief The replace content to be used in conjunction with the x position role @@ -713,17 +839,46 @@ QString QItemModelScatterDataProxy::rotationRoleReplace() const } /*! - * Changes \a xPosRole, \a yPosRole, \a zPosRole, and \a rotationRole mapping. + * \property QItemModelScatterDataProxy::scaleRoleReplace + * + * \brief The replace content to be used in conjunction with the scale role + * pattern. + * + * Defaults to an empty string. For more information on how the search and + * replace using regular expressions works, see QString::replace(const + * QRegularExpression &rx, const QString &after) function documentation. + * + * \sa scaleRole, scaleRolePattern + */ +void QItemModelScatterDataProxy::setScaleRoleReplace(const QString &replace) +{ + Q_D(QItemModelScatterDataProxy); + if (d->m_scaleRoleReplace != replace) { + d->m_scaleRoleReplace = replace; + emit scaleRoleReplaceChanged(replace); + } +} + +QString QItemModelScatterDataProxy::scaleRoleReplace() const +{ + Q_D(const QItemModelScatterDataProxy); + return d->m_scaleRoleReplace; +} + +/*! + * Changes \a xPosRole, \a yPosRole, \a zPosRole, \a rotationRole, and \a scaleRole mapping. */ void QItemModelScatterDataProxy::remap(const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, - const QString &rotationRole) + const QString &rotationRole, + const QString &scaleRole) { setXPosRole(xPosRole); setYPosRole(yPosRole); setZPosRole(zPosRole); setRotationRole(rotationRole); + setScaleRole(scaleRole); } // QItemModelScatterDataProxyPrivate @@ -761,6 +916,10 @@ void QItemModelScatterDataProxyPrivate::connectItemModelHandler() m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(q, + &QItemModelScatterDataProxy::scaleRoleChanged, + m_itemModelHandler, + &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(q, &QItemModelScatterDataProxy::xPosRolePatternChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); @@ -777,6 +936,10 @@ void QItemModelScatterDataProxyPrivate::connectItemModelHandler() m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); QObject::connect(q, + &QItemModelScatterDataProxy::scaleRolePatternChanged, + m_itemModelHandler, + &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(q, &QItemModelScatterDataProxy::xPosRoleReplaceChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); @@ -792,6 +955,10 @@ void QItemModelScatterDataProxyPrivate::connectItemModelHandler() &QItemModelScatterDataProxy::rotationRoleReplaceChanged, m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged); + QObject::connect(q, + &QItemModelScatterDataProxy::scaleRoleReplaceChanged, + m_itemModelHandler, + &AbstractItemModelHandler::handleMappingChanged); } QT_END_NAMESPACE |