diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-16 16:00:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-16 16:44:09 +0200 |
commit | a1e381a0f87edb396d9c8be90f77fd4bd27024d4 (patch) | |
tree | 63c8f74e970cdcb091796fceed8064705c2e0098 /Libraries | |
parent | f6d7204689a009ce804b56e9e921985d2e61fc19 (diff) | |
download | serenity-a1e381a0f87edb396d9c8be90f77fd4bd27024d4.zip |
LibGUI: Move GUI::Model::Role to GUI::ModelRole
This is preparation for using ModelRole in the ModelIndex API.
Diffstat (limited to 'Libraries')
25 files changed, 107 insertions, 75 deletions
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp index 1fcb9293ae..0dd19e8f29 100644 --- a/Libraries/LibGUI/AbstractView.cpp +++ b/Libraries/LibGUI/AbstractView.cpp @@ -134,7 +134,7 @@ void AbstractView::begin_editing(const ModelIndex& index) ASSERT(aid_create_editing_delegate); m_editing_delegate = aid_create_editing_delegate(index); m_editing_delegate->bind(*model(), index); - m_editing_delegate->set_value(model()->data(index, Model::Role::Display)); + m_editing_delegate->set_value(model()->data(index, ModelRole::Display)); m_edit_widget = m_editing_delegate->widget(); add_child(*m_edit_widget); m_edit_widget->move_to_back(); @@ -187,7 +187,7 @@ NonnullRefPtr<Gfx::Font> AbstractView::font_for_index(const ModelIndex& index) c if (!model()) return font(); - auto font_data = model()->data(index, Model::Role::Font); + auto font_data = model()->data(index, ModelRole::Font); if (font_data.is_font()) return font_data.as_font(); @@ -285,14 +285,14 @@ void AbstractView::mousemove_event(MouseEvent& event) text_builder.append(", "); text_builder.append(text_data.to_string()); - auto drag_data = m_model->data(index, Model::Role::DragData); + auto drag_data = m_model->data(index, ModelRole::DragData); data_builder.append(drag_data.to_string()); data_builder.append('\n'); first = false; if (!bitmap) { - Variant icon_data = model()->data(index, Model::Role::Icon); + Variant icon_data = model()->data(index, ModelRole::Icon); if (icon_data.is_icon()) bitmap = icon_data.as_icon().bitmap_for_size(32); } diff --git a/Libraries/LibGUI/ColumnsView.cpp b/Libraries/LibGUI/ColumnsView.cpp index ffc1e63cbf..2c27ce1312 100644 --- a/Libraries/LibGUI/ColumnsView.cpp +++ b/Libraries/LibGUI/ColumnsView.cpp @@ -125,7 +125,7 @@ void ColumnsView::paint_event(PaintEvent& event) Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() }; painter.fill_rect(row_rect, background_color); - auto icon = model()->data(index, Model::Role::Icon); + auto icon = model()->data(index, ModelRole::Icon); Gfx::IntRect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() }; icon_rect.center_vertically_within(row_rect); if (icon.is_icon()) { diff --git a/Libraries/LibGUI/FileSystemModel.cpp b/Libraries/LibGUI/FileSystemModel.cpp index 8bf9aa00a4..8c5035a760 100644 --- a/Libraries/LibGUI/FileSystemModel.cpp +++ b/Libraries/LibGUI/FileSystemModel.cpp @@ -349,11 +349,11 @@ ModelIndex FileSystemModel::parent_index(const ModelIndex& index) const return node.parent->index(*this, index.column()); } -Variant FileSystemModel::data(const ModelIndex& index, Role role) const +Variant FileSystemModel::data(const ModelIndex& index, ModelRole role) const { ASSERT(index.is_valid()); - if (role == Role::TextAlignment) { + if (role == ModelRole::TextAlignment) { switch (index.column()) { case Column::Icon: return Gfx::TextAlignment::Center; @@ -374,13 +374,13 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const auto& node = this->node(index); - if (role == Role::Custom) { + if (role == ModelRole::Custom) { // For GUI::FileSystemModel, custom role means the full path. ASSERT(index.column() == Column::Name); return node.full_path(*this); } - if (role == Role::DragData) { + if (role == ModelRole::DragData) { if (index.column() == Column::Name) { StringBuilder builder; builder.append("file://"); @@ -390,7 +390,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const return {}; } - if (role == Role::Sort) { + if (role == ModelRole::Sort) { switch (index.column()) { case Column::Icon: return node.is_directory() ? 0 : 1; @@ -414,7 +414,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const ASSERT_NOT_REACHED(); } - if (role == Role::Display) { + if (role == ModelRole::Display) { switch (index.column()) { case Column::Icon: return icon_for(node); @@ -437,7 +437,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const } } - if (role == Role::Icon) { + if (role == ModelRole::Icon) { return icon_for(node); } return {}; diff --git a/Libraries/LibGUI/FileSystemModel.h b/Libraries/LibGUI/FileSystemModel.h index 94bd3fbff1..c09bea5012 100644 --- a/Libraries/LibGUI/FileSystemModel.h +++ b/Libraries/LibGUI/FileSystemModel.h @@ -133,7 +133,7 @@ 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 Variant data(const ModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const override; virtual void update() override; virtual ModelIndex parent_index(const ModelIndex&) const override; virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; diff --git a/Libraries/LibGUI/FilteringProxyModel.cpp b/Libraries/LibGUI/FilteringProxyModel.cpp index 7d14b29a13..fe746a4c36 100644 --- a/Libraries/LibGUI/FilteringProxyModel.cpp +++ b/Libraries/LibGUI/FilteringProxyModel.cpp @@ -53,7 +53,7 @@ int FilteringProxyModel::column_count(const ModelIndex& index) const return m_model.column_count(m_matching_indices[index.row()]); } -Variant FilteringProxyModel::data(const ModelIndex& index, Role role) const +Variant FilteringProxyModel::data(const ModelIndex& index, ModelRole role) const { if (!index.is_valid()) return {}; @@ -84,7 +84,7 @@ void FilteringProxyModel::filter() auto filter_matches = m_model.data_matches(index, m_filter_term); bool matches = filter_matches == TriState::True; if (filter_matches == TriState::Unknown) { - auto data = m_model.data(index, Role::Display); + auto data = m_model.data(index, ModelRole::Display); if (data.is_string() && data.as_string().contains(m_filter_term)) matches = true; } diff --git a/Libraries/LibGUI/FilteringProxyModel.h b/Libraries/LibGUI/FilteringProxyModel.h index f5296c3e6b..422cec1b05 100644 --- a/Libraries/LibGUI/FilteringProxyModel.h +++ b/Libraries/LibGUI/FilteringProxyModel.h @@ -45,7 +45,7 @@ public: virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int column_count(const ModelIndex& = ModelIndex()) const override; - virtual Variant data(const ModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const override; virtual void update() override; virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp index 205d9bcc81..8723f73f91 100644 --- a/Libraries/LibGUI/IconView.cpp +++ b/Libraries/LibGUI/IconView.cpp @@ -438,8 +438,8 @@ void IconView::paint_event(PaintEvent& event) background_color = widget_background_color; } - auto icon = model()->data(item_data.index, Model::Role::Icon); - auto item_text = model()->data(item_data.index, Model::Role::Display); + auto icon = model()->data(item_data.index, ModelRole::Icon); + auto item_text = model()->data(item_data.index, ModelRole::Display); if (icon.is_icon()) { if (auto bitmap = icon.as_icon().bitmap_for_size(item_data.icon_rect.width())) { @@ -458,7 +458,7 @@ void IconView::paint_event(PaintEvent& event) if (item_data.selected) text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); else - text_color = model()->data(item_data.index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(item_data.index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); painter.fill_rect(item_data.text_rect, background_color); painter.draw_text(item_data.text_rect, item_text.to_string(), font_for_index(item_data.index), Gfx::TextAlignment::Center, text_color, Gfx::TextElision::Right); diff --git a/Libraries/LibGUI/JsonArrayModel.cpp b/Libraries/LibGUI/JsonArrayModel.cpp index e845602c14..0837dbcb55 100644 --- a/Libraries/LibGUI/JsonArrayModel.cpp +++ b/Libraries/LibGUI/JsonArrayModel.cpp @@ -92,16 +92,16 @@ bool JsonArrayModel::remove(int row) return true; } -Variant JsonArrayModel::data(const ModelIndex& index, Role role) const +Variant JsonArrayModel::data(const ModelIndex& index, ModelRole role) const { auto& field_spec = m_fields[index.column()]; auto& object = m_array.at(index.row()).as_object(); - if (role == Model::Role::TextAlignment) { + if (role == ModelRole::TextAlignment) { return field_spec.text_alignment; } - if (role == Model::Role::Display) { + if (role == ModelRole::Display) { auto& json_field_name = field_spec.json_field_name; auto data = object.get(json_field_name); if (field_spec.massage_for_display) @@ -111,13 +111,13 @@ Variant JsonArrayModel::data(const ModelIndex& index, Role role) const return object.get(json_field_name).to_string(); } - if (role == Model::Role::Sort) { + if (role == ModelRole::Sort) { if (field_spec.massage_for_sort) return field_spec.massage_for_sort(object); - return data(index, Role::Display); + return data(index, ModelRole::Display); } - if (role == Model::Role::Custom) { + if (role == ModelRole::Custom) { if (field_spec.massage_for_custom) return field_spec.massage_for_custom(object); return {}; diff --git a/Libraries/LibGUI/JsonArrayModel.h b/Libraries/LibGUI/JsonArrayModel.h index 0c59663663..9b19fb81e0 100644 --- a/Libraries/LibGUI/JsonArrayModel.h +++ b/Libraries/LibGUI/JsonArrayModel.h @@ -69,7 +69,7 @@ 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 Variant data(const ModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const override; virtual void update() override; const String& json_path() const { return m_json_path; } diff --git a/Libraries/LibGUI/ListView.cpp b/Libraries/LibGUI/ListView.cpp index 2b3d1785a2..73bea486f1 100644 --- a/Libraries/LibGUI/ListView.cpp +++ b/Libraries/LibGUI/ListView.cpp @@ -59,7 +59,7 @@ void ListView::update_content_size() int content_width = 0; for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) { - auto text = model()->data(model()->index(row, m_model_column), Model::Role::Display); + auto text = model()->data(model()->index(row, m_model_column), ModelRole::Display); content_width = max(content_width, font().width(text.to_string())); } @@ -162,11 +162,11 @@ void ListView::paint_event(PaintEvent& event) if (is_selected_row) text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); else - text_color = model()->data(index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); auto text_rect = row_rect; text_rect.move_by(horizontal_padding(), 0); text_rect.set_width(text_rect.width() - horizontal_padding() * 2); - auto text_alignment = model()->data(index, Model::Role::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); + auto text_alignment = model()->data(index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color); } diff --git a/Libraries/LibGUI/Model.h b/Libraries/LibGUI/Model.h index b6c57437fc..7aec5b231a 100644 --- a/Libraries/LibGUI/Model.h +++ b/Libraries/LibGUI/Model.h @@ -32,6 +32,7 @@ #include <AK/RefCounted.h> #include <AK/String.h> #include <LibGUI/ModelIndex.h> +#include <LibGUI/ModelRole.h> #include <LibGUI/Variant.h> #include <LibGfx/Forward.h> #include <LibGfx/TextAlignment.h> @@ -58,25 +59,12 @@ public: InvalidateAllIndexes = 1 << 0, }; - enum class Role { - Display, - Sort, - ForegroundColor, - BackgroundColor, - Icon, - Font, - DragData, - TextAlignment, - Search, - Custom = 0x100, // Applications are free to use roles above this number as they please - }; - virtual ~Model(); virtual int row_count(const ModelIndex& = ModelIndex()) const = 0; virtual int column_count(const ModelIndex& = ModelIndex()) const = 0; virtual String column_name(int) const { return {}; } - virtual Variant data(const ModelIndex&, Role = Role::Display) const = 0; + virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const = 0; virtual TriState data_matches(const ModelIndex&, Variant) const { return TriState::Unknown; } virtual void update() = 0; virtual ModelIndex parent_index(const ModelIndex&) const { return {}; } diff --git a/Libraries/LibGUI/ModelRole.h b/Libraries/LibGUI/ModelRole.h new file mode 100644 index 0000000000..79b868076d --- /dev/null +++ b/Libraries/LibGUI/ModelRole.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#pragma once + +namespace GUI { + +enum class ModelRole { + Display, + Sort, + ForegroundColor, + BackgroundColor, + Icon, + Font, + DragData, + TextAlignment, + Search, + Custom = 0x100, // Applications are free to use roles above this number as they please +}; + +} diff --git a/Libraries/LibGUI/ProcessChooser.cpp b/Libraries/LibGUI/ProcessChooser.cpp index 8cca04732d..7d3df57fd1 100644 --- a/Libraries/LibGUI/ProcessChooser.cpp +++ b/Libraries/LibGUI/ProcessChooser.cpp @@ -57,7 +57,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& m_table_view = widget.add<GUI::TableView>(); auto sorting_model = GUI::SortingProxyModel::create(RunningProcessesModel::create()); - sorting_model->set_sort_role(GUI::Model::Role::Display); + sorting_model->set_sort_role(GUI::ModelRole::Display); m_table_view->set_key_column_and_sort_order(RunningProcessesModel::Column::PID, GUI::SortOrder::Descending); m_table_view->set_model(sorting_model); @@ -96,7 +96,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& m_refresh_timer->on_timeout = [this] { auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update. if (!m_table_view->selection().is_empty()) { - auto pid_as_variant = m_table_view->model()->data(m_table_view->selection().first(), GUI::Model::Role::Custom); + auto pid_as_variant = m_table_view->model()->data(m_table_view->selection().first(), GUI::ModelRole::Custom); previous_selected_pid = pid_as_variant.as_i32(); } @@ -111,7 +111,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& auto column_index = 1; // Corresponds to PID column in the m_table_view. for (int row_index = 0; row_index < row_count; ++row_index) { auto cell_index = model->index(row_index, column_index); - auto pid_as_variant = model->data(cell_index, GUI::Model::Role::Custom); + auto pid_as_variant = model->data(cell_index, GUI::ModelRole::Custom); if (previous_selected_pid == pid_as_variant.as_i32()) { m_table_view->selection().set(cell_index); // Set only if PIDs are matched. } @@ -121,7 +121,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView& void ProcessChooser::set_pid_from_index_and_close(const ModelIndex& index) { - auto pid_as_variant = m_table_view->model()->data(index, GUI::Model::Role::Custom); + auto pid_as_variant = m_table_view->model()->data(index, GUI::ModelRole::Custom); m_pid = pid_as_variant.as_i32(); done(ExecOK); } diff --git a/Libraries/LibGUI/RunningProcessesModel.cpp b/Libraries/LibGUI/RunningProcessesModel.cpp index 8d3b2090d4..10da47d1c6 100644 --- a/Libraries/LibGUI/RunningProcessesModel.cpp +++ b/Libraries/LibGUI/RunningProcessesModel.cpp @@ -92,15 +92,15 @@ String RunningProcessesModel::column_name(int column_index) const ASSERT_NOT_REACHED(); } -GUI::Variant RunningProcessesModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant RunningProcessesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& process = m_processes[index.row()]; - if (role == Role::Custom) { + if (role == ModelRole::Custom) { return process.pid; } - if (role == Role::Display) { + if (role == ModelRole::Display) { switch (index.column()) { case Column::Icon: if (!process.icon) diff --git a/Libraries/LibGUI/RunningProcessesModel.h b/Libraries/LibGUI/RunningProcessesModel.h index ae29cea6f2..3d6ec20ceb 100644 --- a/Libraries/LibGUI/RunningProcessesModel.h +++ b/Libraries/LibGUI/RunningProcessesModel.h @@ -47,7 +47,7 @@ public: virtual int row_count(const GUI::ModelIndex&) const override; virtual int column_count(const GUI::ModelIndex&) const override; virtual String column_name(int column_index) const override; - virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; virtual void update() override; private: diff --git a/Libraries/LibGUI/SortingProxyModel.cpp b/Libraries/LibGUI/SortingProxyModel.cpp index 0752dc1206..440dd338e8 100644 --- a/Libraries/LibGUI/SortingProxyModel.cpp +++ b/Libraries/LibGUI/SortingProxyModel.cpp @@ -113,7 +113,7 @@ String SortingProxyModel::column_name(int column) const return source().column_name(column); } -Variant SortingProxyModel::data(const ModelIndex& proxy_index, Role role) const +Variant SortingProxyModel::data(const ModelIndex& proxy_index, ModelRole role) const { return source().data(map_to_source(proxy_index), role); } diff --git a/Libraries/LibGUI/SortingProxyModel.h b/Libraries/LibGUI/SortingProxyModel.h index 04b452210d..439b2b43e9 100644 --- a/Libraries/LibGUI/SortingProxyModel.h +++ b/Libraries/LibGUI/SortingProxyModel.h @@ -40,7 +40,7 @@ public: virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual String column_name(int) const override; - virtual Variant data(const ModelIndex&, Role = Role::Display) const override; + virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const override; virtual void update() override; virtual StringView drag_data_type() const override; virtual ModelIndex parent_index(const ModelIndex&) const override; @@ -53,8 +53,8 @@ public: ModelIndex map_to_source(const ModelIndex&) const; ModelIndex map_to_proxy(const ModelIndex&) const; - Role sort_role() const { return m_sort_role; } - void set_sort_role(Role role) { m_sort_role = role; } + ModelRole sort_role() const { return m_sort_role; } + void set_sort_role(ModelRole role) { m_sort_role = role; } virtual void sort(int column, SortOrder) override; @@ -84,7 +84,7 @@ private: NonnullRefPtr<Model> m_source; HashMap<ModelIndex, NonnullOwnPtr<Mapping>> m_mappings; - Role m_sort_role { Role::Sort }; + ModelRole m_sort_role { ModelRole::Sort }; int m_last_key_column { -1 }; SortOrder m_last_sort_order { SortOrder::Ascending }; }; diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp index 8387abb99f..e0da2140f9 100644 --- a/Libraries/LibGUI/TableView.cpp +++ b/Libraries/LibGUI/TableView.cpp @@ -128,13 +128,13 @@ void TableView::paint_event(PaintEvent& event) if (is_selected_row) text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); else - text_color = model()->data(cell_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); + text_color = model()->data(cell_index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); if (!is_selected_row) { - auto cell_background_color = model()->data(cell_index, Model::Role::BackgroundColor); + auto cell_background_color = model()->data(cell_index, ModelRole::BackgroundColor); if (cell_background_color.is_valid()) painter.fill_rect(cell_rect_for_fill, cell_background_color.to_color(background_color)); } - auto text_alignment = model()->data(cell_index, Model::Role::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); + auto text_alignment = model()->data(cell_index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); } } diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index 63f23156db..01c1407bea 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -171,7 +171,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const if (index.is_valid()) { auto& metadata = ensure_metadata_for_index(index); int x_offset = tree_column_x_offset + horizontal_padding() + indent_level * indent_width_in_pixels(); - auto node_text = model.data(index, Model::Role::Display).to_string(); + auto node_text = model.data(index, ModelRole::Display).to_string(); Gfx::IntRect rect = { x_offset, y_offset, icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), item_height() @@ -302,15 +302,15 @@ void TreeView::paint_event(PaintEvent& event) painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); } else { if (!is_selected_row) - text_color = model.data(cell_index, Model::Role::ForegroundColor).to_color(palette().color(foreground_role())); - auto text_alignment = model.data(cell_index, Model::Role::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); + text_color = model.data(cell_index, ModelRole::ForegroundColor).to_color(palette().color(foreground_role())); + auto text_alignment = model.data(cell_index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft); painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right); } } } else { // It's the tree column! Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; - auto icon = model.data(index, Model::Role::Icon); + auto icon = model.data(index, ModelRole::Icon); if (icon.is_icon()) { if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) @@ -323,7 +323,7 @@ void TreeView::paint_event(PaintEvent& event) icon_rect.right() + 1 + icon_spacing(), rect.y(), rect.width() - icon_size() - icon_spacing(), rect.height() }; - auto node_text = model.data(index, Model::Role::Display).to_string(); + auto node_text = model.data(index, ModelRole::Display).to_string(); painter.draw_text(text_rect, node_text, font_for_index(index), Gfx::TextAlignment::Center, text_color); auto index_at_indent = index; for (int i = indent_level; i > 0; --i) { diff --git a/Libraries/LibWeb/DOMTreeModel.cpp b/Libraries/LibWeb/DOMTreeModel.cpp index 018b42acb1..a8c30e2f23 100644 --- a/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Libraries/LibWeb/DOMTreeModel.cpp @@ -115,10 +115,10 @@ static String with_whitespace_collapsed(const StringView& string) return builder.to_string(); } -GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& node = *static_cast<DOM::Node*>(index.internal_data()); - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { if (node.is_document()) return m_document_icon; if (node.is_element()) @@ -126,7 +126,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const // FIXME: More node type icons? return m_text_icon; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (node.is_text()) return String::format("%s", with_whitespace_collapsed(downcast<DOM::Text>(node).data()).characters()); if (!node.is_element()) diff --git a/Libraries/LibWeb/DOMTreeModel.h b/Libraries/LibWeb/DOMTreeModel.h index d023d39f0d..42a568b306 100644 --- a/Libraries/LibWeb/DOMTreeModel.h +++ b/Libraries/LibWeb/DOMTreeModel.h @@ -42,7 +42,7 @@ public: virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; - virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual void update() override; diff --git a/Libraries/LibWeb/LayoutTreeModel.cpp b/Libraries/LibWeb/LayoutTreeModel.cpp index 43e19fa17e..3a681295f4 100644 --- a/Libraries/LibWeb/LayoutTreeModel.cpp +++ b/Libraries/LibWeb/LayoutTreeModel.cpp @@ -115,17 +115,17 @@ static String with_whitespace_collapsed(const StringView& string) return builder.to_string(); } -GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& node = *static_cast<LayoutNode*>(index.internal_data()); - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { if (node.is_root()) return m_document_icon; if (node.is_text()) return m_text_icon; return m_element_icon; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (node.is_text()) return String::format("LayoutText: %s", with_whitespace_collapsed(downcast<LayoutText>(node).text_for_rendering()).characters()); StringBuilder builder; diff --git a/Libraries/LibWeb/LayoutTreeModel.h b/Libraries/LibWeb/LayoutTreeModel.h index bbca5e4b22..f1deedcce1 100644 --- a/Libraries/LibWeb/LayoutTreeModel.h +++ b/Libraries/LibWeb/LayoutTreeModel.h @@ -42,7 +42,7 @@ public: virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; - virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual void update() override; diff --git a/Libraries/LibWeb/StylePropertiesModel.cpp b/Libraries/LibWeb/StylePropertiesModel.cpp index aaad7c4e75..123337db8e 100644 --- a/Libraries/LibWeb/StylePropertiesModel.cpp +++ b/Libraries/LibWeb/StylePropertiesModel.cpp @@ -61,10 +61,10 @@ String StylePropertiesModel::column_name(int column_index) const ASSERT_NOT_REACHED(); } } -GUI::Variant StylePropertiesModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant StylePropertiesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& value = m_values[index.row()]; - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (index.column() == Column::PropertyName) return value.name; if (index.column() == Column::PropertyValue) diff --git a/Libraries/LibWeb/StylePropertiesModel.h b/Libraries/LibWeb/StylePropertiesModel.h index 78396ab457..2c260b62f1 100644 --- a/Libraries/LibWeb/StylePropertiesModel.h +++ b/Libraries/LibWeb/StylePropertiesModel.h @@ -46,7 +46,7 @@ public: 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 GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; virtual void update() override; private: |