Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More system object refinements #26653

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ LayoutPanelTreeModel::LayoutPanelTreeModel(QObject* parent)
updateRearrangementAvailability();
updateRemovingAvailability();
updateSelectedItemsType();
emit isAddingSystemMarkingsAvailableChanged(isAddingSystemMarkingsAvailable());
});

connect(this, &LayoutPanelTreeModel::rowsInserted, this, [this]() {
Expand Down Expand Up @@ -453,6 +454,8 @@ void LayoutPanelTreeModel::addSystemMarkings()
if (const Staff* staff = resolveNewSystemObjectStaff()) {
m_masterNotation->parts()->addSystemObjects({ staff->id() });
}

emit isAddingSystemMarkingsAvailableChanged(isAddingSystemMarkingsAvailable());
}

void LayoutPanelTreeModel::moveSelectedRowsUp()
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/instrumentsscene/view/systemobjectslayertreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading