1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

LibGUI: Add SortingProxyModel::sort_role()

This allows you to specify a role to sort by. Defaults to Role::Sort.
Also reordered the Role enum so that Role::Custom is last.
This commit is contained in:
Andreas Kling 2020-07-04 18:40:21 +02:00
parent d851863704
commit a5799ed462
3 changed files with 7 additions and 3 deletions

View file

@ -54,13 +54,13 @@ public:
enum class Role { enum class Role {
Display, Display,
Sort, Sort,
Custom,
ForegroundColor, ForegroundColor,
BackgroundColor, BackgroundColor,
Icon, Icon,
Font, Font,
DragData, DragData,
TextAlignment, TextAlignment,
Custom = 0x100, // Applications are free to use roles above this number as they please
}; };
virtual ~Model(); virtual ~Model();

View file

@ -112,8 +112,8 @@ void SortingProxyModel::resort()
return; return;
} }
quick_sort(m_row_mappings, [&](auto row1, auto row2) -> bool { quick_sort(m_row_mappings, [&](auto row1, auto row2) -> bool {
auto data1 = target().data(target().index(row1, m_key_column), Model::Role::Sort); auto data1 = target().data(target().index(row1, m_key_column), m_sort_role);
auto data2 = target().data(target().index(row2, m_key_column), Model::Role::Sort); auto data2 = target().data(target().index(row2, m_key_column), m_sort_role);
if (data1 == data2) if (data1 == data2)
return 0; return 0;
bool is_less_than; bool is_less_than;

View file

@ -49,6 +49,9 @@ public:
ModelIndex map_to_target(const ModelIndex&) const; ModelIndex map_to_target(const ModelIndex&) const;
Role sort_role() const { return m_sort_role; }
void set_sort_role(Role role) { m_sort_role = role; }
private: private:
explicit SortingProxyModel(NonnullRefPtr<Model>&&); explicit SortingProxyModel(NonnullRefPtr<Model>&&);
@ -64,6 +67,7 @@ private:
Vector<int> m_row_mappings; Vector<int> m_row_mappings;
int m_key_column { -1 }; int m_key_column { -1 };
SortOrder m_sort_order { SortOrder::Ascending }; SortOrder m_sort_order { SortOrder::Ascending };
Role m_sort_role { Role::Sort };
bool m_sorting_case_sensitive { false }; bool m_sorting_case_sensitive { false };
}; };