Skip to content

Commit

Permalink
optimization: collect system objects for all staves at once
Browse files Browse the repository at this point in the history
As it's quite an expensive operation
  • Loading branch information
RomanPudashkin committed Feb 21, 2025
1 parent af02fba commit a6ec17b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,8 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
m_shouldUpdateSystemObjectLayers = false;

// Create copy, because we're going to modify them
std::vector<Staff*> newSystemObjectStaves = m_masterNotation->notation()->parts()->systemObjectStaves();
const INotationPartsPtr notationParts = m_masterNotation->notation()->parts();
std::vector<Staff*> newSystemObjectStaves = notationParts->systemObjectStaves();
QList<AbstractLayoutPanelTreeItem*> children = m_rootItem->childItems();

// Remove old system object layers
Expand All @@ -1016,6 +1017,8 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
endRemoveRows();
}

SystemObjectGroupsByStaff systemObjects = collectSystemObjectGroups(notationParts->systemObjectStaves());

// Update position of existing layers if changed
for (SystemObjectsLayerTreeItem* layerItem : existingSystemObjectLayers) {
const PartTreeItem* partItem = findPartItemByStaff(layerItem->staff());
Expand All @@ -1032,16 +1035,10 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
endMoveRows();
}

layerItem->updateSystemObjects();
}

if (newSystemObjectStaves.empty()) {
return;
layerItem->setSystemObjects(systemObjects[layerItem->staff()]);
}

// Create new system object layers
SystemObjectGroupsByStaff systemObjects = collectSystemObjectGroups(newSystemObjectStaves);

for (const Staff* staff : newSystemObjectStaves) {
for (const PartTreeItem* partItem : partItems) {
if (staff->part() != partItem->part()) {
Expand Down
9 changes: 3 additions & 6 deletions src/instrumentsscene/view/systemobjectslayertreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,13 @@ SystemObjectsLayerTreeItem::SystemObjectsLayerTreeItem(IMasterNotationPtr master

void SystemObjectsLayerTreeItem::init(const Staff* staff, const SystemObjectGroups& systemObjects)
{
m_systemObjectGroups = systemObjects;

setStaff(staff);
setSystemObjects(systemObjects);

bool isTopLayer = staff->score()->staff(0) == staff;
setIsRemovable(!isTopLayer);
setIsSelectable(!isTopLayer);

updateState();

connect(this, &AbstractLayoutPanelTreeItem::isVisibleChanged, this, [this](bool isVisible) {
onVisibleChanged(isVisible);
});
Expand All @@ -123,9 +120,9 @@ void SystemObjectsLayerTreeItem::setStaff(const Staff* staff)
}
}

void SystemObjectsLayerTreeItem::updateSystemObjects()
void SystemObjectsLayerTreeItem::setSystemObjects(const SystemObjectGroups& systemObjects)
{
m_systemObjectGroups = collectSystemObjectGroups(m_staff);
m_systemObjectGroups = systemObjects;
updateState();
}

Expand Down
2 changes: 1 addition & 1 deletion src/instrumentsscene/view/systemobjectslayertreeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SystemObjectsLayerTreeItem : public AbstractLayoutPanelTreeItem

const mu::engraving::Staff* staff() const;
void setStaff(const mu::engraving::Staff* staff);
void updateSystemObjects();
void setSystemObjects(const SystemObjectGroups& systemObjects);

Q_INVOKABLE QString staffId() const;
Q_INVOKABLE bool canAcceptDrop(const QVariant& item) const override;
Expand Down

0 comments on commit a6ec17b

Please sign in to comment.