Template Class MapModel#

Inheritance Relationships#

Base Type#

Class Documentation#

template<typename SourceModelData, typename MappedModelData = SourceModelData>
class MapModel : public slint::Model<SourceModelData>#

The MapModel acts as an adapter model for a given source model by applying a mapping function. The mapping function is called for each row on the source model and allows transforming the values on the fly. The MapModel has two template parameters: The SourceModelData specifies the data type of the underlying source model, and the MappedModelData the data type of this MapModel. This permits not only changing the values of the underlying source model, but also changing the data type itself. For example a MapModel can be used to adapt a model that provides numbers to be a model that exposes all numbers converted to strings, by calling std::to_string on each value given in the mapping lambda expression.

Public Functions

inline MapModel(std::shared_ptr<Model<SourceModelData>> source_model, std::function<MappedModelData(const SourceModelData&)> map_fn)#

Constructs a new MapModel that provides an altered view on the source_model by applying map_fn on the data in each row.

inline virtual size_t row_count() const override#

The amount of row in the model.

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

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

inline std::shared_ptr<Model<SourceModelData>> source_model() const#

Returns the source model of this filter model.

Friends

friend struct private_api::MapModelInner< SourceModelData, MappedModelData >