1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

LibGUI: Move GUI::Model::Role to GUI::ModelRole

This is preparation for using ModelRole in the ModelIndex API.
This commit is contained in:
Andreas Kling 2020-08-16 16:00:07 +02:00
parent f6d7204689
commit a1e381a0f8
66 changed files with 201 additions and 167 deletions

View file

@ -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); auto& month = Calendar::name_of_month(index.row() + 1);
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Month: case Column::Month:
return month; return month;

View file

@ -58,7 +58,7 @@ private:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; 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 int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) 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 void update() override; virtual void update() override;
private: private:

View file

@ -52,11 +52,11 @@ public:
return "Data"; 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; return Gfx::TextAlignment::CenterLeft;
if (role == Role::Display) if (role == GUI::ModelRole::Display)
return m_data.at(index.row()); return m_data.at(index.row());
return {}; return {};

View file

@ -438,7 +438,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
view.selection().for_each_index([&](const GUI::ModelIndex& index) { view.selection().for_each_index([&](const GUI::ModelIndex& index) {
auto parent_index = model.parent_index(index); auto parent_index = model.parent_index(index);
auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_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); paths.append(path);
}); });
return paths; return paths;

View file

@ -155,17 +155,17 @@ int ManualModel::column_count(const GUI::ModelIndex&) const
return 1; 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<const ManualNode*>(index.internal_data()); auto* node = static_cast<const ManualNode*>(index.internal_data());
switch (role) { switch (role) {
case Role::Search: case GUI::ModelRole::Search:
if (!node->is_page()) if (!node->is_page())
return {}; return {};
return String(page_view(page_path(index)).value()); return String(page_view(page_path(index)).value());
case Role::Display: case GUI::ModelRole::Display:
return node->name(); return node->name();
case Role::Icon: case GUI::ModelRole::Icon:
if (node->is_page()) if (node->is_page())
return m_page_icon; return m_page_icon;
if (node->is_open()) if (node->is_open())

View file

@ -50,7 +50,7 @@ public:
void update_section_node_on_toggle(const GUI::ModelIndex&, const bool); void update_section_node_on_toggle(const GUI::ModelIndex&, const bool);
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 TriState data_matches(const GUI::ModelIndex&, GUI::Variant) const override;
virtual void update() override; virtual void update() override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;

View file

@ -57,11 +57,11 @@ String IRCChannelMemberListModel::column_name(int column) const
ASSERT_NOT_REACHED(); 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; return Gfx::TextAlignment::CenterLeft;
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Name: case Column::Name:
return m_channel.member_at(index.row()); return m_channel.member_at(index.row());
@ -77,5 +77,5 @@ void IRCChannelMemberListModel::update()
String IRCChannelMemberListModel::nick_at(const GUI::ModelIndex& index) const 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();
} }

View file

@ -42,7 +42,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override; virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) 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 void update() override;
virtual String nick_at(const GUI::ModelIndex& index) const; virtual String nick_at(const GUI::ModelIndex& index) const;

View file

@ -56,11 +56,11 @@ String IRCWindowListModel::column_name(int column) const
ASSERT_NOT_REACHED(); 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; return Gfx::TextAlignment::CenterLeft;
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Name: { case Column::Name: {
auto& window = m_client.window_at(index.row()); 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()) { switch (index.column()) {
case Column::Name: { case Column::Name: {
auto& window = m_client.window_at(index.row()); auto& window = m_client.window_at(index.row());

View file

@ -44,7 +44,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override; virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) 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 void update() override;
private: private:

View file

@ -48,12 +48,12 @@ public:
return 1; 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.is_valid());
ASSERT(index.column() == 0); ASSERT(index.column() == 0);
if (role == Role::Display) if (role == GUI::ModelRole::Display)
return m_file_names.at(index.row()); return m_file_names.at(index.row());
return {}; return {};

View file

@ -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)); ASSERT(is_valid(index));
if (role == Role::TextAlignment) { if (role == GUI::ModelRole::TextAlignment) {
switch (index.column()) { switch (index.column()) {
case Column::Device: case Column::Device:
return Gfx::TextAlignment::CenterLeft; return Gfx::TextAlignment::CenterLeft;
@ -93,7 +93,7 @@ GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, Role role) const
return {}; return {};
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
const DeviceInfo& device = m_devices[index.row()]; const DeviceInfo& device = m_devices[index.row()];
switch (index.column()) { switch (index.column()) {
case Column::Device: case Column::Device:

View file

@ -47,7 +47,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override; virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) 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 void update() override;
private: private:

View file

@ -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 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 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(); float scale_factor = (float)pagemap.length() / (float)rect.width();

View file

@ -156,11 +156,11 @@ static String pretty_byte_size(size_t size)
return String::format("%uK", size / 1024); 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)); ASSERT(is_valid(index));
if (role == Role::TextAlignment) { if (role == GUI::ModelRole::TextAlignment) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
case Column::Name: 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 it = m_threads.find(m_pids[index.row()]);
auto& thread = *(*it).value; auto& thread = *(*it).value;
if (role == Role::Sort) { if (role == GUI::ModelRole::Sort) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
return 0; return 0;
@ -272,7 +272,7 @@ GUI::Variant ProcessModel::data(const GUI::ModelIndex& index, Role role) const
return {}; return {};
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
if (thread.current_state.icon_id != -1) { if (thread.current_state.icon_id != -1) {

View file

@ -89,7 +89,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override; virtual int column_count(const GUI::ModelIndex&) const override;
virtual String column_name(int column) 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 void update() override;
struct CpuInfo { struct CpuInfo {

View file

@ -193,7 +193,7 @@ int main(int argc, char** argv)
if (process_table_view.selection().is_empty()) if (process_table_view.selection().is_empty())
return -1; return -1;
auto pid_index = process_table_view.model()->index(process_table_view.selection().first().row(), column); 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&) { 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 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 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; String text;
if (data.is_string()) if (data.is_string())
text = data.as_string(); text = data.as_string();

View file

@ -65,11 +65,11 @@ public:
virtual ~ListViewModel() override { } virtual ~ListViewModel() override { }
virtual int row_count(const GUI::ModelIndex&) const override { return m_model_items.size(); } 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 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.is_valid());
ASSERT(index.column() == 0); ASSERT(index.column() == 0);
if (role == Role::Display) if (role == GUI::ModelRole::Display)
return m_model_items.at(index.row()); return m_model_items.at(index.row());
return {}; return {};
} }

View file

@ -32,9 +32,9 @@ NonnullRefPtr<BacktraceModel> BacktraceModel::create(const DebugSession& debug_s
return adopt(*new BacktraceModel(create_backtrace(debug_session, regs))); 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()); auto& frame = m_frames.at(index.row());
return frame.function_name; return frame.function_name;
} }

View file

@ -45,7 +45,7 @@ public:
return ""; 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 void update() override {}
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override; virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex&) const override;

View file

@ -159,15 +159,15 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri
GUI::MessageBox::Type::Error); 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<const DebugInfo::VariableInfo*>(index.internal_data()); auto* variable = static_cast<const DebugInfo::VariableInfo*>(index.internal_data());
switch (role) { switch (role) {
case Role::Display: { case GUI::ModelRole::Display: {
auto value_as_string = variable_value_as_string(*variable); auto value_as_string = variable_value_as_string(*variable);
return String::format("%s: %s", variable->name.characters(), value_as_string.characters()); return String::format("%s: %s", variable->name.characters(), value_as_string.characters());
} }
case Role::Icon: case GUI::ModelRole::Icon:
return m_variable_icon; return m_variable_icon;
default: default:
return {}; return {};

View file

@ -40,7 +40,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; 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 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 void update() override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const 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; virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override;

View file

@ -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; return Gfx::TextAlignment::CenterLeft;
if (role == Role::Font) { if (role == GUI::ModelRole::Font) {
if (index.column() == Column::MatchedText) if (index.column() == Column::MatchedText)
return Gfx::Font::default_fixed_width_font(); return Gfx::Font::default_fixed_width_font();
return {}; return {};
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
auto& match = m_matches.at(index.row()); auto& match = m_matches.at(index.row());
switch (index.column()) { switch (index.column()) {
case Column::Filename: case Column::Filename:

View file

@ -50,10 +50,10 @@ public:
}; };
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_suggestions.size(); } 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 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()); auto& suggestion = m_suggestions.at(index.row());
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (index.column() == Column::Name) if (index.column() == Column::Name)
return suggestion; return suggestion;
if (index.column() == Column::Icon) { if (index.column() == Column::Icon) {
@ -142,7 +142,7 @@ Locator::~Locator()
void Locator::open_suggestion(const GUI::ModelIndex& index) void Locator::open_suggestion(const GUI::ModelIndex& index)
{ {
auto filename_index = m_suggestion_view->model()->index(index.row(), LocatorSuggestionModel::Column::Name); 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); open_file(filename);
close(); close();
} }

View file

@ -97,16 +97,16 @@ public:
return 1; 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<Project::ProjectTreeNode*>(index.internal_data()); auto* node = static_cast<Project::ProjectTreeNode*>(index.internal_data());
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
return node->name; return node->name;
} }
if (role == Role::Custom) { if (role == GUI::ModelRole::Custom) {
return node->path; return node->path;
} }
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
if (node->type == Project::ProjectTreeNode::Type::Project) if (node->type == Project::ProjectTreeNode::Type::Project)
return m_project.m_project_icon; return m_project.m_project_icon;
if (node->type == Project::ProjectTreeNode::Type::Directory) if (node->type == Project::ProjectTreeNode::Type::Directory)
@ -117,7 +117,7 @@ public:
return m_project.m_header_icon; return m_project.m_header_icon;
return m_project.m_file_icon; return m_project.m_file_icon;
} }
if (role == Role::Font) { if (role == GUI::ModelRole::Font) {
if (node->name == g_currently_open_file) if (node->name == g_currently_open_file)
return Gfx::Font::default_bold_font(); return Gfx::Font::default_bold_font();
return {}; return {};

View file

@ -85,13 +85,13 @@ int WidgetTreeModel::column_count(const GUI::ModelIndex&) const
return 1; 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<GUI::Widget*>(index.internal_data()); auto* widget = static_cast<GUI::Widget*>(index.internal_data());
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
return m_widget_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 String::format("%s (%s)", widget->class_name(), widget->relative_rect().to_string().characters());
} }
return {}; return {};

View file

@ -36,7 +36,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override; virtual void update() override;

View file

@ -478,7 +478,7 @@ int main(int argc, char** argv)
toolbar.add_separator(); toolbar.add_separator();
g_project_tree_view->on_activation = [&](auto& index) { 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); open_file(filename);
}; };

View file

@ -96,10 +96,10 @@ int RemoteObjectGraphModel::column_count(const GUI::ModelIndex&) const
return 1; 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<RemoteObject*>(index.internal_data()); auto* remote_object = static_cast<RemoteObject*>(index.internal_data());
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
if (remote_object->class_name == "Window") if (remote_object->class_name == "Window")
return m_window_icon; return m_window_icon;
if (remote_object->class_name == "Timer") 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_layout_icon;
return m_object_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 String::format("%s{%p}", remote_object->class_name.characters(), remote_object->address);
} }
return {}; return {};

View file

@ -45,7 +45,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override; virtual void update() override;

View file

@ -62,13 +62,13 @@ String RemoteObjectPropertyModel::column_name(int column) const
ASSERT_NOT_REACHED(); 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<const JsonPath*>(index.internal_data()); auto* path = static_cast<const JsonPath*>(index.internal_data());
if (!path) if (!path)
return {}; return {};
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Name: case Column::Name:
return path->last().to_string(); return path->last().to_string();

View file

@ -50,7 +50,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; 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 int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) 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 void set_data(const GUI::ModelIndex&, const GUI::Variant&) override; virtual void set_data(const GUI::ModelIndex&, const GUI::Variant&) override;
virtual void update() override; virtual void update() override;
virtual bool is_editable(const GUI::ModelIndex& index) const override { return index.column() == Column::Value; } virtual bool is_editable(const GUI::ModelIndex& index) const override { return index.column() == Column::Value; }

View file

@ -157,25 +157,25 @@ static Optional<ColorPair> color_pair_for(const InstructionData& insn)
return ColorPair { background, foreground }; 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()]; auto& insn = m_instructions[index.row()];
if (role == Role::BackgroundColor) { if (role == GUI::ModelRole::BackgroundColor) {
auto colors = color_pair_for(insn); auto colors = color_pair_for(insn);
if (!colors.has_value()) if (!colors.has_value())
return {}; return {};
return colors.value().background; return colors.value().background;
} }
if (role == Role::ForegroundColor) { if (role == GUI::ModelRole::ForegroundColor) {
auto colors = color_pair_for(insn); auto colors = color_pair_for(insn);
if (!colors.has_value()) if (!colors.has_value())
return {}; return {};
return colors.value().foreground; return colors.value().foreground;
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (index.column() == Column::SampleCount) { if (index.column() == Column::SampleCount) {
if (m_profile.show_percentages()) if (m_profile.show_percentages())
return ((float)insn.event_count / (float)m_node.event_count()) * 100.0f; return ((float)insn.event_count / (float)m_node.event_count()) * 100.0f;

View file

@ -61,7 +61,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; 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 int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) 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 void update() override; virtual void update() override;
private: private:

View file

@ -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<ProfileNode*>(index.internal_data()); auto* node = static_cast<ProfileNode*>(index.internal_data());
if (role == Role::TextAlignment) { if (role == GUI::ModelRole::TextAlignment) {
if (index.column() == Column::SampleCount || index.column() == Column::SelfCount) if (index.column() == Column::SampleCount || index.column() == Column::SelfCount)
return Gfx::TextAlignment::CenterRight; return Gfx::TextAlignment::CenterRight;
} }
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
if (index.column() == Column::StackFrame) { if (index.column() == Column::StackFrame) {
if (node->address() >= 0xc0000000) if (node->address() >= 0xc0000000)
return m_kernel_frame_icon; return m_kernel_frame_icon;
@ -123,7 +123,7 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, Role role) const
} }
return {}; return {};
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (index.column() == Column::SampleCount) { if (index.column() == Column::SampleCount) {
if (m_profile.show_percentages()) if (m_profile.show_percentages())
return ((float)node->event_count() / (float)m_profile.filtered_event_count()) * 100.0f; return ((float)node->event_count() / (float)m_profile.filtered_event_count()) * 100.0f;

View file

@ -50,7 +50,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 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 index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override; virtual void update() override;

View file

@ -38,9 +38,9 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override { return 2; } virtual int row_count(const GUI::ModelIndex&) const override { return 2; }
virtual int column_count(const GUI::ModelIndex&) const override { return 1; } virtual int column_count(const GUI::ModelIndex&) const override { return 1; }
virtual void update() override {} 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 {}; return {};
switch (index.row()) { switch (index.row()) {
case 0: case 0:
@ -94,7 +94,7 @@ VBPropertiesWindow::VBPropertiesWindow()
if (!m_table_view->model()) if (!m_table_view->model())
return nullptr; return nullptr;
auto type_index = m_table_view->model()->index(index.row(), VBWidgetPropertyModel::Column::Type); 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) { switch ((GUI::Variant::Type)type) {
case GUI::Variant::Type::Bool: case GUI::Variant::Type::Bool:
return make<BoolModelEditingDelegate>(); return make<BoolModelEditingDelegate>();

View file

@ -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; return Gfx::TextAlignment::CenterLeft;
} }
if (role == Role::Font) { if (role == GUI::ModelRole::Font) {
if (index.column() == Column::Name) if (index.column() == Column::Name)
return Gfx::Font::default_bold_font(); return Gfx::Font::default_bold_font();
return {}; return {};
} }
if (role == Role::Custom) { if (role == GUI::ModelRole::Custom) {
auto& property = m_widget.m_properties[index.row()]; auto& property = m_widget.m_properties[index.row()];
if (index.column() == Column::Type) if (index.column() == Column::Type)
return (int)property.value().type(); return (int)property.value().type();
return {}; return {};
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
auto& property = m_widget.m_properties[index.row()]; auto& property = m_widget.m_properties[index.row()];
switch (index.column()) { switch (index.column()) {
case Column::Name: case Column::Name:
@ -85,7 +85,7 @@ GUI::Variant VBWidgetPropertyModel::data(const GUI::ModelIndex& index, Role role
} }
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
if (role == Role::ForegroundColor) { if (role == GUI::ModelRole::ForegroundColor) {
auto& property = m_widget.m_properties[index.row()]; auto& property = m_widget.m_properties[index.row()];
switch (index.column()) { switch (index.column()) {
case Column::Name: case Column::Name:

View file

@ -46,7 +46,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; } virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; }
virtual String column_name(int column) 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 { did_update(); } virtual void update() override { did_update(); }
virtual bool is_editable(const GUI::ModelIndex&) const override; virtual bool is_editable(const GUI::ModelIndex&) const override;
virtual void set_data(const GUI::ModelIndex&, const GUI::Variant&) override; virtual void set_data(const GUI::ModelIndex&, const GUI::Variant&) override;

View file

@ -134,7 +134,7 @@ void AbstractView::begin_editing(const ModelIndex& index)
ASSERT(aid_create_editing_delegate); ASSERT(aid_create_editing_delegate);
m_editing_delegate = aid_create_editing_delegate(index); m_editing_delegate = aid_create_editing_delegate(index);
m_editing_delegate->bind(*model(), 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(); m_edit_widget = m_editing_delegate->widget();
add_child(*m_edit_widget); add_child(*m_edit_widget);
m_edit_widget->move_to_back(); m_edit_widget->move_to_back();
@ -187,7 +187,7 @@ NonnullRefPtr<Gfx::Font> AbstractView::font_for_index(const ModelIndex& index) c
if (!model()) if (!model())
return font(); return font();
auto font_data = model()->data(index, Model::Role::Font); auto font_data = model()->data(index, ModelRole::Font);
if (font_data.is_font()) if (font_data.is_font())
return font_data.as_font(); return font_data.as_font();
@ -285,14 +285,14 @@ void AbstractView::mousemove_event(MouseEvent& event)
text_builder.append(", "); text_builder.append(", ");
text_builder.append(text_data.to_string()); 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(drag_data.to_string());
data_builder.append('\n'); data_builder.append('\n');
first = false; first = false;
if (!bitmap) { if (!bitmap) {
Variant icon_data = model()->data(index, Model::Role::Icon); Variant icon_data = model()->data(index, ModelRole::Icon);
if (icon_data.is_icon()) if (icon_data.is_icon())
bitmap = icon_data.as_icon().bitmap_for_size(32); bitmap = icon_data.as_icon().bitmap_for_size(32);
} }

View file

@ -125,7 +125,7 @@ void ColumnsView::paint_event(PaintEvent& event)
Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() }; Gfx::IntRect row_rect { column_x, row * item_height(), column.width, item_height() };
painter.fill_rect(row_rect, background_color); 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() }; Gfx::IntRect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() };
icon_rect.center_vertically_within(row_rect); icon_rect.center_vertically_within(row_rect);
if (icon.is_icon()) { if (icon.is_icon()) {

View file

@ -349,11 +349,11 @@ ModelIndex FileSystemModel::parent_index(const ModelIndex& index) const
return node.parent->index(*this, index.column()); 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()); ASSERT(index.is_valid());
if (role == Role::TextAlignment) { if (role == ModelRole::TextAlignment) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
return Gfx::TextAlignment::Center; return Gfx::TextAlignment::Center;
@ -374,13 +374,13 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const
auto& node = this->node(index); auto& node = this->node(index);
if (role == Role::Custom) { if (role == ModelRole::Custom) {
// For GUI::FileSystemModel, custom role means the full path. // For GUI::FileSystemModel, custom role means the full path.
ASSERT(index.column() == Column::Name); ASSERT(index.column() == Column::Name);
return node.full_path(*this); return node.full_path(*this);
} }
if (role == Role::DragData) { if (role == ModelRole::DragData) {
if (index.column() == Column::Name) { if (index.column() == Column::Name) {
StringBuilder builder; StringBuilder builder;
builder.append("file://"); builder.append("file://");
@ -390,7 +390,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const
return {}; return {};
} }
if (role == Role::Sort) { if (role == ModelRole::Sort) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
return node.is_directory() ? 0 : 1; return node.is_directory() ? 0 : 1;
@ -414,7 +414,7 @@ Variant FileSystemModel::data(const ModelIndex& index, Role role) const
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
if (role == Role::Display) { if (role == ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
return icon_for(node); 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 icon_for(node);
} }
return {}; return {};

View file

@ -133,7 +133,7 @@ public:
virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int row_count(const ModelIndex& = ModelIndex()) const override;
virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual int column_count(const ModelIndex& = ModelIndex()) const override;
virtual String column_name(int column) 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 void update() override;
virtual ModelIndex parent_index(const ModelIndex&) const override; virtual ModelIndex parent_index(const ModelIndex&) const override;
virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override;

View file

@ -53,7 +53,7 @@ int FilteringProxyModel::column_count(const ModelIndex& index) const
return m_model.column_count(m_matching_indices[index.row()]); 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()) if (!index.is_valid())
return {}; return {};
@ -84,7 +84,7 @@ void FilteringProxyModel::filter()
auto filter_matches = m_model.data_matches(index, m_filter_term); auto filter_matches = m_model.data_matches(index, m_filter_term);
bool matches = filter_matches == TriState::True; bool matches = filter_matches == TriState::True;
if (filter_matches == TriState::Unknown) { 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)) if (data.is_string() && data.as_string().contains(m_filter_term))
matches = true; matches = true;
} }

View file

@ -45,7 +45,7 @@ public:
virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int row_count(const ModelIndex& = ModelIndex()) const override;
virtual int column_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 void update() override;
virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override; virtual ModelIndex index(int row, int column = 0, const ModelIndex& parent = ModelIndex()) const override;

View file

@ -438,8 +438,8 @@ void IconView::paint_event(PaintEvent& event)
background_color = widget_background_color; background_color = widget_background_color;
} }
auto icon = model()->data(item_data.index, Model::Role::Icon); auto icon = model()->data(item_data.index, ModelRole::Icon);
auto item_text = model()->data(item_data.index, Model::Role::Display); auto item_text = model()->data(item_data.index, ModelRole::Display);
if (icon.is_icon()) { if (icon.is_icon()) {
if (auto bitmap = icon.as_icon().bitmap_for_size(item_data.icon_rect.width())) { 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) if (item_data.selected)
text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text();
else 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.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); 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);

View file

@ -92,16 +92,16 @@ bool JsonArrayModel::remove(int row)
return true; 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& field_spec = m_fields[index.column()];
auto& object = m_array.at(index.row()).as_object(); auto& object = m_array.at(index.row()).as_object();
if (role == Model::Role::TextAlignment) { if (role == ModelRole::TextAlignment) {
return field_spec.text_alignment; return field_spec.text_alignment;
} }
if (role == Model::Role::Display) { if (role == ModelRole::Display) {
auto& json_field_name = field_spec.json_field_name; auto& json_field_name = field_spec.json_field_name;
auto data = object.get(json_field_name); auto data = object.get(json_field_name);
if (field_spec.massage_for_display) 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(); return object.get(json_field_name).to_string();
} }
if (role == Model::Role::Sort) { if (role == ModelRole::Sort) {
if (field_spec.massage_for_sort) if (field_spec.massage_for_sort)
return field_spec.massage_for_sort(object); 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) if (field_spec.massage_for_custom)
return field_spec.massage_for_custom(object); return field_spec.massage_for_custom(object);
return {}; return {};

View file

@ -69,7 +69,7 @@ public:
virtual int row_count(const ModelIndex& = ModelIndex()) const override { return m_array.size(); } 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 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 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; virtual void update() override;
const String& json_path() const { return m_json_path; } const String& json_path() const { return m_json_path; }

View file

@ -59,7 +59,7 @@ void ListView::update_content_size()
int content_width = 0; int content_width = 0;
for (int row = 0, row_count = model()->row_count(); row < row_count; ++row) { 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())); content_width = max(content_width, font().width(text.to_string()));
} }
@ -162,11 +162,11 @@ void ListView::paint_event(PaintEvent& event)
if (is_selected_row) if (is_selected_row)
text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text();
else 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; auto text_rect = row_rect;
text_rect.move_by(horizontal_padding(), 0); text_rect.move_by(horizontal_padding(), 0);
text_rect.set_width(text_rect.width() - horizontal_padding() * 2); 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); painter.draw_text(text_rect, data.to_string(), font, text_alignment, text_color);
} }

View file

@ -32,6 +32,7 @@
#include <AK/RefCounted.h> #include <AK/RefCounted.h>
#include <AK/String.h> #include <AK/String.h>
#include <LibGUI/ModelIndex.h> #include <LibGUI/ModelIndex.h>
#include <LibGUI/ModelRole.h>
#include <LibGUI/Variant.h> #include <LibGUI/Variant.h>
#include <LibGfx/Forward.h> #include <LibGfx/Forward.h>
#include <LibGfx/TextAlignment.h> #include <LibGfx/TextAlignment.h>
@ -58,25 +59,12 @@ public:
InvalidateAllIndexes = 1 << 0, 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 ~Model();
virtual int row_count(const ModelIndex& = ModelIndex()) const = 0; virtual int row_count(const ModelIndex& = ModelIndex()) const = 0;
virtual int column_count(const ModelIndex& = ModelIndex()) const = 0; virtual int column_count(const ModelIndex& = ModelIndex()) const = 0;
virtual String column_name(int) const { return {}; } 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 TriState data_matches(const ModelIndex&, Variant) const { return TriState::Unknown; }
virtual void update() = 0; virtual void update() = 0;
virtual ModelIndex parent_index(const ModelIndex&) const { return {}; } virtual ModelIndex parent_index(const ModelIndex&) const { return {}; }

View file

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

View file

@ -57,7 +57,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
m_table_view = widget.add<GUI::TableView>(); m_table_view = widget.add<GUI::TableView>();
auto sorting_model = GUI::SortingProxyModel::create(RunningProcessesModel::create()); 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_key_column_and_sort_order(RunningProcessesModel::Column::PID, GUI::SortOrder::Descending);
m_table_view->set_model(sorting_model); 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] { m_refresh_timer->on_timeout = [this] {
auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update. auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update.
if (!m_table_view->selection().is_empty()) { 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(); 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. auto column_index = 1; // Corresponds to PID column in the m_table_view.
for (int row_index = 0; row_index < row_count; ++row_index) { for (int row_index = 0; row_index < row_count; ++row_index) {
auto cell_index = model->index(row_index, column_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()) { if (previous_selected_pid == pid_as_variant.as_i32()) {
m_table_view->selection().set(cell_index); // Set only if PIDs are matched. 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) 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(); m_pid = pid_as_variant.as_i32();
done(ExecOK); done(ExecOK);
} }

View file

@ -92,15 +92,15 @@ String RunningProcessesModel::column_name(int column_index) const
ASSERT_NOT_REACHED(); 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()]; auto& process = m_processes[index.row()];
if (role == Role::Custom) { if (role == ModelRole::Custom) {
return process.pid; return process.pid;
} }
if (role == Role::Display) { if (role == ModelRole::Display) {
switch (index.column()) { switch (index.column()) {
case Column::Icon: case Column::Icon:
if (!process.icon) if (!process.icon)

View file

@ -47,7 +47,7 @@ public:
virtual int row_count(const GUI::ModelIndex&) const override; virtual int row_count(const GUI::ModelIndex&) const override;
virtual int column_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 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; virtual void update() override;
private: private:

View file

@ -113,7 +113,7 @@ String SortingProxyModel::column_name(int column) const
return source().column_name(column); 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); return source().data(map_to_source(proxy_index), role);
} }

View file

@ -40,7 +40,7 @@ public:
virtual int row_count(const ModelIndex& = ModelIndex()) const override; virtual int row_count(const ModelIndex& = ModelIndex()) const override;
virtual int column_count(const ModelIndex& = ModelIndex()) const override; virtual int column_count(const ModelIndex& = ModelIndex()) const override;
virtual String column_name(int) 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 void update() override;
virtual StringView drag_data_type() const override; virtual StringView drag_data_type() const override;
virtual ModelIndex parent_index(const ModelIndex&) 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_source(const ModelIndex&) const;
ModelIndex map_to_proxy(const ModelIndex&) const; ModelIndex map_to_proxy(const ModelIndex&) const;
Role sort_role() const { return m_sort_role; } ModelRole sort_role() const { return m_sort_role; }
void set_sort_role(Role role) { m_sort_role = role; } void set_sort_role(ModelRole role) { m_sort_role = role; }
virtual void sort(int column, SortOrder) override; virtual void sort(int column, SortOrder) override;
@ -84,7 +84,7 @@ private:
NonnullRefPtr<Model> m_source; NonnullRefPtr<Model> m_source;
HashMap<ModelIndex, NonnullOwnPtr<Mapping>> m_mappings; HashMap<ModelIndex, NonnullOwnPtr<Mapping>> m_mappings;
Role m_sort_role { Role::Sort }; ModelRole m_sort_role { ModelRole::Sort };
int m_last_key_column { -1 }; int m_last_key_column { -1 };
SortOrder m_last_sort_order { SortOrder::Ascending }; SortOrder m_last_sort_order { SortOrder::Ascending };
}; };

View file

@ -128,13 +128,13 @@ void TableView::paint_event(PaintEvent& event)
if (is_selected_row) if (is_selected_row)
text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text(); text_color = is_focused() ? palette().selection_text() : palette().inactive_selection_text();
else 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) { 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()) if (cell_background_color.is_valid())
painter.fill_rect(cell_rect_for_fill, cell_background_color.to_color(background_color)); 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); painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right);
} }
} }

View file

@ -171,7 +171,7 @@ void TreeView::traverse_in_paint_order(Callback callback) const
if (index.is_valid()) { if (index.is_valid()) {
auto& metadata = ensure_metadata_for_index(index); auto& metadata = ensure_metadata_for_index(index);
int x_offset = tree_column_x_offset + horizontal_padding() + indent_level * indent_width_in_pixels(); 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 = { Gfx::IntRect rect = {
x_offset, y_offset, x_offset, y_offset,
icon_size() + icon_spacing() + text_padding() + font_for_index(index)->width(node_text) + text_padding(), item_height() 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()); painter.blit(cell_rect.location(), *bitmap, bitmap->rect());
} else { } else {
if (!is_selected_row) if (!is_selected_row)
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()));
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); painter.draw_text(cell_rect, data.to_string(), font_for_index(cell_index), text_alignment, text_color, Gfx::TextElision::Right);
} }
} }
} else { } else {
// It's the tree column! // It's the tree column!
Gfx::IntRect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; 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 (icon.is_icon()) {
if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { 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()) 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(), icon_rect.right() + 1 + icon_spacing(), rect.y(),
rect.width() - icon_size() - icon_spacing(), rect.height() 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); painter.draw_text(text_rect, node_text, font_for_index(index), Gfx::TextAlignment::Center, text_color);
auto index_at_indent = index; auto index_at_indent = index;
for (int i = indent_level; i > 0; --i) { for (int i = indent_level; i > 0; --i) {

View file

@ -115,10 +115,10 @@ static String with_whitespace_collapsed(const StringView& string)
return builder.to_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()); auto& node = *static_cast<DOM::Node*>(index.internal_data());
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
if (node.is_document()) if (node.is_document())
return m_document_icon; return m_document_icon;
if (node.is_element()) if (node.is_element())
@ -126,7 +126,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const
// FIXME: More node type icons? // FIXME: More node type icons?
return m_text_icon; return m_text_icon;
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (node.is_text()) if (node.is_text())
return String::format("%s", with_whitespace_collapsed(downcast<DOM::Text>(node).data()).characters()); return String::format("%s", with_whitespace_collapsed(downcast<DOM::Text>(node).data()).characters());
if (!node.is_element()) if (!node.is_element())

View file

@ -42,7 +42,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override; virtual void update() override;

View file

@ -115,17 +115,17 @@ static String with_whitespace_collapsed(const StringView& string)
return builder.to_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()); auto& node = *static_cast<LayoutNode*>(index.internal_data());
if (role == Role::Icon) { if (role == GUI::ModelRole::Icon) {
if (node.is_root()) if (node.is_root())
return m_document_icon; return m_document_icon;
if (node.is_text()) if (node.is_text())
return m_text_icon; return m_text_icon;
return m_element_icon; return m_element_icon;
} }
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (node.is_text()) if (node.is_text())
return String::format("LayoutText: %s", with_whitespace_collapsed(downcast<LayoutText>(node).text_for_rendering()).characters()); return String::format("LayoutText: %s", with_whitespace_collapsed(downcast<LayoutText>(node).text_for_rendering()).characters());
StringBuilder builder; StringBuilder builder;

View file

@ -42,7 +42,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_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 index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override; virtual void update() override;

View file

@ -61,10 +61,10 @@ String StylePropertiesModel::column_name(int column_index) const
ASSERT_NOT_REACHED(); 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()]; auto& value = m_values[index.row()];
if (role == Role::Display) { if (role == GUI::ModelRole::Display) {
if (index.column() == Column::PropertyName) if (index.column() == Column::PropertyName)
return value.name; return value.name;
if (index.column() == Column::PropertyValue) if (index.column() == Column::PropertyValue)

View file

@ -46,7 +46,7 @@ public:
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override; 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 int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) 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 void update() override; virtual void update() override;
private: private:

View file

@ -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()]; auto& data_and_type = m_history_items[index.row()];
switch (index.column()) { switch (index.column()) {
case Column::Data: case Column::Data:

View file

@ -49,7 +49,7 @@ private:
virtual int row_count(const GUI::ModelIndex&) const override { return m_history_items.size(); } virtual int row_count(const GUI::ModelIndex&) const override { return m_history_items.size(); }
virtual String column_name(int) const override; virtual String column_name(int) const override;
virtual int column_count(const GUI::ModelIndex&) const override { return Column::__Count; } 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; virtual void update() override;
Vector<GUI::Clipboard::DataAndType> m_history_items; Vector<GUI::Clipboard::DataAndType> m_history_items;