From 6830b5082abd0e7ba7224d8c4217096244a6707a Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 1 Dec 2023 12:53:05 +0100 Subject: [PATCH] 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