Template Class FilterModel

Inheritance Relationships

Base Type

Class Documentation

template<typename ModelData>
class FilterModel : public slint::Model<ModelData>

The FilterModel acts as an adapter model for a given source model by applying a filter function. The filter function is called for each row on the source model and if the filter accepts the row (i.e. returns true), the row is also visible in the FilterModel.

Public Functions

inline FilterModel(std::shared_ptr<Model<ModelData>> source_model, std::function<bool(const ModelData&)> filter_fn)

Constructs a new FilterModel that provides a limited view on the source_model by applying filter_fn on each row. If the provided function returns true, the row is exposed by the FilterModel.

inline virtual size_t row_count() const override

The amount of row in the model.

inline virtual std::optional<ModelData> row_data(size_t i) const override

Returns the data for a particular row. This function should be called with row < row_count().

inline virtual void set_row_data(size_t i, const ModelData &value) override

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

inline void reset()

Re-applies the model’s filter function on each row of the source model. Use this if state external to the filter function has changed.

inline int unfiltered_row(int filtered_row) const

Given the filtered_row index, this function returns the corresponding row index in the source model.

inline std::shared_ptr<Model<ModelData>> source_model() const

Returns the source model of this filter model.

Friends

friend struct private_api::FilterModelInner< ModelData >