summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-04 18:40:21 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-04 18:40:21 +0200
commita5799ed46229211c056138bea685fb70c4449d9e (patch)
tree565b82f2c42a3ae50e9ccdb1a54328e680ae3f84 /Libraries
parentd8518637040d31a33a81be8d8e2ce7f869f0a59d (diff)
downloadserenity-a5799ed46229211c056138bea685fb70c4449d9e.zip
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.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibGUI/Model.h2
-rw-r--r--Libraries/LibGUI/SortingProxyModel.cpp4
-rw-r--r--Libraries/LibGUI/SortingProxyModel.h4
3 files changed, 7 insertions, 3 deletions
diff --git a/Libraries/LibGUI/Model.h b/Libraries/LibGUI/Model.h
index 2999c982a7..9af578fbaa 100644
--- a/Libraries/LibGUI/Model.h
+++ b/Libraries/LibGUI/Model.h
@@ -54,13 +54,13 @@ public:
enum class Role {
Display,
Sort,
- Custom,
ForegroundColor,
BackgroundColor,
Icon,
Font,
DragData,
TextAlignment,
+ Custom = 0x100, // Applications are free to use roles above this number as they please
};
virtual ~Model();
diff --git a/Libraries/LibGUI/SortingProxyModel.cpp b/Libraries/LibGUI/SortingProxyModel.cpp
index 4e00e287ca..07dd92e046 100644
--- a/Libraries/LibGUI/SortingProxyModel.cpp
+++ b/Libraries/LibGUI/SortingProxyModel.cpp
@@ -112,8 +112,8 @@ void SortingProxyModel::resort()
return;
}
quick_sort(m_row_mappings, [&](auto row1, auto row2) -> bool {
- auto data1 = target().data(target().index(row1, m_key_column), Model::Role::Sort);
- auto data2 = target().data(target().index(row2, 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), m_sort_role);
if (data1 == data2)
return 0;
bool is_less_than;
diff --git a/Libraries/LibGUI/SortingProxyModel.h b/Libraries/LibGUI/SortingProxyModel.h
index 6e8751f4cf..5857ef747a 100644
--- a/Libraries/LibGUI/SortingProxyModel.h
+++ b/Libraries/LibGUI/SortingProxyModel.h
@@ -49,6 +49,9 @@ public:
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:
explicit SortingProxyModel(NonnullRefPtr<Model>&&);
@@ -64,6 +67,7 @@ private:
Vector<int> m_row_mappings;
int m_key_column { -1 };
SortOrder m_sort_order { SortOrder::Ascending };
+ Role m_sort_role { Role::Sort };
bool m_sorting_case_sensitive { false };
};