Téléverser les fichiers vers "CenRa_AUTOMAP"
This commit is contained in:
parent
bace581f5c
commit
055b9cc69d
1
CenRa_AUTOMAP/README.md
Normal file
1
CenRa_AUTOMAP/README.md
Normal file
@ -0,0 +1 @@
|
||||
# CenRa_AutoMap
|
||||
559
CenRa_AUTOMAP/editor.py
Normal file
559
CenRa_AUTOMAP/editor.py
Normal file
@ -0,0 +1,559 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
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 *
|
||||
from qgis.core import (
|
||||
NULL,
|
||||
QgsApplication,
|
||||
QgsDataSourceUri,
|
||||
QgsProject,
|
||||
QgsProviderConnectionException,
|
||||
QgsProviderRegistry,
|
||||
QgsRasterLayer,
|
||||
QgsSettings,
|
||||
QgsVectorLayer,
|
||||
QgsGeometry,
|
||||
QgsPrintLayout,
|
||||
QgsReadWriteContext,
|
||||
QgsLayoutItemMap,
|
||||
QgsLayoutItemPage,
|
||||
QgsLayoutSize,
|
||||
QgsUnitTypes,
|
||||
QgsLayoutPoint,
|
||||
QgsLayoutItemLabel,
|
||||
QgsLayoutItemPicture,
|
||||
QgsLayoutItemLegend,
|
||||
QgsLegendStyle,
|
||||
QgsLayoutItemScaleBar,
|
||||
QgsLayerTreeGroup,
|
||||
QgsCoordinateReferenceSystem,
|
||||
QgsCoordinateTransform,
|
||||
QgsLayerTree,
|
||||
)
|
||||
|
||||
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 (
|
||||
QDialog,
|
||||
QAction,
|
||||
QDockWidget,
|
||||
QFileDialog,
|
||||
QInputDialog,
|
||||
QMenu,
|
||||
QToolButton,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
)
|
||||
from qgis.PyQt.QtXml import QDomDocument
|
||||
from qgis.utils import iface
|
||||
import glob
|
||||
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_AutoMap_base.ui')
|
||||
LOGGER = logging.getLogger('CenRa_AutoMap')
|
||||
|
||||
class AutoMap_Editor(QDialog, EDITOR_CLASS):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
_ = parent
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.settings = QgsSettings()
|
||||
|
||||
path = ''
|
||||
ix = 0
|
||||
plugin_dir = str(os.path.dirname(os.path.abspath(__file__))).split(os.sep)
|
||||
for i in plugin_dir[1:]:
|
||||
ix = ix+1
|
||||
path = path+'/'+i
|
||||
self.tabWidget.setStyleSheet('background-image: url('+path+'/tools/bg/Capture.png);')
|
||||
|
||||
self.commandLinkButton.clicked.connect(self.chargement_qpt)
|
||||
|
||||
## On ajoute le nom des templates à la liste déroulante de l'onglet "mises en page" :
|
||||
mises_en_page = []
|
||||
|
||||
for filename in glob.glob(resources_path("mises_en_pages","*.qpt")):
|
||||
mises_en_page.append(filename)
|
||||
|
||||
|
||||
for i, filename in enumerate(mises_en_page):
|
||||
nom_fichier = os.path.basename(filename)
|
||||
self.comboBox.addItem(nom_fichier)
|
||||
self.comboBox.setCurrentIndex(1)
|
||||
|
||||
self.template_parameters = {
|
||||
'map_size': None,
|
||||
'map_position' : None,
|
||||
'title_position': None,
|
||||
'title_size': None,
|
||||
'subtitle_position': None,
|
||||
'subtitle_size': None,
|
||||
'logo_position': None,
|
||||
'logo_size': None,
|
||||
'legend_position': None,
|
||||
'legend_size': None,
|
||||
'scalebarnumeric_position':None,
|
||||
'scalebarnumeric_size':None,
|
||||
'scalebar_position': None,
|
||||
'scalebar_size': None,
|
||||
'north_position': None,
|
||||
'north_size': None,
|
||||
'credit_text_position': None,
|
||||
'credit_text_size': None,
|
||||
'credit_text2_position': None,
|
||||
'credit_text2_size': None,
|
||||
# Add more variables as needed
|
||||
}
|
||||
def raise_(self):
|
||||
self.mComboBox_2.clear()
|
||||
|
||||
couches = []
|
||||
for lyr in QgsProject.instance().mapLayers().values():
|
||||
couches.append(lyr.name())
|
||||
|
||||
self.mComboBox_2.addItems(sorted(couches))
|
||||
|
||||
def chargement_qpt(self):
|
||||
|
||||
|
||||
project = QgsProject.instance()
|
||||
self.manager = project.layoutManager()
|
||||
layout_name = self.lineEdit_2.text()
|
||||
layouts_list = self.manager.printLayouts()
|
||||
|
||||
for filename in glob.glob(resources_path("mises_en_pages","*.qpt")):
|
||||
with open(os.path.join(os.getcwd(), filename), 'r') as f:
|
||||
self.layout = QgsPrintLayout(project)
|
||||
self.layout.initializeDefaults()
|
||||
template_content = f.read()
|
||||
doc = QDomDocument()
|
||||
doc.setContent(template_content)
|
||||
self.layout.loadFromTemplate(doc, QgsReadWriteContext(), True)
|
||||
self.layout.setName(self.lineEdit_2.text())
|
||||
|
||||
if os.path.basename(filename) == "1. Modèle carto standard (consolidé).qpt":
|
||||
|
||||
self.actualisation_mise_en_page()
|
||||
|
||||
## Add map to layout
|
||||
self.map_modele_test = QgsLayoutItemMap(self.layout)
|
||||
# Charger une carte vide
|
||||
self.map_modele_test.setRect(20, 20, 20, 20)
|
||||
# Mettre le canvas courant comme emprise
|
||||
self.map_modele_test.setExtent(iface.mapCanvas().extent())
|
||||
# Position de la carte dans le composeur
|
||||
|
||||
self.map_modele_test.attemptMove(self.template_parameters['map_position'])
|
||||
# on dimensionne le rendu de la carte (pour référence la page totale est une page A4 donc 297*210)
|
||||
self.map_modele_test.attemptResize(self.template_parameters['map_size'])
|
||||
self.map_modele_test.refresh()
|
||||
self.map_modele_test.setKeepLayerSet(True)
|
||||
self.map_modele_test.setKeepLayerStyles(True)
|
||||
|
||||
self.map_modele_test.setBackgroundColor(QColor(255, 255, 255, 255))
|
||||
self.map_modele_test.setFrameEnabled(True)
|
||||
self.layout.addLayoutItem(self.map_modele_test)
|
||||
self.map_modele_test.setId("carte_principale")
|
||||
|
||||
## Ajout d'un titre à la mise en page
|
||||
title = QgsLayoutItemLabel(self.layout)
|
||||
self.layout.addLayoutItem(title)
|
||||
titre = self.lineEdit_2.text()
|
||||
title.setText(titre)
|
||||
title.setFont(QFont("Calibri", 15, QFont.Bold))
|
||||
title.attemptMove(self.template_parameters['title_position'])
|
||||
title.attemptResize(self.template_parameters['title_size'])
|
||||
self.layout.addItem(title)
|
||||
# title.adjustSizeToText() on n'utilise plutot setFixedSize pour pouvoir centrer le titre de manière plus optimale ici
|
||||
title.setHAlign(Qt.AlignHCenter)
|
||||
title.setVAlign(Qt.AlignVCenter)
|
||||
|
||||
|
||||
## Ajout d'un sous titre à la mise en page
|
||||
subtitle = QgsLayoutItemLabel(self.layout)
|
||||
self.layout.addLayoutItem(subtitle)
|
||||
titre = self.lineEdit_3.text()
|
||||
subtitle.setText(titre)
|
||||
subtitle.setFont(QFont("MS Shell Dlg 2", 10))
|
||||
subtitle.attemptMove(self.template_parameters['subtitle_position'])
|
||||
subtitle.attemptResize(self.template_parameters['subtitle_size'])
|
||||
self.layout.addItem(subtitle)
|
||||
subtitle.setHAlign(Qt.AlignHCenter)
|
||||
subtitle.setVAlign(Qt.AlignVCenter)
|
||||
|
||||
|
||||
## Ajout du logo CEN NA en haut à gauche de la page
|
||||
logo = QgsLayoutItemPicture(self.layout)
|
||||
logo.setResizeMode(QgsLayoutItemPicture.Zoom)
|
||||
logo.setMode(QgsLayoutItemPicture.FormatRaster)
|
||||
logo.attemptMove(self.template_parameters['logo_position'])
|
||||
logo.setFixedSize(self.template_parameters['logo_size'])
|
||||
logo.setPicturePath(resources_path("icons","CEN_RA.png"))
|
||||
self.layout.addLayoutItem(logo)
|
||||
|
||||
|
||||
## Ajout de la legende :
|
||||
legend = QgsLayoutItemLegend(self.layout)
|
||||
|
||||
legend.setId('legende_model1')
|
||||
# legend.setTitle('Legende')
|
||||
legend.adjustBoxSize()
|
||||
legend.setFrameEnabled(False)
|
||||
legend.setAutoUpdateModel(False)
|
||||
|
||||
legend.setLinkedMap(self.map_modele_test)
|
||||
self.layout.addItem(legend)
|
||||
|
||||
# group_name = 'Périmètres écologiques' # Name of a group in your legend
|
||||
|
||||
checked_items = self.mComboBox_2.checkedItems()
|
||||
|
||||
layers_to_remove = []
|
||||
|
||||
for lyr in project.mapLayers().values():
|
||||
if lyr.name() not in checked_items:
|
||||
layers_to_remove.append(lyr.name())
|
||||
|
||||
# the layer tree
|
||||
root = project.layerTreeRoot()
|
||||
|
||||
# get legend
|
||||
legend = [i for i in self.layout.items() if isinstance(i, QgsLayoutItemLegend)][0]
|
||||
|
||||
# disable auto-update
|
||||
legend.setAutoUpdateModel(False)
|
||||
legend.setLegendFilterByMapEnabled(True)
|
||||
# legend model
|
||||
model = legend.model()
|
||||
|
||||
# the root legend group
|
||||
root_group = model.rootGroup()
|
||||
|
||||
# loop through layer names
|
||||
for layer_name in layers_to_remove:
|
||||
# find layer in project
|
||||
layer = project.mapLayersByName(layer_name)[0]
|
||||
# get layer tree layer instance of layer
|
||||
layertreelayer = root.findLayer(layer.id())
|
||||
|
||||
# get the parent of the layer tree layer (layer tree root, or group)
|
||||
parent = layertreelayer.parent()
|
||||
|
||||
# if the parent is a group and has a name, find it and remove the layer
|
||||
if isinstance(parent, QgsLayerTreeGroup) and parent.name():
|
||||
group = root_group.findGroup(parent.name())
|
||||
group.removeLayer(layer)
|
||||
# remove layers that are not in a group
|
||||
else:
|
||||
root_group.removeLayer(layer)
|
||||
|
||||
|
||||
legend.setEqualColumnWidth(True)
|
||||
legend.setSplitLayer(True)
|
||||
legend.setColumnSpace(5)
|
||||
legend.rstyle(QgsLegendStyle.Title).setMargin(1.5) # 1 mm
|
||||
legend.rstyle(QgsLegendStyle.Group).setMargin(QgsLegendStyle.Top, 3)
|
||||
legend.rstyle(QgsLegendStyle.Subgroup).setMargin(QgsLegendStyle.Top, 3)
|
||||
|
||||
legend.adjustBoxSize()
|
||||
self.layout.refresh()
|
||||
|
||||
legend.updateLegend()
|
||||
legend.attemptMove(self.template_parameters['legend_position'])
|
||||
|
||||
|
||||
## Ajout de l'échelle numeric à la mise en page
|
||||
self.scalebarnumeric_qpt = QgsLayoutItemScaleBar(self.layout)
|
||||
self.scalebarnumeric_qpt.setStyle('Numeric')
|
||||
self.scalebarnumeric_qpt.setLinkedMap(self.map_modele_test)
|
||||
self.scalebarnumeric_qpt.applyDefaultSize()
|
||||
# self.scalebarnumeric_qpt.applyDefaultSettings()
|
||||
|
||||
self.scalebarnumeric_qpt.setNumberOfSegments(2)
|
||||
self.scalebarnumeric_qpt.setNumberOfSegmentsLeft(0)
|
||||
|
||||
self.scalebarnumeric_qpt.attemptMove(self.template_parameters['scalebarnumeric_position'])
|
||||
self.scalebarnumeric_qpt.attemptResize(self.template_parameters['scalebarnumeric_size'])
|
||||
|
||||
self.layout.addLayoutItem(self.scalebarnumeric_qpt)
|
||||
|
||||
## Ajout de l'échelle à la mise en page
|
||||
self.scalebar_qpt = QgsLayoutItemScaleBar(self.layout)
|
||||
self.scalebar_qpt.setStyle('Single Box')
|
||||
self.scalebar_qpt.setLinkedMap(self.map_modele_test)
|
||||
self.scalebar_qpt.applyDefaultSize()
|
||||
self.scalebar_qpt.applyDefaultSettings()
|
||||
|
||||
self.scalebar_qpt.setNumberOfSegments(2)
|
||||
self.scalebar_qpt.setNumberOfSegmentsLeft(0)
|
||||
|
||||
self.scalebar_qpt.attemptMove(self.template_parameters['scalebar_position'])
|
||||
self.scalebar_qpt.attemptResize(self.template_parameters['scalebar_size'])
|
||||
|
||||
|
||||
self.layout.addLayoutItem(self.scalebar_qpt)
|
||||
# self.scalebar_qpt.setFixedSize(QgsLayoutSize(55, 15))
|
||||
|
||||
# ajout de la fleche du Nord
|
||||
north = QgsLayoutItemPicture(self.layout)
|
||||
north.setPicturePath(resources_path("mises_en_pages","NorthArrow_02.svg"))
|
||||
self.layout.addLayoutItem(north)
|
||||
north.attemptMove(self.template_parameters['north_position'])
|
||||
north.attemptResize(self.template_parameters['north_size'])
|
||||
|
||||
# ajout note info:
|
||||
info = ["Réalisation : " + "CEN Rhône-Alpes (" + date.today().strftime(
|
||||
"%d/%m/%Y") + ")"]
|
||||
info2 = ["Source : " + self.lineEdit_4.text()]
|
||||
credit_text = QgsLayoutItemLabel(self.layout)
|
||||
credit_text.setText(info[0])
|
||||
credit_text.setFont(QFont("Calibri", 9))
|
||||
credit_text.setHAlign(Qt.AlignRight)
|
||||
credit_text.setVAlign(Qt.AlignVCenter)
|
||||
credit_text.setItemRotation(-90)
|
||||
credit_text2 = QgsLayoutItemLabel(self.layout)
|
||||
credit_text2.setText(info2[0])
|
||||
credit_text2.setFont(QFont("Calibri", 9))
|
||||
credit_text2.setHAlign(Qt.AlignRight)
|
||||
credit_text2.setVAlign(Qt.AlignVCenter)
|
||||
credit_text.attemptMove(self.template_parameters['credit_text_position'])
|
||||
credit_text.attemptResize(self.template_parameters['credit_text_size'])
|
||||
credit_text2.attemptMove(self.template_parameters['credit_text2_position'])
|
||||
credit_text2.attemptResize(self.template_parameters['credit_text2_size'])
|
||||
self.layout.addLayoutItem(credit_text)
|
||||
self.layout.addLayoutItem(credit_text2)
|
||||
|
||||
# credit_text.attemptResize(QgsLayoutSize(95, 5, QgsUnitTypes.LayoutMillimeters))
|
||||
|
||||
self.bar_echelle_auto(iface.mapCanvas(), self.scalebar_qpt)
|
||||
|
||||
existing_layout = project.layoutManager().layoutByName(self.layout.name())
|
||||
if existing_layout:
|
||||
project.layoutManager().removeLayout(existing_layout)
|
||||
|
||||
result = project.layoutManager().addLayout(self.layout)
|
||||
|
||||
|
||||
|
||||
self.manager.addLayout(self.layout)
|
||||
fichier_mise_en_page = self.lineEdit_2.text()
|
||||
layout_modifie = QgsProject.instance().layoutManager().layoutByName(fichier_mise_en_page)
|
||||
iface.openLayoutDesigner(layout_modifie)
|
||||
|
||||
def actualisation_mise_en_page(self):
|
||||
|
||||
|
||||
if self.radioButton_6.isChecked() and self.radioButton_7.isChecked():
|
||||
|
||||
pc = self.layout.pageCollection()
|
||||
pc.pages()[0].setPageSize('A4', QgsLayoutItemPage.Portrait)
|
||||
|
||||
self.template_parameters['map_size'] = QgsLayoutSize(199, 175, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['map_position'] = QgsLayoutPoint(5, 25, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['title_size'] = QgsLayoutSize(200, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['title_position'] = QgsLayoutPoint(5, 2, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['subtitle_size'] = QgsLayoutSize(200, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['subtitle_position'] = QgsLayoutPoint(5, 12, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['logo_size'] = QgsLayoutSize(46, 16, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['logo_position'] = QgsLayoutPoint(5, 4, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['legend_size'] = QgsLayoutSize(405, 203, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['legend_position'] = QgsLayoutPoint(5, 205, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebarnumeric_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebarnumeric_position'] = QgsLayoutPoint(140, 228, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebar_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebar_position'] = QgsLayoutPoint(145, 215, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['north_size'] = QgsLayoutSize(12, 12, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['north_position'] = QgsLayoutPoint(193, 214, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text_position'] = QgsLayoutPoint(205, 125, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text2_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text2_position'] = QgsLayoutPoint(104, 201, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
|
||||
|
||||
if self.radioButton_6.isChecked() and self.radioButton_8.isChecked():
|
||||
|
||||
pc = self.layout.pageCollection()
|
||||
pc.pages()[0].setPageSize('A4', QgsLayoutItemPage.Landscape)
|
||||
|
||||
self.template_parameters['map_size'] = QgsLayoutSize(285, 145, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['map_position'] = QgsLayoutPoint(6, 23, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['title_size'] = QgsLayoutSize(286, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['title_position'] = QgsLayoutPoint(5, 2, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['subtitle_size'] = QgsLayoutSize(286, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['subtitle_position'] = QgsLayoutPoint(5, 10, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['logo_size'] = QgsLayoutSize(46, 16, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['logo_position'] = QgsLayoutPoint(5, 4, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['legend_size'] = QgsLayoutSize(405, 203, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['legend_position'] = QgsLayoutPoint(5, 168, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebarnumeric_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebarnumeric_position'] = QgsLayoutPoint(207, 193, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebar_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebar_position'] = QgsLayoutPoint(207, 180, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['north_size'] = QgsLayoutSize(8.4, 12.5, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['north_position'] = QgsLayoutPoint(273, 182, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text_position'] = QgsLayoutPoint(291.5, 123, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text2_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text2_position'] = QgsLayoutPoint(189, 168.5, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
|
||||
|
||||
if self.radioButton_5.isChecked() and self.radioButton_7.isChecked():
|
||||
|
||||
pc = self.layout.pageCollection()
|
||||
pc.pages()[0].setPageSize('A3', QgsLayoutItemPage.Portrait)
|
||||
|
||||
|
||||
self.template_parameters['map_size'] = QgsLayoutSize(285, 260, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['map_position'] = QgsLayoutPoint(6, 23, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['title_size'] = QgsLayoutSize(286, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['title_position'] = QgsLayoutPoint(5, 2, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['subtitle_size'] = QgsLayoutSize(286, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['subtitle_position'] = QgsLayoutPoint(5, 10, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['logo_size'] = QgsLayoutSize(46, 16, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['logo_position'] = QgsLayoutPoint(5, 4, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['legend_size'] = QgsLayoutSize(405, 203, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['legend_position'] = QgsLayoutPoint(5, 284, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebarnumeric_size'] = QgsLayoutSize(50, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebarnumeric_position'] = QgsLayoutPoint(207, 310, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebar_size'] = QgsLayoutSize(50, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebar_position'] = QgsLayoutPoint(207, 298, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['north_size'] = QgsLayoutSize(8.4, 12.5, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['north_position'] = QgsLayoutPoint(273, 297, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text_position'] = QgsLayoutPoint(291.5, 123, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text2_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text2_position'] = QgsLayoutPoint(189, 284, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
|
||||
|
||||
if self.radioButton_5.isChecked() and self.radioButton_8.isChecked():
|
||||
|
||||
pc = self.layout.pageCollection()
|
||||
pc.pages()[0].setPageSize('A3', QgsLayoutItemPage.Landscape)
|
||||
|
||||
self.template_parameters['map_size'] = QgsLayoutSize(408.5, 222, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['map_position'] = QgsLayoutPoint(5, 23.5, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['title_size'] = QgsLayoutSize(409, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['title_position'] = QgsLayoutPoint(5, 2, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['subtitle_size'] = QgsLayoutSize(409, 8, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['subtitle_position'] = QgsLayoutPoint(5, 10, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['logo_size'] = QgsLayoutSize(46, 16, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['logo_position'] = QgsLayoutPoint(5, 4, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['legend_size'] = QgsLayoutSize(405, 203, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['legend_position'] = QgsLayoutPoint(5, 249, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebarnumeric_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebarnumeric_position'] = QgsLayoutPoint(323, 282, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['scalebar_size'] = QgsLayoutSize(55, 15, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['scalebar_position'] = QgsLayoutPoint(323, 270, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['north_size'] = QgsLayoutSize(8.4, 12.5, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['north_position'] = QgsLayoutPoint(402, 270, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text_position'] = QgsLayoutPoint(415, 123, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
self.template_parameters['credit_text2_size'] = QgsLayoutSize(100, 3.9, QgsUnitTypes.LayoutMillimeters)
|
||||
self.template_parameters['credit_text2_position'] = QgsLayoutPoint(313, 247, QgsUnitTypes.LayoutMillimeters)
|
||||
|
||||
def bar_echelle_auto(self, echelle, bar_echelle):
|
||||
|
||||
if echelle.scale() >= 45000:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
bar_echelle.setUnitLabel("km")
|
||||
bar_echelle.setUnitsPerSegment(1.5)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
# self.scalebar_test.setUnitLabel("km")
|
||||
# self.scalebar_test.setUnitsPerSegment(1.5)
|
||||
|
||||
elif echelle.scale() >= 30000:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
bar_echelle.setUnitLabel("km")
|
||||
bar_echelle.setUnitsPerSegment(1)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
# self.scalebar_test.setUnitLabel("km")
|
||||
# self.scalebar_test.setUnitsPerSegment(1)
|
||||
|
||||
elif echelle.scale() >= 20000:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
bar_echelle.setUnitLabel("km")
|
||||
bar_echelle.setUnitsPerSegment(0.5)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceKilometers)
|
||||
# self.scalebar_test.setUnitLabel("km")
|
||||
# self.scalebar_test.setUnitsPerSegment(0.5)
|
||||
|
||||
elif echelle.scale() >= 9000:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
bar_echelle.setUnitLabel("m")
|
||||
bar_echelle.setUnitsPerSegment(250)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
# self.scalebar_test.setUnitLabel("m")
|
||||
# self.scalebar_test.setUnitsPerSegment(250)
|
||||
|
||||
elif echelle.scale() >= 5000:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
bar_echelle.setUnitLabel("m")
|
||||
bar_echelle.setUnitsPerSegment(100)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
# self.scalebar_test.setUnitLabel("m")
|
||||
# self.scalebar_test.setUnitsPerSegment(100)
|
||||
|
||||
else:
|
||||
bar_echelle.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
bar_echelle.setUnitLabel("m")
|
||||
bar_echelle.setUnitsPerSegment(50)
|
||||
# self.scalebar_test.setUnits(QgsUnitTypes.DistanceMeters)
|
||||
# self.scalebar_test.setUnitLabel("m")
|
||||
# self.scalebar_test.setUnitsPerSegment(50)
|
||||
|
||||
|
||||
bar_echelle.update()
|
||||
BIN
CenRa_AUTOMAP/icon.png
Normal file
BIN
CenRa_AUTOMAP/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
89
CenRa_AUTOMAP/issues.py
Normal file
89
CenRa_AUTOMAP/issues.py
Normal file
@ -0,0 +1,89 @@
|
||||
import os
|
||||
plugin_dir = os.path.dirname(__file__)
|
||||
end_find = plugin_dir.rfind('\\')+1
|
||||
|
||||
NAME = plugin_dir[end_find:]
|
||||
#print(NAME)
|
||||
|
||||
from qgis.gui import *
|
||||
|
||||
from qgis.core import (
|
||||
NULL,
|
||||
QgsApplication,
|
||||
QgsDataSourceUri,
|
||||
QgsProject,
|
||||
QgsProviderConnectionException,
|
||||
QgsProviderRegistry,
|
||||
QgsRasterLayer,
|
||||
QgsSettings,
|
||||
QgsVectorLayer,
|
||||
QgsGeometry,
|
||||
)
|
||||
from qgis.PyQt.QtWidgets import (
|
||||
QDialog,
|
||||
QAction,
|
||||
QDockWidget,
|
||||
QFileDialog,
|
||||
QInputDialog,
|
||||
QMenu,
|
||||
QToolButton,
|
||||
QTableWidget,
|
||||
QTableWidgetItem,
|
||||
)
|
||||
from qgis.utils import iface
|
||||
|
||||
|
||||
from .tools.resources import (
|
||||
load_ui,
|
||||
resources_path,
|
||||
send_issues,
|
||||
)
|
||||
|
||||
EDITOR_CLASS = load_ui('CenRa_IssuesSend.ui')
|
||||
|
||||
class CenRa_Issues(QDialog, EDITOR_CLASS):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
_ = parent
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.settings = QgsSettings()
|
||||
|
||||
#place connect here
|
||||
self.annuler_button.clicked.connect(self.close)
|
||||
self.ok_button.clicked.connect(self.run_sendissues)
|
||||
|
||||
def run_sendissues(self):
|
||||
text_titre = self.titre_line.text()
|
||||
text_message = self.messages_plain.toPlainText()
|
||||
statu_bug = self.check_bug.isChecked()
|
||||
statu_aide = self.check_aide.isChecked()
|
||||
statu_question = self.check_question.isChecked()
|
||||
statu_amelioration = self.check_amelioration.isChecked()
|
||||
statu_autre = self.check_autre.isChecked()
|
||||
|
||||
statu = []
|
||||
if statu_bug == True : statu = statu + [1]
|
||||
if statu_aide == True : statu = statu + [3]
|
||||
if statu_question == True : statu = statu + [5]
|
||||
if statu_amelioration == True : statu = statu + [2]
|
||||
if statu_autre == True : statu = statu + [6]
|
||||
|
||||
if len(statu) >= 1:
|
||||
import qgis
|
||||
url = qgis.utils.pluginMetadata(NAME,'tracker')
|
||||
print(text_message)
|
||||
send_info = send_issues(url,text_titre,text_message,statu)
|
||||
code = send_info.status_code
|
||||
print(code)
|
||||
else:
|
||||
code = 423
|
||||
if code == 201:
|
||||
iface.messageBar().pushMessage("Envoyer :", "Votre messages à bien été envoyer.", level=Qgis.Success, duration=20)
|
||||
self.close()
|
||||
elif code == 422:
|
||||
iface.messageBar().pushMessage("Erreur :", "Erreur dans le contenu du messages.", level=Qgis.Critical, duration=20)
|
||||
elif code == 423:
|
||||
iface.messageBar().pushMessage("Erreur :", "Pas de sujet sélectionné.", level=Qgis.Critical, duration=20)
|
||||
elif code == 404:
|
||||
iface.messageBar().pushMessage("Missing :", "Le serveur de messagerie est injoignable.", level=Qgis.Warning, duration=20)
|
||||
48
CenRa_AUTOMAP/metadata.txt
Normal file
48
CenRa_AUTOMAP/metadata.txt
Normal file
@ -0,0 +1,48 @@
|
||||
# This file contains metadata for your plugin.
|
||||
|
||||
# This file should be included when you package your plugin.# Mandatory items:
|
||||
|
||||
[general]
|
||||
name=CenRa_AutoMap
|
||||
qgisMinimumVersion=3.0
|
||||
description=CenRa_AutoMap
|
||||
version=1.0
|
||||
author=Conservatoire d'Espaces Naturels de Rhône-Alpes
|
||||
email=si_besoin@cen-rhonealpes.fr
|
||||
|
||||
about=Outils de création de mise en page prédéfinis pour simplifier et organiser cette étape.
|
||||
|
||||
repository=https://gitea.cenra-outils.org/CEN-RA/Plugin_QGIS
|
||||
homepage=https://plateformesig.cenra-outils.org/
|
||||
tracker=https://gitea.cenra-outils.org/api/v1/repos/CEN-RA/Plugin_QGIS/issues
|
||||
# End of mandatory metadata
|
||||
|
||||
# Recommended items:
|
||||
|
||||
hasProcessingProvider=no
|
||||
# Uncomment the following line and add your changelog:
|
||||
changelog=<h2>CenRa_AutoMap:</h2></br><p><h3>26/09/2024 - Version 1.0: </h3> - Lancement du plugin CenRa_AutoMap avec une seul mise en page. </p></br>
|
||||
|
||||
# Tags are comma separated with spaces allowed
|
||||
tags=python
|
||||
|
||||
|
||||
category=Plugins
|
||||
icon=icon.png
|
||||
# experimental flag
|
||||
experimental=False
|
||||
|
||||
# deprecated flag (applies to the whole plugin, not just a single version)
|
||||
deprecated=False
|
||||
|
||||
# Since QGIS 3.8, a comma separated list of plugins to be installed
|
||||
# (or upgraded) can be specified.
|
||||
# Check the documentation for more information.
|
||||
# plugin_dependencies=
|
||||
|
||||
Category of the plugin: Raster, Vector, Database or Web
|
||||
# category=cenra,mise en page,aide
|
||||
|
||||
# If the plugin can run on QGIS Server.
|
||||
server=False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user