1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibGUI: Make ItemListModels filterable

Implements data_matches() for proxy filtering and handles valid parent
indices in row_count(). This fixes an infinite recursion when filtering
matches for models without any hierarchy.
This commit is contained in:
thankyouverycool 2022-02-16 10:03:12 -05:00 committed by Tim Flynn
parent 8fa334a70c
commit de9dfc13b1

View file

@ -36,9 +36,11 @@ public:
virtual ~ItemListModel() override { }
virtual int row_count(ModelIndex const&) const override
virtual int row_count(ModelIndex const& index) const override
{
if (!index.is_valid())
return m_provided_row_count.has_value() ? *m_provided_row_count : m_data.size();
return 0;
}
virtual int column_count(ModelIndex const& index) const override
@ -77,6 +79,13 @@ public:
return {};
}
virtual TriState data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override
{
if (index.data().as_string().contains(term.as_string(), CaseSensitivity::CaseInsensitive))
return TriState::True;
return TriState::False;
}
virtual bool is_searchable() const override { return true; }
virtual Vector<GUI::ModelIndex> matches(StringView searching, unsigned flags, GUI::ModelIndex const&) override
{