Allow setting custom IntGrid values
This pull request introduces the ability for users to edit IntGridValueDef values through an input field, while ensuring proper validation and rule updates.
Closes #1083.
Overview:
- Changed value indicator to an input field in
editLayerDefs.html - Added
IntInputto thevalueinput field with the following:- Validation rule:
LayerDef.isIntGridValueValidensures that0 < value <= 999and no otherIntGridValueDefon this layer uses the samevalue. - On invalid: Created new notification
invalidValue. - Setter: calls new method,
updateIntGridValue, on the current layer instance with the old and new value.
- Validation rule:
- Added
updateIntGridValuemethod toLayerInstancewhich does the following:- Updates the
IntGridValueDefto change the value. - Updates all stored values by calling
setIntGrid. - Updates the current layer's definition's auto rules (as the patterns need to be updated with the new value).
- Updates the auto rules for all levels whose auto source is this layer (not combined with the previous step as the current layer does not have a reference to itself in
autoSourceLayerDefUid).
- Updates the
Notes:
- Changing the value indicator to an input field altered the text formatting slightly, but I am unsure how to restore the original formatting. I can look into it further if needed.
- The range validation is currently handled in
LayerDef.isIntGridValueValidto centralize the logic across the layer. If preferred, I can refactor this to useIntInput.setBoundsfor inline validation. - The
invalidValuenotification uses similar messaging toinvalidIdentifier. However, I can modify it to explicitly state the value restrictions (e.g., "Value must be a positive integer less than 1000 and unique within the layer.") if you'd prefer a more detailed message. - I tried to keep the code style as close as I could to the existing code. Let me know if you have any recommendations.
Example Usage:
Below is an example of updating the IntGridValueDef, including verification that changes are properly reflected in the map, auto rules, and when reloading the file.
Initial IntGrid settings:
Selecting the value for the IntGridValueDef we want to update:
Changing the value to 2:
Verifying that the map has updated:
Verifying that the rules have updated:
Verifying that the contents are preserved when loading the file again:
By submitting this pull request, I hereby assign all copyright and related rights in the changes contained in this pull request to the maintainer(s) of this project, to the extent permitted by law.
Thanks for the PR 🙂 I know I'm late here, I will see how to integrate that in next update.
No worries. Let me know if you want me to make any changes or if you have other updates you need me to deconflict with.