From 18e3488ca8214e52fc0291a9b7571bb545694460 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Fri, 22 Nov 2024 16:52:17 +0100 Subject: [PATCH] Add Qt6 support in the source code --- dynamic_layers/dynamic_layers_dialog.py | 54 ++++++++++++------------- dynamic_layers/generate_projects.py | 18 ++++----- dynamic_layers/metadata.txt | 1 + 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/dynamic_layers/dynamic_layers_dialog.py b/dynamic_layers/dynamic_layers_dialog.py index 0637692..28dc0ff 100644 --- a/dynamic_layers/dynamic_layers_dialog.py +++ b/dynamic_layers/dynamic_layers_dialog.py @@ -27,6 +27,7 @@ from qgis.PyQt import uic from qgis.PyQt.QtGui import QIcon, QTextCursor from qgis.PyQt.QtWidgets import ( + QApplication, QDialog, QDialogButtonBox, QHeaderView, @@ -36,7 +37,6 @@ QTableWidgetItem, QTextEdit, QWidget, - qApp, ) from qgis.utils import OverrideCursor @@ -75,7 +75,7 @@ def __init__(self, parent: QDialog = None): self.project = QgsProject.instance() self.tab_widget.setCurrentIndex(0) self.is_expression = True - self.button_box.button(QDialogButtonBox.Close).clicked.connect(self.close) + self.button_box.button(QDialogButtonBox.StandardButton.Close).clicked.connect(self.close) self.btAddVariable.setText("") self.btAddVariable.setIcon(QIcon(QgsApplication.iconPath('symbologyAdd.svg'))) @@ -92,10 +92,10 @@ def __init__(self, parent: QDialog = None): self.btCopyFromLayer.setIcon(QIcon(QgsApplication.iconPath('mActionEditCopy.svg'))) self.btCopyFromProject.setIcon(QIcon(QgsApplication.iconPath('mActionEditCopy.svg'))) - self.inExtentLayer.setFilters(QgsMapLayerProxyModel.VectorLayer) + self.inExtentLayer.setFilters(QgsMapLayerProxyModel.Filter.VectorLayer) self.inExtentLayer.setAllowEmptyLayer(True) - self.inVariableSourceLayer.setFilters(QgsMapLayerProxyModel.VectorLayer) + self.inVariableSourceLayer.setFilters(QgsMapLayerProxyModel.Filter.VectorLayer) self.inVariableSourceLayer.setAllowEmptyLayer(False) self.selected_layer = None @@ -239,8 +239,8 @@ def __init__(self, parent: QDialog = None): self.btAddVariable.clicked.connect(self.on_add_variable_clicked) self.btRemoveVariable.clicked.connect(self.on_remove_variable_clicked) - self.button_box.button(QDialogButtonBox.Apply).clicked.connect(self.on_apply_variables_clicked) - self.button_box.button(QDialogButtonBox.Help).clicked.connect(open_help) + self.button_box.button(QDialogButtonBox.StandardButton.Apply).clicked.connect(self.on_apply_variables_clicked) + self.button_box.button(QDialogButtonBox.StandardButton.Help).clicked.connect(open_help) # Project properties tab self.btCopyFromProject.clicked.connect(self.on_copy_from_project_clicked) @@ -302,8 +302,8 @@ def populate_layer_table(self): self.twLayers.setColumnCount(col_count) self.twLayers.setHorizontalHeaderLabels(tuple(columns)) header = self.twLayers.horizontalHeader() - header.setSectionResizeMode(QHeaderView.ResizeToContents) - header.setSectionResizeMode(1, QHeaderView.Stretch) + header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) + header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) # load content from project layers for layer in self.project.mapLayers().values(): @@ -449,15 +449,15 @@ def on_copy_from_layer(self): if ask: box = QMessageBox(self) - box.setIcon(QMessageBox.Question) + box.setIcon(QMessageBox.Icon.Question) box.setWindowIcon(QIcon(str(resources_path('icons', 'icon.png')))) box.setWindowTitle(tr('Replace settings by layer properties')) box.setText(tr( 'You have already set some values for this layer, are you sure you want to reset these ?')) - box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) - box.setDefaultButton(QMessageBox.No) - result = box.exec_() - if result == QMessageBox.No: + box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + box.setDefaultButton(QMessageBox.StandardButton.No) + result = box.exec() + if result == QMessageBox.StandardButton.No: return self.dynamicDatasourceContent.setPlainText(uri) @@ -484,8 +484,8 @@ def populate_variable_table(self): self.twVariableList.setColumnCount(2) header = self.twVariableList.horizontalHeader() - header.setSectionResizeMode(QHeaderView.ResizeToContents) - header.setSectionResizeMode(1, QHeaderView.Stretch) + header.setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents) + header.setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch) # Fill the table for i, variable in enumerate(variable_list[0]): @@ -555,16 +555,16 @@ def on_copy_from_project_clicked(self): if ask: box = QMessageBox(self) - box.setIcon(QMessageBox.Question) + box.setIcon(QMessageBox.Icon.Question) # noinspection PyArgumentList box.setWindowIcon(QIcon(str(resources_path('icons', 'icon.png')))) box.setWindowTitle(tr('Replace settings by project properties')) box.setText(tr( 'You have already set some values for this project, are you sure you want to reset these ?')) - box.setStandardButtons(QMessageBox.Yes | QMessageBox.No) - box.setDefaultButton(QMessageBox.No) - result = box.exec_() - if result == QMessageBox.No: + box.setStandardButtons(QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No) + box.setDefaultButton(QMessageBox.StandardButton.No) + result = box.exec() + if result == QMessageBox.StandardButton.No: return if not self.project.readEntry(WmsProjectProperty.Capabilities, "/")[1]: @@ -670,15 +670,15 @@ def on_apply_variables_clicked(self): self.message_bar.pushSuccess("👍", tr("Current project has been updated")) box = QMessageBox(self) - box.setIcon(QMessageBox.Warning) + box.setIcon(QMessageBox.Icon.Warning) box.setWindowIcon(QIcon(str(resources_path('icons', 'icon.png')))) box.setWindowTitle(tr('Reboot your QGIS Desktop')) box.setText(tr( 'To avoid your QGIS to crash, we strongly recommend you to restart your QGIS Desktop. The plugin worked as ' 'expected related the replacement.' )) - box.setStandardButtons(QMessageBox.Ok) - box.exec_() + box.setStandardButtons(QMessageBox.StandardButton.Ok) + box.exec() def origin_variable_toggled(self): """ Radio buttons to choose the origin of variables. """ @@ -723,7 +723,7 @@ def validate_expression(self, source: str): if text_input and (expression.hasEvalError() or expression.hasParserError()): if isinstance(widget, QLineEdit): icon = QIcon(":/images/themes/default/mIconWarning.svg") - widget.addAction(icon, QLineEdit.LeadingPosition) + widget.addAction(icon, QLineEdit.ActionPosition.LeadingPosition) else: widget.setStyleSheet("background-color: #55f3bc3c") else: @@ -771,7 +771,7 @@ def open_expression_builder(self, source: str): dialog.setExpressionText(self.text_widget(widget)) result = dialog.exec() - if result != QDialog.Accepted: + if result != QDialog.DialogCode.Accepted: return content = dialog.expressionText() @@ -962,6 +962,6 @@ def update_log(self, msg: str): suffix = '' self.txtLog.append(f'{prefix} {msg} {suffix}') c = self.txtLog.textCursor() - c.movePosition(QTextCursor.End, QTextCursor.MoveAnchor) + c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.MoveAnchor) self.txtLog.setTextCursor(c) - qApp.processEvents() + QApplication.instance().processEvents() diff --git a/dynamic_layers/generate_projects.py b/dynamic_layers/generate_projects.py index 9845d1e..1331ad2 100644 --- a/dynamic_layers/generate_projects.py +++ b/dynamic_layers/generate_projects.py @@ -44,9 +44,9 @@ def __init__(self, parent: QDialog = None): self.setWindowTitle(tr("Generate many QGIS projects")) self.project = QgsProject.instance() - self.button_box.button(QDialogButtonBox.Apply).clicked.connect(self.generate_projects) - self.button_box.button(QDialogButtonBox.Help).clicked.connect(open_help) - self.button_box.button(QDialogButtonBox.Cancel).clicked.connect(self.close) + self.button_box.button(QDialogButtonBox.StandardButton.Apply).clicked.connect(self.generate_projects) + self.button_box.button(QDialogButtonBox.StandardButton.Help).clicked.connect(open_help) + self.button_box.button(QDialogButtonBox.StandardButton.Cancel).clicked.connect(self.close) self.expression.setText("") self.expression.setToolTip(tr("Open the expression builder")) @@ -62,9 +62,9 @@ def __init__(self, parent: QDialog = None): self.debug_limit.setValue(0) # DEBUG - self.file_name.setText('"schema" || \'/test_\' || "schema" || \'.qgs\'') - self.destination.setFilePath('/tmp/demo_cartophyl') - self.debug_limit.setValue(5) + # self.file_name.setText('"schema" || \'/test_\' || "schema" || \'.qgs\'') + # self.destination.setFilePath('/tmp/demo_cartophyl') + # self.debug_limit.setValue(5) def layer_changed(self): self.field.setLayer(self.coverage.currentLayer()) @@ -83,7 +83,7 @@ def open_expression_builder(self): dialog.setExpressionText(self.file_name.text()) result = dialog.exec() - if result != QDialog.Accepted: + if result != QDialog.DialogCode.Accepted: return content = dialog.expressionText() @@ -100,7 +100,7 @@ def generate_projects(self): if self.project.isDirty(): feedback.reportError(tr("You must save your project first.")) - self.button_box.button(QDialogButtonBox.Apply).setEnabled(False) + self.button_box.button(QDialogButtonBox.StandardButton.Apply).setEnabled(False) result = False with OverrideCursor(QtVar.WaitCursor): self.logs.clear() @@ -129,7 +129,7 @@ def generate_projects(self): # In case of success, the button is not enabled again else: feedback.pushWarning(tr("End, but there was an error")) - self.button_box.button(QDialogButtonBox.Apply).setEnabled(True) + self.button_box.button(QDialogButtonBox.StandardButton.Apply).setEnabled(True) class TextFeedBack(QgsProcessingFeedback): diff --git a/dynamic_layers/metadata.txt b/dynamic_layers/metadata.txt index 29a97ef..913dc7e 100644 --- a/dynamic_layers/metadata.txt +++ b/dynamic_layers/metadata.txt @@ -25,6 +25,7 @@ category=Plugins icon=resources/icons/icon.png # experimental flag experimental=False +supportsQt6=True # deprecated flag (applies to the whole plugin, not just a single version) deprecated=False