Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not fully Qt6 compatible #519

Open
nicogodet opened this issue Jan 9, 2025 · 1 comment
Open

Not fully Qt6 compatible #519

nicogodet opened this issue Jan 9, 2025 · 1 comment
Labels
bug An identified bug

Comments

@nicogodet
Copy link

What is the bug?

Missing Qt enums conversion

QuickOSM\ui\map_preset_panel.py", line 93, in setup_default_preset
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)

@nicogodet nicogodet added the bug An identified bug label Jan 9, 2025
@nicogodet
Copy link
Author

Full patch

diff --git a/core/actions.py b/core/actions.py
index 6383ccb..05f0be5 100644
--- a/core/actions.py
+++ b/core/actions.py
@@ -247,7 +247,7 @@ class Actions:
 
         query = QgsExpressionContextUtils.layerScope(layer).variable('quickosm_query')
 
-        with OverrideCursor(Qt.WaitCursor):
+        with OverrideCursor(Qt.CursorShape.WaitCursor):
             process.reload_query(query, layer_name, dialog)
 
     def pre_run_reload(self):
diff --git a/core/utilities/completer_free.py b/core/utilities/completer_free.py
index bcec6ce..626b6e3 100644
--- a/core/utilities/completer_free.py
+++ b/core/utilities/completer_free.py
@@ -29,13 +29,13 @@ class DiactricFreeStringListModel(QStringListModel):
     def __init__(self, *args, **kwargs):
         """Constructor"""
         super().__init__(*args, **kwargs)
-        self.setDiactricFreeRole(Qt.UserRole + 10)
+        self.setDiactricFreeRole(Qt.ItemDataRole.UserRole + 10)
         self._diactric_free_role = None
 
     def data(self, index, role: int) -> str:
         """Handle the diacritic elements"""
         if role == self.diactricFreeRole():
-            value = super().data(index, Qt.DisplayRole)
+            value = super().data(index, Qt.ItemDataRole.DisplayRole)
             return strip_accents(value).lower()
         return super().data(index, role)
 
diff --git a/qgis_plugin_tools/widgets/list_fields_selection.py b/qgis_plugin_tools/widgets/list_fields_selection.py
index ff33f95..f495967 100644
--- a/qgis_plugin_tools/widgets/list_fields_selection.py
+++ b/qgis_plugin_tools/widgets/list_fields_selection.py
@@ -17,8 +17,8 @@ __revision__ = "$Format:%H$"
 class ListFieldsSelection(QListWidget):
     def __init__(self, parent=None):
         super().__init__(parent)
-        self.setSelectionMode(QAbstractItemView.MultiSelection)
-        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
+        self.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
+        self.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
         self.layer = None
 
     def set_layer(self, layer: QgsVectorLayer):
@@ -33,7 +33,7 @@ class ListFieldsSelection(QListWidget):
                 cell.setText(field.name())
             else:
                 cell.setText("{} ({})".format(field.name(), alias))
-            cell.setData(Qt.UserRole, field.name())
+            cell.setData(Qt.ItemDataRole.UserRole, field.name())
             index = layer.fields().indexFromName(field.name())
             if index >= 0:
                 cell.setIcon(self.layer.fields().iconForField(index))
@@ -42,12 +42,12 @@ class ListFieldsSelection(QListWidget):
     def set_selection(self, fields: tuple):
         for i in range(self.count()):
             item = self.item(i)
-            item.setSelected(item.data(Qt.UserRole) in fields)
+            item.setSelected(item.data(Qt.ItemDataRole.UserRole) in fields)
 
     def selection(self) -> list:
         selection = []
         for i in range(self.count()):
             item = self.item(i)
             if item.isSelected():
-                selection.append(item.data(Qt.UserRole))
+                selection.append(item.data(Qt.ItemDataRole.UserRole))
         return selection
diff --git a/qgis_plugin_tools/widgets/list_layers_selection.py b/qgis_plugin_tools/widgets/list_layers_selection.py
index f52fcb0..6184159 100644
--- a/qgis_plugin_tools/widgets/list_layers_selection.py
+++ b/qgis_plugin_tools/widgets/list_layers_selection.py
@@ -17,8 +17,8 @@ __revision__ = "$Format:%H$"
 class ListLayersSelection(QListWidget):
     def __init__(self, parent=None):
         super().__init__(parent)
-        self.setSelectionMode(QAbstractItemView.MultiSelection)
-        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
+        self.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection)
+        self.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
         self.project = None
 
     def set_project(self, project: QgsProject):
@@ -35,19 +35,19 @@ class ListLayersSelection(QListWidget):
 
             cell = QListWidgetItem()
             cell.setText(layer.name())
-            cell.setData(Qt.UserRole, layer.id())
+            cell.setData(Qt.ItemDataRole.UserRole, layer.id())
             cell.setIcon(QgsMapLayerModel.iconForLayer(layer))
             self.addItem(cell)
 
     def set_selection(self, layers: tuple):
         for i in range(self.count()):
             item = self.item(i)
-            item.setSelected(item.data(Qt.UserRole) in layers)
+            item.setSelected(item.data(Qt.ItemDataRole.UserRole) in layers)
 
     def selection(self) -> list:
         selection = []
         for i in range(self.count()):
             item = self.item(i)
             if item.isSelected():
-                selection.append(item.data(Qt.UserRole))
+                selection.append(item.data(Qt.ItemDataRole.UserRole))
         return selection
diff --git a/qgis_plugin_tools/widgets/selectable_combobox.py b/qgis_plugin_tools/widgets/selectable_combobox.py
index 4026a27..cd1d1f5 100644
--- a/qgis_plugin_tools/widgets/selectable_combobox.py
+++ b/qgis_plugin_tools/widgets/selectable_combobox.py
@@ -30,8 +30,8 @@ class CheckableComboBox:
             self.select_all.clicked.connect(self.select_all_clicked)
 
     def select_all_clicked(self):
-        for item in self.model.findItems("*", Qt.MatchWildcard):
-            item.setCheckState(Qt.Checked)
+        for item in self.model.findItems("*", Qt.MatchFlag.MatchWildcard):
+            item.setCheckState(Qt.CheckState.Checked)
 
     def append_row(self, item: QStandardItem):
         """Add an item to the combobox."""
@@ -46,15 +46,15 @@ class CheckableComboBox:
 
     def selected_items(self) -> list:
         checked_items = []
-        for item in self.model.findItems("*", Qt.MatchWildcard):
-            if item.checkState() == Qt.Checked:
+        for item in self.model.findItems("*", Qt.MatchFlag.MatchWildcard):
+            if item.checkState() == Qt.CheckState.Checked:
                 checked_items.append(item.data())
         return checked_items
 
     def set_selected_items(self, items):
-        for item in self.model.findItems("*", Qt.MatchWildcard):
+        for item in self.model.findItems("*", Qt.MatchFlag.MatchWildcard):
             checked = item.data() in items
-            item.setCheckState(Qt.Checked if checked else Qt.Unchecked)
+            item.setCheckState(Qt.CheckState.Checked if checked else Qt.CheckState.Unchecked)
 
     def text_changed(self, text):
         """Update the preview with all selected items, separated by a comma."""
diff --git a/ui/base_processing_panel.py b/ui/base_processing_panel.py
index ae36a2c..9bbaf9b 100644
--- a/ui/base_processing_panel.py
+++ b/ui/base_processing_panel.py
@@ -110,7 +110,7 @@ class BaseProcessingPanel(BasePanel):
 
     def _start_process(self):
         """Make some stuff before launching the process."""
-        QApplication.setOverrideCursor(Qt.WaitCursor)
+        QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
 
         self.dialog.feedback_process = QgsFeedback()
 
diff --git a/ui/custom_table.py b/ui/custom_table.py
index 81dc101..aa60c7f 100644
--- a/ui/custom_table.py
+++ b/ui/custom_table.py
@@ -79,20 +79,20 @@ class TableKeyValue:
                     icon_path = resources_path('icons', "josm", icon_path)
                     if os.path.exists(icon_path):
                         icon = QPixmap(icon_path)
-                        widget_item.setData(Qt.DecorationRole, icon.scaled(20, 20, Qt.KeepAspectRatio))
+                        widget_item.setData(Qt.ItemDataRole.DecorationRole, icon.scaled(20, 20, Qt.AspectRatioMode.KeepAspectRatio))
                         self.preset.setItemData(
-                            k + 1, icon.scaled(20, 20, Qt.KeepAspectRatio),
-                            Qt.DecorationRole
+                            k + 1, icon.scaled(20, 20, Qt.AspectRatioMode.KeepAspectRatio),
+                            Qt.ItemDataRole.DecorationRole
                         )
                 self.preset_items.append(widget_item)
         self.preset.setCompleter(keys_preset_completer)
         self.preset.completer().setCompletionMode(
             QCompleter.CompletionMode.PopupCompletion)
         self.preset.completer().setFilterMode(
-            Qt.MatchContains
+            Qt.MatchFlag.MatchContains
         )
         self.preset.completer().setCaseSensitivity(
-            Qt.CaseInsensitive
+            Qt.CaseSensitivity.CaseInsensitive
         )
 
         self.preset.activated.connect(self.choice_preset)
@@ -168,7 +168,7 @@ class TableKeyValue:
         key_field.completer().setCompletionMode(
             QCompleter.CompletionMode.PopupCompletion)
         key_field.completer().setCaseSensitivity(
-            Qt.CaseInsensitive
+            Qt.CaseSensitivity.CaseInsensitive
         )
 
         key_field.lineEdit().setPlaceholderText(
diff --git a/ui/dialog.py b/ui/dialog.py
index 814c6bd..9a07c1a 100644
--- a/ui/dialog.py
+++ b/ui/dialog.py
@@ -214,7 +214,7 @@ class Dialog(QDialog, FORM_CLASS):
 
     def eventFilter(self, obj: QObject, e: QEvent) -> bool:
         """Set up a custom event to avoid scroll"""
-        return e.type() == QEvent.Wheel
+        return e.type() == QEvent.Type.Wheel
 
     def display_quickosm_exception(self, exception: QuickOsmException):
         """Display QuickOSM exceptions.
diff --git a/ui/edit_preset.py b/ui/edit_preset.py
index 43fd43d..c8dc863 100644
--- a/ui/edit_preset.py
+++ b/ui/edit_preset.py
@@ -64,10 +64,10 @@ class EditPreset(QDialog, FORM_CLASS, TableKeyValue):
         self.button_remove.clicked.connect(self.remove_selection)
 
         self.list_queries.currentRowChanged.connect(self.change_query)
-        self.list_queries.setContextMenuPolicy(Qt.CustomContextMenu)
+        self.list_queries.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
         self.list_queries.customContextMenuRequested.connect(self.item_context)
 
-        self.label_help_qml.setTextInteractionFlags(Qt.TextSelectableByMouse)
+        self.label_help_qml.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
 
         self.bbox = QgsExtentWidget()
         self.bbox.setMapCanvas(parent.iface.mapCanvas())
diff --git a/ui/map_preset_panel.py b/ui/map_preset_panel.py
index 8cd865f..59d1e4e 100644
--- a/ui/map_preset_panel.py
+++ b/ui/map_preset_panel.py
@@ -90,7 +90,7 @@ class MapPresetPanel(BaseOverpassPanel):
                 data = json.load(json_file, object_hook=as_enum)
 
             item = QListWidgetItem(self.dialog.list_default_mp)
-            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
+            item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsUserCheckable | Qt.ItemFlag.ItemIsEnabled)
             self.dialog.list_default_mp.addItem(item)
 
             widget = QFrame()
@@ -104,7 +104,7 @@ class MapPresetPanel(BaseOverpassPanel):
             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)
+            icon.scaled(QSize(150, 250), Qt.AspectRatioMode.KeepAspectRatio)
             picture.setPixmap(icon)
             picture.setStyleSheet('max-height: 150px; max-width: 250px; margin-right: 50px;')
             hbox.addWidget(picture)
@@ -172,7 +172,7 @@ class MapPresetPanel(BaseOverpassPanel):
             name = data['file_name']
 
             item = QListWidgetItem(self.dialog.list_personal_preset_mp)
-            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
+            item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsUserCheckable | Qt.ItemFlag.ItemIsEnabled)
             self.dialog.list_personal_preset_mp.addItem(item)
 
             preset = QFrame()
diff --git a/ui/query_panel.py b/ui/query_panel.py
index ab493e9..f33058e 100644
--- a/ui/query_panel.py
+++ b/ui/query_panel.py
@@ -223,7 +223,7 @@ class QueryPanel(BaseOverpassPanel):
     def query_language_check(self):
         """Check the wanted language."""
 
-        with OverrideCursor(Qt.WaitCursor):
+        with OverrideCursor(Qt.CursorShape.WaitCursor):
             if self.dialog.query_language[Panels.Query] == QueryLanguage.OQL:
                 self.generate_query(oql_output=True)
             elif self.dialog.query_language[Panels.Query] == QueryLanguage.XML:
diff --git a/ui/xml_highlighter.py b/ui/xml_highlighter.py
index a653ee9..06dc8f4 100644
--- a/ui/xml_highlighter.py
+++ b/ui/xml_highlighter.py
@@ -15,7 +15,7 @@ class QueryHighlighter(QSyntaxHighlighter):
         super().__init__(parent)
 
         keyword_format = QTextCharFormat()
-        keyword_format.setForeground(Qt.darkMagenta)
+        keyword_format.setForeground(Qt.GlobalColor.darkMagenta)
 
         keyword_patterns = [
             "\\b?xml\\b", "/>", ">", "<",
@@ -46,7 +46,7 @@ class QueryHighlighter(QSyntaxHighlighter):
             (QRegularExpression("\\b[A-Za-z0-9_-]+(?=\\=|\\[|\\(|$|\\.)"), attribute_format))
 
         value_format = QTextCharFormat()
-        value_format.setForeground(Qt.red)
+        value_format.setForeground(Qt.GlobalColor.red)
         self.highlightingRules.append(
             (QRegularExpression("(\"[A-Za-z0-9:, _.]*\"|\\:([0-9]+)(?=\\,|\\]))"), value_format))
 
@@ -61,7 +61,7 @@ class QueryHighlighter(QSyntaxHighlighter):
                 (QRegularExpression(pattern), area_format))
 
         single_line_comment_format = QTextCharFormat()
-        single_line_comment_format.setForeground(Qt.gray)
+        single_line_comment_format.setForeground(Qt.GlobalColor.gray)
         self.highlightingRules.append(
             (QRegularExpression("(<!--[^\n]*-->|//[^\n]*)"), single_line_comment_format))
 
@@ -140,4 +140,4 @@ class QueryHighlighter(QSyntaxHighlighter):
             self.oql_start_comment,
             self.oql_end_comment,
             1,
-            Qt.gray)
+            Qt.GlobalColor.gray)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An identified bug
Projects
None yet
Development

No branches or pull requests

1 participant