From 2adb0a07e53695e1f636384a3323aba828d48e52 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 21 May 2020 19:52:04 +0200 Subject: LibGUI: Get rid of Model::ColumnMetadata and always use auto-sizing Auto-sizing of view columns is now enabled by default. This removes the last remaining need for ColumnMetadata, so this patch gets rid of it. --- Libraries/LibGUI/AbstractTableView.cpp | 11 +---------- Libraries/LibGUI/AbstractTableView.h | 4 ---- Libraries/LibGUI/FileSystemModel.cpp | 25 ------------------------- Libraries/LibGUI/FileSystemModel.h | 1 - Libraries/LibGUI/JsonArrayModel.cpp | 6 ------ Libraries/LibGUI/JsonArrayModel.h | 1 - Libraries/LibGUI/Model.h | 5 ----- Libraries/LibGUI/SortingProxyModel.cpp | 5 ----- Libraries/LibGUI/SortingProxyModel.h | 1 - Libraries/LibGUI/TreeView.cpp | 4 ---- 10 files changed, 1 insertion(+), 62 deletions(-) (limited to 'Libraries') diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp index 094f637d01..9e8694b0ad 100644 --- a/Libraries/LibGUI/AbstractTableView.cpp +++ b/Libraries/LibGUI/AbstractTableView.cpp @@ -59,9 +59,6 @@ void AbstractTableView::select_all() void AbstractTableView::update_column_sizes() { - if (!m_size_columns_to_fit_content) - return; - if (!model()) return; @@ -249,13 +246,7 @@ int AbstractTableView::column_width(int column_index) const { if (!model()) return 0; - auto& column_data = this->column_data(column_index); - if (!column_data.has_initialized_width) { - ASSERT(!m_size_columns_to_fit_content); - column_data.has_initialized_width = true; - column_data.width = model()->column_metadata(column_index).preferred_width; - } - return column_data.width; + return column_data(column_index).width; } void AbstractTableView::mousemove_event(MouseEvent& event) diff --git a/Libraries/LibGUI/AbstractTableView.h b/Libraries/LibGUI/AbstractTableView.h index 7fece2dd44..8ef3486f1d 100644 --- a/Libraries/LibGUI/AbstractTableView.h +++ b/Libraries/LibGUI/AbstractTableView.h @@ -52,9 +52,6 @@ public: bool is_column_hidden(int) const; void set_column_hidden(int, bool); - void set_size_columns_to_fit_content(bool b) { m_size_columns_to_fit_content = b; } - bool size_columns_to_fit_content() const { return m_size_columns_to_fit_content; } - void set_cell_painting_delegate(int column, OwnPtr&&); int horizontal_padding() const { return m_horizontal_padding; } @@ -117,7 +114,6 @@ protected: private: bool m_headers_visible { true }; - bool m_size_columns_to_fit_content { false }; bool m_in_column_resize { false }; bool m_alternating_row_colors { true }; int m_horizontal_padding { 5 }; diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 622bf94abc..fd1fe6fe3d 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -568,31 +568,6 @@ String FileSystemModel::column_name(int column) const ASSERT_NOT_REACHED(); } -Model::ColumnMetadata FileSystemModel::column_metadata(int column) const -{ - switch (column) { - case Column::Icon: - return { 16 }; - case Column::Name: - return { 120 }; - case Column::Size: - return { 80 }; - case Column::Owner: - return { 50 }; - case Column::Group: - return { 50 }; - case Column::ModificationTime: - return { 110 }; - case Column::Permissions: - return { 65 }; - case Column::Inode: - return { 60 }; - case Column::SymlinkTarget: - return { 120 }; - } - ASSERT_NOT_REACHED(); -} - bool FileSystemModel::accepts_drag(const ModelIndex& index, const StringView& data_type) { if (!index.is_valid()) diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index 2a80933da2..5e5ee27ea7 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -141,7 +141,6 @@ public: virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual String column_name(int column) const override; - virtual ColumnMetadata column_metadata(int column) const override; virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; virtual ModelIndex parent_index(const ModelIndex&) const override; diff --git a/Libraries/LibGUI/JsonArrayModel.cpp b/Libraries/LibGUI/JsonArrayModel.cpp index 9dd75001da..fee86003ea 100644 --- a/Libraries/LibGUI/JsonArrayModel.cpp +++ b/Libraries/LibGUI/JsonArrayModel.cpp @@ -91,12 +91,6 @@ bool JsonArrayModel::remove(int row) return true; } -Model::ColumnMetadata JsonArrayModel::column_metadata(int column) const -{ - ASSERT(column < static_cast(m_fields.size())); - return { 100 }; -} - Variant JsonArrayModel::data(const ModelIndex& index, Role role) const { auto& field_spec = m_fields[index.column()]; diff --git a/Libraries/LibGUI/JsonArrayModel.h b/Libraries/LibGUI/JsonArrayModel.h index f6366cf637..0c59663663 100644 --- a/Libraries/LibGUI/JsonArrayModel.h +++ b/Libraries/LibGUI/JsonArrayModel.h @@ -69,7 +69,6 @@ public: virtual int row_count(const ModelIndex& = ModelIndex()) const override { return m_array.size(); } virtual int column_count(const ModelIndex& = ModelIndex()) const override { return m_fields.size(); } virtual String column_name(int column) const override { return m_fields[column].column_name; } - virtual ColumnMetadata column_metadata(int) const override; virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; diff --git a/Libraries/LibGUI/Model.h b/Libraries/LibGUI/Model.h index 0ec45006ee..15a2789ff9 100644 --- a/Libraries/LibGUI/Model.h +++ b/Libraries/LibGUI/Model.h @@ -46,10 +46,6 @@ enum class SortOrder { class Model : public RefCounted { public: - struct ColumnMetadata { - int preferred_width { 0 }; - }; - enum UpdateFlag { DontInvalidateIndexes = 0, InvalidateAllIndexes = 1 << 0, @@ -73,7 +69,6 @@ public: virtual int column_count(const ModelIndex& = ModelIndex()) const = 0; virtual String row_name(int) const { return {}; } virtual String column_name(int) const { return {}; } - virtual ColumnMetadata column_metadata(int) const { return {}; } virtual Variant data(const ModelIndex&, Role = Role::Display) const = 0; virtual void update() = 0; virtual ModelIndex parent_index(const ModelIndex&) const { return {}; } diff --git a/Libraries/LibGUI/SortingProxyModel.cpp b/Libraries/LibGUI/SortingProxyModel.cpp index 27dc08f145..7bf6d7f6dc 100644 --- a/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Libraries/LibGUI/SortingProxyModel.cpp @@ -74,11 +74,6 @@ String SortingProxyModel::column_name(int index) const return target().column_name(index); } -Model::ColumnMetadata SortingProxyModel::column_metadata(int index) const -{ - return target().column_metadata(index); -} - Variant SortingProxyModel::data(const ModelIndex& index, Role role) const { auto target_index = map_to_target(index); diff --git a/Libraries/LibGUI/SortingProxyModel.h b/Libraries/LibGUI/SortingProxyModel.h index 4198ad1494..942a7403a3 100644 --- a/Libraries/LibGUI/SortingProxyModel.h +++ b/Libraries/LibGUI/SortingProxyModel.h @@ -39,7 +39,6 @@ public: virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual String row_name(int) const override; virtual String column_name(int) const override; - virtual ColumnMetadata column_metadata(int) const override; virtual Variant data(const ModelIndex&, Role = Role::Display) const override; virtual void update() override; virtual StringView drag_data_type() const override; diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index 51b9ae8456..e3b2f113e0 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -56,7 +56,6 @@ TreeView::TreeView() set_fill_with_background_color(true); set_background_role(ColorRole::Base); set_foreground_role(ColorRole::BaseText); - set_size_columns_to_fit_content(true); set_headers_visible(false); m_expand_bitmap = Gfx::Bitmap::load_from_file("/res/icons/treeview-expand.png"); m_collapse_bitmap = Gfx::Bitmap::load_from_file("/res/icons/treeview-collapse.png"); @@ -515,9 +514,6 @@ int TreeView::item_count() const void TreeView::update_column_sizes() { - if (!size_columns_to_fit_content()) - return; - if (!model()) return; -- cgit v1.2.3