Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2024 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #ifndef NO_QT_SUPPORT
26 : #include <QObject>
27 : class QQmlContext;
28 : #endif
29 :
30 : #include "../thirdparty/kors_modularity/modularity/ioc.h" // IWYU pragma: export
31 :
32 : namespace muse::modularity {
33 : #ifdef IOC_CHECK_INTERFACE_TYPE
34 : using ModulesGlobalIoC = kors::modularity::ModulesGlobalIoC;
35 : using ModulesContextIoC = kors::modularity::ModulesContextIoC;
36 : #else
37 : using ModulesGlobalIoC = kors::modularity::ModulesIoCBase;
38 : using ModulesContextIoC = kors::modularity::ModulesIoCBase;
39 : #endif
40 : using kors::modularity::IoCID;
41 : using kors::modularity::Context;
42 : using kors::modularity::ContextPtr;
43 :
44 13455 : inline muse::modularity::ContextPtr globalCtx()
45 : {
46 13455 : return kors::modularity::globalCtx;
47 : }
48 :
49 34919 : inline ModulesGlobalIoC* globalIoc()
50 : {
51 34919 : return kors::modularity::globalIoc();
52 : }
53 :
54 36 : inline ModulesContextIoC* ioc(const ContextPtr& ctx)
55 : {
56 36 : return kors::modularity::ioc(ctx);
57 : }
58 :
59 12 : inline void removeIoC(const ContextPtr& ctx = nullptr)
60 : {
61 12 : kors::modularity::removeIoC(ctx);
62 12 : }
63 :
64 46 : inline void resetAll()
65 : {
66 46 : kors::modularity::resetAll();
67 46 : }
68 : }
69 :
70 : namespace muse {
71 : using kors::modularity::GlobalInject;
72 : using kors::modularity::GlobalThreadSafeInject;
73 : using kors::modularity::ContextInject;
74 : using kors::modularity::ContextThreadSafeInject;
75 : using kors::modularity::Contextable;
76 :
77 : //! NOTE Temporary for compatibility
78 : using kors::modularity::Inject;
79 : using kors::modularity::ThreadSafeInject;
80 : using kors::modularity::Injectable;
81 : //! ----
82 :
83 : #ifndef NO_QT_SUPPORT
84 : struct QmlIoCContext : public QObject
85 : {
86 : Q_OBJECT
87 : public:
88 3 : QmlIoCContext(QObject* p)
89 3 : : QObject(p) {}
90 :
91 : modularity::ContextPtr ctx;
92 : };
93 :
94 : Contextable::GetContext iocCtxForQmlObject(const QObject* o);
95 : modularity::ContextPtr iocCtxForQmlContext(const QQmlContext* c);
96 : muse::Contextable::GetContext iocCtxForQWidget(const QWidget* o);
97 : #endif
98 : }
|