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
63
70
98
100{
101 QWidget *widget = nullptr;
102
103 if (widgetName == "QToolBar"_L1) {
105 } else if (widgetName == "QMenu"_L1) {
107 } else if (widgetName == "QMenuBar"_L1) {
109 } else {
111 }
112
113 if (widget) {
117 }
118
119 if (m_mainWidget) { // We need to apply the DPI here to take effect on size hints, etc.
121 m_mainWidget = false;
122 }
123 return widget;
124}
125
127{
128 // Use container extension or rely on scripts unless main window.
130 return true;
131
134 return true;
135 }
136 return false;
137}
138
143
145{
148 qWarning() << "QDesignerFormBuilder::nameToIcon() is obsoleted";
149 return QIcon();
150}
151
153{
156 qWarning() << "QDesignerFormBuilder::nameToPixmap() is obsoleted";
157 return QPixmap();
158}
159
160/* If the property is a enum or flag value, retrieve
161 * the existing enum/flag type via property sheet and use it to convert */
162
163static bool readDomEnumerationValue(const DomProperty *p,
164 const QDesignerPropertySheetExtension* sheet,
165 QVariant &v)
166{
167 switch (p->kind()) {
168 case DomProperty::Set: {
169 const int index = sheet->indexOf(p->attributeName());
170 if (index == -1)
171 return false;
172 const QVariant sheetValue = sheet->property(index);
173 if (sheetValue.canConvert<PropertySheetFlagValue>()) {
174 const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(sheetValue);
175 bool ok = false;
176 v = f.metaFlags.parseFlags(p->elementSet(), &ok);
177 if (!ok)
178 designerWarning(f.metaFlags.messageParseFailed(p->elementSet()));
179 return true;
180 }
181 }
182 break;
183 case DomProperty::Enum: {
184 const int index = sheet->indexOf(p->attributeName());
185 if (index == -1)
186 return false;
187 const QVariant sheetValue = sheet->property(index);
188 if (sheetValue.canConvert<PropertySheetEnumValue>()) {
189 const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(sheetValue);
190 bool ok = false;
191 v = e.metaEnum.parseEnum(p->elementEnum(), &ok);
192 if (!ok)
193 designerWarning(e.metaEnum.messageParseFailed(p->elementEnum()));
194 return true;
195 }
196 }
197 break;
198 default:
199 break;
200 }
201 return false;
202}
203
205{
206 if (properties.isEmpty())
207 return;
208
211 const bool changingMetaObject = WidgetFactory::classNameOf(core(), o) == "QAxWidget"_L1;
214
217
223 }
224
225 for (DomProperty *p : properties) {
226 QVariant v;
228 v = toVariant(o->metaObject(), p);
229
230 if (v.isNull())
231 continue;
232
235 continue;
236
237 // refuse fake properties like current tab name (weak test)
239 if (changingMetaObject) // Changes after setting control of QAxWidget
242 continue;
243 }
244
245 QObject *obj = o;
247 if (scroll && attributeName == "cursor"_L1 && scroll->viewport())
248 obj = scroll->viewport();
249
250 // a real property
252 }
253}
254
261
263{
265 // Do not apply state if scripts are to be run in preview mode
267 return widget;
268}
269
285
290
295
297 const QString &styleName,
298 const QString &appStyleSheet,
301{
302 // load
305
307
310
311 QWidget *widget = builder.load(&buffer, nullptr);
312 if (!widget) { // Shouldn't happen
313 *errorMessage = QCoreApplication::translate("QDesignerFormBuilder", "The preview failed to build.");
314 return nullptr;
315 }
316 // Make sure palette is applied
318 if (!styleToUse.isEmpty()) {
320 if (styleToUse != wf->styleName())
322 }
323 }
324 // Fake application style sheet by prepending. (If this doesn't work, fake by nesting
325 // into parent widget).
326 if (!appStyleSheet.isEmpty())
328 return widget;
329}
330
335
343
345{
348 if (!widget && !errorMessage.isEmpty()) {
349 // Display Script errors or message box
352 QMessageBox::Warning, QCoreApplication::translate("QDesignerFormBuilder", "Designer"),
354 return nullptr;
355 }
356 return widget;
357}
358
360{
362 if (!widget)
363 return QPixmap();
364
365 const QPixmap rc = widget->grab(QRect(0, 0, -1, -1));
367 return rc;
368}
369
370// ---------- NewFormWidgetFormBuilder
371
377
382
383} // namespace qdesigner_internal
384
385QT_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)