mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
LibGUI: Simplify TableCellPaintingDelegate API slightly
No need to pass the Model *and* a ModelIndex, the index knows which model it belongs to anyway.
This commit is contained in:
parent
f882424869
commit
96f98b1fc9
5 changed files with 8 additions and 8 deletions
|
@ -37,10 +37,10 @@ class PagemapPaintingDelegate final : public GUI::TableCellPaintingDelegate {
|
||||||
public:
|
public:
|
||||||
virtual ~PagemapPaintingDelegate() override {}
|
virtual ~PagemapPaintingDelegate() override {}
|
||||||
|
|
||||||
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::ModelIndex& index) override
|
||||||
{
|
{
|
||||||
auto rect = a_rect.shrunken(2, 2);
|
auto rect = a_rect.shrunken(2, 2);
|
||||||
auto pagemap = model.data(index, GUI::ModelRole::Custom).to_string();
|
auto pagemap = index.data(GUI::ModelRole::Custom).to_string();
|
||||||
|
|
||||||
float scale_factor = (float)pagemap.length() / (float)rect.width();
|
float scale_factor = (float)pagemap.length() / (float)rect.width();
|
||||||
|
|
||||||
|
|
|
@ -337,12 +337,12 @@ class ProgressBarPaintingDelegate final : public GUI::TableCellPaintingDelegate
|
||||||
public:
|
public:
|
||||||
virtual ~ProgressBarPaintingDelegate() override { }
|
virtual ~ProgressBarPaintingDelegate() override { }
|
||||||
|
|
||||||
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::ModelIndex& index) override
|
||||||
{
|
{
|
||||||
auto rect = a_rect.shrunken(2, 2);
|
auto rect = a_rect.shrunken(2, 2);
|
||||||
auto percentage = model.data(index, GUI::ModelRole::Custom).to_i32();
|
auto percentage = index.data(GUI::ModelRole::Custom).to_i32();
|
||||||
|
|
||||||
auto data = model.data(index, GUI::ModelRole::Display);
|
auto data = index.data(GUI::ModelRole::Display);
|
||||||
String text;
|
String text;
|
||||||
if (data.is_string())
|
if (data.is_string())
|
||||||
text = data.as_string();
|
text = data.as_string();
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TableCellPaintingDelegate {
|
||||||
public:
|
public:
|
||||||
virtual ~TableCellPaintingDelegate() {}
|
virtual ~TableCellPaintingDelegate() {}
|
||||||
|
|
||||||
virtual void paint(Painter&, const Gfx::IntRect&, const Gfx::Palette&, const Model&, const ModelIndex&) = 0;
|
virtual void paint(Painter&, const Gfx::IntRect&, const Gfx::Palette&, const ModelIndex&) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AbstractTableView : public AbstractView {
|
class AbstractTableView : public AbstractView {
|
||||||
|
|
|
@ -111,7 +111,7 @@ void TableView::paint_event(PaintEvent& event)
|
||||||
auto cell_index = model()->index(row_index, column_index);
|
auto cell_index = model()->index(row_index, column_index);
|
||||||
|
|
||||||
if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) {
|
if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) {
|
||||||
delegate->paint(painter, cell_rect, palette(), *model(), cell_index);
|
delegate->paint(painter, cell_rect, palette(), cell_index);
|
||||||
} else {
|
} else {
|
||||||
auto data = model()->data(cell_index);
|
auto data = model()->data(cell_index);
|
||||||
if (data.is_bitmap()) {
|
if (data.is_bitmap()) {
|
||||||
|
|
|
@ -291,7 +291,7 @@ void TreeView::paint_event(PaintEvent& event)
|
||||||
auto cell_index = model.index(index.row(), column_index, index.parent());
|
auto cell_index = model.index(index.row(), column_index, index.parent());
|
||||||
|
|
||||||
if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) {
|
if (auto* delegate = column_data(column_index).cell_painting_delegate.ptr()) {
|
||||||
delegate->paint(painter, cell_rect, palette(), model, cell_index);
|
delegate->paint(painter, cell_rect, palette(), cell_index);
|
||||||
} else {
|
} else {
|
||||||
auto data = model.data(cell_index);
|
auto data = model.data(cell_index);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue