|
10 | 10 | import os |
11 | 11 | import webbrowser |
12 | 12 |
|
| 13 | +from qgis.core import QgsProject, QgsVectorLayer |
13 | 14 | from qgis.PyQt.QtCore import Qt |
14 | 15 | from qgis.PyQt.QtGui import QFont, QPixmap |
15 | 16 | from qgis.PyQt.QtWidgets import ( |
| 17 | + QComboBox, |
16 | 18 | QDialog, |
17 | 19 | QVBoxLayout, |
18 | 20 | QHBoxLayout, |
|
47 | 49 | _SmoothTransformation = Qt.SmoothTransformation |
48 | 50 |
|
49 | 51 |
|
| 52 | +def _is_point_layer(layer): |
| 53 | + """Verifica se il layer è puntuale (compatibile Qt5/Qt6).""" |
| 54 | + try: |
| 55 | + from qgis.core import Qgis |
| 56 | + return layer.geometryType() == Qgis.GeometryType.Point |
| 57 | + except AttributeError: |
| 58 | + return layer.geometryType() == 0 |
| 59 | + |
| 60 | + |
| 61 | +def _is_polygon_layer(layer): |
| 62 | + """Verifica se il layer è poligonale (compatibile Qt5/Qt6).""" |
| 63 | + try: |
| 64 | + from qgis.core import Qgis |
| 65 | + return layer.geometryType() == Qgis.GeometryType.Polygon |
| 66 | + except AttributeError: |
| 67 | + return layer.geometryType() == 2 |
| 68 | + |
| 69 | + |
50 | 70 | def _plugin_version(): |
51 | 71 | """Legge la versione dal file metadata.txt del plugin.""" |
52 | 72 | meta_path = os.path.join(os.path.dirname(__file__), "metadata.txt") |
@@ -190,6 +210,39 @@ def __init__(self, parent=None, default_buffer_m=50, |
190 | 210 | self._default_snap_px = default_snap_px |
191 | 211 | self._init_ui() |
192 | 212 |
|
| 213 | + def showEvent(self, event): |
| 214 | + """Aggiorna le combo dei layer ogni volta che il dialog viene mostrato.""" |
| 215 | + super().showEvent(event) |
| 216 | + self._refresh_layer_combos() |
| 217 | + |
| 218 | + def _refresh_layer_combos(self): |
| 219 | + """Ripopola le combo con i layer correnti del progetto.""" |
| 220 | + # --- Sorgente punti: si azzera sempre a "(clicca sulla mappa)" --- |
| 221 | + self.combo_source_layer.blockSignals(True) |
| 222 | + self.combo_source_layer.clear() |
| 223 | + self.combo_source_layer.addItem("(clicca sulla mappa)", None) |
| 224 | + for layer in QgsProject.instance().mapLayers().values(): |
| 225 | + if isinstance(layer, QgsVectorLayer) and _is_point_layer(layer): |
| 226 | + self.combo_source_layer.addItem(layer.name(), layer.id()) |
| 227 | + # Non ripristinare la selezione: ogni operazione parte da "(clicca sulla mappa)" |
| 228 | + self.combo_source_layer.blockSignals(False) |
| 229 | + |
| 230 | + # --- Layer destinazione append --- |
| 231 | + self.combo_append_layer.blockSignals(True) |
| 232 | + current_append_id = self.combo_append_layer.currentData() |
| 233 | + self.combo_append_layer.clear() |
| 234 | + self.combo_append_layer.addItem("(nuovo layer)", None) |
| 235 | + for layer in QgsProject.instance().mapLayers().values(): |
| 236 | + if isinstance(layer, QgsVectorLayer) and _is_polygon_layer(layer): |
| 237 | + if "Particelle" in layer.name() or "WFS" in layer.name(): |
| 238 | + self.combo_append_layer.addItem(layer.name(), layer.id()) |
| 239 | + # Ripristina selezione precedente se ancora presente |
| 240 | + if current_append_id is not None: |
| 241 | + idx = self.combo_append_layer.findData(current_append_id) |
| 242 | + if idx >= 0: |
| 243 | + self.combo_append_layer.setCurrentIndex(idx) |
| 244 | + self.combo_append_layer.blockSignals(False) |
| 245 | + |
193 | 246 | def _init_ui(self): |
194 | 247 | ver = _plugin_version() |
195 | 248 | titolo = "WFS Catasto - Scelta modalità" |
@@ -450,6 +503,36 @@ def _cell_punti(self, svg_w, svg_h): |
450 | 503 | params_row.addStretch() |
451 | 504 | gl.addLayout(params_row) |
452 | 505 |
|
| 506 | + # Layer sorgente punti |
| 507 | + src_row = QHBoxLayout() |
| 508 | + src_lbl = QLabel("Sorgente:") |
| 509 | + src_lbl.setStyleSheet("font-weight: normal; font-size: 10px;") |
| 510 | + src_row.addWidget(src_lbl) |
| 511 | + self.combo_source_layer = QComboBox() |
| 512 | + self.combo_source_layer.addItem("(clicca sulla mappa)", None) |
| 513 | + self.combo_source_layer.setStyleSheet("font-size: 10px;") |
| 514 | + self.combo_source_layer.setToolTip( |
| 515 | + "Scegli un layer punti dal progetto oppure lascia\n" |
| 516 | + "'(clicca sulla mappa)' per selezionarlo cliccando." |
| 517 | + ) |
| 518 | + src_row.addWidget(self.combo_source_layer, 1) |
| 519 | + gl.addLayout(src_row) |
| 520 | + |
| 521 | + # Layer destinazione (append) |
| 522 | + app_row = QHBoxLayout() |
| 523 | + app_lbl = QLabel("Aggiungi a:") |
| 524 | + app_lbl.setStyleSheet("font-weight: normal; font-size: 10px;") |
| 525 | + app_row.addWidget(app_lbl) |
| 526 | + self.combo_append_layer = QComboBox() |
| 527 | + self.combo_append_layer.addItem("(nuovo layer)", None) |
| 528 | + self.combo_append_layer.setStyleSheet("font-size: 10px;") |
| 529 | + self.combo_append_layer.setToolTip( |
| 530 | + "Scegli un layer Particelle WFS esistente a cui aggiungere\n" |
| 531 | + "le nuove particelle, oppure lascia '(nuovo layer)'." |
| 532 | + ) |
| 533 | + app_row.addWidget(self.combo_append_layer, 1) |
| 534 | + gl.addLayout(app_row) |
| 535 | + |
453 | 536 | gl.addStretch() |
454 | 537 |
|
455 | 538 | btn = QPushButton("Seleziona Punti") |
@@ -515,6 +598,22 @@ def _on_snap_changed(self, value): |
515 | 598 | def _on_punti(self): |
516 | 599 | self.scelta = "punti" |
517 | 600 | self.accept() |
| 601 | + |
| 602 | + @property |
| 603 | + def selected_point_layer(self): |
| 604 | + """Restituisce il layer punti sorgente selezionato, o None se 'clicca sulla mappa'.""" |
| 605 | + layer_id = self.combo_source_layer.currentData() |
| 606 | + if layer_id is None: |
| 607 | + return None |
| 608 | + return QgsProject.instance().mapLayer(layer_id) |
| 609 | + |
| 610 | + @property |
| 611 | + def append_to_wfs_layer(self): |
| 612 | + """Restituisce il layer WFS destinazione selezionato, o None se 'nuovo layer'.""" |
| 613 | + layer_id = self.combo_append_layer.currentData() |
| 614 | + if layer_id is None: |
| 615 | + return None |
| 616 | + return QgsProject.instance().mapLayer(layer_id) |
518 | 617 |
|
519 | 618 | def _on_aiuto(self): |
520 | 619 | """Apre la pagina di aiuto del plugin su GitHub Pages.""" |
|
0 commit comments