PySide6.QtGraphs.QItemModelBarDataProxy

class QItemModelBarDataProxy

Proxy class for presenting data in item models with Q3DBarsWidgetItem . More

Inheritance diagram of PySide6.QtGraphs.QItemModelBarDataProxy

Synopsis

Properties

Methods

Signals

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

QItemModelBarDataProxy allows you to use QAbstractItemModel derived models as a data source for Q3DBarsWidgetItem . It uses the defined mappings to map data from the model to rows, columns, and values of Q3DBarsWidgetItem graph.

The data is resolved asynchronously whenever mappings 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 directly to rows and columns of Q3DBarsWidgetItem , and uses the value returned for Qt::DisplayRole as bar value by default. The value role to be used can be redefined if Qt::DisplayRole is 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 value.

  • 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 for storing various monthly values related to a business. Each item in the model has the roles “year”, “month”, “income”, and “expenses”. You could do the following to display the data in a bar graph:

# By defining row and column categories, you tell the mapping which row and column each item
# belongs to. The categories must match the data stored in the model in the roles you define
# for row and column mapping. In this example we expect "year" role to return four digit year
# and "month" to return three letter designation for the month.
#
# An example of an item in model would be:
# Requested role -> Returned data
# "year" -> "2016" // Matches the first row category, so this item is added to the first row.
# "month" -> "jan" // Matches the first column category, so this item is added as first item in the row.
# "income" -> "12.1"
# "expenses" -> "9.2"
years = QStringList()
months = QStringList()
years << "2016" << "2017" << "2018" << "2019" << "2020" << "2021" << "2022"
months << "jan" << "feb" << "mar" << "apr" << "may" << "jun" << "jul" << "aug" << "sep" << "oct" << "nov" << "dec"
proxy = QItemModelBarDataProxy(customModel,()
                                                           "year", // Row role
                                                           "month", // Column role
                                                           "income", // Value role
                                                           years, // Row categories
                                                           months) # Column categories
#...
# To display different data later, you can simply change the mapping.
proxy.setValueRole("expenses")

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 Simple Bar Graph .

See also

Qt Graphs Data Handling with 3D

class MultiMatchBehavior

Behavior types for multiMatchBehavior property.

Constant

Description

QItemModelBarDataProxy.MultiMatchBehavior.First

The value is taken from the first item in the item model that matches each row/column combination.

QItemModelBarDataProxy.MultiMatchBehavior.Last

The value is taken from the last item in the item model that matches each row/column combination.

QItemModelBarDataProxy.MultiMatchBehavior.Average

The values from all items matching each row/column combination are averaged together and the average is used as the bar value.

QItemModelBarDataProxy.MultiMatchBehavior.Cumulative

The values from all items matching each row/column combination are added together and the total is used as the bar value.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property autoColumnCategoriesᅟ: bool

This property holds Whether column categories are generated automatically..

When set to true, the mapping ignores any explicitly set column categories and overwrites them with automatically generated ones whenever the data from model is resolved. Defaults to true.

Access functions:
property autoRowCategoriesᅟ: bool

This property holds Whether row categories are generated automatically..

When set to true, the mapping ignores any explicitly set row categories and overwrites them with automatically generated ones whenever the data from model is resolved. Defaults to true.

Access functions:
property columnCategoriesᅟ: list of strings

This property holds The column categories for the mapping..

Access functions:
property columnRoleᅟ: str

This property holds The column role for the mapping..

Access functions:
property columnRolePatternᅟ: QRegularExpression

This property holds Whether a search and replace is done on the value mapped by column role before it is used as a column category..

This property specifies the regular expression to find the portion of the mapped value to replace and columnRoleReplace property contains the replacement string. This is useful for example in parsing row and column categories from a single timestamp field in the item model.

Access functions:
property columnRoleReplaceᅟ: str

This property holds The replacement content to be used in conjunction with columnRolePattern ..

Defaults to 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.

Access functions:
property itemModelᅟ: QAbstractItemModel

This property holds The item model..

Access functions:
property multiMatchBehaviorᅟ: QItemModelBarDataProxy.MultiMatchBehavior

This property holds How multiple matches for each row/column combination are handled..

Defaults to Last . The chosen behavior affects both bar value and rotation.

For example, you might have an item model with timestamped data taken at irregular intervals and you want to visualize total value of data items on each day with a bar graph. This can be done by specifying row and column categories so that each bar represents a day, and setting multiMatchBehavior to Cumulative .

Access functions:
property rotationRoleᅟ: str

This property holds The rotation role for the mapping..

Access functions:
property rotationRolePatternᅟ: QRegularExpression

This property holds Whether a search and replace is done on the value mapped by rotation role before it is used as a bar rotation angle..

This property specifies the regular expression to find the portion of the mapped value to replace and rotationRoleReplace property contains the replacement string.

Access functions:
property rotationRoleReplaceᅟ: str

This property holds The replacement 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 QRegularExpression &rx, const QString &after) function documentation.

Access functions:
property rowCategoriesᅟ: list of strings

This property holds The row categories for the mapping..

Access functions:
property rowRoleᅟ: str

This property holds The row role for the mapping..

Access functions:
property rowRolePatternᅟ: QRegularExpression

This property holds Whether a search and replace is performed on the value mapped by row role before it is used as a row category..

This property specifies the regular expression to find the portion of the mapped value to replace and rowRoleReplace property contains the replacement string. This is useful for example in parsing row and column categories from a single timestamp field in the item model.

Access functions:
property rowRoleReplaceᅟ: str

This property holds The replacement content to be used in conjunction with rowRolePattern ..

Defaults to 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.

Access functions:
property useModelCategoriesᅟ: bool

This property holds Whether row and column roles and categories are used for mapping..

When set to true, the mapping ignores row and column roles and categories, and uses the rows and columns from the model instead. Defaults to false.

Access functions:
property valueRoleᅟ: str

This property holds The value role for the mapping..

Access functions:
property valueRolePatternᅟ: QRegularExpression

This property holds Whether a search and replace is done on the value mapped by value role before it is used as a bar value..

This property specifies the regular expression to find the portion of the mapped value to replace and valueRoleReplace property contains the replacement string.

Access functions:
property valueRoleReplaceᅟ: str

This property holds The replacement content to be used in conjunction with valueRolePattern ..

Defaults to 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.

Access functions:
__init__([parent=None])
Parameters:

parentQObject

Constructs QItemModelBarDataProxy with an optional parent.

__init__(itemModel[, parent=None])
Parameters:

Constructs QItemModelBarDataProxy 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__(itemModel, valueRole[, parent=None])
Parameters:

Constructs QItemModelBarDataProxy 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 value role is set to valueRole. 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__(itemModel, rowRole, columnRole, valueRole[, parent=None])
Parameters:

Constructs QItemModelBarDataProxy 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 valueRole.

__init__(itemModel, rowRole, columnRole, valueRole, rotationRole[, parent=None])
Parameters:
  • itemModelQAbstractItemModel

  • rowRole – str

  • columnRole – str

  • valueRole – str

  • rotationRole – str

  • parentQObject

Constructs QItemModelBarDataProxy 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, valueRole, and rotationRole.

__init__(itemModel, rowRole, columnRole, valueRole, rowCategories, columnCategories[, parent=None])
Parameters:
  • itemModelQAbstractItemModel

  • rowRole – str

  • columnRole – str

  • valueRole – str

  • rowCategories – list of strings

  • columnCategories – list of strings

  • parentQObject

Constructs QItemModelBarDataProxy 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 valueRole. Row and column categories are set with rowCategories and columnCategories. This constructor also sets autoRowCategories and autoColumnCategories to false.

__init__(itemModel, rowRole, columnRole, valueRole, rotationRole, rowCategories, columnCategories[, parent=None])
Parameters:
  • itemModelQAbstractItemModel

  • rowRole – str

  • columnRole – str

  • valueRole – str

  • rotationRole – str

  • rowCategories – list of strings

  • columnCategories – list of strings

  • parentQObject

Constructs QItemModelBarDataProxy 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, valueRole, and rotationRole. Row and column categories are set with rowCategories and columnCategories. This constructor also sets autoRowCategories and autoColumnCategories to false.

autoColumnCategories()
Return type:

bool

Getter of property autoColumnCategoriesᅟ .

autoColumnCategoriesChanged(enable)
Parameters:

enable – bool

Notification signal of property autoColumnCategoriesᅟ .

autoRowCategories()
Return type:

bool

Getter of property autoRowCategoriesᅟ .

autoRowCategoriesChanged(enable)
Parameters:

enable – bool

Notification signal of property autoRowCategoriesᅟ .

columnCategories()
Return type:

list of strings

Getter of property columnCategoriesᅟ .

columnCategoriesChanged()

Notification signal of property columnCategoriesᅟ .

columnCategoryIndex(category)
Parameters:

category – str

Return type:

int

Returns the index of the specified category in 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()
Return type:

str

See also

setColumnRole()

Getter of property columnRoleᅟ .

columnRoleChanged(role)
Parameters:

role – str

Notification signal of property columnRoleᅟ .

columnRolePattern()
Return type:

QRegularExpression

Getter of property columnRolePatternᅟ .

columnRolePatternChanged(pattern)
Parameters:

patternQRegularExpression

Notification signal of property columnRolePatternᅟ .

columnRoleReplace()
Return type:

str

Getter of property columnRoleReplaceᅟ .

columnRoleReplaceChanged(replace)
Parameters:

replace – str

Notification signal of property columnRoleReplaceᅟ .

itemModel()
Return type:

QAbstractItemModel

See also

setItemModel()

Getter of property itemModelᅟ .

itemModelChanged(itemModel)
Parameters:

itemModelQAbstractItemModel

Notification signal of property itemModelᅟ .

multiMatchBehavior()
Return type:

MultiMatchBehavior

Getter of property multiMatchBehaviorᅟ .

multiMatchBehaviorChanged(behavior)
Parameters:

behaviorMultiMatchBehavior

Notification signal of property multiMatchBehaviorᅟ .

remap(rowRole, columnRole, valueRole, rotationRole, rowCategories, columnCategories)
Parameters:
  • rowRole – str

  • columnRole – str

  • valueRole – str

  • rotationRole – str

  • rowCategories – list of strings

  • columnCategories – list of strings

Changes rowRole, columnRole, valueRole, rotationRole, rowCategories and columnCategories to the mapping.

rotationRole()
Return type:

str

Getter of property rotationRoleᅟ .

rotationRoleChanged(role)
Parameters:

role – str

Notification signal of property rotationRoleᅟ .

rotationRolePattern()
Return type:

QRegularExpression

Getter of property rotationRolePatternᅟ .

rotationRolePatternChanged(pattern)
Parameters:

patternQRegularExpression

Notification signal of property rotationRolePatternᅟ .

rotationRoleReplace()
Return type:

str

Getter of property rotationRoleReplaceᅟ .

rotationRoleReplaceChanged(replace)
Parameters:

replace – str

Notification signal of property rotationRoleReplaceᅟ .

rowCategories()
Return type:

list of strings

Getter of property rowCategoriesᅟ .

rowCategoriesChanged()

Notification signal of property rowCategoriesᅟ .

rowCategoryIndex(category)
Parameters:

category – str

Return type:

int

Returns the index of the specified category in 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()
Return type:

str

See also

setRowRole()

Getter of property rowRoleᅟ .

rowRoleChanged(role)
Parameters:

role – str

Notification signal of property rowRoleᅟ .

rowRolePattern()
Return type:

QRegularExpression

Getter of property rowRolePatternᅟ .

rowRolePatternChanged(pattern)
Parameters:

patternQRegularExpression

Notification signal of property rowRolePatternᅟ .

rowRoleReplace()
Return type:

str

Getter of property rowRoleReplaceᅟ .

rowRoleReplaceChanged(replace)
Parameters:

replace – str

Notification signal of property rowRoleReplaceᅟ .

setAutoColumnCategories(enable)
Parameters:

enable – bool

Setter of property autoColumnCategoriesᅟ .

setAutoRowCategories(enable)
Parameters:

enable – bool

Setter of property autoRowCategoriesᅟ .

setColumnCategories(categories)
Parameters:

categories – list of strings

Setter of property columnCategoriesᅟ .

setColumnRole(role)
Parameters:

role – str

See also

columnRole()

Setter of property columnRoleᅟ .

setColumnRolePattern(pattern)
Parameters:

patternQRegularExpression

Setter of property columnRolePatternᅟ .

setColumnRoleReplace(replace)
Parameters:

replace – str

Setter of property columnRoleReplaceᅟ .

setItemModel(itemModel)
Parameters:

itemModelQAbstractItemModel

Sets the item model to itemModel. Does not take ownership of the model, but does connect to it to listen for changes.

See also

itemModel()

Setter of property itemModelᅟ .

setMultiMatchBehavior(behavior)
Parameters:

behaviorMultiMatchBehavior

Setter of property multiMatchBehaviorᅟ .

setRotationRole(role)
Parameters:

role – str

See also

rotationRole()

Setter of property rotationRoleᅟ .

setRotationRolePattern(pattern)
Parameters:

patternQRegularExpression

Setter of property rotationRolePatternᅟ .

setRotationRoleReplace(replace)
Parameters:

replace – str

Setter of property rotationRoleReplaceᅟ .

setRowCategories(categories)
Parameters:

categories – list of strings

See also

rowCategories()

Setter of property rowCategoriesᅟ .

setRowRole(role)
Parameters:

role – str

See also

rowRole()

Setter of property rowRoleᅟ .

setRowRolePattern(pattern)
Parameters:

patternQRegularExpression

See also

rowRolePattern()

Setter of property rowRolePatternᅟ .

setRowRoleReplace(replace)
Parameters:

replace – str

See also

rowRoleReplace()

Setter of property rowRoleReplaceᅟ .

setUseModelCategories(enable)
Parameters:

enable – bool

Setter of property useModelCategoriesᅟ .

setValueRole(role)
Parameters:

role – str

See also

valueRole()

Setter of property valueRoleᅟ .

setValueRolePattern(pattern)
Parameters:

patternQRegularExpression

Setter of property valueRolePatternᅟ .

setValueRoleReplace(replace)
Parameters:

replace – str

Setter of property valueRoleReplaceᅟ .

useModelCategories()
Return type:

bool

Getter of property useModelCategoriesᅟ .

useModelCategoriesChanged(enable)
Parameters:

enable – bool

Notification signal of property useModelCategoriesᅟ .

valueRole()
Return type:

str

See also

setValueRole()

Getter of property valueRoleᅟ .

valueRoleChanged(role)
Parameters:

role – str

Notification signal of property valueRoleᅟ .

valueRolePattern()
Return type:

QRegularExpression

Getter of property valueRolePatternᅟ .

valueRolePatternChanged(pattern)
Parameters:

patternQRegularExpression

Notification signal of property valueRolePatternᅟ .

valueRoleReplace()
Return type:

str

Getter of property valueRoleReplaceᅟ .

valueRoleReplaceChanged(replace)
Parameters:

replace – str

Notification signal of property valueRoleReplaceᅟ .