mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 20:31:27 +00:00
C++: Add convenience functions to clear and replace the VectorModel's vector
This was requested by a customer recently and it seems rather straight-forward to implement and offer. `clear()` mirrors `std::vector::clear()` and `set_vector` mirrors the `set_vec` we have in Rust.
This commit is contained in:
parent
2871fadd5c
commit
8e0af0bf63
3 changed files with 48 additions and 0 deletions
|
|
@ -494,3 +494,34 @@ SCENARIO("Reverse Model Change")
|
|||
REQUIRE(reverse_model->row_data(2) == 10);
|
||||
REQUIRE(reverse_model->row_data(3) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("VectorModel clear and replace")
|
||||
{
|
||||
using namespace slint::private_api;
|
||||
|
||||
auto model = std::make_shared<slint::VectorModel<int>>(std::vector<int> { 0, 1, 2, 3, 4 });
|
||||
|
||||
auto observer = std::make_shared<ModelObserver>();
|
||||
model->attach_peer(observer);
|
||||
|
||||
REQUIRE(model->row_count() == 5);
|
||||
model->clear();
|
||||
REQUIRE(model->row_count() == 0);
|
||||
REQUIRE(observer->added_rows.empty());
|
||||
REQUIRE(observer->changed_rows.empty());
|
||||
REQUIRE(observer->removed_rows.empty());
|
||||
REQUIRE(observer->model_reset);
|
||||
observer->clear();
|
||||
|
||||
model->clear();
|
||||
REQUIRE(!observer->model_reset);
|
||||
observer->clear();
|
||||
|
||||
model->set_vector({ 2, 3, 4 });
|
||||
REQUIRE(model->row_count() == 3);
|
||||
REQUIRE(model->row_data(1) == 3);
|
||||
REQUIRE(observer->added_rows.empty());
|
||||
REQUIRE(observer->changed_rows.empty());
|
||||
REQUIRE(observer->removed_rows.empty());
|
||||
REQUIRE(observer->model_reset);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue