fix: Allow filters to filters on proxy roles
This commit is contained in:
parent
5b071c9526
commit
c81dcafc35
|
@ -212,7 +212,7 @@ void QQmlSortFilterProxyModel::componentComplete()
|
|||
|
||||
QVariant QQmlSortFilterProxyModel::sourceData(const QModelIndex& sourceIndex, const QString& roleName) const
|
||||
{
|
||||
int role = sourceModel()->roleNames().key(roleName.toUtf8());
|
||||
int role = roleNames().key(roleName.toUtf8());
|
||||
return sourceData(sourceIndex, role);
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,8 @@ void QQmlSortFilterProxyModel::sourceDataChanged(const QModelIndex& topLeft, con
|
|||
|
||||
void QQmlSortFilterProxyModel::emitProxyRolesChanged()
|
||||
{
|
||||
Q_EMIT dataChanged(index(0, 0), index(rowCount()-1, columnCount()-1), m_proxyRoleMap.keys().toVector());
|
||||
invalidate();
|
||||
Q_EMIT dataChanged(index(0,0), index(rowCount() - 1, columnCount() - 1), m_proxyRoleMap.keys().toVector());
|
||||
}
|
||||
|
||||
QVariantMap QQmlSortFilterProxyModel::modelDataMap(const QModelIndex& modelIndex) const
|
||||
|
|
|
@ -16,14 +16,21 @@ Item {
|
|||
SortFilterProxyModel {
|
||||
id: testModel
|
||||
sourceModel: listModel
|
||||
filters: ValueFilter {
|
||||
roleName: "keep"
|
||||
value: true
|
||||
}
|
||||
filters: [
|
||||
ValueFilter {
|
||||
roleName: "keep"
|
||||
value: true
|
||||
},
|
||||
ValueFilter {
|
||||
inverted: true
|
||||
roleName: "staticRole"
|
||||
value: "filterMe"
|
||||
}
|
||||
]
|
||||
|
||||
proxyRoles: [
|
||||
StaticRole {
|
||||
id: proxyRole
|
||||
id: staticRole
|
||||
name: "staticRole"
|
||||
value: "foo"
|
||||
},
|
||||
|
@ -47,12 +54,14 @@ Item {
|
|||
|
||||
function test_proxyRole() {
|
||||
compare(instantiator.object.staticRole, "foo");
|
||||
proxyRole.value = "bar";
|
||||
staticRole.value = "bar";
|
||||
compare(instantiator.object.staticRole, "bar");
|
||||
compare(instantiator.object.sourceIndexRole, 0);
|
||||
compare(testModel.get(1, "sourceIndexRole"), 1);
|
||||
listModel.setProperty(1, "keep", false);
|
||||
compare(testModel.get(1, "sourceIndexRole"), 2);
|
||||
staticRole.value = "filterMe";
|
||||
compare(testModel.count, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue