QAbstractItemModel: remove deprecated setRoleNames()

Remove setRoleNames() and all its now unneeded helper functions.

Change-Id: I0a83751aace35700655d4cc7c79278325994cbdd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Christian Ehrlicher 2020-06-05 20:29:48 +02:00
parent 45b0f1be68
commit 32b586864e
10 changed files with 39 additions and 60 deletions

View File

@ -518,8 +518,7 @@ Q_GLOBAL_STATIC(QEmptyItemModel, qEmptyModel)
QAbstractItemModelPrivate::QAbstractItemModelPrivate()
: QObjectPrivate(),
supportedDragActions(-1),
roleNames(defaultRoleNames())
supportedDragActions(-1)
{
}
@ -2485,30 +2484,6 @@ QSize QAbstractItemModel::span(const QModelIndex &) const
return QSize(1, 1);
}
/*!
\fn void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray> &roleNames)
\since 4.6
\obsolete
This function is obsolete. Reimplement roleNames() instead.
Sets the model's role names to \a roleNames.
This function allows mapping of role identifiers to role property names in
scripting languages.
\sa roleNames()
*/
/*!
\internal
*/
void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames)
{
Q_D(QAbstractItemModel);
d->roleNames = roleNames;
}
/*!
\since 4.6
@ -2542,8 +2517,7 @@ void QAbstractItemModel::doSetRoleNames(const QHash<int,QByteArray> &roleNames)
*/
QHash<int,QByteArray> QAbstractItemModel::roleNames() const
{
Q_D(const QAbstractItemModel);
return d->roleNames;
return QAbstractItemModelPrivate::defaultRoleNames();
}
/*!

View File

@ -349,15 +349,7 @@ protected:
void changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to);
QModelIndexList persistentIndexList() const;
#if QT_DEPRECATED_SINCE(5,0)
QT_DEPRECATED void setRoleNames(const QHash<int,QByteArray> &theRoleNames)
{
doSetRoleNames(theRoleNames);
}
#endif
private:
void doSetRoleNames(const QHash<int,QByteArray> &roleNames);
void doSetSupportedDragActions(Qt::DropActions actions);
Q_DECLARE_PRIVATE(QAbstractItemModel)

View File

@ -149,7 +149,6 @@ public:
Qt::DropActions supportedDragActions;
QHash<int,QByteArray> roleNames;
static const QHash<int,QByteArray> &defaultRoleNames();
static bool isVariantLessThan(const QVariant &left, const QVariant &right,
Qt::CaseSensitivity cs = Qt::CaseSensitive, bool isLocaleAware = false);

View File

@ -138,20 +138,10 @@ void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
} else {
d->model = QAbstractItemModelPrivate::staticEmptyModel();
}
d->roleNames = d->model->roleNames();
emit sourceModelChanged(QPrivateSignal());
}
}
/*!
Clears the roleNames of this proxy model.
*/
void QAbstractProxyModel::resetInternalData()
{
Q_D(QAbstractProxyModel);
d->roleNames = d->model->roleNames();
}
/*!
Returns the model that contains the data that is available through the proxy model.
*/
@ -477,6 +467,16 @@ Qt::DropActions QAbstractProxyModel::supportedDropActions() const
return d->model->supportedDropActions();
}
/*!
\reimp
*/
QHash<int,QByteArray> QAbstractProxyModel::roleNames() const
{
Q_D(const QAbstractProxyModel);
return d->model->roleNames();
}
QT_END_NAMESPACE
#include "moc_qabstractproxymodel.cpp"

View File

@ -98,17 +98,11 @@ public:
QStringList mimeTypes() const override;
Qt::DropActions supportedDragActions() const override;
Qt::DropActions supportedDropActions() const override;
QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
void sourceModelChanged(QPrivateSignal);
protected Q_SLOTS:
void resetInternalData()
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
override
#endif
;
protected:
QAbstractProxyModel(QAbstractProxyModelPrivate &, QObject *parent);

View File

@ -2232,6 +2232,15 @@ void QStandardItemModel::setItemRoleNames(const QHash<int,QByteArray> &roleNames
d->roleNames = roleNames;
}
/*!
reimp
*/
QHash<int, QByteArray> QStandardItemModel::roleNames() const
{
Q_D(const QStandardItemModel);
return d->roleNames;
}
/*!
Removes all items (including header items) from the model and sets the
number of rows and columns to zero.

View File

@ -321,6 +321,7 @@ public:
~QStandardItemModel();
void setItemRoleNames(const QHash<int,QByteArray> &roleNames);
QHash<int, QByteArray> roleNames() const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;

View File

@ -245,6 +245,7 @@ public:
QVector<QStandardItem*> columnHeaderItems;
QVector<QStandardItem*> rowHeaderItems;
QHash<int, QByteArray> roleNames;
QScopedPointer<QStandardItem> root;
const QStandardItem *itemPrototype;
int sortRole;

View File

@ -1263,6 +1263,20 @@ Qt::DropActions QFileSystemModel::supportedDropActions() const
return Qt::CopyAction | Qt::MoveAction | Qt::LinkAction;
}
/*!
\reimp
*/
QHash<int, QByteArray> QFileSystemModel::roleNames() const
{
auto ret = QAbstractItemModel::roleNames();
ret.insert(QFileSystemModel::FileIconRole,
QByteArrayLiteral("fileIcon")); // == Qt::decoration
ret.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath"));
ret.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName"));
ret.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions"));
return ret;
}
/*!
\enum QFileSystemModel::Option
\since 5.14
@ -2075,12 +2089,6 @@ void QFileSystemModelPrivate::init()
q, SIGNAL(directoryLoaded(QString)));
#endif // filesystemwatcher
q->connect(&delayedSortTimer, SIGNAL(timeout()), q, SLOT(_q_performDelayedSort()), Qt::QueuedConnection);
roleNames.insert(QFileSystemModel::FileIconRole,
QByteArrayLiteral("fileIcon")); // == Qt::decoration
roleNames.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath"));
roleNames.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName"));
roleNames.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions"));
}
/*!

View File

@ -115,6 +115,7 @@ public:
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) override;
Qt::DropActions supportedDropActions() const override;
QHash<int, QByteArray> roleNames() const override;
// QFileSystemModel specific API
QModelIndex setRootPath(const QString &path);