plugin/fsm: fix crash
Fixes #663 Fixes #681 Fixes #647 also build dev plugin with RelWithDebInfo
This commit is contained in:
parent
2ccd3a8662
commit
e294adf96a
4 changed files with 14 additions and 31 deletions
2
.envrc
2
.envrc
|
|
@ -9,7 +9,7 @@ watch_file plugin/**/*.cpp
|
|||
watch_file plugin/**/*.hpp
|
||||
watch_file **/CMakeLists.txt
|
||||
|
||||
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=clazy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DDISTRIBUTOR=direnv
|
||||
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_COMPILER=clazy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DDISTRIBUTOR=direnv
|
||||
cmake --build build
|
||||
export CAELESTIA_LIB_DIR="$PWD/build/lib"
|
||||
export QML2_IMPORT_PATH="$PWD/build/qml:${QML2_IMPORT_PATH:-}"
|
||||
|
|
|
|||
|
|
@ -266,14 +266,11 @@ void FileSystemModel::updateWatcher() {
|
|||
void FileSystemModel::updateEntries() {
|
||||
if (m_path.isEmpty()) {
|
||||
if (!m_entries.isEmpty()) {
|
||||
auto toDelete = m_entries;
|
||||
|
||||
beginResetModel();
|
||||
qDeleteAll(m_entries);
|
||||
m_entries.clear();
|
||||
endResetModel();
|
||||
emit entriesChanged();
|
||||
|
||||
qDeleteAll(toDelete);
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -396,8 +393,7 @@ void FileSystemModel::applyChanges(const QSet<QString>& removedPaths, const QSet
|
|||
}
|
||||
std::sort(removedIndices.begin(), removedIndices.end(), std::greater<int>());
|
||||
|
||||
QList<FileSystemEntry*> toDelete;
|
||||
|
||||
// Batch remove old entries
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
for (int idx : std::as_const(removedIndices)) {
|
||||
|
|
@ -409,8 +405,7 @@ void FileSystemModel::applyChanges(const QSet<QString>& removedPaths, const QSet
|
|||
} else {
|
||||
beginRemoveRows(QModelIndex(), end, start);
|
||||
for (int i = start; i >= end; --i) {
|
||||
emit removed(m_entries[i]->path());
|
||||
toDelete << m_entries.takeAt(i);
|
||||
m_entries.takeAt(i)->deleteLater();
|
||||
}
|
||||
endRemoveRows();
|
||||
|
||||
|
|
@ -421,12 +416,12 @@ void FileSystemModel::applyChanges(const QSet<QString>& removedPaths, const QSet
|
|||
if (start != -1) {
|
||||
beginRemoveRows(QModelIndex(), end, start);
|
||||
for (int i = start; i >= end; --i) {
|
||||
emit removed(m_entries[i]->path());
|
||||
toDelete << m_entries.takeAt(i);
|
||||
m_entries.takeAt(i)->deleteLater();
|
||||
}
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
// Create new entries
|
||||
QList<FileSystemEntry*> newEntries;
|
||||
for (const auto& path : addedPaths) {
|
||||
newEntries << new FileSystemEntry(path, m_dir.relativeFilePath(path), this);
|
||||
|
|
@ -435,57 +430,50 @@ void FileSystemModel::applyChanges(const QSet<QString>& removedPaths, const QSet
|
|||
return compareEntries(a, b);
|
||||
});
|
||||
|
||||
// Batch insert new entries
|
||||
int insertStart = -1;
|
||||
int prevRow = -1;
|
||||
QList<FileSystemEntry*> batchItems;
|
||||
for (const auto& entry : std::as_const(newEntries)) {
|
||||
const auto it = std::lower_bound(
|
||||
m_entries.begin(), m_entries.end(), entry, [this](const FileSystemEntry* a, const FileSystemEntry* b) {
|
||||
return compareEntries(a, b);
|
||||
});
|
||||
int row = static_cast<int>(it - m_entries.begin());
|
||||
const auto row = static_cast<int>(it - m_entries.begin());
|
||||
|
||||
if (insertStart == -1) {
|
||||
insertStart = row;
|
||||
prevRow = row;
|
||||
batchItems.clear();
|
||||
batchItems << entry;
|
||||
} else if (row == prevRow + 1) {
|
||||
prevRow = row;
|
||||
} else if (row == insertStart + batchItems.size()) {
|
||||
batchItems << entry;
|
||||
} else {
|
||||
beginInsertRows(QModelIndex(), insertStart, static_cast<int>(insertStart + batchItems.size() - 1));
|
||||
beginInsertRows(QModelIndex(), insertStart, insertStart + static_cast<int>(batchItems.size()) - 1);
|
||||
for (int i = 0; i < batchItems.size(); ++i) {
|
||||
m_entries.insert(insertStart + i, batchItems[i]);
|
||||
emit added(batchItems[i]);
|
||||
}
|
||||
endInsertRows();
|
||||
|
||||
insertStart = row;
|
||||
prevRow = row;
|
||||
batchItems.clear();
|
||||
batchItems << entry;
|
||||
}
|
||||
prevRow = static_cast<int>(m_entries.indexOf(entry));
|
||||
}
|
||||
if (!batchItems.isEmpty()) {
|
||||
beginInsertRows(QModelIndex(), insertStart, static_cast<int>(insertStart + batchItems.size() - 1));
|
||||
beginInsertRows(QModelIndex(), insertStart, insertStart + static_cast<int>(batchItems.size()) - 1);
|
||||
for (int i = 0; i < batchItems.size(); ++i) {
|
||||
m_entries.insert(insertStart + i, batchItems[i]);
|
||||
emit added(batchItems[i]);
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
emit entriesChanged();
|
||||
qDeleteAll(toDelete);
|
||||
}
|
||||
|
||||
bool FileSystemModel::compareEntries(const FileSystemEntry* a, const FileSystemEntry* b) const {
|
||||
if (a->isDir() != b->isDir()) {
|
||||
return m_sortReverse ^ a->isDir();
|
||||
}
|
||||
return m_sortReverse ^ (a->relativePath().localeAwareCompare(b->relativePath()) < 0);
|
||||
const auto cmp = a->relativePath().localeAwareCompare(b->relativePath());
|
||||
return m_sortReverse ? cmp > 0 : cmp < 0;
|
||||
}
|
||||
|
||||
} // namespace caelestia
|
||||
|
|
|
|||
|
|
@ -121,9 +121,6 @@ signals:
|
|||
void nameFiltersChanged();
|
||||
void entriesChanged();
|
||||
|
||||
void added(const caelestia::FileSystemEntry* entry);
|
||||
void removed(const QString& path);
|
||||
|
||||
private:
|
||||
QDir m_dir;
|
||||
QFileSystemWatcher m_watcher;
|
||||
|
|
|
|||
|
|
@ -207,18 +207,16 @@ void AppDb::updateApps() {
|
|||
newIds.insert(entry->property("id").toString());
|
||||
}
|
||||
|
||||
QList<AppEntry*> toDelete;
|
||||
for (auto it = m_apps.keyBegin(); it != m_apps.keyEnd(); ++it) {
|
||||
const auto& id = *it;
|
||||
if (!newIds.contains(id)) {
|
||||
dirty = true;
|
||||
toDelete << m_apps.take(id);
|
||||
m_apps.take(id)->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
if (dirty) {
|
||||
emit appsChanged();
|
||||
qDeleteAll(toDelete);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue