Skip to content

Commit

Permalink
Get TransactionMode and write to topic
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Dec 1, 2023
1 parent bb3d7e0 commit 6830b50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_toppingmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
# ---
Expand Down
25 changes: 25 additions & 0 deletions toppingmaker/projecttopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."),
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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
Expand Down

0 comments on commit 6830b50

Please sign in to comment.