Skip to content

Commit

Permalink
Merge pull request #37 from Geonature-GIS/revision-1.1.0
Browse files Browse the repository at this point in the history
Revision 1.1.0
  • Loading branch information
maximetoma committed Apr 22, 2024
2 parents 7ccf1b2 + fda18cd commit 6023971
Show file tree
Hide file tree
Showing 13 changed files with 1,761 additions and 1,376 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Actual version : 1.0.0
Actual version : 1.1.0

* 08/03/2024 - Version 0.1 : Base du Plugin avec connexion entre les fenêtres QTdesigner
* 10/03/2024 - Version 0.2 : Implémentation, Connexion bdd, Sélection du type de zonage v1 , Ajout des icones
Expand All @@ -8,3 +8,4 @@ Actual version : 1.0.0
* 15/03/2024 - Version 0.4.2: Liste types de zonages v3, Sources v2, Additional_data_filter v1, boutons quitter et annuler, paramètre avancé, about
* 28/03/2024 - Version 0.5.0: Version de restitution à la LPO et fin du projet tutoré
* 09/04/2024 - Version 1.0.0: Première release du plugin
* 22/04/2024 - Version 1.1.0: Blocage du QMenu en cas de déconnexion, Tri par id de la liste des exports, QDockWidget rendus scrollables, Gestion de l'activation/Désactivation des boutons selon la sélection des entités, Gestion des exports sans géométrie, Gestion des types de champs dans la clause WHERE de la partie EXPORTS, Changement de l'affichage des types "date" dans les filtres de la partie EXPORTS
11 changes: 10 additions & 1 deletion connexion_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import sys, os

from .geonaturegisPlugin import *

sys.path.append(os.path.dirname(__file__))
from .resources_rc import *

Expand All @@ -17,14 +19,17 @@
form_connect, _ = uic.loadUiType(os.path.join(ui_path, "connect.ui"))

class ConnexionWidget(QDialog, form_connect):
def __init__(self, iface, wpsw, parent=None):
def __init__(self, iface, wpsw, pluginGeonatGIS, parent=None):
QDialog.__init__(self)

self.setupUi(self) # méthode de Ui_action1_form pour construire les widgets

self.psw = wpsw
self.recupParametre()

# Stockage de la référence à l'instance de pluginGeonatGIS
self.pluginGeonatGIS = pluginGeonatGIS

self.btnBox.accepted.connect(self.accept)
self.btnBox.rejected.connect(self.reject)

Expand Down Expand Up @@ -70,6 +75,10 @@ def accept(self):
self.majParametre()
if self.testCnxOk():
QMessageBox.information(self, "Test de connexion", "Test de connexion à la base de données OK ...", QMessageBox.Ok)
self.pluginGeonatGIS.actionRefGeo.setEnabled(True)
self.pluginGeonatGIS.actionExport.setEnabled(True)
QDialog.accept(self)
else:
QMessageBox.critical(self, "Erreur", "Impossible de se connecter à la base de données ...", QMessageBox.Ok)
self.pluginGeonatGIS.actionRefGeo.setEnabled(False)
self.pluginGeonatGIS.actionExport.setEnabled(False)
111 changes: 92 additions & 19 deletions export_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from qgis.core import *
from qgis.gui import *
import qgis.utils
import time

import sys, os

Expand Down Expand Up @@ -38,6 +39,11 @@ def __init__(self, interface, whost, wport, wbdd, wusername, wpsw):
self.username = wusername
self.psw = wpsw

self.pb_addfilter.setEnabled(False)
self.pb_runquery.setEnabled(False)
self.pb_loadlayer.setEnabled(False)
self.pb_export.setEnabled(False)

# Fonction réinitialisation des paramètres des filtes
self.pb_reset.clicked.connect(self.reinitialisation)

Expand All @@ -56,7 +62,7 @@ def __init__(self, interface, whost, wport, wbdd, wusername, wpsw):

self.pb_quit.clicked.connect(self.quitter)


self.lw_typegeomresult.itemSelectionChanged.connect(self.activeLoadAndExportButtons)

self.nom_export = ""
self.schema = ""
Expand All @@ -72,12 +78,22 @@ def __init__(self, interface, whost, wport, wbdd, wusername, wpsw):
self.vlayer_multipoly = QgsVectorLayer()
self.nom_couche = ""

def activeLoadAndExportButtons(self):
if self.lw_typegeomresult.selectedItems():
self.pb_loadlayer.setEnabled(True)
self.pb_export.setEnabled(True)
else:
self.pb_loadlayer.setEnabled(False)
self.pb_export.setEnabled(False)

def openSelectExport(self):
self.connexionSelect = SelectExportWidget(self.interfaceFenetres, self.host, self.port, self.bdd, self.username, self.psw)
self.reinitialisation()
self.connexionSelect = SelectExportWidget(self.interfaceFenetres, self.host, self.port, self.bdd, self.username, self.psw)
# connexion.show()
result = self.connexionSelect.exec_()
if result:
self.pb_addfilter.setEnabled(True)
self.pb_runquery.setEnabled(True)
return self.connexionSelect.selected_export_name , self.connexionSelect.description , self.connexionSelect.selected_view_schema, self.connexionSelect.selected_view_name, self.connexionSelect.geom_field, self.connexionSelect.srid, self.connexionSelect.pk_column, self.maj_lbl_nom_export(), self.maj_lbl_description()


Expand Down Expand Up @@ -109,6 +125,18 @@ def maj_lbl_filterparam(self):

def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Ligne 234 separer_geom()

# === On créé une instance de QProgressDialog pour l'execution de la requête ===

progress_dialog = QProgressDialog("Exécution de la requête...", None, 0, 0, self)
progress_dialog.setWindowTitle("Chargement")
progress_dialog.setWindowModality(Qt.WindowModal)
progress_dialog.setAutoReset(False)
progress_dialog.setAutoClose(False)

# === On execute les requêtes ===

progress_dialog.show()

self.lw_typegeomresult.clear()

self.nom_export = self.connexionSelect.selected_export_name[0]
Expand All @@ -134,6 +162,7 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
wuri_multipoint = QgsDataSourceUri()
wuri_multiligne = QgsDataSourceUri()
wuri_multipoly = QgsDataSourceUri()
wuri_ssgeom = QgsDataSourceUri()

# set host name, port, database name, username and password
# wuri.setConnection(self.host, str(self.port), self.bdd , self.username, self.psw)
Expand All @@ -144,6 +173,7 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
wuri_multipoint.setConnection(self.host, str(self.port), self.bdd , self.username, self.psw)
wuri_multiligne.setConnection(self.host, str(self.port), self.bdd , self.username, self.psw)
wuri_multipoly.setConnection(self.host, str(self.port), self.bdd , self.username, self.psw)
wuri_ssgeom.setConnection(self.host, str(self.port), self.bdd , self.username, self.psw)

if self.connexionSelect.selected_view_name != [] :
print(self.schema)
Expand All @@ -158,23 +188,26 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
where_multipoint = f"{filter} ST_GeometryType({geom_column}) ILIKE 'ST_MultiPoint'"
where_multiligne = f"{filter} ST_GeometryType({geom_column}) ILIKE 'ST_MultiLineString'"
where_multipoly = f"{filter} ST_GeometryType({geom_column}) ILIKE 'ST_MultiPolygon'"
where_ssgeom = f"{filter[:-5]}" # [:-5] supprime le dernier AND necessaire en cas de géométrie


# set database schema, table name, geometry column and optionally
# subset (WHERE clause)
wuri_point.setDataSource(self.schema, self.vue, geom_column, where_point, pk_column) # 6 LIGNES ST_geometry
wuri_ligne.setDataSource(self.schema, self.vue, geom_column, where_ligne, pk_column)
wuri_poly.setDataSource(self.schema, self.vue, geom_column, where_poly, pk_column)
wuri_multipoint.setDataSource(self.schema, self.vue, geom_column, where_multipoint, pk_column)
wuri_multiligne.setDataSource(self.schema, self.vue, geom_column, where_multiligne, pk_column)
wuri_multipoly.setDataSource(self.schema, self.vue, geom_column, where_multipoly, pk_column)
wuri_point.setDataSource(self.schema, self.vue, str(geom_column), where_point, pk_column) # 6 LIGNES ST_geometry
wuri_ligne.setDataSource(self.schema, self.vue, str(geom_column), where_ligne, pk_column)
wuri_poly.setDataSource(self.schema, self.vue, str(geom_column), where_poly, pk_column)
wuri_multipoint.setDataSource(self.schema, self.vue, str(geom_column), where_multipoint, pk_column)
wuri_multiligne.setDataSource(self.schema, self.vue, str(geom_column), where_multiligne, pk_column)
wuri_multipoly.setDataSource(self.schema, self.vue, str(geom_column), where_multipoly, pk_column)
wuri_ssgeom.setDataSource(self.schema, self.vue, "", where_ssgeom, pk_column)

self.vlayer_point = QgsVectorLayer(wuri_point.uri(), f"{self.nom_export}_{self.srid}_point", "postgres")
self.vlayer_ligne = QgsVectorLayer(wuri_ligne.uri(), f"{self.nom_export}_{self.srid}_ligne", "postgres")
self.vlayer_poly = QgsVectorLayer(wuri_poly.uri(), f"{self.nom_export}_{self.srid}_poly", "postgres")
self.vlayer_multipoint = QgsVectorLayer(wuri_multipoint.uri(), f"{self.nom_export}_{self.srid}_multipoint", "postgres")
self.vlayer_multiligne = QgsVectorLayer(wuri_multiligne.uri(), f"{self.nom_export}_{self.srid}_multiligne", "postgres")
self.vlayer_multipoly = QgsVectorLayer(wuri_multipoly.uri(), f"{self.nom_export}_{self.srid}_multipoly", "postgres")
self.vlayer_ssgeom = QgsVectorLayer(wuri_ssgeom.uri(), f"{self.nom_export}_sansgeom", "postgres")

if self.vlayer_point.featureCount() > 0 :
if self.vlayer_point.isValid() :
Expand All @@ -192,6 +225,8 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()

if self.vlayer_ligne.featureCount() > 0 :
if self.vlayer_ligne.isValid() :
Expand All @@ -205,11 +240,11 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
print(data)
item.setData(256,data) # 256 = constante renvoyée par Qt.UserRole (bug avec Qt.UserRole sur certains pc)
self.lw_typegeomresult.addItem(item)


else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()

if self.vlayer_poly.featureCount() > 0 :
if self.vlayer_poly.isValid() :
Expand All @@ -224,10 +259,11 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
print(data)
item.setData(256,data) # 256 = constante renvoyée par Qt.UserRole (bug avec Qt.UserRole sur certains pc)
self.lw_typegeomresult.addItem(item)

else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()

if self.vlayer_multipoint.featureCount() > 0 :
if self.vlayer_multipoint.isValid():
Expand All @@ -244,6 +280,8 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid multipoint")
if progress_dialog:
progress_dialog.hide()


if self.vlayer_multiligne.featureCount() > 0 :
Expand All @@ -261,6 +299,8 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()

if self.vlayer_multipoly.featureCount() > 0 :
if self.vlayer_multipoly.isValid():
Expand All @@ -274,10 +314,35 @@ def executer(self, feature): # TO DO : TRIER LES TYPES DE GEOM D'UNE VUE CF Lign
print(data)
item.setData(256,data) # 256 = constante renvoyée par Qt.UserRole (bug avec Qt.UserRole sur certains pc)
self.lw_typegeomresult.addItem(item)

else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()


if self.vlayer_ssgeom.featureCount() > 0 and geom_column == '' or geom_column == None :
if self.vlayer_ssgeom.isValid():
print("vlayer valide sans geom")
QMessageBox.information(self, "Information", "Couche valide !", QMessageBox.Ok)
QgsProject.instance().addMapLayer(self.vlayer_ssgeom, False)
# on crée un item qui contient à la fois le texte présenté à l'utilisateur
item = QListWidgetItem(f"Sans geométrie ({self.vlayer_ssgeom.featureCount()})")
# et les données associées
data = self.vlayer_ssgeom.name()
print(data)
item.setData(256,data) # 256 = constante renvoyée par Qt.UserRole (bug avec Qt.UserRole sur certains pc)
self.lw_typegeomresult.addItem(item)
else:
QMessageBox.critical(self, "Erreur", "Couche non valide", QMessageBox.Ok)
print("vlayer non valid")
if progress_dialog:
progress_dialog.hide()

if self.vlayer_point.featureCount() == 0 and self.vlayer_multipoint.featureCount() == 0 and self.vlayer_multiligne.featureCount() == 0 and self.vlayer_multipoly.featureCount() == 0 and self.vlayer_ssgeom.featureCount() == 0 :
QMessageBox.warning(self, "Aucune entité", "Aucune entité n'a été retourné par la requête", QMessageBox.Ok)
if progress_dialog:
progress_dialog.hide()

def retrouveCouche(self, sonNom):
vlayer = None
Expand Down Expand Up @@ -496,12 +561,13 @@ def reinitialisation(self):
print('Réinitialisé !')

#Export
self.connexionSelect.selected_export_name = []
self.connexionSelect.description = []
self.connexionSelect.selected_view_schema = []
self.connexionSelect.selected_view_name = []
self.connexionSelect.geom_field = []
self.connexionSelect.srid = []
if self.connexionSelect: # Réinitialise si self.connexionSelect existe
self.connexionSelect.selected_export_name = []
self.connexionSelect.description = []
self.connexionSelect.selected_view_schema = []
self.connexionSelect.selected_view_name = []
self.connexionSelect.geom_field = []
self.connexionSelect.srid = []

#Filtre
self.filter_result = []
Expand All @@ -517,9 +583,16 @@ def reinitialisation(self):
self.vlayer_multiligne = QgsVectorLayer()
self.vlayer_multipoly = QgsVectorLayer()

#Type de géométrie trouvée
#Type de géométrie trouvée
self.lw_typegeomresult.clear()

# Désactivation des boutons
self.pb_addfilter.setEnabled(False)
self.pb_runquery.setEnabled(False)
self.pb_loadlayer.setEnabled(False)
self.pb_export.setEnabled(False)


def closeEvent(self, event):
self.fermeFenetreFonction.emit(["export"])
event.accept()
Expand Down
Loading

0 comments on commit 6023971

Please sign in to comment.