def__init__(self,parent,parent_item=None,items=[],item_type=Activity):"""Constructor"""super().__init__()self.setupUi(self)self.parent=parentself.parent_item=parent_itemself.item_type=item_typeself.items=itemsselect_all_btn=QtWidgets.QPushButton(tr("Select All"))select_all_btn.setToolTip(tr("Select the all listed items"))select_all_btn.clicked.connect(self.select_all_clicked)self.mButtonBox.addButton(select_all_btn,QtWidgets.QDialogButtonBox.ActionRole)clear_all_btn=QtWidgets.QPushButton(tr("Clear Selection"))clear_all_btn.setToolTip(tr("Clear the current selection"))clear_all_btn.clicked.connect(self.clear_all_clicked)self.mButtonBox.addButton(clear_all_btn,QtWidgets.QDialogButtonBox.ActionRole)toggle_selection_btn=QtWidgets.QPushButton(tr("Toggle Selection"))toggle_selection_btn.clicked.connect(self.toggle_selection_clicked)self.mButtonBox.addButton(toggle_selection_btn,QtWidgets.QDialogButtonBox.ActionRole)self.mButtonBox.accepted.connect(self.accept)self.set_items()forindexinrange(self.list_widget.count()):item=self.list_widget.item(index)item_uuid=item.data(QtCore.Qt.UserRole)ifself.item_typeisActivity:activity=settings_manager.get_activity(str(item_uuid))layer_model_uuids=[item.uuidforiteminself.items]activity_layer_uuids=[layer.get("uuid")forlayerinactivity.priority_layersiflayerisnotNone]if(self.parent_itemisnotNoneandstr(self.parent_item.get("uuid"))inactivity_layer_uuids)or(activity.uuidinlayer_model_uuids):item.setCheckState(QtCore.Qt.Checked)else:layer=settings_manager.get_priority_layer(str(item_uuid))group_uuids=[]forgroupinlayer.get("groups"):group=settings_manager.find_group_by_name(group.get("name"))ifgroupisnotNone:group_uuids.append(str(group.get("uuid")))ifself.parent_item.get("uuid")ingroup_uuids:item.setCheckState(QtCore.Qt.Checked)
accept
accept()
Saves the item selection
Source code in src/cplus_plugin/gui/items_selection_dialog.py
defclear_all_clicked(self):"""Slot for handling clear selection for all items."""foritem_indexinrange(self.list_widget.count()):item_item=self.list_widget.item(item_index)item_item.setCheckState(QtCore.Qt.Unchecked)
select_all_clicked
select_all_clicked()
Slot for handling selection for all items.
Source code in src/cplus_plugin/gui/items_selection_dialog.py
defselect_all_clicked(self):"""Slot for handling selection for all items."""foritem_indexinrange(self.list_widget.count()):item_item=self.list_widget.item(item_index)item_item.setCheckState(QtCore.Qt.Checked)
selected_items
selected_items()
Returns the selected items from the dialog
Source code in src/cplus_plugin/gui/items_selection_dialog.py
defselected_items(self):"""Returns the selected items from the dialog"""ifself.item_typeisActivity:items=settings_manager.get_all_activities()else:all_layers=settings_manager.get_priority_layers()items=[]forlayerinall_layers:model_layer=PriorityLayer(uuid=uuid.UUID(layer.get("uuid")),name=layer.get("name"),description=layer.get("description"),groups=layer.get("groups"),)items.append(model_layer)items_text=[]forindexinrange(self.list_widget.count()):item=self.list_widget.item(index)ifitem.checkState()==QtCore.Qt.Checked:items_text.append(item.text())final_items=[]foriteminitems:foritem_nameinitems_text:ifitem.name==item_name:final_items.append(item)breakreturnfinal_items
set_items
set_items()
Sets the item list in the dialog
Source code in src/cplus_plugin/gui/items_selection_dialog.py
defset_items(self):"""Sets the item list in the dialog"""ifself.item_typeisActivity:items=settings_manager.get_all_activities()else:all_layers=settings_manager.get_priority_layers()items=[]forlayerinall_layers:model_layer=PriorityLayer(uuid=uuid.UUID(layer.get("uuid")),name=layer.get("name"),description=layer.get("description"),groups=layer.get("groups"),)items.append(model_layer)foriteminitems:list_widget_item=QtWidgets.QListWidgetItem(item.name)list_widget_item.setFlags(list_widget_item.flags()|QtCore.Qt.ItemIsUserCheckable)list_widget_item.setData(QtCore.Qt.UserRole,item.uuid)list_widget_item.setCheckState(QtCore.Qt.Unchecked)self.list_widget.addItem(list_widget_item)
toggle_selection_clicked
toggle_selection_clicked()
Toggles all the current items selection.
Source code in src/cplus_plugin/gui/items_selection_dialog.py
deftoggle_selection_clicked(self):"""Toggles all the current items selection."""foritem_indexinrange(self.list_widget.count()):item_item=self.list_widget.item(item_index)state=item_item.checkState()ifstate==QtCore.Qt.Checked:item_item.setCheckState(QtCore.Qt.Unchecked)elifstate==QtCore.Qt.Unchecked:item_item.setCheckState(QtCore.Qt.Checked)
unselected_items
unselected_items()
Returns unselected items from the dialog
Source code in src/cplus_plugin/gui/items_selection_dialog.py
defunselected_items(self):"""Returns unselected items from the dialog"""ifself.item_typeisActivity:items=settings_manager.get_all_activities()else:all_layers=settings_manager.get_priority_layers()items=[]forlayerinall_layers:model_layer=PriorityLayer(uuid=uuid.UUID(layer.get("uuid")),name=layer.get("name"),description=layer.get("description"),groups=layer.get("groups"),)items.append(model_layer)items_text=[]forindexinrange(self.list_widget.count()):item=self.list_widget.item(index)ifitem.checkState()==QtCore.Qt.Unchecked:items_text.append(item.text())item_names=",".join(items_text)items=[itemforiteminitemsifitem.nameinitem_names]returnitems