0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtDesigner/default_extensionfactory.h>
|
|
43 |
#include "qextensionmanager.h"
|
|
44 |
#include <qpointer.h>
|
|
45 |
#include <QtCore/qdebug.h>
|
|
46 |
|
|
47 |
QT_BEGIN_NAMESPACE
|
|
48 |
|
|
49 |
/*!
|
|
50 |
\class QExtensionFactory
|
|
51 |
|
|
52 |
\brief The QExtensionFactory class allows you to create a factory
|
|
53 |
that is able to make instances of custom extensions in Qt
|
|
54 |
Designer.
|
|
55 |
|
|
56 |
\inmodule QtDesigner
|
|
57 |
|
|
58 |
In \QD the extensions are not created until they are required. For
|
|
59 |
that reason, when implementing a custom extension, you must also
|
|
60 |
create a QExtensionFactory, i.e. a class that is able to make an
|
|
61 |
instance of your extension, and register it using \QD's \l
|
|
62 |
{QExtensionManager}{extension manager}.
|
|
63 |
|
|
64 |
The QExtensionManager class provides extension management
|
|
65 |
facilities for Qt Designer. When an extension is required, Qt
|
|
66 |
Designer's \l {QExtensionManager}{extension manager} will run
|
|
67 |
through all its registered factories calling
|
|
68 |
QExtensionFactory::createExtension() for each until the first one
|
|
69 |
that is able to create a requested extension for the selected
|
|
70 |
object, is found. This factory will then make an instance of the
|
|
71 |
extension.
|
|
72 |
|
|
73 |
There are four available types of extensions in Qt Designer:
|
|
74 |
QDesignerContainerExtension , QDesignerMemberSheetExtension,
|
|
75 |
QDesignerPropertySheetExtension and QDesignerTaskMenuExtension. Qt
|
|
76 |
Designer's behavior is the same whether the requested extension is
|
|
77 |
associated with a multi page container, a member sheet, a property
|
|
78 |
sheet or a task menu.
|
|
79 |
|
|
80 |
You can either create a new QExtensionFactory and reimplement the
|
|
81 |
QExtensionFactory::createExtension() function. For example:
|
|
82 |
|
|
83 |
\snippet doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp 0
|
|
84 |
|
|
85 |
Or you can use an existing factory, expanding the
|
|
86 |
QExtensionFactory::createExtension() function to make the factory
|
|
87 |
able to create your extension as well. For example:
|
|
88 |
|
|
89 |
\snippet doc/src/snippets/code/tools_designer_src_lib_extension_default_extensionfactory.cpp 1
|
|
90 |
|
|
91 |
For a complete example using the QExtensionFactory class, see the
|
|
92 |
\l {designer/taskmenuextension}{Task Menu Extension example}. The
|
|
93 |
example shows how to create a custom widget plugin for Qt
|
|
94 |
Designer, and how to to use the QDesignerTaskMenuExtension class
|
|
95 |
to add custom items to Qt Designer's task menu.
|
|
96 |
|
|
97 |
\sa QExtensionManager, QAbstractExtensionFactory
|
|
98 |
*/
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Constructs an extension factory with the given \a parent.
|
|
102 |
*/
|
|
103 |
QExtensionFactory::QExtensionFactory(QExtensionManager *parent)
|
|
104 |
: QObject(parent)
|
|
105 |
{
|
|
106 |
}
|
|
107 |
|
|
108 |
/*!
|
|
109 |
Returns the extension specified by \a iid for the given \a object.
|
|
110 |
|
|
111 |
\sa createExtension()
|
|
112 |
*/
|
|
113 |
|
|
114 |
QObject *QExtensionFactory::extension(QObject *object, const QString &iid) const
|
|
115 |
{
|
|
116 |
if (!object)
|
|
117 |
return 0;
|
|
118 |
const IdObjectKey key = qMakePair(iid, object);
|
|
119 |
|
|
120 |
ExtensionMap::iterator it = m_extensions.find(key);
|
|
121 |
if (it == m_extensions.end()) {
|
|
122 |
if (QObject *ext = createExtension(object, iid, const_cast<QExtensionFactory*>(this))) {
|
|
123 |
connect(ext, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));
|
|
124 |
it = m_extensions.insert(key, ext);
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
if (!m_extended.contains(object)) {
|
|
129 |
connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*)));
|
|
130 |
m_extended.insert(object, true);
|
|
131 |
}
|
|
132 |
|
|
133 |
if (it == m_extensions.end())
|
|
134 |
return 0;
|
|
135 |
|
|
136 |
return it.value();
|
|
137 |
}
|
|
138 |
|
|
139 |
void QExtensionFactory::objectDestroyed(QObject *object)
|
|
140 |
{
|
|
141 |
QMutableMapIterator< IdObjectKey, QObject*> it(m_extensions);
|
|
142 |
while (it.hasNext()) {
|
|
143 |
it.next();
|
|
144 |
|
|
145 |
QObject *o = it.key().second;
|
|
146 |
if (o == object || object == it.value()) {
|
|
147 |
it.remove();
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
m_extended.remove(object);
|
|
152 |
}
|
|
153 |
|
|
154 |
/*!
|
|
155 |
Creates an extension specified by \a iid for the given \a object.
|
|
156 |
The extension object is created as a child of the specified \a
|
|
157 |
parent.
|
|
158 |
|
|
159 |
\sa extension()
|
|
160 |
*/
|
|
161 |
QObject *QExtensionFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
|
|
162 |
{
|
|
163 |
Q_UNUSED(object);
|
|
164 |
Q_UNUSED(iid);
|
|
165 |
Q_UNUSED(parent);
|
|
166 |
|
|
167 |
return 0;
|
|
168 |
}
|
|
169 |
|
|
170 |
/*!
|
|
171 |
Returns the extension manager for the extension factory.
|
|
172 |
*/
|
|
173 |
QExtensionManager *QExtensionFactory::extensionManager() const
|
|
174 |
{
|
|
175 |
return static_cast<QExtensionManager *>(parent());
|
|
176 |
}
|
|
177 |
|
|
178 |
QT_END_NAMESPACE
|