Print an warning in stderr when modifying read-only model

... and improve the documentation of Model
This commit is contained in:
Olivier Goffart 2021-08-31 09:54:29 +02:00 committed by Olivier Goffart
parent ab522eb147
commit e1be599bc0
3 changed files with 92 additions and 12 deletions

View file

@ -431,11 +431,17 @@ public:
/// Returns the data for a particular row. This function should be called with `row <
/// row_count()`.
virtual ModelData row_data(int i) const = 0;
/// Sets the data for a particular row. This function should be called with `row < row_count()`.
/// If the model cannot support data changes, then it is ok to do nothing (default
/// implementation). If the model can update the data, the implementation should also call
/// row_changed.
virtual void set_row_data(int, const ModelData &) {};
/// Sets the data for a particular row.
///
/// This function should only be called with `row < row_count()`.
///
/// If the model cannot support data changes, then it is ok to do nothing.
/// The default implementation will print a warning to stderr.
///
/// If the model can update the data, it should also call `row_changed`
virtual void set_row_data(int, const ModelData &) {
std::cerr << "Model::set_row_data was called on a read-only model" << std::endl;
};
/// \private
/// Internal function called by the view to register itself