1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10: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:
Tim Ledbetter 2023-04-26 17:23:08 +01:00 committed by Andrew Kaster
parent a042c4e93d
commit 556c4ac358
15 changed files with 89 additions and 51 deletions

View file

@ -62,13 +62,18 @@ public:
MatchFull = 1 << 3,
};
struct MatchResult {
TriState matched { TriState::Unknown };
int score { 0 };
};
virtual ~Model();
virtual int row_count(ModelIndex const& = ModelIndex()) const = 0;
virtual int column_count(ModelIndex const& = ModelIndex()) const = 0;
virtual String column_name(int) const { return {}; }
virtual Variant data(ModelIndex const&, ModelRole = ModelRole::Display) const = 0;
virtual TriState data_matches(ModelIndex const&, Variant const&) const { return TriState::Unknown; }
virtual MatchResult data_matches(ModelIndex const&, Variant const&) const { return {}; }
virtual void invalidate();
virtual ModelIndex parent_index(ModelIndex const&) const { return {}; }
virtual ModelIndex index(int row, int column = 0, ModelIndex const& parent = ModelIndex()) const;