From 6830b5082abd0e7ba7224d8c4217096244a6707a Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 12:53:05 +0100 Subject: [PATCH 1/6] Get TransactionMode and write to topic --- tests/test_toppingmaker.py | 16 ++++++++++++++++ toppingmaker/projecttopping.py | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tests/test_toppingmaker.py b/tests/test_toppingmaker.py index 4beec2d..aea0d09 100644 --- a/tests/test_toppingmaker.py +++ b/tests/test_toppingmaker.py @@ -422,6 +422,15 @@ def test_generate_files(self): assert foundFirstVariable assert foundVariableWithStructure + # check transaction mode + with open(projecttopping_file_path, "r") as yamlfile: + projecttopping_data = yaml.safe_load(yamlfile) + assert "properties" in projecttopping_data + if Qgis.QGIS_VERSION_INT < 32600: + assert projecttopping_data["properties"]["transaction_mode"] == True + else: + assert projecttopping_data["properties"]["transaction_mode"] == "AutomaticGroups" + # check layouts layout_count = 0 foundLayoutOne = False @@ -706,6 +715,13 @@ def _make_project_and_export_settings(self): layout.setName("Layout Three") project.layoutManager().addLayout(layout) + # set transaction mode + if Qgis.QGIS_VERSION_INT < 32600: + project.setAutoTransaction(True) + else: + project.setTransactionMode(Qgis.TransactionMode.AutomaticGroups) + + # --- # and make the export settings # --- diff --git a/toppingmaker/projecttopping.py b/toppingmaker/projecttopping.py index 1566e43..e8bf59f 100644 --- a/toppingmaker/projecttopping.py +++ b/toppingmaker/projecttopping.py @@ -50,6 +50,7 @@ class ProjectTopping(QObject): - layerorder - map themes - project variables + - project properties - print layouts QML style files, QLR layer definition files and the source of a layer can be linked in the YAML file and are exported to the specific folders. @@ -428,6 +429,23 @@ def make_items( ).variable(variable_key) self[variable_key] = variable_value or None + class Properties(dict): + """ + A dict object of dict items describing a selection of projet properties + Currently we don't use export settings and export them per default. + """ + + def make_items( + self, + project: QgsProject + ): + self.clear() + transaction_mode = None + if Qgis.QGIS_VERSION_INT < 32600: + transaction_mode = project.autoTransaction() + else: + transaction_mode = project.transactionMode() + class Layouts(dict): """ A dict object of dict items describing a layout with templatefile according to the layout names listed in the ExportSettings passed on parsing the QGIS project. @@ -496,6 +514,7 @@ def __init__(self): self.mapthemes = self.MapThemes() self.layerorder = [] self.variables = self.Variables() + self.properties = self.Properties() self.layouts = self.Layouts(temporary_toppingfile_dir) def parse_project( @@ -528,6 +547,8 @@ def parse_project( self.variables.make_items(project, export_settings) # make print layouts self.layouts.make_items(project, export_settings) + # make properties + self.properties.make_items(project, export_settings) self.stdout.emit( self.tr("QGIS project map themes parsed with export settings."), @@ -586,6 +607,7 @@ def _projecttopping_dict(self, target: Target): Gets the layerorder as a list. Gets the mapthemes as a dict. Gets the variables as a dict. + Gets the properties as a dict. Gets the layouts as a dict. And it generates and stores the toppingfiles according th the Target. """ @@ -599,6 +621,9 @@ def _projecttopping_dict(self, target: Target): variables_dict = dict(self.variables) if variables_dict: projecttopping_dict["variables"] = variables_dict + properties_dict = dict(self.properties) + if properties_dict: + projecttopping_dict["properties"] = properties_dict layouts_item_dict = self.layouts.item_dict(target) if layouts_item_dict: projecttopping_dict["layouts"] = layouts_item_dict From a702ab484337c99a36112ed85e75a11be93ffff2 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 12:59:33 +0100 Subject: [PATCH 2/6] missing import --- tests/test_toppingmaker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_toppingmaker.py b/tests/test_toppingmaker.py index aea0d09..bbfa250 100644 --- a/tests/test_toppingmaker.py +++ b/tests/test_toppingmaker.py @@ -25,6 +25,7 @@ import yaml from qgis.core import ( + Qgis, QgsExpressionContextUtils, QgsMapThemeCollection, QgsPrintLayout, From 20d311496ba59f9d63db236511f5acc49e9b53e2 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 13:56:06 +0100 Subject: [PATCH 3/6] remove exportsettings from properties.make_item --- toppingmaker/projecttopping.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toppingmaker/projecttopping.py b/toppingmaker/projecttopping.py index e8bf59f..fbe7878 100644 --- a/toppingmaker/projecttopping.py +++ b/toppingmaker/projecttopping.py @@ -548,7 +548,7 @@ def parse_project( # make print layouts self.layouts.make_items(project, export_settings) # make properties - self.properties.make_items(project, export_settings) + self.properties.make_items(project) self.stdout.emit( self.tr("QGIS project map themes parsed with export settings."), From 1ed6943b0db1e6bc7d14fbda0863141e8a9f57f5 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 14:23:02 +0100 Subject: [PATCH 4/6] save transactionmode --- toppingmaker/projecttopping.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/toppingmaker/projecttopping.py b/toppingmaker/projecttopping.py index fbe7878..f72e840 100644 --- a/toppingmaker/projecttopping.py +++ b/toppingmaker/projecttopping.py @@ -440,11 +440,10 @@ def make_items( project: QgsProject ): self.clear() - transaction_mode = None if Qgis.QGIS_VERSION_INT < 32600: - transaction_mode = project.autoTransaction() + self["transaction_mode"] = project.autoTransaction() else: - transaction_mode = project.transactionMode() + self["transaction_mode"] = project.transactionMode().name class Layouts(dict): """ From a5b32d2eeceeec98bbf5306ea0738e5dc4cdc380 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 14:30:52 +0100 Subject: [PATCH 5/6] update pre commit versions --- .pre-commit-config.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c6eb536..429f540 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: # Sort imports - repo: https://github.com/pycqa/isort - rev: "5.7.0" + rev: "5.11.5" hooks: - id: isort args: @@ -35,3 +35,9 @@ repos: rev: 22.3.0 hooks: - id: black + + # Automatically upgrade syntax for newer versions + - repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade From ed2fd1c0d820072a1b9de384c81e9b80bf8816e1 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 14:35:16 +0100 Subject: [PATCH 6/6] style --- setup.py | 4 ++-- tests/test_toppingmaker.py | 25 +++++++++++++------------ toppingmaker/__init__.py | 1 - toppingmaker/exportsettings.py | 3 +-- toppingmaker/projecttopping.py | 14 +++++--------- toppingmaker/target.py | 3 +-- toppingmaker/utils.py | 1 - 7 files changed, 22 insertions(+), 29 deletions(-) diff --git a/setup.py b/setup.py index 123781a..d93e6ca 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ import setuptools -with open("README.md", "r", encoding="utf-8") as fh: +with open("README.md", encoding="utf-8") as fh: long_description = fh.read() -with open("VERSION", "r", encoding="utf-8") as fh: +with open("VERSION", encoding="utf-8") as fh: version = fh.read().strip() setuptools.setup( diff --git a/tests/test_toppingmaker.py b/tests/test_toppingmaker.py index bbfa250..8327526 100644 --- a/tests/test_toppingmaker.py +++ b/tests/test_toppingmaker.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -205,7 +204,7 @@ def test_generate_files(self): foundLayerOne = False foundLayerTwo = False - with open(projecttopping_file_path, "r") as yamlfile: + with open(projecttopping_file_path) as yamlfile: projecttopping_data = yaml.safe_load(yamlfile) assert "layertree" in projecttopping_data assert projecttopping_data["layertree"] @@ -231,7 +230,7 @@ def test_generate_files(self): foundFrenchTheme = False foundRobotTheme = False - with open(projecttopping_file_path, "r") as yamlfile: + with open(projecttopping_file_path) as yamlfile: projecttopping_data = yaml.safe_load(yamlfile) assert "mapthemes" in projecttopping_data assert projecttopping_data["mapthemes"] @@ -397,7 +396,7 @@ def test_generate_files(self): foundFirstVariable = False foundVariableWithStructure = False - with open(projecttopping_file_path, "r") as yamlfile: + with open(projecttopping_file_path) as yamlfile: projecttopping_data = yaml.safe_load(yamlfile) assert "variables" in projecttopping_data assert projecttopping_data["variables"] @@ -423,21 +422,24 @@ def test_generate_files(self): assert foundFirstVariable assert foundVariableWithStructure - # check transaction mode - with open(projecttopping_file_path, "r") as yamlfile: + # check transaction mode + with open(projecttopping_file_path) as yamlfile: projecttopping_data = yaml.safe_load(yamlfile) assert "properties" in projecttopping_data if Qgis.QGIS_VERSION_INT < 32600: assert projecttopping_data["properties"]["transaction_mode"] == True - else: - assert projecttopping_data["properties"]["transaction_mode"] == "AutomaticGroups" + else: + assert ( + projecttopping_data["properties"]["transaction_mode"] + == "AutomaticGroups" + ) # check layouts layout_count = 0 foundLayoutOne = False foundLayoutThree = False - with open(projecttopping_file_path, "r") as yamlfile: + with open(projecttopping_file_path) as yamlfile: projecttopping_data = yaml.safe_load(yamlfile) assert "layouts" in projecttopping_data assert projecttopping_data["layouts"] @@ -716,13 +718,12 @@ def _make_project_and_export_settings(self): layout.setName("Layout Three") project.layoutManager().addLayout(layout) - # set transaction mode + # set transaction mode if Qgis.QGIS_VERSION_INT < 32600: project.setAutoTransaction(True) - else: + else: project.setTransactionMode(Qgis.TransactionMode.AutomaticGroups) - # --- # and make the export settings # --- diff --git a/toppingmaker/__init__.py b/toppingmaker/__init__.py index 1c68e38..74755ea 100644 --- a/toppingmaker/__init__.py +++ b/toppingmaker/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- diff --git a/toppingmaker/exportsettings.py b/toppingmaker/exportsettings.py index 7e1d036..bff4966 100644 --- a/toppingmaker/exportsettings.py +++ b/toppingmaker/exportsettings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -23,7 +22,7 @@ from qgis.core import QgsLayerTreeGroup, QgsLayerTreeLayer -class ExportSettings(object): +class ExportSettings: """ # Layertree: diff --git a/toppingmaker/projecttopping.py b/toppingmaker/projecttopping.py index f72e840..1eae40c 100644 --- a/toppingmaker/projecttopping.py +++ b/toppingmaker/projecttopping.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -63,12 +62,12 @@ class ProjectTopping(QObject): LAYERSTYLE_TYPE = "layerstyle" LAYOUTTEMPLATE_TYPE = "layouttemplate" - class TreeItemProperties(object): + class TreeItemProperties: """ The properties of a node (tree item) """ - class StyleItemProperties(object): + class StyleItemProperties: """ The properties of a style item of a node style. Currently it's only a qmlstylefile. Maybe in future here a style can be defined. @@ -106,7 +105,7 @@ def __init__(self): # the styles can contain multiple style items with StyleItemProperties self.styles = {} - class LayerTreeItem(object): + class LayerTreeItem: """ A tree item of the layer tree. Every item contains the properties of a layer and according the ExportSettings passed on parsing the QGIS project. """ @@ -435,14 +434,11 @@ class Properties(dict): Currently we don't use export settings and export them per default. """ - def make_items( - self, - project: QgsProject - ): + def make_items(self, project: QgsProject): self.clear() if Qgis.QGIS_VERSION_INT < 32600: self["transaction_mode"] = project.autoTransaction() - else: + else: self["transaction_mode"] = project.transactionMode().name class Layouts(dict): diff --git a/toppingmaker/target.py b/toppingmaker/target.py index 413e4a9..7de5001 100644 --- a/toppingmaker/target.py +++ b/toppingmaker/target.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -23,7 +22,7 @@ from .utils import slugify -class Target(object): +class Target: """ The target defines where to store the topping files (YAML, style, definition etc.) diff --git a/toppingmaker/utils.py b/toppingmaker/utils.py index c95df12..2dfa12e 100644 --- a/toppingmaker/utils.py +++ b/toppingmaker/utils.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** -------------------