fix #290053: don't trigger layout for elements not yet added to score #5092
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See https://musescore.org/en/node/290053
Currently, adding an element to the score often causes a layout of the whole score from the start to that point. That's because the act of constructing the new element often involves some setProperty() calls, and Eement::setProperty() as well as many of its overrides call triggerLayout(). That would be fine, but the element being constructed does not yet have a parent, so when triggerLayout() goes to get a tick, it comes up with 0. Thus, we end up setting the start tick for the layout range to 0 unnecessarily. The result is that adding elements to the score gets progressively slower the deeper into the score you go.
My PR here is very simple, I simply have triggerLayout() do nothing for elements with no parent. Once the element is fully constructed, and given a parent, there is an explicit triggerLayout() call right at the top of Score::addElement() as well, so that we are able to set the correct tick and perform the proper layout.