8000
Skip to content

Conversation

@MariaF203
Copy link
@MariaF203 MariaF203 commented Dec 2, 2025

Description

Resolves #3430

This PR fixes the issue where custom Parameter subclasses (e.g. ComplexParameter and ScalableGroup, defined in examples/parametertree.py) cannot be correctly restored using saveState() and restoreState().

The cause of this problem is that these classes overwrite opts['type'] with existing types (e.g. 'group') already associated to an other Parameter subclass.

Thus, for example, the restore mechanism instantiates a GroupParameter instead of the expected subclass ScalableGroup. Similarly, it instantiates a SimpleParameter instead of a ComplexParameter.

Summary of changes

1. Use and register unique parameters types

We use unique type names ('complexparameter', 'scalablegroup') for the example subclasses ComplexParameter and ScalableGroup and register them using registerParameterType().

2. Add a type check in Parameter

Created a new method check_type(). It validates that:

  • the specified type is registered in PARAM_TYPES
  • the corresponding registered class matches the actual class.

This method is then called in the __init__ function of Parameter.

3. Add a compare_parameters() function

Created a new function compare_parameters() that allows to compare two parameters. In particular, it checks that the parameters classes are the same.
The existing eq() function only compare saved states and cannot compare classes.

4. Add tests

  • Tests for compareParameters()
  • Update of test in test_parametertypes.py to check that the restored parameters keep the correct class.

5. Fix BoolOrRadioParameter inconsistency

A BoolOrRadioParameter could represent a 'bool' or a 'radio', but only one class per type can be registered in PARAM_TYPES. Thus, it caused inconsistencies. To resolve this:

  • Removed the BoolOrRadioParameter class.
  • Created a new registered class RadioParameter, associated to the 'radio' type;
  • Updated ChecklistParameter so the created list items are either a BoolParameter or a RadioParameter.

Conclusion

  • Parameter subclasses are now properly saved and restored.
  • Type registration is consistent.
  • Parameters comparison is now fully coherent.

Maria Flesch added 2 commits December 1, 2025 14:34
fix parameter example in parametertree
add a type checking in the Parameter init function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type of Parameter subclasses incorrectly saved with saveState() / restoreState()

1 participant

0