mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:37:34 +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:
parent
8fa334a70c
commit
de9dfc13b1
1 changed files with 11 additions and 2 deletions
|
@ -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
|
||||
{
|
||||
return m_provided_row_count.has_value() ? *m_provided_row_count : m_data.size();
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue