Skip to content

Commit

Permalink
Merge pull request #26588 from mike-spa/systemObjectCorrection
Browse files Browse the repository at this point in the history
System object correction
  • Loading branch information
mike-spa authored Feb 21, 2025
2 parents 40d8cee + 1e50918 commit 9b783d6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ void LayoutPanelTreeModel::onBeforeChangeNotation()
QList<muse::ID> partIdList;

for (const AbstractLayoutPanelTreeItem* item : m_rootItem->childItems()) {
partIdList << item->id();
if (item->type() == LayoutPanelItemType::ItemType::PART) {
partIdList << item->id();
}
}

m_sortedPartIdList[notationToKey(m_notation)] = partIdList;
Expand Down Expand Up @@ -799,7 +801,9 @@ void LayoutPanelTreeModel::updateMovingDownAvailability(bool isSelectionMovable,

// exclude the control item
bool hasControlItem = parentItem->type() != LayoutPanelItemType::ROOT;
int lastItemRowIndex = parentItem->childCount() - 1 - (hasControlItem ? 1 : 0);
const AbstractLayoutPanelTreeItem* curItem = modelIndexToItem(lastSelectedRowIndex);
bool lastSelectedIsSystemObjectLayer = curItem && curItem->type() == LayoutPanelItemType::ItemType::SYSTEM_OBJECTS_LAYER;
int lastItemRowIndex = parentItem->childCount() - 1 - (hasControlItem ? 1 : 0) - (lastSelectedIsSystemObjectLayer ? 1 : 0);

bool isRowInBoundaries = lastSelectedRowIndex.isValid() && lastSelectedRowIndex.row() < lastItemRowIndex;

Expand Down Expand Up @@ -869,6 +873,9 @@ void LayoutPanelTreeModel::setItemsSelected(const QModelIndexList& indexes, bool
{
for (const QModelIndex& index : indexes) {
if (AbstractLayoutPanelTreeItem* item = modelIndexToItem(index)) {
if (!item->isSelectable()) {
continue;
}
item->setIsSelected(selected);
}
}
Expand Down Expand Up @@ -962,17 +969,17 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()

// Remove old system object layers
std::vector<const PartTreeItem*> partItems;
std::vector<const SystemObjectsLayerTreeItem*> existingSystemObjectLayers;
std::vector<SystemObjectsLayerTreeItem*> existingSystemObjectLayers;

for (const AbstractLayoutPanelTreeItem* item : children) {
for (AbstractLayoutPanelTreeItem* item : children) {
if (item->type() != LayoutPanelItemType::SYSTEM_OBJECTS_LAYER) {
if (item->type() == LayoutPanelItemType::PART) {
partItems.push_back(static_cast<const PartTreeItem*>(item));
}
continue;
}

auto layerItem = static_cast<const SystemObjectsLayerTreeItem*>(item);
auto layerItem = static_cast<SystemObjectsLayerTreeItem*>(item);
if (muse::remove(newSystemObjectStaves, const_cast<Staff*>(layerItem->staff()))) {
existingSystemObjectLayers.push_back(layerItem);
continue;
Expand All @@ -985,7 +992,7 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
}

// Update position of existing layers if changed
for (const SystemObjectsLayerTreeItem* layerItem : existingSystemObjectLayers) {
for (SystemObjectsLayerTreeItem* layerItem : existingSystemObjectLayers) {
const PartTreeItem* partItem = findPartItemByStaff(layerItem->staff());
IF_ASSERT_FAILED(partItem) {
continue;
Expand All @@ -994,11 +1001,13 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
const int partRow = partItem->row();
const int layerRow = layerItem->row();

if (partRow < layerRow) {
if (layerRow != partRow - 1) {
beginMoveRows(QModelIndex(), layerRow, layerRow, QModelIndex(), partRow);
m_rootItem->moveChildren(layerRow, 1, m_rootItem, partRow, false /*updateNotation*/);
endMoveRows();
}

layerItem->updateSystemObjects();
}

if (newSystemObjectStaves.empty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/instrumentsscene/view/systemobjectslayertreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ void SystemObjectsLayerTreeItem::setStaff(const Staff* staff)
}
}

void SystemObjectsLayerTreeItem::updateSystemObjects()
{
m_systemObjectGroups = collectSystemObjectGroups(m_staff);
updateState();
}

QString SystemObjectsLayerTreeItem::staffId() const
{
const Staff* s = staff();
Expand Down
1 change: 1 addition & 0 deletions src/instrumentsscene/view/systemobjectslayertreeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class SystemObjectsLayerTreeItem : public AbstractLayoutPanelTreeItem, public mu

const mu::engraving::Staff* staff() const;
void setStaff(const mu::engraving::Staff* staff);
void updateSystemObjects();

Q_INVOKABLE QString staffId() const;
Q_INVOKABLE bool canAcceptDrop(const QVariant& item) const override;
Expand Down
1 change: 1 addition & 0 deletions src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ void NotationParts::moveSystemObjects(const ID& sourceStaffId, const ID& destina
if (item->staff() == srcStaff) {
item->undoChangeProperty(Pid::TRACK, staff2track(dstStaffIdx, item->voice()));
} else {
item->undoUnlink();
score()->undoRemoveElement(item, false /*removeLinked*/);
}
}
Expand Down

0 comments on commit 9b783d6

Please sign in to comment.