author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 "customwidget.h" |
|
43 |
#include "formbuilder.h" |
|
44 |
#include "formbuilderextra_p.h" |
|
45 |
#include "ui4_p.h" |
|
46 |
||
47 |
#include <QtGui/QtGui> |
|
48 |
#include <QtCore/QCoreApplication> |
|
49 |
||
50 |
QT_BEGIN_NAMESPACE |
|
51 |
||
52 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
53 |
namespace QFormInternal { |
|
54 |
#endif |
|
55 |
||
56 |
/*! |
|
57 |
\class QFormBuilder |
|
58 |
||
59 |
\brief The QFormBuilder class is used to dynamically construct |
|
60 |
user interfaces from UI files at run-time. |
|
61 |
||
62 |
\inmodule QtDesigner |
|
63 |
||
64 |
The QFormBuilder class provides a mechanism for dynamically |
|
65 |
creating user interfaces at run-time, based on UI files |
|
66 |
created with \QD. For example: |
|
67 |
||
68 |
\snippet doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp 0 |
|
69 |
||
70 |
By including the user interface in the example's resources (\c |
|
71 |
myForm.qrc), we ensure that it will be present when the example is |
|
72 |
run: |
|
73 |
||
74 |
\snippet doc/src/snippets/code/tools_designer_src_lib_uilib_formbuilder.cpp 1 |
|
75 |
||
76 |
QFormBuilder extends the QAbstractFormBuilder base class with a |
|
77 |
number of functions that are used to support custom widget |
|
78 |
plugins: |
|
79 |
||
80 |
\list |
|
81 |
\o pluginPaths() returns the list of paths that the form builder |
|
82 |
searches when loading custom widget plugins. |
|
83 |
\o addPluginPath() allows additional paths to be registered with |
|
84 |
the form builder. |
|
85 |
\o setPluginPath() is used to replace the existing list of paths |
|
86 |
with a list obtained from some other source. |
|
87 |
\o clearPluginPaths() removes all paths registered with the form |
|
88 |
builder. |
|
89 |
\o customWidgets() returns a list of interfaces to plugins that |
|
90 |
can be used to create new instances of registered custom widgets. |
|
91 |
\endlist |
|
92 |
||
93 |
The QFormBuilder class is typically used by custom components and |
|
94 |
applications that embed \QD. Standalone applications that need to |
|
95 |
dynamically generate user interfaces at run-time use the |
|
96 |
QUiLoader class, found in the QtUiTools module. |
|
97 |
||
98 |
\sa QAbstractFormBuilder, {QtUiTools Module} |
|
99 |
*/ |
|
100 |
||
101 |
/*! |
|
102 |
\fn QFormBuilder::QFormBuilder() |
|
103 |
||
104 |
Constructs a new form builder. |
|
105 |
*/ |
|
106 |
||
107 |
QFormBuilder::QFormBuilder() : QAbstractFormBuilder() |
|
108 |
{ |
|
109 |
} |
|
110 |
||
111 |
/*! |
|
112 |
Destroys the form builder. |
|
113 |
*/ |
|
114 |
QFormBuilder::~QFormBuilder() |
|
115 |
{ |
|
116 |
} |
|
117 |
||
118 |
/*! |
|
119 |
\internal |
|
120 |
*/ |
|
121 |
QWidget *QFormBuilder::create(DomWidget *ui_widget, QWidget *parentWidget) |
|
122 |
{ |
|
123 |
QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); |
|
124 |
if (!fb->parentWidgetIsSet()) |
|
125 |
fb->setParentWidget(parentWidget); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
// Is this a QLayoutWidget with a margin of 0: Not a known page-based |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
// container and no method for adding pages registered. |
0 | 128 |
fb->setProcessingLayoutWidget(false); |
129 |
if (ui_widget->attributeClass() == QFormBuilderStrings::instance().qWidgetClass && !ui_widget->hasAttributeNative() |
|
130 |
&& parentWidget |
|
131 |
#ifndef QT_NO_MAINWINDOW |
|
132 |
&& !qobject_cast<QMainWindow *>(parentWidget) |
|
133 |
#endif |
|
134 |
#ifndef QT_NO_TOOLBOX |
|
135 |
&& !qobject_cast<QToolBox *>(parentWidget) |
|
136 |
#endif |
|
137 |
#ifndef QT_NO_STACKEDWIDGET |
|
138 |
&& !qobject_cast<QStackedWidget *>(parentWidget) |
|
139 |
#endif |
|
140 |
#ifndef QT_NO_STACKEDWIDGET |
|
141 |
&& !qobject_cast<QTabWidget *>(parentWidget) |
|
142 |
#endif |
|
143 |
#ifndef QT_NO_SCROLLAREA |
|
144 |
&& !qobject_cast<QScrollArea *>(parentWidget) |
|
145 |
#endif |
|
146 |
#ifndef QT_NO_MDIAREA |
|
147 |
&& !qobject_cast<QMdiArea *>(parentWidget) |
|
148 |
#endif |
|
149 |
#ifndef QT_NO_DOCKWIDGET |
|
150 |
&& !qobject_cast<QDockWidget *>(parentWidget) |
|
151 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
const QString parentClassName = QLatin1String(parentWidget->metaObject()->className()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
if (!fb->isCustomWidgetContainer(parentClassName)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
fb->setProcessingLayoutWidget(true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
} |
0 | 157 |
return QAbstractFormBuilder::create(ui_widget, parentWidget); |
158 |
} |
|
159 |
||
160 |
||
161 |
/*! |
|
162 |
\internal |
|
163 |
*/ |
|
164 |
QWidget *QFormBuilder::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name) |
|
165 |
{ |
|
166 |
if (widgetName.isEmpty()) { |
|
167 |
//: Empty class name passed to widget factory method |
|
168 |
qWarning() << QCoreApplication::translate("QFormBuilder", "An empty class name was passed on to %1 (object name: '%2').").arg(QString::fromUtf8(Q_FUNC_INFO), name); |
|
169 |
return 0; |
|
170 |
} |
|
171 |
||
172 |
QWidget *w = 0; |
|
173 |
||
174 |
#ifndef QT_NO_TABWIDGET |
|
175 |
if (qobject_cast<QTabWidget*>(parentWidget)) |
|
176 |
parentWidget = 0; |
|
177 |
#endif |
|
178 |
#ifndef QT_NO_STACKEDWIDGET |
|
179 |
if (qobject_cast<QStackedWidget*>(parentWidget)) |
|
180 |
parentWidget = 0; |
|
181 |
#endif |
|
182 |
#ifndef QT_NO_TOOLBOX |
|
183 |
if (qobject_cast<QToolBox*>(parentWidget)) |
|
184 |
parentWidget = 0; |
|
185 |
#endif |
|
186 |
||
187 |
// ### special-casing for Line (QFrame) -- fix for 4.2 |
|
188 |
do { |
|
189 |
if (widgetName == QFormBuilderStrings::instance().lineClass) { |
|
190 |
w = new QFrame(parentWidget); |
|
191 |
static_cast<QFrame*>(w)->setFrameStyle(QFrame::HLine | QFrame::Sunken); |
|
192 |
break; |
|
193 |
} |
|
194 |
const QByteArray widgetNameBA = widgetName.toUtf8(); |
|
195 |
const char *widgetNameC = widgetNameBA.constData(); |
|
196 |
if (w) { // symmetry for macro |
|
197 |
} |
|
198 |
||
199 |
#define DECLARE_LAYOUT(L, C) |
|
200 |
#define DECLARE_COMPAT_WIDGET(W, C) |
|
201 |
#define DECLARE_WIDGET(W, C) else if (!qstrcmp(widgetNameC, #W)) { Q_ASSERT(w == 0); w = new W(parentWidget); } |
|
202 |
#define DECLARE_WIDGET_1(W, C) else if (!qstrcmp(widgetNameC, #W)) { Q_ASSERT(w == 0); w = new W(0, parentWidget); } |
|
203 |
||
204 |
#include "widgets.table" |
|
205 |
||
206 |
#undef DECLARE_COMPAT_WIDGET |
|
207 |
#undef DECLARE_LAYOUT |
|
208 |
#undef DECLARE_WIDGET |
|
209 |
#undef DECLARE_WIDGET_1 |
|
210 |
||
211 |
if (w) |
|
212 |
break; |
|
213 |
||
214 |
// try with a registered custom widget |
|
215 |
QDesignerCustomWidgetInterface *factory = m_customWidgets.value(widgetName); |
|
216 |
if (factory != 0) |
|
217 |
w = factory->createWidget(parentWidget); |
|
218 |
} while(false); |
|
219 |
||
220 |
QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); |
|
221 |
if (w == 0) { // Attempt to instantiate base class of promoted/custom widgets |
|
222 |
const QString baseClassName = fb->customWidgetBaseClass(widgetName); |
|
223 |
if (!baseClassName.isEmpty()) { |
|
224 |
qWarning() << QCoreApplication::translate("QFormBuilder", "QFormBuilder was unable to create a custom widget of the class '%1'; defaulting to base class '%2'.").arg(widgetName, baseClassName); |
|
225 |
return createWidget(baseClassName, parentWidget, name); |
|
226 |
} |
|
227 |
} |
|
228 |
||
229 |
if (w == 0) { // nothing to do |
|
230 |
qWarning() << QCoreApplication::translate("QFormBuilder", "QFormBuilder was unable to create a widget of the class '%1'.").arg(widgetName); |
|
231 |
return 0; |
|
232 |
} |
|
233 |
||
234 |
w->setObjectName(name); |
|
235 |
||
236 |
if (qobject_cast<QDialog *>(w)) |
|
237 |
w->setParent(parentWidget); |
|
238 |
||
239 |
return w; |
|
240 |
} |
|
241 |
||
242 |
/*! |
|
243 |
\internal |
|
244 |
*/ |
|
245 |
QLayout *QFormBuilder::createLayout(const QString &layoutName, QObject *parent, const QString &name) |
|
246 |
{ |
|
247 |
QLayout *l = 0; |
|
248 |
||
249 |
QWidget *parentWidget = qobject_cast<QWidget*>(parent); |
|
250 |
QLayout *parentLayout = qobject_cast<QLayout*>(parent); |
|
251 |
||
252 |
Q_ASSERT(parentWidget || parentLayout); |
|
253 |
||
254 |
#define DECLARE_WIDGET(W, C) |
|
255 |
#define DECLARE_COMPAT_WIDGET(W, C) |
|
256 |
||
257 |
#define DECLARE_LAYOUT(L, C) \ |
|
258 |
if (layoutName == QLatin1String(#L)) { \ |
|
259 |
Q_ASSERT(l == 0); \ |
|
260 |
l = parentLayout \ |
|
261 |
? new L() \ |
|
262 |
: new L(parentWidget); \ |
|
263 |
} |
|
264 |
||
265 |
#include "widgets.table" |
|
266 |
||
267 |
#undef DECLARE_LAYOUT |
|
268 |
#undef DECLARE_COMPAT_WIDGET |
|
269 |
#undef DECLARE_WIDGET |
|
270 |
||
271 |
if (l) { |
|
272 |
l->setObjectName(name); |
|
273 |
if (parentLayout) { |
|
274 |
QWidget *w = qobject_cast<QWidget *>(parentLayout->parent()); |
|
275 |
if (w && w->inherits("Q3GroupBox")) { |
|
276 |
l->setContentsMargins(w->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
|
277 |
w->style()->pixelMetric(QStyle::PM_LayoutTopMargin), |
|
278 |
w->style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
|
279 |
w->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
|
280 |
QGridLayout *grid = qobject_cast<QGridLayout *>(l); |
|
281 |
if (grid) { |
|
282 |
grid->setHorizontalSpacing(-1); |
|
283 |
grid->setVerticalSpacing(-1); |
|
284 |
} else { |
|
285 |
l->setSpacing(-1); |
|
286 |
} |
|
287 |
l->setAlignment(Qt::AlignTop); |
|
288 |
} |
|
289 |
} |
|
290 |
} else { |
|
291 |
qWarning() << QCoreApplication::translate("QFormBuilder", "The layout type `%1' is not supported.").arg(layoutName); |
|
292 |
} |
|
293 |
||
294 |
return l; |
|
295 |
} |
|
296 |
||
297 |
/*! |
|
298 |
\internal |
|
299 |
*/ |
|
300 |
bool QFormBuilder::addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout) |
|
301 |
{ |
|
302 |
return QAbstractFormBuilder::addItem(ui_item, item, layout); |
|
303 |
} |
|
304 |
||
305 |
/*! |
|
306 |
\internal |
|
307 |
*/ |
|
308 |
bool QFormBuilder::addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) |
|
309 |
{ |
|
310 |
return QAbstractFormBuilder::addItem(ui_widget, widget, parentWidget); |
|
311 |
} |
|
312 |
||
313 |
/*! |
|
314 |
\internal |
|
315 |
*/ |
|
316 |
QWidget *QFormBuilder::widgetByName(QWidget *topLevel, const QString &name) |
|
317 |
{ |
|
318 |
Q_ASSERT(topLevel); |
|
319 |
if (topLevel->objectName() == name) |
|
320 |
return topLevel; |
|
321 |
||
322 |
return qFindChild<QWidget*>(topLevel, name); |
|
323 |
} |
|
324 |
||
325 |
static QObject *objectByName(QWidget *topLevel, const QString &name) |
|
326 |
{ |
|
327 |
Q_ASSERT(topLevel); |
|
328 |
if (topLevel->objectName() == name) |
|
329 |
return topLevel; |
|
330 |
||
331 |
return qFindChild<QObject*>(topLevel, name); |
|
332 |
} |
|
333 |
||
334 |
/*! |
|
335 |
\internal |
|
336 |
*/ |
|
337 |
void QFormBuilder::createConnections(DomConnections *ui_connections, QWidget *widget) |
|
338 |
{ |
|
339 |
typedef QList<DomConnection*> DomConnectionList; |
|
340 |
Q_ASSERT(widget != 0); |
|
341 |
||
342 |
if (ui_connections == 0) |
|
343 |
return; |
|
344 |
||
345 |
const DomConnectionList connections = ui_connections->elementConnection(); |
|
346 |
if (!connections.empty()) { |
|
347 |
const DomConnectionList::const_iterator cend = connections.constEnd(); |
|
348 |
for (DomConnectionList::const_iterator it = connections.constBegin(); it != cend; ++it) { |
|
349 |
||
350 |
QObject *sender = objectByName(widget, (*it)->elementSender()); |
|
351 |
QObject *receiver = objectByName(widget, (*it)->elementReceiver()); |
|
352 |
if (!sender || !receiver) |
|
353 |
continue; |
|
354 |
||
355 |
QByteArray sig = (*it)->elementSignal().toUtf8(); |
|
356 |
sig.prepend("2"); |
|
357 |
QByteArray sl = (*it)->elementSlot().toUtf8(); |
|
358 |
sl.prepend("1"); |
|
359 |
QObject::connect(sender, sig, receiver, sl); |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
/*! |
|
365 |
\internal |
|
366 |
*/ |
|
367 |
QWidget *QFormBuilder::create(DomUI *ui, QWidget *parentWidget) |
|
368 |
{ |
|
369 |
return QAbstractFormBuilder::create(ui, parentWidget); |
|
370 |
} |
|
371 |
||
372 |
/*! |
|
373 |
\internal |
|
374 |
*/ |
|
375 |
QLayout *QFormBuilder::create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget) |
|
376 |
{ |
|
377 |
QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); |
|
378 |
// Is this a temporary layout widget used to represent QLayout hierarchies in Designer? |
|
379 |
// Set its margins to 0. |
|
380 |
bool layoutWidget = fb->processingLayoutWidget(); |
|
381 |
QLayout *l = QAbstractFormBuilder::create(ui_layout, layout, parentWidget); |
|
382 |
if (layoutWidget) { |
|
383 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
384 |
int left, top, right, bottom; |
|
385 |
left = top = right = bottom = 0; |
|
386 |
const DomPropertyHash properties = propertyMap(ui_layout->elementProperty()); |
|
387 |
||
388 |
if (DomProperty *prop = properties.value(strings.leftMarginProperty)) |
|
389 |
left = prop->elementNumber(); |
|
390 |
||
391 |
if (DomProperty *prop = properties.value(strings.topMarginProperty)) |
|
392 |
top = prop->elementNumber(); |
|
393 |
||
394 |
if (DomProperty *prop = properties.value(strings.rightMarginProperty)) |
|
395 |
right = prop->elementNumber(); |
|
396 |
||
397 |
if (DomProperty *prop = properties.value(strings.bottomMarginProperty)) |
|
398 |
bottom = prop->elementNumber(); |
|
399 |
||
400 |
l->setContentsMargins(left, top, right, bottom); |
|
401 |
fb->setProcessingLayoutWidget(false); |
|
402 |
} |
|
403 |
return l; |
|
404 |
} |
|
405 |
||
406 |
/*! |
|
407 |
\internal |
|
408 |
*/ |
|
409 |
QLayoutItem *QFormBuilder::create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget) |
|
410 |
{ |
|
411 |
return QAbstractFormBuilder::create(ui_layoutItem, layout, parentWidget); |
|
412 |
} |
|
413 |
||
414 |
/*! |
|
415 |
\internal |
|
416 |
*/ |
|
417 |
QAction *QFormBuilder::create(DomAction *ui_action, QObject *parent) |
|
418 |
{ |
|
419 |
return QAbstractFormBuilder::create(ui_action, parent); |
|
420 |
} |
|
421 |
||
422 |
/*! |
|
423 |
\internal |
|
424 |
*/ |
|
425 |
QActionGroup *QFormBuilder::create(DomActionGroup *ui_action_group, QObject *parent) |
|
426 |
{ |
|
427 |
return QAbstractFormBuilder::create(ui_action_group, parent); |
|
428 |
} |
|
429 |
||
430 |
/*! |
|
431 |
Returns the list of paths the form builder searches for plugins. |
|
432 |
||
433 |
\sa addPluginPath() |
|
434 |
*/ |
|
435 |
QStringList QFormBuilder::pluginPaths() const |
|
436 |
{ |
|
437 |
return m_pluginPaths; |
|
438 |
} |
|
439 |
||
440 |
/*! |
|
441 |
Clears the list of paths that the form builder uses to search for |
|
442 |
custom widget plugins. |
|
443 |
||
444 |
\sa pluginPaths() |
|
445 |
*/ |
|
446 |
void QFormBuilder::clearPluginPaths() |
|
447 |
{ |
|
448 |
m_pluginPaths.clear(); |
|
449 |
updateCustomWidgets(); |
|
450 |
} |
|
451 |
||
452 |
/*! |
|
453 |
Adds a new plugin path specified by \a pluginPath to the list of |
|
454 |
paths that will be searched by the form builder when loading a |
|
455 |
custom widget plugin. |
|
456 |
||
457 |
\sa setPluginPath(), clearPluginPaths() |
|
458 |
*/ |
|
459 |
void QFormBuilder::addPluginPath(const QString &pluginPath) |
|
460 |
{ |
|
461 |
m_pluginPaths.append(pluginPath); |
|
462 |
updateCustomWidgets(); |
|
463 |
} |
|
464 |
||
465 |
/*! |
|
466 |
Sets the list of plugin paths to the list specified by \a pluginPaths. |
|
467 |
||
468 |
\sa addPluginPath() |
|
469 |
*/ |
|
470 |
void QFormBuilder::setPluginPath(const QStringList &pluginPaths) |
|
471 |
{ |
|
472 |
m_pluginPaths = pluginPaths; |
|
473 |
updateCustomWidgets(); |
|
474 |
} |
|
475 |
||
476 |
static void insertPlugins(QObject *o, QMap<QString, QDesignerCustomWidgetInterface*> *customWidgets) |
|
477 |
{ |
|
478 |
// step 1) try with a normal plugin |
|
479 |
if (QDesignerCustomWidgetInterface *iface = qobject_cast<QDesignerCustomWidgetInterface *>(o)) { |
|
480 |
customWidgets->insert(iface->name(), iface); |
|
481 |
return; |
|
482 |
} |
|
483 |
// step 2) try with a collection of plugins |
|
484 |
if (QDesignerCustomWidgetCollectionInterface *c = qobject_cast<QDesignerCustomWidgetCollectionInterface *>(o)) { |
|
485 |
foreach (QDesignerCustomWidgetInterface *iface, c->customWidgets()) |
|
486 |
customWidgets->insert(iface->name(), iface); |
|
487 |
} |
|
488 |
} |
|
489 |
||
490 |
/*! |
|
491 |
\internal |
|
492 |
*/ |
|
493 |
void QFormBuilder::updateCustomWidgets() |
|
494 |
{ |
|
495 |
m_customWidgets.clear(); |
|
496 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
497 |
foreach (const QString &path, m_pluginPaths) { |
0 | 498 |
const QDir dir(path); |
499 |
const QStringList candidates = dir.entryList(QDir::Files); |
|
500 |
||
501 |
foreach (const QString &plugin, candidates) { |
|
502 |
if (!QLibrary::isLibrary(plugin)) |
|
503 |
continue; |
|
504 |
||
505 |
QString loaderPath = path; |
|
506 |
loaderPath += QLatin1Char('/'); |
|
507 |
loaderPath += plugin; |
|
508 |
||
509 |
QPluginLoader loader(loaderPath); |
|
510 |
if (loader.load()) |
|
511 |
insertPlugins(loader.instance(), &m_customWidgets); |
|
512 |
} |
|
513 |
} |
|
514 |
// Check statically linked plugins |
|
515 |
const QObjectList staticPlugins = QPluginLoader::staticInstances(); |
|
516 |
if (!staticPlugins.empty()) |
|
517 |
foreach (QObject *o, staticPlugins) |
|
518 |
insertPlugins(o, &m_customWidgets); |
|
519 |
} |
|
520 |
||
521 |
/*! |
|
522 |
\fn QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const |
|
523 |
||
524 |
Returns a list of the available plugins. |
|
525 |
*/ |
|
526 |
QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const |
|
527 |
{ |
|
528 |
return m_customWidgets.values(); |
|
529 |
} |
|
530 |
||
531 |
/*! |
|
532 |
\internal |
|
533 |
*/ |
|
534 |
||
535 |
void QFormBuilder::applyProperties(QObject *o, const QList<DomProperty*> &properties) |
|
536 |
{ |
|
537 |
typedef QList<DomProperty*> DomPropertyList; |
|
538 |
||
539 |
if (properties.empty()) |
|
540 |
return; |
|
541 |
||
542 |
QFormBuilderExtra *fb = QFormBuilderExtra::instance(this); |
|
543 |
const QFormBuilderStrings &strings = QFormBuilderStrings::instance(); |
|
544 |
||
545 |
const DomPropertyList::const_iterator cend = properties.constEnd(); |
|
546 |
for (DomPropertyList::const_iterator it = properties.constBegin(); it != cend; ++it) { |
|
547 |
const QVariant v = toVariant(o->metaObject(), *it); |
|
548 |
if (v.isNull()) |
|
549 |
continue; |
|
550 |
||
551 |
const QString attributeName = (*it)->attributeName(); |
|
552 |
const bool isWidget = o->isWidgetType(); |
|
553 |
if (isWidget && o->parent() == fb->parentWidget() && attributeName == strings.geometryProperty) { |
|
554 |
// apply only the size part of a geometry for the root widget |
|
555 |
static_cast<QWidget*>(o)->resize(qvariant_cast<QRect>(v).size()); |
|
556 |
} else if (fb->applyPropertyInternally(o, attributeName, v)) { |
|
557 |
} else if (isWidget && !qstrcmp("QFrame", o->metaObject()->className ()) && attributeName == strings.orientationProperty) { |
|
558 |
// ### special-casing for Line (QFrame) -- try to fix me |
|
559 |
o->setProperty("frameShape", v); // v is of QFrame::Shape enum |
|
560 |
} else { |
|
561 |
o->setProperty(attributeName.toUtf8(), v); |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
567 |
} // namespace QFormInternal |
|
568 |
#endif |
|
569 |
||
570 |
QT_END_NAMESPACE |