LibGUI: Remove `AbstractView::did_update_model()'

...and use `ModelClient::model_did_update()' instead.
This makes AbstractView a ModelClient (which it always was anyway).
This commit is contained in:
AnotherTest 2020-11-26 11:10:14 +03:30 committed by Andreas Kling
parent 868c315e51
commit 71de8b7480
13 changed files with 26 additions and 23 deletions

View file

@ -287,9 +287,9 @@ Gfx::IntPoint AbstractTableView::adjusted_position(const Gfx::IntPoint& position
return position.translated(horizontal_scrollbar().value() - frame_thickness(), vertical_scrollbar().value() - frame_thickness());
}
void AbstractTableView::did_update_model(unsigned flags)
void AbstractTableView::model_did_update(unsigned flags)
{
AbstractView::did_update_model(flags);
AbstractView::model_did_update(flags);
update_row_sizes();
update_column_sizes();
update_content_size();

View file

@ -89,6 +89,8 @@ public:
HeaderView& row_header() { return *m_row_header; }
const HeaderView& row_header() const { return *m_row_header; }
virtual void model_did_update(unsigned flags) override;
protected:
virtual ~AbstractTableView() override;
AbstractTableView();
@ -98,7 +100,6 @@ protected:
virtual void keydown_event(KeyEvent&) override;
virtual void resize_event(ResizeEvent&) override;
virtual void did_update_model(unsigned flags) override;
virtual void toggle_index(const ModelIndex&) { }
void update_content_size();

View file

@ -63,11 +63,11 @@ void AbstractView::set_model(RefPtr<Model> model)
m_model = move(model);
if (m_model)
m_model->register_view({}, *this);
did_update_model(GUI::Model::InvalidateAllIndexes);
model_did_update(GUI::Model::InvalidateAllIndexes);
scroll_to_top();
}
void AbstractView::did_update_model(unsigned flags)
void AbstractView::model_did_update(unsigned int flags)
{
// FIXME: It's unfortunate that we lose so much view state when the model updates in any way.
stop_editing();

View file

@ -27,13 +27,17 @@
#pragma once
#include <AK/Function.h>
#include <LibGUI/Model.h>
#include <LibGUI/ModelSelection.h>
#include <LibGUI/ScrollableWidget.h>
#include <LibGfx/TextElision.h>
namespace GUI {
class AbstractView : public ScrollableWidget {
class AbstractView
: public ScrollableWidget
, public ModelClient {
C_OBJECT_ABSTRACT(AbstractView);
public:
@ -87,7 +91,7 @@ public:
bool is_multi_select() const { return m_multi_select; }
void set_multi_select(bool);
virtual void did_update_model(unsigned flags);
virtual void model_did_update(unsigned flags) override;
virtual void did_update_selection();
virtual Gfx::IntRect content_rect(const ModelIndex&) const { return {}; }

View file

@ -267,9 +267,9 @@ void ColumnsView::mousedown_event(MouseEvent& event)
}
}
void ColumnsView::did_update_model(unsigned flags)
void ColumnsView::model_did_update(unsigned flags)
{
AbstractView::did_update_model(flags);
AbstractView::model_did_update(flags);
// FIXME: Don't drop the columns on minor updates.
dbg() << "Model was updated; dropping columns :(";

View file

@ -51,7 +51,7 @@ private:
int icon_spacing() const { return 2; }
int text_padding() const { return 2; }
virtual void did_update_model(unsigned flags) override;
virtual void model_did_update(unsigned flags) override;
virtual void paint_event(PaintEvent&) override;
virtual void mousedown_event(MouseEvent& event) override;

View file

@ -135,9 +135,9 @@ auto IconView::item_data_from_content_position(const Gfx::IntPoint& content_posi
return &get_item_data(item_index);
}
void IconView::did_update_model(unsigned flags)
void IconView::model_did_update(unsigned flags)
{
AbstractView::did_update_model(flags);
AbstractView::model_did_update(flags);
if (!model() || (flags & GUI::Model::InvalidateAllIndexes)) {
m_item_data_cache.clear();
AbstractView::clear_selection();

View file

@ -56,7 +56,7 @@ public:
private:
IconView();
virtual void did_update_model(unsigned flags) override;
virtual void model_did_update(unsigned flags) override;
virtual void paint_event(PaintEvent&) override;
virtual void second_paint_event(PaintEvent&) override;
virtual void resize_event(ResizeEvent&) override;

View file

@ -75,9 +75,9 @@ void ListView::resize_event(ResizeEvent& event)
AbstractView::resize_event(event);
}
void ListView::did_update_model(unsigned flags)
void ListView::model_did_update(unsigned flags)
{
AbstractView::did_update_model(flags);
AbstractView::model_did_update(flags);
update_content_size();
update();
}

View file

@ -67,7 +67,7 @@ protected:
virtual void paint_list_item(Painter&, int row_index, int painted_item_index);
private:
virtual void did_update_model(unsigned flags) override;
virtual void model_did_update(unsigned flags) override;
virtual void paint_event(PaintEvent&) override;
virtual void keydown_event(KeyEvent&) override;
virtual void resize_event(ResizeEvent&) override;

View file

@ -40,11 +40,13 @@ Model::~Model()
void Model::register_view(Badge<AbstractView>, AbstractView& view)
{
m_views.set(&view);
m_clients.set(&view);
}
void Model::unregister_view(Badge<AbstractView>, AbstractView& view)
{
m_views.remove(&view);
m_clients.remove(&view);
}
void Model::for_each_view(Function<void(AbstractView&)> callback)
@ -57,10 +59,6 @@ void Model::did_update(unsigned flags)
{
for (auto* client : m_clients)
client->model_did_update(flags);
for_each_view([&](auto& view) {
view.did_update_model(flags);
});
}
ModelIndex Model::create_index(int row, int column, const void* data) const

View file

@ -399,10 +399,10 @@ void TreeView::scroll_into_view(const ModelIndex& a_index, bool scroll_horizonta
ScrollableWidget::scroll_into_view(found_rect, scroll_horizontally, scroll_vertically);
}
void TreeView::did_update_model(unsigned flags)
void TreeView::model_did_update(unsigned flags)
{
m_view_metadata.clear();
AbstractTableView::did_update_model(flags);
AbstractTableView::model_did_update(flags);
}
void TreeView::did_update_selection()

View file

@ -59,7 +59,7 @@ protected:
virtual void keydown_event(KeyEvent&) override;
virtual void did_update_selection() override;
virtual void did_update_model(unsigned flags) override;
virtual void model_did_update(unsigned flags) override;
virtual void move_cursor(CursorMovement, SelectionUpdate) override;
private: