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

GTableView: add 'sortable' column header flag.

This prevents sorting unsortable by unsortable things, like icons.
This commit is contained in:
Ignas S 2019-08-12 10:58:53 +03:00 committed by Andreas Kling
parent 57c92f943b
commit 823d5d097b
2 changed files with 3 additions and 1 deletions

View file

@ -44,6 +44,7 @@ public:
struct ColumnMetadata { struct ColumnMetadata {
int preferred_width { 0 }; int preferred_width { 0 };
TextAlignment text_alignment { TextAlignment::CenterLeft }; TextAlignment text_alignment { TextAlignment::CenterLeft };
bool sortable { true };
const Font* font { nullptr }; const Font* font { nullptr };
}; };

View file

@ -158,7 +158,8 @@ void GTableView::mousedown_event(GMouseEvent& event)
return; return;
} }
auto header_rect = this->header_rect(i); auto header_rect = this->header_rect(i);
if (header_rect.contains(event.position())) { auto column_metadata = model()->column_metadata(i);
if (header_rect.contains(event.position()) && column_metadata.sortable) {
auto new_sort_order = GSortOrder::Ascending; auto new_sort_order = GSortOrder::Ascending;
if (model()->key_column() == i) if (model()->key_column() == i)
new_sort_order = model()->sort_order() == GSortOrder::Ascending new_sort_order = model()->sort_order() == GSortOrder::Ascending