QItemModelBarDataProxy

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

Inheritance diagram of PySide6.QtDataVisualization.QItemModelBarDataProxy

Synopsis

Functions

Detailed Description

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

The data is resolved asynchronously whenever mappings or the model changes. 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 Q3DBars , and uses the value returned for DisplayRole as bar value by default. The value role to be used can be redefined if 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 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" -> "2006" // 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"
QStringList years;
QStringList months;
years << "2006" << "2007" << "2008" << "2009" << "2010" << "2011" << "2012";
months << "jan" << "feb" << "mar" << "apr" << "may" << "jun" << "jul" << "aug" << "sep" << "oct" << "nov" << "dec";

QItemModelBarDataProxy *proxy = new QItemModelBarDataProxy(customModel,
                                                           QStringLiteral("year"), // Row role
                                                           QStringLiteral("month"), // Column role
                                                           QStringLiteral("income"), // Value role
                                                           years, // Row categories
                                                           months); // Column categories

//...

// To display different data later, you can simply change the mapping.
proxy->setValueRole(QStringLiteral("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 how the replace using regular expressions works, see 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 Qt Quick 2 Bars Example .

class PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel, rowRole, columnRole, valueRole[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel, rowRole, columnRole, valueRole, rotationRole[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel, rowRole, columnRole, valueRole, rotationRole, rowCategories, columnCategories[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel, rowRole, columnRole, valueRole, rowCategories, columnCategories[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy(itemModel, valueRole[, parent=None])

PySide6.QtDataVisualization.QItemModelBarDataProxy([parent=None])

Parameters

Constructs QItemModelBarDataProxy with itemModel and optional parent. Proxy doesn’t take ownership of the itemModel, as typically item models are owned by other controls.

Constructs QItemModelBarDataProxy with itemModel and optional parent. 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.

Constructs QItemModelBarDataProxy with itemModel and optional parent. 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.

Constructs QItemModelBarDataProxy with itemModel and optional parent. 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.

Constructs QItemModelBarDataProxy with itemModel and optional parent. 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.

Constructs QItemModelBarDataProxy with itemModel and optional parent. 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.

Constructs QItemModelBarDataProxy with optional parent.

PySide6.QtDataVisualization.QItemModelBarDataProxy.MultiMatchBehavior

Behavior types for multiMatchBehavior property.

Constant

Description

QItemModelBarDataProxy.MMBFirst

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

QItemModelBarDataProxy.MMBLast

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

QItemModelBarDataProxy.MMBAverage

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

QItemModelBarDataProxy.MMBCumulative

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

PySide6.QtDataVisualization.QItemModelBarDataProxy.autoColumnCategories()
Return type

bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.autoColumnCategoriesChanged(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.autoRowCategories()
Return type

bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.autoRowCategoriesChanged(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnCategories()
Return type

list of strings

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnCategoriesChanged()
PySide6.QtDataVisualization.QItemModelBarDataProxy.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.

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRole()
Return type

str

See also

setColumnRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRoleChanged(role)
Parameters

role – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRolePattern()
Return type

PySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRolePatternChanged(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRoleReplace()
Return type

str

PySide6.QtDataVisualization.QItemModelBarDataProxy.columnRoleReplaceChanged(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.itemModel()
Return type

PySide6.QtCore.QAbstractItemModel

See also

setItemModel()

PySide6.QtDataVisualization.QItemModelBarDataProxy.itemModelChanged(itemModel)
Parameters

itemModelPySide6.QtCore.QAbstractItemModel

PySide6.QtDataVisualization.QItemModelBarDataProxy.multiMatchBehavior()
Return type

MultiMatchBehavior

PySide6.QtDataVisualization.QItemModelBarDataProxy.multiMatchBehaviorChanged(behavior)
Parameters

behaviorMultiMatchBehavior

PySide6.QtDataVisualization.QItemModelBarDataProxy.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.

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRole()
Return type

str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRoleChanged(role)
Parameters

role – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRolePattern()
Return type

PySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRolePatternChanged(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRoleReplace()
Return type

str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rotationRoleReplaceChanged(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowCategories()
Return type

list of strings

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowCategoriesChanged()
PySide6.QtDataVisualization.QItemModelBarDataProxy.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.

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRole()
Return type

str

See also

setRowRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRoleChanged(role)
Parameters

role – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRolePattern()
Return type

PySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRolePatternChanged(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRoleReplace()
Return type

str

PySide6.QtDataVisualization.QItemModelBarDataProxy.rowRoleReplaceChanged(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.setAutoColumnCategories(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.setAutoRowCategories(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.setColumnCategories(categories)
Parameters

categories – list of strings

PySide6.QtDataVisualization.QItemModelBarDataProxy.setColumnRole(role)
Parameters

role – str

See also

columnRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setColumnRolePattern(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.setColumnRoleReplace(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.setItemModel(itemModel)
Parameters

itemModelPySide6.QtCore.QAbstractItemModel

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()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setMultiMatchBehavior(behavior)
Parameters

behaviorMultiMatchBehavior

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRotationRole(role)
Parameters

role – str

See also

rotationRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRotationRolePattern(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRotationRoleReplace(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRowCategories(categories)
Parameters

categories – list of strings

See also

rowCategories()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRowRole(role)
Parameters

role – str

See also

rowRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRowRolePattern(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

See also

rowRolePattern()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setRowRoleReplace(replace)
Parameters

replace – str

See also

rowRoleReplace()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setUseModelCategories(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.setValueRole(role)
Parameters

role – str

See also

valueRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.setValueRolePattern(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.setValueRoleReplace(replace)
Parameters

replace – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.useModelCategories()
Return type

bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.useModelCategoriesChanged(enable)
Parameters

enable – bool

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRole()
Return type

str

See also

setValueRole()

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRoleChanged(role)
Parameters

role – str

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRolePattern()
Return type

PySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRolePatternChanged(pattern)
Parameters

patternPySide6.QtCore.QRegularExpression

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRoleReplace()
Return type

str

PySide6.QtDataVisualization.QItemModelBarDataProxy.valueRoleReplaceChanged(replace)
Parameters

replace – str