mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
LibGUI: Allow FilteringProxyModel to optionally sort results by score
When the `FilteringOptions::SortByScore` flag is set, filtered indices are sorted by match score in descending order, meaning the most relevant results should appear first. The default behavior of FilteringProxyModel is unchanged.
This commit is contained in:
parent
a042c4e93d
commit
556c4ac358
15 changed files with 89 additions and 51 deletions
|
@ -16,15 +16,19 @@ GUI::Variant BasicModel::data(GUI::ModelIndex const& index, GUI::ModelRole role)
|
|||
return m_items.at(index.row());
|
||||
}
|
||||
|
||||
TriState BasicModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& data) const
|
||||
GUI::Model::MatchResult BasicModel::data_matches(GUI::ModelIndex const& index, GUI::Variant const& data) const
|
||||
{
|
||||
if (!is_within_range(index))
|
||||
return TriState::False;
|
||||
return { TriState::False };
|
||||
if (!data.is_string())
|
||||
return TriState::False;
|
||||
return { TriState::False };
|
||||
|
||||
auto& value = m_items.at(index.row());
|
||||
return value.contains(data.as_string()) ? TriState::True : TriState::False;
|
||||
|
||||
if (value.contains(data.as_string()))
|
||||
return { TriState::True };
|
||||
|
||||
return { TriState::False };
|
||||
}
|
||||
|
||||
void BasicModel::invalidate()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue