aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/treemodel.cc12
-rw-r--r--gui/treemodel.h9
2 files changed, 15 insertions, 6 deletions
diff --git a/gui/treemodel.cc b/gui/treemodel.cc
index 900d5101..33dd6a96 100644
--- a/gui/treemodel.cc
+++ b/gui/treemodel.cc
@@ -70,12 +70,14 @@ void IdStringList::updateElements(Context *ctx, std::vector<IdString> elements)
}
// For any elements that are in managed_ but not in new, delete them.
- for (auto &pair : managed_) {
- if (element_set.count(pair.first) != 0) {
- continue;
+ auto it = managed_.begin();
+ while (it != managed_.end()) {
+ if (element_set.count(it->first) != 0) {
+ ++it;
+ } else {
+ it = managed_.erase(it);
+ changed = true;
}
- managed_.erase(pair.first);
- changed = true;
}
// Return early if there are no changes.
diff --git a/gui/treemodel.h b/gui/treemodel.h
index 4c3f64c3..c3f9fe88 100644
--- a/gui/treemodel.h
+++ b/gui/treemodel.h
@@ -62,6 +62,8 @@ class Item
void addChild(Item *child) { children_.append(child); }
+ void deleteChild(Item *child) { children_.removeAll(child); }
+
public:
Item(QString name, Item *parent) : name_(name), parent_(parent)
{
@@ -100,7 +102,12 @@ class Item
virtual bool canFetchMore() const { return false; }
virtual void fetchMore() {}
- ~Item() {}
+ ~Item()
+ {
+ if (parent_ != nullptr) {
+ parent_->deleteChild(this);
+ }
+ }
};
// IdString is an Item that corresponds to a real element in Arch.