dataengine based models set their roles when setting the data, so respond to that
syncRoleNames is fast (and faster now that we check that the role names actually changed) but it may be nicer to find a more efficient way in future than checking the role names on all / any data changes. in fact, the documentation for QAbstractItemModel::setRoleNames says: "This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour." BUG:308101
This commit is contained in:
parent
a518f3bb6e
commit
19a7d82ed9
@ -38,6 +38,7 @@ SortFilterModel::SortFilterModel(QObject* parent)
|
||||
this, SIGNAL(countChanged()));
|
||||
connect(this, SIGNAL(modelReset()),
|
||||
this, SIGNAL(countChanged()));
|
||||
connect(this, SIGNAL(countChanged()), this, SLOT(syncRoleNames()));
|
||||
}
|
||||
|
||||
SortFilterModel::~SortFilterModel()
|
||||
@ -46,6 +47,10 @@ SortFilterModel::~SortFilterModel()
|
||||
|
||||
void SortFilterModel::syncRoleNames()
|
||||
{
|
||||
if (!sourceModel() || sourceModel()->roleNames() == roleNames()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_roleIds.clear();
|
||||
|
||||
setRoleNames(sourceModel()->roleNames());
|
||||
@ -85,9 +90,6 @@ void SortFilterModel::setModel(QAbstractItemModel* model)
|
||||
emit sourceModelChanged(model);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SortFilterModel::setFilterRegExp(const QString &exp)
|
||||
{
|
||||
if (exp == filterRegExp()) {
|
||||
@ -366,8 +368,6 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRoleNames(m_roleNames);
|
||||
}
|
||||
|
||||
setRoleNames(m_roleNames);
|
||||
|
Loading…
Reference in New Issue
Block a user