diff --git a/CenRa_AUTOMAP/CenRa_AutoMap.py b/CenRa_AUTOMAP/CenRa_AutoMap.py index 1c02888b..2040104f 100644 --- a/CenRa_AUTOMAP/CenRa_AutoMap.py +++ b/CenRa_AUTOMAP/CenRa_AutoMap.py @@ -30,6 +30,7 @@ from .tools.resources import ( maj_verif, ) from .canvas_editor import AutoMap_Editor +from .style_invoke import AutoMap_Style from .about_form import AboutDialog from PyQt5.QtCore import * @@ -38,6 +39,7 @@ class PgAutoMap: def __init__(self): """ Constructor. """ self.canvas_editor = None + self.style_dock = None # self.issues = None self.provider = None self.locator_filter = None @@ -73,10 +75,16 @@ class PgAutoMap: if not self.canvas_editor: self.canvas_editor = AutoMap_Editor() - self.automap_action = QAction(icon, 'CenRa_AutoMap',None) self.toolBar.addAction(self.automap_action) self.automap_action.triggered.connect(self.open_editor) + + if not self.style_dock: + self.style_dock = AutoMap_Style() + + if os.environ['USERNAME'] == 'tlaveille' or os.environ['USERNAME'] == 'lpoulin' or os.environ['USERNAME'] == 'rclement': + iface.addDockWidget(Qt.LeftDockWidgetArea, self.style_dock) + ''' if not self.locator_filter: self.locator_filter = LocatorFilter(iface) diff --git a/CenRa_AUTOMAP/metadata.txt b/CenRa_AUTOMAP/metadata.txt index 5c2416f6..0732ade8 100644 --- a/CenRa_AUTOMAP/metadata.txt +++ b/CenRa_AUTOMAP/metadata.txt @@ -6,7 +6,7 @@ name=CenRa_AutoMap qgisMinimumVersion=3.0 description=CenRa_AutoMap -version=1.1 +version=1.2 author=Conservatoire d'Espaces Naturels de Rhône-Alpes email=si_besoin@cen-rhonealpes.fr @@ -21,7 +21,7 @@ tracker=https://gitea.cenra-outils.org/api/v1/repos/CEN-RA/Plugin_QGIS/issues hasProcessingProvider=no # Uncomment the following line and add your changelog: -changelog=

CenRa_AutoMap:


28/01/2025 - Version 1.1:

- Multi-Composeur pris en charge.


27/01/2025 - Version 1.0:

- Version releases.
- Ajoute un message d'avertissement au moment d'écraser la mise en page.
- Ajoute prénom et nom dans la réalisation.
- Utilisation de Calibri.


13/01/2025 - Version 0.1.10:

- Correctif.


07/01/2025 - Version 0.1.9:

- ByPass du certif ssl ci erreur.


19/12/2024 - Version 0.1.8:

- Nouvelle mise en page.
- Incrémentation automatique de nouveau modele de mise en page.
- Correctif de bug.


21/10/2024 - Version 0.1.7:

- Epurations du code.


07/10/2024 - Version 0.1.6:

- Option de bibliotheque de logo custome.


03/10/2024 - Version 0.1.5:

- Remonte la fênetre dans la pille.
- Gestion du nombre de colonne dans la légend.


02/10/2024 - Version 0.1.4:

- Mise en page plein écrant.


01/10/2024 - Version 0.1.3:

- Récupération du titre et sous-titre pour mise en page existente.
- Integration de bibliotheque de logo.
- Integration de gestionaire pour les source de donnée.
- Mise en place d'une bar d'echelle adaptative.


30/09/2024 - Version 0.1.2:

- Activation du thème.
- Ajouter une carte de suivie.


27/09/2024 - Version 0.1.1:

- Ajout d'une liste déroulante pour les sources de données.
- Bouton pour ajouter des fonts de carte customisés.
- Fonctionnalité de génération d'atlas.


26/09/2024 - Version 0.1.0:

- Lancement du plugin CenRa_AutoMap avec une seul mise en page.


+changelog=

CenRa_AutoMap:


25/02/2025 - Version 1.2:

- DockWidget pour ouverture de couche avec theme.


28/01/2025 - Version 1.1:

- Multi-Composeur pris en charge.


27/01/2025 - Version 1.0:

- Version releases.
- Ajoute un message d'avertissement au moment d'écraser la mise en page.
- Ajoute prénom et nom dans la réalisation.
- Utilisation de Calibri.


13/01/2025 - Version 0.1.10:

- Correctif.


07/01/2025 - Version 0.1.9:

- ByPass du certif ssl ci erreur.


19/12/2024 - Version 0.1.8:

- Nouvelle mise en page.
- Incrémentation automatique de nouveau modele de mise en page.
- Correctif de bug.


21/10/2024 - Version 0.1.7:

- Epurations du code.


07/10/2024 - Version 0.1.6:

- Option de bibliotheque de logo custome.


03/10/2024 - Version 0.1.5:

- Remonte la fênetre dans la pille.
- Gestion du nombre de colonne dans la légend.


02/10/2024 - Version 0.1.4:

- Mise en page plein écrant.


01/10/2024 - Version 0.1.3:

- Récupération du titre et sous-titre pour mise en page existente.
- Integration de bibliotheque de logo.
- Integration de gestionaire pour les source de donnée.
- Mise en place d'une bar d'echelle adaptative.


30/09/2024 - Version 0.1.2:

- Activation du thème.
- Ajouter une carte de suivie.


27/09/2024 - Version 0.1.1:

- Ajout d'une liste déroulante pour les sources de données.
- Bouton pour ajouter des fonts de carte customisés.
- Fonctionnalité de génération d'atlas.


26/09/2024 - Version 0.1.0:

- Lancement du plugin CenRa_AutoMap avec une seul mise en page.


# Tags are comma separated with spaces allowed tags=python diff --git a/CenRa_AUTOMAP/style_invoke.py b/CenRa_AUTOMAP/style_invoke.py new file mode 100644 index 00000000..cc340c21 --- /dev/null +++ b/CenRa_AUTOMAP/style_invoke.py @@ -0,0 +1,197 @@ +import logging +import os +from PyQt5.QtCore import QSettings +from collections import namedtuple +from enum import Enum +from functools import partial +from pathlib import Path +from xml.dom.minidom import parseString +from qgis.gui import * +import qgis +from importlib import import_module +from qgis.core import ( + NULL, + QgsApplication, + QgsScaleBarSettings, + QgsDataSourceUri, + QgsProject, + QgsProviderConnectionException, + QgsProviderRegistry, + QgsRasterLayer, + QgsSettings, + QgsVectorLayer, + QgsGeometry, + QgsPrintLayout, + QgsReadWriteContext, + QgsLayoutItemMap, + QgsLayoutItemPage, + QgsLayoutSize, + QgsUnitTypes, + QgsLayoutPoint, + QgsLayoutItemLabel, + QgsLayoutItemPicture, + QgsLayoutItemLegend, + QgsLegendStyle, + QgsLayoutItemScaleBar, + QgsLayerTreeGroup, + QgsCoordinateReferenceSystem, + QgsCoordinateTransform, + QgsLayerTree, + QgsLayoutTableColumn, + QgsRectangle, + QgsLayoutItemMapOverviewStack, + QgsMapThemeCollection, +) +from qgis.PyQt.QtCore import QLocale, QUrl, QDateTime, Qt +from qgis.PyQt.QtGui import QDesktopServices, QIcon, QColor, QFont, QMovie +from qgis.PyQt.QtPrintSupport import QPrinter +from qgis.PyQt.QtWebKitWidgets import QWebPage +from qgis.PyQt.QtWidgets import ( + QDockWidget, + QAction, + QMessageBox, + QPushButton, + QDockWidget, + QFileDialog, + QInputDialog, + QMenu, + QToolButton, + QTableWidget, + QTableWidgetItem, + QVBoxLayout, +) +import psycopg2 +from PyQt5 import QtGui +from PyQt5 import QtWidgets +from qgis.PyQt.QtXml import QDomDocument +from qgis.utils import iface +import glob +from .tools.PythonSQL import * +from .tools.resources import ( + load_ui, + resources_path, + login_base, + send_issues, +) +from .issues import CenRa_Issues + +from datetime import date + +EDITOR_CLASS = load_ui('CenRa_AutoMapStyle_base.ui') +LOGGER = logging.getLogger('CenRa_AutoMapStyle') + +class AutoMap_Style(QDockWidget, EDITOR_CLASS): + + def __init__(self, parent=None): + _ = parent + super().__init__() + self.setupUi(self) + self.settings = QgsSettings() + self.s = QSettings() + + self.toolButton.setIcon(QtGui.QIcon(resources_path('icons','loader.png'))) + + self.loadComboBox() + self.toolButton.clicked.connect(self.loadStyle) + + def loadComboBox(self): + style = self.comboBox + style.clear() + style.addItem('') + style.addItem('Foncier') + style.addItem('Administratif') + + def loadStyle(self): + style = self.comboBox.currentText() + if style == 'Foncier': + self.loadFoncier() + if style == 'Administratif': + self.loadAdministratif() + + def loginfo(self): + InputDialog = QInputDialog() + mdp = InputDialog.getText(None,'Foncier','Mot de pass base foncier:') + return mdp + + def loadAdministratif(self): + mtc = QgsProject.instance().mapThemeCollection() + theme_name = 'Administratif' + theme_state = mtc.mapThemeState(theme_name) + + mdp = self.loginfo()[0] + if mdp != '': + # couche = [['_form_power_rename','_form_power_rename_contour_2025'],['_42_bois_du_roy','_42_bois_du_roy_habitat_2021']] + couche = [['administratif','departements2024','gid'],['administratif','v_communes','id']] + for schema_table in couche: + schema = schema_table[0] + table = schema_table[1] + key = schema_table[2] + uri = QgsDataSourceUri() + uri.setConnection(host ,port ,dbname ,os_user ,mdp) + # nom du schéma à remplacer: "hydrographie" à supprimer et mettre "couches_collaboratives" lorsqu'on aura regroupé les couches à modifier dans un même schéma + uri.setDataSource(schema, table, "geom") + uri.setKeyColumn(key) + layer = QgsVectorLayer(uri.uri(), table, "postgres") + if layer.isValid() == True: + layerName = layer.name() + listStyle = layer.listStylesInDatabase() + try: + StyleExist = True + indexStyle = (listStyle[2].index(layerName)) + except: + StyleExist = False + if StyleExist: + StyleId = (listStyle[1][indexStyle]) + styleTuple = layer.getStyleFromDatabase(StyleId) + styleqml = styleTuple[0] + styledoc = QDomDocument() + styledoc.setContent(styleqml) + layer.importNamedStyle(styledoc) + + # Ajout de la couche au canevas QGIS + QgsProject.instance().addMapLayer(layer) + + layer_record = QgsMapThemeCollection.MapThemeLayerRecord(layer) + theme_state.addLayerRecord(layer_record) + mtc.insert(theme_name, theme_state) + + def loadFoncier(self): + mtc = QgsProject.instance().mapThemeCollection() + theme_name = 'Foncier' + theme_state = mtc.mapThemeState(theme_name) + + mdp = self.loginfo()[0] + if mdp != '': + # couche = [['_form_power_rename','_form_power_rename_contour_2025'],['_42_bois_du_roy','_42_bois_du_roy_habitat_2021']] + couche = [['sites','v_sites_parcelles'],['sites','v_sites'],['inventaires','suivi_zh'],['inventaires','suivi_ps']] + for schema_table in couche: + schema = schema_table[0] + table = schema_table[1] + uri = QgsDataSourceUri() + uri.setConnection(host ,port ,dbname ,os_user ,mdp) + # nom du schéma à remplacer: "hydrographie" à supprimer et mettre "couches_collaboratives" lorsqu'on aura regroupé les couches à modifier dans un même schéma + uri.setDataSource(schema, table, "geom") + uri.setKeyColumn('gid') + layer = QgsVectorLayer(uri.uri(), table, "postgres") + if layer.isValid() == True: + layerName = layer.name() + listStyle = layer.listStylesInDatabase() + try: + StyleExist = True + indexStyle = (listStyle[2].index(layerName)) + except: + StyleExist = False + if StyleExist: + StyleId = (listStyle[1][indexStyle]) + styleTuple = layer.getStyleFromDatabase(StyleId) + styleqml = styleTuple[0] + styledoc = QDomDocument() + styledoc.setContent(styleqml) + layer.importNamedStyle(styledoc) + + # Ajout de la couche au canevas QGIS + QgsProject.instance().addMapLayer(layer) + + layer_record = QgsMapThemeCollection.MapThemeLayerRecord(layer) + theme_state.addLayerRecord(layer_record) + mtc.insert(theme_name, theme_state) diff --git a/CenRa_AUTOMAP/tools/PythonSQL.py b/CenRa_AUTOMAP/tools/PythonSQL.py index 99963120..ae12f34e 100644 --- a/CenRa_AUTOMAP/tools/PythonSQL.py +++ b/CenRa_AUTOMAP/tools/PythonSQL.py @@ -1,29 +1,11 @@ import sys import socket import os -IPAddr=socket.gethostbyname(socket.gethostname()) -#print(IPAddr) -if IPAddr[0:11] == "100.100.100": #4269 - host = "100.100.100.81" - port = "5432" - dbname = "sig4269" - sigdb="sig4269" - refdb="ref_geo4269" - password = "McVities" -if IPAddr[0:9] == "192.168.0": #01 - host = "192.168.0.201" - port = "5432" - dbname = "sig01" - sigdb="sig01" - refdb="ref_geo01" - password = "McVities" -if IPAddr[0:9] == "192.168.1": #0726 - host = "192.168.1.201" - port = "5432" - dbname = "sig0726" - sigdb="sig0726" - refdb="ref_geo0726" - password = "McVities" + +host = "91.134.194.220" +port = "5432" +dbname = "bd_cen" + if sys.platform == 'linux': os_user = os.environ['USER'] else: diff --git a/CenRa_AUTOMAP/tools/icons/loader.png b/CenRa_AUTOMAP/tools/icons/loader.png new file mode 100644 index 00000000..f4ea0cd3 Binary files /dev/null and b/CenRa_AUTOMAP/tools/icons/loader.png differ diff --git a/CenRa_AUTOMAP/tools/ui/CenRa_AutoMapStyle_base.ui b/CenRa_AUTOMAP/tools/ui/CenRa_AutoMapStyle_base.ui new file mode 100644 index 00000000..47c8cb68 --- /dev/null +++ b/CenRa_AUTOMAP/tools/ui/CenRa_AutoMapStyle_base.ui @@ -0,0 +1,94 @@ + + + CenRa_AutoMapStyle + + + + 0 + 0 + 400 + 48 + + + + + 0 + 0 + + + + false + + + QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable + + + CenRa_AutoMap + + + + true + + + + 5 + + + 0 + + + 5 + + + 0 + + + 5 + + + + + true + + + + + + + + 40 + 16777215 + + + + + 12 + + + + Style: + + + + + + + true + + + + + + + 20 + 20 + + + + + + + + + + diff --git a/CenRa_AUTOMAP/tools/ui/CenRa_AutoMap_base.ui b/CenRa_AUTOMAP/tools/ui/CenRa_AutoMap_base.ui index 571784fb..5a2a8c24 100644 --- a/CenRa_AUTOMAP/tools/ui/CenRa_AutoMap_base.ui +++ b/CenRa_AUTOMAP/tools/ui/CenRa_AutoMap_base.ui @@ -7,7 +7,7 @@ 0 0 1150 - 778 + 680 diff --git a/CenRa_FLUX/flux_editor.py b/CenRa_FLUX/flux_editor.py index 872506e3..a1dc3594 100644 --- a/CenRa_FLUX/flux_editor.py +++ b/CenRa_FLUX/flux_editor.py @@ -45,14 +45,16 @@ import psycopg2 import psycopg2.extras import base64 -first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password) -first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor) -first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')") -res_ident = first_cur.fetchone() -mdp = base64.b64decode(str(res_ident[0])).decode('utf-8') -user = res_ident[1] -first_conn.close() - +try: + first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password) + first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor) + first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')") + res_ident = first_cur.fetchone() + mdp = base64.b64decode(str(res_ident[0])).decode('utf-8') + user = res_ident[1] + first_conn.close() +except: + print('') EDITOR_CLASS = load_ui('CenRa_Flux_base.ui') class Flux_Editor(QDialog, EDITOR_CLASS): diff --git a/CenRa_POSTGIS/postgis_rename.py b/CenRa_POSTGIS/postgis_rename.py index 73b4c95d..fdb643f1 100644 --- a/CenRa_POSTGIS/postgis_rename.py +++ b/CenRa_POSTGIS/postgis_rename.py @@ -37,17 +37,18 @@ from qgis.utils import iface EDITOR_CLASS = load_ui('CenRa_PostgisRename_base.ui') ch = [u"à", u"À", u"â", u"Â", u"ä", u"Ä", u"å", u"Å", u"ç", u"Ç", u"é", u"É", u"è", u"È", u"ê", u"Ê", u"ë", u"Ë", u"î", u"Î", u"ï", u"Ï", u"ô", u"Ô", u"ö", u"Ö", u"ù", u"Ù", u"û", u"Û", u"ü", u"Ü", u"ÿ", u"Ÿ", u"'", u"-", u" "] -first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password) -first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor) -first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')") -res_ident = first_cur.fetchone() -mdp = base64.b64decode(str(res_ident[0])).decode('utf-8') -user = res_ident[1] - -con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp) -cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor) -first_conn.close() - +try: + first_conn = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=first_cnx password=" + password) + first_cur = first_conn.cursor(cursor_factory = psycopg2.extras.DictCursor) + first_cur.execute("SELECT mdp_w, login_w FROM pg_catalog.pg_user t1, admin_sig.vm_users_sig t2 WHERE t2.oid = t1.usesysid AND (login_w = '" + os_user + "' OR login_w = '" + os_user + "')") + res_ident = first_cur.fetchone() + mdp = base64.b64decode(str(res_ident[0])).decode('utf-8') + user = res_ident[1] + first_conn.close() + con = psycopg2.connect("host=" + host + " port=" + port + " dbname="+dbname+" user=" + user + " password=" + mdp) + cur = con.cursor(cursor_factory = psycopg2.extras.DictCursor) +except: + print('') class Postgis_Rename(QDialog, EDITOR_CLASS): def __init__(self, parent=None): diff --git a/CenRa_POSTGIS/tools/ui/CenRa_PostgisRename_base.ui b/CenRa_POSTGIS/tools/ui/CenRa_PostgisRename_base.ui index 6f32b2d5..75d67f7e 100644 --- a/CenRa_POSTGIS/tools/ui/CenRa_PostgisRename_base.ui +++ b/CenRa_POSTGIS/tools/ui/CenRa_PostgisRename_base.ui @@ -13,268 +13,242 @@ Ajout d'une table - - - - 360 - 330 - 161 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 160 - 0 - 201 - 31 - - - - - 14 - 75 - true - - - - Renommée de table - - - - - - 10 - 80 - 511 - 101 - - - - - 75 - true - - - - Tester mon éligibilite : - - - Qt::AlignCenter - - - - - 10 - 19 - 491 - 71 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Compte - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Couche - - - - - - - - - - 10 - 40 - 511 - 31 - - - - - - - - 90 - 16777215 - - - - Code analytique : - - - - - - - - - - - - 10 - 180 - 511 - 151 - - - - - 75 - true - - - - Les changement : - - - Qt::AlignCenter - - - - - 10 - 20 - 491 - 61 - - - - - - - - 50 - false - - - - Nouvau nom : - - - - - - - - 50 - false - - - - Partie a renommée : - - - - - - - false - - - - 75 - true - true - - - - - - - - - - - - - 10 - 80 - 491 - 61 - - - - - + + + + + 3 + + + - 130 - 16777215 + 90 + 1977 - - - 50 - false - - - Département/Animation : + Code analytique : - - - - Animation territoriale - - - - - + + - - + + + + + + 0 + 0 + + + + + 75 + true + + + + Tester mon éligibilite : + + + Qt::AlignCenter + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Compte + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Couche + + + + + + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Les changement : + + + Qt::AlignCenter + + + + + + + + + 50 + false + + + + Nouvau nom : + + + + + + + + 50 + false + + + + Partie a renommée : + + + + + + + false + + + + 75 + true + true + + + + + + + + + + + + + + + + 130 + 16777215 + + + + + 50 + false + + + + Département/Animation : + + + + + + + Animation territoriale + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 16777215 + 30 + + + + + 14 + 75 + true + + + + Renommée de table + + + Qt::AlignCenter + + + + diff --git a/plugins.xml b/plugins.xml index 5531c6d4..2289b9b3 100644 --- a/plugins.xml +++ b/plugins.xml @@ -85,9 +85,9 @@ cenra,metabase - + - 1.1 + 1.2 3.16 https://plateformesig.cenra-outils.org/ CenRa_AUTOMAP.zip @@ -96,7 +96,7 @@ https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS/releases/download/latest/CenRa_AUTOMAP.zip CEN-Rhone-Alpes 2024-09-25 - 2025-01-28 + 2025-02-25 False False cenra,mise en page,atlas