added get_selected_instances method to be able use it in multiple places

This commit is contained in:
iLLiCiTiT 2021-07-15 09:29:04 +02:00
parent 9f4a2630b8
commit 1290312f4e

View file

@ -183,6 +183,21 @@ class PublisherWindow(QtWidgets.QWidget):
def set_context_label(self, label):
self.context_label.setText(label)
def get_selected_instances(self):
instances = []
instances_by_id = {}
for instance in self.controller.instances:
instance_id = instance.data["uuid"]
instances_by_id[instance_id] = instance
for index in self.subset_view.selectionModel().selectedIndexes():
instance_id = index.data(QtCore.Qt.UserRole)
instance = instances_by_id.get(instance_id)
if instance:
instances.append(instance)
return instances
def _on_reset_clicked(self):
self.reset()
@ -236,17 +251,9 @@ class PublisherWindow(QtWidgets.QWidget):
self._refresh_instances()
def _on_subset_change(self, *_args):
instances = []
instances_by_id = {}
for instance in self.controller.instances:
instance_id = instance.data["uuid"]
instances_by_id[instance_id] = instance
instances = self.get_selected_instances()
for index in self.subset_view.selectionModel().selectedIndexes():
instance_id = index.data(QtCore.Qt.UserRole)
instance = instances_by_id.get(instance_id)
if instance:
instances.append(instance)
self.delete_btn.setEnabled(len(instances) >= 0)
self.subset_attributes_widget.set_current_instances(instances)