diff --git a/src/converter/api/converterapi.h b/src/converter/api/converterapi.h index 93d7767dea473..d4da8d3586d07 100644 --- a/src/converter/api/converterapi.h +++ b/src/converter/api/converterapi.h @@ -35,9 +35,9 @@ class ConverterApi : public muse::api::ApiObject, public muse::async::Asyncable { Q_OBJECT - muse::Inject interactive; - muse::Inject fileSystem; - muse::Inject converter; + muse::Inject interactive = { this }; + muse::Inject fileSystem = { this }; + muse::Inject converter = { this }; public: explicit ConverterApi(muse::api::IApiEngine* e); diff --git a/src/framework/audio/engine/internal/enginecontroller.cpp b/src/framework/audio/engine/internal/enginecontroller.cpp index 6238737aa5d47..24528f2509f53 100644 --- a/src/framework/audio/engine/internal/enginecontroller.cpp +++ b/src/framework/audio/engine/internal/enginecontroller.cpp @@ -61,8 +61,9 @@ static muse::modularity::ModulesIoC* ioc() return muse::modularity::globalIoc(); } -EngineController::EngineController(std::shared_ptr rpcChannel) - : m_rpcChannel(rpcChannel) +EngineController::EngineController(std::shared_ptr rpcChannel, + const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_rpcChannel(rpcChannel) { m_rpcChannel->onMethod(rpc::Method::EngineInit, [this](const rpc::Msg& msg) { OutputSpec spec; @@ -89,7 +90,7 @@ void EngineController::registerExports() m_configuration = std::make_shared(); m_audioEngine = std::make_shared(); m_playback = std::make_shared(); - m_rpcController = std::make_shared(); + m_rpcController = std::make_shared(iocContext()); m_fxResolver = std::make_shared(); m_synthResolver = std::make_shared(); m_soundFontRepository = std::make_shared(); diff --git a/src/framework/audio/engine/internal/enginecontroller.h b/src/framework/audio/engine/internal/enginecontroller.h index 20017864ae3c9..7fb957c4e6c9f 100644 --- a/src/framework/audio/engine/internal/enginecontroller.h +++ b/src/framework/audio/engine/internal/enginecontroller.h @@ -23,6 +23,8 @@ #include +#include "global/modularity/ioc.h" + #include "../ienginecontroller.h" namespace muse::audio::rpc { @@ -45,10 +47,10 @@ class WebAudioChannel; class EnginePlayback; class EngineRpcController; -class EngineController : public IEngineController +class EngineController : public IEngineController, public muse::Injectable { public: - EngineController(std::shared_ptr rpcChannel); + EngineController(std::shared_ptr rpcChannel, const muse::modularity::ContextPtr& iocCtx); void registerExports() override; void onStartRunning() override; diff --git a/src/framework/audio/engine/internal/enginerpccontroller.h b/src/framework/audio/engine/internal/enginerpccontroller.h index 55c7129921924..01c499b405d75 100644 --- a/src/framework/audio/engine/internal/enginerpccontroller.h +++ b/src/framework/audio/engine/internal/enginerpccontroller.h @@ -31,16 +31,17 @@ #include "../iaudioengineconfiguration.h" namespace muse::audio::engine { -class EngineRpcController : public async::Asyncable +class EngineRpcController : public async::Asyncable, public muse::Injectable { - Inject channel; - Inject audioEngine; - Inject playback; - Inject soundFontRepository; - Inject configuration; + Inject channel = { this }; + Inject audioEngine = { this }; + Inject playback = { this }; + Inject soundFontRepository = { this }; + Inject configuration = { this }; public: - EngineRpcController() = default; + EngineRpcController(const muse::modularity::ContextPtr& iocCtx) + : Injectable(iocCtx) {} void init(); void deinit(); diff --git a/src/framework/audio/main/audiomodule.cpp b/src/framework/audio/main/audiomodule.cpp index 87c35f59164b5..0d4c4b7ef2be6 100644 --- a/src/framework/audio/main/audiomodule.cpp +++ b/src/framework/audio/main/audiomodule.cpp @@ -62,7 +62,7 @@ std::string AudioModule::moduleName() const void AudioModule::registerExports() { m_configuration = std::make_shared(iocContext()); - m_actionsController = std::make_shared(); + m_actionsController = std::make_shared(iocContext()); m_mainPlayback = std::make_shared(iocContext()); m_audioDriverController = std::make_shared(iocContext()); @@ -71,10 +71,10 @@ void AudioModule::registerExports() m_soundFontController = std::make_shared(); #else m_rpcChannel = std::make_shared(); - m_soundFontController = std::make_shared(); + m_soundFontController = std::make_shared(iocContext()); #endif - m_startAudioController = std::make_shared(m_rpcChannel); + m_startAudioController = std::make_shared(m_rpcChannel, iocContext()); ioc()->registerExport(moduleName(), m_configuration); ioc()->registerExport(moduleName(), m_startAudioController); diff --git a/src/framework/audio/main/internal/audioactionscontroller.h b/src/framework/audio/main/internal/audioactionscontroller.h index 700b167d894e4..8a2926e5f9208 100644 --- a/src/framework/audio/main/internal/audioactionscontroller.h +++ b/src/framework/audio/main/internal/audioactionscontroller.h @@ -32,14 +32,15 @@ #include "audio/common/workmode.h" namespace muse::audio { -class AudioActionsController : public actions::Actionable +class AudioActionsController : public actions::Actionable, public muse::Injectable { - Inject dispatcher; - Inject application; - Inject interactive; + Inject dispatcher = { this }; + Inject application = { this }; + Inject interactive = { this }; public: - AudioActionsController() = default; + AudioActionsController(const muse::modularity::ContextPtr& iocCtx) + : Injectable(iocCtx) {} void init(); diff --git a/src/framework/audio/main/internal/playback.cpp b/src/framework/audio/main/internal/playback.cpp index 60c45b574b4a4..ca029b20e97b2 100644 --- a/src/framework/audio/main/internal/playback.cpp +++ b/src/framework/audio/main/internal/playback.cpp @@ -211,7 +211,7 @@ Channel Playback::sequenceRemoved() const IPlayerPtr Playback::player(const TrackSequenceId id) const { - std::shared_ptr p = std::make_shared(id); + std::shared_ptr p = std::make_shared(id, iocContext()); p->init(); return p; } diff --git a/src/framework/audio/main/internal/playback.h b/src/framework/audio/main/internal/playback.h index c5bbda55b66da..4a2eacdbf4b1d 100644 --- a/src/framework/audio/main/internal/playback.h +++ b/src/framework/audio/main/internal/playback.h @@ -34,8 +34,8 @@ namespace muse::audio { class Playback : public IPlayback, public Injectable, public async::Asyncable { - Inject channel; - Inject startAudioController; + Inject channel = { this }; + Inject startAudioController = { this }; public: Playback(const muse::modularity::ContextPtr& iocCtx) diff --git a/src/framework/audio/main/internal/player.cpp b/src/framework/audio/main/internal/player.cpp index 945635712d1e2..0490745aed14e 100644 --- a/src/framework/audio/main/internal/player.cpp +++ b/src/framework/audio/main/internal/player.cpp @@ -31,8 +31,8 @@ using namespace muse::async; using namespace muse::audio; using namespace muse::audio::rpc; -Player::Player(const TrackSequenceId sequenceId) - : m_sequenceId(sequenceId) +Player::Player(const TrackSequenceId sequenceId, const muse::modularity::ContextPtr& iocCtx) + : Injectable(iocCtx), m_sequenceId(sequenceId) { } diff --git a/src/framework/audio/main/internal/player.h b/src/framework/audio/main/internal/player.h index 5206df20142b1..c5b19226227be 100644 --- a/src/framework/audio/main/internal/player.h +++ b/src/framework/audio/main/internal/player.h @@ -31,12 +31,12 @@ #include "audio/common/rpc/irpcchannel.h" namespace muse::audio { -class Player : public IPlayer, public async::Asyncable +class Player : public IPlayer, public async::Asyncable, public Injectable { - Inject channel; + Inject channel = { this }; public: - Player(const TrackSequenceId sequenceId); + Player(const TrackSequenceId sequenceId, const muse::modularity::ContextPtr& iocCtx); void init(); diff --git a/src/framework/audio/main/internal/startaudiocontroller.cpp b/src/framework/audio/main/internal/startaudiocontroller.cpp index e4a4088f740c1..6c388012a253d 100644 --- a/src/framework/audio/main/internal/startaudiocontroller.cpp +++ b/src/framework/audio/main/internal/startaudiocontroller.cpp @@ -56,11 +56,12 @@ static void measureInputLag(const float* buf, const size_t size) } } -StartAudioController::StartAudioController(std::shared_ptr rpcChannel) - : m_rpcChannel(rpcChannel) +StartAudioController::StartAudioController(std::shared_ptr rpcChannel, + const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_rpcChannel(rpcChannel) { #ifndef Q_OS_WASM - m_engineController = std::make_shared(rpcChannel); + m_engineController = std::make_shared(rpcChannel, iocCtx); #endif } diff --git a/src/framework/audio/main/internal/startaudiocontroller.h b/src/framework/audio/main/internal/startaudiocontroller.h index 8005c993ad6b9..204aa9049b2cd 100644 --- a/src/framework/audio/main/internal/startaudiocontroller.h +++ b/src/framework/audio/main/internal/startaudiocontroller.h @@ -39,14 +39,14 @@ class GeneralAudioWorker; namespace muse::audio { class AlignmentBuffer; -class StartAudioController : public IStartAudioController, public async::Asyncable +class StartAudioController : public IStartAudioController, public muse::Injectable, public async::Asyncable { - Inject configuration; - Inject audioDriverController; - Inject soundFontController; + Inject configuration = { this }; + Inject audioDriverController = { this }; + Inject soundFontController = { this }; public: - StartAudioController(std::shared_ptr rpcChannel); + StartAudioController(std::shared_ptr rpcChannel, const muse::modularity::ContextPtr& iocCtx); void registerExports(); void init(); diff --git a/src/framework/audio/main/platform/general/generalsoundfontcontroller.cpp b/src/framework/audio/main/platform/general/generalsoundfontcontroller.cpp index 55fce46bfa79c..c66c6194a2b9d 100644 --- a/src/framework/audio/main/platform/general/generalsoundfontcontroller.cpp +++ b/src/framework/audio/main/platform/general/generalsoundfontcontroller.cpp @@ -32,6 +32,11 @@ using namespace muse::audio; using namespace muse::audio::rpc; using namespace muse::audio::synth; +GeneralSoundFontController::GeneralSoundFontController(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) +{ +} + void GeneralSoundFontController::loadSoundFonts() { configuration()->soundFontDirectoriesChanged().onReceive(this, [this](const io::paths_t&) { diff --git a/src/framework/audio/main/platform/general/generalsoundfontcontroller.h b/src/framework/audio/main/platform/general/generalsoundfontcontroller.h index 167b367d9dc5e..58f9387c37430 100644 --- a/src/framework/audio/main/platform/general/generalsoundfontcontroller.h +++ b/src/framework/audio/main/platform/general/generalsoundfontcontroller.h @@ -33,15 +33,15 @@ #include "audio/common/rpc/irpcchannel.h" namespace muse::audio { -class GeneralSoundFontController : public ISoundFontController, public async::Asyncable +class GeneralSoundFontController : public ISoundFontController, public async::Asyncable, public muse::Injectable { - Inject interactive; - Inject configuration; - Inject fileSystem; - Inject channel; + Inject interactive = { this }; + Inject configuration = { this }; + Inject fileSystem = { this }; + Inject channel = { this }; public: - GeneralSoundFontController() = default; + GeneralSoundFontController(const muse::modularity::ContextPtr& iocCtx); void loadSoundFonts() override; diff --git a/src/framework/audioplugins/audiopluginsmodule.cpp b/src/framework/audioplugins/audiopluginsmodule.cpp index 0bb3bb990e66c..8d2043bc13ebb 100644 --- a/src/framework/audioplugins/audiopluginsmodule.cpp +++ b/src/framework/audioplugins/audiopluginsmodule.cpp @@ -46,7 +46,7 @@ std::string AudioPluginsModule::moduleName() const void AudioPluginsModule::registerExports() { - m_configuration = std::make_shared(); + m_configuration = std::make_shared(iocContext()); m_registerAudioPluginsScenario = std::make_shared(iocContext()); ioc()->registerExport(moduleName(), m_configuration); diff --git a/src/framework/audioplugins/internal/audiopluginsconfiguration.h b/src/framework/audioplugins/internal/audiopluginsconfiguration.h index ef91893c017e6..5ba72a4add9cd 100644 --- a/src/framework/audioplugins/internal/audiopluginsconfiguration.h +++ b/src/framework/audioplugins/internal/audiopluginsconfiguration.h @@ -28,12 +28,13 @@ #include "global/iglobalconfiguration.h" namespace muse::audioplugins { -class AudioPluginsConfiguration : public IAudioPluginsConfiguration +class AudioPluginsConfiguration : public IAudioPluginsConfiguration, public muse::Injectable { - muse::Inject globalConfiguration; + muse::Inject globalConfiguration = { this }; public: - AudioPluginsConfiguration() = default; + AudioPluginsConfiguration(const muse::modularity::ContextPtr& iocCtx) + : Injectable(iocCtx) {} io::path_t knownAudioPluginsFilePath() const override; }; diff --git a/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.cpp b/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.cpp index b0570802edbec..8d412a6cc63d2 100644 --- a/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.cpp +++ b/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.cpp @@ -20,12 +20,15 @@ * along with this program. If not, see . */ #include "actionsviewmodel.h" +#include "modularity/ioc.h" +#include using namespace muse::diagnostics; using namespace muse::actions; using namespace muse::ui; -ActionsViewModel::ActionsViewModel() +ActionsViewModel::ActionsViewModel(QObject* parent) + : QAbstractListModel(parent), muse::Injectable(muse::iocCtxForQmlObject(parent)) { } diff --git a/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.h b/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.h index c906b53e907a0..9d13c730466d9 100644 --- a/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.h +++ b/src/framework/diagnostics/qml/Muse/Diagnostics/actionsviewmodel.h @@ -29,17 +29,16 @@ #include "ui/iuiactionsregister.h" namespace muse::diagnostics { -class ActionsViewModel : public QAbstractListModel +class ActionsViewModel : public QAbstractListModel, public muse::Injectable { Q_OBJECT - QML_ELEMENT - Inject actionsDispatcher; - Inject uiActionsRegister; + Inject actionsDispatcher = { this }; + Inject uiActionsRegister = { this }; public: - ActionsViewModel(); + ActionsViewModel(QObject* parent = nullptr); Q_INVOKABLE void load(); Q_INVOKABLE void find(const QString& str); diff --git a/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.cpp b/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.cpp index 4af4e8b900fc5..7b61e5a2a918b 100644 --- a/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.cpp +++ b/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.cpp @@ -23,10 +23,12 @@ #include #include +#include using namespace muse::diagnostics; -GraphicsInfoModel::GraphicsInfoModel() +GraphicsInfoModel::GraphicsInfoModel(QObject* parent) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.h b/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.h index 4b868d7443fd0..7bdc2c5b6621d 100644 --- a/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.h +++ b/src/framework/diagnostics/qml/Muse/Diagnostics/system/graphicsinfomodel.h @@ -28,18 +28,17 @@ #include "ui/iuiengine.h" namespace muse::diagnostics { -class GraphicsInfoModel : public QObject +class GraphicsInfoModel : public QObject, public muse::Injectable { Q_OBJECT - - Q_PROPERTY(QString info READ info NOTIFY infoChanged FINAL) - QML_ELEMENT - muse::Inject uiengine; + muse::Inject uiengine = { this }; + + Q_PROPERTY(QString info READ info NOTIFY infoChanged FINAL) public: - GraphicsInfoModel(); + GraphicsInfoModel(QObject* parent = nullptr); QString info() const; @@ -50,6 +49,7 @@ class GraphicsInfoModel : public QObject void infoChanged(); private: + QString m_info; }; } diff --git a/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.cpp b/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.cpp index 62271e17e47ff..83fbebdfff7bf 100644 --- a/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.cpp +++ b/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.cpp @@ -46,7 +46,7 @@ static const QHash TYPES_MAP = { }; ApiDumpModel::ApiDumpModel(QObject* parent) - : QAbstractListModel(parent) + : QAbstractListModel(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.h b/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.h index e178baa46e348..e19c00499b02a 100644 --- a/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.h +++ b/src/framework/extensions/qml/Muse/Extensions/devtools/apidumpmodel.h @@ -30,13 +30,12 @@ #include "global/api/iapiregister.h" namespace muse::extensions { -class ApiDumpModel : public QAbstractListModel +class ApiDumpModel : public QAbstractListModel, public muse::Injectable { Q_OBJECT - QML_ELEMENT - muse::Inject apiRegister; + muse::Inject apiRegister = { this }; public: ApiDumpModel(QObject* parent = nullptr); diff --git a/src/framework/global/internal/baseapplication.cpp b/src/framework/global/internal/baseapplication.cpp index 3755e9cc471c2..d41802fb9d3fa 100644 --- a/src/framework/global/internal/baseapplication.cpp +++ b/src/framework/global/internal/baseapplication.cpp @@ -112,7 +112,7 @@ String BaseApplication::appRevision() } BaseApplication::BaseApplication(const modularity::ContextPtr& ctx) - : m_iocContext(ctx) + : muse::Injectable(ctx), m_iocContext(ctx) { } diff --git a/src/framework/global/internal/baseapplication.h b/src/framework/global/internal/baseapplication.h index ea1fe6877577d..88b004d8f5096 100644 --- a/src/framework/global/internal/baseapplication.h +++ b/src/framework/global/internal/baseapplication.h @@ -28,9 +28,9 @@ #include "global/itickerprovider.h" namespace muse { -class BaseApplication : public IApplication +class BaseApplication : public IApplication, public muse::Injectable { - Inject tickerProvider; + Inject tickerProvider = { this }; public: BaseApplication(const modularity::ContextPtr& ctx); diff --git a/src/framework/ui/qml/Muse/Ui/qmlaccessible.h b/src/framework/ui/qml/Muse/Ui/qmlaccessible.h index 268b80f338f53..d94943c54d5eb 100644 --- a/src/framework/ui/qml/Muse/Ui/qmlaccessible.h +++ b/src/framework/ui/qml/Muse/Ui/qmlaccessible.h @@ -105,7 +105,7 @@ class AccessibleItem : public QObject, public QQmlParserStatus, public accessibi Q_INTERFACES(QQmlParserStatus) - Inject accessibilityController; + Inject accessibilityController = { this }; public: STATE_PROPERTY(enabled, State::Enabled) diff --git a/src/framework/ui/qml/Muse/Ui/qmldrag.cpp b/src/framework/ui/qml/Muse/Ui/qmldrag.cpp index 2f65200a2a33e..816bace46edef 100644 --- a/src/framework/ui/qml/Muse/Ui/qmldrag.cpp +++ b/src/framework/ui/qml/Muse/Ui/qmldrag.cpp @@ -24,7 +24,7 @@ using namespace muse::ui; QmlDrag::QmlDrag(QObject* parent) - : QObject(parent) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { m_data = std::make_shared(); } diff --git a/src/framework/ui/qml/Muse/Ui/qmldrag.h b/src/framework/ui/qml/Muse/Ui/qmldrag.h index 49b7bcf8fa20c..bd6cdf3c1ca67 100644 --- a/src/framework/ui/qml/Muse/Ui/qmldrag.h +++ b/src/framework/ui/qml/Muse/Ui/qmldrag.h @@ -28,7 +28,7 @@ #include "idragcontroller.h" namespace muse::ui { -class QmlDrag : public QObject +class QmlDrag : public QObject, public muse::Injectable { Q_OBJECT @@ -38,7 +38,7 @@ class QmlDrag : public QObject QML_NAMED_ELEMENT(CppDrag) QML_ATTACHED(QmlDrag) - Inject controller; + Inject controller = { this }; public: QmlDrag(QObject* parent = nullptr); diff --git a/src/framework/ui/view/qmltranslation.h b/src/framework/ui/view/qmltranslation.h index 0570e8f3277a9..ab22afb801fab 100644 --- a/src/framework/ui/view/qmltranslation.h +++ b/src/framework/ui/view/qmltranslation.h @@ -29,7 +29,7 @@ class QmlTranslation : public QObject { Q_OBJECT public: - QmlTranslation(QObject* parent); + QmlTranslation(QObject* parent = nullptr); Q_INVOKABLE QString translate(const QString& context, const QString& text, const QString& disambiguation = QString(), int n = -1) const; }; diff --git a/src/importexport/lyricsexport/internal/lrcwriter.h b/src/importexport/lyricsexport/internal/lrcwriter.h index dd439f894a086..862115989ee29 100644 --- a/src/importexport/lyricsexport/internal/lrcwriter.h +++ b/src/importexport/lyricsexport/internal/lrcwriter.h @@ -31,12 +31,17 @@ class Score; } namespace mu::iex::lrcexport { -class LRCWriter : public project::INotationWriter +class LRCWriter : public project::INotationWriter, public muse::Injectable { public: - INJECT_STATIC(mu::iex::lrcexport::ILyricsExportConfiguration, configuration) + muse::Inject configuration = { this }; public: + LRCWriter(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + // Interface implementation std::vector supportedUnitTypes() const override; bool supportsUnitType(UnitType) const override; diff --git a/src/importexport/lyricsexport/lyricsexportmodule.cpp b/src/importexport/lyricsexport/lyricsexportmodule.cpp index 9d44601ac6a71..a55a99930cc06 100644 --- a/src/importexport/lyricsexport/lyricsexportmodule.cpp +++ b/src/importexport/lyricsexport/lyricsexportmodule.cpp @@ -48,7 +48,7 @@ void LyricsExportModule::resolveImports() { auto writers = ioc()->resolve(moduleName()); if (writers) { - writers->reg({ "lrc" }, std::make_shared()); + writers->reg({ "lrc" }, std::make_shared(iocContext())); } } diff --git a/src/importexport/lyricsexport/tests/lrc_tests.cpp b/src/importexport/lyricsexport/tests/lrc_tests.cpp index 0421d4e6ac34c..efffb06fac85b 100644 --- a/src/importexport/lyricsexport/tests/lrc_tests.cpp +++ b/src/importexport/lyricsexport/tests/lrc_tests.cpp @@ -46,7 +46,7 @@ void Lrc_Tests::lrcTest(const char* file, bool enhancedLrc) String fileName = String::fromUtf8(file); auto exportFunc = [](Score* score, const muse::io::path_t& path, bool enhancedLrc) -> bool { - LRCWriter lrcWriter; + LRCWriter lrcWriter(nullptr); return lrcWriter.writeScore(score, path, enhancedLrc); }; diff --git a/src/importexport/mei/internal/meiconverter.h b/src/importexport/mei/internal/meiconverter.h index 4be2a9317ed23..5650454fa933c 100644 --- a/src/importexport/mei/internal/meiconverter.h +++ b/src/importexport/mei/internal/meiconverter.h @@ -87,8 +87,8 @@ enum ElisionType { class Convert { // The fallback font is used to convert smufl codes (char32_t) to engraving::SymId - INJECT_STATIC(engraving::IEngravingFontsProvider, engravingFonts) - INJECT_STATIC(engraving::IEngravingConfiguration, engravingConfiguration) + static inline muse::GlobalInject engravingFonts; + static inline muse::GlobalInject engravingConfiguration; public: /** diff --git a/src/importexport/mei/internal/meiexporter.h b/src/importexport/mei/internal/meiexporter.h index 1565453f5c8a8..bf8f7116e0fbb 100644 --- a/src/importexport/mei/internal/meiexporter.h +++ b/src/importexport/mei/internal/meiexporter.h @@ -76,7 +76,7 @@ enum layerElementCounter { class MeiExporter { public: - INJECT_STATIC(mu::iex::mei::IMeiConfiguration, configuration) + muse::GlobalInject configuration; public: MeiExporter(engraving::Score* s) { m_score = s; } diff --git a/src/importexport/mei/internal/meiimporter.h b/src/importexport/mei/internal/meiimporter.h index 43b26dac638f8..c3270fb78cf98 100644 --- a/src/importexport/mei/internal/meiimporter.h +++ b/src/importexport/mei/internal/meiimporter.h @@ -69,8 +69,8 @@ enum GraceReading { class MeiImporter { - INJECT_STATIC(mu::iex::mei::IMeiConfiguration, configuration) - INJECT(muse::io::IFileSystem, fileSystem) + muse::GlobalInject configuration; + muse::GlobalInject fileSystem; public: MeiImporter(engraving::Score* s) { m_score = s; } diff --git a/src/importexport/midi/internal/midiimport/importmidi_tempo.cpp b/src/importexport/midi/internal/midiimport/importmidi_tempo.cpp index c82193fece7bb..a21bc71757084 100644 --- a/src/importexport/midi/internal/midiimport/importmidi_tempo.cpp +++ b/src/importexport/midi/internal/midiimport/importmidi_tempo.cpp @@ -134,7 +134,7 @@ static void applyAllTempoEvents(const std::multimap& tracks, Score* void setTempo(const std::multimap& tracks, Score* score) { - muse::Inject configuration; + muse::GlobalInject configuration; const bool roundTempo = configuration() ? configuration()->roundTempo() : true; score->tempomap()->clear(); diff --git a/src/importexport/tabledit/internal/tableditreader.h b/src/importexport/tabledit/internal/tableditreader.h index 0b53df67f62bc..0699f7661ac05 100644 --- a/src/importexport/tabledit/internal/tableditreader.h +++ b/src/importexport/tabledit/internal/tableditreader.h @@ -29,7 +29,7 @@ namespace mu::iex::tabledit { class TablEditReader : public project::INotationReader { - INJECT(muse::io::IFileSystem, fileSystem) + muse::GlobalInject fileSystem; public: muse::Ret read(mu::engraving::MasterScore* score, const muse::io::path_t& path, const Options& options = Options()) override; mu::engraving::Err import(mu::engraving::MasterScore* score, const muse::io::path_t& path, const Options& options = Options()); diff --git a/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.cpp b/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.cpp index 3ba8de1767a5d..8015ee73eba51 100644 --- a/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.cpp +++ b/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.cpp @@ -26,6 +26,7 @@ #include "engraving/dom/property.h" #include "engraving/dom/tempotext.h" +#include "modularity/ioc.h" #include "shortcuts/shortcutstypes.h" #include "types/texttypes.h" @@ -153,7 +154,7 @@ QString AbstractInspectorModel::shortcutsForActionCode(std::string code) const AbstractInspectorModel::AbstractInspectorModel(QObject* parent, IElementRepositoryService* repository, mu::engraving::ElementType elementType) - : QObject(parent), m_repository(repository), m_elementType(elementType) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)), m_repository(repository), m_elementType(elementType) { if (!m_repository) { return; diff --git a/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.h b/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.h index a2e3d1fb3a752..07e2efb8d1e56 100644 --- a/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.h +++ b/src/inspector/qml/MuseScore/Inspector/abstractinspectormodel.h @@ -47,7 +47,7 @@ namespace mu::inspector { using MeasurementUnits = CommonTypes::MeasurementUnits; -class AbstractInspectorModel : public QObject, public muse::async::Asyncable +class AbstractInspectorModel : public QObject, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT QML_ELEMENT; @@ -63,10 +63,10 @@ class AbstractInspectorModel : public QObject, public muse::async::Asyncable Q_PROPERTY(mu::inspector::CommonTypes::MeasurementUnits measurementUnits READ measurementUnits NOTIFY measurementUnitsChanged) public: - muse::Inject context; - muse::Inject dispatcher; - muse::Inject uiActionsRegister; - muse::Inject shortcutsRegister; + muse::Inject context = { this }; + muse::Inject dispatcher = { this }; + muse::Inject uiActionsRegister = { this }; + muse::Inject shortcutsRegister = { this }; public: enum class InspectorSectionType { diff --git a/src/inspector/qml/MuseScore/Inspector/general/appearance/appearancesettingsmodel.h b/src/inspector/qml/MuseScore/Inspector/general/appearance/appearancesettingsmodel.h index a1d8592ef0fe5..11ed24caf0b3f 100644 --- a/src/inspector/qml/MuseScore/Inspector/general/appearance/appearancesettingsmodel.h +++ b/src/inspector/qml/MuseScore/Inspector/general/appearance/appearancesettingsmodel.h @@ -26,6 +26,7 @@ #include "abstractinspectormodel.h" +#include "modularity/ioc.h" #include "notation/inotationconfiguration.h" namespace mu::inspector { @@ -35,8 +36,6 @@ class AppearanceSettingsModel : public AbstractInspectorModel QML_ELEMENT; QML_UNCREATABLE("Not creatable from QML") - INJECT(notation::INotationConfiguration, notationConfiguration) - Q_PROPERTY(mu::inspector::PropertyItem * leadingSpace READ leadingSpace CONSTANT) Q_PROPERTY(mu::inspector::PropertyItem * measureWidth READ measureWidth CONSTANT) Q_PROPERTY(mu::inspector::PropertyItem * minimumDistance READ minimumDistance CONSTANT) @@ -46,6 +45,8 @@ class AppearanceSettingsModel : public AbstractInspectorModel Q_PROPERTY(bool isSnappedToGrid READ isSnappedToGrid WRITE setIsSnappedToGrid NOTIFY isSnappedToGridChanged) Q_PROPERTY(bool isVerticalOffsetAvailable READ isVerticalOffsetAvailable NOTIFY isVerticalOffsetAvailableChanged) + muse::GlobalInject notationConfiguration; + public: explicit AppearanceSettingsModel(QObject* parent, IElementRepositoryService* repository); diff --git a/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.cpp b/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.cpp index 5813bd7e18843..d787abee81414 100644 --- a/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.cpp +++ b/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.cpp @@ -38,8 +38,14 @@ using namespace mu::inspector; using namespace mu::notation; InspectorListModel::InspectorListModel(QObject* parent) - : QAbstractListModel(parent) + : QAbstractListModel(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) , m_repository{std::make_unique()} +{ +} + +InspectorListModel::~InspectorListModel() = default; + +void InspectorListModel::classBegin() { listenSelectionChanged(); listenScoreChanges(); @@ -52,8 +58,6 @@ InspectorListModel::InspectorListModel(QObject* parent) }); } -InspectorListModel::~InspectorListModel() = default; - void InspectorListModel::buildModelsForSelectedElements(const ElementKeySet& selectedElementKeySet, bool isRangeSelection, const QList& selectedElementList) { diff --git a/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.h b/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.h index 5908f7fa387cc..bbc4eadb08383 100644 --- a/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.h +++ b/src/inspector/qml/MuseScore/Inspector/inspectorlistmodel.h @@ -25,6 +25,7 @@ #include #include +#include #include #include "engraving/dom/engravingitem.h" @@ -36,12 +37,13 @@ namespace mu::inspector { class IElementRepositoryService; -class InspectorListModel : public QAbstractListModel, public muse::async::Asyncable +class InspectorListModel : public QAbstractListModel, public QQmlParserStatus, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT + Q_INTERFACES(QQmlParserStatus) QML_ELEMENT - INJECT(context::IGlobalContext, context) + muse::Inject context = { this }; public: explicit InspectorListModel(QObject* parent = nullptr); @@ -59,6 +61,9 @@ class InspectorListModel : public QAbstractListModel, public muse::async::Asynca InspectorSectionModelRole = Qt::UserRole + 1 }; + void classBegin() override; + void componentComplete() override {} + void listenSelectionChanged(); void listenScoreChanges(); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.cpp b/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.cpp index 13a310056a323..5c3a766529550 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.cpp +++ b/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.cpp @@ -66,7 +66,7 @@ static QPointF constrainToGrid(const QRectF& frameRectWithoutBorders, const QPoi } BendGridCanvas::BendGridCanvas(QQuickItem* parent) - : muse::uicomponents::QuickPaintedView(parent) + : muse::uicomponents::QuickPaintedView(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.h b/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.h index ea380dbfca035..e789ae1817da8 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.h +++ b/src/inspector/qml/MuseScore/Inspector/notation/bends/bendgridcanvas.h @@ -38,7 +38,7 @@ #include "uicomponents/qml/Muse/UiComponents/quickpaintedview.h" namespace mu::inspector { -class BendGridCanvas : public muse::uicomponents::QuickPaintedView, public muse::async::Asyncable +class BendGridCanvas : public muse::uicomponents::QuickPaintedView, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT QML_ELEMENT; @@ -54,7 +54,7 @@ class BendGridCanvas : public muse::uicomponents::QuickPaintedView, public muse: Q_PROPERTY(muse::ui::AccessibleItem * accessibleParent READ accessibleParent WRITE setAccessibleParent NOTIFY accessibleParentChanged) - muse::Inject uiConfig; + muse::Inject uiConfig = { this }; public: explicit BendGridCanvas(QQuickItem* parent = nullptr); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordlistmodel.h b/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordlistmodel.h index c2f93026898fd..03fa2be50b615 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordlistmodel.h +++ b/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordlistmodel.h @@ -46,7 +46,7 @@ class FretFrameChordListModel : public muse::uicomponents::SelectableItemListMod muse::Inject globalContext = { this }; public: - explicit FretFrameChordListModel(QObject* parent); + explicit FretFrameChordListModel(QObject* parent = nullptr); void load(); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordssettingsmodel.h b/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordssettingsmodel.h index 1cc6acf92b284..8d22630b307fa 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordssettingsmodel.h +++ b/src/inspector/qml/MuseScore/Inspector/notation/frames/fretframe/fretframechordssettingsmodel.h @@ -35,7 +35,7 @@ class FBox; } namespace mu::inspector { -class FretFrameChordsSettingsModel : public AbstractInspectorModel, public muse::Injectable +class FretFrameChordsSettingsModel : public AbstractInspectorModel { Q_OBJECT QML_ELEMENT; diff --git a/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.cpp b/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.cpp index ce0953953b0c3..8055d8c11ad44 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.cpp +++ b/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.cpp @@ -29,7 +29,7 @@ using namespace mu::inspector; FretCanvas::FretCanvas(QQuickItem* parent) - : muse::uicomponents::QuickPaintedView(parent) + : muse::uicomponents::QuickPaintedView(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.h b/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.h index 405e3c7da522e..d627cc7980aea 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.h +++ b/src/inspector/qml/MuseScore/Inspector/notation/fretdiagrams/internal/fretcanvas.h @@ -32,7 +32,7 @@ #include "engraving/dom/fret.h" namespace mu::inspector { -class FretCanvas : public muse::uicomponents::QuickPaintedView +class FretCanvas : public muse::uicomponents::QuickPaintedView, public muse::Injectable { Q_OBJECT QML_ELEMENT; @@ -43,7 +43,7 @@ class FretCanvas : public muse::uicomponents::QuickPaintedView Q_PROPERTY(int currentFretDotType READ currentFretDotType WRITE setCurrentFretDotType NOTIFY currentFretDotTypeChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - muse::Inject globalContext; + muse::Inject globalContext = { this }; public: explicit FretCanvas(QQuickItem* parent = nullptr); diff --git a/src/inspector/qml/MuseScore/Inspector/notation/instrumentname/instrumentnamesettingsmodel.h b/src/inspector/qml/MuseScore/Inspector/notation/instrumentname/instrumentnamesettingsmodel.h index c4af03e7aecc3..cb5f6e31df1ad 100644 --- a/src/inspector/qml/MuseScore/Inspector/notation/instrumentname/instrumentnamesettingsmodel.h +++ b/src/inspector/qml/MuseScore/Inspector/notation/instrumentname/instrumentnamesettingsmodel.h @@ -35,7 +35,7 @@ class InstrumentNameSettingsModel : public AbstractInspectorModel QML_ELEMENT; QML_UNCREATABLE("Not creatable from QML") - INJECT(muse::actions::IActionsDispatcher, dispatcher) + muse::Inject dispatcher = { this }; public: explicit InstrumentNameSettingsModel(QObject* parent, IElementRepositoryService* repository); diff --git a/src/instrumentsscene/instrumentsscenemodule.cpp b/src/instrumentsscene/instrumentsscenemodule.cpp index b2bdc8a9943e7..cb5e4054c915b 100644 --- a/src/instrumentsscene/instrumentsscenemodule.cpp +++ b/src/instrumentsscene/instrumentsscenemodule.cpp @@ -59,16 +59,16 @@ std::string InstrumentsSceneModule::moduleName() const void InstrumentsSceneModule::registerExports() { - m_actionsController = std::make_shared(); + m_actionsController = std::make_shared(iocContext()); - ioc()->registerExport(moduleName(), new SelectInstrumentsScenario()); + ioc()->registerExport(moduleName(), new SelectInstrumentsScenario(iocContext())); } void InstrumentsSceneModule::resolveImports() { auto ar = ioc()->resolve(moduleName()); if (ar) { - ar->reg(std::make_shared()); + ar->reg(std::make_shared(iocContext())); } auto ir = ioc()->resolve(moduleName()); diff --git a/src/instrumentsscene/internal/instrumentsactionscontroller.h b/src/instrumentsscene/internal/instrumentsactionscontroller.h index a1744f089a9a4..f90bfbc0afa3a 100644 --- a/src/instrumentsscene/internal/instrumentsactionscontroller.h +++ b/src/instrumentsscene/internal/instrumentsactionscontroller.h @@ -31,13 +31,19 @@ #include "context/iglobalcontext.h" namespace mu::instrumentsscene { -class InstrumentsActionsController : public muse::actions::Actionable, public muse::async::Asyncable +class InstrumentsActionsController : public muse::actions::Actionable, public muse::async::Asyncable, public muse::Injectable { - INJECT(muse::actions::IActionsDispatcher, dispatcher) - INJECT(notation::ISelectInstrumentsScenario, selectInstrumentsScenario) - INJECT(context::IGlobalContext, context) + muse::Inject dispatcher = { this }; + muse::Inject selectInstrumentsScenario = { this }; + muse::Inject context = { this }; public: + + InstrumentsActionsController(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + virtual ~InstrumentsActionsController() = default; bool canReceiveAction(const muse::actions::ActionCode&) const override; diff --git a/src/instrumentsscene/internal/instrumentsuiactions.h b/src/instrumentsscene/internal/instrumentsuiactions.h index b96c110807cdf..0d416bb4b8112 100644 --- a/src/instrumentsscene/internal/instrumentsuiactions.h +++ b/src/instrumentsscene/internal/instrumentsuiactions.h @@ -27,11 +27,15 @@ #include "context/iuicontextresolver.h" namespace mu::instrumentsscene { -class InstrumentsUiActions : public muse::ui::IUiActionsModule +class InstrumentsUiActions : public muse::ui::IUiActionsModule, public muse::Injectable { - INJECT(context::IUiContextResolver, uicontextResolver) + muse::Inject uicontextResolver = { this }; public: + InstrumentsUiActions(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + {} + const muse::ui::UiActionList& actionsList() const override; bool actionEnabled(const muse::ui::UiAction& act) const override; diff --git a/src/instrumentsscene/internal/selectinstrumentscenario.h b/src/instrumentsscene/internal/selectinstrumentscenario.h index ca15421ac3013..2fc5a8173ff5b 100644 --- a/src/instrumentsscene/internal/selectinstrumentscenario.h +++ b/src/instrumentsscene/internal/selectinstrumentscenario.h @@ -32,12 +32,18 @@ #include "global/async/promise.h" namespace mu::instrumentsscene { -class SelectInstrumentsScenario : public notation::ISelectInstrumentsScenario, public muse::async::Asyncable +class SelectInstrumentsScenario : public notation::ISelectInstrumentsScenario, public muse::async::Asyncable, public muse::Injectable { - muse::Inject interactive; - muse::Inject instrumentsRepository; + muse::Inject interactive = { this }; + muse::Inject instrumentsRepository = { this }; public: + + SelectInstrumentsScenario(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + muse::async::Promise selectInstruments() const override; muse::async::Promise selectInstrument( const notation::InstrumentKey& currentInstrumentId = notation::InstrumentKey()) const override; diff --git a/src/instrumentsscene/view/instrumentlistmodel.cpp b/src/instrumentsscene/view/instrumentlistmodel.cpp index 310f83643c4a0..e4285e362bd5f 100644 --- a/src/instrumentsscene/view/instrumentlistmodel.cpp +++ b/src/instrumentsscene/view/instrumentlistmodel.cpp @@ -22,6 +22,7 @@ #include "instrumentlistmodel.h" #include "log.h" +#include "modularity/ioc.h" #include "translation.h" using namespace mu::instrumentsscene; @@ -34,7 +35,7 @@ static const QString FIRST_GROUP_ID("FIRST_GROUP_ID"); static const QString INSTRUMENT_TEMPLATE_KEY("instrumentTemplate"); InstrumentListModel::InstrumentListModel(QObject* parent) - : QAbstractListModel(parent), m_selection(new ItemMultiSelectionModel(this)) + : QAbstractListModel(parent), muse::Injectable(muse::iocCtxForQmlObject(this)), m_selection(new ItemMultiSelectionModel(this)) { connect(m_selection, &ItemMultiSelectionModel::selectionChanged, this, [this](const QItemSelection& selected, const QItemSelection& deselected) { diff --git a/src/instrumentsscene/view/instrumentlistmodel.h b/src/instrumentsscene/view/instrumentlistmodel.h index a99bb8b5aef92..7b9bfed9c006e 100644 --- a/src/instrumentsscene/view/instrumentlistmodel.h +++ b/src/instrumentsscene/view/instrumentlistmodel.h @@ -32,12 +32,10 @@ #include "uicomponents/qml/Muse/UiComponents/itemmultiselectionmodel.h" namespace mu::instrumentsscene { -class InstrumentListModel : public QAbstractListModel, public muse::async::Asyncable +class InstrumentListModel : public QAbstractListModel, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(notation::IInstrumentsRepository, repository) - Q_PROPERTY(QStringList genres READ genres NOTIFY genresChanged) Q_PROPERTY(QStringList groups READ groups NOTIFY groupsChanged) @@ -47,6 +45,8 @@ class InstrumentListModel : public QAbstractListModel, public muse::async::Async Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged) Q_PROPERTY(QVariant selectedInstrument READ selectedInstrument NOTIFY selectionChanged) + muse::Inject repository = { this }; + public: InstrumentListModel(QObject* parent = nullptr); diff --git a/src/instrumentsscene/view/instrumentsettingsmodel.cpp b/src/instrumentsscene/view/instrumentsettingsmodel.cpp index 5c7e095fc4794..7565024060e3e 100644 --- a/src/instrumentsscene/view/instrumentsettingsmodel.cpp +++ b/src/instrumentsscene/view/instrumentsettingsmodel.cpp @@ -29,7 +29,7 @@ using namespace mu::notation; using namespace mu::engraving; InstrumentSettingsModel::InstrumentSettingsModel(QObject* parent) - : QObject(parent) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/instrumentsscene/view/instrumentsettingsmodel.h b/src/instrumentsscene/view/instrumentsettingsmodel.h index c39d223881a3d..bcd3a46dfaa27 100644 --- a/src/instrumentsscene/view/instrumentsettingsmodel.h +++ b/src/instrumentsscene/view/instrumentsettingsmodel.h @@ -32,12 +32,10 @@ #include "notation/notationtypes.h" namespace mu::instrumentsscene { -class InstrumentSettingsModel : public QObject, public muse::async::Asyncable +class InstrumentSettingsModel : public QObject, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(context::IGlobalContext, context) - Q_PROPERTY(QString instrumentName READ instrumentName WRITE setInstrumentName NOTIFY dataChanged) Q_PROPERTY(QString abbreviature READ abbreviature WRITE setAbbreviature NOTIFY dataChanged) Q_PROPERTY(int hideWhenEmpty READ hideWhenEmpty WRITE setHideWhenEmpty NOTIFY hideWhenEmptyChanged) @@ -47,6 +45,7 @@ class InstrumentSettingsModel : public QObject, public muse::async::Asyncable Q_PROPERTY(bool hasMultipleStaves READ hasMultipleStaves NOTIFY hasMultipleStavesChanged) Q_PROPERTY(bool isMainScore READ isMainScore NOTIFY isMainScoreChanged) + muse::Inject context = { this }; public: explicit InstrumentSettingsModel(QObject* parent = nullptr); diff --git a/src/instrumentsscene/view/instrumentsonscorelistmodel.cpp b/src/instrumentsscene/view/instrumentsonscorelistmodel.cpp index 1f6318cc68534..eaf565b6e1d66 100644 --- a/src/instrumentsscene/view/instrumentsonscorelistmodel.cpp +++ b/src/instrumentsscene/view/instrumentsonscorelistmodel.cpp @@ -52,7 +52,7 @@ class InstrumentsOnScoreListModel::InstrumentItem : public SelectableItemListMod } InstrumentsOnScoreListModel::InstrumentsOnScoreListModel(QObject* parent) - : SelectableItemListModel(parent) + : SelectableItemListModel(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/instrumentsscene/view/instrumentsonscorelistmodel.h b/src/instrumentsscene/view/instrumentsonscorelistmodel.h index ec6edf16da3cb..49f7c24f1b9d4 100644 --- a/src/instrumentsscene/view/instrumentsonscorelistmodel.h +++ b/src/instrumentsscene/view/instrumentsonscorelistmodel.h @@ -29,16 +29,15 @@ #include "notation/iinstrumentsrepository.h" namespace mu::instrumentsscene { -class InstrumentsOnScoreListModel : public muse::uicomponents::SelectableItemListModel +class InstrumentsOnScoreListModel : public muse::uicomponents::SelectableItemListModel, public muse::Injectable { Q_OBJECT - INJECT(context::IGlobalContext, context) - INJECT(notation::IInstrumentsRepository, repository) - Q_PROPERTY(QStringList orders READ orders NOTIFY ordersChanged) Q_PROPERTY(int currentOrderIndex READ currentOrderIndex WRITE setCurrentOrderIndex NOTIFY currentOrderChanged) + muse::Inject context = { this }; + muse::Inject repository = { this }; public: InstrumentsOnScoreListModel(QObject* parent = nullptr); diff --git a/src/instrumentsscene/view/layoutpanelcontextmenumodel.h b/src/instrumentsscene/view/layoutpanelcontextmenumodel.h index 55084db6833ec..4e71fed3f8f7e 100644 --- a/src/instrumentsscene/view/layoutpanelcontextmenumodel.h +++ b/src/instrumentsscene/view/layoutpanelcontextmenumodel.h @@ -35,9 +35,9 @@ class LayoutPanelContextMenuModel : public muse::uicomponents::AbstractMenuModel { Q_OBJECT - INJECT(context::IGlobalContext, globalContext) - INJECT(notation::IInstrumentsRepository, instrumentsRepository) - INJECT(muse::actions::IActionsDispatcher, dispatcher) + muse::Inject globalContext = { this }; + muse::Inject instrumentsRepository = { this }; + muse::Inject dispatcher = { this }; public: explicit LayoutPanelContextMenuModel(QObject* parent = nullptr); diff --git a/src/instrumentsscene/view/layoutpaneltreemodel.cpp b/src/instrumentsscene/view/layoutpaneltreemodel.cpp index 044e0b6dfc9f7..786a59f36ac9f 100644 --- a/src/instrumentsscene/view/layoutpaneltreemodel.cpp +++ b/src/instrumentsscene/view/layoutpaneltreemodel.cpp @@ -46,7 +46,11 @@ using namespace muse::uicomponents; static const muse::actions::ActionCode ADD_INSTRUMENTS_ACTIONCODE("instruments"); LayoutPanelTreeModel::LayoutPanelTreeModel(QObject* parent) - : QAbstractItemModel(parent) + : QAbstractItemModel(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) +{ +} + +void LayoutPanelTreeModel::classBegin() { m_partsNotifyReceiver = std::make_shared(); diff --git a/src/instrumentsscene/view/layoutpaneltreemodel.h b/src/instrumentsscene/view/layoutpaneltreemodel.h index fca5319514deb..8c2b647f1cb50 100644 --- a/src/instrumentsscene/view/layoutpaneltreemodel.h +++ b/src/instrumentsscene/view/layoutpaneltreemodel.h @@ -23,7 +23,9 @@ #pragma once #include +#include #include +#include #include "abstractlayoutpaneltreeitem.h" #include "modularity/ioc.h" @@ -46,15 +48,11 @@ class QItemSelectionModel; namespace mu::instrumentsscene { class PartTreeItem; -class LayoutPanelTreeModel : public QAbstractItemModel, public muse::async::Asyncable, public muse::actions::Actionable +class LayoutPanelTreeModel : public QAbstractItemModel, public QQmlParserStatus, public muse::async::Asyncable, + public muse::actions::Actionable, public muse::Injectable { Q_OBJECT - - INJECT(context::IGlobalContext, context) - INJECT(notation::ISelectInstrumentsScenario, selectInstrumentsScenario) - INJECT(muse::actions::IActionsDispatcher, dispatcher) - INJECT(muse::shortcuts::IShortcutsRegister, shortcutsRegister) - INJECT(muse::IInteractive, interactive) + Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(bool isMovingUpAvailable READ isMovingUpAvailable NOTIFY isMovingUpAvailableChanged) Q_PROPERTY(bool isMovingDownAvailable READ isMovingDownAvailable NOTIFY isMovingDownAvailableChanged) @@ -65,6 +63,11 @@ class LayoutPanelTreeModel : public QAbstractItemModel, public muse::async::Asyn Q_PROPERTY(QString addInstrumentsKeyboardShortcut READ addInstrumentsKeyboardShortcut NOTIFY addInstrumentsKeyboardShortcutChanged) Q_PROPERTY(int selectedItemsType READ selectedItemsType NOTIFY selectedItemsTypeChanged) + muse::Inject context = { this }; + muse::Inject selectInstrumentsScenario = { this }; + muse::Inject dispatcher = { this }; + muse::Inject shortcutsRegister = { this }; + muse::Inject interactive = { this }; public: explicit LayoutPanelTreeModel(QObject* parent = nullptr); ~LayoutPanelTreeModel() override; @@ -126,6 +129,10 @@ private slots: void updateIsAddingSystemMarkingsAvailable(); private: + + void classBegin() override; + void componentComplete() override {} + bool removeRows(int row, int count, const QModelIndex& parent) override; enum RoleNames { diff --git a/src/notation/internal/instrumentsrepository.h b/src/notation/internal/instrumentsrepository.h index 7a83901725c35..cf14c6caeb91b 100644 --- a/src/notation/internal/instrumentsrepository.h +++ b/src/notation/internal/instrumentsrepository.h @@ -31,13 +31,16 @@ #include "framework/musesampler/imusesamplerinfo.h" namespace mu::notation { -class InstrumentsRepository : public IInstrumentsRepository, public muse::async::Asyncable +class InstrumentsRepository : public IInstrumentsRepository, public muse::async::Asyncable, public muse::Injectable { - muse::Inject fileSystem; - muse::Inject configuration; - muse::Inject museSampler; + muse::Inject fileSystem = { this }; + muse::Inject configuration = { this }; + muse::Inject museSampler = { this }; public: + InstrumentsRepository(const muse::modularity::ContextPtr& iocCtx) + : Injectable(iocCtx) {} + void init(); const InstrumentTemplateList& instrumentTemplates() const override; diff --git a/src/notation/internal/notation.cpp b/src/notation/internal/notation.cpp index 246ce94d34c47..ac6c4e81f0c82 100644 --- a/src/notation/internal/notation.cpp +++ b/src/notation/internal/notation.cpp @@ -50,8 +50,8 @@ Notation::Notation(MasterNotation* master, const muse::modularity::ContextPtr& i : muse::Injectable(iocCtx) , m_masterNotation(master) { - m_painting = std::make_shared(this); - m_viewState = std::make_shared(this); + m_painting = std::make_shared(this, iocCtx); + m_viewState = std::make_shared(this, iocCtx); m_soloMuteState = std::make_shared(); m_undoStack = std::make_shared(this, m_notationChanged); m_interaction = std::make_shared(this, m_undoStack); diff --git a/src/notation/internal/notationconfiguration.cpp b/src/notation/internal/notationconfiguration.cpp index ab7235030e7d7..8d1205b7a4768 100644 --- a/src/notation/internal/notationconfiguration.cpp +++ b/src/notation/internal/notationconfiguration.cpp @@ -24,6 +24,7 @@ #include "engraving/dom/mscore.h" #include "io/path.h" +#include "modularity/ioc.h" #include "settings.h" #include "notationtypes.h" @@ -136,6 +137,11 @@ static const std::map NOTE_INPUT_METHOD_TO_STR { { NoteInputMethod::TIMEWISE, "TIMEWISE" }, }; +NotationConfiguration::NotationConfiguration(const muse::modularity::ContextPtr& ctx) + : muse::Injectable(ctx) +{ +} + void NotationConfiguration::init() { settings()->setDefaultValue(BACKGROUND_USE_COLOR, Val(true)); diff --git a/src/notation/internal/notationconfiguration.h b/src/notation/internal/notationconfiguration.h index 2f9035e3903e1..667b077ab87c3 100644 --- a/src/notation/internal/notationconfiguration.h +++ b/src/notation/internal/notationconfiguration.h @@ -33,15 +33,18 @@ #include "../inotationconfiguration.h" namespace mu::notation { -class NotationConfiguration : public INotationConfiguration, public muse::async::Asyncable +class NotationConfiguration : public INotationConfiguration, public muse::async::Asyncable, public muse::Injectable { - INJECT(muse::IGlobalConfiguration, globalConfiguration) - INJECT(muse::io::IFileSystem, fileSystem) - INJECT(muse::ui::IUiConfiguration, uiConfiguration) - INJECT(engraving::IEngravingConfiguration, engravingConfiguration) - INJECT(context::IGlobalContext, context) + muse::Inject globalConfiguration = { this }; + muse::Inject fileSystem = { this }; + muse::Inject uiConfiguration = { this }; + muse::Inject engravingConfiguration = { this }; + muse::Inject context = { this }; public: + + explicit NotationConfiguration(const muse::modularity::ContextPtr& ctx); + void init(); QColor notationColor() const override; diff --git a/src/notation/internal/notationpainting.cpp b/src/notation/internal/notationpainting.cpp index 9e8f987640676..faac02e202a29 100644 --- a/src/notation/internal/notationpainting.cpp +++ b/src/notation/internal/notationpainting.cpp @@ -35,8 +35,8 @@ using namespace mu::notation; using namespace mu::engraving; using namespace muse::draw; -NotationPainting::NotationPainting(Notation* notation) - : m_notation(notation) +NotationPainting::NotationPainting(Notation* notation, const muse::modularity::ContextPtr& ctx) + : muse::Injectable(ctx), m_notation(notation) { } diff --git a/src/notation/internal/notationpainting.h b/src/notation/internal/notationpainting.h index d23506b88fe74..75f97758e35ce 100644 --- a/src/notation/internal/notationpainting.h +++ b/src/notation/internal/notationpainting.h @@ -37,15 +37,15 @@ class Page; namespace mu::notation { class Notation; -class NotationPainting : public INotationPainting +class NotationPainting : public INotationPainting, public muse::Injectable { - INJECT(INotationConfiguration, configuration) - INJECT(engraving::IEngravingConfiguration, engravingConfiguration) - INJECT(engraving::rendering::IScoreRenderer, scoreRenderer) - INJECT(muse::ui::IUiConfiguration, uiConfiguration) + muse::Inject configuration = { this }; + muse::Inject engravingConfiguration = { this }; + muse::Inject scoreRenderer = { this }; + muse::Inject uiConfiguration = { this }; public: - NotationPainting(Notation* notation); + NotationPainting(Notation* notation, const muse::modularity::ContextPtr& ctx); void setViewMode(const ViewMode& viewMode) override; ViewMode viewMode() const override; diff --git a/src/notation/internal/notationplayback.cpp b/src/notation/internal/notationplayback.cpp index 45adf17b5ec6d..8545dcc47d1c1 100644 --- a/src/notation/internal/notationplayback.cpp +++ b/src/notation/internal/notationplayback.cpp @@ -56,7 +56,7 @@ static constexpr double PLAYBACK_TAIL_SECS = 3; NotationPlayback::NotationPlayback(IGetScore* getScore, muse::async::Notification notationChanged, const modularity::ContextPtr& iocCtx) - : m_getScore(getScore), m_notationChanged(notationChanged), m_playbackModel(iocCtx) + : muse::Injectable(iocCtx), m_getScore(getScore), m_notationChanged(notationChanged), m_playbackModel(iocCtx) { m_notationChanged.onNotify(this, [this]() { updateLoopBoundaries(); diff --git a/src/notation/internal/notationplayback.h b/src/notation/internal/notationplayback.h index f7b7389de75fb..9c89b217919bb 100644 --- a/src/notation/internal/notationplayback.h +++ b/src/notation/internal/notationplayback.h @@ -35,9 +35,9 @@ class Score; } namespace mu::notation { -class NotationPlayback : public INotationPlayback, public muse::async::Asyncable +class NotationPlayback : public INotationPlayback, public muse::async::Asyncable, public muse::Injectable { - INJECT(INotationConfiguration, configuration) + muse::Inject configuration = { this }; public: NotationPlayback(IGetScore* getScore, muse::async::Notification notationChanged, const muse::modularity::ContextPtr& iocCtx); diff --git a/src/notation/internal/notationviewstate.cpp b/src/notation/internal/notationviewstate.cpp index b8410f14c5902..b4f479cf5e782 100644 --- a/src/notation/internal/notationviewstate.cpp +++ b/src/notation/internal/notationviewstate.cpp @@ -71,7 +71,8 @@ static QString viewModeToString(ViewMode m) return ""; } -NotationViewState::NotationViewState(Notation* notation) +NotationViewState::NotationViewState(Notation* notation, const modularity::ContextPtr& ctx) + : muse::Injectable(ctx) { notation->openChanged().onNotify(this, [this, notation]() { if (!notation->isOpen()) { diff --git a/src/notation/internal/notationviewstate.h b/src/notation/internal/notationviewstate.h index 053ec3dd57f5d..639971ea52c9d 100644 --- a/src/notation/internal/notationviewstate.h +++ b/src/notation/internal/notationviewstate.h @@ -29,12 +29,12 @@ namespace mu::notation { class Notation; -class NotationViewState : public INotationViewState, public muse::async::Asyncable +class NotationViewState : public INotationViewState, public muse::async::Asyncable, public muse::Injectable { - INJECT_STATIC(INotationConfiguration, configuration) + muse::Inject configuration = { this }; public: - explicit NotationViewState(Notation* notation); + explicit NotationViewState(Notation* notation, const muse::modularity::ContextPtr& ctx); muse::Ret read(const engraving::MscReader& reader, const muse::io::path_t& pathPrefix = "") override; muse::Ret write(engraving::MscWriter& writer, const muse::io::path_t& pathPrefix = "") override; diff --git a/src/notation/internal/positionswriter.cpp b/src/notation/internal/positionswriter.cpp index 3583a00dfe0dc..1fe4fecb05533 100644 --- a/src/notation/internal/positionswriter.cpp +++ b/src/notation/internal/positionswriter.cpp @@ -85,8 +85,13 @@ static void writeMeasureEvents(XmlStreamWriter& writer, Measure* m, int offset, } } -PositionsWriter::PositionsWriter(PositionsWriter::ElementType elementType) - : m_elementType(elementType) +PositionsWriter::PositionsWriter(const muse::modularity::ContextPtr& ctx) + : muse::Injectable(ctx) +{ +} + +PositionsWriter::PositionsWriter(PositionsWriter::ElementType elementType, const muse::modularity::ContextPtr& ctx) + : muse::Injectable(ctx), m_elementType(elementType) { } diff --git a/src/notation/internal/positionswriter.h b/src/notation/internal/positionswriter.h index 0980edb285621..d4a6e61e2ac4b 100644 --- a/src/notation/internal/positionswriter.h +++ b/src/notation/internal/positionswriter.h @@ -35,9 +35,9 @@ class Score; } namespace mu::notation { -class PositionsWriter : public project::INotationWriter +class PositionsWriter : public project::INotationWriter, public muse::Injectable { - INJECT(iex::imagesexport::IImagesExportConfiguration, imagesExportConfiguration) + muse::Inject imagesExportConfiguration = { this }; public: enum class ElementType { @@ -45,8 +45,8 @@ class PositionsWriter : public project::INotationWriter MEASURE }; - explicit PositionsWriter() = default; - explicit PositionsWriter(ElementType elementType); + explicit PositionsWriter(const muse::modularity::ContextPtr& ctx); + explicit PositionsWriter(ElementType elementType, const muse::modularity::ContextPtr& ctx); std::vector supportedUnitTypes() const override; bool supportsUnitType(UnitType unitType) const override; diff --git a/src/notation/notationmodule.cpp b/src/notation/notationmodule.cpp index 5e4d023ef6215..d61c7399e639d 100644 --- a/src/notation/notationmodule.cpp +++ b/src/notation/notationmodule.cpp @@ -43,8 +43,8 @@ std::string NotationModule::moduleName() const void NotationModule::registerExports() { - m_configuration = std::make_shared(); - m_instrumentsRepository = std::make_shared(); + m_configuration = std::make_shared(iocContext()); + m_instrumentsRepository = std::make_shared(iocContext()); #ifdef MUE_BUILD_ENGRAVING_FONTSCONTROLLER m_engravingFontsController = std::make_shared(); @@ -58,8 +58,8 @@ void NotationModule::resolveImports() { auto writers = ioc()->resolve(moduleName()); if (writers) { - writers->reg({ "spos" }, std::make_shared(PositionsWriter::ElementType::SEGMENT)); - writers->reg({ "mpos" }, std::make_shared(PositionsWriter::ElementType::MEASURE)); + writers->reg({ "spos" }, std::make_shared(PositionsWriter::ElementType::SEGMENT, iocContext())); + writers->reg({ "mpos" }, std::make_shared(PositionsWriter::ElementType::MEASURE, iocContext())); writers->reg({ "mscz" }, std::make_shared(engraving::MscIoMode::Zip)); writers->reg({ "mscx" }, std::make_shared(engraving::MscIoMode::Dir)); } diff --git a/src/notationscene/internal/midiinputoutputcontroller.h b/src/notationscene/internal/midiinputoutputcontroller.h index 0964c48877c6e..4e4460d4dfa67 100644 --- a/src/notationscene/internal/midiinputoutputcontroller.h +++ b/src/notationscene/internal/midiinputoutputcontroller.h @@ -32,16 +32,22 @@ #include "shortcuts/imidiremote.h" namespace mu::notation { -class MidiInputOutputController : public muse::async::Asyncable +class MidiInputOutputController : public muse::async::Asyncable, public muse::Injectable { - INJECT(muse::midi::IMidiInPort, midiInPort) - INJECT(muse::midi::IMidiOutPort, midiOutPort) - INJECT(muse::midi::IMidiConfiguration, midiConfiguration) - INJECT(context::IGlobalContext, globalContext) - INJECT(INotationConfiguration, configuration) - INJECT(muse::shortcuts::IMidiRemote, midiRemote) + muse::Inject midiInPort = { this }; + muse::Inject midiOutPort = { this }; + muse::Inject midiConfiguration = { this }; + muse::Inject globalContext = { this }; + muse::Inject configuration = { this }; + muse::Inject midiRemote = { this }; public: + + MidiInputOutputController(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + void init(); private: diff --git a/src/notationscene/internal/notationuiactions.cpp b/src/notationscene/internal/notationuiactions.cpp index 6cff71d708fc2..cf9f7b235404b 100644 --- a/src/notationscene/internal/notationuiactions.cpp +++ b/src/notationscene/internal/notationuiactions.cpp @@ -23,6 +23,7 @@ #include +#include "modularity/ioc.h" #include "types/translatablestring.h" #include "ui/view/iconcodes.h" #include "context/shortcutcontext.h" @@ -2721,8 +2722,8 @@ const UiActionList NotationUiActions::s_engravingDebuggingActions = { ) }; -NotationUiActions::NotationUiActions(std::shared_ptr controller) - : m_controller(controller) +NotationUiActions::NotationUiActions(std::shared_ptr controller, const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_controller(controller) { } diff --git a/src/notationscene/internal/notationuiactions.h b/src/notationscene/internal/notationuiactions.h index 7859b5d10f3b7..3e0ffcec9d746 100644 --- a/src/notationscene/internal/notationuiactions.h +++ b/src/notationscene/internal/notationuiactions.h @@ -31,14 +31,14 @@ #include "notationactioncontroller.h" namespace mu::notation { -class NotationUiActions : public muse::ui::IUiActionsModule, public muse::async::Asyncable +class NotationUiActions : public muse::ui::IUiActionsModule, public muse::async::Asyncable, public muse::Injectable { - INJECT(context::IUiContextResolver, uicontextResolver) - INJECT(engraving::IEngravingConfiguration, engravingConfiguration) + muse::Inject uicontextResolver = { this }; + muse::Inject engravingConfiguration = { this }; public: - NotationUiActions(std::shared_ptr controller); + NotationUiActions(std::shared_ptr controller, const muse::modularity::ContextPtr& iocCtx); void init(); diff --git a/src/notationscene/notationscenemodule.cpp b/src/notationscene/notationscenemodule.cpp index 4259622f489dd..574aee888dc1b 100644 --- a/src/notationscene/notationscenemodule.cpp +++ b/src/notationscene/notationscenemodule.cpp @@ -57,8 +57,8 @@ std::string NotationSceneModule::moduleName() const void NotationSceneModule::registerExports() { m_actionController = std::make_shared(); - m_notationUiActions = std::make_shared(m_actionController); - m_midiInputOutputController = std::make_shared(); + m_notationUiActions = std::make_shared(m_actionController, iocContext()); + m_midiInputOutputController = std::make_shared(iocContext()); } void NotationSceneModule::resolveImports() diff --git a/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.cpp b/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.cpp index 8537800c9c597..fa81c06e1ed83 100644 --- a/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.cpp +++ b/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.cpp @@ -23,12 +23,13 @@ #include #include "paintedengravingitem.h" +#include "modularity/ioc.h" #include "notationscene/utilities/engravingitempreviewpainter.h" using namespace mu::notation; PaintedEngravingItem::PaintedEngravingItem(QQuickItem* parent) - : QQuickPaintedItem(parent) + : QQuickPaintedItem(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } @@ -103,5 +104,5 @@ void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter) co params.spatium = m_spatium; params.numStaffLines = m_numStaffLines; - EngravingItemPreviewPainter::paintPreview(m_item.get(), params); + EngravingItemPreviewPainter::paintPreview(renderer(), m_item.get(), params); } diff --git a/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.h b/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.h index af6a7401368ba..d886d997f14f4 100644 --- a/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.h +++ b/src/notationscene/qml/MuseScore/NotationScene/paintedengravingitem.h @@ -27,14 +27,12 @@ #include "modularity/ioc.h" #include "engraving/iengravingconfiguration.h" - +#include "engraving/rendering/isinglerenderer.h" #include "engraving/dom/engravingitem.h" namespace mu::notation { -class PaintedEngravingItem : public QQuickPaintedItem +class PaintedEngravingItem : public QQuickPaintedItem, public muse::Injectable { - INJECT_STATIC(engraving::IEngravingConfiguration, configuration) - Q_OBJECT Q_PROPERTY(QVariant engravingItem READ engravingItemVariant WRITE setEngravingItemVariant NOTIFY engravingItemVariantChanged) @@ -44,6 +42,9 @@ class PaintedEngravingItem : public QQuickPaintedItem QML_ELEMENT + muse::Inject configuration = { this }; + muse::Inject renderer = { this }; + public: explicit PaintedEngravingItem(QQuickItem* parent = nullptr); diff --git a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.cpp b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.cpp index 5d84083f183d2..ed1483ed53202 100644 --- a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.cpp +++ b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.cpp @@ -27,6 +27,7 @@ #include "audio/common/audioutils.h" +#include "modularity/ioc.h" #include "notationscene/utilities/percussionutilities.h" #include "ui/view/iconcodes.h" @@ -53,7 +54,7 @@ static const std::unordered_mapinstallEventFilter(this); @@ -500,7 +501,7 @@ void PercussionPanelModel::onDefinePadShortcutRequested(int pitch) } Drumset updatedDrumset = *m_padListModel->drumset(); - if (!PercussionUtilities::editPercussionShortcut(updatedDrumset, pitch)) { + if (!PercussionUtilities(iocContext()).editPercussionShortcut(updatedDrumset, pitch)) { return; } @@ -531,7 +532,7 @@ void PercussionPanelModel::playPitch(int pitch) } const NoteInputState& inputState = interaction()->noteInput()->state(); - std::shared_ptr chord = PercussionUtilities::getDrumNoteForPreview(m_padListModel->drumset(), pitch); + std::shared_ptr chord = PercussionUtilities(iocContext()).getDrumNoteForPreview(m_padListModel->drumset(), pitch); chord->setParent(inputState.segment()); chord->setTrack(inputState.track()); @@ -602,7 +603,7 @@ Drumset PercussionPanelModel::museSamplerDefaultDrumset() const } Drumset defaultDrumset; - PercussionUtilities::readDrumset(drumMapping, defaultDrumset); + PercussionUtilities(iocContext()).readDrumset(drumMapping, defaultDrumset); return defaultDrumset; } diff --git a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.h b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.h index 47878aa305ea2..0982607008ba4 100644 --- a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.h +++ b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelmodel.h @@ -53,15 +53,6 @@ Q_ENUM_NS(Mode) class PercussionPanelModel : public QObject, public muse::Injectable, public muse::async::Asyncable { - muse::Inject globalContext = { this }; - muse::Inject dispatcher = { this }; - muse::Inject playbackController = { this }; - muse::Inject museSampler; - muse::Inject instrumentsRepository = { this }; - - muse::Inject notationConfiguration = { this }; - muse::Inject engravingConfiguration = { this }; - Q_OBJECT Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) @@ -79,6 +70,15 @@ class PercussionPanelModel : public QObject, public muse::Injectable, public mus QML_ELEMENT + muse::Inject globalContext = { this }; + muse::Inject dispatcher = { this }; + muse::Inject playbackController = { this }; + muse::Inject museSampler = { this }; + muse::Inject instrumentsRepository = { this }; + + muse::Inject notationConfiguration = { this }; + muse::Inject engravingConfiguration = { this }; + public: explicit PercussionPanelModel(QObject* parent = nullptr); diff --git a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelpadlistmodel.cpp b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelpadlistmodel.cpp index 768e57b89e7ea..77e7589ad8cb2 100644 --- a/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelpadlistmodel.cpp +++ b/src/notationscene/qml/MuseScore/NotationScene/percussionpanel/percussionpanelpadlistmodel.cpp @@ -340,7 +340,7 @@ PercussionPanelPadModel* PercussionPanelPadListModel::createPadModelForPitch(int m_padActionRequestChannel.send(action, pitch); }); - model->setNotationPreviewItem(PercussionUtilities::getDrumNoteForPreview(m_drumset, pitch)); + model->setNotationPreviewItem(PercussionUtilities(iocContext()).getDrumNoteForPreview(m_drumset, pitch)); return model; } diff --git a/src/notationscene/utilities/engravingitempreviewpainter.cpp b/src/notationscene/utilities/engravingitempreviewpainter.cpp index 1a570eacffa1b..21550f4461601 100644 --- a/src/notationscene/utilities/engravingitempreviewpainter.cpp +++ b/src/notationscene/utilities/engravingitempreviewpainter.cpp @@ -35,7 +35,8 @@ using namespace muse::draw; /// 0`, then the element is only centered horizontally; i.e. vertical alignment /// is unchanged from the default so that item will appear at the correct height /// on the staff. -void EngravingItemPreviewPainter::paintPreview(mu::engraving::EngravingItem* element, PaintParams& params) +void EngravingItemPreviewPainter::paintPreview(std::shared_ptr render, + mu::engraving::EngravingItem* element, PaintParams& params) { IF_ASSERT_FAILED(element && params.painter) { return; @@ -58,7 +59,7 @@ void EngravingItemPreviewPainter::paintPreview(mu::engraving::EngravingItem* ele painter->scale(sizeRatio, sizeRatio); // scale coordinates so element is drawn at correct size // calculate bbox - engravingRender()->layoutItem(element); + render->layoutItem(element); PointF elementOrigin = element->ldata()->bbox().center(); @@ -72,10 +73,11 @@ void EngravingItemPreviewPainter::paintPreview(mu::engraving::EngravingItem* ele // shift coordinates so element is drawn at correct position painter->translate(-elementOrigin); - paintItem(element, params); + paintItem(render, element, params); } -void EngravingItemPreviewPainter::paintItem(mu::engraving::EngravingItem* element, PaintParams& params) +void EngravingItemPreviewPainter::paintItem(std::shared_ptr render, + mu::engraving::EngravingItem* element, PaintParams& params) { IF_ASSERT_FAILED(element && params.painter) { return; @@ -99,7 +101,7 @@ void EngravingItemPreviewPainter::paintItem(mu::engraving::EngravingItem* elemen rendering::PaintOptions opt; opt.invertColors = params.colorsInversionEnabled; - engravingRender()->drawItem(item, painter, opt); + render->drawItem(item, painter, opt); item->setProperty(Pid::COLOR, colorBackup); item->setProperty(Pid::FRAME_FG_COLOR, frameColorBackup); diff --git a/src/notationscene/utilities/engravingitempreviewpainter.h b/src/notationscene/utilities/engravingitempreviewpainter.h index ae2379d351312..2c01f33338a29 100644 --- a/src/notationscene/utilities/engravingitempreviewpainter.h +++ b/src/notationscene/utilities/engravingitempreviewpainter.h @@ -22,15 +22,14 @@ #pragma once -#include "modularity/ioc.h" +#include + #include "engraving/dom/engravingitem.h" #include "engraving/rendering/isinglerenderer.h" namespace mu::notation { class EngravingItemPreviewPainter { - INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender) - public: struct PaintParams { @@ -50,8 +49,10 @@ class EngravingItemPreviewPainter int numStaffLines = 0; }; - static void paintPreview(mu::engraving::EngravingItem* element, PaintParams& params); - static void paintItem(mu::engraving::EngravingItem* element, PaintParams& params); + static void paintPreview(std::shared_ptr render, mu::engraving::EngravingItem* element, + PaintParams& params); + static void paintItem(std::shared_ptr render, mu::engraving::EngravingItem* element, + PaintParams& params); private: static double paintStaff(PaintParams& params); diff --git a/src/notationscene/utilities/percussionutilities.h b/src/notationscene/utilities/percussionutilities.h index 69c41749844bb..6eeaaa15a20dd 100644 --- a/src/notationscene/utilities/percussionutilities.h +++ b/src/notationscene/utilities/percussionutilities.h @@ -36,22 +36,28 @@ #include "types/retval.h" namespace mu::notation { -class PercussionUtilities +class PercussionUtilities : public muse::Injectable { - INJECT_STATIC(muse::ui::IUiActionsRegister, uiactionsRegister) - INJECT_STATIC(muse::shortcuts::IShortcutsRegister, shortcutsRegister) + muse::Inject uiactionsRegister = { this }; + muse::Inject shortcutsRegister = { this }; - INJECT_STATIC(muse::IInteractive, interactive) + muse::Inject interactive = { this }; - INJECT_STATIC(mu::engraving::rendering::ISingleRenderer, engravingRender) + muse::Inject engravingRender = { this }; public: - static void readDrumset(const muse::ByteArray& drumMapping, mu::engraving::Drumset& drumset); - static std::shared_ptr getDrumNoteForPreview(const mu::engraving::Drumset* drumset, int pitch); - static bool editPercussionShortcut(mu::engraving::Drumset& drumset, int originPitch); + + PercussionUtilities(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + + void readDrumset(const muse::ByteArray& drumMapping, mu::engraving::Drumset& drumset); + std::shared_ptr getDrumNoteForPreview(const mu::engraving::Drumset* drumset, int pitch); + bool editPercussionShortcut(mu::engraving::Drumset& drumset, int originPitch); private: - static muse::RetVal openPercussionShortcutDialog(const mu::engraving::Drumset& drumset, int originPitch); - static QVariantMap drumToQVariantMap(int pitch, const engraving::DrumInstrument& drum); + muse::RetVal openPercussionShortcutDialog(const mu::engraving::Drumset& drumset, int originPitch); + QVariantMap drumToQVariantMap(int pitch, const engraving::DrumInstrument& drum); }; } diff --git a/src/notationscene/widgets/editstafftype.h b/src/notationscene/widgets/editstafftype.h index 2abcbd32d9730..0a886514dfe1d 100644 --- a/src/notationscene/widgets/editstafftype.h +++ b/src/notationscene/widgets/editstafftype.h @@ -36,7 +36,7 @@ class EditStaffType : public QDialog, private Ui::EditStaffType, public muse::In { Q_OBJECT - INJECT(muse::IInteractive, interactive) + muse::Inject interactive = { this }; mu::engraving::StaffType staffType; diff --git a/src/palette/internal/mimedatautils.h b/src/palette/internal/mimedatautils.h index 26f2494355c2d..e938676b5e3c4 100644 --- a/src/palette/internal/mimedatautils.h +++ b/src/palette/internal/mimedatautils.h @@ -24,6 +24,8 @@ #include "io/buffer.h" +#include "global/modularity/ioc.h" + #include "engraving/rw/xmlreader.h" #include "engraving/rw/xmlwriter.h" @@ -41,13 +43,13 @@ QByteArray toMimeData(T* t) } template -std::shared_ptr fromMimeData(const QByteArray& data, const muse::AsciiStringView& tagName) +std::shared_ptr fromMimeData(const QByteArray& data, const muse::AsciiStringView& tagName, const muse::modularity::ContextPtr& iocCtx) { engraving::XmlReader e(data); while (e.readNextStartElement()) { const muse::AsciiStringView tag(e.name()); if (tag == tagName) { - std::shared_ptr t(new T); + std::shared_ptr t(new T(iocCtx)); if (!t->read(e, true)) { return nullptr; } diff --git a/src/palette/internal/palette.cpp b/src/palette/internal/palette.cpp index bc33f448b4872..d4b8c092be3dc 100644 --- a/src/palette/internal/palette.cpp +++ b/src/palette/internal/palette.cpp @@ -25,6 +25,7 @@ #include "io/buffer.h" #include "io/file.h" +#include "modularity/ioc.h" #include "serialization/zipreader.h" #include "serialization/zipwriter.h" @@ -51,8 +52,8 @@ using namespace muse; using namespace muse::io; using namespace muse::actions; -Palette::Palette(Type t, QObject* parent) - : QObject(parent), m_type(t) +Palette::Palette(const muse::modularity::ContextPtr& iocCtx, Type t, QObject* parent) + : QObject(parent), muse::Injectable(iocCtx), m_type(t) { static int id = 0; m_id = QString::number(++id); @@ -110,7 +111,7 @@ PaletteCellPtr Palette::insertElement(size_t idx, ElementPtr element, const QStr engravingRender()->layoutItem(element.get()); } - PaletteCellPtr cell = std::make_shared(element, name, mag, offset, tag, this); + PaletteCellPtr cell = std::make_shared(iocContext(), element, name, mag, offset, tag, this); auto cellHandler = cellHandlerByPaletteType(m_type); if (cellHandler) { @@ -145,7 +146,7 @@ PaletteCellPtr Palette::appendElement(ElementPtr element, const QString& name, q engravingRender()->layoutItem(element.get()); } - PaletteCellPtr cell = std::make_shared(element, name, mag, offset, tag, this); + PaletteCellPtr cell = std::make_shared(iocContext(), element, name, mag, offset, tag, this); auto cellHandler = cellHandlerByPaletteType(m_type); if (cellHandler) { @@ -317,7 +318,7 @@ bool Palette::read(XmlReader& e, bool pasteMode) } else if (tag == "editable") { m_isEditable = e.readBool(); } else if (tag == "Cell") { - PaletteCellPtr cell = std::make_shared(this); + PaletteCellPtr cell = std::make_shared(iocContext(), this); if (!cell->read(e, pasteMode)) { continue; } @@ -387,9 +388,9 @@ void Palette::write(XmlWriter& xml, bool pasteMode) const xml.endElement(); } -PalettePtr Palette::fromMimeData(const QByteArray& data) +PalettePtr Palette::fromMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx) { - return ::fromMimeData(data, "Palette"); + return ::fromMimeData(data, "Palette", iocCtx); } bool Palette::readFromFile(const QString& p) diff --git a/src/palette/internal/palette.h b/src/palette/internal/palette.h index d5e3730b34267..42216ce70336d 100644 --- a/src/palette/internal/palette.h +++ b/src/palette/internal/palette.h @@ -46,14 +46,14 @@ namespace mu::palette { class Palette; using PalettePtr = std::shared_ptr; -class Palette : public QObject +class Palette : public QObject, public muse::Injectable { Q_GADGET - INJECT_STATIC(IPaletteConfiguration, configuration) - INJECT_STATIC(muse::ui::IUiActionsRegister, actionsRegister) - INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender) - INJECT(muse::IInteractive, interactive) + muse::Inject configuration = { this }; + muse::Inject actionsRegister = { this }; + muse::Inject engravingRender = { this }; + muse::Inject interactive = { this }; public: enum class Type { @@ -93,7 +93,7 @@ class Palette : public QObject }; Q_ENUM(Type) - explicit Palette(Type t = Type::Custom, QObject* parent = nullptr); + explicit Palette(const muse::modularity::ContextPtr& iocCtx, Type t = Type::Custom, QObject* parent = nullptr); ~Palette(); QString id() const; @@ -170,7 +170,7 @@ class Palette : public QObject bool read(engraving::XmlReader&, bool pasteMode); void write(engraving::XmlWriter&, bool pasteMode) const; - static PalettePtr fromMimeData(const QByteArray& data); + static PalettePtr fromMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx); QByteArray toMimeData() const; bool readFromFile(const QString& path); diff --git a/src/palette/internal/palettecell.cpp b/src/palette/internal/palettecell.cpp index b57135da8de08..7cb56598a4aa4 100644 --- a/src/palette/internal/palettecell.cpp +++ b/src/palette/internal/palettecell.cpp @@ -64,14 +64,15 @@ static bool needsStaff(ElementPtr e) } } -PaletteCell::PaletteCell(QObject* parent) - : QObject(parent) +PaletteCell::PaletteCell(const muse::modularity::ContextPtr& iocCtx, QObject* parent) + : QObject(parent), muse::Injectable(iocCtx) { id = makeId(); } -PaletteCell::PaletteCell(ElementPtr e, const QString& _name, qreal _mag, const QPointF& _offset, const QString& _tag, QObject* parent) - : QObject(parent), element(e), name(_name), mag(_mag), xoffset(_offset.x()), yoffset(_offset.y()), tag(_tag) +PaletteCell::PaletteCell(const muse::modularity::ContextPtr& iocCtx, ElementPtr e, const QString& _name, qreal _mag, const QPointF& _offset, + const QString& _tag, QObject* parent) + : QObject(parent), muse::Injectable(iocCtx), element(e), name(_name), mag(_mag), xoffset(_offset.x()), yoffset(_offset.y()), tag(_tag) { id = makeId(); drawStaff = needsStaff(element); @@ -314,12 +315,12 @@ void PaletteCell::write(XmlWriter& xml, bool pasteMode) const xml.endElement(); } -PaletteCellPtr PaletteCell::fromMimeData(const QByteArray& data) +PaletteCellPtr PaletteCell::fromMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx) { - return ::fromMimeData(data, "Cell"); + return ::fromMimeData(data, "Cell", iocCtx); } -PaletteCellPtr PaletteCell::fromElementMimeData(const QByteArray& data) +PaletteCellPtr PaletteCell::fromElementMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx) { PointF dragOffset; Fraction duration(1, 4); @@ -343,7 +344,7 @@ PaletteCellPtr PaletteCell::fromElementMimeData(const QByteArray& data) const String name = (element->isFretDiagram()) ? toFretDiagram(element.get())->harmonyPlainText() : element->translatedTypeUserName(); - return std::make_shared(element, name); + return std::make_shared(iocCtx, element, name); } QByteArray PaletteCell::toMimeData() const diff --git a/src/palette/internal/palettecell.h b/src/palette/internal/palettecell.h index 27dcc1598467e..db4d050434549 100644 --- a/src/palette/internal/palettecell.h +++ b/src/palette/internal/palettecell.h @@ -63,14 +63,14 @@ class AccessiblePaletteCellInterface : public QAccessibleInterface PaletteCell* m_cell = nullptr; }; -class PaletteCell : public QObject +class PaletteCell : public QObject, public muse::Injectable { Q_OBJECT - INJECT_STATIC(muse::ui::IUiActionsRegister, actionsRegister) + static inline muse::GlobalInject actionsRegister; public: - explicit PaletteCell(QObject* parent = nullptr); - PaletteCell(mu::engraving::ElementPtr e, const QString& _name, qreal _mag = 1.0, + explicit PaletteCell(const muse::modularity::ContextPtr& iocCtx, QObject* parent = nullptr); + PaletteCell(const muse::modularity::ContextPtr& iocCtx, mu::engraving::ElementPtr e, const QString& _name, qreal _mag = 1.0, const QPointF& offset = QPointF(), const QString& tag = "", QObject* parent = nullptr); static QAccessibleInterface* accessibleInterface(QObject* object); @@ -87,8 +87,8 @@ class PaletteCell : public QObject bool read(mu::engraving::XmlReader&, bool pasteMode); QByteArray toMimeData() const; - static PaletteCellPtr fromMimeData(const QByteArray& data); - static PaletteCellPtr fromElementMimeData(const QByteArray& data); + static PaletteCellPtr fromMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx); + static PaletteCellPtr fromElementMimeData(const QByteArray& data, const muse::modularity::ContextPtr& iocCtx); mu::engraving::ElementPtr element; mu::engraving::ElementPtr untranslatedElement; diff --git a/src/palette/internal/palettecelliconengine.cpp b/src/palette/internal/palettecelliconengine.cpp index e870b1b3c51e2..5190c663dac54 100644 --- a/src/palette/internal/palettecelliconengine.cpp +++ b/src/palette/internal/palettecelliconengine.cpp @@ -39,14 +39,14 @@ using namespace mu::palette; using namespace muse::draw; using namespace mu::engraving; -PaletteCellIconEngine::PaletteCellIconEngine(PaletteCellConstPtr cell, qreal extraMag) - : QIconEngine(), m_cell(cell), m_extraMag(extraMag) +PaletteCellIconEngine::PaletteCellIconEngine(PaletteCellConstPtr cell, const muse::modularity::ContextPtr& ctx, qreal extraMag) + : QIconEngine(), muse::Injectable(ctx), m_cell(cell), m_extraMag(extraMag) { } QIconEngine* PaletteCellIconEngine::clone() const { - return new PaletteCellIconEngine(m_cell, m_extraMag); + return new PaletteCellIconEngine(m_cell, iocContext(), m_extraMag); } void PaletteCellIconEngine::paint(QPainter* qp, const QRect& rect, QIcon::Mode mode, QIcon::State state) @@ -86,7 +86,7 @@ void PaletteCellIconEngine::paintCell(Painter& painter, const RectF& rect, bool //! NOTE: Slight hack - we can now specify exactly now many staff lines we want... params.numStaffLines = m_cell->drawStaff ? 5 : 0; - notation::EngravingItemPreviewPainter::paintPreview(element, params); + notation::EngravingItemPreviewPainter::paintPreview(engravingRender(), element, params); } void PaletteCellIconEngine::paintBackground(Painter& painter, const RectF& rect, bool selected, bool current) const diff --git a/src/palette/internal/palettecelliconengine.h b/src/palette/internal/palettecelliconengine.h index 6b5414f5dbffc..e5f1ef84ae340 100644 --- a/src/palette/internal/palettecelliconengine.h +++ b/src/palette/internal/palettecelliconengine.h @@ -35,13 +35,13 @@ class Painter; } namespace mu::palette { -class PaletteCellIconEngine : public QIconEngine +class PaletteCellIconEngine : public QIconEngine, public muse::Injectable { - INJECT_STATIC(IPaletteConfiguration, configuration) - INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender) + muse::Inject configuration = { this }; + muse::Inject engravingRender = { this }; public: - explicit PaletteCellIconEngine(PaletteCellConstPtr cell, qreal extraMag = 1.0); + explicit PaletteCellIconEngine(PaletteCellConstPtr cell, const muse::modularity::ContextPtr& ctx, qreal extraMag = 1.0); QIconEngine* clone() const override; diff --git a/src/palette/internal/palettecreator.cpp b/src/palette/internal/palettecreator.cpp index da30ca29a3197..e3e65b046ae73 100644 --- a/src/palette/internal/palettecreator.cpp +++ b/src/palette/internal/palettecreator.cpp @@ -214,7 +214,7 @@ PaletteTreePtr PaletteCreator::newDefaultPaletteTree() PalettePtr PaletteCreator::newBeamPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Beam); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Beam); sp->setName(QT_TRANSLATE_NOOP("palette", "Beam properties")); sp->setGridSize(35, 33); sp->setDrawGrid(true); @@ -235,7 +235,7 @@ PalettePtr PaletteCreator::newBeamPalette() PalettePtr PaletteCreator::newDynamicsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Dynamic); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Dynamic); sp->setName(QT_TRANSLATE_NOOP("palette", "Dynamics")); sp->setGridSize(defaultPalette ? 50 : 60, 28); sp->setDrawGrid(true); @@ -281,7 +281,7 @@ PalettePtr PaletteCreator::newDynamicsPalette(bool defaultPalette) PalettePtr PaletteCreator::newKeySigPalette() { - PalettePtr sp = std::make_shared(Palette::Type::KeySig); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::KeySig); sp->setName(QT_TRANSLATE_NOOP("palette", "Key signatures")); sp->setMag(0.8); sp->setGridSize(56, 47); @@ -316,7 +316,7 @@ PalettePtr PaletteCreator::newKeySigPalette() PalettePtr PaletteCreator::newAccidentalsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Accidental); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Accidental); sp->setName(QT_TRANSLATE_NOOP("palette", "Accidentals")); sp->setGridSize(33, 36); sp->setDrawGrid(true); @@ -346,7 +346,7 @@ PalettePtr PaletteCreator::newAccidentalsPalette(bool defaultPalette) PalettePtr PaletteCreator::newBarLinePalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::BarLine); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::BarLine); sp->setName(QT_TRANSLATE_NOOP("palette", "Barlines")); sp->setMag(0.8); sp->setGridSize(48, 38); @@ -383,7 +383,7 @@ PalettePtr PaletteCreator::newBarLinePalette(bool defaultPalette) PalettePtr PaletteCreator::newRepeatsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Repeat); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Repeat); sp->setName(QT_TRANSLATE_NOOP("palette", "Repeats & jumps")); sp->setMag(0.75); sp->setGridSize(100, 28); @@ -519,7 +519,7 @@ PalettePtr PaletteCreator::newRepeatsPalette(bool defaultPalette) PalettePtr PaletteCreator::newLayoutPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Layout); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Layout); //: The name of a palette sp->setName(QT_TRANSLATE_NOOP("palette", "Layout")); sp->setGridSize(42, 36); @@ -569,7 +569,7 @@ PalettePtr PaletteCreator::newLayoutPalette(bool defaultPalette) PalettePtr PaletteCreator::newFingeringPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Fingering); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Fingering); sp->setName(QT_TRANSLATE_NOOP("palette", "Fingerings")); sp->setMag(1.5); sp->setGridSize(28, 30); @@ -625,7 +625,7 @@ PalettePtr PaletteCreator::newFingeringPalette(bool defaultPalette) PalettePtr PaletteCreator::newTremoloPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Tremolo); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Tremolo); sp->setName(QT_TRANSLATE_NOOP("palette", "Tremolos")); sp->setGridSize(27, 40); sp->setDrawGrid(true); @@ -660,7 +660,7 @@ PalettePtr PaletteCreator::newTremoloPalette() PalettePtr PaletteCreator::newNoteHeadsPalette() { - PalettePtr sp = std::make_shared(Palette::Type::NoteHead); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::NoteHead); sp->setName(QT_TRANSLATE_NOOP("palette", "Noteheads")); sp->setMag(1.3); sp->setGridSize(33, 36); @@ -685,7 +685,7 @@ PalettePtr PaletteCreator::newNoteHeadsPalette() PalettePtr PaletteCreator::newArticulationsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Articulation); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Articulation); sp->setName(QT_TRANSLATE_NOOP("palette", "Articulations")); sp->setGridSize(42, 25); sp->setDrawGrid(true); @@ -777,7 +777,7 @@ PalettePtr PaletteCreator::newArticulationsPalette(bool defaultPalette) PalettePtr PaletteCreator::newOrnamentsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Ornament); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Ornament); sp->setName(QT_TRANSLATE_NOOP("palette", "Ornaments")); sp->setGridSize(73, 27); sp->setMag(1); @@ -842,7 +842,7 @@ PalettePtr PaletteCreator::newOrnamentsPalette(bool defaultPalette) PalettePtr PaletteCreator::newAccordionPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Accordion); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Accordion); //: The name of a palette sp->setName(QT_TRANSLATE_NOOP("palette", "Accordion")); sp->setGridSize(42, 25); @@ -922,7 +922,7 @@ PalettePtr PaletteCreator::newAccordionPalette() PalettePtr PaletteCreator::newBracketsPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Bracket); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Bracket); sp->setName(QT_TRANSLATE_NOOP("palette", "Brackets")); sp->setMag(0.7); sp->setGridSize(40, 60); @@ -953,7 +953,7 @@ PalettePtr PaletteCreator::newBracketsPalette() PalettePtr PaletteCreator::newBreathPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Breath); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Breath); sp->setName(QT_TRANSLATE_NOOP("palette", "Breaths & pauses")); sp->setGridSize(40, 40); sp->setDrawGrid(true); @@ -1000,7 +1000,7 @@ PalettePtr PaletteCreator::newBreathPalette(bool defaultPalette) PalettePtr PaletteCreator::newArpeggioPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Arpeggio); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Arpeggio); sp->setName(QT_TRANSLATE_NOOP("palette", "Arpeggios & glissandos")); sp->setGridSize(42, 44); sp->setDrawGrid(true); @@ -1055,7 +1055,7 @@ PalettePtr PaletteCreator::newArpeggioPalette() PalettePtr PaletteCreator::newClefsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Clef); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Clef); sp->setName(QT_TRANSLATE_NOOP("palette", "Clefs")); sp->setMag(0.8); sp->setGridSize(36, 55); @@ -1088,7 +1088,7 @@ PalettePtr PaletteCreator::newClefsPalette(bool defaultPalette) PalettePtr PaletteCreator::newGraceNotePalette() { - PalettePtr sp = std::make_shared(Palette::Type::GraceNote); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::GraceNote); sp->setName(QT_TRANSLATE_NOOP("palette", "Grace notes")); sp->setMag(1.35); sp->setGridSize(45, 40); @@ -1109,7 +1109,7 @@ PalettePtr PaletteCreator::newGraceNotePalette() PalettePtr PaletteCreator::newBagpipeEmbellishmentPalette() { - PalettePtr sp = std::make_shared(Palette::Type::BagpipeEmbellishment); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::BagpipeEmbellishment); sp->setName(QT_TRANSLATE_NOOP("palette", "Bagpipe embellishments")); sp->setMag(0.8); sp->setYOffset(2.0); @@ -1129,7 +1129,7 @@ PalettePtr PaletteCreator::newBagpipeEmbellishmentPalette() PalettePtr PaletteCreator::newLinesPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Line); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Line); sp->setName(QT_TRANSLATE_NOOP("palette", "Lines")); sp->setMag(.8); sp->setGridSize(75, 28); @@ -1321,7 +1321,7 @@ PalettePtr PaletteCreator::newLinesPalette(bool defaultPalette) PalettePtr PaletteCreator::newTempoPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Tempo); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Tempo); sp->setName(QT_TRANSLATE_NOOP("palette", "Tempo")); sp->setMag(0.65); sp->setGridSize(90, 30); @@ -1483,7 +1483,7 @@ PalettePtr PaletteCreator::newTempoPalette(bool defaultPalette) PalettePtr PaletteCreator::newTextPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Text); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Text); sp->setName(QT_TRANSLATE_NOOP("palette", "Text")); sp->setGridSize(100, 28); sp->setMag(0.85); @@ -1594,7 +1594,7 @@ PalettePtr PaletteCreator::newTimePalette(bool defaultPalette) const char* name; }; - PalettePtr sp = std::make_shared(Palette::Type::TimeSig); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::TimeSig); sp->setName(QT_TRANSLATE_NOOP("palette", "Time signatures")); sp->setMag(.8); sp->setGridSize(42, 38); @@ -1652,7 +1652,7 @@ PalettePtr PaletteCreator::newTimePalette(bool defaultPalette) PalettePtr PaletteCreator::newFretboardDiagramPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::FretboardDiagram); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::FretboardDiagram); sp->setName(QT_TRANSLATE_NOOP("palette", "Fretboard diagrams")); sp->setGridSize(42, 45); sp->setDrawGrid(true); @@ -1717,7 +1717,7 @@ PalettePtr PaletteCreator::newFretboardDiagramPalette(bool defaultPalette) PalettePtr PaletteCreator::newGuitarPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Guitar); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Guitar); sp->setName(QT_TRANSLATE_NOOP("palette", "Guitar")); sp->setGridSize(60, 33); sp->setMag(1.2); @@ -1838,7 +1838,7 @@ PalettePtr PaletteCreator::newGuitarPalette(bool defaultPalette) PalettePtr PaletteCreator::newKeyboardPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Keyboard); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Keyboard); sp->setName(QT_TRANSLATE_NOOP("palette", "Keyboard")); sp->setGridSize(73, 30); sp->setDrawGrid(true); @@ -1894,7 +1894,7 @@ PalettePtr PaletteCreator::newKeyboardPalette() PalettePtr PaletteCreator::newPitchPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Pitch); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Pitch); //: The name of a palette sp->setName(QT_TRANSLATE_NOOP("palette", "Pitch")); sp->setGridSize(100, 30); @@ -1931,7 +1931,7 @@ PalettePtr PaletteCreator::newPitchPalette(bool defaultPalette) PalettePtr PaletteCreator::newHarpPalette() { - PalettePtr sp = std::make_shared(Palette::Type::Harp); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Harp); sp->setName(QT_TRANSLATE_NOOP("palette", "Harp")); sp->setGridSize(90, 30); sp->setDrawGrid(true); @@ -1950,7 +1950,7 @@ PalettePtr PaletteCreator::newHarpPalette() PalettePtr PaletteCreator::newHandbellsPalette(bool defaultPalette) { - PalettePtr sp = std::make_shared(Palette::Type::Handbells); + PalettePtr sp = std::make_shared(iocContext(), Palette::Type::Handbells); sp->setName(QT_TRANSLATE_NOOP("palette", "Handbells")); sp->setGridSize(42, 25); sp->setDrawGrid(true); diff --git a/src/palette/internal/palettecreator.h b/src/palette/internal/palettecreator.h index 1bbd26d28b629..19961f88298a8 100644 --- a/src/palette/internal/palettecreator.h +++ b/src/palette/internal/palettecreator.h @@ -29,43 +29,49 @@ #include "ipaletteconfiguration.h" namespace mu::palette { -class PaletteCreator +class PaletteCreator : public muse::Injectable { - INJECT_STATIC(IPaletteConfiguration, configuration) + muse::Inject configuration; public: - static PalettePtr newTempoPalette(bool defaultPalette = false); - static PalettePtr newTextPalette(bool defaultPalette = false); - static PalettePtr newTimePalette(bool defaultPalette = false); - static PalettePtr newRepeatsPalette(bool defaultPalette = false); - static PalettePtr newBeamPalette(); - static PalettePtr newDynamicsPalette(bool defaultPalette = false); - static PalettePtr newLayoutPalette(bool defaultPalette = false); - static PalettePtr newFingeringPalette(bool defaultPalette = false); - static PalettePtr newTremoloPalette(); - static PalettePtr newNoteHeadsPalette(); - static PalettePtr newArticulationsPalette(bool defaultPalette = false); - static PalettePtr newOrnamentsPalette(bool defaultPalette = false); - static PalettePtr newAccordionPalette(); - static PalettePtr newBracketsPalette(); - static PalettePtr newBreathPalette(bool defaultPalette = false); - static PalettePtr newArpeggioPalette(); - static PalettePtr newClefsPalette(bool defaultPalette = false); - static PalettePtr newGraceNotePalette(); - static PalettePtr newBagpipeEmbellishmentPalette(); - static PalettePtr newKeySigPalette(); - static PalettePtr newAccidentalsPalette(bool defaultPalette = false); - static PalettePtr newBarLinePalette(bool defaultPalette = false); - static PalettePtr newLinesPalette(bool defaultPalette = false); - static PalettePtr newFretboardDiagramPalette(bool defaultPalette = false); - static PalettePtr newGuitarPalette(bool defaultPalette = false); - static PalettePtr newKeyboardPalette(); - static PalettePtr newPitchPalette(bool defaultPalette = false); - static PalettePtr newHarpPalette(); - static PalettePtr newHandbellsPalette(bool defaultPalette = false); - static PaletteTreePtr newMasterPaletteTree(); - static PaletteTreePtr newDefaultPaletteTree(); + PaletteCreator(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + + PalettePtr newTempoPalette(bool defaultPalette = false); + PalettePtr newTextPalette(bool defaultPalette = false); + PalettePtr newTimePalette(bool defaultPalette = false); + PalettePtr newRepeatsPalette(bool defaultPalette = false); + PalettePtr newBeamPalette(); + PalettePtr newDynamicsPalette(bool defaultPalette = false); + PalettePtr newLayoutPalette(bool defaultPalette = false); + PalettePtr newFingeringPalette(bool defaultPalette = false); + PalettePtr newTremoloPalette(); + PalettePtr newNoteHeadsPalette(); + PalettePtr newArticulationsPalette(bool defaultPalette = false); + PalettePtr newOrnamentsPalette(bool defaultPalette = false); + PalettePtr newAccordionPalette(); + PalettePtr newBracketsPalette(); + PalettePtr newBreathPalette(bool defaultPalette = false); + PalettePtr newArpeggioPalette(); + PalettePtr newClefsPalette(bool defaultPalette = false); + PalettePtr newGraceNotePalette(); + PalettePtr newBagpipeEmbellishmentPalette(); + PalettePtr newKeySigPalette(); + PalettePtr newAccidentalsPalette(bool defaultPalette = false); + PalettePtr newBarLinePalette(bool defaultPalette = false); + PalettePtr newLinesPalette(bool defaultPalette = false); + PalettePtr newFretboardDiagramPalette(bool defaultPalette = false); + PalettePtr newGuitarPalette(bool defaultPalette = false); + PalettePtr newKeyboardPalette(); + PalettePtr newPitchPalette(bool defaultPalette = false); + PalettePtr newHarpPalette(); + PalettePtr newHandbellsPalette(bool defaultPalette = false); + + PaletteTreePtr newMasterPaletteTree(); + PaletteTreePtr newDefaultPaletteTree(); }; } diff --git a/src/palette/internal/paletteprovider.cpp b/src/palette/internal/paletteprovider.cpp index 65fe450d293e3..3a4b87d55b219 100644 --- a/src/palette/internal/paletteprovider.cpp +++ b/src/palette/internal/paletteprovider.cpp @@ -233,7 +233,7 @@ Qt::DropAction UserPaletteController::dropAction(const QVariantMap& mimeData, Qt } if (mimeData.contains(PaletteCell::mimeDataFormat) && proposedAction == Qt::MoveAction) { - const auto cell = PaletteCell::fromMimeData(mimeData[PaletteCell::mimeDataFormat].toByteArray()); + const auto cell = PaletteCell::fromMimeData(mimeData[PaletteCell::mimeDataFormat].toByteArray(), iocContext()); if (!cell) { return Qt::IgnoreAction; } @@ -265,7 +265,7 @@ bool UserPaletteController::insert(const QModelIndex& parent, int row, const QVa PaletteCellPtr cell; if (mimeData.contains(PaletteCell::mimeDataFormat)) { - cell = PaletteCell::fromMimeData(mimeData[PaletteCell::mimeDataFormat].toByteArray()); + cell = PaletteCell::fromMimeData(mimeData[PaletteCell::mimeDataFormat].toByteArray(), iocContext()); if (!cell) { return false; @@ -284,7 +284,7 @@ bool UserPaletteController::insert(const QModelIndex& parent, int row, const QVa } } } else if (mimeData.contains(mimeSymbolFormat) && (action == Qt::CopyAction)) { - cell = PaletteCell::fromElementMimeData(mimeData[mimeSymbolFormat].toByteArray()); + cell = PaletteCell::fromElementMimeData(mimeData[mimeSymbolFormat].toByteArray(), iocContext()); } if (!cell) { @@ -602,11 +602,10 @@ bool UserPaletteController::applyPaletteElement(const QModelIndex& index, Qt::Ke void PaletteProvider::init() { - m_userPaletteModel = new PaletteTreeModel(std::make_shared(), this); + m_userPaletteModel = new PaletteTreeModel(std::make_shared(), iocContext(), this); connect(m_userPaletteModel, &PaletteTreeModel::treeChanged, this, &PaletteProvider::notifyAboutUserPaletteChanged); - m_masterPaletteModel = new PaletteTreeModel(PaletteCreator::newMasterPaletteTree()); - m_masterPaletteModel->setParent(this); + m_masterPaletteModel = new PaletteTreeModel(PaletteCreator(iocContext()).newMasterPaletteTree(), iocContext(), this); m_searchFilterModel = new PaletteCellFilterProxyModel(this); m_searchFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -957,7 +956,7 @@ bool PaletteProvider::loadPalette(const QModelIndex& index) return false; } - PalettePtr pp = std::make_shared(); + PalettePtr pp = std::make_shared(iocContext()); if (!pp->readFromFile(path)) { return false; } @@ -978,7 +977,7 @@ void PaletteProvider::setUserPaletteTree(PaletteTreePtr tree) m_userPaletteModel->setPaletteTree(tree); connect(m_userPaletteModel, &PaletteTreeModel::treeChanged, this, &PaletteProvider::notifyAboutUserPaletteChanged); } else { - m_userPaletteModel = new PaletteTreeModel(tree, /* parent */ this); + m_userPaletteModel = new PaletteTreeModel(tree, iocContext(), /* parent */ this); connect(m_userPaletteModel, &PaletteTreeModel::treeChanged, this, &PaletteProvider::notifyAboutUserPaletteChanged); } } @@ -988,7 +987,7 @@ void PaletteProvider::setDefaultPaletteTree(PaletteTreePtr tree) if (m_defaultPaletteModel) { m_defaultPaletteModel->setPaletteTree(tree); } else { - m_defaultPaletteModel = new PaletteTreeModel(tree, /* parent */ this); + m_defaultPaletteModel = new PaletteTreeModel(tree, iocContext(), /* parent */ this); } } @@ -1010,7 +1009,7 @@ void PaletteProvider::write(XmlWriter& xml, bool pasteMode) const bool PaletteProvider::read(XmlReader& e, bool pasteMode) { PaletteTreePtr tree = std::make_shared(); - if (!tree->read(e, pasteMode)) { + if (!tree->read(e, pasteMode, iocContext())) { return false; } diff --git a/src/palette/internal/paletteprovider.h b/src/palette/internal/paletteprovider.h index 3556b5bd10c65..eb405efcaa8ec 100644 --- a/src/palette/internal/paletteprovider.h +++ b/src/palette/internal/paletteprovider.h @@ -43,22 +43,22 @@ class PaletteProvider; // PaletteElementEditor // ======================================================== -class PaletteElementEditor : public QObject, public muse::async::Asyncable +class PaletteElementEditor : public QObject, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(muse::IInteractive, interactive) - INJECT(IPaletteProvider, paletteProvider) - Q_PROPERTY(bool valid READ valid CONSTANT) Q_PROPERTY(QString actionName READ actionName CONSTANT) // TODO: make NOTIFY instead of CONSTANT for retranslations + muse::Inject interactive = { this }; + muse::Inject paletteProvider = { this }; public: PaletteElementEditor(QObject* parent = nullptr) - : QObject(parent) {} + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) {} PaletteElementEditor(AbstractPaletteController* controller, QPersistentModelIndex paletteIndex, Palette::Type type, QObject* parent = nullptr) - : QObject(parent), _controller(controller), _paletteIndex(paletteIndex), _type(type) {} + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)), + _controller(controller), _paletteIndex(paletteIndex), _type(type) {} bool valid() const; QString actionName() const; @@ -79,7 +79,7 @@ class PaletteElementEditor : public QObject, public muse::async::Asyncable // AbstractPaletteController // ======================================================== -class AbstractPaletteController : public QObject +class AbstractPaletteController : public QObject, public muse::Injectable { Q_OBJECT @@ -97,7 +97,7 @@ class AbstractPaletteController : public QObject }; AbstractPaletteController(QObject* parent = nullptr) - : QObject(parent) {} + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) {} Q_INVOKABLE virtual Qt::DropAction dropAction(const QVariantMap& mimeData, Qt::DropAction proposedAction, const QModelIndex& parent, bool internal) const @@ -142,9 +142,9 @@ class UserPaletteController : public AbstractPaletteController, public muse::asy { Q_OBJECT - INJECT(context::IGlobalContext, globalContext) - INJECT(muse::IInteractive, interactive) - INJECT(IPaletteConfiguration, configuration) + muse::Inject globalContext = { this }; + muse::Inject interactive = { this }; + muse::Inject configuration = { this }; QAbstractItemModel* _model; PaletteTreeModel* _userPalette; @@ -205,13 +205,10 @@ class UserPaletteController : public AbstractPaletteController, public muse::asy // PaletteProvider // ======================================================== -class PaletteProvider : public QObject, public IPaletteProvider, public muse::async::Asyncable +class PaletteProvider : public QObject, public IPaletteProvider, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(IPaletteConfiguration, configuration) - INJECT(muse::IInteractive, interactive) - Q_PROPERTY(QAbstractItemModel * mainPaletteModel READ mainPaletteModel NOTIFY mainPaletteChanged) Q_PROPERTY(mu::palette::AbstractPaletteController * mainPaletteController READ mainPaletteController NOTIFY mainPaletteChanged) @@ -222,7 +219,15 @@ class PaletteProvider : public QObject, public IPaletteProvider, public muse::as Q_PROPERTY(bool isSingleClickToOpenPalette READ isSingleClickToOpenPalette NOTIFY isSingleClickToOpenPaletteChanged) Q_PROPERTY(bool isPaletteDragEnabled READ isPaletteDragEnabled NOTIFY isPaletteDragEnabledChanged) + muse::Inject configuration = { this }; + muse::Inject interactive = { this }; public: + + PaletteProvider(const muse::modularity::ContextPtr& ctx, QObject* parent = nullptr) + : QObject(parent), muse::Injectable(ctx) + { + } + void init() override; PaletteTreeModel* userPaletteModel() const { return m_userPaletteModel; } @@ -300,9 +305,9 @@ private slots: void doResetPalette(const QModelIndex& index); - PaletteTreeModel* m_userPaletteModel; - PaletteTreeModel* m_masterPaletteModel; - PaletteTreeModel* m_defaultPaletteModel; // palette used by "Reset palette" action + PaletteTreeModel* m_userPaletteModel = nullptr; + PaletteTreeModel* m_masterPaletteModel = nullptr; + PaletteTreeModel* m_defaultPaletteModel = nullptr; // palette used by "Reset palette" action muse::async::Notification m_userPaletteChanged; diff --git a/src/palette/internal/palettetree.cpp b/src/palette/internal/palettetree.cpp index 2eee05f3d7425..bccd2b4886fba 100644 --- a/src/palette/internal/palettetree.cpp +++ b/src/palette/internal/palettetree.cpp @@ -39,12 +39,12 @@ void PaletteTree::append(PalettePtr palette) palettes.emplace_back(palette); } -bool PaletteTree::read(mu::engraving::XmlReader& e, bool pasteMode) +bool PaletteTree::read(mu::engraving::XmlReader& e, bool pasteMode, const muse::modularity::ContextPtr& iocCtx) { while (e.readNextStartElement()) { const muse::AsciiStringView tag(e.name()); if (tag == "Palette") { - PalettePtr p = std::make_shared(); + PalettePtr p = std::make_shared(iocCtx); p->read(e, pasteMode); palettes.push_back(p); } else { diff --git a/src/palette/internal/palettetree.h b/src/palette/internal/palettetree.h index f90f3822b1215..424b4bd03ce91 100644 --- a/src/palette/internal/palettetree.h +++ b/src/palette/internal/palettetree.h @@ -38,7 +38,7 @@ struct PaletteTree void insert(size_t idx, PalettePtr palette); void append(PalettePtr palette); - bool read(mu::engraving::XmlReader&, bool pasteMode); + bool read(mu::engraving::XmlReader&, bool pasteMode, const muse::modularity::ContextPtr& iocCtx); void write(mu::engraving::XmlWriter&, bool pasteMode) const; void retranslate(); diff --git a/src/palette/internal/paletteuiactions.h b/src/palette/internal/paletteuiactions.h index 20061c0998ee8..0ad47f5452860 100644 --- a/src/palette/internal/paletteuiactions.h +++ b/src/palette/internal/paletteuiactions.h @@ -31,7 +31,8 @@ namespace mu::palette { class PaletteUiActions : public muse::ui::IUiActionsModule, public muse::async::Asyncable { - INJECT(context::IUiContextResolver, uicontextResolver) + muse::GlobalInject uicontextResolver; + public: PaletteUiActions(std::shared_ptr controller); diff --git a/src/palette/internal/paletteworkspacesetup.cpp b/src/palette/internal/paletteworkspacesetup.cpp index 523e76a9f26a2..706fe1ef0c90e 100644 --- a/src/palette/internal/paletteworkspacesetup.cpp +++ b/src/palette/internal/paletteworkspacesetup.cpp @@ -39,7 +39,7 @@ using namespace muse::workspace; static const AsciiStringView PALETTE_XML_TAG("PaletteBox"); -static PaletteTreePtr readPalette(const ByteArray& data) +static PaletteTreePtr readPalette(const ByteArray& data, const muse::modularity::ContextPtr& iocCtx) { ByteArray ba = ByteArray::fromRawData(data.constData(), data.size()); Buffer buf(&ba); @@ -51,7 +51,7 @@ static PaletteTreePtr readPalette(const ByteArray& data) if (reader.name() == PALETTE_XML_TAG) { PaletteTreePtr tree = std::make_shared(); - tree->read(reader, false); + tree->read(reader, false, iocCtx); return tree; } } @@ -75,7 +75,7 @@ void PaletteWorkspaceSetup::setup() return; } - paletteProvider()->setDefaultPaletteTree(PaletteCreator::newDefaultPaletteTree()); + paletteProvider()->setDefaultPaletteTree(PaletteCreator(iocContext()).newDefaultPaletteTree()); paletteProvider()->userPaletteTreeChanged().onNotify(this, [this]() { PaletteTreePtr tree = paletteProvider()->userPaletteTree(); @@ -92,10 +92,10 @@ void PaletteWorkspaceSetup::setup() if (data.ret && !data.val.isEmpty()) { LOGD() << "there is palette data in the workspace, we will use it"; ByteArray ba = ByteArray::fromQByteArrayNoCopy(data.val); - tree = readPalette(ba); + tree = readPalette(ba, iocContext()); } else { LOGD() << "no palette data in workspace, will use default"; - tree = PaletteCreator::newDefaultPaletteTree(); + tree = PaletteCreator(iocContext()).newDefaultPaletteTree(); } paletteProvider()->setUserPaletteTree(tree); }; diff --git a/src/palette/internal/paletteworkspacesetup.h b/src/palette/internal/paletteworkspacesetup.h index 345a11cb6e487..f73e01d72d804 100644 --- a/src/palette/internal/paletteworkspacesetup.h +++ b/src/palette/internal/paletteworkspacesetup.h @@ -28,12 +28,18 @@ #include "async/asyncable.h" namespace mu::palette { -class PaletteWorkspaceSetup : public muse::async::Asyncable +class PaletteWorkspaceSetup : public muse::async::Asyncable, public muse::Injectable { - INJECT(muse::workspace::IWorkspacesDataProvider, workspacesDataProvider) - INJECT(IPaletteProvider, paletteProvider) + muse::Inject workspacesDataProvider = { this }; + muse::Inject paletteProvider = { this }; public: + + explicit PaletteWorkspaceSetup(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + void setup(); }; } diff --git a/src/palette/palettemodule.cpp b/src/palette/palettemodule.cpp index ff058e68abf16..9af8999008d1e 100644 --- a/src/palette/palettemodule.cpp +++ b/src/palette/palettemodule.cpp @@ -67,11 +67,11 @@ std::string PaletteModule::moduleName() const void PaletteModule::registerExports() { - m_paletteProvider = std::make_shared(); + m_paletteProvider = std::make_shared(iocContext()); m_actionsController = std::make_shared(); m_paletteUiActions = std::make_shared(m_actionsController); m_configuration = std::make_shared(); - m_paletteWorkspaceSetup = std::make_shared(); + m_paletteWorkspaceSetup = std::make_shared(iocContext()); ioc()->registerExport(moduleName(), m_paletteProvider); ioc()->registerExport(moduleName(), m_configuration); diff --git a/src/palette/view/drumsetpanelview.cpp b/src/palette/view/drumsetpanelview.cpp index 2f966c74e3f17..0396bfdce8f78 100644 --- a/src/palette/view/drumsetpanelview.cpp +++ b/src/palette/view/drumsetpanelview.cpp @@ -77,7 +77,7 @@ class DrumsetPaletteAdapter : public muse::uicomponents::IDisplayableWidget using namespace mu::palette; DrumsetPanelView::DrumsetPanelView(QQuickItem* parent) - : WidgetView(parent) + : WidgetView(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/palette/view/drumsetpanelview.h b/src/palette/view/drumsetpanelview.h index f2284dfaa85f1..ef1baa749a49e 100644 --- a/src/palette/view/drumsetpanelview.h +++ b/src/palette/view/drumsetpanelview.h @@ -33,17 +33,17 @@ namespace mu::palette { class DrumsetPaletteAdapter; -class DrumsetPanelView : public muse::uicomponents::WidgetView, public muse::async::Asyncable +class DrumsetPanelView : public muse::uicomponents::WidgetView, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(context::IGlobalContext, globalContext) - INJECT(muse::actions::IActionsDispatcher, dispatcher) - INJECT(notation::INotationConfiguration, notationConfiguration) - INJECT(engraving::IEngravingConfiguration, engravingConfiguration) - Q_PROPERTY(QString pitchName READ pitchName NOTIFY pitchNameChanged) + muse::Inject globalContext = { this }; + muse::Inject dispatcher = { this }; + muse::Inject notationConfiguration = { this }; + muse::Inject engravingConfiguration = { this }; + public: explicit DrumsetPanelView(QQuickItem* parent = nullptr); diff --git a/src/palette/view/palettemodel.cpp b/src/palette/view/palettemodel.cpp index 335880780a8fb..eb2b4910691fd 100644 --- a/src/palette/view/palettemodel.cpp +++ b/src/palette/view/palettemodel.cpp @@ -32,6 +32,7 @@ #include "engraving/dom/chordrest.h" #include "engraving/dom/select.h" +#include "modularity/ioc.h" #include "translation.h" using namespace mu; @@ -42,8 +43,8 @@ using namespace mu::engraving; // PaletteTreeModel::PaletteTreeModel //--------------------------------------------------------- -PaletteTreeModel::PaletteTreeModel(PaletteTreePtr tree, QObject* parent) - : QAbstractItemModel(parent), _paletteTree(tree) +PaletteTreeModel::PaletteTreeModel(PaletteTreePtr tree, const muse::modularity::ContextPtr& ctx, QObject* parent) + : QAbstractItemModel(parent), muse::Injectable(ctx), _paletteTree(tree) { connect(this, &QAbstractItemModel::dataChanged, this, &PaletteTreeModel::onDataChanged); connect(this, &QAbstractItemModel::layoutChanged, this, &PaletteTreeModel::setTreeChanged); @@ -336,7 +337,7 @@ QVariant PaletteTreeModel::data(const QModelIndex& index, int role) const if (const Palette* pp = iptrToPalette(index.internalPointer())) { extraMag = pp->mag(); } - return QIcon(new PaletteCellIconEngine(cell, extraMag * configuration()->paletteScaling())); + return QIcon(new PaletteCellIconEngine(cell, iocContext(), extraMag * configuration()->paletteScaling())); } case PaletteCellRole: return QVariant::fromValue(cell.get()); @@ -502,7 +503,7 @@ bool PaletteTreeModel::setData(const QModelIndex& index, const QVariant& value, if (map.contains(PaletteCell::mimeDataFormat)) { const QByteArray cellMimeData = map[PaletteCell::mimeDataFormat].toByteArray(); - PaletteCellPtr newCell(PaletteCell::fromMimeData(cellMimeData)); + PaletteCellPtr newCell(PaletteCell::fromMimeData(cellMimeData, iocContext())); if (!newCell) { return false; } @@ -513,7 +514,7 @@ bool PaletteTreeModel::setData(const QModelIndex& index, const QVariant& value, cell->id = newCell->id; } else if (map.contains(mimeSymbolFormat)) { const QByteArray elementMimeData = map[mimeSymbolFormat].toByteArray(); - PaletteCellPtr newCell = PaletteCell::fromElementMimeData(elementMimeData); + PaletteCellPtr newCell = PaletteCell::fromElementMimeData(elementMimeData, iocContext()); cell->element = newCell->element; cell->untranslatedElement = newCell->untranslatedElement; @@ -649,7 +650,7 @@ bool PaletteTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action return false; } - auto palette = Palette::fromMimeData(data->data(Palette::mimeDataFormat)); + auto palette = Palette::fromMimeData(data->data(Palette::mimeDataFormat), iocContext()); if (!palette) { return false; } @@ -668,12 +669,12 @@ bool PaletteTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action PaletteCellPtr cell; if (data->hasFormat(PaletteCell::mimeDataFormat)) { - cell = PaletteCell::fromMimeData(data->data(PaletteCell::mimeDataFormat)); + cell = PaletteCell::fromMimeData(data->data(PaletteCell::mimeDataFormat), iocContext()); if (action == Qt::CopyAction) { cell->custom = true; } } else if (data->hasFormat(mimeSymbolFormat)) { - cell = PaletteCell::fromElementMimeData(data->data(mimeSymbolFormat)); + cell = PaletteCell::fromElementMimeData(data->data(mimeSymbolFormat), iocContext()); cell->custom = true; // the cell is created by dropping an element so it is custom } @@ -830,7 +831,7 @@ bool PaletteTreeModel::insertRows(int row, int count, const QModelIndex& parent) beginInsertRows(parent, row, row + count - 1); for (int i = 0; i < count; ++i) { - PalettePtr p = std::make_shared(Palette::Type::Custom); + PalettePtr p = std::make_shared(iocContext(), Palette::Type::Custom); p->setName(QT_TRANSLATE_NOOP("palette", "Untitled palette")); p->setGridSize(QSize(48, 48)); p->setExpanded(true); @@ -848,7 +849,7 @@ bool PaletteTreeModel::insertRows(int row, int count, const QModelIndex& parent) beginInsertRows(parent, row, row + count - 1); for (int i = 0; i < count; ++i) { - PaletteCellPtr cell = std::make_shared(palette); + PaletteCellPtr cell = std::make_shared(iocContext(), palette); palette->insertCell(row, cell); } endInsertRows(); diff --git a/src/palette/view/palettemodel.h b/src/palette/view/palettemodel.h index ff668b3bf9f1c..59591771b0f61 100644 --- a/src/palette/view/palettemodel.h +++ b/src/palette/view/palettemodel.h @@ -98,11 +98,11 @@ class CustomizedCellFilter : public PaletteCellFilter // PaletteTreeModel //--------------------------------------------------------- -class PaletteTreeModel : public QAbstractItemModel, public muse::async::Asyncable +class PaletteTreeModel : public QAbstractItemModel, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT(IPaletteConfiguration, configuration) + muse::Inject configuration = { this }; public: enum PaletteTreeModelRoles { @@ -148,7 +148,7 @@ public slots: void treeChanged(); public: - explicit PaletteTreeModel(PaletteTreePtr tree, QObject* parent = nullptr); + explicit PaletteTreeModel(PaletteTreePtr tree, const muse::modularity::ContextPtr& ctx, QObject* parent = nullptr); bool blockTreeChanged(bool block); diff --git a/src/palette/view/paletterootmodel.cpp b/src/palette/view/paletterootmodel.cpp index b6b4bf71d3353..aa1f951f6e47a 100644 --- a/src/palette/view/paletterootmodel.cpp +++ b/src/palette/view/paletterootmodel.cpp @@ -24,14 +24,8 @@ using namespace mu::palette; PaletteRootModel::PaletteRootModel(QObject* parent) - : QObject(parent) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { - dispatcher()->reg(this, "palette-search", [this]() { - emit paletteSearchRequested(); - }); - dispatcher()->reg(this, "apply-current-palette-element", [this]() { - emit applyCurrentPaletteElementRequested(); - }); } PaletteRootModel::~PaletteRootModel() @@ -42,6 +36,16 @@ PaletteRootModel::~PaletteRootModel() } } +void PaletteRootModel::classBegin() +{ + dispatcher()->reg(this, "palette-search", [this]() { + emit paletteSearchRequested(); + }); + dispatcher()->reg(this, "apply-current-palette-element", [this]() { + emit applyCurrentPaletteElementRequested(); + }); +} + PaletteProvider* PaletteRootModel::paletteProvider_property() const { return dynamic_cast(paletteProvider().get()); diff --git a/src/palette/view/paletterootmodel.h b/src/palette/view/paletterootmodel.h index c8f45ee8c7a65..7906b60dbf481 100644 --- a/src/palette/view/paletterootmodel.h +++ b/src/palette/view/paletterootmodel.h @@ -23,6 +23,8 @@ #define MU_PALETTE_PALETTEROOTMODEL_H #include +#include +#include #include "actions/actionable.h" #include "async/asyncable.h" @@ -32,15 +34,17 @@ #include "actions/iactionsdispatcher.h" namespace mu::palette { -class PaletteRootModel : public QObject, public muse::actions::Actionable, public muse::async::Asyncable +class PaletteRootModel : public QObject, public QQmlParserStatus, public muse::actions::Actionable, public muse::async::Asyncable, + public muse::Injectable { Q_OBJECT - - INJECT(IPaletteProvider, paletteProvider) - INJECT(muse::actions::IActionsDispatcher, dispatcher) + Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(mu::palette::PaletteProvider * paletteProvider READ paletteProvider_property CONSTANT) + muse::Inject paletteProvider = { this }; + muse::Inject dispatcher = { this }; + public: explicit PaletteRootModel(QObject* parent = nullptr); ~PaletteRootModel() override; @@ -50,6 +54,10 @@ class PaletteRootModel : public QObject, public muse::actions::Actionable, publi signals: void paletteSearchRequested(); void applyCurrentPaletteElementRequested(); + +private: + void classBegin() override; + void componentComplete() override {} }; } diff --git a/src/palette/view/widgets/customizekitdialog.cpp b/src/palette/view/widgets/customizekitdialog.cpp index 9f30345d997c8..2ee9c49c73585 100644 --- a/src/palette/view/widgets/customizekitdialog.cpp +++ b/src/palette/view/widgets/customizekitdialog.cpp @@ -40,6 +40,7 @@ #include "engraving/dom/score.h" #include "engraving/dom/utils.h" +#include "modularity/ioc.h" #include "notationscene/utilities/percussionutilities.h" #include "draw/types/geometry.h" @@ -141,7 +142,7 @@ struct SymbolIcon { }; CustomizeKitDialog::CustomizeKitDialog(QWidget* parent) - : QDialog(parent) + : QDialog(parent), muse::Injectable(muse::iocCtxForQWidget(this)) { setObjectName(QStringLiteral("CustomizeKitDialog")); @@ -691,7 +692,7 @@ void CustomizeKitDialog::defineShortcut() } const int originPitch = item->data(Column::PITCH, Qt::UserRole).toInt(); - if (!PercussionUtilities::editPercussionShortcut(m_editedDrumset, originPitch)) { + if (!PercussionUtilities(iocContext()).editPercussionShortcut(m_editedDrumset, originPitch)) { return; } diff --git a/src/palette/view/widgets/customizekitdialog.h b/src/palette/view/widgets/customizekitdialog.h index d83d22fe22711..921bcd924dc84 100644 --- a/src/palette/view/widgets/customizekitdialog.h +++ b/src/palette/view/widgets/customizekitdialog.h @@ -39,17 +39,17 @@ namespace mu::palette { // CustomizeKitDialog //--------------------------------------------------------- -class CustomizeKitDialog : public QDialog, private Ui::CustomizeKitDialog +class CustomizeKitDialog : public QDialog, private Ui::CustomizeKitDialog, public muse::Injectable { Q_OBJECT public: - INJECT(muse::IInteractive, interactive) - INJECT(context::IGlobalContext, globalContext) - INJECT(notation::INotationConfiguration, notationConfiguration) - INJECT(engraving::rendering::ISingleRenderer, engravingRenderer) - INJECT_STATIC(engraving::IEngravingFontsProvider, engravingFonts) - INJECT_STATIC(muse::ui::IUiConfiguration, uiConfiguration) + muse::Inject interactive = { this }; + muse::Inject globalContext = { this }; + muse::Inject notationConfiguration = { this }; + muse::Inject engravingRenderer = { this }; + inline static muse::GlobalInject engravingFonts; + inline static muse::GlobalInject uiConfiguration; public: CustomizeKitDialog(QWidget* parent = nullptr); diff --git a/src/palette/view/widgets/drumsetpalette.cpp b/src/palette/view/widgets/drumsetpalette.cpp index 214aad29cf2ab..2abd13a3b9934 100644 --- a/src/palette/view/widgets/drumsetpalette.cpp +++ b/src/palette/view/widgets/drumsetpalette.cpp @@ -24,6 +24,7 @@ #include "engraving/dom/drumset.h" +#include "modularity/ioc.h" #include "notationscene/utilities/percussionutilities.h" #include "translation.h" @@ -36,7 +37,7 @@ using namespace mu::engraving; using namespace mu::palette; DrumsetPalette::DrumsetPalette(QWidget* parent) - : PaletteScrollArea(nullptr, parent) + : PaletteScrollArea(nullptr, parent), muse::Injectable(muse::iocCtxForQWidget(this)) { setObjectName("DrumsetPalette"); setFocusPolicy(Qt::NoFocus); @@ -91,7 +92,7 @@ void DrumsetPalette::updateDrumset() continue; } - std::shared_ptr chord = notation::PercussionUtilities::getDrumNoteForPreview(m_drumset, pitch); + std::shared_ptr chord = notation::PercussionUtilities(iocContext()).getDrumNoteForPreview(m_drumset, pitch); m_drumPalette->appendElement(chord, m_drumset->translatedName(pitch), 1.0, QPointF(0, 0), m_drumset->shortcut(pitch)); } diff --git a/src/palette/view/widgets/drumsetpalette.h b/src/palette/view/widgets/drumsetpalette.h index 14a9955e15430..69cffd4e1df4f 100644 --- a/src/palette/view/widgets/drumsetpalette.h +++ b/src/palette/view/widgets/drumsetpalette.h @@ -36,13 +36,13 @@ class Drumset; } namespace mu::palette { -class DrumsetPalette : public PaletteScrollArea +class DrumsetPalette : public PaletteScrollArea, public muse::Injectable { Q_OBJECT - INJECT(muse::actions::IActionsDispatcher, dispatcher) - INJECT(playback::IPlaybackController, playback) - INJECT(engraving::rendering::ISingleRenderer, engravingRenderer) + muse::Inject dispatcher = { this }; + muse::Inject playback = { this }; + muse::Inject engravingRenderer = { this }; public: explicit DrumsetPalette(QWidget* parent = nullptr); diff --git a/src/palette/view/widgets/keyedit.cpp b/src/palette/view/widgets/keyedit.cpp index a0e4b50a04319..fb17290c57f6a 100644 --- a/src/palette/view/widgets/keyedit.cpp +++ b/src/palette/view/widgets/keyedit.cpp @@ -28,6 +28,7 @@ #include "keyedit.h" +#include "modularity/ioc.h" #include "translation.h" #include "engraving/compat/dummyelement.h" @@ -305,7 +306,7 @@ void KeyCanvas::snap(Accidental* a) //--------------------------------------------------------- KeyEditor::KeyEditor(QWidget* parent) - : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window)) + : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window)), muse::Injectable(muse::iocCtxForQWidget(this)) { setupUi(this); setWindowTitle(muse::qtrc("palette", "Key signatures")); @@ -321,7 +322,7 @@ KeyEditor::KeyEditor(QWidget* parent) keySigframe->setLayout(layout); m_keySigPaletteWidget = new PaletteWidget(this); - m_keySigPaletteWidget->setPalette(PaletteCreator::newKeySigPalette()); + m_keySigPaletteWidget->setPalette(PaletteCreator(iocContext()).newKeySigPalette()); m_keySigPaletteWidget->setReadOnly(false); m_keySigArea = new PaletteScrollArea(m_keySigPaletteWidget); @@ -339,7 +340,7 @@ KeyEditor::KeyEditor(QWidget* parent) accidentalsFrame->setLayout(layout); m_accidentalsPaletteWidget = new PaletteWidget(this); - m_accidentalsPaletteWidget->setPalette(PaletteCreator::newAccidentalsPalette()); + m_accidentalsPaletteWidget->setPalette(PaletteCreator(iocContext()).newAccidentalsPalette()); qreal adj = m_accidentalsPaletteWidget->mag(); m_accidentalsPaletteWidget->setGridSize(m_accidentalsPaletteWidget->gridWidth() / adj, m_accidentalsPaletteWidget->gridHeight() / adj); m_accidentalsPaletteWidget->setMag(1.0); diff --git a/src/palette/view/widgets/keyedit.h b/src/palette/view/widgets/keyedit.h index 9f945ed1c036c..ef967da0218a6 100644 --- a/src/palette/view/widgets/keyedit.h +++ b/src/palette/view/widgets/keyedit.h @@ -33,14 +33,14 @@ namespace mu::palette { class PaletteWidget; class PaletteScrollArea; -class KeyEditor : public QWidget, Ui::KeyEdit +class KeyEditor : public QWidget, Ui::KeyEdit, public muse::Injectable { Q_OBJECT Q_PROPERTY(bool showKeyPalette READ showKeyPalette WRITE setShowKeyPalette) - INJECT(IPaletteConfiguration, configuration) - INJECT(IPaletteProvider, paletteProvider) + muse::Inject configuration = { this }; + muse::Inject paletteProvider = { this }; public: KeyEditor(QWidget* parent = 0); diff --git a/src/palette/view/widgets/masterpalette.cpp b/src/palette/view/widgets/masterpalette.cpp index f4aae751ef8dd..f06fc5f6140f3 100644 --- a/src/palette/view/widgets/masterpalette.cpp +++ b/src/palette/view/widgets/masterpalette.cpp @@ -91,7 +91,9 @@ MasterPalette::MasterPalette(QWidget* parent) treeWidget->clear(); - addPalette(PaletteCreator::newClefsPalette()); + PaletteCreator creator(iocContext()); + + addPalette(creator.newClefsPalette()); m_keyEditor = new KeyEditor; m_keyItem = new QTreeWidgetItem(); @@ -105,27 +107,27 @@ MasterPalette::MasterPalette(QWidget* parent) stack->addWidget(m_timeDialog); treeWidget->addTopLevelItem(m_timeItem); - addPalette(PaletteCreator::newBracketsPalette()); - addPalette(PaletteCreator::newAccidentalsPalette()); - addPalette(PaletteCreator::newArticulationsPalette()); - addPalette(PaletteCreator::newOrnamentsPalette()); - addPalette(PaletteCreator::newBreathPalette()); - addPalette(PaletteCreator::newGraceNotePalette()); - addPalette(PaletteCreator::newNoteHeadsPalette()); - addPalette(PaletteCreator::newLinesPalette()); - addPalette(PaletteCreator::newBarLinePalette()); - addPalette(PaletteCreator::newArpeggioPalette()); - addPalette(PaletteCreator::newTremoloPalette()); - addPalette(PaletteCreator::newTextPalette()); - addPalette(PaletteCreator::newTempoPalette()); - addPalette(PaletteCreator::newDynamicsPalette()); - addPalette(PaletteCreator::newFingeringPalette()); - addPalette(PaletteCreator::newRepeatsPalette()); - addPalette(PaletteCreator::newFretboardDiagramPalette()); - addPalette(PaletteCreator::newAccordionPalette()); - addPalette(PaletteCreator::newBagpipeEmbellishmentPalette()); - addPalette(PaletteCreator::newLayoutPalette()); - addPalette(PaletteCreator::newBeamPalette()); + addPalette(creator.newBracketsPalette()); + addPalette(creator.newAccidentalsPalette()); + addPalette(creator.newArticulationsPalette()); + addPalette(creator.newOrnamentsPalette()); + addPalette(creator.newBreathPalette()); + addPalette(creator.newGraceNotePalette()); + addPalette(creator.newNoteHeadsPalette()); + addPalette(creator.newLinesPalette()); + addPalette(creator.newBarLinePalette()); + addPalette(creator.newArpeggioPalette()); + addPalette(creator.newTremoloPalette()); + addPalette(creator.newTextPalette()); + addPalette(creator.newTempoPalette()); + addPalette(creator.newDynamicsPalette()); + addPalette(creator.newFingeringPalette()); + addPalette(creator.newRepeatsPalette()); + addPalette(creator.newFretboardDiagramPalette()); + addPalette(creator.newAccordionPalette()); + addPalette(creator.newBagpipeEmbellishmentPalette()); + addPalette(creator.newLayoutPalette()); + addPalette(creator.newBeamPalette()); m_symbolItem = new QTreeWidgetItem(); m_idxAllSymbols = stack->count(); diff --git a/src/palette/view/widgets/notegroupsexampleview.h b/src/palette/view/widgets/notegroupsexampleview.h index 6b3cf248dc00e..e81dd659e5729 100644 --- a/src/palette/view/widgets/notegroupsexampleview.h +++ b/src/palette/view/widgets/notegroupsexampleview.h @@ -38,7 +38,7 @@ class NoteGroupsExampleView : public notation::ExampleView { Q_OBJECT - INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender) + muse::Inject engravingRender = { this }; public: NoteGroupsExampleView(QWidget* parent = 0); diff --git a/src/palette/view/widgets/palettewidget.cpp b/src/palette/view/widgets/palettewidget.cpp index 6e980a98353de..13c4e8e1afd3a 100644 --- a/src/palette/view/widgets/palettewidget.cpp +++ b/src/palette/view/widgets/palettewidget.cpp @@ -37,6 +37,7 @@ #include #include +#include "modularity/ioc.h" #include "translation.h" #include "types/bytearray.h" @@ -74,9 +75,9 @@ using namespace muse::draw; using namespace muse::actions; PaletteWidget::PaletteWidget(QWidget* parent) - : QWidget(parent) + : QWidget(parent), muse::Injectable(muse::iocCtxForQWidget(this)) { - m_palette = std::make_shared(); + m_palette = std::make_shared(iocContext()); //! NOTE: need for accessibility m_palette->setParent(this); @@ -611,7 +612,7 @@ QPixmap PaletteWidget::pixmapForCellAt(int paletteIdx) const params.painter = &painter; params.color = configuration()->elementsColor(); - notation::EngravingItemPreviewPainter::paintItem(element.get(), params); + notation::EngravingItemPreviewPainter::paintItem(engravingRender(), element.get(), params); element->setPos(pos); return pm; @@ -1091,7 +1092,7 @@ void PaletteWidget::paintEvent(QPaintEvent* /*event*/) params.useElementColors = m_paintOptions.useElementColors; params.colorsInversionEnabled = m_paintOptions.colorsInversionEnabled; - notation::EngravingItemPreviewPainter::paintItem(el.get(), params); + notation::EngravingItemPreviewPainter::paintItem(engravingRender(), el.get(), params); painter.restore(); } diff --git a/src/palette/view/widgets/palettewidget.h b/src/palette/view/widgets/palettewidget.h index ed1d6ba5e2ec4..ab7364d679d78 100644 --- a/src/palette/view/widgets/palettewidget.h +++ b/src/palette/view/widgets/palettewidget.h @@ -67,17 +67,17 @@ class AccessiblePaletteWidget : public QObject, public QAccessibleWidget PaletteWidget* m_palette = nullptr; }; -class PaletteWidget : public QWidget, public muse::async::Asyncable +class PaletteWidget : public QWidget, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT - INJECT_STATIC(IPaletteConfiguration, configuration) - INJECT_STATIC(muse::ui::IUiActionsRegister, actionsRegister) - INJECT_STATIC(context::IGlobalContext, globalContext) - INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender) - INJECT(muse::IInteractive, interactive) - INJECT(muse::ui::IUiConfiguration, uiConfiguration) - muse::Inject mainWindow; + muse::Inject configuration = { this }; + muse::Inject actionsRegister = { this }; + muse::Inject globalContext = { this }; + muse::Inject engravingRender = { this }; + muse::Inject interactive = { this }; + muse::Inject uiConfiguration = { this }; + muse::Inject mainWindow = { this }; public: PaletteWidget(QWidget* parent = nullptr); diff --git a/src/palette/view/widgets/timedialog.cpp b/src/palette/view/widgets/timedialog.cpp index 58b60fa703ed5..09b8f7f94d1a9 100644 --- a/src/palette/view/widgets/timedialog.cpp +++ b/src/palette/view/widgets/timedialog.cpp @@ -38,7 +38,7 @@ using namespace mu::palette; using namespace mu::engraving; TimeDialog::TimeDialog(QWidget* parent) - : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window)) + : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window)), muse::Injectable(muse::iocCtxForQWidget(this)) { setupUi(this); setWindowTitle(muse::qtrc("palette", "Time signatures")); @@ -50,7 +50,7 @@ TimeDialog::TimeDialog(QWidget* parent) frame->setLayout(l); sp = new PaletteWidget(this); - sp->setPalette(PaletteCreator::newTimePalette()); + sp->setPalette(PaletteCreator(iocContext()).newTimePalette()); sp->setReadOnly(false); sp->setSelectable(true); diff --git a/src/palette/view/widgets/timedialog.h b/src/palette/view/widgets/timedialog.h index 5b7bc3cc3ef15..1076d05293105 100644 --- a/src/palette/view/widgets/timedialog.h +++ b/src/palette/view/widgets/timedialog.h @@ -34,15 +34,15 @@ namespace mu::palette { class PaletteWidget; class PaletteScrollArea; -class TimeDialog : public QWidget, Ui::TimeDialogBase +class TimeDialog : public QWidget, Ui::TimeDialogBase, public muse::Injectable { Q_OBJECT Q_PROPERTY(bool showTimePalette READ showTimePalette WRITE setShowTimePalette) - INJECT(IPaletteConfiguration, configuration) - INJECT(IPaletteProvider, paletteProvider) - INJECT(engraving::rendering::ISingleRenderer, engravingRender) + muse::Inject configuration = { this }; + muse::Inject paletteProvider = { this }; + muse::Inject engravingRender = { this }; public: TimeDialog(QWidget* parent = 0); diff --git a/src/playback/internal/drumsetloader.cpp b/src/playback/internal/drumsetloader.cpp index ac7baa46f07d3..4dc600b26f30e 100644 --- a/src/playback/internal/drumsetloader.cpp +++ b/src/playback/internal/drumsetloader.cpp @@ -75,7 +75,7 @@ void DrumsetLoader::loadDrumset(INotationPtr notation, const InstrumentTrackId& } Drumset drumset; - PercussionUtilities::readDrumset(drumMapping, drumset); + PercussionUtilities(iocContext()).readDrumset(drumMapping, drumset); replaceDrumset(notation, trackId, drumset); m_drumsetCache.emplace(instrumentId, std::move(drumset)); diff --git a/src/playback/internal/drumsetloader.h b/src/playback/internal/drumsetloader.h index a66e6c4af2096..8519bacbd8326 100644 --- a/src/playback/internal/drumsetloader.h +++ b/src/playback/internal/drumsetloader.h @@ -34,12 +34,18 @@ #include "musesampler/imusesamplerinfo.h" namespace mu::playback { -class DrumsetLoader : public muse::async::Asyncable +class DrumsetLoader : public muse::async::Asyncable, public muse::Injectable { - muse::Inject instrumentsRepository; - muse::Inject museSampler; + muse::Inject instrumentsRepository = { this }; + muse::Inject museSampler = { this }; public: + + DrumsetLoader(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + void loadDrumset(notation::INotationPtr notation, const mu::engraving::InstrumentTrackId& trackId, const muse::audio::AudioResourceMeta& resourceMeta); diff --git a/src/playback/internal/onlinesoundscontroller.cpp b/src/playback/internal/onlinesoundscontroller.cpp index 0bb102fa47bc1..4c8ec46608726 100644 --- a/src/playback/internal/onlinesoundscontroller.cpp +++ b/src/playback/internal/onlinesoundscontroller.cpp @@ -25,6 +25,7 @@ #include "audio/common/audioerrors.h" #include "log.h" +#include "modularity/ioc.h" #include "translation.h" using namespace muse; @@ -41,8 +42,8 @@ static Ret retFromProcessingStatus(const InputProcessingProgress::StatusInfo& st return ret; } -OnlineSoundsController::OnlineSoundsController() - : m_onlineSoundsProcessingRet(make_ok()) +OnlineSoundsController::OnlineSoundsController(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_onlineSoundsProcessingRet(make_ok()) { } diff --git a/src/playback/internal/onlinesoundscontroller.h b/src/playback/internal/onlinesoundscontroller.h index c778b73489333..23a8f7e11c6fd 100644 --- a/src/playback/internal/onlinesoundscontroller.h +++ b/src/playback/internal/onlinesoundscontroller.h @@ -33,15 +33,15 @@ #include "audio/main/iplayback.h" namespace mu::playback { -class OnlineSoundsController : public muse::actions::Actionable, public muse::async::Asyncable +class OnlineSoundsController : public muse::actions::Actionable, public muse::async::Asyncable, public muse::Injectable { - muse::Inject configuration; - muse::Inject dispatcher; - muse::Inject interactive; - muse::Inject playback; + muse::Inject configuration = { this }; + muse::Inject dispatcher = { this }; + muse::Inject interactive = { this }; + muse::Inject playback = { this }; public: - OnlineSoundsController(); + OnlineSoundsController(const muse::modularity::ContextPtr& iocCtx); void regActions(); diff --git a/src/playback/internal/playbackcontroller.cpp b/src/playback/internal/playbackcontroller.cpp index d9c16ceea9150..8e4fa4123e3d5 100644 --- a/src/playback/internal/playbackcontroller.cpp +++ b/src/playback/internal/playbackcontroller.cpp @@ -23,6 +23,7 @@ #include "async/notifylist.h" +#include "modularity/ioc.h" #include "onlinesoundscontroller.h" #include "playbacktypes.h" @@ -94,8 +95,8 @@ static std::string resolveAuxTrackTitle(aux_channel_idx_t index, const AudioOutp return muse::mtrc("playback", "Aux %1").arg(index + 1).toStdString(); } -PlaybackController::PlaybackController() - : m_onlineSoundsController(std::make_unique()) +PlaybackController::PlaybackController(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_drumsetLoader(iocCtx), m_onlineSoundsController(std::make_unique(iocCtx)) { } diff --git a/src/playback/internal/playbackcontroller.h b/src/playback/internal/playbackcontroller.h index acb49a21b86d6..a89c40f568cbb 100644 --- a/src/playback/internal/playbackcontroller.h +++ b/src/playback/internal/playbackcontroller.h @@ -46,20 +46,21 @@ namespace mu::playback { class OnlineSoundsController; -class PlaybackController : public IPlaybackController, public muse::actions::Actionable, public muse::async::Asyncable +class PlaybackController : public IPlaybackController, public muse::actions::Actionable, public muse::async::Asyncable, + public muse::Injectable { - INJECT_STATIC(muse::actions::IActionsDispatcher, dispatcher) - INJECT_STATIC(context::IGlobalContext, globalContext) - INJECT_STATIC(IPlaybackConfiguration, configuration) - INJECT_STATIC(notation::INotationConfiguration, notationConfiguration) - INJECT_STATIC(muse::audio::IPlayback, playback) - INJECT_STATIC(muse::audio::IAudioConfiguration, audioConfiguration) - INJECT_STATIC(ISoundProfilesRepository, profilesRepo) - INJECT_STATIC(muse::IInteractive, interactive) - INJECT_STATIC(muse::tours::IToursService, tours) + muse::Inject dispatcher = { this }; + muse::Inject globalContext = { this }; + muse::Inject configuration = { this }; + muse::Inject notationConfiguration = { this }; + muse::Inject playback = { this }; + muse::Inject audioConfiguration = { this }; + muse::Inject profilesRepo = { this }; + muse::Inject interactive = { this }; + muse::Inject tours = { this }; public: - PlaybackController(); + PlaybackController(const muse::modularity::ContextPtr& iocCtx); ~PlaybackController(); void init(); diff --git a/src/playback/internal/soundprofilesrepository.h b/src/playback/internal/soundprofilesrepository.h index ed615a598c852..a493f15532442 100644 --- a/src/playback/internal/soundprofilesrepository.h +++ b/src/playback/internal/soundprofilesrepository.h @@ -33,12 +33,15 @@ #include "iplaybackconfiguration.h" namespace mu::playback { -class SoundProfilesRepository : public ISoundProfilesRepository, public muse::async::Asyncable +class SoundProfilesRepository : public ISoundProfilesRepository, public muse::async::Asyncable, public muse::Injectable { - INJECT_STATIC(muse::audio::IPlayback, playback) - INJECT_STATIC(IPlaybackConfiguration, config) + muse::Inject playback = { this }; + muse::Inject config = { this }; public: - SoundProfilesRepository() = default; + SoundProfilesRepository(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } void init(); diff --git a/src/playback/playbackmodule.cpp b/src/playback/playbackmodule.cpp index eb78915a46f5e..6a986b6265db3 100644 --- a/src/playback/playbackmodule.cpp +++ b/src/playback/playbackmodule.cpp @@ -62,9 +62,9 @@ std::string PlaybackModule::moduleName() const void PlaybackModule::registerExports() { m_configuration = std::make_shared(); - m_playbackController = std::make_shared(); + m_playbackController = std::make_shared(iocContext()); m_playbackUiActions = std::make_shared(m_playbackController); - m_soundProfileRepo = std::make_shared(); + m_soundProfileRepo = std::make_shared(iocContext()); ioc()->registerExport(moduleName(), m_playbackController); ioc()->registerExport(moduleName(), m_configuration); diff --git a/src/playback/view/internal/abstractaudioresourceitem.cpp b/src/playback/view/internal/abstractaudioresourceitem.cpp index 958e7e4da067c..13f78b6d74472 100644 --- a/src/playback/view/internal/abstractaudioresourceitem.cpp +++ b/src/playback/view/internal/abstractaudioresourceitem.cpp @@ -14,7 +14,7 @@ using namespace mu::playback; static constexpr int EXPLICIT_DELAY_MSECS = 1000; AbstractAudioResourceItem::AbstractAudioResourceItem(QObject* parent) - : QObject(parent) + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)) { } diff --git a/src/playback/view/internal/abstractaudioresourceitem.h b/src/playback/view/internal/abstractaudioresourceitem.h index 7b7dbc80c8d5b..f6777997a0f0a 100644 --- a/src/playback/view/internal/abstractaudioresourceitem.h +++ b/src/playback/view/internal/abstractaudioresourceitem.h @@ -25,12 +25,14 @@ #include +#include "modularity/ioc.h" + #include "async/asyncable.h" #include "actions/actiontypes.h" #include "audio/common/audiotypes.h" namespace mu::playback { -class AbstractAudioResourceItem : public QObject, public muse::async::Asyncable +class AbstractAudioResourceItem : public QObject, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT @@ -40,7 +42,7 @@ class AbstractAudioResourceItem : public QObject, public muse::async::Asyncable Q_PROPERTY(bool hasNativeEditorSupport READ hasNativeEditorSupport NOTIFY hasNativeEditorSupportChanged) public: - explicit AbstractAudioResourceItem(QObject* parent); + explicit AbstractAudioResourceItem(QObject* parent = nullptr); ~AbstractAudioResourceItem() override; Q_INVOKABLE void requestToLaunchNativeEditorView(); diff --git a/src/playback/view/internal/inputresourceitem.h b/src/playback/view/internal/inputresourceitem.h index 80090bd3700d9..19f7c78abf3bd 100644 --- a/src/playback/view/internal/inputresourceitem.h +++ b/src/playback/view/internal/inputresourceitem.h @@ -45,12 +45,12 @@ class InputResourceItem : public AbstractAudioResourceItem { Q_OBJECT - INJECT(muse::IGlobalConfiguration, globalConfiguration) - INJECT(muse::IInteractive, interactive) - INJECT(muse::audio::IPlayback, playback) + muse::Inject globalConfiguration = { this }; + muse::Inject interactive = { this }; + muse::Inject playback = { this }; public: - explicit InputResourceItem(QObject* parent); + explicit InputResourceItem(QObject* parent = nullptr); void requestAvailableResources() override; void handleMenuItem(const QString& menuItemId) override; diff --git a/src/playback/view/internal/mixerchannelitem.cpp b/src/playback/view/internal/mixerchannelitem.cpp index cc601b69a9acd..a4096d090360d 100644 --- a/src/playback/view/internal/mixerchannelitem.cpp +++ b/src/playback/view/internal/mixerchannelitem.cpp @@ -45,7 +45,7 @@ static const std::string RESOURCE_ID_KEY("resourceId"); static const std::string CHAIN_ORDER_KEY("chainOrder"); MixerChannelItem::MixerChannelItem(QObject* parent, Type type, bool outputOnly, audio::TrackId trackId) - : QObject(parent), + : QObject(parent), muse::Injectable(muse::iocCtxForQmlObject(this)), m_type(type), m_trackId(trackId), m_outputOnly(outputOnly), diff --git a/src/playback/view/internal/mixerchannelitem.h b/src/playback/view/internal/mixerchannelitem.h index 4adcada6ffae1..3cf429278f74d 100644 --- a/src/playback/view/internal/mixerchannelitem.h +++ b/src/playback/view/internal/mixerchannelitem.h @@ -40,7 +40,7 @@ #include "auxsenditem.h" namespace mu::playback { -class MixerChannelItem : public QObject, public muse::async::Asyncable +class MixerChannelItem : public QObject, public muse::async::Asyncable, public muse::Injectable { Q_OBJECT @@ -64,10 +64,10 @@ class MixerChannelItem : public QObject, public muse::async::Asyncable Q_PROPERTY(muse::ui::NavigationPanel * panel READ panel NOTIFY panelChanged) - muse::Inject interactive; - muse::Inject dispatcher; - muse::Inject context; - muse::Inject configuration; + muse::Inject interactive = { this }; + muse::Inject dispatcher = { this }; + muse::Inject context = { this }; + muse::Inject configuration = { this }; public: enum class Type { @@ -80,7 +80,8 @@ class MixerChannelItem : public QObject, public muse::async::Asyncable }; Q_ENUM(Type) - MixerChannelItem() = default; + MixerChannelItem() + : muse::Injectable(muse::iocCtxForQmlObject(this)) {} MixerChannelItem(QObject* parent, Type type, bool outputOnly = false, muse::audio::TrackId trackId = -1); ~MixerChannelItem() override; diff --git a/src/playback/view/mixerpanelcontextmenumodel.h b/src/playback/view/mixerpanelcontextmenumodel.h index ed78fe184366d..9d2911e633826 100644 --- a/src/playback/view/mixerpanelcontextmenumodel.h +++ b/src/playback/view/mixerpanelcontextmenumodel.h @@ -35,9 +35,6 @@ class MixerPanelContextMenuModel : public muse::uicomponents::AbstractMenuModel, { Q_OBJECT - INJECT(muse::actions::IActionsDispatcher, dispatcher) - INJECT(playback::IPlaybackConfiguration, configuration) - Q_PROPERTY(bool labelsSectionVisible READ labelsSectionVisible NOTIFY labelsSectionVisibleChanged) Q_PROPERTY(bool soundSectionVisible READ soundSectionVisible NOTIFY soundSectionVisibleChanged) Q_PROPERTY(bool audioFxSectionVisible READ audioFxSectionVisible NOTIFY audioFxSectionVisibleChanged) @@ -48,6 +45,9 @@ class MixerPanelContextMenuModel : public muse::uicomponents::AbstractMenuModel, Q_PROPERTY(bool muteAndSoloSectionVisible READ muteAndSoloSectionVisible NOTIFY muteAndSoloSectionVisibleChanged) Q_PROPERTY(bool titleSectionVisible READ titleSectionVisible NOTIFY titleSectionVisibleChanged) + muse::Inject dispatcher = { this }; + muse::Inject configuration = { this }; + public: explicit MixerPanelContextMenuModel(QObject* parent = nullptr); diff --git a/src/playback/view/playbacktoolbarmodel.h b/src/playback/view/playbacktoolbarmodel.h index 3b3037ffc15fd..e551c12c0e1a4 100644 --- a/src/playback/view/playbacktoolbarmodel.h +++ b/src/playback/view/playbacktoolbarmodel.h @@ -49,8 +49,8 @@ class PlaybackToolBarModel : public muse::uicomponents::AbstractMenuModel Q_PROPERTY(QVariant tempo READ tempo NOTIFY tempoChanged) Q_PROPERTY(qreal tempoMultiplier READ tempoMultiplier WRITE setTempoMultiplier NOTIFY tempoChanged) - muse::Inject playbackController; - muse::Inject globalContext; + muse::Inject playbackController = { this }; + muse::Inject globalContext = { this }; muse::Inject notationConfiguration = { this }; public: diff --git a/src/project/internal/exportprojectscenario.h b/src/project/internal/exportprojectscenario.h index 2f5520c07aef2..784187b28aec8 100644 --- a/src/project/internal/exportprojectscenario.h +++ b/src/project/internal/exportprojectscenario.h @@ -34,16 +34,22 @@ #include "async/asyncable.h" namespace mu::project { -class ExportProjectScenario : public IExportProjectScenario, public muse::async::Asyncable +class ExportProjectScenario : public IExportProjectScenario, public muse::async::Asyncable, public muse::Injectable { - INJECT(IProjectConfiguration, configuration) - INJECT(muse::IInteractive, interactive) - INJECT(INotationWritersRegister, writers) - INJECT(iex::imagesexport::IImagesExportConfiguration, imagesExportConfiguration) - INJECT(context::IGlobalContext, context) - INJECT(muse::io::IFileSystem, fileSystem) + muse::Inject configuration = { this }; + muse::Inject interactive = { this }; + muse::Inject writers = { this }; + muse::Inject imagesExportConfiguration = { this }; + muse::Inject context = { this }; + muse::Inject fileSystem = { this }; public: + + ExportProjectScenario(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + std::vector supportedUnitTypes(const ExportType& exportType) const override; muse::RetVal askExportPath(const notation::INotationPtrList& notations, const ExportType& exportType, diff --git a/src/project/internal/mdlmigrator.h b/src/project/internal/mdlmigrator.h index 01d66d0558874..30855f295078b 100644 --- a/src/project/internal/mdlmigrator.h +++ b/src/project/internal/mdlmigrator.h @@ -36,13 +36,14 @@ class Score; namespace mu::project { using RepitchFunc = std::function; -class MdlMigrator +class MdlMigrator : public muse::Injectable { - INJECT(muse::IGlobalConfiguration, globalConfiguration) + muse::GlobalInject globalConfiguration; public: MdlMigrator(mu::engraving::MasterScore* score) : m_score(score) {} + void remapPercussion(); private: diff --git a/src/project/internal/mscmetareader.h b/src/project/internal/mscmetareader.h index efd2d25c14df2..e50bd4cc04e76 100644 --- a/src/project/internal/mscmetareader.h +++ b/src/project/internal/mscmetareader.h @@ -34,7 +34,7 @@ class XmlStreamReader; namespace mu::project { class MscMetaReader : public IMscMetaReader { - INJECT(muse::io::IFileSystem, fileSystem) + muse::GlobalInject fileSystem; public: muse::RetVal readMeta(const muse::io::path_t& filePath) const override; diff --git a/src/project/internal/notationproject.cpp b/src/project/internal/notationproject.cpp index 15d01f2591c48..9d5ba8b9f08d3 100644 --- a/src/project/internal/notationproject.cpp +++ b/src/project/internal/notationproject.cpp @@ -97,7 +97,7 @@ void NotationProject::setupProject() m_engravingProject = EngravingProject::create(iocContext()); m_engravingProject->setFileInfoProvider(std::make_shared(this)); m_masterNotation = std::shared_ptr(new MasterNotation(this, iocContext())); - m_projectAudioSettings = std::shared_ptr(new ProjectAudioSettings()); + m_projectAudioSettings = std::shared_ptr(new ProjectAudioSettings(iocContext())); } Ret NotationProject::load(const muse::io::path_t& path, const OpenParams& openParams, const std::string& format_) diff --git a/src/project/internal/opensaveprojectscenario.h b/src/project/internal/opensaveprojectscenario.h index a577eff2dc99b..df203452fc1d9 100644 --- a/src/project/internal/opensaveprojectscenario.h +++ b/src/project/internal/opensaveprojectscenario.h @@ -33,16 +33,19 @@ #include "cloud/audiocom/iaudiocomservice.h" namespace mu::project { -class OpenSaveProjectScenario : public IOpenSaveProjectScenario +class OpenSaveProjectScenario : public IOpenSaveProjectScenario, public muse::Injectable { - INJECT(IProjectConfiguration, configuration) - INJECT(IProjectFilesController, projectFilesController) - INJECT(muse::IInteractive, interactive) - INJECT(muse::cloud::IMuseScoreComService, museScoreComService) - INJECT(muse::cloud::IAudioComService, audioComService) + muse::Inject configuration = { this }; + muse::Inject projectFilesController = { this }; + muse::Inject interactive = { this }; + muse::Inject museScoreComService = { this }; + muse::Inject audioComService = { this }; public: - OpenSaveProjectScenario() = default; + OpenSaveProjectScenario(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } muse::RetVal askSaveLocation(INotationProjectPtr project, SaveMode mode, SaveLocationType preselectedType = SaveLocationType::Undefined) const override; diff --git a/src/project/internal/projectaudiosettings.h b/src/project/internal/projectaudiosettings.h index 1e9816e0624d7..fda76249ebdc0 100644 --- a/src/project/internal/projectaudiosettings.h +++ b/src/project/internal/projectaudiosettings.h @@ -34,9 +34,10 @@ #include "../iprojectaudiosettings.h" namespace mu::project { -class ProjectAudioSettings : public IProjectAudioSettings +class ProjectAudioSettings : public IProjectAudioSettings, public muse::Injectable { - INJECT_STATIC(playback::IPlaybackConfiguration, playbackConfig) + muse::Inject playbackConfig = { this }; + public: const muse::audio::AudioOutputParams& masterAudioOutputParams() const override; void setMasterAudioOutputParams(const muse::audio::AudioOutputParams& params) override; @@ -73,7 +74,8 @@ class ProjectAudioSettings : public IProjectAudioSettings private: friend class NotationProject; - ProjectAudioSettings() = default; + ProjectAudioSettings(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) {} muse::audio::AudioInputParams inputParamsFromJson(const QJsonObject& object) const; muse::audio::AudioOutputParams outputParamsFromJson(const QJsonObject& object) const; diff --git a/src/project/internal/projectautosaver.h b/src/project/internal/projectautosaver.h index 5a1c6e2005fe5..ca09f979d3450 100644 --- a/src/project/internal/projectautosaver.h +++ b/src/project/internal/projectautosaver.h @@ -34,14 +34,16 @@ #include "../iprojectautosaver.h" namespace mu::project { -class ProjectAutoSaver : public IProjectAutoSaver, public muse::async::Asyncable +class ProjectAutoSaver : public IProjectAutoSaver, public muse::async::Asyncable, public muse::Injectable { - INJECT(context::IGlobalContext, globalContext) - INJECT(muse::io::IFileSystem, fileSystem) - INJECT(IProjectConfiguration, configuration) + muse::Inject globalContext = { this }; + muse::Inject fileSystem = { this }; + muse::Inject configuration = { this }; public: - ProjectAutoSaver() = default; + ProjectAutoSaver(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + {} void init(); diff --git a/src/project/internal/projectconfiguration.cpp b/src/project/internal/projectconfiguration.cpp index f70dd8d8710cc..36cd3d3eb2c67 100644 --- a/src/project/internal/projectconfiguration.cpp +++ b/src/project/internal/projectconfiguration.cpp @@ -68,6 +68,11 @@ static const Settings::Key CREATE_BACKUP_BEFORE_SAVING(module_name, "project/cre static const std::string DEFAULT_FILE_SUFFIX(".mscz"); static const std::string DEFAULT_FILE_FILTER("*.mscz"); +ProjectConfiguration::ProjectConfiguration(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) +{ +} + void ProjectConfiguration::init() { settings()->setDefaultValue(USER_TEMPLATES_PATH, Val(globalConfiguration()->userDataPath() + "/Templates")); diff --git a/src/project/internal/projectconfiguration.h b/src/project/internal/projectconfiguration.h index b2a28564c4158..2a39bfb64b99f 100644 --- a/src/project/internal/projectconfiguration.h +++ b/src/project/internal/projectconfiguration.h @@ -35,16 +35,18 @@ #include "../iprojectconfiguration.h" namespace mu::project { -class ProjectConfiguration : public IProjectConfiguration +class ProjectConfiguration : public IProjectConfiguration, public muse::Injectable { - INJECT(muse::IGlobalConfiguration, globalConfiguration) - INJECT(notation::INotationConfiguration, notationConfiguration) - INJECT(muse::cloud::ICloudConfiguration, cloudConfiguration) - INJECT(muse::accessibility::IAccessibilityConfiguration, accessibilityConfiguration) - INJECT(muse::io::IFileSystem, fileSystem) - INJECT(muse::languages::ILanguagesService, languagesService) + muse::Inject globalConfiguration = { this }; + muse::Inject notationConfiguration = { this }; + muse::Inject cloudConfiguration = { this }; + muse::Inject accessibilityConfiguration = { this }; + muse::GlobalInject fileSystem; + muse::Inject languagesService = { this }; public: + ProjectConfiguration(const muse::modularity::ContextPtr& iocCtx); + void init(); muse::io::path_t recentFilesJsonPath() const override; diff --git a/src/project/internal/projectfileinfoprovider.h b/src/project/internal/projectfileinfoprovider.h index 400ac3a30afcd..59aac71d11263 100644 --- a/src/project/internal/projectfileinfoprovider.h +++ b/src/project/internal/projectfileinfoprovider.h @@ -31,7 +31,8 @@ namespace mu::project { class NotationProject; class ProjectFileInfoProvider : public engraving::IFileInfoProvider { - INJECT(muse::io::IFileSystem, filesystem) + muse::GlobalInject filesystem; + public: explicit ProjectFileInfoProvider(NotationProject* project); diff --git a/src/project/internal/projectmigrator.h b/src/project/internal/projectmigrator.h index 50923153ac3b3..fd18b8c0ef177 100644 --- a/src/project/internal/projectmigrator.h +++ b/src/project/internal/projectmigrator.h @@ -29,12 +29,15 @@ #include "iprojectconfiguration.h" namespace mu::project { -class ProjectMigrator : public IProjectMigrator +class ProjectMigrator : public IProjectMigrator, public muse::Injectable { - INJECT(IProjectConfiguration, configuration) - INJECT(muse::IInteractive, interactive) + muse::Inject configuration = { this }; + muse::Inject interactive = { this }; public: - ProjectMigrator() = default; + ProjectMigrator(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } muse::Ret migrateEngravingProjectIfNeed(engraving::EngravingProjectPtr project) override; diff --git a/src/project/internal/projectuiactions.cpp b/src/project/internal/projectuiactions.cpp index ef125c8fe5ae4..915793df0ad0c 100644 --- a/src/project/internal/projectuiactions.cpp +++ b/src/project/internal/projectuiactions.cpp @@ -21,6 +21,7 @@ */ #include "projectuiactions.h" +#include "modularity/ioc.h" #include "types/translatablestring.h" #include "context/shortcutcontext.h" @@ -131,8 +132,8 @@ const UiActionList ProjectUiActions::m_actions = { ) }; -ProjectUiActions::ProjectUiActions(std::shared_ptr controller) - : m_controller(controller) +ProjectUiActions::ProjectUiActions(std::shared_ptr controller, const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx), m_controller(controller) { } diff --git a/src/project/internal/projectuiactions.h b/src/project/internal/projectuiactions.h index ccb177ba2c735..bfdcc2a28f20c 100644 --- a/src/project/internal/projectuiactions.h +++ b/src/project/internal/projectuiactions.h @@ -28,12 +28,12 @@ #include "context/iuicontextresolver.h" namespace mu::project { -class ProjectUiActions : public muse::ui::IUiActionsModule +class ProjectUiActions : public muse::ui::IUiActionsModule, public muse::Injectable { - INJECT(context::IUiContextResolver, uicontextResolver) + muse::Inject uicontextResolver = { this }; public: - ProjectUiActions(std::shared_ptr controller); + ProjectUiActions(std::shared_ptr controller, const muse::modularity::ContextPtr& iocCtx); const muse::ui::UiActionList& actionsList() const override; diff --git a/src/project/internal/templatesrepository.h b/src/project/internal/templatesrepository.h index 8c6f75270a9eb..66fd91c616594 100644 --- a/src/project/internal/templatesrepository.h +++ b/src/project/internal/templatesrepository.h @@ -31,14 +31,19 @@ #include "io/ifilesystem.h" namespace mu::project { -class TemplatesRepository : public ITemplatesRepository +class TemplatesRepository : public ITemplatesRepository, public muse::Injectable { public: - INJECT(IProjectConfiguration, configuration) - INJECT(IMscMetaReader, mscReader) - INJECT(muse::io::IFileSystem, fileSystem) + muse::Inject configuration = { this }; + muse::Inject mscReader = { this }; + muse::Inject fileSystem = { this }; public: + TemplatesRepository(const muse::modularity::ContextPtr& iocCtx) + : muse::Injectable(iocCtx) + { + } + muse::RetVal templates() const override; private: diff --git a/src/project/projectmodule.cpp b/src/project/projectmodule.cpp index 0cc1898b7b840..fe91298303caa 100644 --- a/src/project/projectmodule.cpp +++ b/src/project/projectmodule.cpp @@ -63,9 +63,9 @@ std::string ProjectModule::moduleName() const void ProjectModule::registerExports() { - m_configuration = std::make_shared(); + m_configuration = std::make_shared(iocContext()); m_actionsController = std::make_shared(iocContext()); - m_projectAutoSaver = std::make_shared(); + m_projectAutoSaver = std::make_shared(iocContext()); m_engravingPluginAPIHelper = std::make_shared(iocContext()); #ifdef Q_OS_MAC @@ -80,12 +80,12 @@ void ProjectModule::registerExports() ioc()->registerExport(moduleName(), new ProjectCreator()); ioc()->registerExport(moduleName(), m_actionsController); ioc()->registerExport(moduleName(), m_actionsController); - ioc()->registerExport(moduleName(), new OpenSaveProjectScenario()); - ioc()->registerExport(moduleName(), new ExportProjectScenario()); + ioc()->registerExport(moduleName(), new OpenSaveProjectScenario(iocContext())); + ioc()->registerExport(moduleName(), new ExportProjectScenario(iocContext())); ioc()->registerExport(moduleName(), m_recentFilesController); ioc()->registerExport(moduleName(), new MscMetaReader()); - ioc()->registerExport(moduleName(), new TemplatesRepository()); - ioc()->registerExport(moduleName(), new ProjectMigrator()); + ioc()->registerExport(moduleName(), new TemplatesRepository(iocContext())); + ioc()->registerExport(moduleName(), new ProjectMigrator(iocContext())); ioc()->registerExport(moduleName(), m_projectAutoSaver); ioc()->registerExport(moduleName(), m_engravingPluginAPIHelper); @@ -99,7 +99,7 @@ void ProjectModule::resolveImports() { auto ar = ioc()->resolve(moduleName()); if (ar) { - ar->reg(std::make_shared(m_actionsController)); + ar->reg(std::make_shared(m_actionsController, iocContext())); } auto ir = ioc()->resolve(moduleName()); diff --git a/src/project/tests/templatesrepositorytest.cpp b/src/project/tests/templatesrepositorytest.cpp index 2978cbfcf6b6e..3b0edf64d2bab 100644 --- a/src/project/tests/templatesrepositorytest.cpp +++ b/src/project/tests/templatesrepositorytest.cpp @@ -43,7 +43,7 @@ class Project_TemplatesRepositoryTest : public ::testing::Test protected: void SetUp() override { - m_repository = std::make_shared(); + m_repository = std::make_shared(nullptr); m_msczReader = std::make_shared >(); m_fileSystem = std::make_shared >(); m_configuration = std::make_shared >();