Skip to content

Commit 5c72065

Browse files
Eismdylan.nicholson
authored andcommitted
Merge pull request #8821 from RomanPudashkin/instruments_panel_restoring_state
[MU4] Various fixes for the instruments panel
2 parents 07b1b84 + 134cd1a commit 5c72065

17 files changed

+123
-65
lines changed

src/engraving/libmscore/excerpt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void MasterScore::deleteExcerpt(Excerpt* excerpt)
437437
undo(new RemoveExcerpt(excerpt));
438438
}
439439

440-
void MasterScore::initExcerpt(Excerpt* excerpt, bool fakeUndo)
440+
void MasterScore::initAndAddExcerpt(Excerpt* excerpt, bool fakeUndo)
441441
{
442442
Score* score = new Score(masterScore());
443443
excerpt->setPartScore(score);
@@ -1371,7 +1371,6 @@ QList<Excerpt*> Excerpt::createExcerptsFromParts(const QList<Part*>& parts)
13711371

13721372
for (Part* part : parts) {
13731373
Excerpt* excerpt = new Excerpt(part->masterScore());
1374-
13751374
excerpt->parts().append(part);
13761375

13771376
for (int i = part->startTrack(), j = 0; i < part->endTrack(); ++i, ++j) {

src/engraving/libmscore/masterscore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class MasterScore : public Score
168168
void addExcerpt(Excerpt*, int index=-1);
169169
void removeExcerpt(Excerpt*);
170170
void deleteExcerpt(Excerpt*);
171-
void initExcerpt(Excerpt*, bool);
171+
void initAndAddExcerpt(Excerpt*, bool);
172172

173173
void setPlaybackScore(Score*);
174174
Score* playbackScore() { return _playbackScore; }

src/engraving/libmscore/score.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ Score* Score::clone()
441441
}
442442
}
443443

444-
masterScore()->initExcerpt(excerpt, true);
444+
masterScore()->initAndAddExcerpt(excerpt, true);
445445
masterScore()->removeExcerpt(excerpt);
446446

447447
return excerpt->partScore();

src/engraving/tests/tst_spanners.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void TestSpanners::spanners05()
310310
parts.append(score->parts().at(0));
311311

312312
Excerpt* ex = new Excerpt(score);
313-
score->initExcerpt(ex, false);
313+
score->initAndAddExcerpt(ex, false);
314314
ex->setTitle(parts.front()->longName());
315315
ex->setParts(parts);
316316

@@ -621,7 +621,7 @@ void TestSpanners::spanners14()
621621
parts.append(score->parts().at(0));
622622

623623
Excerpt* ex = new Excerpt(score);
624-
score->initExcerpt(ex, false);
624+
score->initAndAddExcerpt(ex, false);
625625

626626
ex->setTitle(parts.front()->longName());
627627
ex->setParts(parts);

src/framework/global/id.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ inline bool containsId(const IDList& list, const ID& id)
7070
{
7171
return std::find(list.cbegin(), list.cend(), id) != list.cend();
7272
}
73+
74+
inline uint qHash(const ID& id)
75+
{
76+
return ::qHash(id.toUint64());
77+
}
7378
}
7479

7580
#endif // MU_FRAMEWORK_ID_H

src/instrumentsscene/view/abstractinstrumentspaneltreeitem.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ void AbstractInstrumentsPanelTreeItem::setParentItem(AbstractInstrumentsPanelTre
100100
m_parent = parent;
101101
}
102102

103-
QList<AbstractInstrumentsPanelTreeItem*> AbstractInstrumentsPanelTreeItem::childrenItems() const
104-
{
105-
return m_children;
106-
}
107-
108103
bool AbstractInstrumentsPanelTreeItem::isEmpty() const
109104
{
110105
return m_children.isEmpty();
@@ -130,6 +125,15 @@ AbstractInstrumentsPanelTreeItem* AbstractInstrumentsPanelTreeItem::childAtRow(c
130125
return m_children.at(row);
131126
}
132127

128+
int AbstractInstrumentsPanelTreeItem::indexOf(const AbstractInstrumentsPanelTreeItem* item) const
129+
{
130+
IF_ASSERT_FAILED(item) {
131+
return -1;
132+
}
133+
134+
return m_children.indexOf(const_cast<AbstractInstrumentsPanelTreeItem*>(item));
135+
}
136+
133137
void AbstractInstrumentsPanelTreeItem::appendChild(AbstractInstrumentsPanelTreeItem* child)
134138
{
135139
if (!child) {
@@ -211,7 +215,7 @@ int AbstractInstrumentsPanelTreeItem::row() const
211215
return 0;
212216
}
213217

214-
return parentItem()->childrenItems().indexOf(const_cast<AbstractInstrumentsPanelTreeItem*>(this));
218+
return parentItem()->indexOf(this);
215219
}
216220

217221
void AbstractInstrumentsPanelTreeItem::setType(InstrumentsTreeItemType::ItemType type)

src/instrumentsscene/view/abstractinstrumentspaneltreeitem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ class AbstractInstrumentsPanelTreeItem : public QObject
6464
AbstractInstrumentsPanelTreeItem* parentItem() const;
6565
void setParentItem(AbstractInstrumentsPanelTreeItem* parent);
6666

67-
QList<AbstractInstrumentsPanelTreeItem*> childrenItems() const;
6867
bool isEmpty() const;
6968

7069
AbstractInstrumentsPanelTreeItem* childAtId(const ID& id) const;
7170
AbstractInstrumentsPanelTreeItem* childAtRow(const int row) const;
71+
int indexOf(const AbstractInstrumentsPanelTreeItem* item) const;
7272

7373
void appendChild(AbstractInstrumentsPanelTreeItem* child);
7474
void insertChild(AbstractInstrumentsPanelTreeItem* child, const int beforeRow);

src/instrumentsscene/view/instrumentspaneltreemodel.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ void InstrumentsPanelTreeModel::setupStavesConnections(const ID& stavesPartId)
136136
});
137137
}
138138

139+
void InstrumentsPanelTreeModel::listenSelectionChanged()
140+
{
141+
m_notation->interaction()->selectionChanged().onNotify(this, [this]() {
142+
std::vector<Element*> selectedElements = m_notation->interaction()->selection()->elements();
143+
144+
if (selectedElements.empty()) {
145+
m_selectionModel->clear();
146+
return;
147+
}
148+
149+
QSet<ID> selectedPartIdSet;
150+
for (const Element* element : selectedElements) {
151+
selectedPartIdSet << element->part()->id();
152+
}
153+
154+
for (const ID& selectedPartId : selectedPartIdSet) {
155+
AbstractInstrumentsPanelTreeItem* item = m_rootItem->childAtId(selectedPartId);
156+
157+
if (item) {
158+
m_selectionModel->select(createIndex(item->row(), 0, item));
159+
}
160+
}
161+
});
162+
}
163+
139164
void InstrumentsPanelTreeModel::clear()
140165
{
141166
beginResetModel();
@@ -174,6 +199,7 @@ void InstrumentsPanelTreeModel::load()
174199
endResetModel();
175200

176201
setupPartsConnections();
202+
listenSelectionChanged();
177203

178204
emit isEmptyChanged();
179205
emit isAddingAvailableChanged(true);

src/instrumentsscene/view/instrumentspaneltreemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private slots:
110110

111111
void setupPartsConnections();
112112
void setupStavesConnections(const ID& stavesPartId);
113+
void listenSelectionChanged();
113114

114115
void clear();
115116
void deleteItems();

src/notation/iexcerptnotation.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ using IExcerptNotationPtr = std::shared_ptr<IExcerptNotation>;
3232
class IExcerptNotation
3333
{
3434
public:
35+
virtual ~IExcerptNotation() = default;
3536

3637
virtual bool isInited() const = 0;
3738

38-
virtual void setTitle(const QString& title) = 0;
3939
virtual QString title() const = 0;
40+
virtual void setTitle(const QString& title) = 0;
4041

4142
virtual INotationPtr notation() = 0;
4243
virtual IExcerptNotationPtr clone() const = 0;

0 commit comments

Comments
 (0)