Skip to content

Commit

Permalink
Add Qt6 support in the source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Nov 22, 2024
1 parent 988445f commit 18e3488
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
54 changes: 27 additions & 27 deletions dynamic_layers/dynamic_layers_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,7 +37,6 @@
QTableWidgetItem,
QTextEdit,
QWidget,
qApp,
)
from qgis.utils import OverrideCursor

Expand Down Expand Up @@ -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')))
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand All @@ -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]):
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -962,6 +962,6 @@ def update_log(self, msg: str):
suffix = '</span>'
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()
18 changes: 9 additions & 9 deletions dynamic_layers/generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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())
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions dynamic_layers/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18e3488

Please sign in to comment.