From 66b0653ba505661bf6ce28647b4607c44659f6b0 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 11 Nov 2022 10:02:50 +0100 Subject: [PATCH 1/3] test and testfiles --- tests/test_projecttopping.py | 136 ++++++++ ...belasteterstandort_punkt_default_style.qml | 327 +++++++++++++++++ ..._belasteterstandort_punkt_french_style.qml | 327 +++++++++++++++++ ...4_belasteterstandort_punkt_robot_style.qml | 330 ++++++++++++++++++ ...jecttopping_multistyles_KbS_LV95_V1_4.yaml | 11 + 5 files changed, 1131 insertions(+) create mode 100644 tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml create mode 100644 tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml create mode 100644 tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml create mode 100644 tests/testdata/ilirepo/usabilityhub/projecttopping/opengis_projecttopping_multistyles_KbS_LV95_V1_4.yaml diff --git a/tests/test_projecttopping.py b/tests/test_projecttopping.py index f475433..1af49f0 100644 --- a/tests/test_projecttopping.py +++ b/tests/test_projecttopping.py @@ -386,6 +386,142 @@ def test_kbs_postgis_qml_styles(self): # check if the layers have been considered assert count == 2 + def test_kbs_postgis_qml_multistyles(self): + """ + Checks if "styles" and their qml style files can be applied by the layer tree + """ + + importer = iliimporter.Importer() + importer.tool = DbIliMode.ili2pg + importer.configuration = iliimporter_config( + importer.tool, self.toppings_test_path + ) + importer.configuration.ilimodels = "KbS_LV95_V1_4" + importer.configuration.dbschema = "toppings_{:%Y%m%d%H%M%S%f}".format( + datetime.datetime.now() + ) + importer.configuration.srs_code = "2056" + importer.configuration.tomlfile = os.path.join( + self.toppings_test_path, "metaattributes/sh_KbS_LV95_V1_4.toml" + ) + importer.stdout.connect(self.print_info) + importer.stderr.connect(self.print_error) + assert importer.run() == iliimporter.Importer.SUCCESS + + generator = Generator( + DbIliMode.ili2pg, + get_pg_connection_string(), + "smart2", + importer.configuration.dbschema, + ) + available_layers = generator.layers() + + assert len(available_layers) == 16 + + # load the projecttopping file + projecttopping_file_path = os.path.join( + self.toppings_test_path, + "projecttopping/opengis_projecttopping_multistyles_KbS_LV95_V1_4.yaml", + ) + + with open(projecttopping_file_path, "r") as yamlfile: + projecttopping_data = yaml.safe_load(yamlfile) + assert "layertree" in projecttopping_data + legend = generator.legend( + available_layers, + layertree_structure=projecttopping_data["layertree"], + path_resolver=lambda path: os.path.join( + os.path.dirname(projecttopping_file_path), path + ) + if path + else None, + ) + + # No layers added now - stays 16 + assert len(available_layers) == 16 + + relations, _ = generator.relations(available_layers) + + project = Project() + project.layers = available_layers + project.legend = legend + project.relations = relations + project.post_generate() + + qgis_project = QgsProject.instance() + project.create(None, qgis_project) + count = 0 + + for layer in available_layers: + if ( + layer.name == "belasteter_standort" + and layer.geometry_column == "geo_lage_punkt" + ): + count += 1 + style_manager = layer.layer.styleManager() + + # default style + edit_form_config = layer.layer.editFormConfig() + assert edit_form_config.layout() == QgsEditFormConfig.TabLayout + tabs = edit_form_config.tabs() + assert len(tabs) == 5 + assert tabs[0].name() == "Allgemein" + for field in layer.layer.fields(): + if field.name() == "bemerkung_rm": + assert field.alias() == "Bemerkung Romanisch" + if field.name() == "bemerkung_it": + assert field.alias() == "Bemerkung Italienisch" + assert ( + layer.layer.displayExpression() + == "'Default: '||standorttyp ||' - '||katasternummer" + ) + + # robot style (in binary) + style_manager.setCurrentStyle("robot") + edit_form_config = layer.layer.editFormConfig() + assert edit_form_config.layout() == QgsEditFormConfig.TabLayout + tabs = edit_form_config.tabs() + assert len(tabs) == 5 + assert ( + tabs[0].name() + == "01000111 01100101 01101110 01100101 01110010 01100001 01101100" + ) + for field in layer.layer.fields(): + if field.name() == "bemerkung_rm": + assert ( + field.alias() + == "01100010 01100101 01101101 01100101 01110010 01101011 01110101 01101110 01100111 01011111 01110010 01101101" + ) + if field.name() == "bemerkung_it": + assert ( + field.alias() + == "01100010 01100101 01101101 01100101 01110010 01101011 01110101 01101110 01100111 01011111 01101001 01110100" + ) + assert ( + layer.layer.displayExpression() + == "'Robot: '||standorttyp ||' - '||katasternummer" + ) + + # french style (in french) + style_manager.setCurrentStyle("french") + edit_form_config = layer.layer.editFormConfig() + assert edit_form_config.layout() == QgsEditFormConfig.TabLayout + tabs = edit_form_config.tabs() + assert len(tabs) == 5 + assert tabs[0].name() == "Général" + for field in layer.layer.fields(): + if field.name() == "bemerkung_rm": + assert field.alias() == "Remarque en Romane" + if field.name() == "bemerkung_it": + assert field.alias() == "Remarque en Italien" + assert ( + layer.layer.displayExpression() + == "'French: '||standorttyp ||' - '||katasternummer" + ) + + # check if the layers have been considered + assert count == 1 + def test_kbs_postgis_iliname(self): """ Checks if layers can be loaded by it's iliname and geometry column. diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml new file mode 100644 index 0000000..270bb22 --- /dev/null +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml @@ -0,0 +1,327 @@ + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + tablayout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'Default: '||standorttyp ||' - '||katasternummer + 0 + diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml new file mode 100644 index 0000000..18f236e --- /dev/null +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml @@ -0,0 +1,327 @@ + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + tablayout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'French: '||standorttyp ||' - '||katasternummer + 0 + diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml new file mode 100644 index 0000000..590bdf0 --- /dev/null +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml @@ -0,0 +1,330 @@ + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + tablayout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'Robot: '||standorttyp ||' - '||katasternummer + 0 + diff --git a/tests/testdata/ilirepo/usabilityhub/projecttopping/opengis_projecttopping_multistyles_KbS_LV95_V1_4.yaml b/tests/testdata/ilirepo/usabilityhub/projecttopping/opengis_projecttopping_multistyles_KbS_LV95_V1_4.yaml new file mode 100644 index 0000000..b5d34b6 --- /dev/null +++ b/tests/testdata/ilirepo/usabilityhub/projecttopping/opengis_projecttopping_multistyles_KbS_LV95_V1_4.yaml @@ -0,0 +1,11 @@ +layertree: + - "KbS_LV95_V1_4 Layers": + group: true + child-nodes: + - "Belasteter_Standort (Geo_Lage_Punkt)": + qmlstylefile: "../layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml" + styles: + robot: + qmlstylefile: "../layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml" + french: + qmlstylefile: "../layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml" From 8afad48959f75213183185add1adcaac33ddc2ef Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 11 Nov 2022 15:46:33 +0100 Subject: [PATCH 2/3] import styles from projecttopping --- modelbaker/dataobjects/layers.py | 17 ++++++++++++++++- modelbaker/dataobjects/project.py | 2 +- modelbaker/generator/generator.py | 10 ++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/modelbaker/dataobjects/layers.py b/modelbaker/dataobjects/layers.py index 5d7785d..2def34d 100644 --- a/modelbaker/dataobjects/layers.py +++ b/modelbaker/dataobjects/layers.py @@ -57,6 +57,7 @@ def __init__( ili_name=None, definitionfile=None, qmlstylefile=None, + styles={}, ): self.provider = provider self.uri = uri @@ -101,6 +102,7 @@ def __init__( self.definitionfile = definitionfile self.qmlstylefile = qmlstylefile + self.styles = styles self.__form = Form() @@ -124,6 +126,7 @@ def dump(self): definition["ili_name"] = self.ili_name definition["definitionfile"] = self.definitionfile definition["qmlstylefile"] = self.qmlstylefile + definition["styles"] = self.styles definition["form"] = self.__form.dump() return definition @@ -141,6 +144,7 @@ def load(self, definition): self.ili_name = definition["ili_name"] self.definitionfile = definition["definitionfile"] self.qmlstylefile = definition["qmlstylefile"] + self.styles = definition["styles"] self.__form.load(definition["form"]) def create(self): @@ -197,9 +201,20 @@ def create_form(self, project): edit_form = self.__form.create(self, self.__layer, project) self.__layer.setEditFormConfig(edit_form) - def load_style(self): + def load_styles(self): if self.qmlstylefile: self.__layer.loadNamedStyle(self.qmlstylefile) + if self.styles: + for style_name in self.styles.keys(): + # add the new style (because otherwise we overwrite the previous one) + self.__layer.styleManager().addStyleFromLayer(style_name) + self.__layer.styleManager().setCurrentStyle(style_name) + style_properties = self.styles[style_name] + style_qmlstylefile = style_properties.get("qmlstylefile") + if style_qmlstylefile: + self.__layer.loadNamedStyle(style_qmlstylefile) + # set the default style + self.__layer.styleManager().setCurrentStyle("default") def _create_layer(self, uri, layer_name, provider): if provider and provider.lower() == "wms": diff --git a/modelbaker/dataobjects/project.py b/modelbaker/dataobjects/project.py index 6109316..780fc10 100644 --- a/modelbaker/dataobjects/project.py +++ b/modelbaker/dataobjects/project.py @@ -221,7 +221,7 @@ def create( if layer.layer.type() == QgsMapLayer.VectorLayer: # even when a style will be loaded we create the form because not sure if the style contains form settngs layer.create_form(self) - layer.load_style() + layer.load_styles() if self.legend: self.legend.create(qgis_project, group) diff --git a/modelbaker/generator/generator.py b/modelbaker/generator/generator.py index 57df36f..ee3f364 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -549,6 +549,16 @@ def full_node(self, layers, item, path_resolver=lambda path: path): current_node.qmlstylefile = path_resolver( item_properties.get("qmlstylefile") ) + styles = {} + if "styles" in item_properties: + for style_name in item_properties["styles"].keys(): + style_properties = item_properties["styles"][style_name] + style_qmlstylefile = path_resolver( + style_properties.get("qmlstylefile") + ) + styles[style_name] = {"qmlstylefile": style_qmlstylefile} + current_node.styles = styles + return current_node def legend( From b52ecab49fc8ec53970063f240a981f45fc9c547 Mon Sep 17 00:00:00 2001 From: signedav Date: Fri, 11 Nov 2022 15:46:45 +0100 Subject: [PATCH 3/3] teststyle files --- ...belasteterstandort_punkt_default_style.qml | 245 +++++++++++------ ..._belasteterstandort_punkt_french_style.qml | 260 ++++++++++++------ ...4_belasteterstandort_punkt_robot_style.qml | 249 +++++++++++------ 3 files changed, 517 insertions(+), 237 deletions(-) diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml index 270bb22..2f1a190 100644 --- a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_default_style.qml @@ -1,5 +1,5 @@ - + 1 1 @@ -7,173 +7,173 @@ 0 - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 @@ -205,7 +294,7 @@ def my_form_open(dialog, layer, feature): 0 tablayout - + @@ -225,56 +314,56 @@ def my_form_open(dialog, layer, feature): - - + + - - - + + - - - + + - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml index 18f236e..916d753 100644 --- a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_french_style.qml @@ -1,5 +1,5 @@ - + 1 1 @@ -7,173 +7,186 @@ 0 - + - + - + - + - + - + - + - - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 @@ -205,7 +307,7 @@ def my_form_open(dialog, layer, feature): 0 tablayout - + @@ -225,56 +327,56 @@ def my_form_open(dialog, layer, feature): - - + + - - - + + - - - + + - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml index 590bdf0..36f6020 100644 --- a/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml +++ b/tests/testdata/ilirepo/usabilityhub/layerstyle/opengisch_KbS_LV95_V1_4_004_belasteterstandort_punkt_robot_style.qml @@ -1,5 +1,5 @@ - + 1 1 @@ -7,176 +7,176 @@ 0 - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 @@ -208,7 +297,7 @@ def my_form_open(dialog, layer, feature): 0 tablayout - + @@ -228,56 +317,56 @@ def my_form_open(dialog, layer, feature): - - + + - - - + + - - - + + - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + +