fix: emit modelReset signal after a ProxyRole changes its name
refactor proxy roles tests
This commit is contained in:
parent
dc154fd46b
commit
7a2e70b980
|
@ -21,6 +21,7 @@ void ProxyRole::setName(const QString& name)
|
|||
if (m_name == name)
|
||||
return;
|
||||
|
||||
Q_EMIT nameAboutToBeChanged();
|
||||
m_name = name;
|
||||
Q_EMIT nameChanged();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ protected:
|
|||
void invalidate();
|
||||
|
||||
Q_SIGNALS:
|
||||
void nameAboutToBeChanged();
|
||||
void nameChanged();
|
||||
void invalidated();
|
||||
|
||||
|
|
|
@ -377,7 +377,6 @@ void QQmlSortFilterProxyModel::resetInternalData()
|
|||
m_roleNames[maxRole] = proxyRole->name().toUtf8();
|
||||
m_proxyRoleMap[maxRole] = proxyRole;
|
||||
m_proxyRoleNumbers.append(maxRole);
|
||||
connect(proxyRole, &ProxyRole::invalidated, this, &QQmlSortFilterProxyModel::emitProxyRolesChanged, Qt::UniqueConnection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -516,6 +515,9 @@ void QQmlSortFilterProxyModel::append_proxyRole(QQmlListProperty<ProxyRole>* lis
|
|||
return;
|
||||
|
||||
auto that = static_cast<QQmlSortFilterProxyModel*>(list->object);
|
||||
connect(proxyRole, &ProxyRole::invalidated, that, &QQmlSortFilterProxyModel::emitProxyRolesChanged);
|
||||
connect(proxyRole, &ProxyRole::nameAboutToBeChanged, that, &QQmlSortFilterProxyModel::beginResetModel);
|
||||
connect(proxyRole, &ProxyRole::nameChanged, that, &QQmlSortFilterProxyModel::endResetModel);
|
||||
that->beginResetModel();
|
||||
that->m_proxyRoles.append(proxyRole);
|
||||
that->endResetModel();
|
||||
|
|
|
@ -34,6 +34,11 @@ Item {
|
|||
name: "staticRole"
|
||||
value: "foo"
|
||||
},
|
||||
StaticRole {
|
||||
id: renameRole
|
||||
name: "renameMe"
|
||||
value: "test"
|
||||
},
|
||||
SourceIndexRole {
|
||||
name: "sourceIndexRole"
|
||||
}
|
||||
|
@ -52,16 +57,30 @@ Item {
|
|||
TestCase {
|
||||
name: "ProxyRoles"
|
||||
|
||||
function test_proxyRole() {
|
||||
function test_resetAfterNameChange() {
|
||||
var oldObject = instantiator.object;
|
||||
renameRole.name = "foobarRole";
|
||||
var newObject = instantiator.object;
|
||||
verify(newObject !== oldObject, "Instantiator object should have been reinstantiated");
|
||||
}
|
||||
|
||||
function test_proxyRoleInvalidation() {
|
||||
compare(instantiator.object.staticRole, "foo");
|
||||
staticRole.value = "bar";
|
||||
compare(instantiator.object.staticRole, "bar");
|
||||
}
|
||||
|
||||
function test_proxyRoleGetDataFromSource() {
|
||||
compare(instantiator.object.sourceIndexRole, 0);
|
||||
compare(testModel.get(1, "sourceIndexRole"), 1);
|
||||
listModel.setProperty(1, "keep", false);
|
||||
compare(testModel.get(1, "sourceIndexRole"), 2);
|
||||
}
|
||||
|
||||
function test_filterFromProxyRole() {
|
||||
staticRole.value = "filterMe";
|
||||
compare(testModel.count, 0)
|
||||
staticRole.value = "foo";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue