1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 23:14:59 +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:
Andreas Kling 2020-08-16 16:14:39 +02:00
parent 96f98b1fc9
commit 9102b624ac
18 changed files with 56 additions and 57 deletions

View file

@ -113,7 +113,7 @@ void TableView::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());
} else if (data.is_icon()) {
@ -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, ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
text_color = cell_index.data(ModelRole::ForegroundColor).to_color(palette().color(foreground_role()));
if (!is_selected_row) {
auto cell_background_color = model()->data(cell_index, ModelRole::BackgroundColor);
auto cell_background_color = cell_index.data(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, ModelRole::TextAlignment).to_text_alignment(Gfx::TextAlignment::CenterLeft);
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);
}
}