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// Qt-Security score:significant reason:default
4
10
11#include <QtDesigner/private/ui4_p.h>
12#include <QtDesigner/private/formbuilderextra_p.h>
13// sdk
14#include <QtDesigner/container.h>
15#include <QtDesigner/propertysheet.h>
16#include <QtDesigner/qextensionmanager.h>
17#include <QtDesigner/abstractformeditor.h>
18#include <QtDesigner/abstractformwindow.h>
19#include <QtDesigner/abstractwidgetfactory.h>
20#include <abstractdialoggui_p.h>
21
22#include <QtUiPlugin/customwidget.h>
23
24// shared
25#include <qdesigner_propertysheet_p.h>
26#include <qdesigner_utils_p.h>
27#include <formwindowbase_p.h>
28#include <qtresourcemodel_p.h>
29
30#include <QtWidgets/qwidget.h>
31#include <QtWidgets/qmenu.h>
32#include <QtWidgets/qtoolbar.h>
33#include <QtWidgets/qmenubar.h>
34#include <QtWidgets/qmainwindow.h>
35#include <QtWidgets/qstylefactory.h>
36#include <QtWidgets/qstyle.h>
37#include <QtWidgets/qapplication.h>
38#include <QtWidgets/qabstractscrollarea.h>
39#include <QtWidgets/qmessagebox.h>
40#include <QtGui/qpixmap.h>
41
42#include <QtCore/qbuffer.h>
43#include <QtCore/qdebug.h>
44#include <QtCore/qcoreapplication.h>
45
47
48using namespace Qt::StringLiterals;
49
50namespace qdesigner_internal {
51
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
225 }
226
227 for (DomProperty *p : properties) {
228 QVariant v;
230 v = toVariant(o->metaObject(), p);
231
232 if (v.isNull())
233 continue;
234
237 continue;
238
239 // refuse fake properties like current tab name (weak test)
241 if (changingMetaObject) // Changes after setting control of QAxWidget
244 continue;
245 }
246
247 QObject *obj = o;
249 if (scroll && attributeName == "cursor"_L1 && scroll->viewport())
250 obj = scroll->viewport();
251
252 // a real property
254 }
255
259 }
260}
261
268
270{
272 // Do not apply state if scripts are to be run in preview mode
274 return widget;
275}
276
292
297
302
304 const QString &styleName,
305 const QString &appStyleSheet,
308{
309 // load
312
314
317
318 QWidget *widget = builder.load(&buffer, nullptr);
319 if (!widget) { // Shouldn't happen
320 *errorMessage = QCoreApplication::translate("QDesignerFormBuilder", "The preview failed to build.");
321 return nullptr;
322 }
323 // Make sure palette is applied
325 if (!styleToUse.isEmpty()) {
327 if (styleToUse != wf->styleName())
329 }
330 }
331 // Fake application style sheet by prepending. (If this doesn't work, fake by nesting
332 // into parent widget).
333 if (!appStyleSheet.isEmpty())
335 return widget;
336}
337
342
350
352{
355 if (!widget && !errorMessage.isEmpty()) {
356 // Display Script errors or message box
359 QMessageBox::Warning, QCoreApplication::translate("QDesignerFormBuilder", "Designer"),
361 return nullptr;
362 }
363 return widget;
364}
365
367{
369 if (!widget)
370 return QPixmap();
371
372 const QPixmap rc = widget->grab(QRect(0, 0, -1, -1));
374 return rc;
375}
376
377// ---------- NewFormWidgetFormBuilder
378
384
389
390} // namespace qdesigner_internal
391
392QT_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)