diff --git a/src/instrumentsscene/view/layoutpaneltreemodel.cpp b/src/instrumentsscene/view/layoutpaneltreemodel.cpp index e6e8c2d67e12f..afeb2ad7054ce 100644 --- a/src/instrumentsscene/view/layoutpaneltreemodel.cpp +++ b/src/instrumentsscene/view/layoutpaneltreemodel.cpp @@ -69,6 +69,7 @@ LayoutPanelTreeModel::LayoutPanelTreeModel(QObject* parent) updateRearrangementAvailability(); updateRemovingAvailability(); updateSelectedItemsType(); + emit isAddingSystemMarkingsAvailableChanged(isAddingSystemMarkingsAvailable()); }); connect(this, &LayoutPanelTreeModel::rowsInserted, this, [this]() { @@ -453,6 +454,8 @@ void LayoutPanelTreeModel::addSystemMarkings() if (const Staff* staff = resolveNewSystemObjectStaff()) { m_masterNotation->parts()->addSystemObjects({ staff->id() }); } + + emit isAddingSystemMarkingsAvailableChanged(isAddingSystemMarkingsAvailable()); } void LayoutPanelTreeModel::moveSelectedRowsUp() @@ -553,6 +556,17 @@ bool LayoutPanelTreeModel::moveRows(const QModelIndex& sourceParent, int sourceR sourceParentItem->moveChildren(sourceFirstRow, count, destinationParentItem, destinationRow, !m_dragInProgress); endMoveRows(); + int lastRow = m_rootItem->childCount() - 1; + AbstractLayoutPanelTreeItem* lastItem = m_rootItem->childAtRow(m_rootItem->childCount() - 1); + if (lastItem->type() == LayoutPanelItemType::SYSTEM_OBJECTS_LAYER) { + bool restore = m_isRemovingAvailable; + m_isRemovingAvailable = true; + + removeRow(lastRow); + + m_isRemovingAvailable = restore; + } + updateRearrangementAvailability(); updateSystemObjectLayers(); @@ -719,7 +733,18 @@ bool LayoutPanelTreeModel::isAddingAvailable() const bool LayoutPanelTreeModel::isAddingSystemMarkingsAvailable() const { - return isAddingAvailable() && m_notation->isMaster(); + if (!isAddingAvailable() || !m_notation->isMaster()) { + return false; + } + + int systemLayerCount = 0; + for (const AbstractLayoutPanelTreeItem* item : m_rootItem->childItems()) { + if (item->type() == LayoutPanelItemType::SYSTEM_OBJECTS_LAYER) { + ++systemLayerCount; + } + } + + return systemLayerCount < 0.5 * m_rootItem->childCount(); } bool LayoutPanelTreeModel::isEmpty() const @@ -828,6 +853,13 @@ void LayoutPanelTreeModel::updateMovingDownAvailability(bool isSelectionMovable, bool hasControlItem = parentItem->type() != LayoutPanelItemType::ROOT; const AbstractLayoutPanelTreeItem* curItem = modelIndexToItem(lastSelectedRowIndex); bool lastSelectedIsSystemObjectLayer = curItem && curItem->type() == LayoutPanelItemType::ItemType::SYSTEM_OBJECTS_LAYER; + + IF_ASSERT_FAILED(!(lastSelectedIsSystemObjectLayer && lastSelectedRowIndex.row() == 0)) { + // Selecting/moving the top system object layer not allowed + setIsMovingDownAvailable(false); + return; + } + int lastItemRowIndex = parentItem->childCount() - 1 - (hasControlItem ? 1 : 0) - (lastSelectedIsSystemObjectLayer ? 1 : 0); bool isRowInBoundaries = lastSelectedRowIndex.isValid() && lastSelectedRowIndex.row() < lastItemRowIndex; @@ -1052,7 +1084,10 @@ void LayoutPanelTreeModel::updateSystemObjectLayers() m_rootItem->insertChild(newItem, row); endInsertRows(); - m_selectionModel->select(createIndex(row, 0, newItem)); + if (row != 0) { + m_selectionModel->select(createIndex(row, 0, newItem)); + } + break; } } diff --git a/src/instrumentsscene/view/systemobjectslayertreeitem.cpp b/src/instrumentsscene/view/systemobjectslayertreeitem.cpp index 78979da7ff34b..174a94be3706c 100644 --- a/src/instrumentsscene/view/systemobjectslayertreeitem.cpp +++ b/src/instrumentsscene/view/systemobjectslayertreeitem.cpp @@ -134,7 +134,7 @@ QString SystemObjectsLayerTreeItem::staffId() const bool SystemObjectsLayerTreeItem::canAcceptDrop(const QVariant&) const { - return false; + return m_staffIdx != 0; // all except the first } void SystemObjectsLayerTreeItem::onScoreChanged(const mu::engraving::ScoreChangesRange& changes) diff --git a/src/notation/internal/masternotationparts.cpp b/src/notation/internal/masternotationparts.cpp index 308d8d6bc3210..1c9c744ff69d0 100644 --- a/src/notation/internal/masternotationparts.cpp +++ b/src/notation/internal/masternotationparts.cpp @@ -265,10 +265,6 @@ void MasterNotationParts::addSystemObjects(const muse::IDList& stavesIds) NotationParts::addSystemObjects(stavesIds); - for (INotationPartsPtr parts : excerptsParts()) { - parts->addSystemObjects(stavesIds); - } - endGlobalEdit(); } @@ -282,10 +278,6 @@ void MasterNotationParts::removeSystemObjects(const muse::IDList& stavesIds) NotationParts::removeSystemObjects(stavesIds); - for (INotationPartsPtr parts : excerptsParts()) { - parts->removeSystemObjects(stavesIds); - } - endGlobalEdit(); } diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index 7f2aaa3f954ca..c305f92359923 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -799,7 +799,7 @@ void NotationParts::moveSystemObjects(const ID& sourceStaffId, const ID& destina startEdit(TranslatableString("undoableAction", "Move system markings")); score()->undo(new mu::engraving::RemoveSystemObjectStaff(srcStaff)); - if (!score()->isSystemObjectStaff(dstStaff)) { + if (!score()->isSystemObjectStaff(dstStaff) && !dstStaffIdx == 0) { score()->undo(new mu::engraving::AddSystemObjectStaff(dstStaff)); }