mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 20:32:44 +00:00 
			
		
		
		
	 3f35ffb648
			
		
	
	
		3f35ffb648
		
	
	
	
	
		
			
			As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
		
	
			
		
			
				
	
	
		
			41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Function.h>
 | |
| #include <AK/NonnullRefPtr.h>
 | |
| #include <AK/Vector.h>
 | |
| #include <LibGUI/Model.h>
 | |
| 
 | |
| class BasicModel final : public GUI::Model {
 | |
| public:
 | |
|     static NonnullRefPtr<BasicModel> create()
 | |
|     {
 | |
|         return adopt_ref(*new BasicModel());
 | |
|     }
 | |
| 
 | |
|     virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_items.size(); }
 | |
|     virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return 1; }
 | |
|     virtual ErrorOr<String> column_name(int) const override { return "Item"_string; }
 | |
| 
 | |
|     virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole = GUI::ModelRole::Display) const override;
 | |
|     virtual GUI::Model::MatchResult data_matches(GUI::ModelIndex const&, GUI::Variant const&) const override;
 | |
|     virtual void invalidate() override;
 | |
|     virtual GUI::ModelIndex index(int row, int column = 0, GUI::ModelIndex const& parent = GUI::ModelIndex()) const override;
 | |
| 
 | |
|     Function<void()> on_invalidate;
 | |
| 
 | |
|     void add_item(DeprecatedString const& item);
 | |
|     void remove_item(GUI::ModelIndex const&);
 | |
| 
 | |
| private:
 | |
|     BasicModel()
 | |
|     {
 | |
|     }
 | |
| 
 | |
|     Vector<DeprecatedString> m_items;
 | |
| };
 |