summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2011-12-27 17:02:33 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-10 11:37:28 +0100
commitc3ad8c1c062a972b7fb75d8b51a1f80cb371d503 (patch)
tree47bd4f0b698a16a7a475c19e7c3c9acab60f0ba5 /src/corelib/itemmodels
parent1e10e4deb97885472c36f5b10a5888979f24cee0 (diff)
Make the roleNames a virtual accessor.
This is consistent with the rest of the API of QAbstractItemModel (which is virtual) and removes the need for code like this in the constructor (where it doesn't belong): QHash<int, QByteArray> myRoleNames = roleNames(); myRoleNames.insert(Qt::UserRole + 1, "myCustomRole"); setRoleNames(myRoleNames); in favor of MyModel::roleNames() const { QHash<int, QByteArray> myRoleNames = QAbstractItemModel::roleNames(); myRoleNames.insert(Qt::UserRole + 1, "myCustomRole"); return myRoleNames; } which is consistent with all other QAIM API (eg, flags()). This is a source compatible change. Change-Id: I7e1ce17f8dab2292c4c7b6dbd3c09ec71b5c793b Reviewed-by: David Faure <faure@kde.org> Reviewed-by: Marius Bugge Monsen <marius@cutehacks.com>
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp9
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.h11
2 files changed, 16 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)
};