Browse Source

LibGUI: Add a ModelSelection::add_all(Vector) API

Using add() is very slow due to the change notifications.
AnotherTest 4 năm trước cách đây
mục cha
commit
169beff21e
2 tập tin đã thay đổi với 13 bổ sung0 xóa
  1. 12 0
      Libraries/LibGUI/ModelSelection.cpp
  2. 1 0
      Libraries/LibGUI/ModelSelection.h

+ 12 - 0
Libraries/LibGUI/ModelSelection.cpp

@@ -64,6 +64,18 @@ void ModelSelection::add(const ModelIndex& index)
     notify_selection_changed();
 }
 
+void ModelSelection::add_all(const Vector<ModelIndex>& indices)
+{
+    {
+        TemporaryChange notify_change { m_disable_notify, true };
+        for (auto& index : indices)
+            add(index);
+    }
+
+    if (m_notify_pending)
+        notify_selection_changed();
+}
+
 void ModelSelection::toggle(const ModelIndex& index)
 {
     ASSERT(index.is_valid());

+ 1 - 0
Libraries/LibGUI/ModelSelection.h

@@ -59,6 +59,7 @@ public:
 
     void set(const ModelIndex&);
     void add(const ModelIndex&);
+    void add_all(const Vector<ModelIndex>&);
     void toggle(const ModelIndex&);
     bool remove(const ModelIndex&);
     void clear();