Give DrawnElement a copy constructor #4763
Merged
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.
Identify the Bug or Feature request
Fixes #2433
Properly fixes #4526
Description of the Change
DrawnElement
now has a copy constructor that will copy the underlyingDrawable
andPen
.Pen
already has a copy constructor, butDrawable
did not have anything for this. So a newDrawable.copy()
method is added, with concrete child classes deciding how they should be copied. For practical reasons, this is always implemented via copy constructors.The above is mostly straightforward, but
ShapeDrawable
is a unique case. It wraps a generalShape
, but not allShape
implementations are easily copied. So for this we do case work on the type of the shape: the common cases ofArea
,Polygon
, andRectangularShape
(coveringRectangle
,Ellipse2D
and more), are handled explicitly. There shouldn't be other type encountered inShapeDrawable
, but to cover our bases we simply do a shallow a copy if some unknownShape
implementation is found.In the copy constructor of
Zone
, each drawing is copied using the newDrawnElement
copy constructor. IfkeepIDs
isfalse
, a new GUID will also be generated and set for each copy.Finally, I took the opportunity to refactor
Drawable.fromDto()
so that each concrete class has its ownfromDto()
method, withDrawable.fromDto()
doing nothing but delegating base on type case. I find this easier to read with thetoDto()
andfromDto()
methods for each type sitting right next to each other.Possible Drawbacks
Should be none.
Documentation Notes
N/A
Release Notes
This change is