Fix QSIM::itemData returning role 255
Before this fix, QStandardItemModel::itemData returns a map containing role 255 which is used internally to store the flags. This role is an undocumented implementation detail so it should not be returned to the user. [ChangeLog][QtGui][QStandardItemModel] itemData does not return role 255 Change-Id: Ibead3cba84cfe92b3c664bc8ce87508cbcbdc9bd Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
c88305b68d
commit
dc73a691bf
@ -306,8 +306,11 @@ const QMap<int, QVariant> QStandardItemPrivate::itemData() const
|
||||
{
|
||||
QMap<int, QVariant> result;
|
||||
QVector<QStandardItemData>::const_iterator it;
|
||||
for (it = values.begin(); it != values.end(); ++it)
|
||||
result.insert((*it).role, (*it).value);
|
||||
for (it = values.cbegin(); it != values.cend(); ++it){
|
||||
// Qt::UserRole - 1 is used internally to store the flags
|
||||
if (it->role != Qt::UserRole - 1)
|
||||
result.insert(it->role, it->value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2939,8 +2942,10 @@ bool QStandardItemModel::insertRows(int row, int count, const QModelIndex &paren
|
||||
QMap<int, QVariant> QStandardItemModel::itemData(const QModelIndex &index) const
|
||||
{
|
||||
Q_D(const QStandardItemModel);
|
||||
QStandardItem *item = d->itemFromIndex(index);
|
||||
return item ? item->d_func()->itemData() : QMap<int, QVariant>();
|
||||
const QStandardItem *const item = d->itemFromIndex(index);
|
||||
if (!item || item == d->root.data())
|
||||
return QMap<int, QVariant>();
|
||||
return item->d_func()->itemData();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -750,7 +750,11 @@ void tst_QStandardItemModel::data()
|
||||
|
||||
QCOMPARE(m_model->data(m_model->index(0, 0), Qt::DisplayRole).toString(), QLatin1String("initialitem"));
|
||||
QCOMPARE(m_model->data(m_model->index(0, 0), Qt::ToolTipRole).toString(), QLatin1String("tooltip"));
|
||||
|
||||
const QMap<int, QVariant> itmData = m_model->itemData(m_model->index(0, 0));
|
||||
QCOMPARE(itmData.value(Qt::DisplayRole), QLatin1String("initialitem"));
|
||||
QCOMPARE(itmData.value(Qt::ToolTipRole), QLatin1String("tooltip"));
|
||||
QVERIFY(!itmData.contains(Qt::UserRole - 1));
|
||||
QVERIFY(m_model->itemData(QModelIndex()).isEmpty());
|
||||
}
|
||||
|
||||
void tst_QStandardItemModel::clearItemData()
|
||||
|
Loading…
Reference in New Issue
Block a user