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 createCellWidget(self, qmlDict, attr, count): """ Creates specific widgets for each attribute, which can be a QCombobox, a QLineEdit or a QListWidget. """ if attr in qmlDict: enableIgnoreOption = False #case the type is dict the cell widget must be a combobox if isinstance(qmlDict[attr],dict): comboItem = DsgCustomComboBox() comboItem.addItems(sorted(qmlDict[attr].keys())) self.attributeTableWidget.setCellWidget(count, 1, comboItem) #case the type is tuple the cell widget must be a listwidget if isinstance(qmlDict[attr],tuple): (table, filterKeys) = qmlDict[attr] #getting the value relation dictionary used to make the listwidget valueRelation = self.makeValueRelationDict(table, filterKeys) list = QListWidget() for key in list(valueRelation.keys()): listItem = QListWidgetItem(key) listItem.setCheckState(Qt.Unchecked) list.addItem(listItem) self.attributeTableWidget.setCellWidget(count, 1, list) #this is the normal case, a simple lineedit else: textItem = QLineEdit() self.attributeTableWidget.setCellWidget(count, 1, textItem) enableIgnoreOption = True #insert here aditional parameters self.createAditionalParameters(count, enableIgnoreOption)
def update_widget(self): # 1. Populate suggested structures self.widget.suggestedListWidget.clear() for structure in self._get_suggested_structures(): widget_item = QListWidgetItem(f"Structure {structure.obj_id}/{structure.identifier}") widget_item.setData(Qt.UserRole, structure.obj_id) self.widget.suggestedListWidget.addItem(widget_item) # 2. Populated assigned structures self.widget.assignedWidget.clear() for structure in self._get_assigned_structures(): widget_item = QListWidgetItem(f"Structure {structure.obj_id}/{structure.identifier}") widget_item.setData(Qt.UserRole, structure.obj_id) self.widget.assignedWidget.addItem(widget_item) # 3. Populate child damages self.widget.damagesTreeWidget.clear() for damage in self._get_child_damages(): editor = self.main_dialog.editors.get(damage, None) widget_item = QTreeWidgetItem() widget_item.setData(0, Qt.UserRole, damage.obj_id) if editor: # there may be items that are already in the DB widget_item.setCheckState(0, editor.listitem.checkState(0)) widget_item.setText(1, str(damage.distance)) widget_item.setText( 2, damage.channel_damage_code__REL.value_de if damage.channel_damage_code__REL else "" ) widget_item.setText(3, damage.comments) self.widget.damagesTreeWidget.addTopLevelItem(widget_item) self.widget.damagesTreeWidget.header().setSectionResizeMode(QHeaderView.ResizeToContents)
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 assignCols(self): # Load source and target columns respectively srcCols = self._source_columns() for c in srcCols: srcItem = QListWidgetItem(c, self.lstSrcFields) srcItem.setCheckState(Qt.Unchecked) srcItem.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcFields.addItem(srcItem) # Destination Columns tabIndex = int(self.field("tabIndex")) self.targetTab = self.destCheckedItem.text() targetCols = table_column_names(self.targetTab, False, True) # Remove geometry columns in the target columns list for gc in self.geomcols: colIndex = getIndex(targetCols, gc) if colIndex != -1: targetCols.remove(gc) # Remove 'id' column if there id_idx = getIndex(targetCols, 'id') if id_idx != -1: targetCols.remove('id') self._add_target_table_columns(targetCols)
def loadColumns(self, table): # Load textual and spatial (if available) columns # Get spatial columns first spColumns = table_column_names(table, True, creation_order=True) self.cboSpatialCols_2.clear() self.cboSpatialCols_2.addItems(spColumns) # Textual Columns self.lstSrcCols_2.clear() self.allCols = table_column_names(table, creation_order=True) for sc in spColumns: colIndex = getIndex(self.allCols, sc) if colIndex != -1: self.allCols.remove(sc) for col in self.allCols: if ' ' in col: col = '"{}"'.format(col) tabItem = QListWidgetItem(col, self.lstSrcCols_2) tabItem.setCheckState(Qt.Unchecked) tabItem.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcCols_2.addItem(tabItem) if len(spColumns) > 0: self.cboSpatialCols_2.setEnabled(True)
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 populate_entities_widget(self): """ Add entities in the instance file into a list view widget """ self.lst_widget.clear() entities = self.instance_entities() if len(entities) > 0: for entity in entities: list_widget = QListWidgetItem( current_profile().entity_by_name(entity).short_name, self.lst_widget) list_widget.setCheckState(Qt.Checked)
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 createEditor(self, parent, option, index): """ Creates a custom editor to edit value relation data """ # special combobox for field type if index.column() == self.column: list = QListWidget(parent) for item in self.itemsDict: listItem = QListWidgetItem(item) listItem.setCheckState(Qt.Unchecked) list.addItem(listItem) return list return QItemDelegate.createEditor(self, parent, option, index)
def on_domainListWidget_currentRowChanged(self, idx): curItem = self.domainListWidget.item(idx) self.filterListWidget.clear() if curItem: self.domainName = curItem.data(0) self.domainDict = self.abstractDb.getDomainDictV2('dominios.' + self.domainName) for codeName in list(self.domainDict.keys()): newItem = QListWidgetItem(codeName) newItem.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsTristate | QtCore.Qt.ItemIsUserCheckable) newItem.setCheckState(QtCore.Qt.Unchecked) self.filterListWidget.addItem(newItem)
def loadTables(self, type): # Load textual or spatial tables self.lstDestTables.clear() tables = None if type == "textual": tables = profile_user_tables(self.curr_profile, False, True) elif type == "spatial": tables = profile_spatial_tables(self.curr_profile) if tables is not None: for t in tables: tabItem = QListWidgetItem(t, self.lstDestTables) tabItem.setCheckState(Qt.Unchecked) tabItem.setIcon(GuiUtils.get_icon("table.png")) self.lstDestTables.addItem(tabItem)
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 assignCols(self): # Load source and target columns respectively source_columns = self._source_columns() # Destination Columns self.targetTab = self.selected_destination_table() target_columns = table_column_names(self.targetTab, False, True) # Remove geometry columns and 'id' column in the target columns list target_columns = [c for c in target_columns if c not in self.geom_cols and c != 'id'] # now synchronize the lists, as much as possible # this consists of moving columns with matching names in the source and target lists to the same # placement at the top of the lists, and filtering out lists of remaining unmatched columns matched_source_columns = [] unmatched_source_columns = source_columns[:] matched_target_columns = [] unmatched_target_columns = target_columns[:] for source in source_columns: for target in unmatched_target_columns: if ImportData.names_are_matching(source, target): matched_source_columns.append(source) unmatched_source_columns = [c for c in unmatched_source_columns if c != source] matched_target_columns.append(target) unmatched_target_columns = [c for c in unmatched_target_columns if c != target] break # any matching columns get added to the start of the lists, and unmatched get added # to the end of the list for c in matched_source_columns + unmatched_source_columns: src_item = QListWidgetItem(c, self.lstSrcFields) # automatically check any columns we could match src_item.setCheckState(Qt.Checked if c in matched_source_columns else Qt.Unchecked) src_item.setIcon(GuiUtils.get_icon("column.png")) self.lstSrcFields.addItem(src_item) self._add_target_table_columns(matched_target_columns + unmatched_target_columns)
def load_tables_of_type(self, type: str, initial_selection: Optional[str] = None): """ Load textual or spatial tables If initial_selection is specified then that table will be initially checked """ self.lstDestTables.clear() tables = None if type == "textual": tables = profile_user_tables(self.curr_profile, False, True, include_read_only=False) elif type == "spatial": tables = profile_spatial_tables(self.curr_profile, include_read_only=False) if tables is not None: for table_name, table_label in tables.items(): table_item = QListWidgetItem(table_label, self.lstDestTables) table_item.setData(ImportData.ROLE_TABLE_NAME, table_name) if initial_selection: table_item.setCheckState( Qt.Checked if ImportData.names_are_matching(table_name, initial_selection) else Qt.Unchecked) else: table_item.setCheckState(Qt.Unchecked) table_item.setIcon(GuiUtils.get_icon("table.png")) self.lstDestTables.addItem(table_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