mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 17:28:48 +00:00
LibGUI+DevTools+Applications: Use ModelIndex::data() in many places
This way you don't have to keep track of which model it came from.
This commit is contained in:
parent
96f98b1fc9
commit
9102b624ac
Notes:
sideshowbarker
2024-07-19 03:33:02 +09:00
Author: https://github.com/awesomekling
Commit: 9102b624ac
18 changed files with 56 additions and 57 deletions
|
@ -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, ModelRole::Display).to_string();
|
||||
auto node_text = index.data().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()
|
||||
|
@ -293,7 +293,7 @@ void TreeView::paint_event(PaintEvent& event)
|
|||
if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) {
|
||||
delegate->paint(painter, cell_rect, palette(), cell_index);
|
||||
} else {
|
||||
auto data = model.data(cell_index);
|
||||
auto data = cell_index.data();
|
||||
|
||||
if (data.is_bitmap()) {
|
||||
painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect());
|
||||
|
@ -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, ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
|
||||
auto text_alignment = model.data(cell_index, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
text_color = cell_index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
|
||||
auto text_alignment = cell_index.data(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, ModelRole::Icon);
|
||||
auto icon = index.data(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, ModelRole::Display).to_string();
|
||||
auto node_text = index.data().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) {
|
||||
|
@ -544,7 +544,7 @@ void TreeView::update_column_sizes()
|
|||
int column_width = header_width;
|
||||
|
||||
for (int row = 0; row < row_count; ++row) {
|
||||
auto cell_data = model.data(model.index(row, column));
|
||||
auto cell_data = model.index(row, column).data();
|
||||
int cell_width = 0;
|
||||
if (cell_data.is_bitmap()) {
|
||||
cell_width = cell_data.as_bitmap().width();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue