don't remapp all roles each time, keep the old ones, with the same role number/name mapping: avoids role shuffle after an update
svn path=/trunk/KDE/kdebase/runtime/; revision=1216034
This commit is contained in:
parent
ccf35dd608
commit
45c6ac7dfb
@ -125,7 +125,8 @@ void SortFilterModel::setSortOrder(const Qt::SortOrder order)
|
||||
|
||||
DataModel::DataModel(QObject* parent)
|
||||
: QAbstractItemModel(parent),
|
||||
m_dataSource(0)
|
||||
m_dataSource(0),
|
||||
m_maxRoleId(Qt::UserRole)
|
||||
{
|
||||
setObjectName("DataModel");
|
||||
connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
|
||||
@ -217,21 +218,21 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list)
|
||||
m_items[sourceName] = list.toVector();
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
int role = Qt::UserRole;
|
||||
m_roleNames.clear();
|
||||
m_roleIds.clear();
|
||||
|
||||
if (list.first().canConvert<QVariantHash>()) {
|
||||
foreach (const QString& roleName, list.first().value<QVariantHash>().keys()) {
|
||||
++role;
|
||||
m_roleNames[role] = roleName.toLatin1();
|
||||
m_roleIds[roleName] = role;
|
||||
if (!m_roleIds.contains(roleName)) {
|
||||
++m_maxRoleId;
|
||||
m_roleNames[m_maxRoleId] = roleName.toLatin1();
|
||||
m_roleIds[roleName] = m_maxRoleId;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (const QString& roleName, list.first().value<QVariantMap>().keys()) {
|
||||
++role;
|
||||
m_roleNames[role] = roleName.toLatin1();
|
||||
m_roleIds[roleName] = role;
|
||||
if (!m_roleIds.contains(roleName)) {
|
||||
++m_maxRoleId;
|
||||
m_roleNames[m_maxRoleId] = roleName.toLatin1();
|
||||
m_roleIds[roleName] = m_maxRoleId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ private:
|
||||
QMap<QString, QVector<QVariant> > m_items;
|
||||
QHash<int, QByteArray> m_roleNames;
|
||||
QHash<QString, int> m_roleIds;
|
||||
int m_maxRoleId;
|
||||
};
|
||||
|
||||
int DataModel::countItems() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user