Selaa lähdekoodia

LibGUI: Associate model index metadata directly with the model index

This was using internal_data beforehand, which relies on the internal
data to be distinct for different model indices. That's not the case for
example for SortingProxyModel. Using the model index directly makes tree
expansion work properly when using a tree table widget with a
SortingProxyModel.
kleines Filmröllchen 3 vuotta sitten
vanhempi
commit
d813bf77ee

+ 2 - 2
Userland/Libraries/LibGUI/TreeView.cpp

@@ -25,12 +25,12 @@ struct TreeView::MetadataForIndex {
 TreeView::MetadataForIndex& TreeView::ensure_metadata_for_index(ModelIndex const& index) const
 {
     VERIFY(index.is_valid());
-    auto it = m_view_metadata.find(index.internal_data());
+    auto it = m_view_metadata.find(index);
     if (it != m_view_metadata.end())
         return *it->value;
     auto new_metadata = make<MetadataForIndex>();
     auto& new_metadata_ref = *new_metadata;
-    m_view_metadata.set(index.internal_data(), move(new_metadata));
+    m_view_metadata.set(index, move(new_metadata));
     return new_metadata_ref;
 }
 

+ 1 - 1
Userland/Libraries/LibGUI/TreeView.h

@@ -72,7 +72,7 @@ private:
     MetadataForIndex& ensure_metadata_for_index(ModelIndex const&) const;
     void set_open_state_of_all_in_subtree(ModelIndex const& root, bool open);
 
-    mutable HashMap<void*, NonnullOwnPtr<MetadataForIndex>> m_view_metadata;
+    mutable HashMap<ModelIndex, NonnullOwnPtr<MetadataForIndex>> m_view_metadata;
 
     RefPtr<Gfx::Bitmap> m_expand_bitmap;
     RefPtr<Gfx::Bitmap> m_collapse_bitmap;