Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
extension.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant reason:default
4
5#include <QtDesigner/extension.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \class QAbstractExtensionFactory
11
12 \brief The QAbstractExtensionFactory class provides an interface
13 for extension factories in \QD.
14
15 \inmodule QtDesigner
16
17 QAbstractExtensionFactory is not intended to be instantiated
18 directly; use the QExtensionFactory instead.
19
20 In \QD, extension factories are used to look up and create named
21 extensions as they are required. For that reason, when
22 implementing a custom extension, you must also create a
23 QExtensionFactory, i.e a class that is able to make an instance of
24 your extension, and register it using \QD's \l
25 {QExtensionManager}{extension manager}.
26
27 When an extension is required, \QD's \l
28 {QExtensionManager}{extension manager} will run through all its
29 registered factories calling QExtensionFactory::createExtension()
30 for each until the first one that is able to create the requested
31 extension for the selected object, is found. This factory will
32 then make an instance of the extension.
33
34 \sa QExtensionFactory, QExtensionManager
35*/
36
37/*!
38 Destroys the extension factory.
39*/
40QAbstractExtensionFactory::~QAbstractExtensionFactory()
41 = default;
42
43/*!
44 \fn QObject *QAbstractExtensionFactory::extension(QObject *object, const QString &iid) const
45
46 Returns the extension specified by \a iid for the given \a object.
47*/
48
49
50/*!
51 \class QAbstractExtensionManager
52
53 \brief The QAbstractExtensionManager class provides an interface
54 for extension managers in \QD.
55
56 \inmodule QtDesigner
57
58 QAbstractExtensionManager is not intended to be instantiated
59 directly; use the QExtensionManager instead.
60
61 In \QD, extension are not created until they are required. For
62 that reason, when implementing a custom extension, you must also
63 create a QExtensionFactory, i.e a class that is able to make an
64 instance of your extension, and register it using \QD's \l
65 {QExtensionManager}{extension manager}.
66
67 When an extension is required, \QD's \l
68 {QExtensionManager}{extension manager} will run through all its
69 registered factories calling QExtensionFactory::createExtension()
70 for each until the first one that is able to create the requested
71 extension for the selected object, is found. This factory will
72 then make an instance of the extension.
73
74 \sa QExtensionManager, QExtensionFactory
75*/
76
77/*!
78 Destroys the extension manager.
79*/
80QAbstractExtensionManager::~QAbstractExtensionManager()
81 = default;
82
83/*!
84 \fn void QAbstractExtensionManager::registerExtensions(QAbstractExtensionFactory *factory, const QString &iid)
85
86 Register the given extension \a factory with the extension
87 specified by \a iid.
88*/
89
90/*!
91 \fn void QAbstractExtensionManager::unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid)
92
93 Unregister the given \a factory with the extension specified by \a
94 iid.
95*/
96
97/*!
98 \fn QObject *QAbstractExtensionManager::extension(QObject *object, const QString &iid) const
99
100 Returns the extension, specified by \a iid, for the given \a
101 object.
102*/
103
104/*!
105 \fn template <class T> T qt_extension(QAbstractExtensionManager* manager, QObject *object)
106
107 \relates QExtensionManager
108
109 Returns the extension of the given \a object cast to type T if the
110 object is of type T (or of a subclass); otherwise returns 0. The
111 extension is retrieved using the given extension \a manager.
112
113 \snippet lib/tools_designer_src_lib_extension_extension.cpp 0
114
115 When implementing a custom widget plugin, a pointer to \QD's
116 current QDesignerFormEditorInterface object (\c formEditor) is
117 provided by the QDesignerCustomWidgetInterface::initialize()
118 function's parameter.
119
120 If the widget in the example above doesn't have a defined
121 QDesignerPropertySheetExtension, \c propertySheet will be a null
122 pointer.
123
124*/
125
126/*!
127 \macro Q_DECLARE_EXTENSION_INTERFACE(ExtensionName, Identifier)
128
129 \relates QExtensionManager
130
131 Associates the given \a Identifier (a string literal) to the
132 extension class called \a ExtensionName. The \a Identifier must be
133 unique. For example:
134
135 \snippet lib/tools_designer_src_lib_extension_extension.cpp 1
136
137 Using the company and product names is a good way to ensure
138 uniqueness of the identifier.
139
140 When implementing a custom extension class, you must use
141 Q_DECLARE_EXTENSION_INTERFACE() to enable usage of the
142 qt_extension() function. The macro is normally located right after the
143 class definition for \a ExtensionName, in the associated header
144 file.
145
146 \sa {Q_DECLARE_INTERFACE}{Q_DECLARE_INTERFACE()}
147*/
148
149QT_END_NAMESPACE