plugin/fsm: only update changed dir
Also add added and removed signals
This commit is contained in:
parent
f8dc3f2b38
commit
2601955dfd
2 changed files with 16 additions and 5 deletions
|
|
@ -116,6 +116,10 @@ void FileSystemModel::updateEntries() {
|
|||
return;
|
||||
}
|
||||
|
||||
updateEntriesForDir(m_path);
|
||||
}
|
||||
|
||||
void FileSystemModel::updateEntriesForDir(const QString& dir) {
|
||||
const auto flags = m_recursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
|
||||
|
||||
std::optional<QDirIterator> iter;
|
||||
|
|
@ -126,11 +130,11 @@ void FileSystemModel::updateEntries() {
|
|||
filters << "*." + format;
|
||||
}
|
||||
|
||||
iter.emplace(m_path, filters, QDir::Files, flags);
|
||||
iter.emplace(dir, filters, QDir::Files, flags);
|
||||
} else if (m_filter == Files) {
|
||||
iter.emplace(m_path, QDir::Files, flags);
|
||||
iter.emplace(dir, QDir::Files, flags);
|
||||
} else {
|
||||
iter.emplace(m_path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, flags);
|
||||
iter.emplace(dir, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, flags);
|
||||
}
|
||||
|
||||
QSet<QString> newPaths;
|
||||
|
|
@ -164,12 +168,15 @@ void FileSystemModel::updateEntries() {
|
|||
const int numEntries = static_cast<int>(m_entries.size());
|
||||
for (int i = numEntries - 1; i >= 0; --i) {
|
||||
if (removedPaths.contains(m_entries[i]->path())) {
|
||||
emit removed(m_entries[i]->path());
|
||||
delete m_entries.takeAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& path : addedPaths) {
|
||||
m_entries << new FileSystemEntry(path, m_dir.relativeFilePath(path), this);
|
||||
const auto entry = new FileSystemEntry(path, m_dir.relativeFilePath(path), this);
|
||||
emit added(entry);
|
||||
m_entries << entry;
|
||||
}
|
||||
|
||||
std::sort(m_entries.begin(), m_entries.end(), [](const FileSystemEntry* a, const FileSystemEntry* b) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public:
|
|||
, m_recursive(true)
|
||||
, m_filter(NoFilter) {
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::watchDirIfRecursive);
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntries);
|
||||
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &FileSystemModel::updateEntriesForDir);
|
||||
}
|
||||
|
||||
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
||||
|
|
@ -102,6 +102,9 @@ signals:
|
|||
void filterChanged();
|
||||
void entriesChanged();
|
||||
|
||||
void added(const FileSystemEntry* entry);
|
||||
void removed(const QString& path);
|
||||
|
||||
private:
|
||||
QDir m_dir;
|
||||
QFileSystemWatcher m_watcher;
|
||||
|
|
@ -115,4 +118,5 @@ private:
|
|||
void update();
|
||||
void updateWatcher();
|
||||
void updateEntries();
|
||||
void updateEntriesForDir(const QString& dir);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue