Skip to content

Commit

Permalink
Merge branch '5.5' into CURA-10994_translations_v5p5
Browse files Browse the repository at this point in the history
  • Loading branch information
rburema committed Oct 5, 2023
2 parents 4986b81 + 5d0271e commit 3e182e6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
2 changes: 1 addition & 1 deletion UM/Qt/qml/UM/MenuItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ MenuItem
enabled: root.action == null && root.enabled
onActivated: root.triggered()
context: Qt.ApplicationShortcut
sequence: root.action != null ? root.action.shortcut: null
sequences: root.action !== null ? [root.action] : []
}

// Workaround for menu items in controls not supporting mnemonic shortcuts in all cases.
Expand Down
22 changes: 17 additions & 5 deletions UM/Settings/DefinitionContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,21 @@ def deserialize(self, serialized: str, file_name: Optional[str] = None) -> str:
self._metadata["container_type"] = DefinitionContainer

self._deserializeDefinitions(parsed["settings"])

for definition in self._definitions:
self._updateRelations(definition)

return serialized

def _deserializeDefinitions(self, settings_dict: Dict[str, Any], force_category: Optional[str] = None) -> None:
def _deserializeDefinitions(self, settings_dict: Dict[str, Any], force_category: Optional[str] = None) -> List[SettingDefinition]:

# When there is a forced category (= parent) present, find the category parent, create it if it doesn't exist.
category_parent = None
if force_category:
category_parent = self.findDefinitions(key = force_category)
category_parent = category_parent[0] if len(category_parent) > 0 else None

added_definitions = []
for key, value in settings_dict.items():
definition = SettingDefinition(key, self, category_parent, self._i18n_catalog)
self._definition_cache[key] = definition
Expand All @@ -352,9 +357,9 @@ def _deserializeDefinitions(self, settings_dict: Dict[str, Any], force_category:
category_parent.children.append(definition)
else:
self._definitions.append(definition)
added_definitions.append(definition)

for definition in self._definitions:
self._updateRelations(definition)
return added_definitions

def appendAdditionalSettingDefinitions(self, additional_settings: Dict[str, Dict[str, Any]]) -> None:
"""
Expand All @@ -375,14 +380,18 @@ def appendAdditionalSettingDefinitions(self, additional_settings: Dict[str, Dict
else:
create_new_categories[category] = values

added_definitions = []
if len(create_new_categories) > 0:
self._deserializeDefinitions(create_new_categories)
for category, values in merge_with_existing_categories.items():
if "children" in values:
for key, value in values["children"].items():
self._deserializeDefinitions({key: value}, category)
added_definitions += self._deserializeDefinitions({key: value}, category)
else:
self._deserializeDefinitions(values, category)
added_definitions += self._deserializeDefinitions(values, category)

for definition in added_definitions:
self._updateRelations(definition)

except Exception as ex:
Logger.error(f"Failed to append additional settings from external source because: {str(ex)}")
Expand Down Expand Up @@ -581,3 +590,6 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return str(self)

def __hash__(self) -> int:
return hash(self.getId())
2 changes: 1 addition & 1 deletion UM/Settings/SettingDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __setattr__(self, name: str, value: Any) -> None:
def __hash__(self):
"""Ensure that the SettingDefinition is hashable, so it can be used in a set."""

return hash(str(self))
return hash((id(self), self._key, self._container))

def __getstate__(self):
"""For Pickle support.
Expand Down
34 changes: 19 additions & 15 deletions UM/Settings/SettingInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def _traceRelations(instance: "SettingInstance", container: ContainerInterface,
if SettingDefinition.isReadOnlyProperty(property_name):
continue

changed_relations = set() # type: Set[SettingRelation]
instance._addRelations(changed_relations, instance.definition.relations, [property_name])
changed_relations: Set[SettingRelation] = set()
SettingInstance._listRelations(instance.definition.key, changed_relations, instance.definition.relations, [property_name])

for relation in changed_relations:
Logger.log("d", "Emitting property change for relation {0}", relation)
Expand Down Expand Up @@ -173,14 +173,14 @@ def setProperty(self, name: str, value: Any, container: Optional[ContainerInterf

self.updateRelations(container, emit_signals = emit_signals)

if self._validator and emit_signals:
self.propertyChanged.emit(self._definition.key, "validationState")

if emit_signals:
if self._validator:
self.propertyChanged.emit(self._definition.key, "validationState")

self.propertyChanged.emit(self._definition.key, name)
for property_name in self._definition.getPropertyNames():
if self._definition.dependsOnProperty(property_name) == name:
if emit_signals:

for property_name in self._definition.getPropertyNames():
if self._definition.dependsOnProperty(property_name) == name:
self.propertyChanged.emit(self._definition.key, property_name)
else:
if name == "state":
Expand Down Expand Up @@ -239,32 +239,36 @@ def updateRelations(self, container: ContainerInterface, emit_signals: bool = Tr
if SettingDefinition.isReadOnlyProperty(property_name):
continue

changed_relations = set() # type: Set[SettingRelation]
self._addRelations(changed_relations, self._definition.relations, [property_name])

# TODO: We should send this as a single change event instead of several of them.
# That would increase performance by reducing the amount of updates.
if emit_signals:
changed_relations: Set[SettingRelation] = set()
SettingInstance._listRelations(self.definition.key, changed_relations, self._definition.relations, [property_name])

for relation in changed_relations:
container.propertyChanged.emit(relation.target.key, relation.role)
# If the value/minimum value/etc state is updated, the validation state must be re-evaluated
if relation.role in {"value", "minimum_value", "maximum_value", "minimum_value_warning", "maximum_value_warning"}:
container.propertyChanged.emit(relation.target.key, "validationState")

def _addRelations(self, relations_set: Set["SettingRelation"], relations: List["SettingRelation"], roles: List[str]) -> None:
@staticmethod
def _listRelations(key: str, relations_set: Set["SettingRelation"], relations: List["SettingRelation"], roles: List[str]) -> None:
"""Recursive function to put all settings that require eachother for changes of a property value in a list
:param relations_set: :type{set} Set of keys (strings) of settings that are influenced
:param relations: list of relation objects that need to be checked.
:param roles: list of name of the properties value of the settings
"""

for relation in filter(lambda r: r.role in roles, relations):
for relation in relations:
if relation.type == RelationType.RequiresTarget:
continue

# Do not add relation to self.
if relation.target.key == self.definition.key:
if relation.target.key == key:
continue

if relation.role not in roles:
continue

# Don't add it to list if it's already there.
Expand All @@ -278,4 +282,4 @@ def _addRelations(self, relations_set: Set["SettingRelation"], relations: List["
property_names.remove("value") # Move "value" to the front of the list so we always update that first.
property_names.insert(0, "value")

self._addRelations(relations_set, relation.target.relations, property_names)
SettingInstance._listRelations(key, relations_set, relation.target.relations, property_names)
4 changes: 2 additions & 2 deletions UM/Settings/SettingRelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def __init__(self, owner: SettingDefinition, target: SettingDefinition, relation
self._type = relation_type
self._role = role

def __hash__(self):
def __hash__(self) -> int:
"""Ensure that the SettingRelation is hashable, so it can be used in a set."""

return hash(str(self))
return hash((self._owner, self._target, self._type, self._role))

@property
def owner(self) -> SettingDefinition:
Expand Down

0 comments on commit 3e182e6

Please sign in to comment.