C++: add a Model::row_data_tracked function

This commit is contained in:
Olivier Goffart 2022-04-19 12:10:59 +02:00 committed by Olivier Goffart
parent fd44b2e651
commit 2f67564ea9

View file

@ -527,8 +527,7 @@ using ModelPeer = std::weak_ptr<AbstractRepeaterView>;
template<typename M>
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<ModelData> row_data_tracked(int row) const
{
const_cast<Model *>(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)