mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +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:
parent
f6d7204689
commit
a1e381a0f8
66 changed files with 201 additions and 167 deletions
|
@ -134,7 +134,7 @@ void AbstractView::begin_editing(const ModelIndex& index)
|
|||
ASSERT(aid_create_editing_delegate);
|
||||
m_editing_delegate = aid_create_editing_delegate(index);
|
||||
m_editing_delegate->bind(*model(), index);
|
||||
m_editing_delegate->set_value(model()->data(index, Model::Role::Display));
|
||||
m_editing_delegate->set_value(model()->data(index, ModelRole::Display));
|
||||
m_edit_widget = m_editing_delegate->widget();
|
||||
add_child(*m_edit_widget);
|
||||
m_edit_widget->move_to_back();
|
||||
|
@ -187,7 +187,7 @@ NonnullRefPtr<Gfx::Font> AbstractView::font_for_index(const ModelIndex& index) c
|
|||
if (!model())
|
||||
return font();
|
||||
|
||||
auto font_data = model()->data(index, Model::Role::Font);
|
||||
auto font_data = model()->data(index, ModelRole::Font);
|
||||
if (font_data.is_font())
|
||||
return font_data.as_font();
|
||||
|
||||
|
@ -285,14 +285,14 @@ void AbstractView::mousemove_event(MouseEvent& event)
|
|||
text_builder.append(", ");
|
||||
text_builder.append(text_data.to_string());
|
||||
|
||||
auto drag_data = m_model->data(index, Model::Role::DragData);
|
||||
auto drag_data = m_model->data(index, ModelRole::DragData);
|
||||
data_builder.append(drag_data.to_string());
|
||||
data_builder.append('\n');
|
||||
|
||||
first = false;
|
||||
|
||||
if (!bitmap) {
|
||||
Variant icon_data = model()->data(index, Model::Role::Icon);
|
||||
Variant icon_data = model()->data(index, ModelRole::Icon);
|
||||
if (icon_data.is_icon())
|
||||
bitmap = icon_data.as_icon().bitmap_for_size(32);
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibGUI/ModelIndex.h>
|
||||
#include <LibGUI/ModelRole.h>
|
||||
#include <LibGUI/Variant.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/TextAlignment.h>
|
||||
|
@ -58,25 +59,12 @@ public:
|
|||
InvalidateAllIndexes = 1 << 0,
|
||||
};
|
||||
|
||||
enum class Role {
|
||||
Display,
|
||||
Sort,
|
||||
ForegroundColor,
|
||||
BackgroundColor,
|
||||
Icon,
|
||||
Font,
|
||||
DragData,
|
||||
TextAlignment,
|
||||
Search,
|
||||
Custom = 0x100, // Applications are free to use roles above this number as they please
|
||||
};
|
||||
|
||||
virtual ~Model();
|
||||
|
||||
virtual int row_count(const ModelIndex& = ModelIndex()) const = 0;
|
||||
virtual int column_count(const ModelIndex& = ModelIndex()) const = 0;
|
||||
virtual String column_name(int) const { return {}; }
|
||||
virtual Variant data(const ModelIndex&, Role = Role::Display) const = 0;
|
||||
virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const = 0;
|
||||
virtual TriState data_matches(const ModelIndex&, Variant) const { return TriState::Unknown; }
|
||||
virtual void update() = 0;
|
||||
virtual ModelIndex parent_index(const ModelIndex&) const { return {}; }
|
||||
|
|
44
Libraries/LibGUI/ModelRole.h
Normal file
44
Libraries/LibGUI/ModelRole.h
Normal 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
|
||||
};
|
||||
|
||||
}
|
|
@ -57,7 +57,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
|
||||
m_table_view = widget.add<GUI::TableView>();
|
||||
auto sorting_model = GUI::SortingProxyModel::create(RunningProcessesModel::create());
|
||||
sorting_model->set_sort_role(GUI::Model::Role::Display);
|
||||
sorting_model->set_sort_role(GUI::ModelRole::Display);
|
||||
m_table_view->set_key_column_and_sort_order(RunningProcessesModel::Column::PID, GUI::SortOrder::Descending);
|
||||
m_table_view->set_model(sorting_model);
|
||||
|
||||
|
@ -96,7 +96,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
m_refresh_timer->on_timeout = [this] {
|
||||
auto previous_selected_pid = -1; // Store the selection index to not to clear the selection upon update.
|
||||
if (!m_table_view->selection().is_empty()) {
|
||||
auto pid_as_variant = m_table_view->model()->data(m_table_view->selection().first(), GUI::Model::Role::Custom);
|
||||
auto pid_as_variant = m_table_view->model()->data(m_table_view->selection().first(), GUI::ModelRole::Custom);
|
||||
previous_selected_pid = pid_as_variant.as_i32();
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
auto column_index = 1; // Corresponds to PID column in the m_table_view.
|
||||
for (int row_index = 0; row_index < row_count; ++row_index) {
|
||||
auto cell_index = model->index(row_index, column_index);
|
||||
auto pid_as_variant = model->data(cell_index, GUI::Model::Role::Custom);
|
||||
auto pid_as_variant = model->data(cell_index, GUI::ModelRole::Custom);
|
||||
if (previous_selected_pid == pid_as_variant.as_i32()) {
|
||||
m_table_view->selection().set(cell_index); // Set only if PIDs are matched.
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ ProcessChooser::ProcessChooser(const StringView& window_title, const StringView&
|
|||
|
||||
void ProcessChooser::set_pid_from_index_and_close(const ModelIndex& index)
|
||||
{
|
||||
auto pid_as_variant = m_table_view->model()->data(index, GUI::Model::Role::Custom);
|
||||
auto pid_as_variant = m_table_view->model()->data(index, GUI::ModelRole::Custom);
|
||||
m_pid = pid_as_variant.as_i32();
|
||||
done(ExecOK);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual int row_count(const ModelIndex& = ModelIndex()) const override;
|
||||
virtual int column_count(const ModelIndex& = ModelIndex()) const override;
|
||||
virtual String column_name(int) const override;
|
||||
virtual Variant data(const ModelIndex&, Role = Role::Display) const override;
|
||||
virtual Variant data(const ModelIndex&, ModelRole = ModelRole::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual StringView drag_data_type() const override;
|
||||
virtual ModelIndex parent_index(const ModelIndex&) const override;
|
||||
|
@ -53,8 +53,8 @@ public:
|
|||
ModelIndex map_to_source(const ModelIndex&) const;
|
||||
ModelIndex map_to_proxy(const ModelIndex&) const;
|
||||
|
||||
Role sort_role() const { return m_sort_role; }
|
||||
void set_sort_role(Role role) { m_sort_role = role; }
|
||||
ModelRole sort_role() const { return m_sort_role; }
|
||||
void set_sort_role(ModelRole role) { m_sort_role = role; }
|
||||
|
||||
virtual void sort(int column, SortOrder) override;
|
||||
|
||||
|
@ -84,7 +84,7 @@ private:
|
|||
NonnullRefPtr<Model> m_source;
|
||||
|
||||
HashMap<ModelIndex, NonnullOwnPtr<Mapping>> m_mappings;
|
||||
Role m_sort_role { Role::Sort };
|
||||
ModelRole m_sort_role { ModelRole::Sort };
|
||||
int m_last_key_column { -1 };
|
||||
SortOrder m_last_sort_order { SortOrder::Ascending };
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -115,10 +115,10 @@ static String with_whitespace_collapsed(const StringView& string)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto& node = *static_cast<DOM::Node*>(index.internal_data());
|
||||
if (role == Role::Icon) {
|
||||
if (role == GUI::ModelRole::Icon) {
|
||||
if (node.is_document())
|
||||
return m_document_icon;
|
||||
if (node.is_element())
|
||||
|
@ -126,7 +126,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const
|
|||
// FIXME: More node type icons?
|
||||
return m_text_icon;
|
||||
}
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (node.is_text())
|
||||
return String::format("%s", with_whitespace_collapsed(downcast<DOM::Text>(node).data()).characters());
|
||||
if (!node.is_element())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -115,17 +115,17 @@ static String with_whitespace_collapsed(const StringView& string)
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
||||
{
|
||||
auto& node = *static_cast<LayoutNode*>(index.internal_data());
|
||||
if (role == Role::Icon) {
|
||||
if (role == GUI::ModelRole::Icon) {
|
||||
if (node.is_root())
|
||||
return m_document_icon;
|
||||
if (node.is_text())
|
||||
return m_text_icon;
|
||||
return m_element_icon;
|
||||
}
|
||||
if (role == Role::Display) {
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (node.is_text())
|
||||
return String::format("LayoutText: %s", with_whitespace_collapsed(downcast<LayoutText>(node).text_for_rendering()).characters());
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue