Skip to content

Commit

Permalink
Fix bug in Toolkit::RedoLayout. Fixes #3900
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 44523b8)
  • Loading branch information
lpugin committed Dec 24, 2024
1 parent a5a5d44 commit 04c366d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/vrv/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/calcalignmentpitchposfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ FunctorCode CalcAlignmentPitchPosFunctor::VisitStaffDef(StaffDef *staffDef)
m_octDefaultForStaffN[staffDef->GetN()] = staffDef->GetOctDefault();
}

return FUNCTOR_CONTINUE;
return FUNCTOR_SIBLINGS;
}

} // namespace vrv
8 changes: 8 additions & 0 deletions src/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/scoredef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,21 +484,21 @@ void ScoreDef::ResetFromDrawingValues()
assert(staffDef);

Clef *clef = vrv_cast<Clef *>(staffDef->FindDescendantByType(CLEF));
if (clef) *clef = *staffDef->GetCurrentClef();
if (clef) clef->ReplaceWithCopyOf(staffDef->GetCurrentClef());

KeySig *keySig = vrv_cast<KeySig *>(staffDef->FindDescendantByType(KEYSIG));
if (keySig) *keySig = *staffDef->GetCurrentKeySig();
if (keySig) keySig->ReplaceWithCopyOf(staffDef->GetCurrentKeySig());

Mensur *mensur = vrv_cast<Mensur *>(staffDef->FindDescendantByType(MENSUR));
if (mensur) *mensur = *staffDef->GetCurrentMensur();
if (mensur) mensur->ReplaceWithCopyOf(staffDef->GetCurrentMensur());

MeterSigGrp *meterSigGrp = vrv_cast<MeterSigGrp *>(staffDef->FindDescendantByType(METERSIGGRP));
MeterSig *meterSig = vrv_cast<MeterSig *>(staffDef->FindDescendantByType(METERSIG));
if (meterSigGrp) {
*meterSigGrp = *staffDef->GetCurrentMeterSigGrp();
meterSigGrp->ReplaceWithCopyOf(staffDef->GetCurrentMeterSigGrp());
}
else if (meterSig) {
*meterSig = *staffDef->GetCurrentMeterSig();
meterSig->ReplaceWithCopyOf(staffDef->GetCurrentMeterSig());
}
}
}
Expand Down

0 comments on commit 04c366d

Please sign in to comment.