summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/Models
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-23 15:20:13 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-23 15:20:13 +1000
commitc55f8bd045d3512a2eceb97e9736514e2aab8bea (patch)
tree23ee5d1bb4f679d600678f48c0e59b98e1e51f09 /plugin/src/Caelestia/Models
parentplugin/fsm: emit entriesChanged before destruction (diff)
downloadcaelestia-shell-c55f8bd045d3512a2eceb97e9736514e2aab8bea.tar.gz
caelestia-shell-c55f8bd045d3512a2eceb97e9736514e2aab8bea.tar.bz2
caelestia-shell-c55f8bd045d3512a2eceb97e9736514e2aab8bea.zip
plugin/fsm: update relativePath when path changed
Diffstat (limited to '')
-rw-r--r--plugin/src/Caelestia/Models/filesystemmodel.cpp13
-rw-r--r--plugin/src/Caelestia/Models/filesystemmodel.hpp9
2 files changed, 20 insertions, 2 deletions
diff --git a/plugin/src/Caelestia/Models/filesystemmodel.cpp b/plugin/src/Caelestia/Models/filesystemmodel.cpp
index 90ba5a9..9cebaec 100644
--- a/plugin/src/Caelestia/Models/filesystemmodel.cpp
+++ b/plugin/src/Caelestia/Models/filesystemmodel.cpp
@@ -64,6 +64,14 @@ QString FileSystemEntry::mimeType() const {
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)
: QAbstractListModel(parent)
, m_recursive(false)
@@ -105,6 +113,11 @@ void FileSystemModel::setPath(const QString& path) {
emit pathChanged();
m_dir.setPath(m_path);
+
+ for (const auto& entry : m_entries) {
+ entry->updateRelativePath(m_dir);
+ }
+
update();
}
diff --git a/plugin/src/Caelestia/Models/filesystemmodel.hpp b/plugin/src/Caelestia/Models/filesystemmodel.hpp
index cd2240d..07fb1a1 100644
--- a/plugin/src/Caelestia/Models/filesystemmodel.hpp
+++ b/plugin/src/Caelestia/Models/filesystemmodel.hpp
@@ -17,7 +17,7 @@ class FileSystemEntry : public QObject {
QML_UNCREATABLE("FileSystemEntry instances can only be retrieved from a FileSystemModel")
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 baseName READ baseName CONSTANT)
Q_PROPERTY(QString parentDir READ parentDir CONSTANT)
@@ -41,11 +41,16 @@ public:
[[nodiscard]] bool isImage() const;
[[nodiscard]] QString mimeType() const;
+ void updateRelativePath(const QDir& dir);
+
+signals:
+ void relativePathChanged();
+
private:
const QFileInfo m_fileInfo;
const QString m_path;
- const QString m_relativePath;
+ QString m_relativePath;
mutable bool m_isImage;
mutable bool m_isImageInitialised;