diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-28 21:30:17 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-28 21:30:17 +0100 |
commit | bff5b71467b9ef1f5fcee496923dbc9a814fee40 (patch) | |
tree | f60bec74eb1123e51219d8f579d51df34c04ff8b | |
parent | 322f49caece344889919061b365700f989e8c338 (diff) | |
download | serenity-bff5b71467b9ef1f5fcee496923dbc9a814fee40.zip |
LibGUI: Add a GModelNotification class that views will receive.
I don't want to use GEvent here since these need to be synchronous
and mixing sync and async GEvents would be stupid.
-rw-r--r-- | Applications/ProcessManager/ProcessTableView.cpp | 9 | ||||
-rw-r--r-- | Applications/ProcessManager/ProcessTableView.h | 3 | ||||
-rw-r--r-- | LibGUI/GEvent.h | 1 | ||||
-rw-r--r-- | LibGUI/GTableModel.h | 21 | ||||
-rw-r--r-- | LibGUI/GTableView.cpp | 5 | ||||
-rw-r--r-- | LibGUI/GTableView.h | 4 |
6 files changed, 41 insertions, 2 deletions
diff --git a/Applications/ProcessManager/ProcessTableView.cpp b/Applications/ProcessManager/ProcessTableView.cpp index 0e761c852c..015f1b598d 100644 --- a/Applications/ProcessManager/ProcessTableView.cpp +++ b/Applications/ProcessManager/ProcessTableView.cpp @@ -19,6 +19,15 @@ void ProcessTableView::timer_event(GTimerEvent&) model().update(); } +void ProcessTableView::model_notification(const GModelNotification& notification) +{ + if (notification.type() == GModelNotification::ModelUpdated) { + if (on_status_message) + on_status_message(String::format("%d processes", model().row_count())); + return; + } +} + pid_t ProcessTableView::selected_pid() const { return model().selected_pid(); diff --git a/Applications/ProcessManager/ProcessTableView.h b/Applications/ProcessManager/ProcessTableView.h index d1d823a6e4..bd0fe615b4 100644 --- a/Applications/ProcessManager/ProcessTableView.h +++ b/Applications/ProcessManager/ProcessTableView.h @@ -15,6 +15,9 @@ public: Function<void(String)> on_status_message; +protected: + virtual void model_notification(const GModelNotification&) override; + private: virtual void timer_event(GTimerEvent&) override; diff --git a/LibGUI/GEvent.h b/LibGUI/GEvent.h index 5f1527c5a2..86fce807ae 100644 --- a/LibGUI/GEvent.h +++ b/LibGUI/GEvent.h @@ -165,4 +165,3 @@ public: private: int m_timer_id; }; - diff --git a/LibGUI/GTableModel.h b/LibGUI/GTableModel.h index 9c1a4bcbef..3ea5a2f88f 100644 --- a/LibGUI/GTableModel.h +++ b/LibGUI/GTableModel.h @@ -10,6 +10,27 @@ class GTableView; +class GModelNotification { +public: + enum Type { + Invalid = 0, + ModelUpdated, + }; + + explicit GModelNotification(Type type, const GModelIndex& index = GModelIndex()) + : m_type(type) + , m_index(index) + { + } + + Type type() const { return m_type; } + GModelIndex index() const { return m_index; } + +private: + Type m_type { Invalid }; + GModelIndex m_index; +}; + class GTableModel { public: struct ColumnMetadata { diff --git a/LibGUI/GTableView.cpp b/LibGUI/GTableView.cpp index d05b257745..59dc4a5c1c 100644 --- a/LibGUI/GTableView.cpp +++ b/LibGUI/GTableView.cpp @@ -65,10 +65,15 @@ int GTableView::content_width() const return width; } +void GTableView::model_notification(const GModelNotification&) +{ +} + void GTableView::did_update_model() { update_scrollbar_ranges(); update(); + model_notification(GModelNotification(GModelNotification::ModelUpdated)); } Rect GTableView::row_rect(int item_index) const diff --git a/LibGUI/GTableView.h b/LibGUI/GTableView.h index c5aaab28fa..59d346df85 100644 --- a/LibGUI/GTableView.h +++ b/LibGUI/GTableView.h @@ -1,11 +1,11 @@ #pragma once +#include <LibGUI/GTableModel.h> #include <LibGUI/GWidget.h> #include <AK/Function.h> #include <AK/HashMap.h> class GScrollBar; -class GTableModel; class GTableView : public GWidget { public: @@ -25,6 +25,8 @@ public: int horizontal_padding() const { return m_horizontal_padding; } private: + virtual void model_notification(const GModelNotification&); + virtual void paint_event(GPaintEvent&) override; virtual void resize_event(GResizeEvent&) override; virtual void mousedown_event(GMouseEvent&) override; |