Skip to content

Commit b51ad10

Browse files
Merge pull request #27811 from RomanPudashkin/452_port_fixes
Porting PRs to 4.5.2
2 parents 8b1c92b + 3392cdf commit b51ad10

File tree

6 files changed

+79
-20
lines changed

6 files changed

+79
-20
lines changed

src/instrumentsscene/view/layoutpaneltreemodel.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ bool LayoutPanelTreeModel::removeRows(int row, int count, const QModelIndex& par
157157
return true;
158158
}
159159

160+
bool LayoutPanelTreeModel::shouldShowSystemObjectLayers() const
161+
{
162+
// Only show system object staves in master score
163+
// TODO: extend system object staves logic to parts
164+
return m_notation && m_notation->isMaster();
165+
}
166+
160167
void LayoutPanelTreeModel::initPartOrders()
161168
{
162169
m_sortedPartIdList.clear();
@@ -305,7 +312,7 @@ void LayoutPanelTreeModel::setupNotationConnections()
305312

306313
m_notation->undoStack()->changesChannel().onReceive(this, [this](const mu::engraving::ScoreChangesRange& changes) {
307314
if (!m_layoutPanelVisible) {
308-
m_shouldUpdateSystemObjectLayers = true;
315+
m_scoreChanged = true;
309316
return;
310317
}
311318

@@ -353,6 +360,8 @@ void LayoutPanelTreeModel::onScoreChanged(const mu::engraving::ScoreChangesRange
353360
for (AbstractLayoutPanelTreeItem* item : m_rootItem->childItems()) {
354361
item->onScoreChanged(changes);
355362
}
363+
364+
m_scoreChanged = false;
356365
}
357366

358367
void LayoutPanelTreeModel::clear()
@@ -390,13 +399,16 @@ void LayoutPanelTreeModel::load()
390399
async::NotifyList<const Part*> masterParts = m_masterNotation->parts()->partList();
391400
sortParts(masterParts);
392401

402+
const bool showSystemObjectLayers = shouldShowSystemObjectLayers();
393403
const std::vector<Staff*>& systemObjectStaves = m_masterNotation->notation()->parts()->systemObjectStaves();
394-
SystemObjectGroupsByStaff systemObjects = collectSystemObjectGroups(systemObjectStaves);
404+
405+
SystemObjectGroupsByStaff systemObjects;
406+
if (showSystemObjectLayers) {
407+
systemObjects = collectSystemObjectGroups(systemObjectStaves);
408+
}
395409

396410
for (const Part* part : masterParts) {
397-
if (m_notation->isMaster()) {
398-
// Only show system object staves in master score
399-
// TODO: extend system object staves logic to parts
411+
if (showSystemObjectLayers) {
400412
for (Staff* staff : part->staves()) {
401413
if (muse::contains(systemObjectStaves, staff)) {
402414
m_rootItem->appendChild(buildSystemObjectsLayerItem(staff, systemObjects[staff]));
@@ -454,7 +466,12 @@ void LayoutPanelTreeModel::setLayoutPanelVisible(bool visible)
454466

455467
if (visible) {
456468
updateSelectedRows();
457-
updateSystemObjectLayers();
469+
470+
if (m_scoreChanged) {
471+
onScoreChanged();
472+
m_shouldUpdateSystemObjectLayers = true;
473+
updateSystemObjectLayers();
474+
}
458475
}
459476
}
460477

@@ -1051,6 +1068,10 @@ void LayoutPanelTreeModel::updateSystemObjectLayers()
10511068
return;
10521069
}
10531070

1071+
if (!shouldShowSystemObjectLayers()) {
1072+
return;
1073+
}
1074+
10541075
TRACEFUNC;
10551076

10561077
m_shouldUpdateSystemObjectLayers = false;

src/instrumentsscene/view/layoutpaneltreemodel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ private slots:
133133
void onMasterNotationChanged();
134134
void onNotationChanged();
135135

136+
bool shouldShowSystemObjectLayers() const;
137+
136138
void initPartOrders();
137139
void onBeforeChangeNotation();
138140
void setLoadingBlocked(bool blocked);
@@ -144,7 +146,7 @@ private slots:
144146
void setupNotationConnections();
145147

146148
void updateSelectedRows();
147-
void onScoreChanged(const mu::engraving::ScoreChangesRange& changes);
149+
void onScoreChanged(const mu::engraving::ScoreChangesRange& changes = {});
148150

149151
void clear();
150152
void deleteItems();
@@ -189,6 +191,7 @@ private slots:
189191
QHash<NotationKey, QList<muse::ID> > m_sortedPartIdList;
190192

191193
bool m_layoutPanelVisible = true;
194+
bool m_scoreChanged = false;
192195
bool m_shouldUpdateSystemObjectLayers = false;
193196

194197
bool m_dragInProgress = false;

src/instrumentsscene/view/parttreeitem.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,47 @@ void PartTreeItem::init(const notation::Part* masterPart)
4242
}
4343

4444
const Part* part = notation()->parts()->part(masterPart->id());
45-
bool partExists = part != nullptr;
46-
bool visible = partExists && part->show();
45+
m_partExists = part != nullptr;
46+
bool visible = m_partExists && part->show();
4747

48-
if (!partExists) {
48+
if (!m_partExists) {
4949
part = masterPart;
5050
}
5151

5252
setId(part->id());
5353
setTitle(part->instrument()->nameAsPlainText());
5454
setIsVisible(visible);
55-
setSettingsAvailable(partExists);
56-
setSettingsEnabled(partExists);
57-
setIsExpandable(partExists);
58-
setIsRemovable(partExists);
55+
setSettingsAvailable(m_partExists);
56+
setSettingsEnabled(m_partExists);
57+
setIsExpandable(m_partExists);
58+
setIsRemovable(m_partExists);
5959

6060
m_part = part;
61-
m_isInited = true;
61+
m_ignoreVisibilityChange = false;
6262
}
6363

6464
const Part* PartTreeItem::part() const
6565
{
6666
return m_part;
6767
}
6868

69+
void PartTreeItem::onScoreChanged(const mu::engraving::ScoreChangesRange&)
70+
{
71+
if (!m_part) {
72+
return;
73+
}
74+
75+
setTitle(m_part->instrument()->nameAsPlainText());
76+
77+
m_ignoreVisibilityChange = true;
78+
setIsVisible(m_partExists && m_part->show());
79+
m_ignoreVisibilityChange = false;
80+
}
81+
6982
void PartTreeItem::listenVisibilityChanged()
7083
{
7184
connect(this, &AbstractLayoutPanelTreeItem::isVisibleChanged, this, [this](bool isVisible) {
72-
if (!m_isInited) {
85+
if (m_ignoreVisibilityChange) {
7386
return;
7487
}
7588

src/instrumentsscene/view/parttreeitem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ class PartTreeItem : public AbstractLayoutPanelTreeItem, public muse::Injectable
5959
Q_INVOKABLE void resetAllFormatting();
6060

6161
private:
62+
void onScoreChanged(const mu::engraving::ScoreChangesRange& changes) override;
63+
6264
void listenVisibilityChanged();
6365
void createAndAddPart(const muse::ID& masterPartId);
6466

6567
size_t resolveNewPartIndex(const muse::ID& partId) const;
6668

6769
const notation::Part* m_part = nullptr;
68-
bool m_isInited = false;
70+
bool m_ignoreVisibilityChange = true;
71+
bool m_partExists = false;
6972
};
7073
}

src/notation/internal/notationparts.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void NotationParts::listenUndoStackChanges()
338338
updatePartsAndSystemObjectStaves();
339339

340340
m_undoStack->changesChannel().onReceive(this, [this](const ChangesRange& range) {
341-
if (range.changedTypes.empty()) {
341+
if (range.changedTypes.empty() || m_ignoreUndoStackChanges) {
342342
return;
343343
}
344344

@@ -385,6 +385,9 @@ void NotationParts::updatePartsAndSystemObjectStaves(const mu::engraving::ScoreC
385385
m_systemObjectStavesChanged.notify();
386386
}
387387

388+
std::vector<Staff*> removedStaves;
389+
std::vector<Staff*> addedStaves;
390+
388391
for (auto& pair : range.changedItems) {
389392
if (!pair.first || !pair.first->isStaff()) {
390393
continue;
@@ -393,11 +396,19 @@ void NotationParts::updatePartsAndSystemObjectStaves(const mu::engraving::ScoreC
393396
Staff* staff = toStaff(pair.first);
394397

395398
if (muse::contains(pair.second, CommandType::RemoveStaff)) {
396-
notifyAboutStaffRemoved(staff);
399+
removedStaves.push_back(staff);
397400
} else if (muse::contains(pair.second, CommandType::InsertStaff)) {
398-
notifyAboutStaffAdded(staff);
401+
addedStaves.push_back(staff);
399402
}
400403
}
404+
405+
for (Staff* staff : removedStaves) {
406+
notifyAboutStaffRemoved(staff);
407+
}
408+
409+
for (Staff* staff: addedStaves) {
410+
notifyAboutStaffAdded(staff);
411+
}
401412
}
402413

403414
void NotationParts::doSetScoreOrder(const ScoreOrder& order)
@@ -487,7 +498,13 @@ bool NotationParts::setVoiceVisible(const ID& staffId, int voiceIndex, bool visi
487498

488499
score()->excerpt()->setVoiceVisible(staff, voiceIndex, visible);
489500

501+
//! HACK: Excerpt::setVoiceVisible recreates the staff,
502+
//! so later in listenUndoStackChanges() we will call notifyAboutStaffRemoved() and notifyAboutStaffAdded(),
503+
//! which will result in the wrong UI state in the Layout panel.
504+
//! We should not recreate the staff here, only update it
505+
m_ignoreUndoStackChanges = true;
490506
apply();
507+
m_ignoreUndoStackChanges = false;
491508

492509
Staff* newStaff = staffModifiable(staffId);
493510
notifyAboutStaffChanged(newStaff);

src/notation/internal/notationparts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ class NotationParts : public INotationParts, public muse::async::Asyncable
150150
std::vector<Staff*> m_systemObjectStaves;
151151
muse::async::Notification m_systemObjectStavesChanged;
152152

153+
bool m_ignoreUndoStackChanges = false;
154+
153155
mutable muse::async::ChangedNotifier<const Part*> m_partChangedNotifier;
154156
mutable std::map<muse::ID, muse::async::ChangedNotifier<const Staff*> > m_staffChangedNotifierMap;
155157
};

0 commit comments

Comments
 (0)