summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-11-26 11:10:14 +0330
committerAndreas Kling <kling@serenityos.org>2020-11-30 12:07:45 +0100
commit71de8b748068d3c2a7adb2796b2ed60c17a46552 (patch)
tree87932aec0d736782646c93e71a4f424a226da4b4
parent868c315e51b8322deb9cbe03cb16af22adb25651 (diff)
downloadserenity-71de8b748068d3c2a7adb2796b2ed60c17a46552.zip
LibGUI: Remove `AbstractView::did_update_model()'
...and use `ModelClient::model_did_update()' instead. This makes AbstractView a ModelClient (which it always was anyway).
-rw-r--r--Libraries/LibGUI/AbstractTableView.cpp4
-rw-r--r--Libraries/LibGUI/AbstractTableView.h3
-rw-r--r--Libraries/LibGUI/AbstractView.cpp4
-rw-r--r--Libraries/LibGUI/AbstractView.h8
-rw-r--r--Libraries/LibGUI/ColumnsView.cpp4
-rw-r--r--Libraries/LibGUI/ColumnsView.h2
-rw-r--r--Libraries/LibGUI/IconView.cpp4
-rw-r--r--Libraries/LibGUI/IconView.h2
-rw-r--r--Libraries/LibGUI/ListView.cpp4
-rw-r--r--Libraries/LibGUI/ListView.h2
-rw-r--r--Libraries/LibGUI/Model.cpp6
-rw-r--r--Libraries/LibGUI/TreeView.cpp4
-rw-r--r--Libraries/LibGUI/TreeView.h2
13 files changed, 26 insertions, 23 deletions
diff --git a/Libraries/LibGUI/AbstractTableView.cpp b/Libraries/LibGUI/AbstractTableView.cpp
index 087f217f11..a5fc870fd3 100644
--- a/Libraries/LibGUI/AbstractTableView.cpp
+++ b/Libraries/LibGUI/AbstractTableView.cpp
@@ -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();
diff --git a/Libraries/LibGUI/AbstractTableView.h b/Libraries/LibGUI/AbstractTableView.h
index dc6698c06a..b64e4b3bcb 100644
--- a/Libraries/LibGUI/AbstractTableView.h
+++ b/Libraries/LibGUI/AbstractTableView.h
@@ -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();
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp
index 9270f6b54c..c7f40422dc 100644
--- a/Libraries/LibGUI/AbstractView.cpp
+++ b/Libraries/LibGUI/AbstractView.cpp
@@ -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();
diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h
index 676bca54fc..7e66730c8b 100644
--- a/Libraries/LibGUI/AbstractView.h
+++ b/Libraries/LibGUI/AbstractView.h
@@ -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 {}; }
diff --git a/Libraries/LibGUI/ColumnsView.cpp b/Libraries/LibGUI/ColumnsView.cpp
index 169a29b811..3f4564a562 100644
--- a/Libraries/LibGUI/ColumnsView.cpp
+++ b/Libraries/LibGUI/ColumnsView.cpp
@@ -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 :(";
diff --git a/Libraries/LibGUI/ColumnsView.h b/Libraries/LibGUI/ColumnsView.h
index 5694d20d0e..843b3d2e6c 100644
--- a/Libraries/LibGUI/ColumnsView.h
+++ b/Libraries/LibGUI/ColumnsView.h
@@ -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;
diff --git a/Libraries/LibGUI/IconView.cpp b/Libraries/LibGUI/IconView.cpp
index 5b5b3f8bf1..a72bcecead 100644
--- a/Libraries/LibGUI/IconView.cpp
+++ b/Libraries/LibGUI/IconView.cpp
@@ -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();
diff --git a/Libraries/LibGUI/IconView.h b/Libraries/LibGUI/IconView.h
index 62f4cbd5ca..14faed7929 100644
--- a/Libraries/LibGUI/IconView.h
+++ b/Libraries/LibGUI/IconView.h
@@ -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;
diff --git a/Libraries/LibGUI/ListView.cpp b/Libraries/LibGUI/ListView.cpp
index 916c95511a..f4c0236dfd 100644
--- a/Libraries/LibGUI/ListView.cpp
+++ b/Libraries/LibGUI/ListView.cpp
@@ -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();
}
diff --git a/Libraries/LibGUI/ListView.h b/Libraries/LibGUI/ListView.h
index f1accd47ae..0609b00944 100644
--- a/Libraries/LibGUI/ListView.h
+++ b/Libraries/LibGUI/ListView.h
@@ -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;
diff --git a/Libraries/LibGUI/Model.cpp b/Libraries/LibGUI/Model.cpp
index b9e9d1e30c..6f8b833f7d 100644
--- a/Libraries/LibGUI/Model.cpp
+++ b/Libraries/LibGUI/Model.cpp
@@ -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
diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp
index d09e6ed40b..80f2bef9f6 100644
--- a/Libraries/LibGUI/TreeView.cpp
+++ b/Libraries/LibGUI/TreeView.cpp
@@ -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()
diff --git a/Libraries/LibGUI/TreeView.h b/Libraries/LibGUI/TreeView.h
index 2695dacb34..76b1754302 100644
--- a/Libraries/LibGUI/TreeView.h
+++ b/Libraries/LibGUI/TreeView.h
@@ -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: