mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 04:48:27 +00:00
Add a reset function to the model notifier
This commit is contained in:
parent
2b93504b93
commit
f5030cff06
8 changed files with 67 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -454,6 +454,10 @@ inline Value::Value(const std::shared_ptr<slint::Model<Value>> &model)
|
|||
{
|
||||
cbindgen_private::slint_interpreter_model_notify_row_removed(¬ify, index, count);
|
||||
}
|
||||
void reset() override
|
||||
{
|
||||
cbindgen_private::slint_interpreter_model_notify_reset(¬ify);
|
||||
}
|
||||
};
|
||||
|
||||
auto wrapper = std::make_shared<ModelWrapper>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue