|
4 | 4 | Logica principale del plugin: classe plugin, map tools, download WFS, |
5 | 5 | tiling, deduplicazione e filtro spaziale. |
6 | 6 |
|
7 | | -Compatibile con QGIS 3 (Qt5) e QGIS 4 (Qt6). |
| 7 | +Compatibile con QGIS 4 (Qt6/PyQt6). |
8 | 8 |
|
9 | 9 | Autore: Salvatore Fiandaca |
10 | 10 | Email: pigrecoinfinito@gmail.com |
|
37 | 37 | QgsFillSymbol, |
38 | 38 | ) |
39 | 39 | from qgis.gui import QgsMapTool, QgsRubberBand |
40 | | -from qgis.PyQt.QtCore import Qt, QVariant, QTimer, QSettings |
| 40 | +from qgis.PyQt.QtCore import Qt, QMetaType, QTimer, QSettings |
41 | 41 | from qgis.PyQt.QtGui import QColor, QIcon, QKeySequence |
42 | 42 | from qgis.PyQt.QtWidgets import ( |
43 | 43 | QAction, |
|
54 | 54 |
|
55 | 55 |
|
56 | 56 | # ============================================================================= |
57 | | -# COMPATIBILITÀ QGIS 3 / QGIS 4 (Qt5 / Qt6) |
| 57 | +# HELPERS QGIS 4 (Qt6/PyQt6) |
58 | 58 | # ============================================================================= |
59 | 59 |
|
60 | | -# Tipo geometria per QgsRubberBand e controlli layer |
61 | | -try: |
62 | | - _GEOM_POLYGON = Qgis.GeometryType.Polygon |
63 | | - _GEOM_LINE = Qgis.GeometryType.Line |
64 | | - _GEOM_POINT = Qgis.GeometryType.Point |
65 | | -except AttributeError: |
66 | | - _GEOM_POLYGON = QgsWkbTypes.PolygonGeometry |
67 | | - _GEOM_LINE = QgsWkbTypes.LineGeometry |
68 | | - _GEOM_POINT = QgsWkbTypes.PointGeometry |
| 60 | +_GEOM_POLYGON = Qgis.GeometryType.Polygon |
| 61 | +_GEOM_LINE = Qgis.GeometryType.Line |
| 62 | +_GEOM_POINT = Qgis.GeometryType.Point |
69 | 63 |
|
70 | 64 |
|
71 | 65 | def _exec_dialog(dialog): |
72 | | - """Esegue un dialog in modo compatibile con Qt5 e Qt6.""" |
73 | | - try: |
74 | | - return dialog.exec() |
75 | | - except AttributeError: |
76 | | - return dialog.exec_() |
| 66 | + return dialog.exec() |
77 | 67 |
|
78 | 68 |
|
79 | 69 | def _wkb_display_string(wkb_type): |
80 | | - """Restituisce il nome del tipo WKB, compatibile QGIS 3/4.""" |
81 | | - try: |
82 | | - return QgsWkbTypes.displayString(wkb_type) |
83 | | - except AttributeError: |
84 | | - return str(wkb_type) |
| 70 | + return QgsWkbTypes.displayString(wkb_type) |
85 | 71 |
|
86 | 72 |
|
87 | 73 | def _is_polygon_layer(layer): |
88 | | - """Verifica se il layer è poligonale (compatibile QGIS 3/4).""" |
89 | | - try: |
90 | | - return layer.geometryType() == Qgis.GeometryType.Polygon |
91 | | - except AttributeError: |
92 | | - return layer.geometryType() == 2 |
| 74 | + return layer.geometryType() == Qgis.GeometryType.Polygon |
93 | 75 |
|
94 | 76 |
|
95 | 77 | def _is_line_layer(layer): |
96 | | - """Verifica se il layer è lineare (compatibile QGIS 3/4).""" |
97 | | - try: |
98 | | - return layer.geometryType() == Qgis.GeometryType.Line |
99 | | - except AttributeError: |
100 | | - return layer.geometryType() == 1 |
| 78 | + return layer.geometryType() == Qgis.GeometryType.Line |
101 | 79 |
|
102 | 80 |
|
103 | 81 | def _is_point_layer(layer): |
104 | | - """Verifica se il layer è puntuale (compatibile QGIS 3/4).""" |
105 | | - try: |
106 | | - return layer.geometryType() == Qgis.GeometryType.Point |
107 | | - except AttributeError: |
108 | | - return layer.geometryType() == 0 |
| 82 | + return layer.geometryType() == Qgis.GeometryType.Point |
109 | 83 |
|
110 | 84 |
|
111 | 85 | def _set_show_feature_count(tree_layer, value): |
112 | | - """Imposta showFeatureCount compatibile con QGIS 3 (Qt5) e QGIS 4 (Qt6).""" |
113 | | - try: |
114 | | - tree_layer.setShowFeatureCount(bool(value)) # QGIS 3.32+ / QGIS 4 (Qt6) |
115 | | - except AttributeError: |
116 | | - # Fallback QGIS < 3.32: usa int (1/0) per compatibilità QVariant Qt6 |
117 | | - tree_layer.setCustomProperty("showFeatureCount", 1 if value else 0) |
| 86 | + # setShowFeatureCount() rimosso in QGIS 4; usa la proprietà sottostante |
| 87 | + tree_layer.setCustomProperty("showFeatureCount", 1 if value else 0) |
118 | 88 |
|
119 | 89 |
|
120 | 90 | def _refresh_feature_counts_deferred(layer_id): |
@@ -182,25 +152,14 @@ def _applica_stile_particelle(layer): |
182 | 152 | layer.setRenderer(renderer) |
183 | 153 |
|
184 | 154 |
|
185 | | -# Qt enum scoped (Qt6) vs flat (Qt5) |
186 | | -try: |
187 | | - _WindowModal = Qt.WindowModality.WindowModal |
188 | | - _DashLine = Qt.PenStyle.DashLine |
189 | | - _DialogAccepted = QDialog.DialogCode.Accepted |
190 | | - _Key_Escape = Qt.Key.Key_Escape |
191 | | - _LeftButton = Qt.MouseButton.LeftButton |
192 | | - _RightButton = Qt.MouseButton.RightButton |
193 | | - _MB_Yes = QMessageBox.StandardButton.Yes |
194 | | - _MB_No = QMessageBox.StandardButton.No |
195 | | -except AttributeError: |
196 | | - _WindowModal = Qt.WindowModal |
197 | | - _DashLine = Qt.DashLine |
198 | | - _DialogAccepted = QDialog.Accepted |
199 | | - _Key_Escape = Qt.Key_Escape |
200 | | - _LeftButton = Qt.LeftButton |
201 | | - _RightButton = Qt.RightButton |
202 | | - _MB_Yes = QMessageBox.Yes |
203 | | - _MB_No = QMessageBox.No |
| 155 | +_WindowModal = Qt.WindowModality.WindowModal |
| 156 | +_DashLine = Qt.PenStyle.DashLine |
| 157 | +_DialogAccepted = QDialog.DialogCode.Accepted |
| 158 | +_Key_Escape = Qt.Key.Key_Escape |
| 159 | +_LeftButton = Qt.MouseButton.LeftButton |
| 160 | +_RightButton = Qt.MouseButton.RightButton |
| 161 | +_MB_Yes = QMessageBox.StandardButton.Yes |
| 162 | +_MB_No = QMessageBox.StandardButton.No |
204 | 163 |
|
205 | 164 |
|
206 | 165 | # ============================================================================= |
@@ -859,13 +818,13 @@ def esegui_download_e_caricamento(min_lat, min_lon, max_lat, max_lon, filter_geo |
859 | 818 |
|
860 | 819 | # Copia campi originali + aggiungi campi segnalazione duplicati |
861 | 820 | original_fields = layer_info["fields"].toList() |
862 | | - original_fields.append(QgsField("geom_duplicata", QVariant.String)) |
863 | | - original_fields.append(QgsField("gruppo_duplicato", QVariant.Int)) |
| 821 | + original_fields.append(QgsField("geom_duplicata", QMetaType.Type.QString)) |
| 822 | + original_fields.append(QgsField("gruppo_duplicato", QMetaType.Type.Int)) |
864 | 823 | if espandi_catastale: |
865 | | - original_fields.append(QgsField("sezione", QVariant.String)) |
866 | | - original_fields.append(QgsField("foglio", QVariant.Int)) |
867 | | - original_fields.append(QgsField("allegato", QVariant.String)) |
868 | | - original_fields.append(QgsField("sviluppo", QVariant.String)) |
| 824 | + original_fields.append(QgsField("sezione", QMetaType.Type.QString)) |
| 825 | + original_fields.append(QgsField("foglio", QMetaType.Type.Int)) |
| 826 | + original_fields.append(QgsField("allegato", QMetaType.Type.QString)) |
| 827 | + original_fields.append(QgsField("sviluppo", QMetaType.Type.QString)) |
869 | 828 | mem_provider.addAttributes(original_fields) |
870 | 829 | mem_layer.updateFields() |
871 | 830 |
|
@@ -2160,10 +2119,7 @@ def show_about(self): |
2160 | 2119 | """Mostra il dialog con le informazioni sul plugin.""" |
2161 | 2120 | about_dlg = AboutDialog(self.iface.mainWindow()) |
2162 | 2121 | # Compatibilità Qt5/Qt6 |
2163 | | - try: |
2164 | | - about_dlg.exec() # Qt6 |
2165 | | - except AttributeError: |
2166 | | - about_dlg.exec_() # Qt5 |
| 2122 | + about_dlg.exec() |
2167 | 2123 |
|
2168 | 2124 | def show_help(self): |
2169 | 2125 | """Apre la pagina di aiuto del plugin su GitHub Pages.""" |
|
0 commit comments