plugin/fsm: update relativePath when path changed
This commit is contained in:
parent
f6f8f9b4b8
commit
c55f8bd045
2 changed files with 20 additions and 2 deletions
|
|
@ -64,6 +64,14 @@ QString FileSystemEntry::mimeType() const {
|
||||||
return m_mimeType;
|
return m_mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSystemEntry::updateRelativePath(const QDir& dir) {
|
||||||
|
const auto relPath = dir.relativeFilePath(m_path);
|
||||||
|
if (m_relativePath != relPath) {
|
||||||
|
m_relativePath = relPath;
|
||||||
|
emit relativePathChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileSystemModel::FileSystemModel(QObject* parent)
|
FileSystemModel::FileSystemModel(QObject* parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, m_recursive(false)
|
, m_recursive(false)
|
||||||
|
|
@ -105,6 +113,11 @@ void FileSystemModel::setPath(const QString& path) {
|
||||||
emit pathChanged();
|
emit pathChanged();
|
||||||
|
|
||||||
m_dir.setPath(m_path);
|
m_dir.setPath(m_path);
|
||||||
|
|
||||||
|
for (const auto& entry : m_entries) {
|
||||||
|
entry->updateRelativePath(m_dir);
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class FileSystemEntry : public QObject {
|
||||||
QML_UNCREATABLE("FileSystemEntry instances can only be retrieved from a FileSystemModel")
|
QML_UNCREATABLE("FileSystemEntry instances can only be retrieved from a FileSystemModel")
|
||||||
|
|
||||||
Q_PROPERTY(QString path READ path CONSTANT)
|
Q_PROPERTY(QString path READ path CONSTANT)
|
||||||
Q_PROPERTY(QString relativePath READ relativePath CONSTANT)
|
Q_PROPERTY(QString relativePath READ relativePath NOTIFY relativePathChanged)
|
||||||
Q_PROPERTY(QString name READ name CONSTANT)
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
Q_PROPERTY(QString baseName READ baseName CONSTANT)
|
Q_PROPERTY(QString baseName READ baseName CONSTANT)
|
||||||
Q_PROPERTY(QString parentDir READ parentDir CONSTANT)
|
Q_PROPERTY(QString parentDir READ parentDir CONSTANT)
|
||||||
|
|
@ -41,11 +41,16 @@ public:
|
||||||
[[nodiscard]] bool isImage() const;
|
[[nodiscard]] bool isImage() const;
|
||||||
[[nodiscard]] QString mimeType() const;
|
[[nodiscard]] QString mimeType() const;
|
||||||
|
|
||||||
|
void updateRelativePath(const QDir& dir);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void relativePathChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QFileInfo m_fileInfo;
|
const QFileInfo m_fileInfo;
|
||||||
|
|
||||||
const QString m_path;
|
const QString m_path;
|
||||||
const QString m_relativePath;
|
QString m_relativePath;
|
||||||
|
|
||||||
mutable bool m_isImage;
|
mutable bool m_isImage;
|
||||||
mutable bool m_isImageInitialised;
|
mutable bool m_isImageInitialised;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue