From b5aca6085d38db6979409e58bb263d8ff84b0a0f Mon Sep 17 00:00:00 2001 From: Ash-86 <108089527+Ash-86@users.noreply.github.com> Date: Thu, 10 Sep 2026 18:04:59 -0300 Subject: [PATCH] restore scoreStateChanged --- src/engraving/api/v1/qmlpluginapi.cpp | 60 +++++++++++++++++++++++++++ src/engraving/api/v1/qmlpluginapi.h | 9 +++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/engraving/api/v1/qmlpluginapi.cpp b/src/engraving/api/v1/qmlpluginapi.cpp index 92dc9791c486f..0f192e27ed55d 100644 --- a/src/engraving/api/v1/qmlpluginapi.cpp +++ b/src/engraving/api/v1/qmlpluginapi.cpp @@ -33,6 +33,11 @@ #include "notation/inotation.h" #include "notation/inotationelements.h" // IWYU pragma: keep +#include "notation/inotationinteraction.h" +#include "notation/inotationundostack.h" +#include "notation/inotationparts.h" +#include "project/inotationproject.h" +#include "notation/imasternotation.h" // api #include "engravingapiv1.h" @@ -236,6 +241,8 @@ void PluginAPI::setup(QQmlEngine* e) engravingApi->setApi(this); m_engine = engravingApi->engine(); + + initScoreStateNotifications(); } PluginAPI::PluginAPI(QQuickItem* parent) @@ -495,6 +502,8 @@ apiv1::Fraction* PluginAPI::fractionFromTicks(int ticks) const void PluginAPI::quit() { + m_notationSubscriptions.async_disconnectAll(); + async_disconnectAll(); emit closeRequested(); m_closeRequested.notify(); } @@ -662,3 +671,54 @@ IntervalWrapper* PluginAPI::intervalFromOrnamentInterval(OrnamentIntervalWrapper { return wrap(mu::engraving::Interval::fromOrnamentInterval(o->ornamentInterval())); } + +void PluginAPI::initScoreStateNotifications() +{ + context()->currentNotationChanged().onNotify(this, [this]() { + subscribeToNotationState(context()->currentNotation()); + }); + + subscribeToNotationState(context()->currentNotation()); +} + +void PluginAPI::subscribeToNotationState(notation::INotationPtr n) +{ + m_notationSubscriptions.async_disconnectAll(); + + if (!n) { + return; + } + + auto emitState = [this](bool selection, bool undoRedo, bool instruments, bool excerpts) { + QMap state; + state["selectionChanged"] = selection; + state["undoRedo"] = undoRedo; + state["instrumentsChanged"] = instruments; + state["excerptsChanged"] = excerpts; + emit scoreStateChanged(state); + }; + + if (n->interaction()) { + n->interaction()->selectionChanged().onNotify(&m_notationSubscriptions, [emitState]() { + emitState(true, false, false, false); + }); + } + + if (n->undoStack()) { + n->undoStack()->stackChanged().onNotify(&m_notationSubscriptions, [emitState]() { + emitState(false, true, false, false); + }); + } + + if (n->parts()) { + n->parts()->partsChanged().onNotify(&m_notationSubscriptions, [emitState]() { + emitState(false, false, true, false); + }); + } + + if (n->project() && n->project()->masterNotation()) { + n->project()->masterNotation()->excerptsChanged().onNotify(&m_notationSubscriptions, [emitState]() { + emitState(false, false, false, true); + }); + } +} diff --git a/src/engraving/api/v1/qmlpluginapi.h b/src/engraving/api/v1/qmlpluginapi.h index bfe4a5f7f4847..1f44e158df321 100644 --- a/src/engraving/api/v1/qmlpluginapi.h +++ b/src/engraving/api/v1/qmlpluginapi.h @@ -24,7 +24,7 @@ #include #include "extensions/api/v1/ipluginapiv1.h" - +#include "async/asyncable.h" #include "global/api/apiutils.h" #include "modularity/ioc.h" @@ -92,7 +92,7 @@ class Score; // @P scores array[mu::engraving::Score] all currently open scores (read only) //--------------------------------------------------------- -class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV1, public muse::Contextable +class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV1, public muse::Contextable, public muse::async::Asyncable { Q_OBJECT @@ -592,6 +592,11 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV private: mu::engraving::Score* currentScore() const; + void initScoreStateNotifications(); + void subscribeToNotationState(notation::INotationPtr notation); + + struct NotationSubscriptions : public muse::async::Asyncable {}; + NotationSubscriptions m_notationSubscriptions; muse::api::IApiEngine* m_engine = nullptr; QString m_pluginType;