Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 30 additions & 1 deletion src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ LayoutPanelTreeModel::LayoutPanelTreeModel(QObject* parent)
});
}

void LayoutPanelTreeModel::updateScoreSelection() const
{
const std::vector<EngravingItem*>& selectedElements = m_notation->interaction()->selection()->elements();

// This only gets executed for one part, see break down below
// Rewriting it to early return wouldn't bring much clarity in my opinion
for (EngravingItem* e: selectedElements) {
Part* selectedPart = e->part();
if (!selectedPart) {
continue;
}
ID selectedPartId = selectedPart->id();
AbstractLayoutPanelTreeItem* item = m_rootItem->childAtId(selectedPartId, LayoutPanelItemType::PART);

if (!item->isSelected()) {
m_notation->interaction()->clearSelection();
break;
}
}
}

void LayoutPanelTreeModel::onMasterNotationChanged()
{
m_masterNotation = context()->currentMasterNotation();
Expand Down Expand Up @@ -307,7 +328,9 @@ void LayoutPanelTreeModel::setupStavesConnections(const muse::ID& partId)
void LayoutPanelTreeModel::setupNotationConnections()
{
m_notation->interaction()->selectionChanged().onNotify(this, [this]() {
updateSelectedRows();
if (!m_blockSelectionChangedEvents) {
updateSelectedRows();
}
});

m_notation->undoStack()->changesChannel().onReceive(this, [this](const mu::engraving::ScoreChanges& changes) {
Expand Down Expand Up @@ -490,11 +513,17 @@ void LayoutPanelTreeModel::setLayoutPanelVisible(bool visible)
void LayoutPanelTreeModel::selectRow(const QModelIndex& rowIndex)
{
m_selectionModel->select(rowIndex);
m_blockSelectionChangedEvents = true;
updateScoreSelection();
m_blockSelectionChangedEvents = false;
}

void LayoutPanelTreeModel::clearSelection()
{
m_selectionModel->clear();
m_blockSelectionChangedEvents = true;
updateScoreSelection();
m_blockSelectionChangedEvents = false;
}

void LayoutPanelTreeModel::addInstruments()
Expand Down
3 changes: 3 additions & 0 deletions src/instrumentsscene/view/layoutpaneltreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private slots:

void updateSelectedRows();
void onScoreChanged(const mu::engraving::ScoreChanges& changes = {});
void updateScoreSelection() const;

void clear();
void deleteItems();
Expand Down Expand Up @@ -199,5 +200,7 @@ private slots:
MoveParams m_activeDragMoveParams;

muse::ID m_systemStaffToSelect;

bool m_blockSelectionChangedEvents = false;
};
}
Loading