1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include <QtDesigner/QtDesigner>
30
#include <QtGui/QtGui>
38
\fn QFormBuilder::QFormBuilder()
41
QFormBuilder::QFormBuilder()
45
QWidget *QFormBuilder::create(DomWidget *ui_widget, QWidget *parentWidget)
47
return QAbstractFormBuilder::create(ui_widget, parentWidget);
51
QWidget *QFormBuilder::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name)
55
if (qobject_cast<QTabWidget*>(parentWidget)
56
|| qobject_cast<QStackedWidget*>(parentWidget)
57
|| qobject_cast<QToolBox*>(parentWidget))
60
if (widgetName == QLatin1String("Line"))
61
w = new QFrame(parentWidget);
63
#define DECLARE_LAYOUT(L, C)
64
#define DECLARE_COMPAT_WIDGET(W, C) /*DECLARE_WIDGET(W, C)*/
65
#define DECLARE_WIDGET(W, C) else if (widgetName == QLatin1String(#W)) { Q_ASSERT(w == 0); w = new W(parentWidget); }
67
#include "widgets.table"
69
#undef DECLARE_COMPAT_WIDGET
73
if (w == 0) { // try with a registered custom widget
74
QDesignerCustomWidgetInterface *factory = m_customWidgets.value(widgetName);
76
w = factory->createWidget(parentWidget);
79
if (w == 0) { // nothing to do
83
w->setObjectName(name);
85
if (qobject_cast<QDialog *>(w))
86
w->setParent(parentWidget, 0);
91
QLayout *QFormBuilder::createLayout(const QString &layoutName, QObject *parent, const QString &name)
95
QWidget *parentWidget = qobject_cast<QWidget*>(parent);
96
QLayout *parentLayout = qobject_cast<QLayout*>(parent);
98
Q_ASSERT(parentWidget || parentLayout);
100
#define DECLARE_WIDGET(W, C)
101
#define DECLARE_COMPAT_WIDGET(W, C)
103
#define DECLARE_LAYOUT(L, C) \
104
if (layoutName == QLatin1String(#L)) { \
108
: new L(parentWidget); \
111
#include "widgets.table"
113
#undef DECLARE_LAYOUT
114
#undef DECLARE_COMPAT_WIDGET
115
#undef DECLARE_WIDGET
118
l->setObjectName(name);
120
qWarning("layout `%s' not supported", layoutName.toUtf8().data());
126
bool QFormBuilder::addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout)
128
return QAbstractFormBuilder::addItem(ui_item, item, layout);
131
bool QFormBuilder::addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget)
133
return QAbstractFormBuilder::addItem(ui_widget, widget, parentWidget);
136
QWidget *QFormBuilder::widgetByName(QWidget *topLevel, const QString &name)
139
if (topLevel->objectName() == name)
142
return qFindChild<QWidget*>(topLevel, name);
145
void QFormBuilder::createConnections(DomConnections *ui_connections, QWidget *widget)
147
Q_ASSERT(widget != 0);
149
if (ui_connections == 0)
152
QList<DomConnection*> connections = ui_connections->elementConnection();
153
foreach (DomConnection *c, connections) {
154
QWidget *sender = widgetByName(widget, c->elementSender());
155
QWidget *receiver = widgetByName(widget, c->elementReceiver());
156
if (!sender || !receiver)
159
QByteArray sig = c->elementSignal().toUtf8();
161
QByteArray sl = c->elementSlot().toUtf8();
164
QObject::connect(sender, sig, receiver, sl);
168
QWidget *QFormBuilder::create(DomUI *ui, QWidget *parentWidget)
170
return QAbstractFormBuilder::create(ui, parentWidget);
173
QLayout *QFormBuilder::create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget)
175
return QAbstractFormBuilder::create(ui_layout, layout, parentWidget);
178
QLayoutItem *QFormBuilder::create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget)
180
return QAbstractFormBuilder::create(ui_layoutItem, layout, parentWidget);
183
QAction *QFormBuilder::create(DomAction *ui_action, QObject *parent)
185
return QAbstractFormBuilder::create(ui_action, parent);
188
QActionGroup *QFormBuilder::create(DomActionGroup *ui_action_group, QObject *parent)
190
return QAbstractFormBuilder::create(ui_action_group, parent);
195
QStringList QFormBuilder::pluginPaths() const
197
return m_pluginPaths;
202
void QFormBuilder::clearPluginPaths()
204
m_pluginPaths.clear();
205
updateCustomWidgets();
210
void QFormBuilder::addPluginPath(const QString &pluginPath)
212
m_pluginPaths.append(pluginPath);
213
updateCustomWidgets();
218
void QFormBuilder::setPluginPath(const QStringList &pluginPaths)
220
m_pluginPaths = pluginPaths;
221
updateCustomWidgets();
224
void QFormBuilder::updateCustomWidgets()
226
m_customWidgets.clear();
228
foreach (QString path, m_pluginPaths) {
230
QStringList candidates = dir.entryList(QDir::Files);
232
foreach (QString plugin, candidates) {
233
if (!QLibrary::isLibrary(plugin))
236
QPluginLoader loader(path + QLatin1String("/") + plugin);
238
// step 1) try with a normal plugin
239
QDesignerCustomWidgetInterface *iface = 0;
240
iface = qobject_cast<QDesignerCustomWidgetInterface *>(loader.instance());
242
m_customWidgets.insert(iface->name(), iface);
246
// step 2) try with a collection of plugins
247
QDesignerCustomWidgetCollectionInterface *c = 0;
248
c = qobject_cast<QDesignerCustomWidgetCollectionInterface *>(loader.instance());
250
foreach (QDesignerCustomWidgetInterface *iface, c->customWidgets()) {
251
m_customWidgets.insert(iface->name(), iface);
260
\fn QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const
262
QList<QDesignerCustomWidgetInterface*> QFormBuilder::customWidgets() const
264
return m_customWidgets.values();