1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qqmlextensionplugin.h"
5#include "qqmlextensionplugin_p.h"
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \since 5.0
11 \inmodule QtQml
12 \class QQmlExtensionPlugin
13 \brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins
14 with custom type registration functions.
15
16 \ingroup plugins
17
18 \note If you need to write a plugin manually (which is rare) you should always use
19 \l{QQmlEngineExtensionPlugin}. QQmlExtensionPlugin only provides the registerTypes() and
20 unregisterTypes() functions in addition. You should not use them, but rather declare your
21 types with \l{QML_ELEMENT} and friends and have the build system take care of the registration.
22*/
23
24/*!
25 \since 5.14
26 \inmodule QtQml
27 \class QQmlEngineExtensionPlugin
28 \brief The QQmlEngineExtensionPlugin class provides an abstract base for custom QML extension
29 plugins.
30
31 \ingroup plugins
32
33 \include qqmlextensionplugin.qdocinc
34
35 The \l {Writing QML Extensions with C++} tutorial also contains a chapter
36 on creating QML plugins.
37
38 \sa QQmlEngine::importPlugin(), {How to Create Qt Plugins}
39*/
40
41/*!
42 \fn void QQmlExtensionPlugin::registerTypes(const char *uri)
43
44 Registers the QML types in the given \a uri. Subclasses should implement
45 this to call qmlRegisterType() for all types which are provided by the extension
46 plugin.
47
48 The \a uri is an identifier for the plugin generated by the QML engine
49 based on the name and path of the extension's plugin library.
50*/
51
52/*!
53 \internal
54*/
55QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent)
56#if QT_DEPRECATED_SINCE(6, 3)
57 : QObject(*(new QQmlExtensionPluginPrivate), parent)
58#else
59 : QObject(parent)
60#endif
61{
62}
63
64/*!
65 Constructs a QML extension plugin with the given \a parent.
66
67 Note that this constructor is invoked automatically by the
68 Q_PLUGIN_METADATA() macro, so there is no need for calling it
69 explicitly.
70 */
71QQmlEngineExtensionPlugin::QQmlEngineExtensionPlugin(QObject *parent)
72 : QObject(parent)
73{
74}
75
76
77/*!
78 \internal
79 */
80QQmlExtensionPlugin::~QQmlExtensionPlugin() = default;
81
82/*!
83 \internal
84 */
85QQmlEngineExtensionPlugin::~QQmlEngineExtensionPlugin() = default;
86
87#if QT_DEPRECATED_SINCE(6, 3)
88/*!
89 \since 5.1
90 \internal
91 \deprecated [6.3] This is unnecessary and doesn't work for optional plugins
92 \brief Returns the URL of the directory from which the extension is loaded.
93
94 This is useful when the plugin also needs to load QML files or other
95 assets from the same directory.
96
97 \note You should not need this function. Other files that are part of the
98 module's public interface should be specified accordingly in the build
99 system and qmldir file. The build system makes sure that they end up
100 both in the final module directory, and in the resource file system.
101 You can use the copy from the resource file system in the plugin.
102 Non-QML/JS files private to the plugin can be added to the resource
103 file system manually. However, consider moving all such functionality
104 out of the plugin and making the plugin optional.
105*/
106QUrl QQmlExtensionPlugin::baseUrl() const
107{
108 Q_D(const QQmlExtensionPlugin);
109 return d->baseUrl;
110}
111#endif
112
113/*!
114 \since 6.0
115
116 Override this method to unregister types manually registered in registerTypes.
117*/
118void QQmlExtensionPlugin::unregisterTypes()
119{
120
121}
122
123/*!
124 Initializes the extension from the \a uri using the \a engine. Here an application
125 plugin might, for example, expose some data or objects to QML,
126 as context properties on the engine's root context.
127 */
128void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
129{
130 Q_UNUSED(engine);
131 Q_UNUSED(uri);
132}
133
134/*!
135 Initializes the extension from the \a uri using the \a engine. Here an application
136 plugin might, for example, expose some data or objects to QML,
137 as context properties on the engine's root context.
138 */
139void QQmlEngineExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
140{
141 Q_UNUSED(engine);
142 Q_UNUSED(uri);
143}
144
145/*!
146 \class QQmlExtensionInterface
147 \internal
148 \inmodule QtQml
149*/
150
151/*!
152 \class QQmlTypesExtensionInterface
153 \internal
154 \inmodule QtQml
155*/
156
157/*!
158 \class QQmlEngineExtensionInterface
159 \internal
160 \inmodule QtQml
161*/
162
163
164/*!
165 \macro Q_IMPORT_QML_PLUGIN(PluginName)
166 \since 6.2
167 \relates QQmlEngineExtensionPlugin
168
169 Ensures the plugin whose metadata-declaring class is named \a PluginName
170 is linked into static builds.
171
172 \sa Q_IMPORT_PLUGIN
173*/
174
175QT_END_NAMESPACE
176
177#include "moc_qqmlextensionplugin.cpp"
178

source code of qtdeclarative/src/qml/qml/qqmlextensionplugin.cpp