Ability to make change to the model property

This commit is contained in:
Olivier Goffart 2020-09-30 15:04:32 +02:00
parent 2d01b92c84
commit 2050f08f1e
5 changed files with 130 additions and 20 deletions

View file

@ -340,7 +340,10 @@ public:
}
int row_count() const override { return Count; }
ModelData row_data(int i) const override { return data[i]; }
void set_row_data(int i, const ModelData &value) override { data[i] = value; }
void set_row_data(int i, const ModelData &value) override {
data[i] = value;
this->row_changed(i);
}
};
/// Model to be used when we just want to repeat without data.
@ -472,6 +475,21 @@ public:
x.ptr->compute_layout({ &C::component_type, x.ptr.get() });
}
}
void model_set_row_data(int row, const ModelData &data) const {
if (model.is_dirty()) {
std::abort();
}
if (auto m = model.get()) {
m->set_row_data(row, data);
if (inner && inner->is_dirty) {
auto &c = inner->data[row];
if (c.state == RepeaterInner::State::Dirty && c.ptr) {
c.ptr->update_data(row, m->row_data(row));
}
}
}
}
};
Flickable::Flickable()