mirror of https://github.com/qt/qtbase.git
QAIM: add internally used role values to Qt::ItemDataRole enum
Some Qt models use role values below Qt::UserRole for special purposes.
To avoid that we keep reusing the same value for different models and
potentially cause conflicts across modules (which might already be a
problem when Qt RemoteObject's QAIM wrapper is used on a
QStandardItemModel or QFileSystemModel, as both use
Qt::UserRole - 1), add those values to the Qt::ItemDataRole enum, but
omit them from the documentation.
Not included in this change are the Qt::UserRole + 1/2/3 values we use
in QFileSystemModel for FilePath/Name/Permissions roles. We won't use
role values above Qt::UserRole in Qt in the future.
Use these enum values then internally where we currently hardcode the
values. Pick this back to 6.10 to avoid conflicts. This is not an API
addition.
Amends, at least, 6e8563fb2d
.
Pick-to: 6.10
Change-Id: I6cd93c32b5c6709355b6f048f9d6d574421d6fbb
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
16d9ed713a
commit
26c24bae77
|
@ -1529,7 +1529,12 @@ namespace Qt {
|
|||
StatusTipPropertyRole = 30,
|
||||
WhatsThisPropertyRole = 31,
|
||||
// Reserved
|
||||
UserRole = 0x0100
|
||||
UserRole = 0x0100,
|
||||
|
||||
// Used by Qt models
|
||||
StandardItemFlagsRole = UserRole - 1, // QStandardItemModel
|
||||
FileInfoRole = UserRole - 4, // QFileSystemModel
|
||||
RemoteObjectsCacheRole = UserRole - 1, // QtRemoteObjects::QAbstractItemModelReplica
|
||||
};
|
||||
|
||||
enum ItemFlag {
|
||||
|
|
|
@ -2827,6 +2827,9 @@
|
|||
\omitvalue ToolTipPropertyRole
|
||||
\omitvalue StatusTipPropertyRole
|
||||
\omitvalue WhatsThisPropertyRole
|
||||
\omitvalue StandardItemFlagsRole
|
||||
\omitvalue FileInfoRole
|
||||
\omitvalue RemoteObjectsCacheRole
|
||||
|
||||
For user roles, it is up to the developer to decide which types to use and ensure that
|
||||
components use the correct types when accessing and setting data.
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
enum Roles {
|
||||
FileIconRole = Qt::DecorationRole,
|
||||
|
||||
FileInfoRole = Qt::UserRole - 4, // New values go before, -5, -6 ..etc
|
||||
FileInfoRole = Qt::FileInfoRole, // New values go before, -5, -6 ..etc
|
||||
QT7_ONLY(
|
||||
FilePathRole = Qt::UserRole - 3,
|
||||
FileNameRole = Qt::UserRole - 2,
|
||||
|
|
|
@ -18,11 +18,6 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
// Used internally to store the flags
|
||||
namespace {
|
||||
constexpr auto DataFlagsRole = Qt::ItemDataRole(Qt::UserRole - 1);
|
||||
}
|
||||
|
||||
static inline QString qStandardItemModelDataListMimeType()
|
||||
{
|
||||
return QStringLiteral("application/x-qstandarditemmodeldatalist");
|
||||
|
@ -283,7 +278,7 @@ QMap<int, QVariant> QStandardItemPrivate::itemData() const
|
|||
{
|
||||
QMap<int, QVariant> result;
|
||||
for (const auto &data : values) {
|
||||
if (data.role != DataFlagsRole)
|
||||
if (data.role != Qt::StandardItemFlagsRole)
|
||||
result.insert(data.role, data.value);
|
||||
}
|
||||
return result;
|
||||
|
@ -996,7 +991,7 @@ void QStandardItem::emitDataChanged()
|
|||
*/
|
||||
void QStandardItem::setFlags(Qt::ItemFlags flags)
|
||||
{
|
||||
setData((int)flags, DataFlagsRole);
|
||||
setData((int)flags, Qt::StandardItemFlagsRole);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -1011,7 +1006,7 @@ void QStandardItem::setFlags(Qt::ItemFlags flags)
|
|||
*/
|
||||
Qt::ItemFlags QStandardItem::flags() const
|
||||
{
|
||||
QVariant v = data(DataFlagsRole);
|
||||
QVariant v = data(Qt::StandardItemFlagsRole);
|
||||
if (!v.isValid())
|
||||
return (Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable
|
||||
|Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled);
|
||||
|
|
|
@ -1034,8 +1034,8 @@ public:
|
|||
QStandardItem::setData(value, role);
|
||||
break;
|
||||
default:
|
||||
// setFlags() uses "UserRole - 1" to store the flags, which is an
|
||||
// implementation detail not exposed in the docs.
|
||||
// setFlags() uses Qt::StandardItemFlagsRole to store the flags,
|
||||
// which is an implementation detail not exposed in the docs.
|
||||
QStandardItem::setData(value, role);
|
||||
break;
|
||||
}
|
||||
|
@ -1047,8 +1047,8 @@ public:
|
|||
case Qt::DisplayRole:
|
||||
return QStandardItem::data(role);
|
||||
default:
|
||||
// flags() uses "UserRole - 1" to get the flags, which is an implementation
|
||||
// detail not exposed in the docs.
|
||||
// flags() uses Qt::StandardItemFlagsRole to get the flags, which is
|
||||
// an implementation detail not exposed in the docs.
|
||||
return QStandardItem::data(role);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -762,7 +762,7 @@ void tst_QStandardItemModel::data()
|
|||
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)); // Qt::UserRole - 1 is used to store flags
|
||||
QVERIFY(!itmData.contains(Qt::StandardItemFlagsRole));
|
||||
QVERIFY(m_model->itemData(QModelIndex()).isEmpty());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue