Skip to content

Commit

Permalink
one global connect to undoStack()->changesChannel()
Browse files Browse the repository at this point in the history
instead of reconnecting to it inside each SystemObjectsLayerTreeItem
  • Loading branch information
RomanPudashkin committed Feb 21, 2025
1 parent ecad2bc commit 4f49e8c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/instrumentsscene/view/abstractlayoutpaneltreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ void AbstractLayoutPanelTreeItem::removeChildren(int row, int count, bool delete
}
}

void AbstractLayoutPanelTreeItem::onScoreChanged(const mu::engraving::ScoreChangesRange&)
{
}

AbstractLayoutPanelTreeItem* AbstractLayoutPanelTreeItem::parentItem() const
{
return m_parent;
Expand Down
2 changes: 2 additions & 0 deletions src/instrumentsscene/view/abstractlayoutpaneltreeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class AbstractLayoutPanelTreeItem : public QObject

virtual void removeChildren(int row, int count = 1, bool deleteChild = false);

virtual void onScoreChanged(const mu::engraving::ScoreChangesRange& changes);

AbstractLayoutPanelTreeItem* parentItem() const;
void setParentItem(AbstractLayoutPanelTreeItem* parent);

Expand Down
19 changes: 17 additions & 2 deletions src/instrumentsscene/view/layoutpaneltreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,15 @@ void LayoutPanelTreeModel::setupStavesConnections(const muse::ID& stavesPartId)
});
}

void LayoutPanelTreeModel::listenNotationSelectionChanged()
void LayoutPanelTreeModel::setupNotationConnections()
{
m_notation->interaction()->selectionChanged().onNotify(this, [this]() {
updateSelectedRows();
});

m_notation->undoStack()->changesChannel().onReceive(this, [this](const mu::engraving::ScoreChangesRange& changes) {
onScoreChanged(changes);
});
}

void LayoutPanelTreeModel::updateSelectedRows()
Expand Down Expand Up @@ -307,6 +311,17 @@ void LayoutPanelTreeModel::updateSelectedRows()
}
}

void LayoutPanelTreeModel::onScoreChanged(const mu::engraving::ScoreChangesRange& changes)
{
if (!m_rootItem) {
return;
}

for (AbstractLayoutPanelTreeItem* item : m_rootItem->childItems()) {
item->onScoreChanged(changes);
}
}

void LayoutPanelTreeModel::clear()
{
TRACEFUNC;
Expand Down Expand Up @@ -362,7 +377,7 @@ void LayoutPanelTreeModel::load()
endResetModel();

setupPartsConnections();
listenNotationSelectionChanged();
setupNotationConnections();

emit isEmptyChanged();
emit isAddingAvailableChanged(true);
Expand Down
4 changes: 3 additions & 1 deletion src/instrumentsscene/view/layoutpaneltreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ private slots:

void setupPartsConnections();
void setupStavesConnections(const muse::ID& stavesPartId);
void listenNotationSelectionChanged();
void setupNotationConnections();

void updateSelectedRows();
void onScoreChanged(const mu::engraving::ScoreChangesRange& changes);

void clear();
void deleteItems();
Expand Down
6 changes: 1 addition & 5 deletions src/instrumentsscene/view/systemobjectslayertreeitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ void SystemObjectsLayerTreeItem::init(const Staff* staff, const SystemObjectGrou

updateState();

notation()->undoStack()->changesChannel().onReceive(this, [this](const ChangesRange& changes) {
onUndoStackChanged(changes);
});

connect(this, &AbstractLayoutPanelTreeItem::isVisibleChanged, this, [this](bool isVisible) {
onVisibleChanged(isVisible);
});
Expand Down Expand Up @@ -144,7 +140,7 @@ bool SystemObjectsLayerTreeItem::canAcceptDrop(const QVariant&) const
return false;
}

void SystemObjectsLayerTreeItem::onUndoStackChanged(const mu::engraving::ScoreChangesRange& changes)
void SystemObjectsLayerTreeItem::onScoreChanged(const mu::engraving::ScoreChangesRange& changes)
{
if (muse::contains(changes.changedPropertyIdSet, Pid::TRACK)) {
updateStaff();
Expand Down
5 changes: 2 additions & 3 deletions src/instrumentsscene/view/systemobjectslayertreeitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
#pragma once

#include "abstractlayoutpaneltreeitem.h"
#include "async/asyncable.h"

#include "notation/inotationparts.h"

#include "layoutpanelutils.h"

namespace mu::instrumentsscene {
class SystemObjectsLayerTreeItem : public AbstractLayoutPanelTreeItem, public muse::async::Asyncable
class SystemObjectsLayerTreeItem : public AbstractLayoutPanelTreeItem
{
Q_OBJECT

Expand All @@ -47,7 +46,7 @@ class SystemObjectsLayerTreeItem : public AbstractLayoutPanelTreeItem, public mu
Q_INVOKABLE bool canAcceptDrop(const QVariant& item) const override;

private:
void onUndoStackChanged(const mu::engraving::ScoreChangesRange& changes);
void onScoreChanged(const mu::engraving::ScoreChangesRange& changes) override;
void onVisibleChanged(bool isVisible);

bool addSystemObject(mu::engraving::EngravingItem* obj);
Expand Down

0 comments on commit 4f49e8c

Please sign in to comment.