Add a reset function to the model notifier

This commit is contained in:
Olivier Goffart 2022-04-14 14:06:34 +02:00 committed by GitHub
parent 2b93504b93
commit f5030cff06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 4 deletions

View file

@ -520,6 +520,7 @@ struct AbstractRepeaterView
virtual void row_added(int index, int count) = 0;
virtual void row_removed(int index, int count) = 0;
virtual void row_changed(int index) = 0;
virtual void reset() = 0;
};
using ModelPeer = std::weak_ptr<AbstractRepeaterView>;
@ -614,6 +615,14 @@ protected:
for_each_peers([=](auto peer) { peer->row_removed(index, count); });
}
/// Notify the views that the model has been changed and that everything needs to be reloaded
void reset() {
model_row_count_dirty_property.mark_dirty();
tracked_rows.clear();
model_row_data_dirty_property.mark_dirty();
for_each_peers([=](auto peer) { peer->reset(); });
}
private:
template<typename F>
void for_each_peers(const F &f)
@ -769,6 +778,10 @@ class Repeater
data[i].state = State::Dirty;
}
}
void reset() override {
is_dirty.set(true);
data.clear();
}
};
public: