From 19a7d82ed945deac439951c4d75bf66aede350ab Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Tue, 9 Oct 2012 11:17:03 +0200 Subject: [PATCH] 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 --- declarativeimports/core/datamodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/declarativeimports/core/datamodel.cpp b/declarativeimports/core/datamodel.cpp index e3610da86..80974893f 100644 --- a/declarativeimports/core/datamodel.cpp +++ b/declarativeimports/core/datamodel.cpp @@ -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);