diff options
author | Sune Vuorela <sune@vuorela.dk> | 2024-03-21 12:05:27 +0100 |
---|---|---|
committer | Sune Vuorela <sune@vuorela.dk> | 2024-04-11 23:12:42 +0100 |
commit | 19258608e9ea02043ce9b53d4a9c99700ce49c1b (patch) | |
tree | b7b54989a235c37f8eadbe0b4132d75e4f4f86f2 /src/gui | |
parent | c6a2f7a70e40a6df71342ffceb5eb897af71350c (diff) |
QFileSystemModel: Add role for fileinfo
Instead of having users traverse a ProxyModel hierarchy to
get to a QFileSystemModel to use the fileInfo(QModelIndex)
function, just let it be available with the roles.
Change-Id: I285347d1d85b4c6253fcb893737aa629a56e27fd
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/itemmodels/qfilesystemmodel.cpp | 4 | ||||
-rw-r--r-- | src/gui/itemmodels/qfilesystemmodel.h | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp index 89ced676e5..290891322f 100644 --- a/src/gui/itemmodels/qfilesystemmodel.cpp +++ b/src/gui/itemmodels/qfilesystemmodel.cpp @@ -31,6 +31,7 @@ using namespace Qt::StringLiterals; \value FilePathRole \value FileNameRole \value FilePermissions + \value FileInfoRole The QFileInfo object for the index */ /*! @@ -730,6 +731,8 @@ QVariant QFileSystemModel::data(const QModelIndex &index, int role) const return filePath(index); case FileNameRole: return d->name(index); + case FileInfoRole: + return QVariant::fromValue(fileInfo(index)); case Qt::DecorationRole: if (index.column() == QFileSystemModelPrivate::NameColumn) { QIcon icon = d->icon(index); @@ -1255,6 +1258,7 @@ QHash<int, QByteArray> QFileSystemModel::roleNames() const ret.insert(QFileSystemModel::FilePathRole, QByteArrayLiteral("filePath")); ret.insert(QFileSystemModel::FileNameRole, QByteArrayLiteral("fileName")); ret.insert(QFileSystemModel::FilePermissions, QByteArrayLiteral("filePermissions")); + ret.insert(QFileSystemModel::FileInfoRole, QByteArrayLiteral("fileInfo")); return ret; } diff --git a/src/gui/itemmodels/qfilesystemmodel.h b/src/gui/itemmodels/qfilesystemmodel.h index 17bce1946f..1fd1041f15 100644 --- a/src/gui/itemmodels/qfilesystemmodel.h +++ b/src/gui/itemmodels/qfilesystemmodel.h @@ -32,11 +32,13 @@ Q_SIGNALS: void directoryLoaded(const QString &path); public: + // ### Qt 7: renumber these values to be before Qt::UserRole comment. enum Roles { FileIconRole = Qt::DecorationRole, + FileInfoRole = Qt::UserRole - 1, FilePathRole = Qt::UserRole + 1, FileNameRole = Qt::UserRole + 2, - FilePermissions = Qt::UserRole + 3 + FilePermissions = Qt::UserRole + 3, }; enum Option |