summaryrefslogtreecommitdiff
path: root/src/filetreemodel.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-01-20 18:28:50 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-04 03:33:20 -0500
commit7c4d3c6fb958d61e8d74fac982907f48831c7f7e (patch)
treefe788f9b0feaba09ce0308b0e07c332fa7a89d59 /src/filetreemodel.cpp
parent9c9de680c6d53755d3bf99a0c3af2e2d440f86f3 (diff)
refactored removeDisappearingFiles() to just check for directories in the main loop
Diffstat (limited to 'src/filetreemodel.cpp')
-rw-r--r--src/filetreemodel.cpp71
1 files changed, 32 insertions, 39 deletions
diff --git a/src/filetreemodel.cpp b/src/filetreemodel.cpp
index f5877dbb..00ab13d6 100644
--- a/src/filetreemodel.cpp
+++ b/src/filetreemodel.cpp
@@ -435,60 +435,49 @@ void FileTreeModel::removeDisappearingFiles(
auto& children = parentItem.children();
auto itor = children.begin();
+ firstFileRow = -1;
+
// keeps track of the contiguous directories that need to be removed to
// avoid calling beginRemoveRows(), etc. for each item
int removeStart = -1;
- firstFileRow = 0;
+ int row = 0;
- // directories are always first, so find the first file item
+ // for each item in this tree item
while (itor != children.end()) {
const auto& item = *itor;
if (!item->isDirectory()) {
- break;
- }
-
- ++firstFileRow;
- ++itor;
- }
-
- if (itor == children.end()) {
- // no file items
- return;
- }
-
- int row = firstFileRow;
-
- // for each item in this tree item
- while (itor != children.end()) {
- const auto& item = *itor;
+ if (firstFileRow == -1) {
+ firstFileRow = row;
+ }
- auto f = parentEntry.findFile(item->key());
+ auto f = parentEntry.findFile(item->key());
- if (f) {
- trace([&]{ log::debug("file {} still there", item->filename()); });
+ if (f) {
+ trace([&]{ log::debug("file {} still there", item->filename()); });
- // file is still there
- seen.emplace(f->getIndex());
+ // file is still there
+ seen.emplace(f->getIndex());
- // if there were files before this row that need to be removed,
- // do it now
- if (removeStart != -1) {
- removeRange(parentItem, removeStart, row - 1);
+ // if there were files before this row that need to be removed,
+ // do it now
+ if (removeStart != -1) {
+ removeRange(parentItem, removeStart, row - 1);
- // adjust current row to account for those that were just removed
- row -= (row - removeStart);
- itor = children.begin() + row;
+ // adjust current row to account for those that were just removed
+ row -= (row - removeStart);
+ itor = children.begin() + row;
- removeStart = -1;
- }
- } else {
- // file is gone from the parent entry
- trace([&]{ log::debug("file {} is gone", item->filename()); });
+ removeStart = -1;
+ }
+ } else {
+ // file is gone from the parent entry
+ trace([&]{ log::debug("file {} is gone", item->filename()); });
- if (removeStart == -1) {
- // start a new contiguous sequence
- removeStart = row;
+ if (removeStart == -1) {
+ // start a new contiguous sequence
+ removeStart = row;
+ }
}
}
@@ -496,6 +485,10 @@ void FileTreeModel::removeDisappearingFiles(
++itor;
}
+ if (firstFileRow == -1) {
+ firstFileRow = static_cast<int>(children.size());
+ }
+
// remove the last file range, if any
if (removeStart != -1) {
removeRange(parentItem, removeStart, row -1 );