-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_map2web_dialog.py
More file actions
601 lines (527 loc) · 25 KB
/
Copy pathuniversal_map2web_dialog.py
File metadata and controls
601 lines (527 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# -*- coding: utf-8 -*-
import json
import os
from qgis.core import QgsMapLayer, QgsProject
from qgis.PyQt import QtGui, uic
from qgis.PyQt.QtCore import QCoreApplication, QSettings, Qt
from qgis.PyQt.QtWidgets import (
QColorDialog,
QDialog,
QFileDialog,
QListWidgetItem,
)
from .qt_compat import qenum
FORM_CLASS, _ = uic.loadUiType(
os.path.join(os.path.dirname(__file__), "universal_map2web_dialog_base.ui")
)
class UniversalMap2webDialog(QDialog, FORM_CLASS):
def __init__(self, parent=None):
super(UniversalMap2webDialog, self).__init__(parent)
self.setupUi(self)
self.popup_config = {}
self.derniere_couche_id = None
# Appliquer les traductions de l'interface immédiatement
self.apply_translations()
if hasattr(self, "btnChoisirLogo"):
self.btnChoisirLogo.clicked.connect(self.selectionner_logo)
if hasattr(self, "btnChoisirCouleur"):
self.btnChoisirCouleur.clicked.connect(self.selectionner_couleur)
if hasattr(self, "btnSelectAll"):
self.btnSelectAll.clicked.connect(self.tout_selectionner)
if hasattr(self, "btnDeselectAll"):
self.btnDeselectAll.clicked.connect(self.tout_deselectionner)
if hasattr(self, "btnInvertSelection"):
self.btnInvertSelection.clicked.connect(self.inverser_selection)
if hasattr(self, "btnMoveUp"):
self.btnMoveUp.clicked.connect(self.monter_couche)
if hasattr(self, "btnMoveDown"):
self.btnMoveDown.clicked.connect(self.descendre_couche)
if hasattr(self, "listCouchesPopup"):
self.listCouchesPopup.currentItemChanged.connect(
self.changement_couche_popup
)
self.charger_couches_qgis()
# Restoration de la configuration enregistrée dans le projet
self.restaurer_configuration_projet()
def tr(self, text):
"""Traduit un texte"""
return QCoreApplication.translate("UniversalMap2web", text)
def apply_translations(self):
"""Applique les traductions à tous les éléments de l'interface"""
print("Application des traductions...")
# --- Onglets ---
if hasattr(self, "tabWidget"):
if self.tabWidget.count() > 0:
self.tabWidget.setTabText(0, self.tr("General"))
if self.tabWidget.count() > 1:
self.tabWidget.setTabText(1, self.tr("Customization"))
if self.tabWidget.count() > 2:
self.tabWidget.setTabText(2, self.tr("Layers"))
if self.tabWidget.count() > 3:
self.tabWidget.setTabText(3, self.tr("Advanced"))
if self.tabWidget.count() > 4:
self.tabWidget.setTabText(4, self.tr("Wiki"))
# --- Onglet Général ---
if hasattr(self, "groupLibrairie"):
self.groupLibrairie.setTitle(self.tr("Web Library"))
if hasattr(self, "groupFondsPlan"):
self.groupFondsPlan.setTitle(self.tr("Basemap"))
if hasattr(self, "groupOutils"):
self.groupOutils.setTitle(self.tr("Tools to integrate"))
# --- CheckBox Outils ---
if hasattr(self, "chkRecherche"):
self.chkRecherche.setText(self.tr("Address search"))
if hasattr(self, "chkGeoloc"):
self.chkGeoloc.setText(self.tr("GPS location"))
if hasattr(self, "chkMesure"):
self.chkMesure.setText(self.tr("Measure (distance/area)"))
if hasattr(self, "chkImprimer"):
self.chkImprimer.setText(self.tr("Print button"))
if hasattr(self, "chkPleinEcran"):
self.chkPleinEcran.setText(self.tr("Full screen mode"))
if hasattr(self, "chkMiniMap"):
self.chkMiniMap.setText(self.tr("Overview map (MiniMap)"))
if hasattr(self, "chkScale"):
self.chkScale.setText(self.tr("Scale bar"))
if hasattr(self, "chkMousePosition"):
self.chkMousePosition.setText(self.tr("Cursor position"))
if hasattr(self, "chkAttribution"):
self.chkAttribution.setText(self.tr("Attribution"))
if hasattr(self, "chkFiltreAvance"):
self.chkFiltreAvance.setText(self.tr("Advanced filter"))
# --- Onglet Personnalisation ---
if hasattr(self, "groupTitre"):
self.groupTitre.setTitle(self.tr("Map title"))
if hasattr(self, "groupLogo"):
self.groupLogo.setTitle(self.tr("Logo"))
if hasattr(self, "groupCouleur"):
self.groupCouleur.setTitle(self.tr("Header color"))
if hasattr(self, "groupThemeVisuel"):
self.groupThemeVisuel.setTitle(self.tr("Interface theme"))
if hasattr(self, "btnChoisirLogo"):
self.btnChoisirLogo.setText(self.tr("Choose a logo"))
if hasattr(self, "lblLogoPath"):
self.lblLogoPath.setText(self.tr("No logo"))
if hasattr(self, "chkAfficherLogo"):
self.chkAfficherLogo.setText(self.tr("Show logo"))
if hasattr(self, "btnChoisirCouleur"):
self.btnChoisirCouleur.setText(self.tr("Choose a color"))
# --- Thèmes ---
if hasattr(self, "comboTheme"):
self.comboTheme.setItemText(0, self.tr("Light"))
self.comboTheme.setItemData(0, "Clair")
self.comboTheme.setItemText(1, self.tr("Dark"))
self.comboTheme.setItemData(1, "Sombre")
self.comboTheme.setItemText(2, self.tr("Professional"))
self.comboTheme.setItemData(2, "Professionnel")
self.comboTheme.setItemText(3, self.tr("Colorful"))
self.comboTheme.setItemData(3, "Coloré")
# --- Onglet Couches ---
if hasattr(self, "groupSelectionCouches"):
self.groupSelectionCouches.setTitle(self.tr("Layer selection to export"))
if hasattr(self, "groupPopupsConfiguration"):
self.groupPopupsConfiguration.setTitle(
self.tr("Popup configuration per layer")
)
if hasattr(self, "btnMoveUp"):
self.btnMoveUp.setText(self.tr("Move Up"))
if hasattr(self, "btnMoveDown"):
self.btnMoveDown.setText(self.tr("Move Down"))
if hasattr(self, "btnSelectAll"):
self.btnSelectAll.setText(self.tr("Select all"))
if hasattr(self, "btnDeselectAll"):
self.btnDeselectAll.setText(self.tr("Deselect all"))
if hasattr(self, "btnInvertSelection"):
self.btnInvertSelection.setText(self.tr("Invert"))
if hasattr(self, "lblCouchesPopup"):
self.lblCouchesPopup.setText(self.tr("1. Select a layer:"))
if hasattr(self, "lblChampsPopup"):
self.lblChampsPopup.setText(self.tr("2. Check fields to display:"))
# --- Onglet Avancé ---
if hasattr(self, "groupOptimisation"):
self.groupOptimisation.setTitle(self.tr("Data optimization"))
if hasattr(self, "groupExport"):
self.groupExport.setTitle(self.tr("Export options"))
if hasattr(self, "chkSimplifier"):
self.chkSimplifier.setText(self.tr("Simplify geometries"))
if hasattr(self, "chkCompresser"):
self.chkCompresser.setText(self.tr("Compress JSON data"))
if hasattr(self, "chkPrecision"):
self.chkPrecision.setText(self.tr("Round coordinates"))
if hasattr(self, "chkZip"):
self.chkZip.setText(self.tr("Export as ZIP file"))
if hasattr(self, "chkOuvrirNavigateur"):
self.chkOuvrirNavigateur.setText(self.tr("Open automatically in browser"))
if hasattr(self, "groupPostgres"):
self.groupPostgres.setTitle(self.tr("PostgreSQL data source"))
if hasattr(self, "chkPostgresDynamique"):
self.chkPostgresDynamique.setText(
self.tr(
"Dynamically load PostGIS layers from PostgreSQL "
"(instead of a static export)"
)
)
if hasattr(self, "lblPostgresAvertissement"):
self.lblPostgresAvertissement.setText(
self.tr(
"Requires a hosting environment with PHP and Apache active. "
"Not compatible with a local export or fully static hosting "
"(GitHub Pages, etc.). Only applies to layers already "
"connected to PostGIS in QGIS."
)
)
# --- Fond de plan (combo) ---
if hasattr(self, "comboFondPlan"):
for i in range(self.comboFondPlan.count()):
item = self.comboFondPlan.itemText(i)
if "OpenStreetMap" in item or "OpenStreetMap" in self.tr(
"OpenStreetMap"
):
self.comboFondPlan.setItemText(i, f"🌍 {self.tr('OpenStreetMap')}")
elif "Google Satellite" in item or "Google Satellite" in self.tr(
"Google Satellite"
):
self.comboFondPlan.setItemText(
i, f"🛰️ {self.tr('Google Satellite')}"
)
elif "Google Hybrid" in item or "Google Hybrid" in self.tr(
"Google Hybrid"
):
self.comboFondPlan.setItemText(i, f"🌐 {self.tr('Google Hybrid')}")
if hasattr(self, "chkFondPlanPersonnalise"):
self.chkFondPlanPersonnalise.setText(self.tr("Custom URL"))
# --- Onglet Wiki ---
if hasattr(self, "wikiTextEdit"):
self.load_wiki_content()
# --- Boutons OK / Cancel ---
if hasattr(self, "buttonBox"):
from qgis.PyQt.QtWidgets import QDialogButtonBox
ok_button = self.buttonBox.button(
qenum(QDialogButtonBox, "StandardButton", "Ok")
)
if ok_button:
ok_button.setText(self.tr("OK"))
cancel_button = self.buttonBox.button(
qenum(QDialogButtonBox, "StandardButton", "Cancel")
)
if cancel_button:
cancel_button.setText(self.tr("Cancel"))
print("Traductions appliquées")
def load_wiki_content(self):
"""Charge le contenu du Wiki selon la langue"""
try:
settings = QSettings()
locale = settings.value("locale/userLocale", "en_US")
if locale and locale.startswith("fr"):
wiki_file = os.path.join(
os.path.dirname(__file__), "i18n", "wiki_fr.html"
)
else:
wiki_file = os.path.join(
os.path.dirname(__file__), "i18n", "wiki_en.html"
)
if os.path.exists(wiki_file):
with open(wiki_file, "r", encoding="utf-8") as f:
self.wikiTextEdit.setHtml(f.read())
print(f"Wiki chargé depuis {wiki_file}")
else:
wiki_html = self.tr("WIKI_HTML")
if wiki_html and wiki_html != "WIKI_HTML":
self.wikiTextEdit.setHtml(wiki_html)
else:
self.wikiTextEdit.setHtml(
"<h1>Universal Map2web</h1><p>Wiki non disponible.</p>"
)
except Exception as e:
print(f"Erreur chargement Wiki: {e}")
self.wikiTextEdit.setHtml(f"<h1>Erreur</h1><p>{str(e)}</p>")
def charger_couches_qgis(self):
if not hasattr(self, "listCouches") or not hasattr(self, "listCouchesPopup"):
return
self.listCouches.clear()
self.listCouchesPopup.clear()
layers = QgsProject.instance().mapLayers().values()
for layer in layers:
if layer.type() == qenum(QgsMapLayer, "LayerType", "VectorLayer"):
item_export = QListWidgetItem(layer.name())
item_export.setCheckState(qenum(Qt, "CheckState", "Checked"))
item_export.setData(qenum(Qt, "ItemDataRole", "UserRole"), layer.id())
self.listCouches.addItem(item_export)
item_popup = QListWidgetItem(layer.name())
item_popup.setData(qenum(Qt, "ItemDataRole", "UserRole"), layer.id())
self.listCouchesPopup.addItem(item_popup)
self.popup_config[layer.id()] = [
field.name() for field in layer.fields()
]
if self.listCouchesPopup.count() > 0:
self.listCouchesPopup.setCurrentRow(0)
# ── Sauvegarde et Restauration des paramètres de configuration ────────
def sauvegarder_configuration_projet(self):
"""Sauvegarde toutes les options de la fenêtre dans le fichier de projet QGIS."""
project = QgsProject.instance()
sec = "UniversalMap2web"
# Personnalisation
if hasattr(self, "txtTitreCarte"):
project.writeEntry(sec, "txtTitreCarte", self.txtTitreCarte.text())
if hasattr(self, "lblLogoPath"):
project.writeEntry(sec, "logoPath", self.lblLogoPath.toolTip() or "")
project.writeEntry(sec, "logoText", self.lblLogoPath.text())
if hasattr(self, "chkAfficherLogo"):
project.writeEntry(sec, "chkAfficherLogo", self.chkAfficherLogo.isChecked())
if hasattr(self, "txtCouleurEntete"):
project.writeEntry(sec, "txtCouleurEntete", self.txtCouleurEntete.text())
if hasattr(self, "comboTheme"):
project.writeEntry(sec, "comboTheme", self.comboTheme.currentIndex())
# Fond de plan
if hasattr(self, "comboFondPlan"):
project.writeEntry(sec, "comboFondPlan", self.comboFondPlan.currentIndex())
if hasattr(self, "chkFondPlanPersonnalise"):
project.writeEntry(
sec,
"chkFondPlanPersonnalise",
self.chkFondPlanPersonnalise.isChecked(),
)
if hasattr(self, "txtFondPlanURL"):
project.writeEntry(sec, "txtFondPlanURL", self.txtFondPlanURL.text())
# Outils
chks = [
"chkRecherche",
"chkGeoloc",
"chkMesure",
"chkImprimer",
"chkPleinEcran",
"chkMiniMap",
"chkScale",
"chkMousePosition",
"chkAttribution",
"chkFiltreAvance",
]
for chk in chks:
if hasattr(self, chk):
project.writeEntry(sec, chk, getattr(self, chk).isChecked())
# Options avancées
if hasattr(self, "chkSimplifier"):
project.writeEntry(sec, "chkSimplifier", self.chkSimplifier.isChecked())
if hasattr(self, "spinTolerance"):
project.writeEntry(sec, "spinTolerance", str(self.spinTolerance.value()))
if hasattr(self, "chkCompresser"):
project.writeEntry(sec, "chkCompresser", self.chkCompresser.isChecked())
if hasattr(self, "chkPrecision"):
project.writeEntry(sec, "chkPrecision", self.chkPrecision.isChecked())
if hasattr(self, "spinPrecision"):
project.writeEntry(sec, "spinPrecision", self.spinPrecision.value())
if hasattr(self, "chkPostgresDynamique"):
project.writeEntry(
sec, "chkPostgresDynamique", self.chkPostgresDynamique.isChecked()
)
if hasattr(self, "chkZip"):
project.writeEntry(sec, "chkZip", self.chkZip.isChecked())
if hasattr(self, "chkOuvrirNavigateur"):
project.writeEntry(
sec, "chkOuvrirNavigateur", self.chkOuvrirNavigateur.isChecked()
)
# Sauvegarde de la configuration des popups (JSON)
project.writeEntry(sec, "popup_config", json.dumps(self.popup_config))
def restaurer_configuration_projet(self):
"""Restaure les options précédemment sauvegardées dans le projet QGIS."""
project = QgsProject.instance()
sec = "UniversalMap2web"
# Vérification si une configuration existe pour ce projet
valeur_test, ok = project.readEntry(sec, "txtTitreCarte", "")
if not ok:
return
# Personnalisation
if hasattr(self, "txtTitreCarte"):
val, _ = project.readEntry(sec, "txtTitreCarte", "")
if val:
self.txtTitreCarte.setText(val)
if hasattr(self, "lblLogoPath"):
path, _ = project.readEntry(sec, "logoPath", "")
text, _ = project.readEntry(sec, "logoText", self.tr("No logo"))
self.lblLogoPath.setText(text)
if path:
self.lblLogoPath.setToolTip(path)
if hasattr(self, "chkAfficherLogo"):
val, _ = project.readBoolEntry(sec, "chkAfficherLogo", True)
self.chkAfficherLogo.setChecked(val)
if hasattr(self, "txtCouleurEntete"):
val, _ = project.readEntry(sec, "txtCouleurEntete", "#1a1a2e")
self.txtCouleurEntete.setText(val)
if hasattr(self, "btnChoisirCouleur") and val:
self.btnChoisirCouleur.setStyleSheet(
f"background-color: {val}; color: white;"
)
if hasattr(self, "comboTheme"):
val, _ = project.readNumEntry(sec, "comboTheme", 0)
if 0 <= val < self.comboTheme.count():
self.comboTheme.setCurrentIndex(val)
# Fond de plan
if hasattr(self, "comboFondPlan"):
val, _ = project.readNumEntry(sec, "comboFondPlan", 0)
if 0 <= val < self.comboFondPlan.count():
self.comboFondPlan.setCurrentIndex(val)
if hasattr(self, "chkFondPlanPersonnalise"):
val, _ = project.readBoolEntry(sec, "chkFondPlanPersonnalise", False)
self.chkFondPlanPersonnalise.setChecked(val)
if hasattr(self, "txtFondPlanURL"):
val, _ = project.readEntry(sec, "txtFondPlanURL", "")
self.txtFondPlanURL.setText(val)
# Outils
chks = [
"chkRecherche",
"chkGeoloc",
"chkMesure",
"chkImprimer",
"chkPleinEcran",
"chkMiniMap",
"chkScale",
"chkMousePosition",
"chkAttribution",
"chkFiltreAvance",
]
for chk in chks:
if hasattr(self, chk):
val, _ = project.readBoolEntry(sec, chk, getattr(self, chk).isChecked())
getattr(self, chk).setChecked(val)
# Options avancées
if hasattr(self, "chkSimplifier"):
val, _ = project.readBoolEntry(sec, "chkSimplifier", False)
self.chkSimplifier.setChecked(val)
if hasattr(self, "spinTolerance"):
val, _ = project.readDoubleEntry(sec, "spinTolerance", 0.0)
self.spinTolerance.setValue(val)
if hasattr(self, "chkCompresser"):
val, _ = project.readBoolEntry(sec, "chkCompresser", False)
self.chkCompresser.setChecked(val)
if hasattr(self, "chkPrecision"):
val, _ = project.readBoolEntry(sec, "chkPrecision", False)
self.chkPrecision.setChecked(val)
if hasattr(self, "spinPrecision"):
val, _ = project.readNumEntry(sec, "spinPrecision", 6)
self.spinPrecision.setValue(val)
if hasattr(self, "chkPostgresDynamique"):
val, _ = project.readBoolEntry(sec, "chkPostgresDynamique", False)
self.chkPostgresDynamique.setChecked(val)
if hasattr(self, "chkZip"):
val, _ = project.readBoolEntry(sec, "chkZip", False)
self.chkZip.setChecked(val)
if hasattr(self, "chkOuvrirNavigateur"):
val, _ = project.readBoolEntry(sec, "chkOuvrirNavigateur", True)
self.chkOuvrirNavigateur.setChecked(val)
# Restauration de la configuration des Popups
popup_json, ok = project.readEntry(sec, "popup_config", "")
if ok and popup_json:
try:
self.popup_config = json.loads(popup_json)
# Recharger les cases à cocher si une couche est actuellement sélectionnée
current_item = self.listCouchesPopup.currentItem()
if current_item:
self.changement_couche_popup(current_item, None)
except Exception as e:
print(f"Erreur chargement popups: {e}")
# ── Onglet Personnalisation ──────────────────────────────
def selectionner_logo(self):
fichier, _ = QFileDialog.getOpenFileName(
self,
self.tr("Choose a logo"),
"",
"Images (*.png *.jpg *.jpeg *.svg)",
)
if fichier and hasattr(self, "lblLogoPath"):
self.lblLogoPath.setText(os.path.basename(fichier))
self.lblLogoPath.setToolTip(fichier)
def selectionner_couleur(self):
if not hasattr(self, "txtCouleurEntete"):
return
couleur_actuelle = self.txtCouleurEntete.text() or "#1a1a2e"
couleur = QColorDialog.getColor(QtGui.QColor(couleur_actuelle), self)
if couleur.isValid():
self.txtCouleurEntete.setText(couleur.name())
if hasattr(self, "btnChoisirCouleur"):
self.btnChoisirCouleur.setStyleSheet(
f"background-color: {couleur.name()}; color: white;"
)
# ── Onglet Couches ───────────────────────────────────────
def tout_selectionner(self):
if not hasattr(self, "listCouches"):
return
for i in range(self.listCouches.count()):
self.listCouches.item(i).setCheckState(qenum(Qt, "CheckState", "Checked"))
def tout_deselectionner(self):
if not hasattr(self, "listCouches"):
return
for i in range(self.listCouches.count()):
self.listCouches.item(i).setCheckState(qenum(Qt, "CheckState", "Unchecked"))
def inverser_selection(self):
if not hasattr(self, "listCouches"):
return
for i in range(self.listCouches.count()):
item = self.listCouches.item(i)
new_state = (
qenum(Qt, "CheckState", "Unchecked")
if item.checkState() == qenum(Qt, "CheckState", "Checked")
else qenum(Qt, "CheckState", "Checked")
)
item.setCheckState(new_state)
def monter_couche(self):
"""Déplace la couche sélectionnée d'une position vers le haut."""
if not hasattr(self, "listCouches"):
return
row = self.listCouches.currentRow()
if row <= 0:
return
item = self.listCouches.takeItem(row)
self.listCouches.insertItem(row - 1, item)
self.listCouches.setCurrentRow(row - 1)
def descendre_couche(self):
"""Déplace la couche sélectionnée d'une position vers le bas."""
if not hasattr(self, "listCouches"):
return
row = self.listCouches.currentRow()
if row < 0 or row >= self.listCouches.count() - 1:
return
item = self.listCouches.takeItem(row)
self.listCouches.insertItem(row + 1, item)
self.listCouches.setCurrentRow(row + 1)
# ── Mémorisation des popups ──────────────────────────────
def sauvegarder_champs_couche_actuelle(self):
if not hasattr(self, "listChampsPopup"):
return
if self.derniere_couche_id and self.derniere_couche_id in self.popup_config:
champs_coches = []
for i in range(self.listChampsPopup.count()):
item = self.listChampsPopup.item(i)
if item.checkState() == qenum(Qt, "CheckState", "Checked"):
champs_coches.append(item.text())
self.popup_config[self.derniere_couche_id] = champs_coches
def changement_couche_popup(self, current_item, previous_item):
if not hasattr(self, "listChampsPopup"):
return
if previous_item:
previous_id = previous_item.data(qenum(Qt, "ItemDataRole", "UserRole"))
self.derniere_couche_id = previous_id
self.sauvegarder_champs_couche_actuelle()
self.listChampsPopup.clear()
if not current_item:
return
layer_id = current_item.data(qenum(Qt, "ItemDataRole", "UserRole"))
self.derniere_couche_id = layer_id
layer = QgsProject.instance().mapLayer(layer_id)
if layer:
champs_sauvegardes = self.popup_config.get(
layer_id, [f.name() for f in layer.fields()]
)
for field in layer.fields():
field_name = field.name()
item_champ = QListWidgetItem(field_name)
item_champ.setCheckState(
qenum(Qt, "CheckState", "Checked")
if field_name in champs_sauvegardes
else qenum(Qt, "CheckState", "Unchecked")
)
self.listChampsPopup.addItem(item_champ)
def accept(self):
self.sauvegarder_champs_couche_actuelle()
# Sauvegarder la configuration globale dans le fichier .qgz lors de la validation
self.sauvegarder_configuration_projet()
super(UniversalMap2webDialog, self).accept()