diff options
author | ignas-sa <53993155+ignas-sa@users.noreply.github.com> | 2019-08-11 19:11:25 +0300 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-11 18:11:25 +0200 |
commit | 0faaa1e53a979d27683d1ff75c0e6e78d4c6daf0 (patch) | |
tree | 29f493f99aaf9dd62c5546a8e084a5527448d030 /Libraries | |
parent | b9223e4f04da8bdfa7274457b8423e6e988ac021 (diff) | |
download | serenity-0faaa1e53a979d27683d1ff75c0e6e78d4c6daf0.zip |
GSortingProxyModel: Sort case insensitively by default (#441)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/GSortingProxyModel.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/GSortingProxyModel.h | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/Libraries/LibGUI/GSortingProxyModel.cpp b/Libraries/LibGUI/GSortingProxyModel.cpp index 5bf379695b..0876f960d9 100644 --- a/Libraries/LibGUI/GSortingProxyModel.cpp +++ b/Libraries/LibGUI/GSortingProxyModel.cpp @@ -87,7 +87,11 @@ void GSortingProxyModel::resort() auto data2 = target().data(target().index(row2, m_key_column), GModel::Role::Sort); if (data1 == data2) return 0; - bool is_less_than = data1 < data2; + bool is_less_than; + if (data1.is_string() && data2.is_string() && !m_sorting_case_sensitive) + is_less_than = data1.as_string().to_lowercase() < data2.as_string().to_lowercase(); + else + is_less_than = data1 < data2; return m_sort_order == GSortOrder::Ascending ? is_less_than : !is_less_than; }); if (previously_selected_target_row != -1) { diff --git a/Libraries/LibGUI/GSortingProxyModel.h b/Libraries/LibGUI/GSortingProxyModel.h index d9f64a1ac1..a70ab4ce05 100644 --- a/Libraries/LibGUI/GSortingProxyModel.h +++ b/Libraries/LibGUI/GSortingProxyModel.h @@ -29,8 +29,12 @@ private: void resort(); + void set_sorting_case_sensitive(bool b) { m_sorting_case_sensitive = b; } + bool is_sorting_case_sensitive() { return m_sorting_case_sensitive; } + NonnullRefPtr<GModel> m_target; Vector<int> m_row_mappings; int m_key_column { -1 }; GSortOrder m_sort_order { GSortOrder::Ascending }; + bool m_sorting_case_sensitive { false }; }; |