mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +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
|
@ -73,6 +73,35 @@ TEST_CASE("Property Tracker")
|
|||
REQUIRE(!tracker1.is_dirty());
|
||||
}
|
||||
|
||||
TEST_CASE("Model row changes")
|
||||
{
|
||||
using namespace sixtyfps::private_api;
|
||||
|
||||
auto model = std::make_shared<sixtyfps::VectorModel<int>>();
|
||||
|
||||
PropertyTracker tracker;
|
||||
|
||||
REQUIRE(tracker.evaluate([&]() {
|
||||
model->track_row_count_changes();
|
||||
return model->row_count();
|
||||
}) == 0);
|
||||
REQUIRE(!tracker.is_dirty());
|
||||
model->push_back(1);
|
||||
model->push_back(2);
|
||||
REQUIRE(tracker.is_dirty());
|
||||
REQUIRE(tracker.evaluate([&]() {
|
||||
model->track_row_count_changes();
|
||||
return model->row_count();
|
||||
}) == 2);
|
||||
REQUIRE(!tracker.is_dirty());
|
||||
model->erase(0);
|
||||
REQUIRE(tracker.is_dirty());
|
||||
REQUIRE(tracker.evaluate([&]() {
|
||||
model->track_row_count_changes();
|
||||
return model->row_count();
|
||||
}) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Image")
|
||||
{
|
||||
using namespace sixtyfps;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue