浏览代码

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

Using add() is very slow due to the change notifications.
AnotherTest 4 年之前
父节点
当前提交
169beff21e
共有 2 个文件被更改,包括 13 次插入0 次删除
  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();
     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)
 void ModelSelection::toggle(const ModelIndex& index)
 {
 {
     ASSERT(index.is_valid());
     ASSERT(index.is_valid());

+ 1 - 0
Libraries/LibGUI/ModelSelection.h

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