From cb3ec3cb0c6ba965cc2ebfc774e661727f5ee372 Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Wed, 30 Oct 2024 16:24:11 +0100 Subject: [PATCH] Enable Qt6 on the plugin --- QuickOSM/core/actions.py | 12 ++++---- QuickOSM/core/api/downloader.py | 2 +- QuickOSM/core/process.py | 6 ++-- QuickOSM/core/utilities/extent_tool.py | 4 +-- QuickOSM/metadata.txt | 1 + QuickOSM/quick_osm.py | 10 +++---- .../advanced/decorate_output.py | 6 ++-- QuickOSM/test/test_osm_parser.py | 4 +-- QuickOSM/test/test_saved_query.py | 10 +++---- QuickOSM/ui/base_overpass_panel.py | 2 +- QuickOSM/ui/custom_table.py | 12 ++++---- QuickOSM/ui/dialog.py | 2 +- QuickOSM/ui/edit_preset.py | 14 +++++----- QuickOSM/ui/map_preset_panel.py | 20 ++++++------- QuickOSM/ui/query_panel.py | 2 +- QuickOSM/ui/quick_query_panel.py | 10 +++---- QuickOSM/ui/xml_highlighter.py | 28 +++++++++---------- 17 files changed, 73 insertions(+), 72 deletions(-) diff --git a/QuickOSM/core/actions.py b/QuickOSM/core/actions.py index c31e71a2..6383ccb3 100644 --- a/QuickOSM/core/actions.py +++ b/QuickOSM/core/actions.py @@ -42,7 +42,7 @@ def add_actions(layer: QgsVectorLayer, keys: list): title = tr('OpenStreetMap Browser') osm_browser = QgsAction( - QgsAction.OpenUrl, + QgsAction.ActionType.OpenUrl, title, 'http://www.openstreetmap.org/browse/[% "osm_type" %]/[% "osm_id" %]', '', @@ -55,7 +55,7 @@ def add_actions(layer: QgsVectorLayer, keys: list): title = 'JOSM' josm = QgsAction( - QgsAction.GenericPython, + QgsAction.ActionType.GenericPython, title, ACTIONS_PATH + 'Actions.run("josm","[% "full_id" %]")', resources_path('icons', 'josm_icon.svg'), @@ -68,7 +68,7 @@ def add_actions(layer: QgsVectorLayer, keys: list): title = tr('User default editor') default_editor = QgsAction( - QgsAction.OpenUrl, + QgsAction.ActionType.OpenUrl, title, 'http://www.openstreetmap.org/edit?[% "osm_type" %]=[% "osm_id" %]', '', @@ -95,7 +95,7 @@ def add_actions(layer: QgsVectorLayer, keys: list): link = link.replace(":", "_") generic = QgsAction( - QgsAction.GenericPython, + QgsAction.ActionType.GenericPython, link, (ACTIONS_PATH + f'Actions.run("{link}","[% "{link}" %]")'), @@ -109,7 +109,7 @@ def add_actions(layer: QgsVectorLayer, keys: list): if 'network' in keys and 'ref' in keys: sketch_line = QgsAction( - QgsAction.GenericPython, + QgsAction.ActionType.GenericPython, tr('Sketchline'), ( ACTIONS_PATH + @@ -130,7 +130,7 @@ def add_relaunch_action(layer: QgsVectorLayer, layer_name: str = ""): title = tr('Reload the query in a new file') reload = QgsAction( - QgsAction.GenericPython, + QgsAction.ActionType.GenericPython, title, ACTIONS_PATH + f'Actions.run_reload(layer_name="{layer_name}")', '', diff --git a/QuickOSM/core/api/downloader.py b/QuickOSM/core/api/downloader.py index b51afd51..cfe8eef8 100644 --- a/QuickOSM/core/api/downloader.py +++ b/QuickOSM/core/api/downloader.py @@ -74,4 +74,4 @@ def download(self, get=False): downloader.downloadCanceled.connect(self.canceled) downloader.downloadCompleted.connect(self.completed) downloader.startDownload() - loop.exec_() + loop.exec() diff --git a/QuickOSM/core/process.py b/QuickOSM/core/process.py index 21b18753..695f327d 100644 --- a/QuickOSM/core/process.py +++ b/QuickOSM/core/process.py @@ -143,11 +143,11 @@ def open_file( if str(value) == 'None': value = '' if layer in ['lines', 'multilinestrings']: - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.LineGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.LineGeometry) elif layer == "points": - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.PointGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.PointGeometry) elif layer == "multipolygons": - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.PolygonGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.PolygonGeometry) symbol.setColor(QColor(value)) category = QgsRendererCategory(str(value), symbol, str(value)) categories.append(category) diff --git a/QuickOSM/core/utilities/extent_tool.py b/QuickOSM/core/utilities/extent_tool.py index 6674835f..582249c9 100644 --- a/QuickOSM/core/utilities/extent_tool.py +++ b/QuickOSM/core/utilities/extent_tool.py @@ -30,7 +30,7 @@ def __init__(self, canvas): QgsMapTool.__init__(self, canvas) self.canvas = canvas - self.rubberBand = QgsRubberBand(self.canvas, QgsWkbTypes.PolygonGeometry) + self.rubberBand = QgsRubberBand(self.canvas, QgsWkbTypes.GeometryType.PolygonGeometry) color = QColor(30, 230, 30, 65) self.rubberBand.setColor(color) self.rubberBand.setWidth(1) @@ -49,7 +49,7 @@ def show_extent(self, extent: QgsRectangle): self.end_point = QgsPointXY(extent.xMaximum(), extent.yMaximum()) self.transform_coordinates() - self.rubberBand.reset(QgsWkbTypes.PolygonGeometry) + self.rubberBand.reset(QgsWkbTypes.GeometryType.PolygonGeometry) point1 = QgsPointXY(self.start_point.x(), self.start_point.y()) point2 = QgsPointXY(self.start_point.x(), self.end_point.y()) diff --git a/QuickOSM/metadata.txt b/QuickOSM/metadata.txt index 57fa0134..f2e47416 100644 --- a/QuickOSM/metadata.txt +++ b/QuickOSM/metadata.txt @@ -8,6 +8,7 @@ author=Etienne Trimaille email=etienne@trimaille.eu hasProcessingProvider=yes server=False +supportsQt6=True # End of mandatory metadata diff --git a/QuickOSM/quick_osm.py b/QuickOSM/quick_osm.py index 016e2b69..9b500100 100644 --- a/QuickOSM/quick_osm.py +++ b/QuickOSM/quick_osm.py @@ -238,14 +238,14 @@ def open_dialog(self): # https://github.com/3liz/QuickOSM/issues/422 flag, title, error = check_processing_enable() if not flag: - error_dialog = QMessageBox(QMessageBox.Critical, title, error, QMessageBox.Ok, self) + error_dialog = QMessageBox(QMessageBox.Icon.Critical, title, error, QMessageBox.StandardButton.Ok, self) error_dialog.exec() return from QuickOSM.ui.dialog import Dialog dialog = Dialog() self.open_copyright_message(dialog) - dialog.exec_() + dialog.exec() @staticmethod def open_copyright_message(dialog: QDialog): @@ -274,11 +274,11 @@ def know_copyright(): 'You should read https://www.openstreetmap.org/copyright' ) message.setText(text) - message.setIcon(QMessageBox.Question) + message.setIcon(QMessageBox.Icon.Question) no_button = QPushButton(tr('I understand the copyrights, access to the plugin'), message) yes_button = QPushButton(tr('I want to read the copyrights'), message) - message.addButton(no_button, QMessageBox.NoRole) - message.addButton(yes_button, QMessageBox.YesRole) + message.addButton(no_button, QMessageBox.ButtonRole.NoRole) + message.addButton(yes_button, QMessageBox.ButtonRole.YesRole) yes_button.clicked.connect(read_copyright) no_button.clicked.connect(know_copyright) message.exec() diff --git a/QuickOSM/quick_osm_processing/advanced/decorate_output.py b/QuickOSM/quick_osm_processing/advanced/decorate_output.py index f1b89400..4dd60bcb 100644 --- a/QuickOSM/quick_osm_processing/advanced/decorate_output.py +++ b/QuickOSM/quick_osm_processing/advanced/decorate_output.py @@ -135,11 +135,11 @@ def postProcessLayer(self, layer, context, feedback): if str(value) == 'None': value = '' if layer_type in [self.layer_type_dict['lines'], self.layer_type_dict['multilinestrings']]: - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.LineGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.LineGeometry) elif layer_type == self.layer_type_dict['point']: - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.PointGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.PointGeometry) elif layer_type == self.layer_type_dict['multipolygons']: - symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.PolygonGeometry) + symbol = QgsSymbol.defaultSymbol(QgsWkbTypes.GeometryType.PolygonGeometry) else: break symbol.setColor(QColor(value)) diff --git a/QuickOSM/test/test_osm_parser.py b/QuickOSM/test/test_osm_parser.py index f84d94ad..f2949669 100644 --- a/QuickOSM/test/test_osm_parser.py +++ b/QuickOSM/test/test_osm_parser.py @@ -50,7 +50,7 @@ def test_parser(self): 'barrier' ] features_expected = 52 - geom_type_expected = QgsWkbTypes.Point + geom_type_expected = QgsWkbTypes.Type.Point self.assertEqual(layers['points']['tags'], tags_expected) self.assertEqual(layers['points']['featureCount'], features_expected) @@ -76,7 +76,7 @@ def test_subset_parser(self): 'shelter', 'covered', 'public_transport', 'name', 'bus' ] features_expected = 3 - geom_type_expected = QgsWkbTypes.Point + geom_type_expected = QgsWkbTypes.Type.Point self.assertEqual(layers['points']['tags'], tags_expected) self.assertEqual(layers['points']['featureCount'], features_expected) diff --git a/QuickOSM/test/test_saved_query.py b/QuickOSM/test/test_saved_query.py index 472df647..630ca4da 100644 --- a/QuickOSM/test/test_saved_query.py +++ b/QuickOSM/test/test_saved_query.py @@ -142,7 +142,7 @@ def test_view_bookmark(self): self.assertEqual(nb_queries, 1) edit_dialog.preset_name.setText('Test a new name') - edit_dialog.button_box.button(QDialogButtonBox.Cancel).click() + edit_dialog.button_box.button(QDialogButtonBox.StandardButton.Cancel).click() self.dialog.external_panels[Panels.MapPreset].update_personal_preset_view() @@ -157,7 +157,7 @@ def test_edit_rename_bookmark(self): edit_dialog = EditPreset(self.dialog, data_preset) edit_dialog.preset_name.setText('Test a new name') - edit_dialog.button_box.button(QDialogButtonBox.Ok).click() + edit_dialog.button_box.button(QDialogButtonBox.StandardButton.Ok).click() self.dialog.external_panels[Panels.MapPreset].update_personal_preset_view() @@ -183,7 +183,7 @@ def test_edited_bookmark_file(self): index = edit_dialog.combo_output_format.findData(Format.Kml) edit_dialog.combo_output_format.setCurrentIndex(index) - edit_dialog.button_box.button(QDialogButtonBox.Ok).click() + edit_dialog.button_box.button(QDialogButtonBox.StandardButton.Ok).click() self.preset = self.dialog.list_personal_preset_mp.item(0) new_data = self.set_up_preset_data_text() @@ -259,7 +259,7 @@ def test_bookmark_several_query(self): index = edit_dialog.table_keys_values_eb.cellWidget(0, 2).findText('route') edit_dialog.table_keys_values_eb.cellWidget(0, 2).setCurrentIndex(index) - edit_dialog.button_box.button(QDialogButtonBox.Ok).click() + edit_dialog.button_box.button(QDialogButtonBox.StandardButton.Ok).click() self.preset = self.dialog.list_personal_preset_mp.item(0) new_data = self.set_up_preset_data_text() @@ -334,7 +334,7 @@ def test_bookmark_several_query(self): self.assertEqual( edit_dialog.stacked_parameters_preset.currentWidget(), edit_dialog.advanced_parameters) - edit_dialog.button_box.button(QDialogButtonBox.Ok).click() + edit_dialog.button_box.button(QDialogButtonBox.StandardButton.Ok).click() self.preset = self.dialog.list_personal_preset_mp.item(0) new_data = self.set_up_preset_data_text() diff --git a/QuickOSM/ui/base_overpass_panel.py b/QuickOSM/ui/base_overpass_panel.py index 25ce873d..fff25af0 100644 --- a/QuickOSM/ui/base_overpass_panel.py +++ b/QuickOSM/ui/base_overpass_panel.py @@ -86,7 +86,7 @@ def init_nominatim_autofill(self): for line_edit in self.dialog.places_edits.values(): line_edit.setCompleter(nominatim_completer) line_edit.completer().setCompletionMode( - QCompleter.PopupCompletion) + QCompleter.CompletionMode.PopupCompletion) @staticmethod def sort_nominatim_places(existing_places: list, place: str) -> list: diff --git a/QuickOSM/ui/custom_table.py b/QuickOSM/ui/custom_table.py index c568ddd1..81dc1019 100644 --- a/QuickOSM/ui/custom_table.py +++ b/QuickOSM/ui/custom_table.py @@ -87,7 +87,7 @@ def setup_preset(self): self.preset_items.append(widget_item) self.preset.setCompleter(keys_preset_completer) self.preset.completer().setCompletionMode( - QCompleter.PopupCompletion) + QCompleter.CompletionMode.PopupCompletion) self.preset.completer().setFilterMode( Qt.MatchContains ) @@ -107,10 +107,10 @@ def setup_table(self): # Table Keys/Values header = self.table.horizontalHeader() - header.setSectionResizeMode(QHeaderView.Stretch) - header.setSectionResizeMode(0, QHeaderView.Fixed) - header.setSectionResizeMode(3, QHeaderView.ResizeToContents) - header.setSectionResizeMode(4, QHeaderView.ResizeToContents) + header.setSectionResizeMode(QHeaderView.ResizeMode.Stretch) + header.setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed) + header.setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents) + header.setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents) header.setMinimumSectionSize(25) index_type = header.logicalIndexAt(0) header.resizeSection(index_type, 50) @@ -166,7 +166,7 @@ def prepare_key_field(self) -> QComboBox: key_field.addItems(self.keys) key_field.setCompleter(keys_completer) key_field.completer().setCompletionMode( - QCompleter.PopupCompletion) + QCompleter.CompletionMode.PopupCompletion) key_field.completer().setCaseSensitivity( Qt.CaseInsensitive ) diff --git a/QuickOSM/ui/dialog.py b/QuickOSM/ui/dialog.py index 5d316431..814c6bd6 100644 --- a/QuickOSM/ui/dialog.py +++ b/QuickOSM/ui/dialog.py @@ -174,7 +174,7 @@ def __init__(self, iface=None, parent=None): reloader = partial(actions.pre_run_reload) self.reload_action.triggered.connect(reloader) self.iface.addCustomActionForLayerType( - self.reload_action, "", QgsMapLayer.VectorLayer, False) + self.reload_action, "", QgsMapLayer.LayerType.VectorLayer, False) self.feedback_process = QgsFeedback() diff --git a/QuickOSM/ui/edit_preset.py b/QuickOSM/ui/edit_preset.py index cec79c97..43fd43da 100644 --- a/QuickOSM/ui/edit_preset.py +++ b/QuickOSM/ui/edit_preset.py @@ -113,9 +113,9 @@ def __init__(self, parent=None, data_preset: dict = None): self.tab_widget.setTabIcon(2, QIcon(":images/themes/default/propertyicons/symbology.svg")) # Buttonbox - self.button_box.button(QDialogButtonBox.Cancel).clicked.connect(self.close) - self.button_box.button(QDialogButtonBox.Ok).clicked.connect(self.validate) - self.button_box.button(QDialogButtonBox.Help).clicked.connect(self.open_help) + self.button_box.button(QDialogButtonBox.StandardButton.Cancel).clicked.connect(self.close) + self.button_box.button(QDialogButtonBox.StandardButton.Ok).clicked.connect(self.validate) + self.button_box.button(QDialogButtonBox.StandardButton.Help).clicked.connect(self.open_help) def item_context(self, pos: QPoint): """Set context submenu to delete item in the list.""" @@ -123,7 +123,7 @@ def item_context(self, pos: QPoint): submenu = QMenu() rename_action = submenu.addAction(tr('Rename')) delete_action = submenu.addAction(tr('Delete')) - right_click_item = submenu.exec_(item) + right_click_item = submenu.exec(item) if right_click_item and right_click_item == delete_action: index = self.list_queries.indexAt(pos).row() self.verification_delete_query(index) @@ -285,13 +285,13 @@ def verification_delete_query(self, row: int): """Delete a query in the preset""" name = self.list_queries.item(row).text() validate_delete = QMessageBox( - QMessageBox.Warning, tr('Confirm query deletion'), + QMessageBox.Icon.Warning, tr('Confirm query deletion'), tr(f'Are you sure you want to delete the query \'{name}\'?'), - QMessageBox.Yes | QMessageBox.Cancel, self + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel, self ) ok = validate_delete.exec() - if ok == QMessageBox.Yes: + if ok == QMessageBox.StandardButton.Yes: self.delete_query(row) def delete_query(self, row: int): diff --git a/QuickOSM/ui/map_preset_panel.py b/QuickOSM/ui/map_preset_panel.py index 0fa36eaa..8cd865f0 100644 --- a/QuickOSM/ui/map_preset_panel.py +++ b/QuickOSM/ui/map_preset_panel.py @@ -94,9 +94,9 @@ def setup_default_preset(self): self.dialog.list_default_mp.addItem(item) widget = QFrame() - widget.setFrameStyle(QFrame.StyledPanel) + widget.setFrameStyle(QFrame.Shape.StyledPanel) widget.setStyleSheet('QFrame { margin: 3px; };') - widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + widget.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() picture = QLabel() @@ -109,7 +109,7 @@ def setup_default_preset(self): 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.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed) title.setStyleSheet('font: bold 20px; margin-bottom: 25px;') vbox.addWidget(title) for label in data['description']: @@ -177,8 +177,8 @@ def update_personal_preset_view(self): preset = QFrame() preset.setObjectName('FramePreset') - preset.setFrameStyle(QFrame.StyledPanel) - preset.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + preset.setFrameStyle(QFrame.Shape.StyledPanel) + preset.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() label_name = QLabel(name) @@ -196,8 +196,8 @@ def update_personal_preset_view(self): 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.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + button_remove.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) button_edit.setToolTip(tr('Edit the preset')) button_remove.setToolTip(tr('Delete the preset')) hbox.addWidget(button_edit) @@ -236,13 +236,13 @@ def edit_preset(self, data: dict): def verification_remove_preset(self, item: QListWidgetItem, name: str): """Verification of the removal a preset.""" validate_delete = QMessageBox( - QMessageBox.Warning, tr('Confirm preset deletion'), + QMessageBox.Icon.Warning, tr('Confirm preset deletion'), tr(f'Are you sure you want to delete the preset \'{name}\'?'), - QMessageBox.Yes | QMessageBox.Cancel, self.dialog + QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.Cancel, self.dialog ) ok = validate_delete.exec() - if ok == QMessageBox.Yes: + if ok == QMessageBox.StandardButton.Yes: self.remove_preset(item, name) def remove_preset(self, item: QListWidgetItem, name: str): diff --git a/QuickOSM/ui/query_panel.py b/QuickOSM/ui/query_panel.py index f563f3d8..ab493e98 100644 --- a/QuickOSM/ui/query_panel.py +++ b/QuickOSM/ui/query_panel.py @@ -97,7 +97,7 @@ def setup_panel(self): self.dialog.run_buttons[self.panel].clicked.connect(self.run) self.dialog.button_generate_query.clicked.connect(self.query_language_check) - self.dialog.button_box_q.button(QDialogButtonBox.Reset).clicked.connect( + self.dialog.button_box_q.button(QDialogButtonBox.StandardButton.Reset).clicked.connect( self.dialog.reset_form) self.allow_nominatim_or_extent() diff --git a/QuickOSM/ui/quick_query_panel.py b/QuickOSM/ui/quick_query_panel.py index 48807789..4f9842da 100644 --- a/QuickOSM/ui/quick_query_panel.py +++ b/QuickOSM/ui/quick_query_panel.py @@ -119,7 +119,7 @@ def setup_panel(self): self.dialog.button_run_query_qq.clicked.connect(self.run) self.dialog.button_map_features.clicked.connect(open_plugin_documentation) - self.dialog.button_box_qq.button(QDialogButtonBox.Reset).clicked.connect( + self.dialog.button_box_qq.button(QDialogButtonBox.StandardButton.Reset).clicked.connect( self.dialog.reset_form) # setup callbacks for friendly-label-update only @@ -308,9 +308,9 @@ def update_history_view(self): self.dialog.list_historic.addItem(item) group = QFrame() - group.setFrameStyle(QFrame.StyledPanel) + group.setFrameStyle(QFrame.Shape.StyledPanel) group.setStyleSheet('QFrame { margin: 3px; }') - group.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + group.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) hbox = QHBoxLayout() vbox = QVBoxLayout() label_name = QLabel(name) @@ -328,8 +328,8 @@ def update_history_view(self): button_save = QPushButton() button_run.setIcon(QIcon(QgsApplication.iconPath("mActionStart.svg"))) button_save.setIcon(QIcon(QgsApplication.iconPath("mActionFileSave.svg"))) - button_run.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - button_save.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + button_run.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) + button_save.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) button_run.setToolTip(tr('Run the query')) button_save.setToolTip(tr('Save this query in a new preset')) hbox.addWidget(button_run) diff --git a/QuickOSM/ui/xml_highlighter.py b/QuickOSM/ui/xml_highlighter.py index 6364ffeb..a653ee9a 100644 --- a/QuickOSM/ui/xml_highlighter.py +++ b/QuickOSM/ui/xml_highlighter.py @@ -1,6 +1,6 @@ """Query Highlighter class.""" -from qgis.PyQt.QtCore import QRegExp, Qt +from qgis.PyQt.QtCore import QRegularExpression, Qt from qgis.PyQt.QtGui import QColor, QFont, QSyntaxHighlighter, QTextCharFormat __copyright__ = 'Copyright 2021, 3Liz' @@ -23,32 +23,32 @@ def __init__(self, parent=None): ] self.highlightingRules = [ - (QRegExp(pattern), keyword_format) + (QRegularExpression(pattern), keyword_format) for pattern in keyword_patterns ] element_format = QTextCharFormat() element_format.setForeground(QColor("#117700")) self.highlightingRules.append( - (QRegExp("\\b[A-Za-z_\\-]+(?=[\\s\\/>:;])"), element_format)) + (QRegularExpression("\\b[A-Za-z_\\-]+(?=[\\s\\/>:;])"), element_format)) nominatim_area_format = QTextCharFormat() nominatim_area_format.setFontItalic(True) - nominatim_area_format.setFontWeight(QFont.Bold) + nominatim_area_format.setFontWeight(QFont.Weight.Bold) nominatim_area_format.setForeground(QColor("#FF7C00")) self.highlightingRules.append( - (QRegExp(r"\{\{[A-Za-z0-9:, ]*\}\}"), nominatim_area_format)) + (QRegularExpression(r"\{\{[A-Za-z0-9:, ]*\}\}"), nominatim_area_format)) attribute_format = QTextCharFormat() attribute_format.setFontItalic(True) attribute_format.setForeground(QColor("#2020D2")) self.highlightingRules.append( - (QRegExp("\\b[A-Za-z0-9_-]+(?=\\=|\\[|\\(|$|\\.)"), attribute_format)) + (QRegularExpression("\\b[A-Za-z0-9_-]+(?=\\=|\\[|\\(|$|\\.)"), attribute_format)) value_format = QTextCharFormat() value_format.setForeground(Qt.red) self.highlightingRules.append( - (QRegExp("(\"[A-Za-z0-9:, _.]*\"|\\:([0-9]+)(?=\\,|\\]))"), value_format)) + (QRegularExpression("(\"[A-Za-z0-9:, _.]*\"|\\:([0-9]+)(?=\\,|\\]))"), value_format)) area_format = QTextCharFormat() area_format.setForeground(QColor("#11CC00")) @@ -58,21 +58,21 @@ def __init__(self, parent=None): ] for pattern in area_pattern: self.highlightingRules.append( - (QRegExp(pattern), area_format)) + (QRegularExpression(pattern), area_format)) single_line_comment_format = QTextCharFormat() single_line_comment_format.setForeground(Qt.gray) self.highlightingRules.append( - (QRegExp("(|//[^\n]*)"), single_line_comment_format)) + (QRegularExpression("(|//[^\n]*)"), single_line_comment_format)) # Multi lines comment - self.oql_start_comment = QRegExp(r"\/\*") - self.oql_end_comment = QRegExp(r'\*\/') + self.oql_start_comment = QRegularExpression(r"\/\*") + self.oql_end_comment = QRegularExpression(r'\*\/') def match_multiline( self, text: str, - start_delimiter: QRegExp, - end_delimiter: QRegExp, + start_delimiter: QRegularExpression, + end_delimiter: QRegularExpression, in_state: int, style: Qt) -> bool: """Do highlight of multi-line strings. ``delimiter`` should be a @@ -117,7 +117,7 @@ def highlightBlock(self, text: str): for pattern, char_format in self.highlightingRules: # Create a regular expression from the retrieved pattern - expression = QRegExp(pattern) + expression = QRegularExpression(pattern) # Check what index that expression occurs at with the ENTIRE text index = expression.indexIn(text)