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 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 4beec2d..8327526 100644 --- a/tests/test_toppingmaker.py +++ b/tests/test_toppingmaker.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -25,6 +24,7 @@ import yaml from qgis.core import ( + Qgis, QgsExpressionContextUtils, QgsMapThemeCollection, QgsPrintLayout, @@ -204,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"] @@ -230,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"] @@ -396,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"] @@ -422,12 +422,24 @@ def test_generate_files(self): assert foundFirstVariable assert foundVariableWithStructure + # 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" + ) + # 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"] @@ -706,6 +718,12 @@ 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/__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 1566e43..1eae40c 100644 --- a/toppingmaker/projecttopping.py +++ b/toppingmaker/projecttopping.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ /*************************************************************************** ------------------- @@ -50,6 +49,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. @@ -62,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. @@ -105,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. """ @@ -428,6 +428,19 @@ 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() + if Qgis.QGIS_VERSION_INT < 32600: + self["transaction_mode"] = project.autoTransaction() + else: + self["transaction_mode"] = project.transactionMode().name + 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 +509,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 +542,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) self.stdout.emit( self.tr("QGIS project map themes parsed with export settings."), @@ -586,6 +602,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 +616,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 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 -*- """ /*************************************************************************** -------------------