source: trunk/tools/designer/src/lib/extension/qextensionmanager.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the Qt Designer of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qextensionmanager.h"
43
44QT_BEGIN_NAMESPACE
45
46/*!
47 \class QExtensionManager
48
49 \brief The QExtensionManager class provides extension management
50 facilities for Qt Designer.
51
52 \inmodule QtDesigner
53
54 In \QD the extensions are not created until they are required. For
55 that reason, when implementing an extension, you must also create
56 a QExtensionFactory, i.e a class that is able to make an instance
57 of your extension, and register it using \QD's extension manager.
58
59 The registration of an extension factory is typically made in the
60 QDesignerCustomWidgetInterface::initialize() function:
61
62 \snippet doc/src/snippets/code/tools_designer_src_lib_extension_qextensionmanager.cpp 0
63
64 The QExtensionManager is not intended to be instantiated
65 directly. You can retrieve an interface to \QD's extension manager
66 using the QDesignerFormEditorInterface::extensionManager()
67 function. A pointer to \QD's current QDesignerFormEditorInterface
68 object (\c formEditor in the example above) is provided by the
69 QDesignerCustomWidgetInterface::initialize() function's
70 parameter. When implementing a custom widget plugin, you must
71 subclass the QDesignerCustomWidgetInterface to expose your plugin
72 to \QD.
73
74 Then, when an extension is required, \QD's extension manager will
75 run through all its registered factories calling
76 QExtensionFactory::createExtension() for each until the first one
77 that is able to create the requested extension for the selected
78 object, is found. This factory will then make an instance of the
79 extension.
80
81 There are four available types of extensions in \QD:
82 QDesignerContainerExtension , QDesignerMemberSheetExtension,
83 QDesignerPropertySheetExtension and
84 QDesignerTaskMenuExtension. \QD's behavior is the same whether the
85 requested extension is associated with a container, a member
86 sheet, a property sheet or a task menu.
87
88 For a complete example using the QExtensionManager class, see the
89 \l {designer/taskmenuextension}{Task Menu Extension example}. The
90 example shows how to create a custom widget plugin for Qt
91 Designer, and how to to use the QDesignerTaskMenuExtension class
92 to add custom items to \QD's task menu.
93
94 \sa QExtensionFactory, QAbstractExtensionManager
95*/
96
97/*!
98 Constructs an extension manager with the given \a parent.
99*/
100QExtensionManager::QExtensionManager(QObject *parent)
101 : QObject(parent)
102{
103}
104
105
106/*!
107 Destroys the extension manager
108*/
109QExtensionManager::~QExtensionManager()
110{
111}
112
113/*!
114 Register the extension specified by the given \a factory and
115 extension identifier \a iid.
116*/
117void QExtensionManager::registerExtensions(QAbstractExtensionFactory *factory, const QString &iid)
118{
119 if (iid.isEmpty()) {
120 m_globalExtension.prepend(factory);
121 return;
122 }
123
124 FactoryMap::iterator it = m_extensions.find(iid);
125 if (it == m_extensions.end())
126 it = m_extensions.insert(iid, FactoryList());
127
128 it.value().prepend(factory);
129}
130
131/*!
132 Unregister the extension specified by the given \a factory and
133 extension identifier \a iid.
134*/
135void QExtensionManager::unregisterExtensions(QAbstractExtensionFactory *factory, const QString &iid)
136{
137 if (iid.isEmpty()) {
138 m_globalExtension.removeAll(factory);
139 return;
140 }
141
142 const FactoryMap::iterator it = m_extensions.find(iid);
143 if (it == m_extensions.end())
144 return;
145
146 FactoryList &factories = it.value();
147 factories.removeAll(factory);
148
149 if (factories.isEmpty())
150 m_extensions.erase(it);
151}
152
153/*!
154 Returns the extension specified by \a iid, for the given \a
155 object.
156*/
157QObject *QExtensionManager::extension(QObject *object, const QString &iid) const
158{
159 const FactoryMap::const_iterator it = m_extensions.constFind(iid);
160 if (it != m_extensions.constEnd()) {
161 const FactoryList::const_iterator fcend = it.value().constEnd();
162 for (FactoryList::const_iterator fit = it.value().constBegin(); fit != fcend; ++fit)
163 if (QObject *ext = (*fit)->extension(object, iid))
164 return ext;
165 }
166 const FactoryList::const_iterator gfcend = m_globalExtension.constEnd();
167 for (FactoryList::const_iterator git = m_globalExtension.constBegin(); git != gfcend; ++git)
168 if (QObject *ext = (*git)->extension(object, iid))
169 return ext;
170
171 return 0;
172}
173
174QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.