mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 22:01:13 +00:00
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:
parent
63bf1af093
commit
7d12fd7b4e
6 changed files with 49 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue