Proxy class for presenting data in item models with Q3DBars . 更多...
头: | #include <QItemModelBarDataProxy> |
qmake: | QT += datavisualization |
Since: | QtDataVisualization 1.0 |
实例化: | ItemModelBarDataProxy |
继承: | QBarDataProxy |
该类在 QtDataVisualization 1.0 引入。
enum | MultiMatchBehavior { MMBFirst, MMBLast, MMBAverage, MMBCumulative } |
|
|
QItemModelBarDataProxy (QAbstractItemModel * itemModel , const QString & rowRole , const QString & columnRole , const QString & valueRole , const QString & rotationRole , const QStringList & rowCategories , const QStringList & columnCategories , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QAbstractItemModel * itemModel , const QString & rowRole , const QString & columnRole , const QString & valueRole , const QStringList & rowCategories , const QStringList & columnCategories , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QAbstractItemModel * itemModel , const QString & rowRole , const QString & columnRole , const QString & valueRole , const QString & rotationRole , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QAbstractItemModel * itemModel , const QString & rowRole , const QString & columnRole , const QString & valueRole , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QAbstractItemModel * itemModel , const QString & valueRole , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QAbstractItemModel * itemModel , QObject * parent = nullptr) | |
QItemModelBarDataProxy (QObject * parent = nullptr) | |
virtual | ~QItemModelBarDataProxy () |
bool | autoColumnCategories () const |
bool | autoRowCategories () const |
QStringList | columnCategories () const |
int | columnCategoryIndex (const QString & category ) |
QString | columnRole () const |
QRegExp | columnRolePattern () const |
QString | columnRoleReplace () const |
QAbstractItemModel * | itemModel () const |
QItemModelBarDataProxy::MultiMatchBehavior | multiMatchBehavior () const |
void | remap (const QString & rowRole , const QString & columnRole , const QString & valueRole , const QString & rotationRole , const QStringList & rowCategories , const QStringList & columnCategories ) |
QString | rotationRole () const |
QRegExp | rotationRolePattern () const |
QString | rotationRoleReplace () const |
QStringList | rowCategories () const |
int | rowCategoryIndex (const QString & category ) |
QString | rowRole () const |
QRegExp | rowRolePattern () const |
QString | rowRoleReplace () const |
void | setAutoColumnCategories (bool enable ) |
void | setAutoRowCategories (bool enable ) |
void | setColumnCategories (const QStringList & categories ) |
void | setColumnRole (const QString & role ) |
void | setColumnRolePattern (const QRegExp & pattern ) |
void | setColumnRoleReplace (const QString & replace ) |
void | setItemModel (QAbstractItemModel * itemModel ) |
void | setMultiMatchBehavior (QItemModelBarDataProxy::MultiMatchBehavior behavior ) |
void | setRotationRole (const QString & role ) |
void | setRotationRolePattern (const QRegExp & pattern ) |
void | setRotationRoleReplace (const QString & replace ) |
void | setRowCategories (const QStringList & categories ) |
void | setRowRole (const QString & role ) |
void | setRowRolePattern (const QRegExp & pattern ) |
void | setRowRoleReplace (const QString & replace ) |
void | setUseModelCategories (bool enable ) |
void | setValueRole (const QString & role ) |
void | setValueRolePattern (const QRegExp & pattern ) |
void | setValueRoleReplace (const QString & replace ) |
bool | useModelCategories () const |
QString | valueRole () const |
QRegExp | valueRolePattern () const |
QString | valueRoleReplace () const |
void | autoColumnCategoriesChanged (bool enable ) |
void | autoRowCategoriesChanged (bool enable ) |
void | columnCategoriesChanged () |
void | columnRoleChanged (const QString & role ) |
void | columnRolePatternChanged (const QRegExp & pattern ) |
void | columnRoleReplaceChanged (const QString & replace ) |
void | itemModelChanged (const QAbstractItemModel * itemModel ) |
void | multiMatchBehaviorChanged (QItemModelBarDataProxy::MultiMatchBehavior behavior ) |
void | rotationRoleChanged (const QString & role ) |
void | rotationRolePatternChanged (const QRegExp & pattern ) |
void | rotationRoleReplaceChanged (const QString & replace ) |
void | rowCategoriesChanged () |
void | rowRoleChanged (const QString & role ) |
void | rowRolePatternChanged (const QRegExp & pattern ) |
void | rowRoleReplaceChanged (const QString & replace ) |
void | useModelCategoriesChanged (bool enable ) |
void | valueRoleChanged (const QString & role ) |
void | valueRolePatternChanged (const QRegExp & pattern ) |
void | valueRoleReplaceChanged (const QString & replace ) |
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. 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.
Mappings can be used in the following ways:
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 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 Qt Quick 2 Bars Example .
另请参阅 Qt Data Visualization 数据处理 .
Behavior types for QItemModelBarDataProxy::multiMatchBehavior 特性。
常量 | 值 | 描述 |
---|---|---|
QItemModelBarDataProxy::MMBFirst
|
0
|
The value is taken from the first item in the item model that matches each row/column combination. |
QItemModelBarDataProxy::MMBLast
|
1
|
The value is taken from the last item in the item model that matches each row/column combination. |
QItemModelBarDataProxy::MMBAverage
|
2
|
The values from all items matching each row/column combination are averaged together and the average is used as the bar value. |
QItemModelBarDataProxy::MMBCumulative
|
3
|
The values from all items matching each row/column combination are added together and the total is used as the bar value. |
This property holds whether column categories are generated automatically.
当设为
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
.
访问函数:
bool | autoColumnCategories () const |
void | setAutoColumnCategories (bool enable ) |
通知程序信号:
void | autoColumnCategoriesChanged (bool enable ) |
This property holds whether row categories are generated automatically.
当设为
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
.
访问函数:
bool | autoRowCategories () const |
void | setAutoRowCategories (bool enable ) |
通知程序信号:
void | autoRowCategoriesChanged (bool enable ) |
This property holds the column categories for the mapping.
访问函数:
QStringList | columnCategories () const |
void | setColumnCategories (const QStringList & categories ) |
通知程序信号:
void | columnCategoriesChanged () |
This property holds the column role for the mapping.
访问函数:
QString | columnRole () const |
void | setColumnRole (const QString & role ) |
通知程序信号:
void | columnRoleChanged (const QString & role ) |
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.
访问函数:
QRegExp | columnRolePattern () const |
void | setColumnRolePattern (const QRegExp & pattern ) |
通知程序信号:
void | columnRolePatternChanged (const QRegExp & pattern ) |
另请参阅 columnRole and columnRoleReplace .
This property holds the replace 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 QRegExp &rx, const QString &after) function documentation.
访问函数:
QString | columnRoleReplace () const |
void | setColumnRoleReplace (const QString & replace ) |
通知程序信号:
void | columnRoleReplaceChanged (const QString & replace ) |
另请参阅 columnRole and columnRolePattern .
This property holds the item model.
访问函数:
QAbstractItemModel * | itemModel () const |
void | setItemModel (QAbstractItemModel * itemModel ) |
通知程序信号:
void | itemModelChanged (const QAbstractItemModel * itemModel ) |
How multiple matches for each row/column combination are handled.
默认为 QItemModelBarDataProxy::MMBLast . 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 QItemModelBarDataProxy::MMBCumulative .
访问函数:
QItemModelBarDataProxy::MultiMatchBehavior | multiMatchBehavior () const |
void | setMultiMatchBehavior (QItemModelBarDataProxy::MultiMatchBehavior behavior ) |
通知程序信号:
void | multiMatchBehaviorChanged (QItemModelBarDataProxy::MultiMatchBehavior behavior ) |
This property holds the rotation role for the mapping.
访问函数:
QString | rotationRole () const |
void | setRotationRole (const QString & role ) |
通知程序信号:
void | rotationRoleChanged (const QString & role ) |
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.
访问函数:
QRegExp | rotationRolePattern () const |
void | setRotationRolePattern (const QRegExp & pattern ) |
通知程序信号:
void | rotationRolePatternChanged (const QRegExp & pattern ) |
另请参阅 rotationRole and rotationRoleReplace .
This property holds 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.
访问函数:
QString | rotationRoleReplace () const |
void | setRotationRoleReplace (const QString & replace ) |
通知程序信号:
void | rotationRoleReplaceChanged (const QString & replace ) |
另请参阅 rotationRole and rotationRolePattern .
This property holds the row categories for the mapping.
访问函数:
QStringList | rowCategories () const |
void | setRowCategories (const QStringList & categories ) |
通知程序信号:
void | rowCategoriesChanged () |
This property holds the row role for the mapping.
访问函数:
QString | rowRole () const |
void | setRowRole (const QString & role ) |
通知程序信号:
void | rowRoleChanged (const QString & role ) |
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.
访问函数:
QRegExp | rowRolePattern () const |
void | setRowRolePattern (const QRegExp & pattern ) |
通知程序信号:
void | rowRolePatternChanged (const QRegExp & pattern ) |
另请参阅 rowRole and rowRoleReplace .
This property holds the replace 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 QRegExp &rx, const QString &after) function documentation.
访问函数:
QString | rowRoleReplace () const |
void | setRowRoleReplace (const QString & replace ) |
通知程序信号:
void | rowRoleReplaceChanged (const QString & replace ) |
另请参阅 rowRole and rowRolePattern .
This property holds whether row and column roles and categories are used for mapping.
当设为
true
, the mapping ignores row and column roles and categories, and uses the rows and columns from the model instead. Defaults to
false
.
访问函数:
bool | useModelCategories () const |
void | setUseModelCategories (bool enable ) |
通知程序信号:
void | useModelCategoriesChanged (bool enable ) |
This property holds the value role for the mapping.
访问函数:
QString | valueRole () const |
void | setValueRole (const QString & role ) |
通知程序信号:
void | valueRoleChanged (const QString & role ) |
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.
访问函数:
QRegExp | valueRolePattern () const |
void | setValueRolePattern (const QRegExp & pattern ) |
通知程序信号:
void | valueRolePatternChanged (const QRegExp & pattern ) |
另请参阅 valueRole and valueRoleReplace .
This property holds the replace 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 QRegExp &rx, const QString &after) function documentation.
访问函数:
QString | valueRoleReplace () const |
void | setValueRoleReplace (const QString & replace ) |
通知程序信号:
void | valueRoleReplaceChanged (const QString & replace ) |
另请参阅 valueRole and valueRolePattern .
Constructs QItemModelBarDataProxy with itemModel 和可选 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 ,和 rotationRole . Row and column categories are set with rowCategories and columnCategories . This constructor also sets autoRowCategories and autoColumnCategories 为 false。
Constructs QItemModelBarDataProxy with itemModel 和可选 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 . Row and column categories are set with rowCategories and columnCategories . This constructor also sets autoRowCategories and autoColumnCategories 为 false。
Constructs QItemModelBarDataProxy with itemModel 和可选 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 ,和 rotationRole .
Constructs QItemModelBarDataProxy with itemModel 和可选 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 .
Constructs QItemModelBarDataProxy with itemModel 和可选 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 特性为 true。
Constructs QItemModelBarDataProxy with itemModel 和可选 parent . Proxy doesn't take ownership of the itemModel , as typically item models are owned by other controls.
Constructs QItemModelBarDataProxy with optional parent .
[虚拟]
QItemModelBarDataProxy::
~QItemModelBarDataProxy
()
Returns the index of the specified category in column categories list. If the category is not found, -1 is returned.
注意: 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.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
变化 rowRole , columnRole , valueRole , rotationRole , rowCategories and columnCategories to the mapping.
Returns the index of the specified category in row categories list. If the row categories list is empty, -1 is returned.
注意: 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.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
Sets the item model to itemModel . Does not take ownership of the model, but does connect to it to listen for changes.
注意: setter 函数对于特性 itemModel .
另请参阅 itemModel ().