make work both VariantMaps and QVariantHash
svn path=/trunk/KDE/kdebase/runtime/; revision=1190034
This commit is contained in:
parent
7ec308a228
commit
a780189547
@ -105,10 +105,18 @@ void DataModel::setItems(const QVariantList &list)
|
|||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
int role = Qt::UserRole;
|
int role = Qt::UserRole;
|
||||||
m_roleNames.clear();
|
m_roleNames.clear();
|
||||||
|
|
||||||
|
if (list.first().canConvert<QVariantHash>()) {
|
||||||
|
foreach (QString roleName, list.first().value<QVariantHash>().keys()) {
|
||||||
|
++role;
|
||||||
|
m_roleNames[role] = roleName.toLatin1();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
foreach (QString roleName, list.first().value<QVariantMap>().keys()) {
|
foreach (QString roleName, list.first().value<QVariantMap>().keys()) {
|
||||||
++role;
|
++role;
|
||||||
m_roleNames[role] = roleName.toLatin1();
|
m_roleNames[role] = roleName.toLatin1();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
setRoleNames(m_roleNames);
|
setRoleNames(m_roleNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +132,12 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_items.value(index.row()).canConvert<QVariantHash>()) {
|
||||||
|
return m_items.value(index.row()).value<QVariantHash>().value(m_roleNames.value(role));
|
||||||
|
} else {
|
||||||
return m_items.value(index.row()).value<QVariantMap>().value(m_roleNames.value(role));
|
return m_items.value(index.row()).value<QVariantMap>().value(m_roleNames.value(role));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QVariant DataModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant DataModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user