From 2f67564ea9565bd4bb870416c543cbbff65eebcd Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 19 Apr 2022 12:10:59 +0200 Subject: [PATCH] C++: add a Model::row_data_tracked function --- api/cpp/include/slint.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/cpp/include/slint.h b/api/cpp/include/slint.h index 19eff9e4e..1e4775152 100644 --- a/api/cpp/include/slint.h +++ b/api/cpp/include/slint.h @@ -527,8 +527,7 @@ using ModelPeer = std::weak_ptr; template auto access_array_index(const M &model, int index) { - model->track_row_data_changes(index); - if (const auto v = model->row_data(index)) { + if (const auto v = model->row_data_tracked(index)) { return *v; } else { return decltype(*v) {}; @@ -589,6 +588,14 @@ public: model_row_data_dirty_property.get(); } + /// \private + /// Convenience function that calls `track_row_data_changes` before returning `row_data` + std::optional row_data_tracked(int row) const + { + const_cast(this)->track_row_data_changes(row); + return row_data(row); + } + protected: /// Notify the views that a specific row was changed void row_changed(int row)