QItemModelSurfaceDataProxy — PyQt Documentation v6.9.0 (original) (raw)
PyQt6.QtGraphs.QItemModelSurfaceDataProxy
Inherits from QSurfaceDataProxy.
Description¶
Proxy class for presenting data in item models with Q3DSurfaceWidgetItem.
QItemModelSurfaceDataProxy allows you to use QAbstractItemModel derived models as a data source for Q3DSurfaceWidgetItem. It uses the defined mappings to map data from the model to rows, columns, and surface points of Q3DSurfaceWidgetItem graph.
Data is resolved asynchronously whenever the mapping or the model changes. 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.
Mappings can be used in the following ways:
- If useModelCategories() property is set to
true
, this proxy will map rows and columns of QAbstractItemModel to rows and columns of Q3DSurfaceWidgetItem, and uses the value returned for DisplayRole as Y-position by default. Row and column headers are used for Z-position and X-position by default, if they can be converted to floats. Otherwise row and column indices are used. The Y-position role to be used can be redefined if DisplayRole is not suitable. The Z-position and X-position roles to be used can be redefined if the headers or indices are not suitable. - For models that do not have data already neatly sorted into rows and columns, such as QAbstractListModel based models, you can define a role from the model to map for each of the row, column and Y-position.
- If you do not want to include all data contained in the model, or the autogenerated rows and columns are not ordered as you wish, you can specify which rows and columns should be included and in which order by defining an explicit list of categories for either or both of rows and columns.
For example, assume that you have a custom QAbstractItemModel storing surface topography data. Each item in the model has the roles “longitude”, “latitude”, and “height”. The item model already contains the data properly sorted so that longitudes and latitudes are first encountered in correct order, which enables us to utilize the row and column category autogeneration. You could do the following to display the data in a surface graph:
QItemModelSurfaceDataProxy *proxy = new QItemModelSurfaceDataProxy(customModel,
QStringLiteral("longitude"), // Row role
QStringLiteral("latitude"), // Column role
QStringLiteral("height")); // Y-position role
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 on how the replacement using regular expressions works, see QString::replace(const QRegularExpression &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 Simple Bar Graph.
Enums¶
MultiMatchBehavior
Behavior types for multiMatchBehavior() property.
Member | Value | Description |
---|---|---|
Average | 2 | The position values from all items matching each row/column combination are averaged together and the averages are used as the surface point position. |
CumulativeY | 3 | For X and Z values this acts just like Average, but Y values are added together instead of averaged and the total is used as the surface point Y position. |
First | 0 | The position values are taken from the first item in the item model that matches each row/column combination. |
Last | 1 | The position values are taken from the last item in the item model that matches each row/column combination. |
Methods¶
__init__(parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with an optional parent.
__init__(QAbstractItemModel, parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls.
__init__(QAbstractItemModel, Optional[str], parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls. The yPosRole() role is set to yPosRole. This constructor is meant to be used with models that have data properly sorted in rows and columns already, so it also sets useModelCategories() property to true
.
__init__(QAbstractItemModel, Optional[str], Optional[str], Optional[str], parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls. The role mappings are set with rowRole, columnRole, and yPosRole. The zPosRole() and the xPosRole() are set to rowRole and columnRole, respectively.
__init__(QAbstractItemModel, Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls. The role mappings are set with rowRole, columnRole, xPosRole, yPosRole, and zPosRole.
__init__(QAbstractItemModel, Optional[str], Optional[str], Optional[str], Iterable[Optional[str]], Iterable[Optional[str]], parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls. The role mappings are set with rowRole, columnRole, and yPosRole. The zPosRole() and the xPosRole() are set to rowRole and columnRole, respectively. Row and column categories are set with rowCategories and columnCategories. This constructor also sets autoRowCategories() and autoColumnCategories() to false.
__init__(QAbstractItemModel, Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Iterable[Optional[str]], Iterable[Optional[str]], parent: QObject = None)
Constructs QItemModelSurfaceDataProxy with itemModel and an optional parent. The proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls. The role mappings are set with rowRole, columnRole, xPosRole, yPosRole, and zPosRole. Row and column categories are set with rowCategories and columnCategories. This constructor also sets autoRowCategories() and autoColumnCategories() to false.
autoColumnCategories() → bool
autoRowCategories() → bool
columnCategories() → list[str]
columnCategoryIndex(Optional[str]) → int
Returns the index of the specified category in the column categories list. If the category is not found, -1 is returned.
Note: If the automatic column categories generation is in use, this method will not return a valid index before the data in the model is resolved for the first time.
columnRole() → str
See also
columnRolePattern() → QRegularExpression
columnRoleReplace() → str
itemModel() → QAbstractItemModel
multiMatchBehavior() → MultiMatchBehavior
remap(Optional[str], Optional[str], Optional[str], Optional[str], Optional[str], Iterable[Optional[str]], Iterable[Optional[str]])
Changes rowRole, columnRole, xPosRole, yPosRole, zPosRole, rowCategories and columnCategories to the mapping.
rowCategories() → list[str]
See also
rowCategoryIndex(Optional[str]) → int
Returns the index of the specified category in the row categories list. If the row categories list is empty, -1 is returned.
Note: If the automatic row categories generation is in use, this method will not return a valid index before the data in the model is resolved for the first time.
rowRole() → str
rowRolePattern() → QRegularExpression
See also
rowRoleReplace() → str
See also
setAutoColumnCategories(bool)
setAutoRowCategories(bool)
See also
setColumnCategories(Iterable[Optional[str]])
See also
setColumnRole(Optional[str])
setColumnRolePattern(QRegularExpression)
See also
setColumnRoleReplace(Optional[str])
See also
setItemModel(QAbstractItemModel)
Sets the item model to itemModel. Does not take ownership of the model, but does connect to it to listen for changes.
setMultiMatchBehavior(MultiMatchBehavior)
See also
setRowCategories(Iterable[Optional[str]])
See also
setRowRole(Optional[str])
setRowRolePattern(QRegularExpression)
See also
setRowRoleReplace(Optional[str])
See also
setUseModelCategories(bool)
See also
setXPosRole(Optional[str])
setXPosRolePattern(QRegularExpression)
See also
setXPosRoleReplace(Optional[str])
See also
setYPosRole(Optional[str])
setYPosRolePattern(QRegularExpression)
See also
setYPosRoleReplace(Optional[str])
See also
setZPosRole(Optional[str])
setZPosRolePattern(QRegularExpression)
See also
setZPosRoleReplace(Optional[str])
See also
useModelCategories() → bool
xPosRole() → str
xPosRolePattern() → QRegularExpression
See also
xPosRoleReplace() → str
See also
yPosRole() → str
yPosRolePattern() → QRegularExpression
See also
yPosRoleReplace() → str
See also
zPosRole() → str
zPosRolePattern() → QRegularExpression
See also
zPosRoleReplace() → str
See also
Signals¶
autoColumnCategoriesChanged(bool)
TODO
autoRowCategoriesChanged(bool)
TODO
columnCategoriesChanged()
TODO
columnRoleChanged(Optional[str])
TODO
columnRolePatternChanged(QRegularExpression)
TODO
columnRoleReplaceChanged(Optional[str])
TODO
itemModelChanged(QAbstractItemModel)
TODO
multiMatchBehaviorChanged(MultiMatchBehavior)
TODO
rowCategoriesChanged()
TODO
rowRoleChanged(Optional[str])
TODO
rowRolePatternChanged(QRegularExpression)
TODO
rowRoleReplaceChanged(Optional[str])
TODO
useModelCategoriesChanged(bool)
TODO
xPosRoleChanged(Optional[str])
TODO
xPosRolePatternChanged(QRegularExpression)
TODO
xPosRoleReplaceChanged(Optional[str])
TODO
yPosRoleChanged(Optional[str])
TODO
yPosRolePatternChanged(QRegularExpression)
TODO
yPosRoleReplaceChanged(Optional[str])
TODO
zPosRoleChanged(Optional[str])
TODO
zPosRolePatternChanged(QRegularExpression)
TODO
zPosRoleReplaceChanged(Optional[str])
TODO