Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qextensionmanager.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
"qextensionmanager.h"
6
7
QT_BEGIN_NAMESPACE
8
9
/*!
10
\class QExtensionManager
11
12
\brief The QExtensionManager class provides extension management
13
facilities for \QD.
14
15
\inmodule QtDesigner
16
17
In \QD the extensions are not created until they are required. For
18
that reason, when implementing an extension, you must also create
19
a QExtensionFactory, i.e a class that is able to make an instance
20
of your extension, and register it using \QD's extension manager.
21
22
The registration of an extension factory is typically made in the
23
QDesignerCustomWidgetInterface::initialize() function:
24
25
\snippet lib/tools_designer_src_lib_extension_qextensionmanager.cpp 0
26
27
The QExtensionManager is not intended to be instantiated
28
directly. You can retrieve an interface to \QD's extension manager
29
using the QDesignerFormEditorInterface::extensionManager()
30
function. A pointer to \QD's current QDesignerFormEditorInterface
31
object (\c formEditor in the example above) is provided by the
32
QDesignerCustomWidgetInterface::initialize() function's
33
parameter. When implementing a custom widget plugin, you must
34
subclass the QDesignerCustomWidgetInterface to expose your plugin
35
to \QD.
36
37
Then, when an extension is required, \QD's extension manager will
38
run through all its registered factories calling
39
QExtensionFactory::createExtension() for each until the first one
40
that is able to create the requested extension for the selected
41
object, is found. This factory will then make an instance of the
42
extension.
43
44
There are four available types of extensions in \QD:
45
QDesignerContainerExtension , QDesignerMemberSheetExtension,
46
QDesignerPropertySheetExtension and
47
QDesignerTaskMenuExtension. \QD's behavior is the same whether the
48
requested extension is associated with a container, a member
49
sheet, a property sheet or a task menu.
50
51
For a complete example using the QExtensionManager class, see the
52
\l {taskmenuextension}{Task Menu Extension example}. The
53
example shows how to create a custom widget plugin for Qt
54
Designer, and how to use the QDesignerTaskMenuExtension class
55
to add custom items to \QD's task menu.
56
57
\sa QExtensionFactory, QAbstractExtensionManager
58
*/
59
60
/*!
61
Constructs an extension manager with the given \a parent.
62
*/
63
QExtensionManager::QExtensionManager(QObject *parent)
64
: QObject(parent)
65
{
66
}
67
68
69
/*!
70
Destroys the extension manager
71
*/
72
QExtensionManager::~QExtensionManager() =
default
;
73
74
/*!
75
Register the extension specified by the given \a factory and
76
extension identifier \a iid.
77
*/
78
void
QExtensionManager::registerExtensions(QAbstractExtensionFactory *factory,
const
QString &iid)
79
{
80
if
(iid.isEmpty()) {
81
m_globalExtension.prepend(factory);
82
return
;
83
}
84
85
auto
it = m_extensions.find(iid);
86
if
(it == m_extensions.end())
87
it = m_extensions.insert(iid, FactoryList());
88
89
it.value().prepend(factory);
90
}
91
92
/*!
93
Unregister the extension specified by the given \a factory and
94
extension identifier \a iid.
95
*/
96
void
QExtensionManager::unregisterExtensions(QAbstractExtensionFactory *factory,
const
QString &iid)
97
{
98
if
(iid.isEmpty()) {
99
m_globalExtension.removeAll(factory);
100
return
;
101
}
102
103
const
auto
it = m_extensions.find(iid);
104
if
(it == m_extensions.end())
105
return
;
106
107
FactoryList &factories = it.value();
108
factories.removeAll(factory);
109
110
if
(factories.isEmpty())
111
m_extensions.erase(it);
112
}
113
114
/*!
115
Returns the extension specified by \a iid, for the given \a
116
object.
117
*/
118
QObject *QExtensionManager::extension(QObject *object,
const
QString &iid)
const
119
{
120
const
auto
it = m_extensions.constFind(iid);
121
if
(it != m_extensions.constEnd()) {
122
for
(
const
auto
&f : it.value()) {
123
if
(QObject *ext = f->extension(object, iid))
124
return
ext;
125
}
126
}
127
128
for
(
const
auto
&gf : m_globalExtension) {
129
if
(QObject *ext = gf->extension(object, iid))
130
return
ext;
131
}
132
133
return
nullptr
;
134
}
135
136
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qttools
src
designer
src
lib
extension
qextensionmanager.cpp
Generated on
for Qt by
1.18.0