diff --git a/src/editortoolkit_neume.cpp b/src/editortoolkit_neume.cpp index 1bd268778c8..a961a308fe2 100644 --- a/src/editortoolkit_neume.cpp +++ b/src/editortoolkit_neume.cpp @@ -1711,6 +1711,8 @@ bool EditorToolkitNeume::MatchHeight(std::string elementId) bool EditorToolkitNeume::Merge(std::vector elementIds) { if (!m_doc->GetDrawingPage()) return false; + Object *page = m_doc->GetDrawingPage(); + ListOfObjects staves; // Get the staves by element ID and fail if a staff does not exist. @@ -1777,8 +1779,35 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) Layer *sourceLayer = vrv_cast(sourceStaff->GetFirst(LAYER)); fillLayer->MoveChildrenFrom(sourceLayer); assert(sourceLayer->GetChildCount() == 0); - Object *parent = sourceStaff->GetParent(); - parent->DeleteChild(sourceStaff); + + // Delete empty staff with its system parent + // Move SECTION, PB, and SYSTEM_MILESTONE_END if any + Object *system = sourceStaff->GetFirstAncestor(SYSTEM); + if (system->FindDescendantByType(SECTION)) { + Object *section = system->FindDescendantByType(SECTION); + Object *nextSystem = page->GetNext(system, SYSTEM); + if (nextSystem) { + section = system->DetachChild(section->GetIdx()); + nextSystem->InsertChild(section, 0); + } + } + if (system->FindDescendantByType(PB)) { + Object *pb = system->FindDescendantByType(PB); + Object *nextSystem = page->GetNext(system, SYSTEM); + if (nextSystem) { + pb = system->DetachChild(pb->GetIdx()); + nextSystem->InsertChild(pb, 1); + } + } + if (system->FindDescendantByType(SYSTEM_MILESTONE_END)) { + Object *milestoneEnd = system->FindDescendantByType(SYSTEM_MILESTONE_END); + Object *previousSystem = page->GetPrevious(system, SYSTEM); + if (previousSystem) { + milestoneEnd = system->DetachChild(milestoneEnd->GetIdx()); + previousSystem->InsertChild(milestoneEnd, previousSystem->GetChildCount()); + } + } + page->DeleteChild(system); } // Set the bounding box for the staff to the new bounds Zone *staffZone = fillStaff->GetZone(); @@ -1790,13 +1819,25 @@ bool EditorToolkitNeume::Merge(std::vector elementIds) fillLayer->ReorderByXPos(); - m_editInfo.import("uuid", fillStaff->GetID()); - m_editInfo.import("status", "OK"); - m_editInfo.import("message", ""); + for (Object *child = page->GetFirst(); child != NULL; child = page->GetNext()) { + LogError("%s", child->GetClassName().c_str()); + if (child->Is(SYSTEM)) { + for (Object *grandchild = child->GetFirst(); grandchild != NULL; grandchild = child->GetNext()) { + LogError("system child %s", grandchild->GetClassName().c_str()); + if (grandchild->Is(MEASURE)) { + for (Object *ggchild = grandchild->GetFirst(); ggchild != NULL; ggchild = grandchild->GetNext()) { + LogError("system measure child %s", ggchild->GetClassName().c_str()); + } + } + } + } + } if (m_doc->IsTranscription() && m_doc->HasFacsimile()) m_doc->SyncFromFacsimileDoc(); - // TODO change zones for staff children + m_editInfo.import("uuid", fillStaff->GetID()); + m_editInfo.import("status", "OK"); + m_editInfo.import("message", ""); return true; }