Add support for tracking the length of a model in C++

Similar to the parent commit, the model tracks changes to the rows and
marks an internal property dirty. Since we have a base class this is a
little less intrusive.

cc #98
This commit is contained in:
Simon Hausmann 2021-10-20 14:11:16 +02:00 committed by Simon Hausmann
parent 63bf1af093
commit 7d12fd7b4e
6 changed files with 49 additions and 2 deletions

View file

@ -456,6 +456,11 @@ public:
/// Internal function called by the view to register itself
void attach_peer(private_api::ModelPeer p) { peers.push_back(std::move(p)); }
/// \private
/// Internal function called from within bindings to register with the currently
/// evaluating dependency and get notified when this model's row count changes.
void track_row_count_changes() { model_dirty_property.get(); }
protected:
/// Notify the views that a specific row was changed
void row_changed(int row)
@ -465,11 +470,13 @@ protected:
/// Notify the views that rows were added
void row_added(int index, int count)
{
model_dirty_property.set_dirty();
for_each_peers([=](auto peer) { peer->row_added(index, count); });
}
/// Notify the views that rows were removed
void row_removed(int index, int count)
{
model_dirty_property.set_dirty();
for_each_peers([=](auto peer) { peer->row_removed(index, count); });
}
@ -489,6 +496,7 @@ private:
peers.end());
}
std::vector<private_api::ModelPeer> peers;
private_api::Property<bool> model_dirty_property;
};
namespace private_api {