Skip to content

Commit

Permalink
'initial_status and other style issues improved
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcb committed Jan 16, 2025
1 parent 7e661cc commit 0a8c08c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion wntrqgis/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PumpTypes(str, Enum):

class InitialStatus(str, Enum):
Open = "Open"
Active = "Active"
Closed = "Closed"


Expand Down Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions wntrqgis/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from wntrqgis.elements import (
FieldGroup,
InitialStatus,
ModelField,
ModelLayer,
ResultField,
Expand Down Expand Up @@ -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},
Expand All @@ -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()
Expand Down

0 comments on commit 0a8c08c

Please sign in to comment.