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:
Andreas Kling 2020-05-21 19:45:15 +02:00
parent 2e03bded43
commit c666c251c8
Notes: sideshowbarker 2024-07-19 06:16:40 +09:00
6 changed files with 12 additions and 9 deletions

View File

@ -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();

View File

@ -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:

View File

@ -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)
{

View File

@ -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);

View File

@ -153,4 +153,9 @@ void SortingProxyModel::resort()
});
}
bool SortingProxyModel::is_column_sortable(int column_index) const
{
return target().is_column_sortable(column_index);
}
}

View File

@ -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;