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