Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_formbuilder.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
9
10#include <QtDesigner/private/ui4_p.h>
11#include <QtDesigner/private/formbuilderextra_p.h>
12// sdk
13#include <QtDesigner/container.h>
14#include <QtDesigner/propertysheet.h>
15#include <QtDesigner/qextensionmanager.h>
16#include <QtDesigner/abstractformeditor.h>
17#include <QtDesigner/abstractformwindow.h>
18#include <QtDesigner/abstractwidgetfactory.h>
19#include <abstractdialoggui_p.h>
20
21#include <QtUiPlugin/customwidget.h>
22
23// shared
24#include <qdesigner_propertysheet_p.h>
25#include <qdesigner_utils_p.h>
26#include <formwindowbase_p.h>
27#include <qtresourcemodel_p.h>
28
29#include <QtWidgets/qwidget.h>
30#include <QtWidgets/qmenu.h>
31#include <QtWidgets/qtoolbar.h>
32#include <QtWidgets/qmenubar.h>
33#include <QtWidgets/qmainwindow.h>
34#include <QtWidgets/qstylefactory.h>
35#include <QtWidgets/qstyle.h>
36#include <QtWidgets/qapplication.h>
37#include <QtWidgets/qabstractscrollarea.h>
38#include <QtWidgets/qmessagebox.h>
39#include <QtGui/qpixmap.h>
40
41#include <QtCore/qbuffer.h>
42#include <QtCore/qdebug.h>
43#include <QtCore/qcoreapplication.h>
44
46
47using namespace Qt::StringLiterals;
48
49namespace qdesigner_internal {
50
62
69
97
99{
100 QWidget *widget = nullptr;
101
102 if (widgetName == "QToolBar"_L1) {
104 } else if (widgetName == "QMenu"_L1) {
106 } else if (widgetName == "QMenuBar"_L1) {
108 } else {
110 }
111
112 if (widget) {
116 }
117
118 if (m_mainWidget) { // We need to apply the DPI here to take effect on size hints, etc.
120 m_mainWidget = false;
121 }
122 return widget;
123}
124
126{
127 // Use container extension or rely on scripts unless main window.
129 return true;
130
133 return true;
134 }
135 return false;
136}
137
142
144{
147 qWarning() << "QDesignerFormBuilder::nameToIcon() is obsoleted";
148 return QIcon();
149}
150
152{
155 qWarning() << "QDesignerFormBuilder::nameToPixmap() is obsoleted";
156 return QPixmap();
157}
158
159/* If the property is a enum or flag value, retrieve
160 * the existing enum/flag type via property sheet and use it to convert */
161
162static bool readDomEnumerationValue(const DomProperty *p,
163 const QDesignerPropertySheetExtension* sheet,
164 QVariant &v)
165{
166 switch (p->kind()) {
167 case DomProperty::Set: {
168 const int index = sheet->indexOf(p->attributeName());
169 if (index == -1)
170 return false;
171 const QVariant sheetValue = sheet->property(index);
172 if (sheetValue.canConvert<PropertySheetFlagValue>()) {
173 const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(sheetValue);
174 bool ok = false;
175 v = f.metaFlags.parseFlags(p->elementSet(), &ok);
176 if (!ok)
177 designerWarning(f.metaFlags.messageParseFailed(p->elementSet()));
178 return true;
179 }
180 }
181 break;
182 case DomProperty::Enum: {
183 const int index = sheet->indexOf(p->attributeName());
184 if (index == -1)
185 return false;
186 const QVariant sheetValue = sheet->property(index);
187 if (sheetValue.canConvert<PropertySheetEnumValue>()) {
188 const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(sheetValue);
189 bool ok = false;
190 v = e.metaEnum.parseEnum(p->elementEnum(), &ok);
191 if (!ok)
192 designerWarning(e.metaEnum.messageParseFailed(p->elementEnum()));
193 return true;
194 }
195 }
196 break;
197 default:
198 break;
199 }
200 return false;
201}
202
204{
205 if (properties.isEmpty())
206 return;
207
210 const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == "QAxWidget"_L1;
213
216
224 }
225
226 for (DomProperty *p : properties) {
227 QVariant v;
229 v = toVariant(o->metaObject(), p);
230
231 if (v.isNull())
232 continue;
233
236 continue;
237
238 // refuse fake properties like current tab name (weak test)
240 if (changingMetaObject) // Changes after setting control of QAxWidget
243 continue;
244 }
245
246 QObject *obj = o;
248 if (scroll && attributeName == "cursor"_L1 && scroll->viewport())
249 obj = scroll->viewport();
250
251 // a real property
253 }
254
258 }
259}
260
267
269{
271 // Do not apply state if scripts are to be run in preview mode
273 return widget;
274}
275
291
296
301
303 const QString &styleName,
304 const QString &appStyleSheet,
307{
308 // load
311
313
316
317 QWidget *widget = builder.load(&buffer, nullptr);
318 if (!widget) { // Shouldn't happen
319 *errorMessage = QCoreApplication::translate("QDesignerFormBuilder", "The preview failed to build.");
320 return nullptr;
321 }
322 // Make sure palette is applied
324 if (!styleToUse.isEmpty()) {
326 if (styleToUse != wf->styleName())
328 }
329 }
330 // Fake application style sheet by prepending. (If this doesn't work, fake by nesting
331 // into parent widget).
332 if (!appStyleSheet.isEmpty())
334 return widget;
335}
336
341
349
351{
354 if (!widget && !errorMessage.isEmpty()) {
355 // Display Script errors or message box
358 QMessageBox::Warning, QCoreApplication::translate("QDesignerFormBuilder", "Designer"),
360 return nullptr;
361 }
362 return widget;
363}
364
366{
368 if (!widget)
369 return QPixmap();
370
371 const QPixmap rc = widget->grab(QRect(0, 0, -1, -1));
373 return rc;
374}
375
376// ---------- NewFormWidgetFormBuilder
377
383
388
389} // namespace qdesigner_internal
390
391QT_END_NAMESPACE
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static bool readDomEnumerationValue(const DomProperty *p, const QDesignerPropertySheetExtension *sheet, QVariant &v)