|
8 | 8 | #include <QtQml/QQmlEngine> |
9 | 9 | #include <QtQml/QQmlComponent> |
10 | 10 |
|
| 11 | +#ifdef DOXYGEN_RUN |
| 12 | +namespace de::skycoder42::QtMvvm::Core { |
| 13 | + |
| 14 | +/*! @brief A QML singleton to access some QtMvvm::ServiceRegistry functionality |
| 15 | + * |
| 16 | + * @extends QtQml.QtObject |
| 17 | + * @since 1.1 |
| 18 | + * |
| 19 | + * @sa QtMvvm::ServiceRegistry |
| 20 | + */ |
| 21 | +class ServiceRegistry |
| 22 | +#else |
11 | 23 | namespace QtMvvm { |
12 | 24 |
|
13 | 25 | class QQmlServiceRegistry : public QObject |
| 26 | +#endif |
14 | 27 | { |
15 | 28 | Q_OBJECT |
16 | 29 |
|
17 | 30 | public: |
| 31 | + //! @copybrief QtMvvm::ServiceRegistry |
18 | 32 | enum DestructionScope { |
19 | | - DestroyOnAppQuit = ServiceRegistry::DestroyOnAppQuit, |
20 | | - DestroyOnAppDestroy = ServiceRegistry::DestroyOnAppDestroy, |
21 | | - DestroyOnRegistryDestroy = ServiceRegistry::DestroyOnRegistryDestroy, |
22 | | - |
23 | | - DestroyNever = ServiceRegistry::DestroyNever |
| 33 | + DestroyOnAppQuit = ServiceRegistry::DestroyOnAppQuit, //!< @copybrief QtMvvm::ServiceRegistry::DestroyOnAppQuit |
| 34 | + DestroyOnAppDestroy = ServiceRegistry::DestroyOnAppDestroy, //!< @copybrief QtMvvm::ServiceRegistry::DestroyOnAppDestroy |
| 35 | + DestroyOnRegistryDestroy = ServiceRegistry::DestroyOnRegistryDestroy, //!< @copybrief QtMvvm::ServiceRegistry::DestroyOnRegistryDestroy |
| 36 | + DestroyNever = ServiceRegistry::DestroyNever //!< @copybrief QtMvvm::ServiceRegistry::DestroyNever |
24 | 37 | }; |
25 | 38 | Q_ENUM(DestructionScope) |
26 | 39 |
|
| 40 | + //! @private |
27 | 41 | explicit QQmlServiceRegistry(QQmlEngine *parent = nullptr); |
28 | 42 |
|
| 43 | + //! @copydoc QtMvvm::ServiceRegistry::isRegistered() const |
29 | 44 | Q_INVOKABLE bool isRegistered(const QString &iid) const; |
30 | 45 |
|
31 | | - Q_INVOKABLE void registerObject(QObject *object, QtMvvm::QQmlServiceRegistry::DestructionScope scope = DestroyOnAppQuit, bool weak = false); |
| 46 | + //! @copydoc QtMvvm::ServiceRegistry::registerObject(TService *, DestructionScope, bool) |
| 47 | + Q_INVOKABLE void registerObject(QObject *service, QtMvvm::QQmlServiceRegistry::DestructionScope scope = DestroyOnAppQuit, bool weak = false); |
| 48 | + /*! |
| 49 | + * @brief Register a service via a constructor function |
| 50 | + * |
| 51 | + * @param iid The interface id of the type to register the service for |
| 52 | + * @param function The function to be called to construct the service |
| 53 | + * @param weak Specifies if the registration should be a weak one or a normal one |
| 54 | + * |
| 55 | + * If the function returns successfully, from now on a service of the given type can be accessed |
| 56 | + * via the registry for the interface. The service is lazy initialized an will be created as soon |
| 57 | + * as it is requested for the first time. It is created by calling the given `function`. |
| 58 | + * |
| 59 | + * If the service is registered as weak, registering another service for the same iid will not |
| 60 | + * throw an exception but instead discard (and delete) this one. |
| 61 | + */ |
32 | 62 | Q_INVOKABLE void registerObject(const QString &iid, const QJSValue &function, bool weak = false); |
| 63 | + /*! |
| 64 | + * @brief Register a qml component as service object |
| 65 | + * |
| 66 | + * @param componentUrl The URL of the component to be created |
| 67 | + * @param weak Specifies if the registration should be a weak one or a normal one |
| 68 | + * |
| 69 | + * This method works similar to the other register methods, but is special in that it |
| 70 | + * allows you to register a qml component. On construction, that component is loaded |
| 71 | + * synchronously and then insanciated to create an instance of the contained object. |
| 72 | + * |
| 73 | + * Unlike the other methods, the destruction scope for those is always |
| 74 | + * ServiceRegistry::DestroyOnAppDestroy, as the object will depend on the QML engine |
| 75 | + * |
| 76 | + * If the service is registered as weak, registering another service for the same iid will not |
| 77 | + * throw an exception but instead discard (and delete) this one. |
| 78 | + */ |
33 | 79 | Q_INVOKABLE void registerObject(const QUrl &componentUrl, bool weak = false); |
34 | 80 |
|
| 81 | + //! @copydoc QtMvvm::ServiceRegistry::registerService(QByteArray, QString, QString, DestructionScope, bool) |
35 | 82 | Q_INVOKABLE void registerPlugin(const QString &iid, |
36 | 83 | QString pluginType = {}, |
37 | 84 | QString pluginKey = {}, |
38 | 85 | DestructionScope scope = DestroyOnAppDestroy, |
39 | 86 | bool weak = false); |
40 | 87 |
|
| 88 | + //! @copydoc QtMvvm::ServiceRegistry::serviceObj(const QByteArray &) |
41 | 89 | Q_INVOKABLE QObject *service(const QString &iid); |
42 | 90 |
|
43 | 91 | private: |
|
0 commit comments