aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlextensionplugin.cpp
blob: 5af51769abcb6e01715ae730412be318b267878a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qqmlextensionplugin.h"
#include "qqmlextensionplugin_p.h"

QT_BEGIN_NAMESPACE

/*!
    \since 5.0
    \inmodule QtQml
    \class QQmlExtensionPlugin
    \brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins
           with custom type registration functions.

    \ingroup plugins

    \note If you need to write a plugin manually (which is rare) you should always use
    \l{QQmlEngineExtensionPlugin}. QQmlExtensionPlugin only provides the registerTypes() and
    unregisterTypes() functions in addition. You should not use them, but rather declare your
    types with \l{QML_ELEMENT} and friends and have the build system take care of the registration.
*/

/*!
    \since 5.14
    \inmodule QtQml
    \class QQmlEngineExtensionPlugin
    \brief The QQmlEngineExtensionPlugin class provides an abstract base for custom QML extension
           plugins.

    \ingroup plugins

    \include qqmlextensionplugin.qdocinc

    The \l {Writing QML Extensions with C++} tutorial also contains a chapter
    on creating QML plugins.

    \sa QQmlEngine::importPlugin(), {How to Create Qt Plugins}
*/

/*!
    \fn void QQmlExtensionPlugin::registerTypes(const char *uri)

    Registers the QML types in the given \a uri. Subclasses should implement
    this to call \l {QQmlEngine::}{qmlRegisterType()} for all types which are
    provided by the extension plugin.

    The \a uri is an identifier for the plugin generated by the QML engine
    based on the name and path of the extension's plugin library.
*/

/*!
    \internal
*/
QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent)
#if QT_DEPRECATED_SINCE(6, 3)
    : QObject(*(new QQmlExtensionPluginPrivate), parent)
#else
    : QObject(parent)
#endif
{
}

/*!
    Constructs a QML extension plugin with the given \a parent.

    Note that this constructor is invoked automatically by the
    Q_PLUGIN_METADATA() macro, so there is no need for calling it
    explicitly.
 */
QQmlEngineExtensionPlugin::QQmlEngineExtensionPlugin(QObject *parent)
    : QObject(parent)
{
}


/*!
  \internal
 */
QQmlExtensionPlugin::~QQmlExtensionPlugin() = default;

/*!
  \internal
 */
QQmlEngineExtensionPlugin::~QQmlEngineExtensionPlugin() = default;

#if QT_DEPRECATED_SINCE(6, 3)
/*!
    \since 5.1
    \internal
    \deprecated [6.3] This is unnecessary and doesn't work for optional plugins
    \brief Returns the URL of the directory from which the extension is loaded.

    This is useful when the plugin also needs to load QML files or other
    assets from the same directory.

    \note You should not need this function. Other files that are part of the
          module's public interface should be specified accordingly in the build
          system and qmldir file. The build system makes sure that they end up
          both in the final module directory, and in the resource file system.
          You can use the copy from the resource file system in the plugin.
          Non-QML/JS files private to the plugin can be added to the resource
          file system manually. However, consider moving all such functionality
          out of the plugin and making the plugin optional.
*/
QUrl QQmlExtensionPlugin::baseUrl() const
{
    Q_D(const QQmlExtensionPlugin);
    return d->baseUrl;
}
#endif

/*!
  \since 6.0

  Override this method to unregister types manually registered in registerTypes.
*/
void QQmlExtensionPlugin::unregisterTypes()
{

}

/*!
    Initializes the extension from the \a uri using the \a engine. Here an application
    plugin might, for example, expose some data or objects to QML,
    as context properties on the engine's root context.
 */
void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    Q_UNUSED(engine);
    Q_UNUSED(uri);
}

/*!
    Initializes the extension from the \a uri using the \a engine. Here an application
    plugin might, for example, expose some data or objects to QML,
    as context properties on the engine's root context.
 */
void QQmlEngineExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    Q_UNUSED(engine);
    Q_UNUSED(uri);
}

/*!
  \class QQmlExtensionInterface
  \internal
  \inmodule QtQml
*/

/*!
  \class QQmlTypesExtensionInterface
  \internal
  \inmodule QtQml
*/

/*!
  \class QQmlEngineExtensionInterface
  \internal
  \inmodule QtQml
*/


/*!
    \macro Q_IMPORT_QML_PLUGIN(PluginName)
    \since 6.2
    \relates QQmlEngineExtensionPlugin

    Ensures the plugin whose metadata-declaring plugin extension class is named
    \a PluginName is linked into static builds. For the modules created using
    \l qt_add_qml_module, the default plugin extension class name is computed
    from the QML module URI by replacing dots with underscores, unless the
    \c CLASS_NAME argument is specified.

    For example:
    \badcode
        qt_add_qml_module(myplugin
            # The plugin extension class name in this case is my_Company_QmlComponents.
            URI my.Company.QmlComponents
            ...
        )
    \endcode

    \sa Q_IMPORT_PLUGIN
*/

QT_END_NAMESPACE

#include "moc_qqmlextensionplugin.cpp"