From 0a8c08c208df80a0d8e54ca22246c69e356f6b1b Mon Sep 17 00:00:00 2001 From: angusmcb Date: Thu, 16 Jan 2025 22:02:07 +0100 Subject: [PATCH] 'initial_status and other style issues improved --- wntrqgis/elements.py | 3 ++- wntrqgis/style.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wntrqgis/elements.py b/wntrqgis/elements.py index ece74e9..47fde7f 100644 --- a/wntrqgis/elements.py +++ b/wntrqgis/elements.py @@ -45,6 +45,7 @@ class PumpTypes(str, Enum): class InitialStatus(str, Enum): Open = "Open" + Active = "Active" Closed = "Closed" @@ -305,13 +306,13 @@ class ModelField(_AbstractField): LENGTH = "length", float, FieldGroup.BASE ROUGHNESS = "roughness", float, FieldGroup.BASE | FieldGroup.REQUIRED MINOR_LOSS = "minor_loss", float, FieldGroup.BASE - INITIAL_STATUS = "initial_status", InitialStatus, FieldGroup.BASE CHECK_VALVE = "check_valve", bool, FieldGroup.BASE PUMP_TYPE = "pump_type", PumpTypes, FieldGroup.BASE | FieldGroup.REQUIRED PUMP_CURVE = "pump_curve", str, FieldGroup.BASE POWER = "power", float, FieldGroup.BASE BASE_SPEED = "base_speed", float, FieldGroup.BASE SPEED_PATTERN = "speed_pattern", str, FieldGroup.BASE + INITIAL_STATUS = "initial_status", InitialStatus, FieldGroup.BASE INITIAL_SETTING = "initial_setting", float, FieldGroup.BASE HEADLOSS_CURVE = "headloss_curve", str, FieldGroup.BASE diff --git a/wntrqgis/style.py b/wntrqgis/style.py index 0f52272..dc70528 100644 --- a/wntrqgis/style.py +++ b/wntrqgis/style.py @@ -24,6 +24,7 @@ from wntrqgis.elements import ( FieldGroup, + InitialStatus, ModelField, ModelLayer, ResultField, @@ -59,7 +60,12 @@ def editor_widget(self) -> QgsEditorWidgetSetup: {"AllowNullState": False}, ) if issubclass(python_type_class, Enum): - value_map = [{enum_instance.value: enum_instance.name} for enum_instance in python_type_class] + enum_list = list(python_type_class) + if python_type_class is InitialStatus and self.layer_type is ModelLayer.PIPES: + enum_list = [InitialStatus.Open, InitialStatus.Closed] + + value_map = [{enum_instance.value: enum_instance.name} for enum_instance in enum_list] + return QgsEditorWidgetSetup( "ValueMap", {"map": value_map}, @@ -71,14 +77,24 @@ def editor_widget(self) -> QgsEditorWidgetSetup: @property def default_value(self): # [f.defaultValueDefinition() for f in iface.activeLayer().fields()] + if self.field_type is ModelField.ROUGHNESS: return QgsDefaultValue("100") # TODO: check if it is d-w or h-w + if self.field_type is ModelField.DIAMETER and ( self.layer_type is ModelLayer.PIPES or self.layer_type is ModelLayer.VALVES ): - return QgsDefaultValue("100") # TODO: check if it is d-w or h-w + return QgsDefaultValue("100") # TODO: check if it is lps or gpm... + + if self.field_type in [ModelField.ELEVATION, ModelField.BASE_HEAD]: + return QgsDefaultValue("0") + + if self.field_type.python_type is InitialStatus and self.layer_type is ModelLayer.VALVES: + return QgsDefaultValue(f"'{InitialStatus.Active.name}'") + if issubclass(self.field_type.python_type, Enum): return QgsDefaultValue(f"'{next(iter(self.field_type.python_type)).name}'") + if self.field_type.python_type is str: return QgsDefaultValue("''") # because 'NULL' doesn't look nice return QgsDefaultValue()