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

@ -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;