84QWidget *QFormBuilder::create(DomWidget *ui_widget, QWidget *parentWidget)
86 if (!d->parentWidgetIsSet())
87 d->setParentWidget(parentWidget);
90 d->setProcessingLayoutWidget(
false);
91 if (ui_widget->attributeClass() ==
"QWidget"_L1 && !ui_widget->hasAttributeNative()
93#if QT_CONFIG(mainwindow)
94 && !qobject_cast<QMainWindow *>(parentWidget)
97 && !qobject_cast<QToolBox *>(parentWidget)
99#if QT_CONFIG(stackedwidget)
100 && !qobject_cast<QStackedWidget *>(parentWidget)
102#if QT_CONFIG(tabwidget)
103 && !qobject_cast<QTabWidget *>(parentWidget)
105#if QT_CONFIG(scrollarea)
106 && !qobject_cast<QScrollArea *>(parentWidget)
108#if QT_CONFIG(mdiarea)
109 && !qobject_cast<QMdiArea *>(parentWidget)
111#if QT_CONFIG(dockwidget)
112 && !qobject_cast<QDockWidget *>(parentWidget)
115 const QString parentClassName = QLatin1StringView(parentWidget->metaObject()->className());
116 if (!d->isCustomWidgetContainer(parentClassName))
117 d->setProcessingLayoutWidget(
true);
119 return QAbstractFormBuilder::create(ui_widget, parentWidget);
126QWidget *QFormBuilder::createWidget(
const QString &widgetName, QWidget *parentWidget,
const QString &name)
128 if (widgetName.isEmpty()) {
130 qWarning() << QCoreApplication::translate(
"QFormBuilder",
"An empty class name was passed on to %1 (object name: '%2').").arg(QString::fromUtf8(Q_FUNC_INFO), name);
134 QWidget *w =
nullptr;
136#if QT_CONFIG(tabwidget)
137 if (qobject_cast<QTabWidget*>(parentWidget))
138 parentWidget =
nullptr;
140#if QT_CONFIG(stackedwidget)
141 if (qobject_cast<QStackedWidget*>(parentWidget))
142 parentWidget =
nullptr;
144#if QT_CONFIG(toolbox)
145 if (qobject_cast<QToolBox*>(parentWidget))
146 parentWidget =
nullptr;
151 if (widgetName ==
"Line"_L1) {
152 w =
new QFrame(parentWidget);
153 static_cast<QFrame*>(w)->setFrameStyle(QFrame::HLine | QFrame::Sunken);
156 const QByteArray widgetNameBA = widgetName.toUtf8();
157 const char *widgetNameC = widgetNameBA.constData();
161#define DECLARE_LAYOUT(L, C)
162#define DECLARE_COMPAT_WIDGET(W, C)
163#define DECLARE_WIDGET(W, C) else if (!qstrcmp(widgetNameC, #W)) { Q_ASSERT(w == 0
); w = new W(parentWidget); }
164#define DECLARE_WIDGET_1(W, C) else if (!qstrcmp(widgetNameC, #W)) { Q_ASSERT(w == 0
); w = new W(0
, parentWidget); }
166#include "widgets.table"
168#undef DECLARE_COMPAT_WIDGET
171#undef DECLARE_WIDGET_1
177 QDesignerCustomWidgetInterface *factory = d->m_customWidgets.value(widgetName);
178 if (factory !=
nullptr)
179 w = factory->createWidget(parentWidget);
183 const QString baseClassName = d->customWidgetBaseClass(widgetName);
184 if (!baseClassName.isEmpty()) {
185 qWarning() << QCoreApplication::translate(
"QFormBuilder",
"QFormBuilder was unable to create a custom widget of the class '%1'; defaulting to base class '%2'.").arg(widgetName, baseClassName);
186 return createWidget(baseClassName, parentWidget, name);
191 qWarning() << QCoreApplication::translate(
"QFormBuilder",
"QFormBuilder was unable to create a widget of the class '%1'.").arg(widgetName);
195 w->setObjectName(name);
197 if (qobject_cast<QDialog *>(w))
198 w->setParent(parentWidget);
206QLayout *QFormBuilder::createLayout(
const QString &layoutName, QObject *parent,
const QString &name)
208 QLayout *l =
nullptr;
210 QWidget *parentWidget = qobject_cast<QWidget*>(parent);
211 QLayout *parentLayout = qobject_cast<QLayout*>(parent);
213 Q_ASSERT(parentWidget || parentLayout);
215#define DECLARE_WIDGET(W, C)
216#define DECLARE_COMPAT_WIDGET(W, C)
218#define DECLARE_LAYOUT(L, C)
219 if (layoutName == QLatin1StringView(#L)) {
223 : new L(parentWidget);
226#include "widgets.table"
229#undef DECLARE_COMPAT_WIDGET
233 l->setObjectName(name);
235 qWarning() << QCoreApplication::translate(
"QFormBuilder",
"The layout type `%1' is not supported.").arg(layoutName);
281void QFormBuilder::createConnections(DomConnections *ui_connections, QWidget *widget)
283 Q_ASSERT(widget !=
nullptr);
285 if (ui_connections ==
nullptr)
288 const auto &connections = ui_connections->elementConnection();
289 for (
const DomConnection *c : connections) {
290 QObject *sender = objectByName(widget, c->elementSender());
291 QObject *receiver = objectByName(widget, c->elementReceiver());
292 if (!sender || !receiver)
295 QByteArray sig = c->elementSignal().toUtf8();
297 QByteArray sl = c->elementSlot().toUtf8();
299 QObject::connect(sender, sig, receiver, sl);
314QLayout *QFormBuilder::create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget)
318 bool layoutWidget = d->processingLayoutWidget();
319 QLayout *l = QAbstractFormBuilder::create(ui_layout, layout, parentWidget);
321 int left = 0, top = 0, right = 0, bottom = 0;
322 QFormBuilderExtra::getLayoutMargins(ui_layout->elementProperty(),
323 &left, &top, &right, &bottom);
324 l->setContentsMargins(left, top, right, bottom);
325 d->setProcessingLayoutWidget(
false);