mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	LibGUI: Replace ColumnMetadata::sortable => Model::is_column_sortable()
Now there's only one thing left in ColumnMetadata: the initial width.
This commit is contained in:
		
							parent
							
								
									2e03bded43
								
							
						
					
					
						commit
						c666c251c8
					
				
					 6 changed files with 12 additions and 9 deletions
				
			
		|  | @ -150,7 +150,7 @@ void AbstractTableView::paint_headers(Painter& painter) | |||
|         bool is_key_column = model()->key_column() == column_index; | ||||
|         Gfx::Rect cell_rect(x_offset, 0, column_width + horizontal_padding() * 2, header_height()); | ||||
|         bool pressed = column_index == m_pressed_column_header_index && m_pressed_column_header_is_pressed; | ||||
|         bool hovered = column_index == m_hovered_column_header_index && model()->column_metadata(column_index).sortable == Model::ColumnMetadata::Sortable::True; | ||||
|         bool hovered = column_index == m_hovered_column_header_index && model()->is_column_sortable(column_index); | ||||
|         Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered); | ||||
|         String text; | ||||
|         if (is_key_column) { | ||||
|  | @ -372,8 +372,7 @@ void AbstractTableView::mousedown_event(MouseEvent& event) | |||
|                 return; | ||||
|             } | ||||
|             auto header_rect = this->header_rect(i); | ||||
|             auto column_metadata = model()->column_metadata(i); | ||||
|             if (header_rect.contains(horizontally_adjusted_position) && column_metadata.sortable == Model::ColumnMetadata::Sortable::True) { | ||||
|             if (header_rect.contains(horizontally_adjusted_position) && model()->is_column_sortable(i)) { | ||||
|                 m_pressed_column_header_index = i; | ||||
|                 m_pressed_column_header_is_pressed = true; | ||||
|                 update_headers(); | ||||
|  |  | |||
|  | @ -572,7 +572,7 @@ Model::ColumnMetadata FileSystemModel::column_metadata(int column) const | |||
| { | ||||
|     switch (column) { | ||||
|     case Column::Icon: | ||||
|         return { 16, Model::ColumnMetadata::Sortable::False }; | ||||
|         return { 16 }; | ||||
|     case Column::Name: | ||||
|         return { 120 }; | ||||
|     case Column::Size: | ||||
|  |  | |||
|  | @ -148,6 +148,7 @@ public: | |||
|     virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; | ||||
|     virtual StringView drag_data_type() const override { return "text/uri-list"; } | ||||
|     virtual bool accepts_drag(const ModelIndex&, const StringView& data_type) override; | ||||
|     virtual bool is_column_sortable(int column_index) const override { return column_index != Column::Icon; } | ||||
| 
 | ||||
|     static String timestamp_string(time_t timestamp) | ||||
|     { | ||||
|  |  | |||
|  | @ -48,11 +48,6 @@ class Model : public RefCounted<Model> { | |||
| public: | ||||
|     struct ColumnMetadata { | ||||
|         int preferred_width { 0 }; | ||||
|         enum class Sortable { | ||||
|             False, | ||||
|             True, | ||||
|         }; | ||||
|         Sortable sortable { Sortable::True }; | ||||
|     }; | ||||
| 
 | ||||
|     enum UpdateFlag { | ||||
|  | @ -89,6 +84,8 @@ public: | |||
|     virtual int tree_column() const { return 0; } | ||||
|     virtual bool accepts_drag(const ModelIndex&, const StringView& data_type); | ||||
| 
 | ||||
|     virtual bool is_column_sortable([[maybe_unused]] int column_index) const { return true; } | ||||
| 
 | ||||
|     bool is_valid(const ModelIndex& index) const | ||||
|     { | ||||
|         auto parent_index = this->parent_index(index); | ||||
|  |  | |||
|  | @ -153,4 +153,9 @@ void SortingProxyModel::resort() | |||
|     }); | ||||
| } | ||||
| 
 | ||||
| bool SortingProxyModel::is_column_sortable(int column_index) const | ||||
| { | ||||
|     return target().is_column_sortable(column_index); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -47,6 +47,7 @@ public: | |||
|     virtual int key_column() const override { return m_key_column; } | ||||
|     virtual SortOrder sort_order() const override { return m_sort_order; } | ||||
|     virtual void set_key_column_and_sort_order(int, SortOrder) override; | ||||
|     virtual bool is_column_sortable(int column_index) const override; | ||||
| 
 | ||||
|     ModelIndex map_to_target(const ModelIndex&) const; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling