mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
LibGUI: Make SortingProxyModel support hierarchical models
We now create multiple levels of internal mappings between source and proxy indexes, to support tree models. This breaks selection update after resort, which we'll have to deal with somehow.
This commit is contained in:
parent
05dd9e5bfb
commit
8c8281de4e
2 changed files with 136 additions and 57 deletions
|
@ -43,6 +43,8 @@ public:
|
|||
virtual Variant data(const ModelIndex&, Role = Role::Display) const override;
|
||||
virtual void update() override;
|
||||
virtual StringView drag_data_type() const override;
|
||||
virtual ModelIndex parent_index(const ModelIndex&) const override;
|
||||
virtual ModelIndex index(int row, int column, const ModelIndex& parent) const override;
|
||||
|
||||
virtual int key_column() const override { return m_key_column; }
|
||||
virtual SortOrder sort_order() const override { return m_sort_order; }
|
||||
|
@ -52,6 +54,7 @@ public:
|
|||
virtual bool less_than(const ModelIndex&, const ModelIndex&) const;
|
||||
|
||||
ModelIndex map_to_source(const ModelIndex&) const;
|
||||
ModelIndex map_to_proxy(const ModelIndex&) const;
|
||||
|
||||
Role sort_role() const { return m_sort_role; }
|
||||
void set_sort_role(Role role) { m_sort_role = role; }
|
||||
|
@ -59,16 +62,27 @@ public:
|
|||
private:
|
||||
explicit SortingProxyModel(NonnullRefPtr<Model> source);
|
||||
|
||||
// NOTE: The internal_data() of indexes points to the corresponding Mapping object for that index.
|
||||
struct Mapping {
|
||||
Vector<int> source_rows;
|
||||
Vector<int> proxy_rows;
|
||||
ModelIndex source_parent;
|
||||
};
|
||||
|
||||
using InternalMapIterator = HashMap<ModelIndex, NonnullOwnPtr<Mapping>>::IteratorType;
|
||||
|
||||
// ^ModelClient
|
||||
virtual void model_did_update(unsigned) override;
|
||||
|
||||
Model& source() { return *m_source; }
|
||||
const Model& source() const { return *m_source; }
|
||||
|
||||
void resort(unsigned flags = Model::UpdateFlag::DontInvalidateIndexes);
|
||||
void invalidate(unsigned flags = Model::UpdateFlag::DontInvalidateIndexes);
|
||||
InternalMapIterator build_mapping(const ModelIndex& proxy_index);
|
||||
|
||||
NonnullRefPtr<Model> m_source;
|
||||
Vector<int> m_row_mappings;
|
||||
|
||||
HashMap<ModelIndex, NonnullOwnPtr<Mapping>> m_mappings;
|
||||
int m_key_column { -1 };
|
||||
SortOrder m_sort_order { SortOrder::Ascending };
|
||||
Role m_sort_role { Role::Sort };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue