Skip to content

Commit

Permalink
fix test and replace setting of variable since the create function is…
Browse files Browse the repository at this point in the history
… used multiple times and the optimization strat is not always the same. so it's better to set it once in the end.
  • Loading branch information
signedav committed Oct 19, 2023
1 parent 4380aec commit f9a9509
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
24 changes: 13 additions & 11 deletions modelbaker/dataobjects/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def load(self, definition):
self.styles = definition["styles"]
self.__form.load(definition["form"])

def create(self, optimize_strategy=OptimizeStrategy.NONE):
def create(self):
if self.definitionfile:
if self.__layer is None:
layers = QgsLayerDefinition.loadLayerDefinitionLayers(
Expand Down Expand Up @@ -191,16 +191,6 @@ def create(self, optimize_strategy=OptimizeStrategy.NONE):
)
self.__layer.geometryOptions().setRemoveDuplicateNodes(True)

# set the layer variable according to the strategy
interlis_topics = ",".join(
self.all_topics
if optimize_strategy == OptimizeStrategy.NONE
else self.relevant_topics
)
QgsExpressionContextUtils.setLayerVariable(
self.__layer, "interlis_topic", interlis_topics
)

for field in self.fields:
field.create(self)

Expand Down Expand Up @@ -236,6 +226,8 @@ def post_generate(self, project):
Will be called when the whole project has been generated and
therefore all relations are available and the form
can also be generated.
As well we set the variable.
"""
has_tabs = False
for relation in project.relations:
Expand Down Expand Up @@ -321,6 +313,16 @@ def post_generate(self, project):
widget = FormFieldWidget(field.alias, field.name)
self.__form.add_element(widget)

# set the layer variable according to the strategy
interlis_topics = ",".join(
self.all_topics
if project.optimize_strategy == OptimizeStrategy.NONE
else self.relevant_topics
)
QgsExpressionContextUtils.setLayerVariable(
self.__layer, "interlis_topic", interlis_topics
)

def source(self):
return QgsDataSourceUri(self.uri)

Expand Down
4 changes: 2 additions & 2 deletions modelbaker/dataobjects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def create(
qgis_project.setEvaluateDefaultValues(self.evaluate_default_values)
qgis_layers = list()
for layer in self.layers:
qgis_layer = layer.create(self.optimize_strategy)
qgis_layer = layer.create()
self.layer_added.emit(qgis_layer.id())
if not self.crs and qgis_layer.isSpatial():
self.crs = qgis_layer.crs()
Expand Down Expand Up @@ -234,7 +234,7 @@ def create(
"Value": value_field,
"OrderByValue": False,
"AllowNull": True,
"Layer": domain_table.real_id,
"Layer": domain_table.create().id(),
"FilterExpression": "",
"Key": key_field,
"NofColumns": 1,
Expand Down
4 changes: 2 additions & 2 deletions modelbaker/dataobjects/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def create(self, qgis_project, relations):

relation.setId(self._id)
relation.setName(self.name)
relation.setReferencingLayer(self.referencing_layer.real_id)
relation.setReferencedLayer(self.referenced_layer.real_id)
relation.setReferencingLayer(self.referencing_layer.create().id())
relation.setReferencedLayer(self.referenced_layer.create().id())
relation.addFieldPair(self.referencing_field, self.referenced_field)
relation.setStrength(self.strength)
self.qgis_relation = relation
Expand Down
4 changes: 2 additions & 2 deletions tests/test_projectgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3006,7 +3006,7 @@ def test_kbs_postgis_basket_handling(self):
assert map["Relation"] == "belasteter_standort_t_basket_fkey"
assert (
map["FilterExpression"]
== f"\"topic\" = 'KbS_LV95_V1_3.Belastete_Standorte' and attribute(get_feature('t_ili2db_dataset', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'"
== f"\"topic\" IN ('KbS_LV95_V1_3.Belastete_Standorte') and attribute(get_feature('t_ili2db_dataset', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'"
)

# check the display expression of the basket table
Expand Down Expand Up @@ -3099,7 +3099,7 @@ def test_kbs_geopackage_basket_handling(self):
)
assert (
map["FilterExpression"]
== f"\"topic\" = 'KbS_LV95_V1_3.Belastete_Standorte' and attribute(get_feature('T_ILI2DB_DATASET', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'"
== f"\"topic\" IN ('KbS_LV95_V1_3.Belastete_Standorte') and attribute(get_feature('T_ILI2DB_DATASET', 't_id', \"dataset\"), 'datasetname') != '{CATALOGUE_DATASETNAME}'"
)

# check the display expression of the basket table
Expand Down

0 comments on commit f9a9509

Please sign in to comment.