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 populate_field_list(self, excluded_fields=None): """Helper to add field of the layer to the list. :param excluded_fields: List of field that want to be excluded. :type excluded_fields: list """ # Populate fields list if excluded_fields is None: excluded_fields = [] self.field_list.clear() for field in self.layer.fields(): # Skip if it's excluded if field.name() in excluded_fields: continue # Skip if it's not number (float, int, etc) if field.type() not in qvariant_numbers: continue field_item = QListWidgetItem(self.field_list) field_item.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field.name()) field_item.setText(field.name()) self.field_list.addItem(field_item)
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_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 populate_classified_values( self, unassigned_values, assigned_values, default_classes): """Populate lstUniqueValues and treeClasses.from the parameters. :param unassigned_values: List of values that haven't been assigned to a class. It will be put in self.lstUniqueValues. :type unassigned_values: list :param assigned_values: Dictionary with class as the key and list of value as the value of the dictionary. It will be put in self.treeClasses. :type assigned_values: dict :param default_classes: Default classes from unit. :type default_classes: list """ # Populate the unique values list self.lstUniqueValues.clear() self.lstUniqueValues.setSelectionMode( QAbstractItemView.ExtendedSelection) for value in unassigned_values: value_as_string = value is not None and str(value) or 'NULL' list_item = QListWidgetItem(self.lstUniqueValues) list_item.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) list_item.setData(Qt.UserRole, value) list_item.setText(value_as_string) self.lstUniqueValues.addItem(list_item) # Populate assigned values tree self.treeClasses.clear() self.treeClasses.invisibleRootItem().setFlags(Qt.ItemIsEnabled) for default_class in default_classes: # Create branch for class tree_branch = QTreeWidgetItem(self.treeClasses) tree_branch.setFlags(Qt.ItemIsDropEnabled | Qt.ItemIsEnabled) tree_branch.setExpanded(True) tree_branch.setFont(0, bold_font) if 'name' in default_class: default_class_name = default_class['name'] else: default_class_name = default_class['key'] tree_branch.setText(0, default_class_name) tree_branch.setData(0, Qt.UserRole, default_class['key']) if 'description' in default_class: tree_branch.setToolTip(0, default_class['description']) # Assign known values for value in assigned_values[default_class['key']]: string_value = value is not None and str(value) or 'NULL' tree_leaf = QTreeWidgetItem(tree_branch) tree_leaf.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) tree_leaf.setData(0, Qt.UserRole, value) tree_leaf.setText(0, string_value)
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 _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 __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 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 __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 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 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 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 setup_default_preset(self): """Setup the display of presets""" preset_folder = resources_path('map_preset') folders = os.listdir(preset_folder) for folder_name in folders: file_path = join(preset_folder, folder_name, folder_name + '.json') with open(file_path, encoding='utf8') as json_file: data = json.load(json_file, object_hook=as_enum) item = QListWidgetItem(self.dialog.list_default_mp) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) self.dialog.list_default_mp.addItem(item) widget = QFrame() widget.setFrameStyle(QFrame.StyledPanel) widget.setStyleSheet('QFrame { margin: 3px; };') widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() picture = QLabel() icon_path = resources_path('map_preset', folder_name, folder_name + '_icon.png') if not os.path.isfile(icon_path): icon_path = resources_path('icons', 'QuickOSM.svg') icon = QPixmap(icon_path) icon.scaled(QSize(150, 250), Qt.KeepAspectRatio) picture.setPixmap(icon) picture.setStyleSheet( 'max-height: 150px; max-width: 250px; margin-right: 50px;') hbox.addWidget(picture) title = QLabel(data['file_name']) title.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) title.setStyleSheet('font: bold 20px; margin-bottom: 25px;') vbox.addWidget(title) for label in data['description']: if not label: label = tr('No description') real_label = QLabel(label) real_label.setWordWrap(True) vbox.addWidget(real_label) hbox.addItem(vbox) widget.setLayout(hbox) item.setSizeHint(widget.minimumSizeHint()) self.dialog.list_default_mp.setItemWidget(item, widget)
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 update_list_widget(self): """Update list widget when radio button is clicked.""" # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id > -1: selected_dict = list( self._parameter.options.values())[radio_button_checked_id] if selected_dict.get('type') == MULTIPLE_DYNAMIC: for field in selected_dict.get('value'): # Update list widget field_item = QListWidgetItem(self.list_widget) field_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field) field_item.setText(field) self.list_widget.addItem(field_item)
def update_list_widget(self): """Update list widget when radio button is clicked.""" # Get selected radio button radio_button_checked_id = self.input_button_group.checkedId() # No radio button checked, then default value = None if radio_button_checked_id > -1: selected_dict = list(self._parameter.options.values())[ radio_button_checked_id] if selected_dict.get('type') == MULTIPLE_DYNAMIC: for field in selected_dict.get('value'): # Update list widget field_item = QListWidgetItem(self.list_widget) field_item.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field) field_item.setText(field) self.list_widget.addItem(field_item)
def populate_field_list(self, excluded_fields=None): """Helper to add field of the layer to the list. :param excluded_fields: List of field that want to be excluded. :type excluded_fields: list """ # Populate fields list if excluded_fields is None: excluded_fields = [] self.field_list.clear() for field in self.layer.fields(): # Skip if it's excluded if field.name() in excluded_fields: continue # Skip if it's not number (float, int, etc) if field.type() not in qvariant_numbers: continue field_item = QListWidgetItem(self.field_list) field_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) field_item.setData(Qt.UserRole, field.name()) field_item.setText(field.name()) self.field_list.addItem(field_item)
def update_personal_preset_view(self): """Update the presets displayed.""" preset_folder = query_preset() files = filter( lambda folder: os.path.isdir(join(preset_folder, folder)), os.listdir(preset_folder)) self.dialog.list_personal_preset_mp.clear() for file in files: file_path = join(preset_folder, file, file + '.json') with open(file_path, encoding='utf8') as json_file: data = json.load(json_file, object_hook=as_enum) name = data['file_name'] item = QListWidgetItem(self.dialog.list_personal_preset_mp) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled) self.dialog.list_personal_preset_mp.addItem(item) preset = QFrame() preset.setObjectName('FramePreset') preset.setFrameStyle(QFrame.StyledPanel) preset.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() label_name = QLabel(name) label_name.setStyleSheet('font-weight: bold;') label_name.setWordWrap(True) vbox.addWidget(label_name) for label in data['description']: if not label: label = tr('No description') real_label = QLabel(label) real_label.setWordWrap(True) vbox.addWidget(real_label) hbox.addItem(vbox) button_edit = QPushButton() button_remove = QPushButton() button_edit.setIcon( QIcon(QgsApplication.iconPath("mActionToggleEditing.svg"))) button_remove.setIcon( QIcon(QgsApplication.iconPath('symbologyRemove.svg'))) button_edit.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_remove.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) button_edit.setToolTip(tr('Edit the preset')) button_remove.setToolTip(tr('Delete the preset')) hbox.addWidget(button_edit) hbox.addWidget(button_remove) if data['advanced']: self.listAdvanced.append(True) preset.setStyleSheet('#FramePreset { margin: 3px;' ' border: 3px solid ' + self.advanced_selected + ';' ' border-width: 1px 1px 1px 4px;}') else: self.listAdvanced.append(False) preset.setStyleSheet('#FramePreset { margin: 3px;' ' border: 3px solid ' + self.basic_selected + ';' ' border-width: 1px 1px 1px 4px;}') preset.setLayout(hbox) # Actions on click remove = partial(self.verification_remove_preset, item, name) button_remove.clicked.connect(remove) edit = partial(self.edit_preset, data) button_edit.clicked.connect(edit) item.setSizeHint(preset.minimumSizeHint()) self.dialog.list_personal_preset_mp.setItemWidget(item, preset) self.listAdvanced.append(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)
def add_wfs2_service(self, text): item = QListWidgetItem(text) item.setFlags(item.flags() | Qt.ItemIsEditable | Qt.ItemIsUserCheckable) self.wfs2ServicesList.addItem(item) return item
def __init__(self, parent=None): """Constructor. :param parent: Optional widget to use as parent :type parent: QWidget :param iface: An instance of QGisInterface :type iface: QGisInterface """ super(ResourceSharingDialog, self).__init__(parent) self.setupUi(self) # Reconfigure UI self.setWindowTitle(f"{__title__} - {__version__}") self.setModal(True) self.button_edit.setEnabled(False) self.button_delete.setEnabled(False) self.button_install.setEnabled(False) self.button_open.setEnabled(False) self.button_uninstall.setEnabled(False) # Set up the "main menu" - QListWidgetItem # All collections icon_all = QIcon() icon_all.addFile(str(resources_path("img", "plugin.svg")), QSize(), QIcon.Normal, QIcon.Off) item_all = QListWidgetItem() item_all.setIcon(icon_all) item_all.setText(self.tr("All collections")) # Installed collections icon_installed = QIcon() icon_installed.addFile( str(resources_path("img", "plugin-installed.svg")), QSize(), QIcon.Normal, QIcon.Off, ) item_installed = QListWidgetItem() item_installed.setIcon(icon_installed) item_installed.setText(self.tr("Installed collections")) item_all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) # Settings / repositories icon_settings = QIcon() icon_settings.addFile(str(resources_path("img", "settings.svg")), QSize(), QIcon.Normal, QIcon.Off) item_settings = QListWidgetItem() item_settings.setIcon(icon_settings) item_settings.setText(self.tr("Settings")) item_all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) # Add the items to the list widget self.menu_list_widget.addItem(item_all) self.menu_list_widget.addItem(item_installed) self.menu_list_widget.addItem(item_settings) # Init the message bar self.message_bar = QgsMessageBar(self) self.message_bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.vlayoutRightColumn.insertWidget(0, self.message_bar) # Progress dialog for long running processes self.progress_dialog = None # Init the repository manager dialog self.repository_manager = RepositoryManager() self.collection_manager = CollectionManager() # Collections list view self.collections_model = QStandardItemModel(0, 1) self.collections_model.sort(0, Qt.AscendingOrder) self.collection_proxy = CustomSortFilterProxyModel(self) self.collection_proxy.setSourceModel(self.collections_model) self.list_view_collections.setModel(self.collection_proxy) # Active selected collection self._sel_coll_id = None # Slots self.button_add.clicked.connect(self.add_repository) self.button_edit.clicked.connect(self.edit_repository) self.button_delete.clicked.connect(self.delete_repository) self.button_reload.clicked.connect(self.reload_repositories) self.button_reload_dir.clicked.connect(self.reload_off_res_directory) self.menu_list_widget.currentRowChanged.connect(self.set_current_tab) self.list_view_collections.selectionModel().currentChanged.connect( self.on_list_view_collections_clicked) self.line_edit_filter.textChanged.connect(self.filter_collections) self.button_install.clicked.connect(self.install_collection) self.button_open.clicked.connect(self.open_collection) self.button_uninstall.clicked.connect(self.uninstall_collection) self.button_box.button(QDialogButtonBox.Help).clicked.connect( self.open_help) # Populate the repositories widget and collections list view self.populate_repositories_widget() self.reload_collections_model()
def populate_classified_values( unassigned_values, assigned_values, default_classes, list_unique_values, tree_mapping_widget): """Populate lstUniqueValues and treeClasses.from the parameters. :param unassigned_values: List of values that haven't been assigned to a class. It will be put in list_unique_values. :type unassigned_values: list :param assigned_values: Dictionary with class as the key and list of value as the value of the dictionary. It will be put in tree_mapping_widget. :type assigned_values: dict :param default_classes: Default classes from unit. :type default_classes: list :param list_unique_values: List Widget for unique values :type list_unique_values: QListWidget :param tree_mapping_widget: Tree Widget for classifying. :type tree_mapping_widget: QTreeWidget """ # Populate the unique values list list_unique_values.clear() list_unique_values.setSelectionMode( QAbstractItemView.ExtendedSelection) for value in unassigned_values: value_as_string = value is not None and str(value) or 'NULL' list_item = QListWidgetItem(list_unique_values) list_item.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) list_item.setData(Qt.UserRole, value) list_item.setText(value_as_string) list_unique_values.addItem(list_item) # Populate assigned values tree tree_mapping_widget.clear() bold_font = QFont() bold_font.setItalic(True) bold_font.setBold(True) bold_font.setWeight(75) tree_mapping_widget.invisibleRootItem().setFlags( Qt.ItemIsEnabled) for default_class in default_classes: # Create branch for class tree_branch = QTreeWidgetItem(tree_mapping_widget) tree_branch.setFlags( Qt.ItemIsDropEnabled | Qt.ItemIsEnabled) tree_branch.setExpanded(True) tree_branch.setFont(0, bold_font) if 'name' in default_class: default_class_name = default_class['name'] else: default_class_name = default_class['key'] tree_branch.setText(0, default_class_name) tree_branch.setData(0, Qt.UserRole, default_class['key']) if 'description' in default_class: tree_branch.setToolTip(0, default_class['description']) # Assign known values for value in assigned_values[default_class['key']]: string_value = value is not None and str(value) or 'NULL' tree_leaf = QTreeWidgetItem(tree_branch) tree_leaf.setFlags( Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsDragEnabled) tree_leaf.setData(0, Qt.UserRole, value) tree_leaf.setText(0, string_value)
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