QItemModelScatterDataProxy Class
用于在项目模型中通过Q3DScatter 呈现数据的代理类。更多内容...
| 头文件: | #include <QItemModelScatterDataProxy> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS DataVisualization) target_link_libraries(mytarget PRIVATE Qt6::DataVisualization) |
| qmake: | QT += datavisualization |
| 自: | QtDataVisualization 1.0 |
| 在 QML 中: | ItemModelScatterDataProxy |
| 继承自: | QScatterDataProxy |
| 状态: | 已弃用 |
该类已弃用。我们强烈建议不要在新代码中使用它。
属性
|
|
公共函数
| QItemModelScatterDataProxy(QObject *parent = nullptr) | |
| QItemModelScatterDataProxy(QAbstractItemModel *itemModel, QObject *parent = nullptr) | |
| QItemModelScatterDataProxy(QAbstractItemModel *itemModel, const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, QObject *parent = nullptr) | |
| QItemModelScatterDataProxy(QAbstractItemModel *itemModel, const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, const QString &rotationRole, QObject *parent = nullptr) | |
| virtual | ~QItemModelScatterDataProxy() |
| QAbstractItemModel * | itemModel() const |
| void | remap(const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, const QString &rotationRole) |
| QString | rotationRole() const |
| QRegularExpression | rotationRolePattern() const |
| QString | rotationRoleReplace() const |
| void | setItemModel(QAbstractItemModel *itemModel) |
| void | setRotationRole(const QString &role) |
| void | setRotationRolePattern(const QRegularExpression &pattern) |
| void | setRotationRoleReplace(const QString &replace) |
| void | setXPosRole(const QString &role) |
| void | setXPosRolePattern(const QRegularExpression &pattern) |
| void | setXPosRoleReplace(const QString &replace) |
| void | setYPosRole(const QString &role) |
| void | setYPosRolePattern(const QRegularExpression &pattern) |
| void | setYPosRoleReplace(const QString &replace) |
| void | setZPosRole(const QString &role) |
| void | setZPosRolePattern(const QRegularExpression &pattern) |
| void | setZPosRoleReplace(const QString &replace) |
| QString | xPosRole() const |
| QRegularExpression | xPosRolePattern() const |
| QString | xPosRoleReplace() const |
| QString | yPosRole() const |
| QRegularExpression | yPosRolePattern() const |
| QString | yPosRoleReplace() const |
| QString | zPosRole() const |
| QRegularExpression | zPosRolePattern() const |
| QString | zPosRoleReplace() const |
信号
| void | itemModelChanged(const QAbstractItemModel *itemModel) |
| void | rotationRoleChanged(const QString &role) |
| void | rotationRolePatternChanged(const QRegularExpression &pattern) |
| void | rotationRoleReplaceChanged(const QString &replace) |
| void | xPosRoleChanged(const QString &role) |
| void | xPosRolePatternChanged(const QRegularExpression &pattern) |
| void | xPosRoleReplaceChanged(const QString &replace) |
| void | yPosRoleChanged(const QString &role) |
| void | yPosRolePatternChanged(const QRegularExpression &pattern) |
| void | yPosRoleReplaceChanged(const QString &replace) |
| void | zPosRoleChanged(const QString &role) |
| void | zPosRolePatternChanged(const QRegularExpression &pattern) |
| void | zPosRoleReplaceChanged(const QString &replace) |
详细说明
QItemModelScatterDataProxy 允许您将继承自QAbstractItemModel 的模型用作Q3DScatter 的数据源。它将QAbstractItemModel 的角色映射到Q3DScatter 中点的XYZ值。
每当映射或模型发生变化时,数据都会异步解析。数据解析完成后会触发QScatterDataProxy::arrayReset()事件。但是,模型初始化后的插入、移除以及单个数据项的更改将同步解析,除非同一帧中还包含导致整个模型被解析的更改。
映射会忽略 `QAbstractItemModel ` 的行和列,并将所有项一视同仁。它要求模型为数据项提供角色,这些角色可映射为散点图中点的 X、Y 和 Z 值。
例如,假设您有一个自定义的QAbstractItemModel ,用于存储对材料样本进行的各种测量数据,并为“密度”、“硬度”和“导电率”等角色提供数据。您可以使用以下代理在散点图上可视化这些属性:
// Map "density" value to X-axis, "hardness" to Y-axis and "conductivity" to Z-axis.
QItemModelScatterDataProxy *proxy = new QItemModelScatterDataProxy(customModel,
QStringLiteral("density"),
QStringLiteral("hardness"),
QStringLiteral("conductivity"));如果模型的字段中数据格式与您的需求不完全匹配,您可以为每个角色指定一个搜索模式正则表达式和一条替换规则,以将值转换为您所需的格式。 有关使用正则表达式进行替换的更多信息,请参阅QString::replace (constQRegularExpression &rx, constQString &after)函数文档。请注意,使用正则表达式会影响性能,因此,在无需通过搜索和替换即可获得所需值的情况下,使用项模型会更高效。
关于将搜索模式与角色结合使用的示例,请参阅ItemModelBarDataProxy 在“简单柱状图”示例中的应用。
另请参阅 Qt Data Visualization 数据处理。
属性文档
itemModel : QAbstractItemModel*
此属性保存将用作 3D 散点系列数据源的项目模型。
访问函数:
| QAbstractItemModel * | itemModel() const |
| void | setItemModel(QAbstractItemModel *itemModel) |
通知信号:
| void | itemModelChanged(const QAbstractItemModel *itemModel) |
rotationRole : QString
该属性承担项目模型角色,用于映射到项目轮换。
该模型可提供两种形式的旋转值:一种是可直接转换为QQuaternion 的变体,另一种是以下字符串表示形式之一:"scalar,x,y,z" 或"@angle,x,y,z" 。前者将直接使用给定值构建四元数,后者则通过QQuaternion::fromAxisAndAngle()方法构建四元数。
访问函数:
| QString | rotationRole() const |
| void | setRotationRole(const QString &role) |
通知信号:
| void | rotationRoleChanged(const QString &role) |
rotationRolePattern : QRegularExpression
该属性用于指定在将旋转角色映射的值用作项目旋转之前,是否对其进行搜索和替换操作。
该属性指定用于查找映射值中待替换部分的正则表达式,而rotationRoleReplace 属性则包含替换字符串。
访问函数:
| QRegularExpression | rotationRolePattern() const |
| void | setRotationRolePattern(const QRegularExpression &pattern) |
通知器信号:
| void | rotationRolePatternChanged(const QRegularExpression &pattern) |
另请参阅 rotationRole 和rotationRoleReplace 。
rotationRoleReplace : QString
该属性用于存储与“rotation”角色模式配合使用的替换内容。
默认值为空字符串。有关使用正则表达式进行搜索和替换的更多信息,请参阅QString::replace (constQRegularExpression &rx, constQString &after)函数文档。
访问函数:
| QString | rotationRoleReplace() const |
| void | setRotationRoleReplace(const QString &replace) |
通知器信号:
| void | rotationRoleReplaceChanged(const QString &replace) |
另请参阅 rotationRole 和rotationRolePattern 。
xPosRole : QString
该属性承担项目模型的角色,用于映射到 X 坐标位置。
访问函数:
| QString | xPosRole() const |
| void | setXPosRole(const QString &role) |
通知器信号:
| void | xPosRoleChanged(const QString &role) |
xPosRolePattern : QRegularExpression
此属性控制是否在将 x 位置角色映射的值用作项目位置值之前,对其进行搜索和替换操作。
该属性指定用于查找映射值中待替换部分的正则表达式,而xPosRoleReplace 属性则包含替换字符串。
访问函数:
| QRegularExpression | xPosRolePattern() const |
| void | setXPosRolePattern(const QRegularExpression &pattern) |
通知信号:
| void | xPosRolePatternChanged(const QRegularExpression &pattern) |
另请参阅 xPosRole 和xPosRoleReplace 。
xPosRoleReplace : QString
该属性用于存储与“x 位置”角色模式配合使用的替换内容。
默认值为空字符串。有关使用正则表达式进行搜索和替换的更多信息,请参阅QString::replace (constQRegularExpression &rx, constQString &after)函数文档。
访问函数:
| QString | xPosRoleReplace() const |
| void | setXPosRoleReplace(const QString &replace) |
通知器信号:
| void | xPosRoleReplaceChanged(const QString &replace) |
另请参阅 xPosRole 和xPosRolePattern 。
yPosRole : QString
该属性承担项目模型的角色,用于映射到 Y 位置。
访问函数:
| QString | yPosRole() const |
| void | setYPosRole(const QString &role) |
通知器信号:
| void | yPosRoleChanged(const QString &role) |
yPosRolePattern : QRegularExpression
该属性控制是否在将由 y 位置角色映射的值用作项目位置值之前,对其进行搜索和替换操作。
该属性指定用于查找映射值中待替换部分的正则表达式,而yPosRoleReplace 属性包含替换字符串。
访问函数:
| QRegularExpression | yPosRolePattern() const |
| void | setYPosRolePattern(const QRegularExpression &pattern) |
通知信号:
| void | yPosRolePatternChanged(const QRegularExpression &pattern) |
另请参阅 yPosRole 和yPosRoleReplace 。
yPosRoleReplace : QString
该属性存储将与 y 位置角色模式配合使用的替换内容。
默认值为空字符串。有关使用正则表达式进行搜索和替换的更多信息,请参阅QString::replace(constQRegularExpression &rx, constQString &after) 函数文档。
访问函数:
| QString | yPosRoleReplace() const |
| void | setYPosRoleReplace(const QString &replace) |
通知器信号:
| void | yPosRoleReplaceChanged(const QString &replace) |
另请参阅 yPosRole 和yPosRolePattern 。
zPosRole : QString
该属性承担项目模型的角色,用于映射到 Z 位置。
访问函数:
| QString | zPosRole() const |
| void | setZPosRole(const QString &role) |
通知信号:
| void | zPosRoleChanged(const QString &role) |
zPosRolePattern : QRegularExpression
该属性用于指定在将 z 位置角色映射的值用作项目位置值之前,是否对其进行搜索和替换。
该属性指定用于查找映射值中待替换部分的正则表达式,而zPosRoleReplace 属性则包含替换字符串。
访问函数:
| QRegularExpression | zPosRolePattern() const |
| void | setZPosRolePattern(const QRegularExpression &pattern) |
通知信号:
| void | zPosRolePatternChanged(const QRegularExpression &pattern) |
另请参阅 zPosRole 和zPosRoleReplace 。
zPosRoleReplace : QString
该属性存储将与 z 位置角色模式配合使用的替换内容。
默认值为空字符串。有关使用正则表达式进行搜索和替换的更多信息,请参阅QString::replace(constQRegularExpression &rx, constQString &after) 函数文档。
访问函数:
| QString | zPosRoleReplace() const |
| void | setZPosRoleReplace(const QString &replace) |
通知器信号:
| void | zPosRoleReplaceChanged(const QString &replace) |
另请参阅 zPosRole 和zPosRolePattern 。
成员函数文档
[explicit] QItemModelScatterDataProxy::QItemModelScatterDataProxy(QObject *parent = nullptr)
使用可选的parent 构造 QItemModelScatterDataProxy。
[explicit] QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, QObject *parent = nullptr)
使用itemModel 以及可选的parent 来构建QItemModelScatterDataProxy。该代理不会拥有itemModel 的所有权,因为通常项模型由其他控件拥有。
[explicit] QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, QObject *parent = nullptr)
使用itemModel 以及可选的parent 来构造QItemModelScatterDataProxy。该代理不会拥有itemModel 的所有权,因为通常项模型由其他控件拥有。将xPosRole 属性设置为xPosRole ,yPosRole 属性设置为yPosRole ,zPosRole 属性设置为zPosRole 。
[explicit] QItemModelScatterDataProxy::QItemModelScatterDataProxy(QAbstractItemModel *itemModel, const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, const QString &rotationRole, QObject *parent = nullptr)
使用itemModel 以及可选的parent 来构建QItemModelScatterDataProxy。该代理不会拥有itemModel 的所有权,因为通常项目模型由其他控件拥有。将xPosRole 属性设置为xPosRole ,yPosRole 属性设置为yPosRole ,zPosRole 属性设置为zPosRole ,rotationRole 属性设置为rotationRole 。
[virtual noexcept] QItemModelScatterDataProxy::~QItemModelScatterDataProxy()
销毁QItemModelScatterDataProxy 。
void QItemModelScatterDataProxy::remap(const QString &xPosRole, const QString &yPosRole, const QString &zPosRole, const QString &rotationRole)
更改了xPosRole 、yPosRole 、zPosRole 和rotationRole 的映射关系。
void QItemModelScatterDataProxy::setItemModel(QAbstractItemModel *itemModel)
将itemModel 设置为Q3DScatter的项模型。不会获取该模型的所有权,但会与其建立连接以监听变化。
注意: 这是属性itemModel 的设置 函数。
另请参阅 itemModel()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.