summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp9
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.h11
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp28
3 files changed, 44 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index f320d595e8..7e6c8baa1d 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -2132,6 +2132,7 @@ QSize QAbstractItemModel::span(const QModelIndex &) const
/*!
\since 4.6
+ \obsolete
Sets the model's role names to \a roleNames.
@@ -2142,7 +2143,11 @@ QSize QAbstractItemModel::span(const QModelIndex &) const
\sa roleNames()
*/
-void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames)
+
+/*!
+ \internal
+ */
+void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames)
{
Q_D(QAbstractItemModel);
d->roleNames = roleNames;
@@ -2155,7 +2160,7 @@ void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames)
\sa setRoleNames()
*/
-const QHash<int,QByteArray> &QAbstractItemModel::roleNames() const
+QHash<int,QByteArray> QAbstractItemModel::roleNames() const
{
Q_D(const QAbstractItemModel);
return d->roleNames;
diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h
index 0ac297e57b..8c9615f7cb 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.h
+++ b/src/corelib/itemmodels/qabstractitemmodel.h
@@ -222,7 +222,7 @@ public:
Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const;
virtual QSize span(const QModelIndex &index) const;
- const QHash<int,QByteArray> &roleNames() const;
+ virtual QHash<int,QByteArray> roleNames() const;
#ifdef Q_NO_USING_KEYWORD
inline QObject *parent() const { return QObject::parent(); }
@@ -302,9 +302,16 @@ protected:
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to);
QModelIndexList persistentIndexList() const;
- void setRoleNames(const QHash<int,QByteArray> &roleNames);
+#if QT_DEPRECATED_SINCE(5,0)
+ QT_DEPRECATED void setRoleNames(const QHash<int,QByteArray> &roleNames)
+ {
+ doSetRoleNames(roleNames);
+ }
+#endif
private:
+ void doSetRoleNames(const QHash<int,QByteArray> &roleNames);
+
Q_DECLARE_PRIVATE(QAbstractItemModel)
Q_DISABLE_COPY(QAbstractItemModel)
};
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 1952314ce2..fd7b0d76ba 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -112,6 +112,8 @@ private slots:
void testChildrenLayoutsChanged();
+ void testRoleNames();
+
private:
DynamicTreeModel *m_model;
};
@@ -1976,5 +1978,31 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged()
}
}
+class OverrideRoleNames : public QStringListModel
+{
+ Q_OBJECT
+public:
+ OverrideRoleNames(QObject *parent = 0)
+ : QStringListModel(parent)
+ {
+
+ }
+
+ QHash<int, QByteArray> roleNames() const
+ {
+ QHash<int, QByteArray> roles = QStringListModel::roleNames();
+ roles.insert(Qt::UserRole + 2, "custom");
+ return roles;
+ }
+};
+
+void tst_QAbstractItemModel::testRoleNames()
+{
+ QAbstractItemModel *model = new OverrideRoleNames(this);
+ QHash<int, QByteArray> roles = model->roleNames();
+ QVERIFY(roles.contains(Qt::UserRole + 2));
+ QVERIFY(roles.value(Qt::UserRole + 2) == "custom");
+}
+
QTEST_MAIN(tst_QAbstractItemModel)
#include "tst_qabstractitemmodel.moc"