From 44523b815179eb752c54a2926a9e012d71960225 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Mon, 23 Dec 2024 18:53:57 +0000 Subject: [PATCH] Fix bug in Toolkit::RedoLayout. Fixes #3900 staffDef values were loosing their parent when being replaced. Fixed with a new method added for doing it properly. Also, processing them in CalcAligmentPitchPos is not needed, so VisitStaffDef was modified accordingly. --- include/vrv/object.h | 6 ++++++ src/calcalignmentpitchposfunctor.cpp | 2 +- src/object.cpp | 8 ++++++++ src/scoredef.cpp | 10 +++++----- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/vrv/object.h b/include/vrv/object.h index f5c2590419d..6ed92a82656 100644 --- a/include/vrv/object.h +++ b/include/vrv/object.h @@ -430,6 +430,12 @@ class Object : public BoundingBox { */ Object *DetachChild(int idx); + /** + * Replace an object with a copy of the other. + * They must be of the same class. + */ + void ReplaceWithCopyOf(Object *object); + /** * Return true if the object has the child Object as descendant (reference of direct). * Processes in depth-first. diff --git a/src/calcalignmentpitchposfunctor.cpp b/src/calcalignmentpitchposfunctor.cpp index dabdc80d3e5..1887e8cfe95 100644 --- a/src/calcalignmentpitchposfunctor.cpp +++ b/src/calcalignmentpitchposfunctor.cpp @@ -357,7 +357,7 @@ FunctorCode CalcAlignmentPitchPosFunctor::VisitStaffDef(StaffDef *staffDef) m_octDefaultForStaffN[staffDef->GetN()] = staffDef->GetOctDefault(); } - return FUNCTOR_CONTINUE; + return FUNCTOR_SIBLINGS; } } // namespace vrv diff --git a/src/object.cpp b/src/object.cpp index cc9bfeb9aa7..52cfdaa7c42 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -572,6 +572,14 @@ Object *Object::DetachChild(int idx) return child; } +void Object::ReplaceWithCopyOf(Object *object) +{ + Object *parent = this->GetParent(); + *this = *object; + this->CloneReset(); + this->SetParent(parent); +} + bool Object::HasDescendant(const Object *child, int deepness) const { ArrayOfObjects::const_iterator iter; diff --git a/src/scoredef.cpp b/src/scoredef.cpp index 172f1d5a021..5185a08acb2 100644 --- a/src/scoredef.cpp +++ b/src/scoredef.cpp @@ -484,21 +484,21 @@ void ScoreDef::ResetFromDrawingValues() assert(staffDef); Clef *clef = vrv_cast(staffDef->FindDescendantByType(CLEF)); - if (clef) *clef = *staffDef->GetCurrentClef(); + if (clef) clef->ReplaceWithCopyOf(staffDef->GetCurrentClef()); KeySig *keySig = vrv_cast(staffDef->FindDescendantByType(KEYSIG)); - if (keySig) *keySig = *staffDef->GetCurrentKeySig(); + if (keySig) keySig->ReplaceWithCopyOf(staffDef->GetCurrentKeySig()); Mensur *mensur = vrv_cast(staffDef->FindDescendantByType(MENSUR)); - if (mensur) *mensur = *staffDef->GetCurrentMensur(); + if (mensur) mensur->ReplaceWithCopyOf(staffDef->GetCurrentMensur()); MeterSigGrp *meterSigGrp = vrv_cast(staffDef->FindDescendantByType(METERSIGGRP)); MeterSig *meterSig = vrv_cast(staffDef->FindDescendantByType(METERSIG)); if (meterSigGrp) { - *meterSigGrp = *staffDef->GetCurrentMeterSigGrp(); + meterSigGrp->ReplaceWithCopyOf(staffDef->GetCurrentMeterSigGrp()); } else if (meterSig) { - *meterSig = *staffDef->GetCurrentMeterSig(); + meterSig->ReplaceWithCopyOf(staffDef->GetCurrentMeterSig()); } } }