summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2014-05-12 12:55:10 +0300
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2014-05-12 13:11:39 +0300
commit3d7f8820a86a4852fe2df27df53b745cfa32eb94 (patch)
tree3c1dabe786e25a23998f8891f96054cc5d69a00d /src
parent4dcef4be656aedb7c6c9e222f291a1a508641007 (diff)
Enable mapping single role to multiple properties for scatter
Task-number: QTRD-3074 Change-Id: I7b1d338d28000eee7563a11a6069453f3e349c16 Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/datavisualization/data/qitemmodelbardataproxy.cpp3
-rw-r--r--src/datavisualization/data/qitemmodelscatterdataproxy.cpp314
-rw-r--r--src/datavisualization/data/qitemmodelscatterdataproxy.h35
-rw-r--r--src/datavisualization/data/qitemmodelscatterdataproxy_p.h10
-rw-r--r--src/datavisualization/data/qitemmodelsurfacedataproxy.cpp3
-rw-r--r--src/datavisualization/data/scatteritemmodelhandler.cpp72
-rw-r--r--src/datavisualization/data/scatteritemmodelhandler_p.h12
-rw-r--r--src/datavisualizationqml2/datavisualizationqml2_plugin.cpp1
8 files changed, 426 insertions, 24 deletions
diff --git a/src/datavisualization/data/qitemmodelbardataproxy.cpp b/src/datavisualization/data/qitemmodelbardataproxy.cpp
index 2351bc25..cccf7d44 100644
--- a/src/datavisualization/data/qitemmodelbardataproxy.cpp
+++ b/src/datavisualization/data/qitemmodelbardataproxy.cpp
@@ -33,6 +33,9 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*
* The data is resolved asynchronously whenever mappings or the model changes.
* QBarDataProxy::arrayReset() is emitted when the data has been resolved.
+ * However, when useModelCategories property is set to true, single item changes are resolved
+ * synchronously, unless the same frame also contains a change that causes the whole model to be
+ * resolved.
*
* There are three ways to use mappings:
*
diff --git a/src/datavisualization/data/qitemmodelscatterdataproxy.cpp b/src/datavisualization/data/qitemmodelscatterdataproxy.cpp
index 16a7b8b5..ad588ab1 100644
--- a/src/datavisualization/data/qitemmodelscatterdataproxy.cpp
+++ b/src/datavisualization/data/qitemmodelscatterdataproxy.cpp
@@ -36,7 +36,7 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* unless the same frame also contains a change that causes the whole model to be resolved.
*
* Mapping ignores rows and columns of the QAbstractItemModel and treats
- * all items equally. It requires the model to provide at least three roles for the data items
+ * all items equally. It requires the model to provide roles for the data items
* that can be mapped to X, Y, and Z-values for the scatter points.
*
* For example, assume that you have a custom QAbstractItemModel for storing various measurements
@@ -45,6 +45,16 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*
* \snippet doc_src_qtdatavisualization.cpp 4
*
+ * If the fields of the model do not contain the data in the exact format you need, you can specify
+ * a search pattern regular expression and a replace rule for each role to get the value in a
+ * format you need. For more information how the replace using regular expressions works, see
+ * QString::replace(const QRegExp &rx, const QString &after) function documentation. Note that
+ * using regular expressions has an impact on the performance, so it's more efficient to utilize
+ * item models where doing search and replace is not necessary to get the desired values.
+ *
+ * For example about using the search patterns in conjunction with the roles, see
+ * ItemModelBarDataProxy usage in \l{Qt Quick 2 Bars Example}.
+ *
* \sa {Qt Data Visualization Data Handling}
*/
@@ -78,27 +88,109 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
/*!
* \qmlproperty string ItemModelScatterDataProxy::xPosRole
- * The X position role of the mapping.
+ * Defines the item model role to map into X position.
*/
/*!
* \qmlproperty string ItemModelScatterDataProxy::yPosRole
- * The Y position role of the mapping.
+ * Defines the item model role to map into Y position.
*/
/*!
* \qmlproperty string ItemModelScatterDataProxy::zPosRole
- * The Z position role of the mapping.
+ * Defines the item model role to map into Z position.
*/
/*!
* \qmlproperty string ItemModelScatterDataProxy::rotationRole
*
- * Defines the rotation role for the mapping.
+ * Defines the item model role to map into item rotation.
* The model may supply the value for rotation as either variant that is directly convertible
- * to QQuaternion, or as one of the string representations: \c{"scalar,x,y,z"} or \c{"@angle,x,y,z"}. The first
- * will construct the quaternion directly with given values, and the second one will construct
- * the quaternion using QQuaternion::fromAxisAndAngle() method.
+ * to QQuaternion, or as one of the string representations: \c{"scalar,x,y,z"} or
+ * \c{"@angle,x,y,z"}. The first format will construct the quaternion directly with given values,
+ * and the second one will construct the quaternion using QQuaternion::fromAxisAndAngle() method.
+ */
+
+/*!
+ * \qmlproperty regExp ItemModelScatterDataProxy::xPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by xPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and xPosRoleReplace property contains the replacement string.
+ *
+ * \sa xPosRole, xPosRoleReplace
+ */
+
+/*!
+ * \qmlproperty regExp ItemModelScatterDataProxy::yPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by yPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and yPosRoleReplace property contains the replacement string.
+ *
+ * \sa yPosRole, yPosRoleReplace
+ */
+
+/*!
+ * \qmlproperty regExp ItemModelScatterDataProxy::zPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by zPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and zPosRoleReplace property contains the replacement string.
+ *
+ * \sa zPosRole, zPosRoleReplace
+ */
+
+/*!
+ * \qmlproperty regExp ItemModelScatterDataProxy::rotationRolePattern
+ * When set, a search and replace is done on the value mapped by rotation role before it is used
+ * as a item rotation. This property specifies the regular expression to find the portion
+ * of the mapped value to replace and rotationRoleReplace property contains the replacement string.
+ *
+ * \sa rotationRole, rotationRoleReplace
+ */
+
+/*!
+ * \qmlproperty string ItemModelScatterDataProxy::xPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with xPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa xPosRole, xPosRolePattern
+ */
+
+/*!
+ * \qmlproperty string ItemModelScatterDataProxy::yPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with yPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa yPosRole, yPosRolePattern
+ */
+
+/*!
+ * \qmlproperty string ItemModelScatterDataProxy::zPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with zPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa zPosRole, zPosRolePattern
+ */
+
+/*!
+ * \qmlproperty string ItemModelScatterDataProxy::rotationRoleReplace
+ * This property defines the replace content to be used in conjunction with rotationRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa rotationRole, rotationRolePattern
*/
/*!
@@ -190,7 +282,7 @@ const QAbstractItemModel *QItemModelScatterDataProxy::itemModel() const
/*!
* \property QItemModelScatterDataProxy::xPosRole
*
- * Defines the X position \a role for the mapping.
+ * Defines the item model role to map into X position.
*/
void QItemModelScatterDataProxy::setXPosRole(const QString &role)
{
@@ -208,7 +300,7 @@ QString QItemModelScatterDataProxy::xPosRole() const
/*!
* \property QItemModelScatterDataProxy::yPosRole
*
- * Defines the Y position \a role for the mapping.
+ * Defines the item model role to map into Y position.
*/
void QItemModelScatterDataProxy::setYPosRole(const QString &role)
{
@@ -226,7 +318,7 @@ QString QItemModelScatterDataProxy::yPosRole() const
/*!
* \property QItemModelScatterDataProxy::zPosRole
*
- * Defines the Z position \a role for the mapping.
+ * Defines the item model role to map into Z position.
*/
void QItemModelScatterDataProxy::setZPosRole(const QString &role)
{
@@ -244,7 +336,7 @@ QString QItemModelScatterDataProxy::zPosRole() const
/*!
* \property QItemModelScatterDataProxy::rotationRole
*
- * Defines the rotation \a role for the mapping.
+ * Defines the item model role to map into item rotation.
*
* The model may supply the value for rotation as either variant that is directly convertible
* to QQuaternion, or as one of the string representations: \c{"scalar,x,y,z"} or \c{"@angle,x,y,z"}.
@@ -265,6 +357,186 @@ QString QItemModelScatterDataProxy::rotationRole() const
}
/*!
+ * \property QItemModelScatterDataProxy::xPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by xPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and xPosRoleReplace property contains the replacement string.
+ *
+ * \sa xPosRole, xPosRoleReplace
+ */
+void QItemModelScatterDataProxy::setXPosRolePattern(const QRegExp &pattern)
+{
+ if (dptr()->m_xPosRolePattern != pattern) {
+ dptr()->m_xPosRolePattern = pattern;
+ emit xPosRolePatternChanged(pattern);
+ }
+}
+
+QRegExp QItemModelScatterDataProxy::xPosRolePattern() const
+{
+ return dptrc()->m_xPosRolePattern;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::yPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by yPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and yPosRoleReplace property contains the replacement string.
+ *
+ * \sa yPosRole, yPosRoleReplace
+ */
+void QItemModelScatterDataProxy::setYPosRolePattern(const QRegExp &pattern)
+{
+ if (dptr()->m_yPosRolePattern != pattern) {
+ dptr()->m_yPosRolePattern = pattern;
+ emit yPosRolePatternChanged(pattern);
+ }
+}
+
+QRegExp QItemModelScatterDataProxy::yPosRolePattern() const
+{
+ return dptrc()->m_yPosRolePattern;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::zPosRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by zPos role before it is used as
+ * a item position value. This property specifies the regular expression to find the portion of the
+ * mapped value to replace and zPosRoleReplace property contains the replacement string.
+ *
+ * \sa zPosRole, zPosRoleReplace
+ */
+void QItemModelScatterDataProxy::setZPosRolePattern(const QRegExp &pattern)
+{
+ if (dptr()->m_zPosRolePattern != pattern) {
+ dptr()->m_zPosRolePattern = pattern;
+ emit zPosRolePatternChanged(pattern);
+ }
+}
+
+QRegExp QItemModelScatterDataProxy::zPosRolePattern() const
+{
+ return dptrc()->m_zPosRolePattern;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::rotationRolePattern
+ *
+ * When set, a search and replace is done on the value mapped by rotation role before it is used
+ * as a item rotation. This property specifies the regular expression to find the portion
+ * of the mapped value to replace and rotationRoleReplace property contains the replacement string.
+ *
+ * \sa rotationRole, rotationRoleReplace
+ */
+void QItemModelScatterDataProxy::setRotationRolePattern(const QRegExp &pattern)
+{
+ if (dptr()->m_rotationRolePattern != pattern) {
+ dptr()->m_rotationRolePattern = pattern;
+ emit rotationRolePatternChanged(pattern);
+ }
+}
+
+QRegExp QItemModelScatterDataProxy::rotationRolePattern() const
+{
+ return dptrc()->m_rotationRolePattern;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::xPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with xPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa xPosRole, xPosRolePattern
+ */
+void QItemModelScatterDataProxy::setXPosRoleReplace(const QString &replace)
+{
+ if (dptr()->m_xPosRoleReplace != replace) {
+ dptr()->m_xPosRoleReplace = replace;
+ emit xPosRoleReplaceChanged(replace);
+ }
+}
+
+QString QItemModelScatterDataProxy::xPosRoleReplace() const
+{
+ return dptrc()->m_xPosRoleReplace;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::yPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with yPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa yPosRole, yPosRolePattern
+ */
+void QItemModelScatterDataProxy::setYPosRoleReplace(const QString &replace)
+{
+ if (dptr()->m_yPosRoleReplace != replace) {
+ dptr()->m_yPosRoleReplace = replace;
+ emit yPosRoleReplaceChanged(replace);
+ }
+}
+
+QString QItemModelScatterDataProxy::yPosRoleReplace() const
+{
+ return dptrc()->m_yPosRoleReplace;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::zPosRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with zPosRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa zPosRole, zPosRolePattern
+ */
+void QItemModelScatterDataProxy::setZPosRoleReplace(const QString &replace)
+{
+ if (dptr()->m_zPosRoleReplace != replace) {
+ dptr()->m_zPosRoleReplace = replace;
+ emit zPosRoleReplaceChanged(replace);
+ }
+}
+
+QString QItemModelScatterDataProxy::zPosRoleReplace() const
+{
+ return dptrc()->m_zPosRoleReplace;
+}
+
+/*!
+ * \property QItemModelScatterDataProxy::rotationRoleReplace
+ *
+ * This property defines the replace content to be used in conjunction with rotationRolePattern.
+ * Defaults to empty string. For more information on how the search and replace using regular
+ * expressions works, see QString::replace(const QRegExp &rx, const QString &after)
+ * function documentation.
+ *
+ * \sa rotationRole, rotationRolePattern
+ */
+void QItemModelScatterDataProxy::setRotationRoleReplace(const QString &replace)
+{
+ if (dptr()->m_rotationRoleReplace != replace) {
+ dptr()->m_rotationRoleReplace = replace;
+ emit rotationRoleReplaceChanged(replace);
+ }
+}
+
+QString QItemModelScatterDataProxy::rotationRoleReplace() const
+{
+ return dptrc()->m_rotationRoleReplace;
+}
+
+/*!
* Changes \a xPosRole, \a yPosRole, \a zPosRole, and \a rotationRole mapping.
*/
void QItemModelScatterDataProxy::remap(const QString &xPosRole, const QString &yPosRole,
@@ -320,6 +592,24 @@ void QItemModelScatterDataProxyPrivate::connectItemModelHandler()
m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
QObject::connect(qptr(), &QItemModelScatterDataProxy::zPosRoleChanged,
m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::rotationRoleChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::xPosRolePatternChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::yPosRolePatternChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::zPosRolePatternChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::rotationRolePatternChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::xPosRoleReplaceChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::yPosRoleReplaceChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::zPosRoleReplaceChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
+ QObject::connect(qptr(), &QItemModelScatterDataProxy::rotationRoleReplaceChanged,
+ m_itemModelHandler, &AbstractItemModelHandler::handleMappingChanged);
}
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/data/qitemmodelscatterdataproxy.h b/src/datavisualization/data/qitemmodelscatterdataproxy.h
index c6d2245d..5c2bbce9 100644
--- a/src/datavisualization/data/qitemmodelscatterdataproxy.h
+++ b/src/datavisualization/data/qitemmodelscatterdataproxy.h
@@ -22,6 +22,7 @@
#include <QtDataVisualization/qscatterdataproxy.h>
#include <QtCore/QAbstractItemModel>
#include <QtCore/QString>
+#include <QtCore/QRegExp>
QT_BEGIN_NAMESPACE_DATAVISUALIZATION
@@ -35,6 +36,14 @@ class QT_DATAVISUALIZATION_EXPORT QItemModelScatterDataProxy : public QScatterDa
Q_PROPERTY(QString yPosRole READ yPosRole WRITE setYPosRole NOTIFY yPosRoleChanged)
Q_PROPERTY(QString zPosRole READ zPosRole WRITE setZPosRole NOTIFY zPosRoleChanged)
Q_PROPERTY(QString rotationRole READ rotationRole WRITE setRotationRole NOTIFY rotationRoleChanged)
+ Q_PROPERTY(QRegExp xPosRolePattern READ xPosRolePattern WRITE setXPosRolePattern NOTIFY xPosRolePatternChanged REVISION 1)
+ Q_PROPERTY(QRegExp yPosRolePattern READ yPosRolePattern WRITE setYPosRolePattern NOTIFY yPosRolePatternChanged REVISION 1)
+ Q_PROPERTY(QRegExp zPosRolePattern READ zPosRolePattern WRITE setZPosRolePattern NOTIFY zPosRolePatternChanged REVISION 1)
+ Q_PROPERTY(QRegExp rotationRolePattern READ rotationRolePattern WRITE setRotationRolePattern NOTIFY rotationRolePatternChanged REVISION 1)
+ Q_PROPERTY(QString xPosRoleReplace READ xPosRoleReplace WRITE setXPosRoleReplace NOTIFY xPosRoleReplaceChanged REVISION 1)
+ Q_PROPERTY(QString yPosRoleReplace READ yPosRoleReplace WRITE setYPosRoleReplace NOTIFY yPosRoleReplaceChanged REVISION 1)
+ Q_PROPERTY(QString zPosRoleReplace READ zPosRoleReplace WRITE setZPosRoleReplace NOTIFY zPosRoleReplaceChanged REVISION 1)
+ Q_PROPERTY(QString rotationRoleReplace READ rotationRoleReplace WRITE setRotationRoleReplace NOTIFY rotationRoleReplaceChanged REVISION 1)
public:
explicit QItemModelScatterDataProxy(QObject *parent = 0);
@@ -63,12 +72,38 @@ public:
void remap(const QString &xPosRole, const QString &yPosRole, const QString &zPosRole,
const QString &rotationRole);
+ void setXPosRolePattern(const QRegExp &pattern);
+ QRegExp xPosRolePattern() const;
+ void setYPosRolePattern(const QRegExp &pattern);
+ QRegExp yPosRolePattern() const;
+ void setZPosRolePattern(const QRegExp &pattern);
+ QRegExp zPosRolePattern() const;
+ void setRotationRolePattern(const QRegExp &pattern);
+ QRegExp rotationRolePattern() const;
+
+ void setXPosRoleReplace(const QString &replace);
+ QString xPosRoleReplace() const;
+ void setYPosRoleReplace(const QString &replace);
+ QString yPosRoleReplace() const;
+ void setZPosRoleReplace(const QString &replace);
+ QString zPosRoleReplace() const;
+ void setRotationRoleReplace(const QString &replace);
+ QString rotationRoleReplace() const;
+
signals:
void itemModelChanged(const QAbstractItemModel* itemModel);
void xPosRoleChanged(const QString &role);
void yPosRoleChanged(const QString &role);
void zPosRoleChanged(const QString &role);
void rotationRoleChanged(const QString &role);
+ Q_REVISION(1) void xPosRolePatternChanged(const QRegExp &pattern);
+ Q_REVISION(1) void yPosRolePatternChanged(const QRegExp &pattern);
+ Q_REVISION(1) void zPosRolePatternChanged(const QRegExp &pattern);
+ Q_REVISION(1) void rotationRolePatternChanged(const QRegExp &pattern);
+ Q_REVISION(1) void rotationRoleReplaceChanged(const QString &replace);
+ Q_REVISION(1) void xPosRoleReplaceChanged(const QString &replace);
+ Q_REVISION(1) void yPosRoleReplaceChanged(const QString &replace);
+ Q_REVISION(1) void zPosRoleReplaceChanged(const QString &replace);
protected:
QItemModelScatterDataProxyPrivate *dptr();
diff --git a/src/datavisualization/data/qitemmodelscatterdataproxy_p.h b/src/datavisualization/data/qitemmodelscatterdataproxy_p.h
index 4e1f321f..733cbb1e 100644
--- a/src/datavisualization/data/qitemmodelscatterdataproxy_p.h
+++ b/src/datavisualization/data/qitemmodelscatterdataproxy_p.h
@@ -54,6 +54,16 @@ private:
QString m_zPosRole;
QString m_rotationRole;
+ QRegExp m_xPosRolePattern;
+ QRegExp m_yPosRolePattern;
+ QRegExp m_zPosRolePattern;
+ QRegExp m_rotationRolePattern;
+
+ QString m_xPosRoleReplace;
+ QString m_yPosRoleReplace;
+ QString m_zPosRoleReplace;
+ QString m_rotationRoleReplace;
+
friend class ScatterItemModelHandler;
friend class QItemModelScatterDataProxy;
};
diff --git a/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp b/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp
index 77f90ed4..94f36ec7 100644
--- a/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp
+++ b/src/datavisualization/data/qitemmodelsurfacedataproxy.cpp
@@ -33,6 +33,9 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*
* Data is resolved asynchronously whenever the mapping or the model changes.
* QSurfaceDataProxy::arrayReset() is emitted when the data has been resolved.
+ * However, when useModelCategories property is set to true, single item changes are resolved
+ * synchronously, unless the same frame also contains a change that causes the whole model to be
+ * resolved.
*
* There are three ways to use mappings:
*
diff --git a/src/datavisualization/data/scatteritemmodelhandler.cpp b/src/datavisualization/data/scatteritemmodelhandler.cpp
index 280f2a23..8b4a6f89 100644
--- a/src/datavisualization/data/scatteritemmodelhandler.cpp
+++ b/src/datavisualization/data/scatteritemmodelhandler.cpp
@@ -29,7 +29,11 @@ ScatterItemModelHandler::ScatterItemModelHandler(QItemModelScatterDataProxy *pro
m_xPosRole(noRoleIndex),
m_yPosRole(noRoleIndex),
m_zPosRole(noRoleIndex),
- m_rotationRole(noRoleIndex)
+ m_rotationRole(noRoleIndex),
+ m_haveXPosPattern(false),
+ m_haveYPosPattern(false),
+ m_haveZPosPattern(false),
+ m_haveRotationPattern(false)
{
}
@@ -134,17 +138,48 @@ void ScatterItemModelHandler::modelPosToScatterItem(int modelRow, int modelColum
QScatterDataItem &item)
{
QModelIndex index = m_itemModel->index(modelRow, modelColumn);
- float xPos(0.0f);
- float yPos(0.0f);
- float zPos(0.0f);
- if (m_xPosRole != noRoleIndex)
- xPos = index.data(m_xPosRole).toFloat();
- if (m_yPosRole != noRoleIndex)
- yPos = index.data(m_yPosRole).toFloat();
- if (m_zPosRole != noRoleIndex)
- zPos = index.data(m_zPosRole).toFloat();
- if (m_rotationRole != noRoleIndex)
- item.setRotation(toQuaternion(index.data(m_rotationRole)));
+ float xPos;
+ float yPos;
+ float zPos;
+ if (m_xPosRole != noRoleIndex) {
+ QVariant xValueVar = index.data(m_xPosRole);
+ if (m_haveXPosPattern)
+ xPos = xValueVar.toString().replace(m_xPosPattern, m_xPosReplace).toFloat();
+ else
+ xPos = xValueVar.toFloat();
+ } else {
+ xPos = 0.0f;
+ }
+ if (m_yPosRole != noRoleIndex) {
+ QVariant yValueVar = index.data(m_yPosRole);
+ if (m_haveYPosPattern)
+ yPos = yValueVar.toString().replace(m_yPosPattern, m_yPosReplace).toFloat();
+ else
+ yPos = yValueVar.toFloat();
+ } else {
+ yPos = 0.0f;
+ }
+ if (m_zPosRole != noRoleIndex) {
+ QVariant zValueVar = index.data(m_zPosRole);
+ if (m_haveZPosPattern)
+ zPos = zValueVar.toString().replace(m_zPosPattern, m_zPosReplace).toFloat();
+ else
+ zPos = zValueVar.toFloat();
+ } else {
+ zPos = 0.0f;
+ }
+ if (m_rotationRole != noRoleIndex) {
+ QVariant rotationVar = index.data(m_rotationRole);
+ if (m_haveRotationPattern) {
+ item.setRotation(
+ toQuaternion(
+ QVariant(rotationVar.toString().replace(m_rotationPattern,
+ m_rotationReplace))));
+ } else {
+ item.setRotation(toQuaternion(rotationVar));
+ }
+ }
+
item.setPosition(QVector3D(xPos, yPos, zPos));
}
@@ -157,6 +192,19 @@ void ScatterItemModelHandler::resolveModel()
return;
}
+ m_xPosPattern = m_proxy->xPosRolePattern();
+ m_yPosPattern = m_proxy->yPosRolePattern();
+ m_zPosPattern = m_proxy->zPosRolePattern();
+ m_rotationPattern = m_proxy->rotationRolePattern();
+ m_xPosReplace = m_proxy->xPosRoleReplace();
+ m_yPosReplace = m_proxy->yPosRoleReplace();
+ m_zPosReplace = m_proxy->zPosRoleReplace();
+ m_rotationReplace = m_proxy->rotationRoleReplace();
+ m_haveXPosPattern = !m_xPosPattern.isEmpty() && m_xPosPattern.isValid();
+ m_haveYPosPattern = !m_yPosPattern.isEmpty() && m_yPosPattern.isValid();
+ m_haveZPosPattern = !m_zPosPattern.isEmpty() && m_zPosPattern.isValid();
+ m_haveRotationPattern = !m_rotationPattern.isEmpty() && m_rotationPattern.isValid();
+
QHash<int, QByteArray> roleHash = m_itemModel->roleNames();
m_xPosRole = roleHash.key(m_proxy->xPosRole().toLatin1(), noRoleIndex);
m_yPosRole = roleHash.key(m_proxy->yPosRole().toLatin1(), noRoleIndex);
diff --git a/src/datavisualization/data/scatteritemmodelhandler_p.h b/src/datavisualization/data/scatteritemmodelhandler_p.h
index 0661d734..817b245d 100644
--- a/src/datavisualization/data/scatteritemmodelhandler_p.h
+++ b/src/datavisualization/data/scatteritemmodelhandler_p.h
@@ -59,6 +59,18 @@ private:
int m_yPosRole;
int m_zPosRole;
int m_rotationRole;
+ QRegExp m_xPosPattern;
+ QRegExp m_yPosPattern;
+ QRegExp m_zPosPattern;
+ QRegExp m_rotationPattern;
+ QString m_xPosReplace;
+ QString m_yPosReplace;
+ QString m_zPosReplace;
+ QString m_rotationReplace;
+ bool m_haveXPosPattern;
+ bool m_haveYPosPattern;
+ bool m_haveZPosPattern;
+ bool m_haveRotationPattern;
};
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
index 09afb6b1..8e89109e 100644
--- a/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
+++ b/src/datavisualizationqml2/datavisualizationqml2_plugin.cpp
@@ -94,6 +94,7 @@ void QtDataVisualizationQml2Plugin::registerTypes(const char *uri)
QLatin1String("Trying to create uncreatable: AbstractGraph3D."));
qmlRegisterType<QItemModelBarDataProxy, 1>(uri, 1, 1, "ItemModelBarDataProxy");
qmlRegisterType<QItemModelSurfaceDataProxy, 1>(uri, 1, 1, "ItemModelSurfaceDataProxy");
+ qmlRegisterType<QItemModelScatterDataProxy, 1>(uri, 1, 1, "ItemModelScatterDataProxy");
// New types
qmlRegisterType<QValue3DAxisFormatter>(uri, 1, 1, "ValueAxis3DFormatter");