mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:37:46 +00:00
LibGUI: Make ItemListModel searchable
This commit is contained in:
parent
8dbb996200
commit
c2a89cac4e
1 changed files with 31 additions and 0 deletions
|
@ -77,6 +77,37 @@ public:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool is_searchable() const override { return true; }
|
||||||
|
virtual Vector<GUI::ModelIndex, 1> matches(StringView const& searching, unsigned flags, GUI::ModelIndex const&) override
|
||||||
|
{
|
||||||
|
Vector<GUI::ModelIndex, 1> found_indices;
|
||||||
|
if constexpr (IsTwoDimensional) {
|
||||||
|
for (auto it = m_data.begin(); it != m_data.end(); ++it) {
|
||||||
|
for (auto it2d = (*it).begin(); it2d != (*it).end(); ++it2d) {
|
||||||
|
GUI::ModelIndex index = this->index(it.index(), it2d.index());
|
||||||
|
if (!string_matches(data(index, ModelRole::Display).as_string(), searching, flags))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found_indices.append(index);
|
||||||
|
if (flags & FirstMatchOnly)
|
||||||
|
return found_indices;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (auto it = m_data.begin(); it != m_data.end(); ++it) {
|
||||||
|
GUI::ModelIndex index = this->index(it.index());
|
||||||
|
if (!string_matches(data(index, ModelRole::Display).as_string(), searching, flags))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
found_indices.append(index);
|
||||||
|
if (flags & FirstMatchOnly)
|
||||||
|
return found_indices;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found_indices;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ItemListModel(const Container& data, Optional<size_t> row_count = {}) requires(!IsTwoDimensional)
|
explicit ItemListModel(const Container& data, Optional<size_t> row_count = {}) requires(!IsTwoDimensional)
|
||||||
: m_data(data)
|
: m_data(data)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue