plugin/fsm: only provide modelData role

This commit is contained in:
2 * r + 2 * t 2025-09-01 16:26:54 +10:00
parent 7dcb545ba0
commit 704db7b6a6
2 changed files with 6 additions and 41 deletions

View file

@ -9,46 +9,21 @@
#include <QImageReader> #include <QImageReader>
int FileSystemModel::rowCount(const QModelIndex& parent) const { int FileSystemModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent); if (parent != QModelIndex()) {
return 0;
}
return static_cast<int>(m_entries.size()); return static_cast<int>(m_entries.size());
} }
QVariant FileSystemModel::data(const QModelIndex& index, int role) const { QVariant FileSystemModel::data(const QModelIndex& index, int role) const {
if (!index.isValid() || index.row() >= m_entries.size()) { if (role != Qt::UserRole || !index.isValid() || index.row() >= m_entries.size()) {
return QVariant();
}
FileSystemEntry* file = m_entries.at(index.row());
switch (role) {
case FilePathRole:
return file->path();
case RelativeFilePathRole:
return file->relativePath();
case FileNameRole:
return file->name();
case ParentDirRole:
return file->parentDir();
case FileSizeRole:
return file->size();
case FileIsDirRole:
return file->isDir();
case FileIsImageRole:
return file->isImage();
default:
return QVariant(); return QVariant();
} }
return QVariant::fromValue(m_entries.at(index.row()));
} }
QHash<int, QByteArray> FileSystemModel::roleNames() const { QHash<int, QByteArray> FileSystemModel::roleNames() const {
QHash<int, QByteArray> roles; return {{ Qt::UserRole, "modelData"}};
roles[FilePathRole] = "filePath";
roles[RelativeFilePathRole] = "relativeFilePath";
roles[FileNameRole] = "fileName";
roles[ParentDirRole] = "parentDir";
roles[FileSizeRole] = "fileSize";
roles[FileIsDirRole] = "fileIsDir";
roles[FileIsImageRole] = "fileIsImage";
return roles;
} }
QString FileSystemModel::path() const { QString FileSystemModel::path() const {

View file

@ -63,16 +63,6 @@ class FileSystemModel : public QAbstractListModel {
Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged) Q_PROPERTY(QList<FileSystemEntry*> entries READ entries NOTIFY entriesChanged)
public: public:
enum Roles {
FilePathRole = Qt::UserRole + 1,
RelativeFilePathRole,
FileNameRole,
ParentDirRole,
FileSizeRole,
FileIsDirRole,
FileIsImageRole
};
enum Filter { enum Filter {
NoFilter, NoFilter,
Images, Images,