From a1e381a0f87edb396d9c8be90f77fd4bd27024d4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 16 Aug 2020 16:00:07 +0200 Subject: [PATCH] LibGUI: Move GUI::Model::Role to GUI::ModelRole This is preparation for using ModelRole in the ModelIndex API. --- Applications/Calendar/AddEventDialog.cpp | 4 +- Applications/Calendar/AddEventDialog.h | 2 +- Applications/DisplaySettings/ItemListModel.h | 6 +-- Applications/FileManager/main.cpp | 2 +- Applications/Help/ManualModel.cpp | 8 ++-- Applications/Help/ManualModel.h | 2 +- .../IRCClient/IRCChannelMemberListModel.cpp | 8 ++-- .../IRCClient/IRCChannelMemberListModel.h | 2 +- Applications/IRCClient/IRCWindowListModel.cpp | 8 ++-- Applications/IRCClient/IRCWindowListModel.h | 2 +- .../CharacterMapFileListModel.h | 4 +- Applications/SystemMonitor/DevicesModel.cpp | 6 +-- Applications/SystemMonitor/DevicesModel.h | 2 +- .../SystemMonitor/ProcessMemoryMapWidget.cpp | 2 +- Applications/SystemMonitor/ProcessModel.cpp | 8 ++-- Applications/SystemMonitor/ProcessModel.h | 2 +- Applications/SystemMonitor/main.cpp | 6 +-- Demos/WidgetGallery/main.cpp | 4 +- .../HackStudio/Debugger/BacktraceModel.cpp | 4 +- DevTools/HackStudio/Debugger/BacktraceModel.h | 2 +- .../HackStudio/Debugger/VariablesModel.cpp | 6 +-- DevTools/HackStudio/Debugger/VariablesModel.h | 2 +- DevTools/HackStudio/FindInFilesWidget.cpp | 8 ++-- DevTools/HackStudio/Locator.cpp | 6 +-- DevTools/HackStudio/Project.cpp | 10 ++--- DevTools/HackStudio/WidgetTreeModel.cpp | 6 +-- DevTools/HackStudio/WidgetTreeModel.h | 2 +- DevTools/HackStudio/main.cpp | 2 +- DevTools/Inspector/RemoteObjectGraphModel.cpp | 6 +-- DevTools/Inspector/RemoteObjectGraphModel.h | 2 +- .../Inspector/RemoteObjectPropertyModel.cpp | 4 +- .../Inspector/RemoteObjectPropertyModel.h | 2 +- DevTools/Profiler/DisassemblyModel.cpp | 8 ++-- DevTools/Profiler/DisassemblyModel.h | 2 +- DevTools/Profiler/ProfileModel.cpp | 8 ++-- DevTools/Profiler/ProfileModel.h | 2 +- DevTools/VisualBuilder/VBPropertiesWindow.cpp | 6 +-- .../VisualBuilder/VBWidgetPropertyModel.cpp | 12 ++--- .../VisualBuilder/VBWidgetPropertyModel.h | 2 +- Libraries/LibGUI/AbstractView.cpp | 8 ++-- Libraries/LibGUI/ColumnsView.cpp | 2 +- Libraries/LibGUI/FileSystemModel.cpp | 14 +++--- Libraries/LibGUI/FileSystemModel.h | 2 +- Libraries/LibGUI/FilteringProxyModel.cpp | 4 +- Libraries/LibGUI/FilteringProxyModel.h | 2 +- Libraries/LibGUI/IconView.cpp | 6 +-- Libraries/LibGUI/JsonArrayModel.cpp | 12 ++--- Libraries/LibGUI/JsonArrayModel.h | 2 +- Libraries/LibGUI/ListView.cpp | 6 +-- Libraries/LibGUI/Model.h | 16 +------ Libraries/LibGUI/ModelRole.h | 44 +++++++++++++++++++ Libraries/LibGUI/ProcessChooser.cpp | 8 ++-- Libraries/LibGUI/RunningProcessesModel.cpp | 6 +-- Libraries/LibGUI/RunningProcessesModel.h | 2 +- Libraries/LibGUI/SortingProxyModel.cpp | 2 +- Libraries/LibGUI/SortingProxyModel.h | 8 ++-- Libraries/LibGUI/TableView.cpp | 6 +-- Libraries/LibGUI/TreeView.cpp | 10 ++--- Libraries/LibWeb/DOMTreeModel.cpp | 6 +-- Libraries/LibWeb/DOMTreeModel.h | 2 +- Libraries/LibWeb/LayoutTreeModel.cpp | 6 +-- Libraries/LibWeb/LayoutTreeModel.h | 2 +- Libraries/LibWeb/StylePropertiesModel.cpp | 4 +- Libraries/LibWeb/StylePropertiesModel.h | 2 +- .../ClipboardHistoryModel.cpp | 4 +- .../ClipboardHistory/ClipboardHistoryModel.h | 2 +- 66 files changed, 201 insertions(+), 167 deletions(-) create mode 100644 Libraries/LibGUI/ModelRole.h diff --git a/Applications/Calendar/AddEventDialog.cpp b/Applications/Calendar/AddEventDialog.cpp index 429690b50f..24b3ed30e5 100644 --- a/Applications/Calendar/AddEventDialog.cpp +++ b/Applications/Calendar/AddEventDialog.cpp @@ -146,10 +146,10 @@ String AddEventDialog::MonthListModel::column_name(int column) const } } -GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant AddEventDialog::MonthListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& month = Calendar::name_of_month(index.row() + 1); - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Month: return month; diff --git a/Applications/Calendar/AddEventDialog.h b/Applications/Calendar/AddEventDialog.h index 3d8ace75f1..b19394c3d8 100644 --- a/Applications/Calendar/AddEventDialog.h +++ b/Applications/Calendar/AddEventDialog.h @@ -58,7 +58,7 @@ private: 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: diff --git a/Applications/DisplaySettings/ItemListModel.h b/Applications/DisplaySettings/ItemListModel.h index e35be9b7e9..1ce1122ac7 100644 --- a/Applications/DisplaySettings/ItemListModel.h +++ b/Applications/DisplaySettings/ItemListModel.h @@ -52,11 +52,11 @@ public: return "Data"; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { - if (role == Role::TextAlignment) + if (role == GUI::ModelRole::TextAlignment) return Gfx::TextAlignment::CenterLeft; - if (role == Role::Display) + if (role == GUI::ModelRole::Display) return m_data.at(index.row()); return {}; diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index 9c6eb39742..a4b82b9edc 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -438,7 +438,7 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio view.selection().for_each_index([&](const GUI::ModelIndex& index) { auto parent_index = model.parent_index(index); auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index); - auto path = model.data(name_index, GUI::Model::Role::Custom).to_string(); + auto path = model.data(name_index, GUI::ModelRole::Custom).to_string(); paths.append(path); }); return paths; diff --git a/Applications/Help/ManualModel.cpp b/Applications/Help/ManualModel.cpp index 092a2b99b9..b8829f5077 100644 --- a/Applications/Help/ManualModel.cpp +++ b/Applications/Help/ManualModel.cpp @@ -155,17 +155,17 @@ int ManualModel::column_count(const GUI::ModelIndex&) const return 1; } -GUI::Variant ManualModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant ManualModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* node = static_cast(index.internal_data()); switch (role) { - case Role::Search: + case GUI::ModelRole::Search: if (!node->is_page()) return {}; return String(page_view(page_path(index)).value()); - case Role::Display: + case GUI::ModelRole::Display: return node->name(); - case Role::Icon: + case GUI::ModelRole::Icon: if (node->is_page()) return m_page_icon; if (node->is_open()) diff --git a/Applications/Help/ManualModel.h b/Applications/Help/ManualModel.h index f235b59c20..f2a9c47122 100644 --- a/Applications/Help/ManualModel.h +++ b/Applications/Help/ManualModel.h @@ -50,7 +50,7 @@ public: void update_section_node_on_toggle(const GUI::ModelIndex&, const bool); 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 TriState data_matches(const GUI::ModelIndex&, GUI::Variant) const override; virtual void update() override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; diff --git a/Applications/IRCClient/IRCChannelMemberListModel.cpp b/Applications/IRCClient/IRCChannelMemberListModel.cpp index 7b415ec817..22cdcd710f 100644 --- a/Applications/IRCClient/IRCChannelMemberListModel.cpp +++ b/Applications/IRCClient/IRCChannelMemberListModel.cpp @@ -57,11 +57,11 @@ String IRCChannelMemberListModel::column_name(int column) const ASSERT_NOT_REACHED(); } -GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant IRCChannelMemberListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - if (role == Role::TextAlignment) + if (role == GUI::ModelRole::TextAlignment) return Gfx::TextAlignment::CenterLeft; - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Name: return m_channel.member_at(index.row()); @@ -77,5 +77,5 @@ void IRCChannelMemberListModel::update() String IRCChannelMemberListModel::nick_at(const GUI::ModelIndex& index) const { - return data(index, IRCChannelMemberListModel::Role::Display).to_string(); + return data(index, GUI::ModelRole::Display).to_string(); } diff --git a/Applications/IRCClient/IRCChannelMemberListModel.h b/Applications/IRCClient/IRCChannelMemberListModel.h index aab7451391..99e4128fc6 100644 --- a/Applications/IRCClient/IRCChannelMemberListModel.h +++ b/Applications/IRCClient/IRCChannelMemberListModel.h @@ -42,7 +42,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) 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; virtual String nick_at(const GUI::ModelIndex& index) const; diff --git a/Applications/IRCClient/IRCWindowListModel.cpp b/Applications/IRCClient/IRCWindowListModel.cpp index 0a205111b3..10e20a689e 100644 --- a/Applications/IRCClient/IRCWindowListModel.cpp +++ b/Applications/IRCClient/IRCWindowListModel.cpp @@ -56,11 +56,11 @@ String IRCWindowListModel::column_name(int column) const ASSERT_NOT_REACHED(); } -GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - if (role == Role::TextAlignment) + if (role == GUI::ModelRole::TextAlignment) return Gfx::TextAlignment::CenterLeft; - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Name: { auto& window = m_client.window_at(index.row()); @@ -70,7 +70,7 @@ GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, Role role) c } } } - if (role == Role::ForegroundColor) { + if (role == GUI::ModelRole::ForegroundColor) { switch (index.column()) { case Column::Name: { auto& window = m_client.window_at(index.row()); diff --git a/Applications/IRCClient/IRCWindowListModel.h b/Applications/IRCClient/IRCWindowListModel.h index a93ddd49fb..4d0cc720b3 100644 --- a/Applications/IRCClient/IRCWindowListModel.h +++ b/Applications/IRCClient/IRCWindowListModel.h @@ -44,7 +44,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) 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/Applications/KeyboardSettings/CharacterMapFileListModel.h b/Applications/KeyboardSettings/CharacterMapFileListModel.h index 29d79e06d0..2091d46674 100644 --- a/Applications/KeyboardSettings/CharacterMapFileListModel.h +++ b/Applications/KeyboardSettings/CharacterMapFileListModel.h @@ -48,12 +48,12 @@ public: return 1; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { ASSERT(index.is_valid()); ASSERT(index.column() == 0); - if (role == Role::Display) + if (role == GUI::ModelRole::Display) return m_file_names.at(index.row()); return {}; diff --git a/Applications/SystemMonitor/DevicesModel.cpp b/Applications/SystemMonitor/DevicesModel.cpp index 5777d0f601..7ab4dddca1 100644 --- a/Applications/SystemMonitor/DevicesModel.cpp +++ b/Applications/SystemMonitor/DevicesModel.cpp @@ -73,11 +73,11 @@ String DevicesModel::column_name(int column) const } } -GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { ASSERT(is_valid(index)); - if (role == Role::TextAlignment) { + if (role == GUI::ModelRole::TextAlignment) { switch (index.column()) { case Column::Device: return Gfx::TextAlignment::CenterLeft; @@ -93,7 +93,7 @@ GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const return {}; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { const DeviceInfo& device = m_devices[index.row()]; switch (index.column()) { case Column::Device: diff --git a/Applications/SystemMonitor/DevicesModel.h b/Applications/SystemMonitor/DevicesModel.h index dde59df53e..dd8cacc7e0 100644 --- a/Applications/SystemMonitor/DevicesModel.h +++ b/Applications/SystemMonitor/DevicesModel.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) 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/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp b/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp index d0412954a5..ece75cd1dd 100644 --- a/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp +++ b/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp @@ -40,7 +40,7 @@ public: virtual void paint(GUI::Painter& painter, const Gfx::IntRect& a_rect, const Gfx::Palette&, const GUI::Model& model, const GUI::ModelIndex& index) override { auto rect = a_rect.shrunken(2, 2); - auto pagemap = model.data(index, GUI::Model::Role::Custom).to_string(); + auto pagemap = model.data(index, GUI::ModelRole::Custom).to_string(); float scale_factor = (float)pagemap.length() / (float)rect.width(); diff --git a/Applications/SystemMonitor/ProcessModel.cpp b/Applications/SystemMonitor/ProcessModel.cpp index bbe52779e0..0c42295a5c 100644 --- a/Applications/SystemMonitor/ProcessModel.cpp +++ b/Applications/SystemMonitor/ProcessModel.cpp @@ -156,11 +156,11 @@ static String pretty_byte_size(size_t size) return String::format("%uK", size / 1024); } -GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { ASSERT(is_valid(index)); - if (role == Role::TextAlignment) { + if (role == GUI::ModelRole::TextAlignment) { switch (index.column()) { case Column::Icon: case Column::Name: @@ -203,7 +203,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const auto it = m_threads.find(m_pids[index.row()]); auto& thread = *(*it).value; - if (role == Role::Sort) { + if (role == GUI::ModelRole::Sort) { switch (index.column()) { case Column::Icon: return 0; @@ -272,7 +272,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const return {}; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Icon: if (thread.current_state.icon_id != -1) { diff --git a/Applications/SystemMonitor/ProcessModel.h b/Applications/SystemMonitor/ProcessModel.h index a60053ef10..921fa964c2 100644 --- a/Applications/SystemMonitor/ProcessModel.h +++ b/Applications/SystemMonitor/ProcessModel.h @@ -89,7 +89,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) 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; struct CpuInfo { diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp index 9f35c8f835..26face0aa1 100644 --- a/Applications/SystemMonitor/main.cpp +++ b/Applications/SystemMonitor/main.cpp @@ -193,7 +193,7 @@ int main(int argc, char** argv) if (process_table_view.selection().is_empty()) return -1; auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), column); - return process_table_view.model()->data(pid_index, GUI::Model::Role::Display).to_i32(); + return process_table_view.model()->data(pid_index, GUI::ModelRole::Display).to_i32(); }; auto kill_action = GUI::Action::create("Kill process", { Mod_Ctrl, Key_K }, Gfx::Bitmap::load_from_file("/res/icons/kill16.png"), [&](const GUI::Action&) { @@ -340,9 +340,9 @@ public: virtual void paint(GUI::Painter& painter, const Gfx::IntRect& a_rect, const Palette& palette, const GUI::Model& model, const GUI::ModelIndex& index) override { auto rect = a_rect.shrunken(2, 2); - auto percentage = model.data(index, GUI::Model::Role::Custom).to_i32(); + auto percentage = model.data(index, GUI::ModelRole::Custom).to_i32(); - auto data = model.data(index, GUI::Model::Role::Display); + auto data = model.data(index, GUI::ModelRole::Display); String text; if (data.is_string()) text = data.as_string(); diff --git a/Demos/WidgetGallery/main.cpp b/Demos/WidgetGallery/main.cpp index 9fad2e7679..8be4d74dd9 100644 --- a/Demos/WidgetGallery/main.cpp +++ b/Demos/WidgetGallery/main.cpp @@ -65,11 +65,11 @@ public: virtual ~ListViewModel() override { } virtual int row_count(const GUI::ModelIndex&) const override { return m_model_items.size(); } virtual int column_count(const GUI::ModelIndex&) const override { return 1; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { ASSERT(index.is_valid()); ASSERT(index.column() == 0); - if (role == Role::Display) + if (role == GUI::ModelRole::Display) return m_model_items.at(index.row()); return {}; } diff --git a/DevTools/HackStudio/Debugger/BacktraceModel.cpp b/DevTools/HackStudio/Debugger/BacktraceModel.cpp index 947a8a1662..f9cb3cdd68 100644 --- a/DevTools/HackStudio/Debugger/BacktraceModel.cpp +++ b/DevTools/HackStudio/Debugger/BacktraceModel.cpp @@ -32,9 +32,9 @@ NonnullRefPtr BacktraceModel::create(const DebugSession& debug_s return adopt(*new BacktraceModel(create_backtrace(debug_session, regs))); } -GUI::Variant BacktraceModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant BacktraceModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { auto& frame = m_frames.at(index.row()); return frame.function_name; } diff --git a/DevTools/HackStudio/Debugger/BacktraceModel.h b/DevTools/HackStudio/Debugger/BacktraceModel.h index 04a613b77f..f81892b238 100644 --- a/DevTools/HackStudio/Debugger/BacktraceModel.h +++ b/DevTools/HackStudio/Debugger/BacktraceModel.h @@ -45,7 +45,7 @@ public: return ""; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex&, GUI::ModelRole) const override; virtual void update() override {} virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override; diff --git a/DevTools/HackStudio/Debugger/VariablesModel.cpp b/DevTools/HackStudio/Debugger/VariablesModel.cpp index 8f63a2b0e5..a6b265b37c 100644 --- a/DevTools/HackStudio/Debugger/VariablesModel.cpp +++ b/DevTools/HackStudio/Debugger/VariablesModel.cpp @@ -159,15 +159,15 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri GUI::MessageBox::Type::Error); } -GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* variable = static_cast(index.internal_data()); switch (role) { - case Role::Display: { + case GUI::ModelRole::Display: { auto value_as_string = variable_value_as_string(*variable); return String::format("%s: %s", variable->name.characters(), value_as_string.characters()); } - case Role::Icon: + case GUI::ModelRole::Icon: return m_variable_icon; default: return {}; diff --git a/DevTools/HackStudio/Debugger/VariablesModel.h b/DevTools/HackStudio/Debugger/VariablesModel.h index 322b49c50d..274e534a8d 100644 --- a/DevTools/HackStudio/Debugger/VariablesModel.h +++ b/DevTools/HackStudio/Debugger/VariablesModel.h @@ -40,7 +40,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 1; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override; + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override; virtual void update() override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override; diff --git a/DevTools/HackStudio/FindInFilesWidget.cpp b/DevTools/HackStudio/FindInFilesWidget.cpp index be64bc8d38..e5538d391d 100644 --- a/DevTools/HackStudio/FindInFilesWidget.cpp +++ b/DevTools/HackStudio/FindInFilesWidget.cpp @@ -70,16 +70,16 @@ public: } } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { - if (role == Role::TextAlignment) + if (role == GUI::ModelRole::TextAlignment) return Gfx::TextAlignment::CenterLeft; - if (role == Role::Font) { + if (role == GUI::ModelRole::Font) { if (index.column() == Column::MatchedText) return Gfx::Font::default_fixed_width_font(); return {}; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { auto& match = m_matches.at(index.row()); switch (index.column()) { case Column::Filename: diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp index f944772a62..bb4e7907a0 100644 --- a/DevTools/HackStudio/Locator.cpp +++ b/DevTools/HackStudio/Locator.cpp @@ -50,10 +50,10 @@ public: }; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_suggestions.size(); } virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Column_Count; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { auto& suggestion = m_suggestions.at(index.row()); - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (index.column() == Column::Name) return suggestion; if (index.column() == Column::Icon) { @@ -142,7 +142,7 @@ Locator::~Locator() void Locator::open_suggestion(const GUI::ModelIndex& index) { auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); - auto filename = m_suggestion_view->model()->data(filename_index, GUI::Model::Role::Display).to_string(); + auto filename = m_suggestion_view->model()->data(filename_index, GUI::ModelRole::Display).to_string(); open_file(filename); close(); } diff --git a/DevTools/HackStudio/Project.cpp b/DevTools/HackStudio/Project.cpp index c247d21fb1..af708026e4 100644 --- a/DevTools/HackStudio/Project.cpp +++ b/DevTools/HackStudio/Project.cpp @@ -97,16 +97,16 @@ public: return 1; } - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role = Role::Display) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { auto* node = static_cast(index.internal_data()); - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { return node->name; } - if (role == Role::Custom) { + if (role == GUI::ModelRole::Custom) { return node->path; } - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { if (node->type == Project::ProjectTreeNode::Type::Project) return m_project.m_project_icon; if (node->type == Project::ProjectTreeNode::Type::Directory) @@ -117,7 +117,7 @@ public: return m_project.m_header_icon; return m_project.m_file_icon; } - if (role == Role::Font) { + if (role == GUI::ModelRole::Font) { if (node->name == g_currently_open_file) return Gfx::Font::default_bold_font(); return {}; diff --git a/DevTools/HackStudio/WidgetTreeModel.cpp b/DevTools/HackStudio/WidgetTreeModel.cpp index 3bc34473f1..0a533a2b28 100644 --- a/DevTools/HackStudio/WidgetTreeModel.cpp +++ b/DevTools/HackStudio/WidgetTreeModel.cpp @@ -85,13 +85,13 @@ int WidgetTreeModel::column_count(const GUI::ModelIndex&) const return 1; } -GUI::Variant WidgetTreeModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant WidgetTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* widget = static_cast(index.internal_data()); - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { return m_widget_icon; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { return String::format("%s (%s)", widget->class_name(), widget->relative_rect().to_string().characters()); } return {}; diff --git a/DevTools/HackStudio/WidgetTreeModel.h b/DevTools/HackStudio/WidgetTreeModel.h index 8f9b0b0393..b08949306a 100644 --- a/DevTools/HackStudio/WidgetTreeModel.h +++ b/DevTools/HackStudio/WidgetTreeModel.h @@ -36,7 +36,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/DevTools/HackStudio/main.cpp b/DevTools/HackStudio/main.cpp index 9e88247274..3cad819615 100644 --- a/DevTools/HackStudio/main.cpp +++ b/DevTools/HackStudio/main.cpp @@ -478,7 +478,7 @@ int main(int argc, char** argv) toolbar.add_separator(); g_project_tree_view->on_activation = [&](auto& index) { - auto filename = g_project_tree_view->model()->data(index, GUI::Model::Role::Custom).to_string(); + auto filename = g_project_tree_view->model()->data(index, GUI::ModelRole::Custom).to_string(); open_file(filename); }; diff --git a/DevTools/Inspector/RemoteObjectGraphModel.cpp b/DevTools/Inspector/RemoteObjectGraphModel.cpp index d6df44161b..8579b622da 100644 --- a/DevTools/Inspector/RemoteObjectGraphModel.cpp +++ b/DevTools/Inspector/RemoteObjectGraphModel.cpp @@ -96,10 +96,10 @@ int RemoteObjectGraphModel::column_count(const GUI::ModelIndex&) const return 1; } -GUI::Variant RemoteObjectGraphModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant RemoteObjectGraphModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* remote_object = static_cast(index.internal_data()); - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { if (remote_object->class_name == "Window") return m_window_icon; if (remote_object->class_name == "Timer") @@ -108,7 +108,7 @@ GUI::Variant RemoteObjectGraphModel::data(const GUI::ModelIndex& index, Role rol return m_layout_icon; return m_object_icon; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { return String::format("%s{%p}", remote_object->class_name.characters(), remote_object->address); } return {}; diff --git a/DevTools/Inspector/RemoteObjectGraphModel.h b/DevTools/Inspector/RemoteObjectGraphModel.h index bd89842924..338c92e4e6 100644 --- a/DevTools/Inspector/RemoteObjectGraphModel.h +++ b/DevTools/Inspector/RemoteObjectGraphModel.h @@ -45,7 +45,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/DevTools/Inspector/RemoteObjectPropertyModel.cpp b/DevTools/Inspector/RemoteObjectPropertyModel.cpp index 78f39bff05..e0a8d1852f 100644 --- a/DevTools/Inspector/RemoteObjectPropertyModel.cpp +++ b/DevTools/Inspector/RemoteObjectPropertyModel.cpp @@ -62,13 +62,13 @@ String RemoteObjectPropertyModel::column_name(int column) const ASSERT_NOT_REACHED(); } -GUI::Variant RemoteObjectPropertyModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant RemoteObjectPropertyModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* path = static_cast(index.internal_data()); if (!path) return {}; - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { switch (index.column()) { case Column::Name: return path->last().to_string(); diff --git a/DevTools/Inspector/RemoteObjectPropertyModel.h b/DevTools/Inspector/RemoteObjectPropertyModel.h index 36a01b32e6..a7380eab15 100644 --- a/DevTools/Inspector/RemoteObjectPropertyModel.h +++ b/DevTools/Inspector/RemoteObjectPropertyModel.h @@ -50,7 +50,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 set_data(const GUI::ModelIndex&, const GUI::Variant&) override; virtual void update() override; virtual bool is_editable(const GUI::ModelIndex& index) const override { return index.column() == Column::Value; } diff --git a/DevTools/Profiler/DisassemblyModel.cpp b/DevTools/Profiler/DisassemblyModel.cpp index 3386ba946d..732210e221 100644 --- a/DevTools/Profiler/DisassemblyModel.cpp +++ b/DevTools/Profiler/DisassemblyModel.cpp @@ -157,25 +157,25 @@ static Optional color_pair_for(const InstructionData& insn) return ColorPair { background, foreground }; } -GUI::Variant DisassemblyModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant DisassemblyModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto& insn = m_instructions[index.row()]; - if (role == Role::BackgroundColor) { + if (role == GUI::ModelRole::BackgroundColor) { auto colors = color_pair_for(insn); if (!colors.has_value()) return {}; return colors.value().background; } - if (role == Role::ForegroundColor) { + if (role == GUI::ModelRole::ForegroundColor) { auto colors = color_pair_for(insn); if (!colors.has_value()) return {}; return colors.value().foreground; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (index.column() == Column::SampleCount) { if (m_profile.show_percentages()) return ((float)insn.event_count / (float)m_node.event_count()) * 100.0f; diff --git a/DevTools/Profiler/DisassemblyModel.h b/DevTools/Profiler/DisassemblyModel.h index 499a980997..e4c1b6fe9d 100644 --- a/DevTools/Profiler/DisassemblyModel.h +++ b/DevTools/Profiler/DisassemblyModel.h @@ -61,7 +61,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: diff --git a/DevTools/Profiler/ProfileModel.cpp b/DevTools/Profiler/ProfileModel.cpp index 1d628e66c0..caf1819446 100644 --- a/DevTools/Profiler/ProfileModel.cpp +++ b/DevTools/Profiler/ProfileModel.cpp @@ -108,14 +108,14 @@ String ProfileModel::column_name(int column) const } } -GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { auto* node = static_cast(index.internal_data()); - if (role == Role::TextAlignment) { + if (role == GUI::ModelRole::TextAlignment) { if (index.column() == Column::SampleCount || index.column() == Column::SelfCount) return Gfx::TextAlignment::CenterRight; } - if (role == Role::Icon) { + if (role == GUI::ModelRole::Icon) { if (index.column() == Column::StackFrame) { if (node->address() >= 0xc0000000) return m_kernel_frame_icon; @@ -123,7 +123,7 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const } return {}; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { if (index.column() == Column::SampleCount) { if (m_profile.show_percentages()) return ((float)node->event_count() / (float)m_profile.filtered_event_count()) * 100.0f; diff --git a/DevTools/Profiler/ProfileModel.h b/DevTools/Profiler/ProfileModel.h index a25520ec3c..580d972997 100644 --- a/DevTools/Profiler/ProfileModel.h +++ b/DevTools/Profiler/ProfileModel.h @@ -50,7 +50,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 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 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/DevTools/VisualBuilder/VBPropertiesWindow.cpp b/DevTools/VisualBuilder/VBPropertiesWindow.cpp index 0b6b1475a4..1d70bd0e15 100644 --- a/DevTools/VisualBuilder/VBPropertiesWindow.cpp +++ b/DevTools/VisualBuilder/VBPropertiesWindow.cpp @@ -38,9 +38,9 @@ public: virtual int row_count(const GUI::ModelIndex&) const override { return 2; } virtual int column_count(const GUI::ModelIndex&) const override { return 1; } virtual void update() override {} - virtual GUI::Variant data(const GUI::ModelIndex& index, Role role) const override + virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override { - if (role != Role::Display) + if (role != GUI::ModelRole::Display) return {}; switch (index.row()) { case 0: @@ -94,7 +94,7 @@ VBPropertiesWindow::VBPropertiesWindow() if (!m_table_view->model()) return nullptr; auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type); - auto type = m_table_view->model()->data(type_index, GUI::Model::Role::Custom).to_i32(); + auto type = m_table_view->model()->data(type_index, GUI::ModelRole::Custom).to_i32(); switch ((GUI::Variant::Type)type) { case GUI::Variant::Type::Bool: return make(); diff --git a/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp b/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp index 96fd12e3bd..4b69e14177 100644 --- a/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp +++ b/DevTools/VisualBuilder/VBWidgetPropertyModel.cpp @@ -57,23 +57,23 @@ String VBWidgetPropertyModel::column_name(int column) const } } -GUI::Variant VBWidgetPropertyModel::data(const GUI::ModelIndex& index, Role role) const +GUI::Variant VBWidgetPropertyModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - if (role == Role::TextAlignment) { + if (role == GUI::ModelRole::TextAlignment) { return Gfx::TextAlignment::CenterLeft; } - if (role == Role::Font) { + if (role == GUI::ModelRole::Font) { if (index.column() == Column::Name) return Gfx::Font::default_bold_font(); return {}; } - if (role == Role::Custom) { + if (role == GUI::ModelRole::Custom) { auto& property = m_widget.m_properties[index.row()]; if (index.column() == Column::Type) return (int)property.value().type(); return {}; } - if (role == Role::Display) { + if (role == GUI::ModelRole::Display) { auto& property = m_widget.m_properties[index.row()]; switch (index.column()) { case Column::Name: @@ -85,7 +85,7 @@ GUI::Variant VBWidgetPropertyModel::data(const GUI::ModelIndex& index, Role role } ASSERT_NOT_REACHED(); } - if (role == Role::ForegroundColor) { + if (role == GUI::ModelRole::ForegroundColor) { auto& property = m_widget.m_properties[index.row()]; switch (index.column()) { case Column::Name: diff --git a/DevTools/VisualBuilder/VBWidgetPropertyModel.h b/DevTools/VisualBuilder/VBWidgetPropertyModel.h index d75b489533..c96a5cad50 100644 --- a/DevTools/VisualBuilder/VBWidgetPropertyModel.h +++ b/DevTools/VisualBuilder/VBWidgetPropertyModel.h @@ -46,7 +46,7 @@ public: 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 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 { did_update(); } virtual bool is_editable(const GUI::ModelIndex&) const override; virtual void set_data(const GUI::ModelIndex&, const GUI::Variant&) override; 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 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 #include #include +#include #include #include #include @@ -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 + * 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(); 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 m_source; HashMap> 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(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(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(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(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: diff --git a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp index 84f89cc764..acea0a45c8 100644 --- a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp +++ b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.cpp @@ -47,8 +47,10 @@ String ClipboardHistoryModel::column_name(int column) const } } -GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, Role) const +GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { + if (role != GUI::ModelRole::Display) + return {}; auto& data_and_type = m_history_items[index.row()]; switch (index.column()) { case Column::Data: diff --git a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h index 6229234e55..1309ccb583 100644 --- a/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h +++ b/MenuApplets/ClipboardHistory/ClipboardHistoryModel.h @@ -49,7 +49,7 @@ private: virtual int row_count(const GUI::ModelIndex&) const override { return m_history_items.size(); } virtual String column_name(int) const override; virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; } - 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; Vector m_history_items;