Skip to content

Commit

Permalink
Merge pull request #12 from opengisch/transactionmode
Browse files Browse the repository at this point in the history
Get TransactionMode and write to topic
  • Loading branch information
signedav authored Dec 4, 2023
2 parents bb3d7e0 + ed2fd1c commit 15eee63
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 18 deletions.
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
28 changes: 23 additions & 5 deletions tests/test_toppingmaker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand All @@ -25,6 +24,7 @@

import yaml
from qgis.core import (
Qgis,
QgsExpressionContextUtils,
QgsMapThemeCollection,
QgsPrintLayout,
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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
# ---
Expand Down
1 change: 0 additions & 1 deletion toppingmaker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand Down
3 changes: 1 addition & 2 deletions toppingmaker/exportsettings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand All @@ -23,7 +22,7 @@
from qgis.core import QgsLayerTreeGroup, QgsLayerTreeLayer


class ExportSettings(object):
class ExportSettings:
"""
# Layertree:
Expand Down
28 changes: 24 additions & 4 deletions toppingmaker/projecttopping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."),
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions toppingmaker/target.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand All @@ -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.)
Expand Down
1 change: 0 additions & 1 deletion toppingmaker/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
-------------------
Expand Down

0 comments on commit 15eee63

Please sign in to comment.