1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
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 a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \class QDesignerCustomWidgetInterface
|
---|
30 |
|
---|
31 | \brief The QDesignerCustomWidgetInterface class enables Qt Designer
|
---|
32 | to access and construct custom widgets.
|
---|
33 |
|
---|
34 | \inmodule QtDesigner
|
---|
35 |
|
---|
36 | QDesignerCustomWidgetInterface provides a custom widget with an
|
---|
37 | interface. The class contains a set of functions that must be subclassed
|
---|
38 | to return basic information about the widget, such as its class name and
|
---|
39 | the name of its header file. Other functions must be implemented to
|
---|
40 | initialize the plugin when it is loaded, and to construct instances of
|
---|
41 | the custom widget for \QD to use.
|
---|
42 |
|
---|
43 | When implementing a custom widget you must subclass
|
---|
44 | QDesignerCustomWidgetInterface to expose your widget to \QD. For
|
---|
45 | example, this is the declaration for the plugin used in the
|
---|
46 | \l{Custom Widget Plugin Example}{Custom Widget Plugin example} that
|
---|
47 | enables an analog clock custom widget to be used by \QD:
|
---|
48 |
|
---|
49 | \snippet examples/designer/customwidgetplugin/customwidgetplugin.h 0
|
---|
50 |
|
---|
51 | Note that the only part of the class definition that is specific
|
---|
52 | to this particular custom widget is the class name. In addition,
|
---|
53 | since we are implementing an interface, we must ensure that it's
|
---|
54 | made known to the meta object system using the Q_INTERFACES()
|
---|
55 | macro. This enables \QD to use the qobject_cast() function to
|
---|
56 | query for supported interfaces using nothing but a QObject
|
---|
57 | pointer.
|
---|
58 |
|
---|
59 | After \QD loads a custom widget plugin, it calls the interface's
|
---|
60 | initialize() function to enable it to set up any resources that it
|
---|
61 | may need. This function is called with a QDesignerFormEditorInterface
|
---|
62 | parameter that provides the plugin with a gateway to all of \QD's API.
|
---|
63 |
|
---|
64 | \QD constructs instances of the custom widget by calling the plugin's
|
---|
65 | createWidget() function with a suitable parent widget. Plugins must
|
---|
66 | construct and return an instance of a custom widget with the specified
|
---|
67 | parent widget.
|
---|
68 |
|
---|
69 | In the implementation of the class you must remember to export
|
---|
70 | your custom widget plugin to \QD using the Q_EXPORT_PLUGIN2()
|
---|
71 | macro. For example, if a library called \c libcustomwidgetplugin.so
|
---|
72 | (on Unix) or \c libcustomwidget.dll (on Windows) contains a widget
|
---|
73 | class called \c MyCustomWidget, we can export it by adding the
|
---|
74 | following line to the file containing the plugin implementation:
|
---|
75 |
|
---|
76 | \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 14
|
---|
77 |
|
---|
78 | This macro ensures that \QD can access and construct the custom widget.
|
---|
79 | Without this macro, there is no way for \QD to use it.
|
---|
80 |
|
---|
81 | When implementing a custom widget plugin, you build it as a
|
---|
82 | separate library. If you want to include several custom widget
|
---|
83 | plugins in the same library, you must in addition subclass
|
---|
84 | QDesignerCustomWidgetCollectionInterface.
|
---|
85 |
|
---|
86 | \warning If your custom widget plugin contains QVariant
|
---|
87 | properties, be aware that only the following \l
|
---|
88 | {QVariant::Type}{types} are supported:
|
---|
89 |
|
---|
90 | \list
|
---|
91 | \o QVariant::ByteArray
|
---|
92 | \o QVariant::Bool
|
---|
93 | \o QVariant::Color
|
---|
94 | \o QVariant::Cursor
|
---|
95 | \o QVariant::Date
|
---|
96 | \o QVariant::DateTime
|
---|
97 | \o QVariant::Double
|
---|
98 | \o QVariant::Int
|
---|
99 | \o QVariant::Point
|
---|
100 | \o QVariant::Rect
|
---|
101 | \o QVariant::Size
|
---|
102 | \o QVariant::SizePolicy
|
---|
103 | \o QVariant::String
|
---|
104 | \o QVariant::Time
|
---|
105 | \o QVariant::UInt
|
---|
106 | \endlist
|
---|
107 |
|
---|
108 | For a complete example using the QDesignerCustomWidgetInterface
|
---|
109 | class, see the \l {designer/customwidgetplugin}{Custom Widget
|
---|
110 | Example}. The example shows how to create a custom widget plugin
|
---|
111 | for \QD.
|
---|
112 |
|
---|
113 | \sa QDesignerCustomWidgetCollectionInterface {Creating Custom
|
---|
114 | Widgets for Qt Designer}
|
---|
115 | */
|
---|
116 |
|
---|
117 | /*!
|
---|
118 | \fn QDesignerCustomWidgetInterface::~QDesignerCustomWidgetInterface()
|
---|
119 |
|
---|
120 | Destroys the custom widget interface.
|
---|
121 | */
|
---|
122 |
|
---|
123 | /*!
|
---|
124 | \fn QString QDesignerCustomWidgetInterface::name() const
|
---|
125 |
|
---|
126 | Returns the class name of the custom widget supplied by the interface.
|
---|
127 |
|
---|
128 | The name returned \e must be identical to the class name used for the
|
---|
129 | custom widget.
|
---|
130 | */
|
---|
131 |
|
---|
132 | /*!
|
---|
133 | \fn QString QDesignerCustomWidgetInterface::group() const
|
---|
134 |
|
---|
135 | Returns the name of the group to which the custom widget belongs.
|
---|
136 | */
|
---|
137 |
|
---|
138 | /*!
|
---|
139 | \fn QString QDesignerCustomWidgetInterface::toolTip() const
|
---|
140 |
|
---|
141 | Returns a short description of the widget that can be used by \QD
|
---|
142 | in a tool tip.
|
---|
143 | */
|
---|
144 |
|
---|
145 | /*!
|
---|
146 | \fn QString QDesignerCustomWidgetInterface::whatsThis() const
|
---|
147 |
|
---|
148 | Returns a description of the widget that can be used by \QD in
|
---|
149 | "What's This?" help for the widget.
|
---|
150 | */
|
---|
151 |
|
---|
152 | /*!
|
---|
153 | \fn QString QDesignerCustomWidgetInterface::includeFile() const
|
---|
154 |
|
---|
155 | Returns the path to the include file that \l uic uses when
|
---|
156 | creating code for the custom widget.
|
---|
157 | */
|
---|
158 |
|
---|
159 | /*!
|
---|
160 | \fn QIcon QDesignerCustomWidgetInterface::icon() const
|
---|
161 |
|
---|
162 | Returns the icon used to represent the custom widget in \QD's
|
---|
163 | widget box.
|
---|
164 | */
|
---|
165 |
|
---|
166 | /*!
|
---|
167 | \fn bool QDesignerCustomWidgetInterface::isContainer() const
|
---|
168 |
|
---|
169 | Returns true if the custom widget is intended to be used as a
|
---|
170 | container; otherwise returns false.
|
---|
171 |
|
---|
172 | Most custom widgets are not used to hold other widgets, so their
|
---|
173 | implementations of this function will return false, but custom
|
---|
174 | containers will return true to ensure that they behave correctly
|
---|
175 | in \QD.
|
---|
176 | */
|
---|
177 |
|
---|
178 | /*!
|
---|
179 | \fn QWidget *QDesignerCustomWidgetInterface::createWidget(QWidget *parent)
|
---|
180 |
|
---|
181 | Returns a new instance of the custom widget, with the given \a
|
---|
182 | parent.
|
---|
183 | */
|
---|
184 |
|
---|
185 | /*!
|
---|
186 | \fn bool QDesignerCustomWidgetInterface::isInitialized() const
|
---|
187 |
|
---|
188 | Returns true if the widget has been initialized; otherwise returns
|
---|
189 | false.
|
---|
190 |
|
---|
191 | \sa initialize()
|
---|
192 | */
|
---|
193 |
|
---|
194 | /*!
|
---|
195 | \fn void QDesignerCustomWidgetInterface::initialize(QDesignerFormEditorInterface *formEditor)
|
---|
196 |
|
---|
197 | Initializes the widget for use with the specified \a formEditor
|
---|
198 | interface.
|
---|
199 |
|
---|
200 | \sa isInitialized()
|
---|
201 | */
|
---|
202 |
|
---|
203 | /*!
|
---|
204 | \fn QString QDesignerCustomWidgetInterface::domXml() const
|
---|
205 |
|
---|
206 | Returns the XML that is used to describe the custom widget's
|
---|
207 | properties to \QD.
|
---|
208 | */
|
---|
209 |
|
---|
210 | /*!
|
---|
211 | \fn QString QDesignerCustomWidgetInterface::codeTemplate() const
|
---|
212 |
|
---|
213 | This function is reserved for future use by \QD.
|
---|
214 |
|
---|
215 | \omit
|
---|
216 | Returns the code template that \QD includes in forms that contain
|
---|
217 | the custom widget when they are saved.
|
---|
218 | \endomit
|
---|
219 | */
|
---|
220 |
|
---|
221 | /*!
|
---|
222 | \macro QDESIGNER_WIDGET_EXPORT
|
---|
223 | \relates QDesignerCustomWidgetInterface
|
---|
224 | \since 4.1
|
---|
225 |
|
---|
226 | This macro is used when defining custom widgets to ensure that they are
|
---|
227 | correctly exported from plugins for use with \QD.
|
---|
228 |
|
---|
229 | On some platforms, the symbols required by \QD to create new widgets
|
---|
230 | are removed from plugins by the build system, making them unusable.
|
---|
231 | Using this macro ensures that the symbols are retained on those platforms,
|
---|
232 | and has no side effects on other platforms.
|
---|
233 |
|
---|
234 | For example, the \l{designer/worldtimeclockplugin}{World Time Clock Plugin}
|
---|
235 | example exports a custom widget class with the following declaration:
|
---|
236 |
|
---|
237 | \snippet examples/designer/worldtimeclockplugin/worldtimeclock.h 0
|
---|
238 | \dots
|
---|
239 | \snippet examples/designer/worldtimeclockplugin/worldtimeclock.h 2
|
---|
240 |
|
---|
241 | \sa {Creating Custom Widgets for Qt Designer}
|
---|
242 | */
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 |
|
---|
247 |
|
---|
248 | /*!
|
---|
249 | \class QDesignerCustomWidgetCollectionInterface
|
---|
250 |
|
---|
251 | \brief The QDesignerCustomWidgetCollectionInterface class allows
|
---|
252 | you to include several custom widgets in one single library.
|
---|
253 |
|
---|
254 | \inmodule QtDesigner
|
---|
255 |
|
---|
256 | When implementing a custom widget plugin, you build it as a
|
---|
257 | separate library. If you want to include several custom widget
|
---|
258 | plugins in the same library, you must in addition subclass
|
---|
259 | QDesignerCustomWidgetCollectionInterface.
|
---|
260 |
|
---|
261 | QDesignerCustomWidgetCollectionInterface contains one single
|
---|
262 | function returning a list of the collection's
|
---|
263 | QDesignerCustomWidgetInterface objects. For example, if you have
|
---|
264 | several custom widgets \c CustomWidgetOne, \c CustomWidgetTwo and
|
---|
265 | \c CustomWidgetThree, the class definition may look like this:
|
---|
266 |
|
---|
267 | \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 12
|
---|
268 |
|
---|
269 | In the class constructor you add the interfaces to your custom
|
---|
270 | widgets to the list which you return in the customWidgets()
|
---|
271 | function:
|
---|
272 |
|
---|
273 | \snippet doc/src/snippets/code/doc_src_qtdesigner.qdoc 13
|
---|
274 |
|
---|
275 | Note that instead of exporting each custom widget plugin using the
|
---|
276 | Q_EXPORT_PLUGIN2() macro, you export the entire collection. The
|
---|
277 | Q_EXPORT_PLUGIN2() macro ensures that \QD can access and construct
|
---|
278 | the custom widgets. Without this macro, there is no way for \QD to
|
---|
279 | use them.
|
---|
280 |
|
---|
281 | \sa QDesignerCustomWidgetInterface, {Creating Custom Widgets for
|
---|
282 | Qt Designer}
|
---|
283 | */
|
---|
284 |
|
---|
285 | /*!
|
---|
286 | \fn QDesignerCustomWidgetCollectionInterface::~QDesignerCustomWidgetCollectionInterface() {
|
---|
287 |
|
---|
288 | Destroys the custom widget collection interface.
|
---|
289 | */
|
---|
290 |
|
---|
291 | /*!
|
---|
292 | \fn QList<QDesignerCustomWidgetInterface*> QDesignerCustomWidgetCollectionInterface::customWidgets() const
|
---|
293 |
|
---|
294 | Returns a list of interfaces to the collection's custom widgets.
|
---|
295 | */
|
---|