def setItems(self, items): self.clear() for name in items: item = QListWidgetItem(name) item.setFlags(item.flags() or Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) self.addItem(item)
def update_schema_names_model(self): res, msg = self.db.test_connection() schema_names = self.db._schema_names_list() if schema_names: for schema_name in schema_names: item = QListWidgetItem(schema_name['schema_name']) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) self.schema_names_list_widget.addItem(item) default_item = self.schema_names_list_widget.item(0) default_item.setCheckState(Qt.Checked) else: self.schema_names_list_widget.clear() self.export_models_list_view.setModel(QStandardItemModel()) message_error = 'There are no schemes to export into the database. Please select another database.' self.txtStdout.setText( QCoreApplication.translate("DialogExportData", message_error)) self.show_message(message_error, Qgis.Warning) self.schema_names_list_widget.currentRowChanged.connect( self.on_current_row_changed_schema_names) self.schema_names_list_widget.itemChanged.connect( self.on_itemchanged_schema_name)
def update_import_models(self): for modelname in DEFAULT_MODEL_NAMES_CHECKED: item = QListWidgetItem(modelname) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) item.setCheckState(DEFAULT_MODEL_NAMES_CHECKED[modelname]) self.import_models_list_widget.addItem(item) self.import_models_list_widget.itemClicked.connect(self.on_item_clicked_import_model) self.import_models_list_widget.itemChanged.connect(self.on_itemchanged_import_model)
def getNewCompo(self, w, cView): """Function that finds new layout to be added to the list.""" nameCompo = cView.name() if not w.findItems(nameCompo, Qt.MatchExactly): item = QListWidgetItem() item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) item.setText(nameCompo) w.addItem(item)
def __addPolygonsToGui(self): self.ui.IDC_listPolygons.clear() self.ui.cmbCadastreLayer.clear() check = Qt.Unchecked for poly_lyr in self.settings.mapData.polygons.polygons(): item = QListWidgetItem(poly_lyr.name) item.setData(Qt.UserRole, poly_lyr) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(check) self.ui.IDC_listPolygons.addItem(item) self.ui.cmbCadastreLayer.addItem(poly_lyr.name, poly_lyr.id)
def __addPolygonsToGui(self): self.ui.IDC_listPolygons.clear() self.ui.cmbCadastreLayer.clear() check = Qt.Unchecked for poly_lyr in self.settings.mapData.polygons.polygons(): item = QListWidgetItem(poly_lyr.name) item.setData(Qt.UserRole, poly_lyr) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(check) self.ui.IDC_listPolygons.addItem(item) self.ui.cmbCadastreLayer.addItem(poly_lyr.name, poly_lyr.id)
def _create_topics_list(self, topics): """Builds qt list with topics items from given data. Args: topics (Dict[str, Any]): topics data (title, abstract, visible_overlays) """ for topic_data in topics: item = QListWidgetItem(topic_data.pop('title')) item.setFlags(item.flags() | Qt.ItemIsEditable) item.setData(Qt.UserRole, topic_data) self.dialog.topicsList.addItem(item)
def on_loadTypesPushButton_clicked(self): LOGGER.info("CLicked") self.listWidget.clear() wfs = self.wfsPathLineEdit.text() self.converter = KuntaGML2Layers(wfs, '2.1.6', '2.1.1', '1.1.0') self.converter.populate_features() for f_type in self.converter.feature_types: item = QListWidgetItem(f_type) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) self.listWidget.addItem(item)
def update_lists(self, only_update_all_list=False): """ Update left list widget and optionally the right one. :param only_update_all_list: Only update left list widget. :type only_update_all_list: bool """ # All parties self.lst_all_parties.clear() if self.txt_search_party.text(): tmp_parties = { i: d for i, d in self.data.items() if self.txt_search_party.text().lower() in d[0].lower() } else: tmp_parties = copy.deepcopy(self.data) # Copy all! for party_id in self.current_selected_parties: if party_id in tmp_parties: del tmp_parties[party_id] for i, d in tmp_parties.items(): item = QListWidgetItem(d[0]) item.setData(Qt.UserRole, i) self.lst_all_parties.addItem(item) if not only_update_all_list: # Selected parties self.tbl_selected_parties.clearContents() self.tbl_selected_parties.setRowCount( len(self.current_selected_parties)) self.tbl_selected_parties.setColumnCount(3) self.tbl_selected_parties.setSortingEnabled(False) for row, party_id in enumerate(self.current_selected_parties): item = QTableWidgetItem(self.data[party_id][0]) item.setFlags(item.flags() & ~Qt.ItemIsEditable) item.setData(Qt.UserRole, party_id) self.tbl_selected_parties.setItem(row, 0, item) value_denominator = self.parties_to_group[party_id][ 0] if party_id in self.parties_to_group else self.data[ party_id][1] self.tbl_selected_parties.setItem( row, 1, QTableWidgetItem(str(value_denominator))) value_numerator = self.parties_to_group[party_id][ 1] if party_id in self.parties_to_group else self.data[ party_id][2] self.tbl_selected_parties.setItem( row, 2, QTableWidgetItem(str(value_numerator))) self.tbl_selected_parties.setSortingEnabled(True)
def __addRastersToGui(self): self.ui.IDC_listRasters.clear() check = Qt.Unchecked if self.settings.mapData.rasters.count() == 1: check = Qt.Checked self.settings.mapData.rasters.rasters()[0].selected = True for raster_lyr in self.settings.mapData.rasters.rasters(): item = QListWidgetItem(raster_lyr.name) item.setData(Qt.UserRole, raster_lyr) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(check) self.ui.IDC_listRasters.addItem(item)
def refreshAnnotations(self): self.annotationList.clearSelection() self.annotationList.clear() for annotation in self.annotationManager.annotations(): item = QListWidgetItem() annotation.appearanceChanged.connect(self.refreshAnnotationTitle) if annotation.isVisible(): item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) item.setFlags(item.flags()) self.annotationList.addItem(item) self.refreshAnnotationTitle(annotation)
def update_import_models(self): for modelname, checked in DEFAULT_MODEL_NAMES_CHECKED.items(): item = QListWidgetItem(modelname) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked if modelname in self.selected_models or checked == Qt.Checked else Qt.Unchecked) # From parameter or by default self.import_models_list_widget.addItem(item) self.import_models_list_widget.itemClicked.connect( self.on_item_clicked_import_model) self.import_models_list_widget.itemChanged.connect( self.on_itemchanged_import_model)
def __addRastersToGui(self): self.ui.IDC_listRasters.clear() check = Qt.Unchecked if self.settings.mapData.rasters.count() == 1: check = Qt.Checked self.settings.mapData.rasters.rasters()[0].selected = True for raster_lyr in self.settings.mapData.rasters.rasters(): item = QListWidgetItem(raster_lyr.name) item.setData(Qt.UserRole, raster_lyr) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(check) self.ui.IDC_listRasters.addItem(item)
def add_new_item(self, projectid, project, is_new=False, is_valid=True): item = QListWidgetItem(self.moduleList, QListWidgetItem.UserType) item.setData(QListWidgetItem.UserType, project) item.setSizeHint(QSize(150, 150)) if not is_valid: item.setFlags(item.flags() & ~Qt.ItemIsEnabled) projectwidget = ProjectWidget(self.moduleList, project, is_new=is_new) projectwidget.install_project.connect(self.projectInstall.emit) projectwidget.update_project.connect(self.projectUpdate.emit) projectwidget.setEnabled(is_valid) projectwidget.serverinfo = project self.moduleList.addItem(item) self.moduleList.setItemWidget(item, projectwidget) self.projectitems[projectid] = item
def update_import_models(self): for model in self.__ladmcol_models.supported_models(): if not model.hidden(): item = QListWidgetItem(model.full_alias()) item.setData(Qt.UserRole, model.full_name()) item.setFlags(item.flags() | Qt.ItemIsUserCheckable) if self.selected_models: # From parameters item.setCheckState(Qt.Checked if model.id() in self.selected_models else Qt.Unchecked) else: # By default item.setCheckState( Qt.Checked if model.checked() else Qt.Unchecked) self.import_models_list_widget.addItem(item) self.import_models_list_widget.itemClicked.connect( self.on_item_clicked_import_model) self.import_models_list_widget.itemChanged.connect( self.on_itemchanged_import_model)
def add_wfs2_service(self, text): item = QListWidgetItem(text) item.setFlags(item.flags() | Qt.ItemIsEditable | Qt.ItemIsUserCheckable) self.wfs2ServicesList.addItem(item) return item
def startUI(self): if self.first_start == True: # Connect to the export button to do the real work self.dlg.exportButton = self.dlg.buttonBox.button( QDialogButtonBox.Ok) self.dlg.exportButton.disconnect() self.dlg.exportButton.setText(self.tr(u'Export')) self.dlg.exportButton.clicked.connect(self.doIt) else: # clear the 3 lists self.dlg.checkAll.setChecked(False) self.dlg.listLayer.clear() self.dlg.listLayout.clear() self.dlg.supportedFormatsBox.clear() self.dlg.checkAll.clicked.connect(self.checkAll) self.dlg.browse.setStorageMode(QgsFileWidget.StorageMode.GetDirectory) #init the list of layers #old method who doesn't keep the order #lay = QgsProject.instance().mapLayers() #layers = list(lay.values()) layers = QgsProject.instance().layerTreeRoot().layerOrder() self.listLayersId = [] #a initialiser correctement for layer in layers: #init the list of layersID self.listLayersId.append(layer.id()) #create the list of layers in UI, and add a checkbox item = QListWidgetItem() item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) item.setText(layer.name()) self.dlg.listLayer.addItem(item) item2 = QListWidgetItem() item2.setFlags(item2.flags() | Qt.ItemIsEditable) item2.setFlags(item2.flags() ^ QtCore.Qt.ItemIsUserCheckable) #if self.first_start == True: item2.setText('Double click to set/change the title') item2.setForeground(QBrush(QtCore.Qt.darkGray)) self.dlg.listLayer.addItem(item2) item2.setHidden(True) self.dlg.listLayer.clicked.connect(self.layerCheckedEvent) # init the list of layouts and insert them in UI layouts = QgsProject.instance().layoutManager().printLayouts() layoutsName = [] for layout in layouts: layoutsName.append(layout.name()) self.dlg.listLayout.addItems(layoutsName) #init the list of supported formats self.dlg.supportedFormatsBox.addItems(self.getSupportedFormats()) #set a the default directory on PDF. Put a signal to open browser in last saved PDF, SVG ou image self.defaultDirectory = QSettings().value('/UI/lastSaveAsPdfFile') self.defaultDirectory = self.dlg.supportedFormatsBox.currentIndexChanged.connect( self.selectDefaultDirectory) self.first_start = False
def add_topic(): item = QListWidgetItem("New topic") item.setFlags(item.flags() | Qt.ItemIsEditable) dialog.topicsList.addItem(item) dialog.topicsList.editItem(item) dialog.topicsList.setCurrentRow(dialog.topicsList.count() - 1)