1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +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

@ -32,9 +32,9 @@ NonnullRefPtr<BacktraceModel> 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;
}

View file

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

View file

@ -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<const DebugInfo::VariableInfo*>(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 {};

View file

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

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;
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:

View file

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

View file

@ -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<Project::ProjectTreeNode*>(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 {};

View file

@ -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<GUI::Widget*>(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 {};

View file

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

View file

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