Skip to content

Commit

Permalink
LibGUI: Get rid of Model::ColumnMetadata and always use auto-sizing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awesomekling committed May 21, 2020
1 parent c666c25 commit 2adb0a0
Show file tree
Hide file tree
Showing 38 changed files with 1 addition and 216 deletions.
3 changes: 0 additions & 3 deletions Applications/Browser/InspectorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ InspectorWidget::InspectorWidget()
auto& tab_widget = splitter.add<GUI::TabWidget>();

m_style_table_view = tab_widget.add_tab<GUI::TableView>("Styles");
m_style_table_view->set_size_columns_to_fit_content(true);

m_computed_style_table_view = tab_widget.add_tab<GUI::TableView>("Computed");
m_computed_style_table_view->set_size_columns_to_fit_content(true);
}

InspectorWidget::~InspectorWidget()
Expand Down
5 changes: 0 additions & 5 deletions Applications/Calendar/AddEventDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ String AddEventDialog::MonthListModel::column_name(int column) const
}
}

GUI::Model::ColumnMetadata AddEventDialog::MonthListModel::column_metadata([[maybe_unused]] int column) const
{
return {};
}

GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, Role role) const
{
auto& month = Calendar::name_of_month(index.row() + 1);
Expand Down
1 change: 0 additions & 1 deletion Applications/Calendar/AddEventDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class AddEventDialog final : public GUI::Dialog {
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) const override;
virtual ColumnMetadata column_metadata(int) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;

Expand Down
5 changes: 0 additions & 5 deletions Applications/DisplaySettings/ItemListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class ItemListModel final : public GUI::Model {
return "Data";
}

virtual ColumnMetadata column_metadata(int) const override
{
return { 70 };
}

virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override
{
if (role == Role::TextAlignment)
Expand Down
1 change: 0 additions & 1 deletion Applications/IRCClient/IRCAppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ void IRCAppWindow::setup_widgets()
m_window_list = horizontal_container.add<GUI::TableView>();
m_window_list->set_headers_visible(false);
m_window_list->set_alternating_row_colors(false);
m_window_list->set_size_columns_to_fit_content(true);
m_window_list->set_model(m_client->client_window_list_model());
m_window_list->set_activates_on_selection(true);
m_window_list->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
Expand Down
9 changes: 0 additions & 9 deletions Applications/IRCClient/IRCChannelMemberListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ String IRCChannelMemberListModel::column_name(int column) const
ASSERT_NOT_REACHED();
}

GUI::Model::ColumnMetadata IRCChannelMemberListModel::column_metadata(int column) const
{
switch (column) {
case Column::Name:
return { 70 };
}
ASSERT_NOT_REACHED();
}

GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, Role role) const
{
if (role == Role::TextAlignment)
Expand Down
1 change: 0 additions & 1 deletion Applications/IRCClient/IRCChannelMemberListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class IRCChannelMemberListModel final : public GUI::Model {
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual ColumnMetadata column_metadata(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;
virtual String nick_at(const GUI::ModelIndex& index) const;
Expand Down
9 changes: 0 additions & 9 deletions Applications/IRCClient/IRCWindowListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ String IRCWindowListModel::column_name(int column) const
ASSERT_NOT_REACHED();
}

GUI::Model::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
{
switch (column) {
case Column::Name:
return { 70 };
}
ASSERT_NOT_REACHED();
}

GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, Role role) const
{
if (role == Role::TextAlignment)
Expand Down
1 change: 0 additions & 1 deletion Applications/IRCClient/IRCWindowListModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class IRCWindowListModel final : public GUI::Model {
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual ColumnMetadata column_metadata(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;

Expand Down
1 change: 0 additions & 1 deletion Applications/PixelPaint/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ int main(int argc, char** argv)
right_panel.set_layout<GUI::VerticalBoxLayout>();

auto& layer_table_view = right_panel.add<GUI::TableView>();
layer_table_view.set_size_columns_to_fit_content(true);

window->show();

Expand Down
18 changes: 0 additions & 18 deletions Applications/SystemMonitor/DevicesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ String DevicesModel::column_name(int column) const
}
}

GUI::Model::ColumnMetadata DevicesModel::column_metadata(int column) const
{
switch (column) {
case Column::Device:
return { 70 };
case Column::Major:
return { 32 };
case Column::Minor:
return { 32 };
case Column::ClassName:
return { 120 };
case Column::Type:
return { 120 };
default:
ASSERT_NOT_REACHED();
}
}

GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const
{
ASSERT(is_valid(index));
Expand Down
1 change: 0 additions & 1 deletion Applications/SystemMonitor/DevicesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class DevicesModel final : public GUI::Model {
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual ColumnMetadata column_metadata(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;

Expand Down
2 changes: 0 additions & 2 deletions Applications/SystemMonitor/NetworkStatisticsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
adapters_group_box.set_preferred_size(0, 120);

m_adapter_table_view = adapters_group_box.add<GUI::TableView>();
m_adapter_table_view->set_size_columns_to_fit_content(true);

Vector<GUI::JsonArrayModel::FieldSpec> net_adapters_fields;
net_adapters_fields.empend("name", "Name", Gfx::TextAlignment::CenterLeft);
Expand All @@ -64,7 +63,6 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
sockets_group_box.set_preferred_size(0, 0);

m_socket_table_view = sockets_group_box.add<GUI::TableView>();
m_socket_table_view->set_size_columns_to_fit_content(true);

Vector<GUI::JsonArrayModel::FieldSpec> net_tcp_fields;
net_tcp_fields.empend("peer_address", "Peer", Gfx::TextAlignment::CenterLeft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ProcessFileDescriptorMapWidget::ProcessFileDescriptorMapWidget()
set_layout<GUI::VerticalBoxLayout>();
layout()->set_margins({ 4, 4, 4, 4 });
m_table_view = add<GUI::TableView>();
m_table_view->set_size_columns_to_fit_content(true);

Vector<GUI::JsonArrayModel::FieldSpec> pid_fds_fields;
pid_fds_fields.empend("fd", "FD", Gfx::TextAlignment::CenterRight);
Expand Down
1 change: 0 additions & 1 deletion Applications/SystemMonitor/ProcessMemoryMapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget()
set_layout<GUI::VerticalBoxLayout>();
layout()->set_margins({ 4, 4, 4, 4 });
m_table_view = add<GUI::TableView>();
m_table_view->set_size_columns_to_fit_content(true);
Vector<GUI::JsonArrayModel::FieldSpec> pid_vm_fields;
pid_vm_fields.empend("Address", Gfx::TextAlignment::CenterLeft, [](auto& object) {
return String::format("%#x", object.get("address").to_u32());
Expand Down
62 changes: 0 additions & 62 deletions Applications/SystemMonitor/ProcessModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,68 +128,6 @@ String ProcessModel::column_name(int column) const
}
}

GUI::Model::ColumnMetadata ProcessModel::column_metadata(int column) const
{
switch (column) {
case Column::Icon:
return { 16 };
case Column::PID:
return { 32 };
case Column::TID:
return { 32 };
case Column::State:
return { 75 };
case Column::Priority:
return { 16 };
case Column::EffectivePriority:
return { 16 };
case Column::User:
return { 50 };
case Column::Virtual:
return { 65 };
case Column::Physical:
return { 65 };
case Column::DirtyPrivate:
return { 65 };
case Column::CleanInode:
return { 65 };
case Column::PurgeableVolatile:
return { 65 };
case Column::PurgeableNonvolatile:
return { 65 };
case Column::CPU:
return { 32 };
case Column::Name:
return { 140 };
case Column::Syscalls:
return { 60 };
case Column::InodeFaults:
return { 60 };
case Column::ZeroFaults:
return { 60 };
case Column::CowFaults:
return { 60 };
case Column::FileReadBytes:
return { 60 };
case Column::FileWriteBytes:
return { 60 };
case Column::UnixSocketReadBytes:
return { 60 };
case Column::UnixSocketWriteBytes:
return { 60 };
case Column::IPv4SocketReadBytes:
return { 60 };
case Column::IPv4SocketWriteBytes:
return { 60 };
case Column::Pledge:
return { 60 };
case Column::Veil:
return { 60 };
default:
ASSERT_NOT_REACHED();
}
}

static String pretty_byte_size(size_t size)
{
return String::format("%uK", size / 1024);
Expand Down
1 change: 0 additions & 1 deletion Applications/SystemMonitor/ProcessModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class ProcessModel final : public GUI::Model {
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) const override;
virtual ColumnMetadata column_metadata(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;

Expand Down
1 change: 0 additions & 1 deletion Applications/SystemMonitor/ProcessTableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

ProcessTableView::ProcessTableView()
{
set_size_columns_to_fit_content(true);
set_model(GUI::SortingProxyModel::create(ProcessModel::create()));
model()->set_key_column_and_sort_order(ProcessModel::Column::CPU, GUI::SortOrder::Descending);
refresh();
Expand Down
1 change: 0 additions & 1 deletion Applications/SystemMonitor/ProcessUnveiledPathsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ProcessUnveiledPathsWidget::ProcessUnveiledPathsWidget()
set_layout<GUI::VerticalBoxLayout>();
layout()->set_margins({ 4, 4, 4, 4 });
m_table_view = add<GUI::TableView>();
m_table_view->set_size_columns_to_fit_content(true);

Vector<GUI::JsonArrayModel::FieldSpec> pid_unveil_fields;
pid_unveil_fields.empend("path", "Path", Gfx::TextAlignment::CenterLeft);
Expand Down
3 changes: 0 additions & 3 deletions Applications/SystemMonitor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ NonnullRefPtr<GUI::Widget> build_file_systems_tab()
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
auto& fs_table_view = self.add<GUI::TableView>();
fs_table_view.set_size_columns_to_fit_content(true);

Vector<GUI::JsonArrayModel::FieldSpec> df_fields;
df_fields.empend("mount_point", "Mount point", Gfx::TextAlignment::CenterLeft);
Expand Down Expand Up @@ -402,7 +401,6 @@ NonnullRefPtr<GUI::Widget> build_pci_devices_tab()
self.set_layout<GUI::VerticalBoxLayout>();
self.layout()->set_margins({ 4, 4, 4, 4 });
auto& pci_table_view = self.add<GUI::TableView>();
pci_table_view.set_size_columns_to_fit_content(true);

auto db = PCIDB::Database::open();

Expand Down Expand Up @@ -461,7 +459,6 @@ NonnullRefPtr<GUI::Widget> build_devices_tab()
self.layout()->set_margins({ 4, 4, 4, 4 });

auto& devices_table_view = self.add<GUI::TableView>();
devices_table_view.set_size_columns_to_fit_content(true);
devices_table_view.set_model(GUI::SortingProxyModel::create(DevicesModel::create()));
devices_table_view.model()->update();
};
Expand Down
1 change: 0 additions & 1 deletion DevTools/HackStudio/FindInFilesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ FindInFilesWidget::FindInFilesWidget()
m_button->set_preferred_size(100, 0);

m_result_view = add<GUI::TableView>();
m_result_view->set_size_columns_to_fit_content(true);

m_result_view->on_activation = [](auto& index) {
auto& match = *(const Match*)index.internal_data();
Expand Down
1 change: 0 additions & 1 deletion DevTools/HackStudio/Locator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Locator::Locator()
m_popup_window->set_rect(0, 0, 500, 200);

m_suggestion_view = m_popup_window->set_main_widget<GUI::TableView>();
m_suggestion_view->set_size_columns_to_fit_content(true);
m_suggestion_view->set_headers_visible(false);

m_suggestion_view->on_activation = [this](auto& index) {
Expand Down
1 change: 0 additions & 1 deletion DevTools/Inspector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ int main(int argc, char** argv)
tree_view.set_activates_on_selection(true);

auto& properties_table_view = splitter.add<GUI::TableView>();
properties_table_view.set_size_columns_to_fit_content(true);
properties_table_view.set_editable(true);
properties_table_view.aid_create_editing_delegate = [](auto&) {
return make<GUI::StringModelEditingDelegate>();
Expand Down
2 changes: 0 additions & 2 deletions DevTools/ProfileViewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ int main(int argc, char** argv)

auto& tree_view = bottom_splitter.add<GUI::TreeView>();
tree_view.set_headers_visible(true);
tree_view.set_size_columns_to_fit_content(true);
tree_view.set_model(profile->model());

auto& disassembly_view = bottom_splitter.add<GUI::TableView>();
disassembly_view.set_size_columns_to_fit_content(true);

tree_view.on_selection = [&](auto& index) {
profile->set_disassembly_index(index);
Expand Down
8 changes: 0 additions & 8 deletions DevTools/VisualBuilder/VBWidgetPropertyModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ String VBWidgetPropertyModel::column_name(int column) const
}
}

GUI::Model::ColumnMetadata VBWidgetPropertyModel::column_metadata(int column) const
{
UNUSED_PARAM(column);
if (column == Column::Name)
return { 110 };
return { 90 };
}

GUI::Variant VBWidgetPropertyModel::data(const GUI::ModelIndex& index, Role role) const
{
if (role == Role::TextAlignment) {
Expand Down
1 change: 0 additions & 1 deletion DevTools/VisualBuilder/VBWidgetPropertyModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class VBWidgetPropertyModel : public GUI::Model {
virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; }
virtual String column_name(int column) const override;
virtual ColumnMetadata column_metadata(int column) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override { did_update(); }
virtual bool is_editable(const GUI::ModelIndex&) const override;
Expand Down
11 changes: 1 addition & 10 deletions Libraries/LibGUI/AbstractTableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ void AbstractTableView::select_all()

void AbstractTableView::update_column_sizes()
{
if (!m_size_columns_to_fit_content)
return;

if (!model())
return;

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions Libraries/LibGUI/AbstractTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class AbstractTableView : public AbstractView {
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<TableCellPaintingDelegate>&&);

int horizontal_padding() const { return m_horizontal_padding; }
Expand Down Expand Up @@ -117,7 +114,6 @@ class AbstractTableView : public AbstractView {

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 };
Expand Down
Loading

0 comments on commit 2adb0a0

Please sign in to comment.