plugin/fsm: incremental updates + sort
This commit is contained in:
parent
23db04e1b7
commit
2a5a24c51f
1 changed files with 22 additions and 11 deletions
|
|
@ -133,10 +133,9 @@ void FileSystemModel::updateEntries() {
|
||||||
iter.emplace(m_path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, flags);
|
iter.emplace(m_path, QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList newPaths;
|
QSet<QString> newPaths;
|
||||||
|
while (iter->hasNext()) {
|
||||||
while (iter.value().hasNext()) {
|
QString path = iter->next();
|
||||||
QString path = iter.value().next();
|
|
||||||
|
|
||||||
if (m_filter == Images) {
|
if (m_filter == Images) {
|
||||||
QImageReader reader(path);
|
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) {
|
for (const auto& entry : m_entries) {
|
||||||
oldPaths << entry->path();
|
oldPaths.insert(entry->path());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newPaths == oldPaths) {
|
if (newPaths == oldPaths) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
beginResetModel();
|
const QSet<QString> removedPaths = oldPaths - newPaths;
|
||||||
qDeleteAll(m_entries);
|
const QSet<QString> addedPaths = newPaths - oldPaths;
|
||||||
m_entries.clear();
|
|
||||||
|
|
||||||
for (const auto& path : newPaths) {
|
beginResetModel();
|
||||||
|
|
||||||
|
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);
|
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();
|
emit entriesChanged();
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue