mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-12-05 16:51:12 -07:00
Use ListModel.setItems() instead of appending one item at a time
setItems sets the items to a (presorted) list of items instead of adding items one by one and then sorting the list. This way if an update to the model causes a signal storm at least it happens only once for an update. Specifically this reduces switching to a dual extrusion printer by half. Contributes to CURA-2193
This commit is contained in:
parent
0e602b8d0b
commit
b343649131
3 changed files with 14 additions and 9 deletions
|
|
@ -97,9 +97,10 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
changed = False
|
||||
|
||||
if self.rowCount() != 0:
|
||||
self.clear()
|
||||
changed = True
|
||||
|
||||
items = []
|
||||
|
||||
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
if self._add_global:
|
||||
|
|
@ -111,7 +112,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"color": color,
|
||||
"index": -1
|
||||
}
|
||||
self.appendItem(item)
|
||||
items.append(item)
|
||||
changed = True
|
||||
|
||||
manager = ExtruderManager.getInstance()
|
||||
|
|
@ -133,9 +134,10 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
|||
"color": color,
|
||||
"index": position
|
||||
}
|
||||
self.appendItem(item)
|
||||
items.append(item)
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
self.sort(lambda item: item["index"])
|
||||
items.sort(key = lambda i: i["index"])
|
||||
self.setItems(items)
|
||||
self.modelChanged.emit()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue