mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:32:44 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									322f49caec
								
							
						
					
					
						commit
						bff5b71467
					
				
					 6 changed files with 41 additions and 2 deletions
				
			
		|  | @ -19,6 +19,15 @@ void ProcessTableView::timer_event(GTimerEvent&) | ||||||
|     model().update(); |     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 | pid_t ProcessTableView::selected_pid() const | ||||||
| { | { | ||||||
|     return model().selected_pid(); |     return model().selected_pid(); | ||||||
|  |  | ||||||
|  | @ -15,6 +15,9 @@ public: | ||||||
| 
 | 
 | ||||||
|     Function<void(String)> on_status_message; |     Function<void(String)> on_status_message; | ||||||
| 
 | 
 | ||||||
|  | protected: | ||||||
|  |     virtual void model_notification(const GModelNotification&) override; | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|     virtual void timer_event(GTimerEvent&) override; |     virtual void timer_event(GTimerEvent&) override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -165,4 +165,3 @@ public: | ||||||
| private: | private: | ||||||
|     int m_timer_id; |     int m_timer_id; | ||||||
| }; | }; | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -10,6 +10,27 @@ | ||||||
| 
 | 
 | ||||||
| class GTableView; | 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 { | class GTableModel { | ||||||
| public: | public: | ||||||
|     struct ColumnMetadata { |     struct ColumnMetadata { | ||||||
|  |  | ||||||
|  | @ -65,10 +65,15 @@ int GTableView::content_width() const | ||||||
|     return width; |     return width; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void GTableView::model_notification(const GModelNotification&) | ||||||
|  | { | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void GTableView::did_update_model() | void GTableView::did_update_model() | ||||||
| { | { | ||||||
|     update_scrollbar_ranges(); |     update_scrollbar_ranges(); | ||||||
|     update(); |     update(); | ||||||
|  |     model_notification(GModelNotification(GModelNotification::ModelUpdated)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Rect GTableView::row_rect(int item_index) const | Rect GTableView::row_rect(int item_index) const | ||||||
|  |  | ||||||
|  | @ -1,11 +1,11 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <LibGUI/GTableModel.h> | ||||||
| #include <LibGUI/GWidget.h> | #include <LibGUI/GWidget.h> | ||||||
| #include <AK/Function.h> | #include <AK/Function.h> | ||||||
| #include <AK/HashMap.h> | #include <AK/HashMap.h> | ||||||
| 
 | 
 | ||||||
| class GScrollBar; | class GScrollBar; | ||||||
| class GTableModel; |  | ||||||
| 
 | 
 | ||||||
| class GTableView : public GWidget { | class GTableView : public GWidget { | ||||||
| public: | public: | ||||||
|  | @ -25,6 +25,8 @@ public: | ||||||
|     int horizontal_padding() const { return m_horizontal_padding; } |     int horizontal_padding() const { return m_horizontal_padding; } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |     virtual void model_notification(const GModelNotification&); | ||||||
|  | 
 | ||||||
|     virtual void paint_event(GPaintEvent&) override; |     virtual void paint_event(GPaintEvent&) override; | ||||||
|     virtual void resize_event(GResizeEvent&) override; |     virtual void resize_event(GResizeEvent&) override; | ||||||
|     virtual void mousedown_event(GMouseEvent&) override; |     virtual void mousedown_event(GMouseEvent&) override; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling