diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-02 14:32:40 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-02 14:32:40 +1000 |
| commit | 2a5a24c51f7bce4756a58424c6f9c8c34910f746 (patch) | |
| tree | ab0c005ff91f093d6980d2d5e64f396b1447181c /plugin/src/Caelestia | |
| parent | internal: remove singleton reloadableId (diff) | |
| download | caelestia-shell-2a5a24c51f7bce4756a58424c6f9c8c34910f746.tar.gz caelestia-shell-2a5a24c51f7bce4756a58424c6f9c8c34910f746.tar.bz2 caelestia-shell-2a5a24c51f7bce4756a58424c6f9c8c34910f746.zip | |
plugin/fsm: incremental updates + sort
Diffstat (limited to 'plugin/src/Caelestia')
| -rw-r--r-- | plugin/src/Caelestia/filesystemmodel.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/plugin/src/Caelestia/filesystemmodel.cpp b/plugin/src/Caelestia/filesystemmodel.cpp index 0a3d31a..832e458 100644 --- a/plugin/src/Caelestia/filesystemmodel.cpp +++ b/plugin/src/Caelestia/filesystemmodel.cpp @@ -133,10 +133,9 @@ void FileSystemModel::updateEntries() { iter.emplace(m_path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, flags); } - QStringList newPaths; - - while (iter.value().hasNext()) { - QString path = iter.value().next(); + QSet<QString> newPaths; + while (iter->hasNext()) { + QString path = iter->next(); if (m_filter == Images) { QImageReader reader(path); @@ -145,26 +144,38 @@ void FileSystemModel::updateEntries() { } } - newPaths << path; + newPaths.insert(path); } - QStringList oldPaths; + QSet<QString> oldPaths; for (const auto& entry : m_entries) { - oldPaths << entry->path(); + oldPaths.insert(entry->path()); } if (newPaths == oldPaths) { return; } + const QSet<QString> removedPaths = oldPaths - newPaths; + const QSet<QString> addedPaths = newPaths - oldPaths; + beginResetModel(); - qDeleteAll(m_entries); - m_entries.clear(); - for (const auto& path : newPaths) { + const int numEntries = static_cast<int>(m_entries.size()); + for (int i = numEntries - 1; i >= 0; --i) { + if (removedPaths.contains(m_entries[i]->path())) { + delete m_entries.takeAt(i); + } + } + + for (const auto& path : addedPaths) { m_entries << new FileSystemEntry(path, m_dir.relativeFilePath(path), this); } + std::sort(m_entries.begin(), m_entries.end(), [](const FileSystemEntry* a, const FileSystemEntry* b) { + return a->relativePath().localeAwareCompare(b->relativePath()) < 0; + }); + emit entriesChanged(); endResetModel(); |