From 5f0acdf5e0e4972de0c7ece07d2dbb3c51b62f8a Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 29 Nov 2023 13:23:31 +0100 Subject: [PATCH 1/3] check if the layer is a vectorlayer before getting the fields. This fixes #849 --- modelbaker/utils/qgis_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modelbaker/utils/qgis_utils.py b/modelbaker/utils/qgis_utils.py index 6a60990..9e473a3 100644 --- a/modelbaker/utils/qgis_utils.py +++ b/modelbaker/utils/qgis_utils.py @@ -159,6 +159,8 @@ def get_oid_settings(self): tree_layers = root.findLayers() for tree_layer in tree_layers: # get t_ili_tid field OID field + if tree_layer.layer().type() != QgsMapLayer.VectorLayer: + continue fields = tree_layer.layer().fields() field_idx = fields.lookupField("t_ili_tid") if field_idx < 0: From 65a74362652671e8c6e488d6d0f96275bc98117e Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 29 Nov 2023 13:37:08 +0100 Subject: [PATCH 2/3] introduce prefix qgis.modelbaker. to metaattributes --- modelbaker/generator/generator.py | 5 ++++- tests/test_projectgen.py | 3 +++ tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modelbaker/generator/generator.py b/modelbaker/generator/generator.py index 64dd60a..c4d47f6 100644 --- a/modelbaker/generator/generator.py +++ b/modelbaker/generator/generator.py @@ -233,7 +233,10 @@ def layers(self, filter_layer_list=[]): elif "ili_name" in record and record["ili_name"]: meta_attrs = self.get_meta_attrs(record["ili_name"]) for attr_record in meta_attrs: - if attr_record["attr_name"] == "dispExpression": + if attr_record["attr_name"] in [ + "dispExpression", + "qgis.modelbaker.dispExpression", + ]: display_expression = attr_record["attr_value"] coord_decimals = ( diff --git a/tests/test_projectgen.py b/tests/test_projectgen.py index 30b1f7b..20a76ef 100644 --- a/tests/test_projectgen.py +++ b/tests/test_projectgen.py @@ -1623,6 +1623,7 @@ def test_meta_attr_toml_postgis(self): assert layer.layer.displayExpression() == ( '"t_ili_tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"t_id"' ) + assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 assert layer.layer.displayExpression() == "type" @@ -1679,6 +1680,7 @@ def test_meta_attr_toml_mssql(self): assert layer.layer.displayExpression() == ( '"T_Ili_Tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"T_Id"' ) + assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 assert layer.layer.displayExpression() == "type" @@ -1837,6 +1839,7 @@ def test_meta_attr_toml_geopackage(self): assert layer.layer.displayExpression() == ( '"T_Ili_Tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"T_Id"' ) + assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 assert layer.layer.displayExpression() == "type" diff --git a/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili b/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili index 1087f25..f84efc8 100644 --- a/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili +++ b/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili @@ -50,6 +50,7 @@ VERSION "2017-02-08" = RestrictAxisLoad : 0 .. 1000 [Units.t]; END Obstacle; + !!@ qgis.modelbaker.dispExpression="type" CLASS Route = Identifier : MANDATORY TEXT*50; Canton : MANDATORY CHAdminCodes_V1.CHCantonCode; From ae3a878f3a3d82c22fdf481b2e3d6dae71f75dc8 Mon Sep 17 00:00:00 2001 From: signedav Date: Wed, 29 Nov 2023 14:21:56 +0100 Subject: [PATCH 3/3] fix tests --- tests/test_projectgen.py | 15 +++------------ .../ilimodels/ExceptionalLoadsRoute_V1.ili | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/test_projectgen.py b/tests/test_projectgen.py index 20a76ef..961fb87 100644 --- a/tests/test_projectgen.py +++ b/tests/test_projectgen.py @@ -1437,7 +1437,7 @@ def test_meta_attr_postgis(self): importer = iliimporter.Importer() importer.tool = DbIliMode.ili2pg importer.configuration = iliimporter_config(importer.tool, "ilimodels") - importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV95_V1" + importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV03_V1" importer.configuration.dbschema = "ciaf_ladm_{:%Y%m%d%H%M%S%f}".format( datetime.datetime.now() ) @@ -1482,7 +1482,7 @@ def test_meta_attr_geopackage(self): importer = iliimporter.Importer() importer.tool = DbIliMode.ili2gpkg importer.configuration = iliimporter_config(importer.tool, "ilimodels") - importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV95_V1" + importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV03_V1" importer.configuration.dbfile = os.path.join( self.basetestpath, @@ -1531,7 +1531,7 @@ def test_meta_attr_mssql(self): importer = iliimporter.Importer() importer.tool = DbIliMode.ili2mssql importer.configuration = iliimporter_config(importer.tool, "ilimodels") - importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV95_V1" + importer.configuration.ilimodels = "ExceptionalLoadsRoute_LV03_V1" importer.configuration.dbschema = "ciaf_ladm_{:%Y%m%d%H%M%S%f}".format( datetime.datetime.now() ) @@ -1620,9 +1620,6 @@ def test_meta_attr_toml_postgis(self): assert layer.layer.displayExpression() == "type" if layer.name == "route": count += 1 - assert layer.layer.displayExpression() == ( - '"t_ili_tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"t_id"' - ) assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 @@ -1677,9 +1674,6 @@ def test_meta_attr_toml_mssql(self): assert layer.layer.displayExpression() == "type" if layer.name == "route": count += 1 - assert layer.layer.displayExpression() == ( - '"T_Ili_Tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"T_Id"' - ) assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 @@ -1836,9 +1830,6 @@ def test_meta_attr_toml_geopackage(self): assert layer.layer.displayExpression() == "type" if layer.name == "route": count += 1 - assert layer.layer.displayExpression() == ( - '"T_Ili_Tid"' if Qgis.QGIS_VERSION_INT >= 31800 else '"T_Id"' - ) assert layer.layer.displayExpression() == "type" if layer.name == "obstacle": count += 1 diff --git a/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili b/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili index f84efc8..a98289a 100644 --- a/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili +++ b/tests/testdata/ilimodels/ExceptionalLoadsRoute_V1.ili @@ -50,7 +50,6 @@ VERSION "2017-02-08" = RestrictAxisLoad : 0 .. 1000 [Units.t]; END Obstacle; - !!@ qgis.modelbaker.dispExpression="type" CLASS Route = Identifier : MANDATORY TEXT*50; Canton : MANDATORY CHAdminCodes_V1.CHCantonCode; @@ -88,6 +87,7 @@ VERSION "2017-02-08" = RestrictAxisLoad : 0 .. 1000 [Units.t]; END Obstacle; + !!@ qgis.modelbaker.dispExpression="type" CLASS Route = Identifier : MANDATORY TEXT*50; Canton : MANDATORY CHAdminCodes_V1.CHCantonCode;