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_resource.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
5#include "formwindow.h"
8#include "iconloader_p.h"
20
21#include <QtDesigner/abstractformeditor.h>
22#include <QtDesigner/abstractintegration.h>
23#include <QtDesigner/private/ui4_p.h>
24#include <QtDesigner/private/formbuilderextra_p.h>
25#include <QtDesigner/private/resourcebuilder_p.h>
26#include <QtDesigner/private/textbuilder_p.h>
27#include <qdesigner_widgetitem_p.h>
28
29// shared
30#include <widgetdatabase_p.h>
31#include <metadatabase_p.h>
32#include <layout_p.h>
33#include <layoutinfo_p.h>
34#include <spacer_widget_p.h>
35#include <pluginmanager_p.h>
36#include <widgetfactory_p.h>
37#include <abstractlanguage.h>
38#include <abstractintrospection_p.h>
39
40#include <qlayout_widget_p.h>
41#include <qdesigner_utils_p.h>
42#include <QtDesigner/private/ui4_p.h>
43
44// sdk
45#include <QtDesigner/propertysheet.h>
46#include <QtDesigner/abstractformeditor.h>
47#include <QtDesigner/extrainfo.h>
48#include <QtDesigner/abstractformwindowtool.h>
49#include <QtDesigner/qextensionmanager.h>
50#include <QtDesigner/container.h>
51#include <abstractdialoggui_p.h>
52
53#include <QtWidgets/qmenu.h>
54#include <QtWidgets/qmessagebox.h>
55#include <QtWidgets/qlayout.h>
56#include <QtWidgets/qformlayout.h>
57#include <QtWidgets/qtabwidget.h>
58#include <QtWidgets/qtoolbox.h>
59#include <QtWidgets/qstackedwidget.h>
60#include <QtWidgets/qtoolbar.h>
61#include <QtWidgets/qtabbar.h>
62#include <QtWidgets/qbuttongroup.h>
63#include <QtWidgets/qapplication.h>
64#include <QtWidgets/qmainwindow.h>
65#include <QtWidgets/qsplitter.h>
66#include <QtWidgets/qmdiarea.h>
67#include <QtWidgets/qmenubar.h>
68#include <QtWidgets/qfiledialog.h>
69#include <QtWidgets/qheaderview.h>
70#include <QtWidgets/qwizard.h>
71#include <private/qlayoutengine_p.h>
72
73#include <QtGui/qaction.h>
74#include <QtGui/qactiongroup.h>
75
76#include <QtCore/qbuffer.h>
77#include <QtCore/qdir.h>
78#include <QtCore/qmetaobject.h>
79#include <QtCore/qdebug.h>
80#include <QtCore/qversionnumber.h>
81#include <QtCore/qxmlstream.h>
82
83#include <algorithm>
84#include <iterator>
85
86Q_DECLARE_METATYPE(QWidgetList)
87
88QT_BEGIN_NAMESPACE
89
90using namespace Qt::StringLiterals;
91
92using QFBE = QFormBuilderExtra;
93
94namespace {
95 using DomPropertyList = QList<DomProperty *>;
96}
97
98static constexpr auto currentUiVersion = "4.0"_L1;
99static constexpr auto clipboardObjectName = "__qt_fake_top_level"_L1;
100
101#define OLD_RESOURCE_FORMAT // Support pre 4.4 format.
102
103namespace qdesigner_internal {
104
105static bool supportsQualifiedEnums(const QVersionNumber &qtVersion)
106{
107 if (qtVersion >= QVersionNumber{6, 6, 2})
108 return true;
109
110 switch (qtVersion.majorVersion()) {
111 case 6: // Qt 6
112 switch (qtVersion.minorVersion()) {
113 case 5: // 6.5 LTS
114 if (qtVersion.microVersion() >= 4)
115 return true;
116 break;
117 case 2: // 6.2 LTS
118 if (qtVersion.microVersion() >= 13)
119 return true;
120 break;
121 }
122 break;
123
124 case 5: // Qt 5 LTS
125 if (qtVersion >= QVersionNumber{5, 15, 18})
126 return true;
127 break;
128 }
129 return false;
130}
131
132// -------------------- QDesignerResourceBuilder: A resource builder that works on the property sheet icon types.
134{
135public:
136 QDesignerResourceBuilder(QDesignerFormEditorInterface *core, DesignerPixmapCache *pixmapCache, DesignerIconCache *iconCache);
137
138 void setPixmapCache(DesignerPixmapCache *pixmapCache) { m_pixmapCache = pixmapCache; }
139 void setIconCache(DesignerIconCache *iconCache) { m_iconCache = iconCache; }
140 bool isSaveRelative() const { return m_saveRelative; }
141 void setSaveRelative(bool relative) { m_saveRelative = relative; }
142 QStringList usedQrcFiles() const { return m_usedQrcFiles.keys(); }
144 QStringList loadedQrcFiles() const { return m_loadedQrcFiles.keys(); } // needed only for loading old resource attribute of <iconset> tag.
145#endif
146
147 QVariant loadResource(const QDir &workingDirectory, const DomProperty *icon) const override;
148
149 QVariant toNativeValue(const QVariant &value) const override;
150
151 DomProperty *saveResource(const QDir &workingDirectory, const QVariant &value) const override;
152
153 bool isResourceType(const QVariant &value) const override;
154private:
155
156 QDesignerFormEditorInterface *m_core;
157 DesignerPixmapCache *m_pixmapCache;
158 DesignerIconCache *m_iconCache;
159 const QDesignerLanguageExtension *m_lang;
160 bool m_saveRelative;
161 mutable QMap<QString, bool> m_usedQrcFiles;
162 mutable QMap<QString, bool> m_loadedQrcFiles;
163};
164
165QDesignerResourceBuilder::QDesignerResourceBuilder(QDesignerFormEditorInterface *core, DesignerPixmapCache *pixmapCache, DesignerIconCache *iconCache) :
166 m_core(core),
167 m_pixmapCache(pixmapCache),
168 m_iconCache(iconCache),
169 m_lang(qt_extension<QDesignerLanguageExtension *>(core->extensionManager(), core)),
170 m_saveRelative(true)
171{
172}
173
174static inline void setIconPixmap(QIcon::Mode m, QIcon::State s, const QDir &workingDirectory,
175 QString path, PropertySheetIconValue &icon,
176 const QDesignerLanguageExtension *lang = nullptr)
177{
178 if (lang == nullptr || !lang->isLanguageResource(path))
179 path = QFileInfo(workingDirectory, path).absoluteFilePath();
180 icon.setPixmap(m, s, PropertySheetPixmapValue(path));
181}
182
183QVariant QDesignerResourceBuilder::loadResource(const QDir &workingDirectory, const DomProperty *property) const
184{
185 switch (property->kind()) {
186 case DomProperty::Pixmap: {
188 DomResourcePixmap *dp = property->elementPixmap();
189 if (!dp->text().isEmpty()) {
190 if (m_lang != nullptr && m_lang->isLanguageResource(dp->text())) {
191 pixmap.setPath(dp->text());
192 } else {
193 pixmap.setPath(QFileInfo(workingDirectory, dp->text()).absoluteFilePath());
194 }
196 if (dp->hasAttributeResource())
197 m_loadedQrcFiles.insert(QFileInfo(workingDirectory, dp->attributeResource()).absoluteFilePath(), false);
198#endif
199 }
200 return QVariant::fromValue(pixmap);
201 }
202
203 case DomProperty::IconSet: {
205 DomResourceIcon *di = property->elementIconSet();
206 const bool hasTheme = di->hasAttributeTheme();
207 if (hasTheme) {
208 const QString &theme = di->attributeTheme();
209 const qsizetype themeEnum = theme.startsWith("QIcon::"_L1)
210 ? QDesignerResourceBuilder::themeIconIndex(theme) : -1;
211 if (themeEnum != -1)
212 icon.setThemeEnum(themeEnum);
213 else
214 icon.setTheme(theme);
215 }
216 if (const int flags = iconStateFlags(di)) { // new, post 4.4 format
217 if (flags & NormalOff)
218 setIconPixmap(QIcon::Normal, QIcon::Off, workingDirectory, di->elementNormalOff()->text(), icon, m_lang);
219 if (flags & NormalOn)
220 setIconPixmap(QIcon::Normal, QIcon::On, workingDirectory, di->elementNormalOn()->text(), icon, m_lang);
221 if (flags & DisabledOff)
222 setIconPixmap(QIcon::Disabled, QIcon::Off, workingDirectory, di->elementDisabledOff()->text(), icon, m_lang);
223 if (flags & DisabledOn)
224 setIconPixmap(QIcon::Disabled, QIcon::On, workingDirectory, di->elementDisabledOn()->text(), icon, m_lang);
225 if (flags & ActiveOff)
226 setIconPixmap(QIcon::Active, QIcon::Off, workingDirectory, di->elementActiveOff()->text(), icon, m_lang);
227 if (flags & ActiveOn)
228 setIconPixmap(QIcon::Active, QIcon::On, workingDirectory, di->elementActiveOn()->text(), icon, m_lang);
229 if (flags & SelectedOff)
230 setIconPixmap(QIcon::Selected, QIcon::Off, workingDirectory, di->elementSelectedOff()->text(), icon, m_lang);
231 if (flags & SelectedOn)
232 setIconPixmap(QIcon::Selected, QIcon::On, workingDirectory, di->elementSelectedOn()->text(), icon, m_lang);
233 } else if (!hasTheme) {
235 setIconPixmap(QIcon::Normal, QIcon::Off, workingDirectory, di->text(), icon, m_lang);
236 if (di->hasAttributeResource())
237 m_loadedQrcFiles.insert(QFileInfo(workingDirectory, di->attributeResource()).absoluteFilePath(), false);
238#endif
239 }
240 return QVariant::fromValue(icon);
241 }
242 default:
243 break;
244 }
245 return QVariant();
246}
247
248QVariant QDesignerResourceBuilder::toNativeValue(const QVariant &value) const
249{
250 if (value.canConvert<PropertySheetPixmapValue>()) {
251 if (m_pixmapCache)
252 return m_pixmapCache->pixmap(qvariant_cast<PropertySheetPixmapValue>(value));
253 } else if (value.canConvert<PropertySheetIconValue>()) {
254 if (m_iconCache)
255 return m_iconCache->icon(qvariant_cast<PropertySheetIconValue>(value));
256 }
257 return value;
258}
259
260DomProperty *QDesignerResourceBuilder::saveResource(const QDir &workingDirectory, const QVariant &value) const
261{
262 DomProperty *p = new DomProperty;
263 if (value.canConvert<PropertySheetPixmapValue>()) {
264 const PropertySheetPixmapValue pix = qvariant_cast<PropertySheetPixmapValue>(value);
265 DomResourcePixmap *rp = new DomResourcePixmap;
266 const QString pixPath = pix.path();
267 switch (pix.pixmapSource(m_core)) {
268 case PropertySheetPixmapValue::LanguageResourcePixmap:
269 rp->setText(pixPath);
270 break;
271 case PropertySheetPixmapValue::ResourcePixmap: {
272 rp->setText(pixPath);
273 const QString qrcFile = m_core->resourceModel()->qrcPath(pixPath);
274 if (!qrcFile.isEmpty()) {
275 m_usedQrcFiles.insert(qrcFile, false);
276#ifdef OLD_RESOURCE_FORMAT // Legacy: Add qrc path
277 rp->setAttributeResource(workingDirectory.relativeFilePath(qrcFile));
278#endif
279 }
280 }
281 break;
282 case PropertySheetPixmapValue::FilePixmap:
283 rp->setText(m_saveRelative ? workingDirectory.relativeFilePath(pixPath) : pixPath);
284 break;
285 }
286 p->setElementPixmap(rp);
287 return p;
288 }
289 if (value.canConvert<PropertySheetIconValue>()) {
290 const PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(value);
291 const auto &pixmaps = icon.paths();
292 const int themeEnum = icon.themeEnum();
293 const QString theme = themeEnum != -1
294 ? QDesignerResourceBuilder::fullyQualifiedThemeIconName(themeEnum) : icon.theme();
295 if (!pixmaps.isEmpty() || !theme.isEmpty()) {
296 DomResourceIcon *ri = new DomResourceIcon;
297 if (!theme.isEmpty())
298 ri->setAttributeTheme(theme);
299 for (auto itPix = pixmaps.cbegin(), end = pixmaps.cend(); itPix != end; ++itPix) {
300 const QIcon::Mode mode = itPix.key().first;
301 const QIcon::State state = itPix.key().second;
302 DomResourcePixmap *rp = new DomResourcePixmap;
303 const PropertySheetPixmapValue &pix = itPix.value();
304 const PropertySheetPixmapValue::PixmapSource ps = pix.pixmapSource(m_core);
305 const QString pixPath = pix.path();
306 rp->setText(ps == PropertySheetPixmapValue::FilePixmap && m_saveRelative ? workingDirectory.relativeFilePath(pixPath) : pixPath);
307 if (state == QIcon::Off) {
308 switch (mode) {
309 case QIcon::Normal:
310 ri->setElementNormalOff(rp);
311#ifdef OLD_RESOURCE_FORMAT // Legacy: Set Normal off as text/path in old format.
312 ri->setText(rp->text());
313#endif
314 if (ps == PropertySheetPixmapValue::ResourcePixmap) {
315 // Be sure that ri->text() file comes from active resourceSet (i.e. make appropriate
316 // resourceSet active before calling this method).
317 const QString qrcFile = m_core->resourceModel()->qrcPath(ri->text());
318 if (!qrcFile.isEmpty()) {
319 m_usedQrcFiles.insert(qrcFile, false);
320#ifdef OLD_RESOURCE_FORMAT // Legacy: Set Normal off as text/path in old format.
321 ri->setAttributeResource(workingDirectory.relativeFilePath(qrcFile));
322#endif
323 }
324 }
325 break;
326 case QIcon::Disabled: ri->setElementDisabledOff(rp); break;
327 case QIcon::Active: ri->setElementActiveOff(rp); break;
328 case QIcon::Selected: ri->setElementSelectedOff(rp); break;
329 }
330 } else {
331 switch (mode) {
332 case QIcon::Normal: ri->setElementNormalOn(rp); break;
333 case QIcon::Disabled: ri->setElementDisabledOn(rp); break;
334 case QIcon::Active: ri->setElementActiveOn(rp); break;
335 case QIcon::Selected: ri->setElementSelectedOn(rp); break;
336 }
337 }
338 }
339 p->setElementIconSet(ri);
340 return p;
341 }
342 }
343 delete p;
344 return nullptr;
345}
346
347bool QDesignerResourceBuilder::isResourceType(const QVariant &value) const
348{
349 return value.canConvert<PropertySheetPixmapValue>()
350 || value.canConvert<PropertySheetIconValue>();
351}
352// ------------------------- QDesignerTextBuilder
353
354template <class DomElement> // for DomString, potentially DomStringList
355inline void translationParametersToDom(const PropertySheetTranslatableData &data, DomElement *e)
356{
357 const QString propertyComment = data.disambiguation();
358 if (!propertyComment.isEmpty())
359 e->setAttributeComment(propertyComment);
360 const QString propertyExtracomment = data.comment();
361 if (!propertyExtracomment.isEmpty())
362 e->setAttributeExtraComment(propertyExtracomment);
363 const QString &id = data.id();
364 if (!id.isEmpty())
365 e->setAttributeId(id);
366 if (!data.translatable())
367 e->setAttributeNotr(u"true"_s);
368}
369
370template <class DomElement> // for DomString, potentially DomStringList
371inline void translationParametersFromDom(const DomElement *e, PropertySheetTranslatableData *data)
372{
373 if (e->hasAttributeComment())
374 data->setDisambiguation(e->attributeComment());
375 if (e->hasAttributeExtraComment())
376 data->setComment(e->attributeExtraComment());
377 if (e->hasAttributeId())
378 data->setId(e->attributeId());
379 if (e->hasAttributeNotr()) {
380 const QString notr = e->attributeNotr();
381 const bool translatable = !(notr == "true"_L1 || notr == "yes"_L1);
382 data->setTranslatable(translatable);
383 }
384}
385
387{
388public:
390
391 QVariant loadText(const DomProperty *icon) const override;
392
393 QVariant toNativeValue(const QVariant &value) const override;
394
395 DomProperty *saveText(const QVariant &value) const override;
396};
397
398QVariant QDesignerTextBuilder::loadText(const DomProperty *text) const
399{
400 if (const DomString *domString = text->elementString()) {
401 PropertySheetStringValue stringValue(domString->text());
402 translationParametersFromDom(domString, &stringValue);
403 return QVariant::fromValue(stringValue);
404 }
405 return QVariant(QString());
406}
407
408QVariant QDesignerTextBuilder::toNativeValue(const QVariant &value) const
409{
410 if (value.canConvert<PropertySheetStringValue>())
411 return QVariant::fromValue(qvariant_cast<PropertySheetStringValue>(value).value());
412 return value;
413}
414
415static inline DomProperty *stringToDomProperty(const QString &value)
416{
417 DomString *domString = new DomString();
418 domString->setText(value);
419 DomProperty *property = new DomProperty();
420 property->setElementString(domString);
421 return property;
422}
423
424static inline DomProperty *stringToDomProperty(const QString &value,
425 const PropertySheetTranslatableData &translatableData)
426{
427 DomString *domString = new DomString();
428 domString->setText(value);
429 translationParametersToDom(translatableData, domString);
430 DomProperty *property = new DomProperty();
431 property->setElementString(domString);
432 return property;
433}
434
435DomProperty *QDesignerTextBuilder::saveText(const QVariant &value) const
436{
437 if (value.canConvert<PropertySheetStringValue>()) {
438 const PropertySheetStringValue str = qvariant_cast<PropertySheetStringValue>(value);
439 return stringToDomProperty(str.value(), str);
440 }
441 if (value.canConvert<QString>())
442 return stringToDomProperty(value.toString());
443 return nullptr;
444}
445
448 m_formWindow(formWindow),
449 m_copyWidget(false),
450 m_selected(nullptr),
451 m_resourceBuilder(new QDesignerResourceBuilder(m_formWindow->core(), m_formWindow->pixmapCache(), m_formWindow->iconCache()))
452{
453 // Check language unless extension present (Jambi)
454 QDesignerFormEditorInterface *core = m_formWindow->core();
455 if (const QDesignerLanguageExtension *le = qt_extension<QDesignerLanguageExtension*>(core->extensionManager(), core))
456 d->m_language = le->name();
457
458 setWorkingDirectory(formWindow->absoluteDir());
459 setResourceBuilder(m_resourceBuilder);
460 setTextBuilder(new QDesignerTextBuilder());
461
462 // ### generalise
463 const QString designerWidget = u"QDesignerWidget"_s;
464 const QString layoutWidget = u"QLayoutWidget"_s;
465 const QString widget = u"QWidget"_s;
466 m_internal_to_qt.insert(layoutWidget, widget);
467 m_internal_to_qt.insert(designerWidget, widget);
468 m_internal_to_qt.insert(u"QDesignerDialog"_s, u"QDialog"_s);
469 m_internal_to_qt.insert(u"QDesignerMenuBar"_s, u"QMenuBar"_s);
470 m_internal_to_qt.insert(u"QDesignerMenu"_s, u"QMenu"_s);
471 m_internal_to_qt.insert(u"QDesignerDockWidget"_s, u"QDockWidget"_s);
472
473 // invert
474 for (auto it = m_internal_to_qt.cbegin(), cend = m_internal_to_qt.cend(); it != cend; ++it ) {
475 if (it.value() != designerWidget && it.value() != layoutWidget)
476 m_qt_to_internal.insert(it.value(), it.key());
477
478 }
479}
480
482
483DomUI *QDesignerResource::readUi(QIODevice *dev)
484{
485 return d->readUi(dev);
486}
487
488static inline QString messageBoxTitle()
489{
490 return QApplication::translate("Designer", "Qt Widgets Designer");
491}
492
493void QDesignerResource::save(QIODevice *dev, QWidget *widget)
494{
495 // Do not write fully qualified enumerations for spacer/line orientations
496 // and other enum/flag properties for older Qt versions since that breaks
497 // older uic.
498 d->m_fullyQualifiedEnums = supportsQualifiedEnums(m_formWindow->core()->integration()->qtVersion());
499 QAbstractFormBuilder::save(dev, widget);
500}
501
502void QDesignerResource::saveDom(DomUI *ui, QWidget *widget)
503{
504 QAbstractFormBuilder::saveDom(ui, widget);
505
506 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), widget);
507 Q_ASSERT(sheet != nullptr);
508
509 const QVariant classVar = sheet->property(sheet->indexOf(u"objectName"_s));
510 QString classStr;
511 if (classVar.canConvert<QString>())
512 classStr = classVar.toString();
513 else
514 classStr = qvariant_cast<PropertySheetStringValue>(classVar).value();
515 ui->setElementClass(classStr);
516
517 for (int index = 0; index < m_formWindow->toolCount(); ++index) {
518 QDesignerFormWindowToolInterface *tool = m_formWindow->tool(index);
519 Q_ASSERT(tool != nullptr);
520 tool->saveToDom(ui, widget);
521 }
522
523 const QString author = m_formWindow->author();
524 if (!author.isEmpty()) {
525 ui->setElementAuthor(author);
526 }
527
528 const QString comment = m_formWindow->comment();
529 if (!comment.isEmpty()) {
530 ui->setElementComment(comment);
531 }
532
533 const QString exportMacro = m_formWindow->exportMacro();
534 if (!exportMacro.isEmpty()) {
535 ui->setElementExportMacro(exportMacro);
536 }
537
538 if (m_formWindow->useIdBasedTranslations())
539 ui->setAttributeIdbasedtr(true);
540 if (!m_formWindow->connectSlotsByName()) // Don't write out if true (default)
541 ui->setAttributeConnectslotsbyname(false);
542
543 const QVariantMap designerFormData = m_formWindow->formData();
544 if (!designerFormData.isEmpty()) {
545 DomPropertyList domPropertyList;
546 for (auto it = designerFormData.cbegin(), cend = designerFormData.cend(); it != cend; ++it) {
547 if (DomProperty *prop = variantToDomProperty(this, widget->metaObject(), it.key(), it.value()))
548 domPropertyList += prop;
549 }
550 if (!domPropertyList.isEmpty()) {
551 DomDesignerData* domDesignerFormData = new DomDesignerData;
552 domDesignerFormData->setElementProperty(domPropertyList);
553 ui->setElementDesignerdata(domDesignerFormData);
554 }
555 }
556
557 if (!m_formWindow->includeHints().isEmpty()) {
558 const QString local = u"local"_s;
559 const QString global = u"global"_s;
560 QList<DomInclude *> ui_includes;
561 const QStringList &includeHints = m_formWindow->includeHints();
562 ui_includes.reserve(includeHints.size());
563 for (QString includeHint : includeHints) {
564 if (includeHint.isEmpty())
565 continue;
566 DomInclude *incl = new DomInclude;
567 const QString location = includeHint.at(0) == u'<' ? global : local;
568 includeHint.remove(u'"');
569 includeHint.remove(u'<');
570 includeHint.remove(u'>');
571 incl->setAttributeLocation(location);
572 incl->setText(includeHint);
573 ui_includes.append(incl);
574 }
575
576 DomIncludes *includes = new DomIncludes;
577 includes->setElementInclude(ui_includes);
578 ui->setElementIncludes(includes);
579 }
580
581 int defaultMargin = INT_MIN, defaultSpacing = INT_MIN;
582 m_formWindow->layoutDefault(&defaultMargin, &defaultSpacing);
583
584 if (defaultMargin != INT_MIN || defaultSpacing != INT_MIN) {
585 DomLayoutDefault *def = new DomLayoutDefault;
586 if (defaultMargin != INT_MIN)
587 def->setAttributeMargin(defaultMargin);
588 if (defaultSpacing != INT_MIN)
589 def->setAttributeSpacing(defaultSpacing);
590 ui->setElementLayoutDefault(def);
591 }
592
593 QString marginFunction, spacingFunction;
594 m_formWindow->layoutFunction(&marginFunction, &spacingFunction);
595 if (!marginFunction.isEmpty() || !spacingFunction.isEmpty()) {
596 DomLayoutFunction *def = new DomLayoutFunction;
597
598 if (!marginFunction.isEmpty())
599 def->setAttributeMargin(marginFunction);
600 if (!spacingFunction.isEmpty())
601 def->setAttributeSpacing(spacingFunction);
602 ui->setElementLayoutFunction(def);
603 }
604
605 QString pixFunction = m_formWindow->pixmapFunction();
606 if (!pixFunction.isEmpty()) {
607 ui->setElementPixmapFunction(pixFunction);
608 }
609
610 if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core()->extensionManager(), core()))
611 extra->saveUiExtraInfo(ui);
612
613 if (MetaDataBase *metaDataBase = qobject_cast<MetaDataBase *>(core()->metaDataBase())) {
614 const MetaDataBaseItem *item = metaDataBase->metaDataBaseItem(m_formWindow->mainContainer());
615 const QStringList fakeSlots = item->fakeSlots();
616 const QStringList fakeSignals =item->fakeSignals();
617 if (!fakeSlots.isEmpty() || !fakeSignals.isEmpty()) {
618 DomSlots *domSlots = new DomSlots();
619 domSlots->setElementSlot(fakeSlots);
620 domSlots->setElementSignal(fakeSignals);
621 ui->setElementSlots(domSlots);
622 }
623 }
624}
625
626QWidget *QDesignerResource::load(QIODevice *dev, QWidget *parentWidget)
627{
628 QScopedPointer<DomUI> ui(readUi(dev));
629 return ui.isNull() ? nullptr : loadUi(ui.data(), parentWidget);
630}
631
632QWidget *QDesignerResource::loadUi(DomUI *ui, QWidget *parentWidget)
633{
634 QWidget *widget = create(ui, parentWidget);
635 // Store the class name as 'reset' value for the main container's object name.
636 if (widget)
637 widget->setProperty("_q_classname", widget->objectName());
638 else if (d->m_errorString.isEmpty())
639 d->m_errorString = QFormBuilderExtra::msgInvalidUiFile();
640 return widget;
641}
642
644{
645 return m_resourceBuilder->isSaveRelative();
646}
647
649{
650 m_resourceBuilder->setSaveRelative(relative);
651}
652
653QWidget *QDesignerResource::create(DomUI *ui, QWidget *parentWidget)
654{
655 // Load extra info extension. This is used by Jambi for preventing
656 // C++ UI files from being loaded
657 if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core()->extensionManager(), core())) {
658 if (!extra->loadUiExtraInfo(ui)) {
659 const QString errorMessage = QApplication::translate("Designer", "This file cannot be read because the extra info extension failed to load.");
660 core()->dialogGui()->message(parentWidget->window(), QDesignerDialogGuiInterface::FormLoadFailureMessage,
661 QMessageBox::Warning, messageBoxTitle(), errorMessage, QMessageBox::Ok);
662 return nullptr;
663 }
664 }
665
666 qdesigner_internal::WidgetFactory *factory = qobject_cast<qdesigner_internal::WidgetFactory*>(core()->widgetFactory());
667 Q_ASSERT(factory != nullptr);
668
669 QDesignerFormWindowInterface *previousFormWindow = factory->currentFormWindow(m_formWindow);
670
671 m_isMainWidget = true;
672 QDesignerWidgetItemInstaller wii; // Make sure we use QDesignerWidgetItem.
673 QWidget *mainWidget = QAbstractFormBuilder::create(ui, parentWidget);
674
675 if (m_formWindow) {
676 m_formWindow->setUseIdBasedTranslations(ui->attributeIdbasedtr());
677 // Default to true unless set.
678 const bool connectSlotsByName = !ui->hasAttributeConnectslotsbyname() || ui->attributeConnectslotsbyname();
679 m_formWindow->setConnectSlotsByName(connectSlotsByName);
680 }
681
682 if (mainWidget && m_formWindow) {
683 m_formWindow->setAuthor(ui->elementAuthor());
684 m_formWindow->setComment(ui->elementComment());
685 m_formWindow->setExportMacro(ui->elementExportMacro());
686
687 // Designer data
688 QVariantMap designerFormData;
689 if (ui->hasElementDesignerdata()) {
690 const DomPropertyList domPropertyList = ui->elementDesignerdata()->elementProperty();
691 for (auto *prop : domPropertyList) {
692 const QVariant vprop = domPropertyToVariant(this, mainWidget->metaObject(), prop);
693 if (vprop.metaType().id() != QMetaType::UnknownType)
694 designerFormData.insert(prop->attributeName(), vprop);
695 }
696 }
697 m_formWindow->setFormData(designerFormData);
698
699 m_formWindow->setPixmapFunction(ui->elementPixmapFunction());
700
701 if (DomLayoutDefault *def = ui->elementLayoutDefault()) {
702 m_formWindow->setLayoutDefault(def->attributeMargin(), def->attributeSpacing());
703 }
704
705 if (DomLayoutFunction *fun = ui->elementLayoutFunction()) {
706 m_formWindow->setLayoutFunction(fun->attributeMargin(), fun->attributeSpacing());
707 }
708
709 if (DomIncludes *includes = ui->elementIncludes()) {
710 const auto global = "global"_L1;
711 QStringList includeHints;
712 const auto &elementInclude = includes->elementInclude();
713 for (DomInclude *incl : elementInclude) {
714 QString text = incl->text();
715
716 if (text.isEmpty())
717 continue;
718
719 if (incl->hasAttributeLocation() && incl->attributeLocation() == global ) {
720 text.prepend(u'<');
721 text.append(u'>');
722 } else {
723 text.prepend(u'"');
724 text.append(u'"');
725 }
726
727 includeHints.append(text);
728 }
729
730 m_formWindow->setIncludeHints(includeHints);
731 }
732
733 // Register all button groups the form builder adds as children of the main container for them to be found
734 // in the signal slot editor
735 auto *mdb = core()->metaDataBase();
736 for (auto *child : mainWidget->children()) {
737 if (QButtonGroup *bg = qobject_cast<QButtonGroup*>(child))
738 mdb->add(bg);
739 }
740 // Load tools
741 for (int index = 0; index < m_formWindow->toolCount(); ++index) {
742 QDesignerFormWindowToolInterface *tool = m_formWindow->tool(index);
743 Q_ASSERT(tool != nullptr);
744 tool->loadFromDom(ui, mainWidget);
745 }
746 }
747
748 factory->currentFormWindow(previousFormWindow);
749
750 if (const DomSlots *domSlots = ui->elementSlots()) {
751 if (MetaDataBase *metaDataBase = qobject_cast<MetaDataBase *>(core()->metaDataBase())) {
752 QStringList fakeSlots;
753 QStringList fakeSignals;
754 if (addFakeMethods(domSlots, fakeSlots, fakeSignals)) {
755 MetaDataBaseItem *item = metaDataBase->metaDataBaseItem(mainWidget);
756 item->setFakeSlots(fakeSlots);
757 item->setFakeSignals(fakeSignals);
758 }
759 }
760 }
761 if (mainWidget) {
762 // Initialize the mainwindow geometry. Has it been explicitly specified?
763 bool hasExplicitGeometry = false;
764 const auto &properties = ui->elementWidget()->elementProperty();
765 if (!properties.isEmpty()) {
766 for (const DomProperty *p : properties) {
767 if (p->attributeName() == "geometry"_L1) {
768 hasExplicitGeometry = true;
769 break;
770 }
771 }
772 }
773 if (hasExplicitGeometry) {
774 // Geometry was specified explicitly: Verify that smartMinSize is respected
775 // (changed fonts, label wrapping policies, etc). This does not happen automatically in docked mode.
776 const QSize size = mainWidget->size();
777 const QSize minSize = size.expandedTo(qSmartMinSize(mainWidget));
778 if (minSize != size)
779 mainWidget->resize(minSize);
780 } else {
781 // No explicit Geometry: perform an adjustSize() to resize the form correctly before embedding it into a container
782 // (which might otherwise squeeze the form)
783 mainWidget->adjustSize();
784 }
785 // Some integration wizards create forms with main containers
786 // based on derived classes of QWidget and load them into Designer
787 // without the plugin existing. This will trigger the auto-promotion
788 // mechanism of Designer, which will set container=false for
789 // QWidgets. For the main container, force container=true and warn.
790 const QDesignerWidgetDataBaseInterface *wdb = core()->widgetDataBase();
791 const int wdbIndex = wdb->indexOfObject(mainWidget);
792 if (wdbIndex != -1) {
793 QDesignerWidgetDataBaseItemInterface *item = wdb->item(wdbIndex);
794 // Promoted main container that is not of container type
795 if (item->isPromoted() && !item->isContainer()) {
796 item->setContainer(true);
797 qWarning("** WARNING The form's main container is an unknown custom widget '%s'."
798 " Defaulting to a promoted instance of '%s', assuming container.",
799 item->name().toUtf8().constData(), item->extends().toUtf8().constData());
800 }
801 }
802 }
803 return mainWidget;
804}
805
806QWidget *QDesignerResource::create(DomWidget *ui_widget, QWidget *parentWidget)
807{
808 const QString className = ui_widget->attributeClass();
809 if (!m_isMainWidget && className == "QWidget"_L1
810 && !ui_widget->elementLayout().isEmpty()
811 && !ui_widget->hasAttributeNative()) {
812 // ### check if elementLayout.size() == 1
813
814 QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), parentWidget);
815
816 if (container == nullptr) {
817 // generate a QLayoutWidget iff the parent is not an QDesignerContainerExtension.
818 ui_widget->setAttributeClass(u"QLayoutWidget"_s);
819 }
820 }
821
822 // save the actions
823 const auto &actionRefs = ui_widget->elementAddAction();
824 ui_widget->setElementAddAction(QList<DomActionRef *>());
825
826 QWidget *w = QAbstractFormBuilder::create(ui_widget, parentWidget);
827
828 // restore the actions
829 ui_widget->setElementAddAction(actionRefs);
830
831 if (w == nullptr)
832 return nullptr;
833
834 // ### generalize using the extension manager
835 QDesignerMenu *menu = qobject_cast<QDesignerMenu*>(w);
836 QDesignerMenuBar *menuBar = qobject_cast<QDesignerMenuBar*>(w);
837
838 if (menu)
839 menu->hide();
840
841 for (DomActionRef *ui_action_ref : actionRefs) {
842 const QString name = ui_action_ref->attributeName();
843 if (name == "separator"_L1) {
844 QAction *sep = new QAction(w);
845 sep->setSeparator(true);
846 w->addAction(sep);
847 addMenuAction(sep);
848 } else if (QAction *a = d->m_actions.value(name)) {
849 w->addAction(a);
850 } else if (QActionGroup *g = d->m_actionGroups.value(name)) {
851 w->addActions(g->actions());
852 } else if (QMenu *menu = w->findChild<QMenu*>(name)) {
853 w->addAction(menu->menuAction());
854 addMenuAction(menu->menuAction());
855 }
856 }
857
858 if (menu)
859 menu->adjustSpecialActions();
860 else if (menuBar)
861 menuBar->adjustSpecialActions();
862
863 ui_widget->setAttributeClass(className); // fix the class name
864 applyExtensionDataFromDOM(this, core(), ui_widget, w);
865
866 return w;
867}
868
869QLayout *QDesignerResource::create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget)
870{
871 QLayout *l = QAbstractFormBuilder::create(ui_layout, layout, parentWidget);
872
873 if (QGridLayout *gridLayout = qobject_cast<QGridLayout*>(l)) {
874 QLayoutSupport::createEmptyCells(gridLayout);
875 } else {
876 if (QFormLayout *formLayout = qobject_cast<QFormLayout*>(l))
877 QLayoutSupport::createEmptyCells(formLayout);
878 }
879 // While the actual values are applied by the form builder, we still need
880 // to mark them as 'changed'.
882 return l;
883}
884
885QLayoutItem *QDesignerResource::create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget)
886{
887 if (ui_layoutItem->kind() == DomLayoutItem::Spacer) {
888 const DomSpacer *domSpacer = ui_layoutItem->elementSpacer();
889 Spacer *spacer = static_cast<Spacer*>(core()->widgetFactory()->createWidget(u"Spacer"_s, parentWidget));
890 if (domSpacer->hasAttributeName())
891 changeObjectName(spacer, domSpacer->attributeName());
892 core()->metaDataBase()->add(spacer);
893
894 spacer->setInteractiveMode(false);
895 applyProperties(spacer, ui_layoutItem->elementSpacer()->elementProperty());
896 spacer->setInteractiveMode(true);
897
898 if (m_formWindow) {
899 m_formWindow->manageWidget(spacer);
900 if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), spacer))
901 sheet->setChanged(sheet->indexOf(u"orientation"_s), true);
902 }
903
904 return new QWidgetItem(spacer);
905 }
906 if (ui_layoutItem->kind() == DomLayoutItem::Layout && parentWidget) {
907 DomLayout *ui_layout = ui_layoutItem->elementLayout();
908 QLayoutWidget *layoutWidget = new QLayoutWidget(m_formWindow, parentWidget);
909 core()->metaDataBase()->add(layoutWidget);
910 if (m_formWindow)
911 m_formWindow->manageWidget(layoutWidget);
912 (void) create(ui_layout, nullptr, layoutWidget);
913 return new QWidgetItem(layoutWidget);
914 }
915 return QAbstractFormBuilder::create(ui_layoutItem, layout, parentWidget);
916}
917
918void QDesignerResource::changeObjectName(QObject *o, QString objName)
919{
920 m_formWindow->unify(o, objName, true);
921 o->setObjectName(objName);
922
923}
924
925/* If the property is a enum or flag value, retrieve
926 * the existing enum/flag via property sheet and use it to convert */
927
928static bool readDomEnumerationValue(const DomProperty *p,
929 const QDesignerPropertySheetExtension* sheet, int index,
930 QVariant &v)
931{
932 switch (p->kind()) {
933 case DomProperty::Set: {
934 const QVariant sheetValue = sheet->property(index);
935 if (sheetValue.canConvert<PropertySheetFlagValue>()) {
936 const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(sheetValue);
937 bool ok = false;
938 v = f.metaFlags.parseFlags(p->elementSet(), &ok);
939 if (!ok)
940 designerWarning(f.metaFlags.messageParseFailed(p->elementSet()));
941 return true;
942 }
943 }
944 break;
945 case DomProperty::Enum: {
946 const QVariant sheetValue = sheet->property(index);
947 if (sheetValue.canConvert<PropertySheetEnumValue>()) {
948 const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(sheetValue);
949 bool ok = false;
950 v = e.metaEnum.parseEnum(p->elementEnum(), &ok);
951 if (!ok)
952 designerWarning(e.metaEnum.messageParseFailed(p->elementEnum()));
953 return true;
954 }
955 }
956 break;
957 default:
958 break;
959 }
960 return false;
961}
962
963// ### fixme Qt 7 remove this: Exclude deprecated properties of Qt 5.
964static bool isDeprecatedQt5Property(const QObject *o, const DomProperty *p)
965{
966 const QString &propertyName = p->attributeName();
967 switch (p->kind()) {
968 case DomProperty::Set:
969 if (propertyName == u"features" && o->inherits("QDockWidget")
970 && p->elementSet() == u"QDockWidget::AllDockWidgetFeatures") {
971 return true;
972 }
973 break;
974 case DomProperty::Enum:
975 if (propertyName == u"sizeAdjustPolicy" && o->inherits("QComboBox")
976 && p->elementEnum() == u"QComboBox::AdjustToMinimumContentsLength") {
977 return true;
978 }
979 break;
980 default:
981 break;
982 }
983 return false;
984}
985
986void QDesignerResource::applyProperties(QObject *o, const QList<DomProperty*> &properties)
987{
988 if (properties.isEmpty())
989 return;
990
991 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), o);
992 if (!sheet)
993 return;
994
995 QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), o);
996 const bool dynamicPropertiesAllowed = dynamicSheet && dynamicSheet->dynamicPropertiesAllowed();
997
998 for (DomProperty *p : properties) {
999 if (isDeprecatedQt5Property(o, p)) // ### fixme Qt 7 remove this
1000 continue; // ### fixme Qt 7 remove this: Exclude deprecated value of Qt 5.
1001 QString propertyName = p->attributeName();
1002 if (propertyName == "numDigits"_L1 && o->inherits("QLCDNumber")) // Deprecated in Qt 4, removed in Qt 5.
1003 propertyName = u"digitCount"_s;
1004 const int index = sheet->indexOf(propertyName);
1005 QVariant v;
1006 if (!readDomEnumerationValue(p, sheet, index, v))
1007 v = toVariant(o->metaObject(), p);
1008
1009 switch (p->kind()) {
1010 case DomProperty::String:
1011 if (index != -1 && sheet->property(index).userType() == qMetaTypeId<PropertySheetKeySequenceValue>()) {
1012 const DomString *key = p->elementString();
1013 PropertySheetKeySequenceValue keyVal(QKeySequence(key->text()));
1014 translationParametersFromDom(key, &keyVal);
1015 v = QVariant::fromValue(keyVal);
1016 } else {
1017 const DomString *str = p->elementString();
1018 PropertySheetStringValue strVal(v.toString());
1019 translationParametersFromDom(str, &strVal);
1020 v = QVariant::fromValue(strVal);
1021 }
1022 break;
1023 case DomProperty::StringList: {
1024 const DomStringList *list = p->elementStringList();
1025 PropertySheetStringListValue listValue(list->elementString());
1026 translationParametersFromDom(list, &listValue);
1027 v = QVariant::fromValue(listValue);
1028 }
1029 break;
1030 default:
1031 break;
1032 }
1033
1034 d->applyPropertyInternally(o, propertyName, v);
1035 if (index != -1) {
1036 sheet->setProperty(index, v);
1037 sheet->setChanged(index, true);
1038 } else if (dynamicPropertiesAllowed) {
1039 QVariant defaultValue = QVariant(v.metaType());
1040 bool isDefault = (v == defaultValue);
1041 if (v.canConvert<PropertySheetIconValue>()) {
1042 defaultValue = QVariant(QMetaType(QMetaType::QIcon));
1043 isDefault = (qvariant_cast<PropertySheetIconValue>(v) == PropertySheetIconValue());
1044 } else if (v.canConvert<PropertySheetPixmapValue>()) {
1045 defaultValue = QVariant(QMetaType(QMetaType::QPixmap));
1046 isDefault = (qvariant_cast<PropertySheetPixmapValue>(v) == PropertySheetPixmapValue());
1047 } else if (v.canConvert<PropertySheetStringValue>()) {
1048 defaultValue = QVariant(QMetaType(QMetaType::QString));
1049 isDefault = (qvariant_cast<PropertySheetStringValue>(v) == PropertySheetStringValue());
1050 } else if (v.canConvert<PropertySheetStringListValue>()) {
1051 defaultValue = QVariant(QMetaType(QMetaType::QStringList));
1052 isDefault = (qvariant_cast<PropertySheetStringListValue>(v) == PropertySheetStringListValue());
1053 } else if (v.canConvert<PropertySheetKeySequenceValue>()) {
1054 defaultValue = QVariant(QMetaType(QMetaType::QKeySequence));
1055 isDefault = (qvariant_cast<PropertySheetKeySequenceValue>(v) == PropertySheetKeySequenceValue());
1056 }
1057 if (defaultValue.metaType().id() != QMetaType::User) {
1058 const int idx = dynamicSheet->addDynamicProperty(p->attributeName(), defaultValue);
1059 if (idx != -1) {
1060 sheet->setProperty(idx, v);
1061 sheet->setChanged(idx, !isDefault);
1062 }
1063 }
1064 }
1065
1066 if (propertyName == "objectName"_L1)
1067 changeObjectName(o, o->objectName());
1068 }
1069}
1070
1071QWidget *QDesignerResource::createWidget(const QString &widgetName, QWidget *parentWidget, const QString &_name)
1072{
1073 QString name = _name;
1074 if (m_isMainWidget)
1075 m_isMainWidget = false;
1076
1077 QWidget *w = core()->widgetFactory()->createWidget(widgetName, parentWidget);
1078 if (!w)
1079 return nullptr;
1080
1081 if (name.isEmpty()) {
1082 QDesignerWidgetDataBaseInterface *db = core()->widgetDataBase();
1083 if (QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(w)))
1084 name = qtify(item->name());
1085 }
1086
1087 changeObjectName(w, name);
1088
1089 QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), parentWidget);
1090 if (!qobject_cast<QMenu*>(w) && (!parentWidget || !container)) {
1091 m_formWindow->manageWidget(w);
1092 if (parentWidget) {
1093 QWidgetList list = qvariant_cast<QWidgetList>(parentWidget->property("_q_widgetOrder"));
1094 list.append(w);
1095 parentWidget->setProperty("_q_widgetOrder", QVariant::fromValue(list));
1096 QWidgetList zOrder = qvariant_cast<QWidgetList>(parentWidget->property("_q_zOrder"));
1097 zOrder.append(w);
1098 parentWidget->setProperty("_q_zOrder", QVariant::fromValue(zOrder));
1099 }
1100 } else {
1101 core()->metaDataBase()->add(w);
1102 }
1103
1104 w->setWindowFlags(w->windowFlags() & ~Qt::Window);
1105 // Make sure it is non-modal (for example, KDialog calls setModal(true) in the constructor).
1106 w->setWindowModality(Qt::NonModal);
1107
1108 return w;
1109}
1110
1111QLayout *QDesignerResource::createLayout(const QString &layoutName, QObject *parent, const QString &name)
1112{
1113 QWidget *layoutBase = nullptr;
1114 QLayout *layout = qobject_cast<QLayout*>(parent);
1115
1116 if (parent->isWidgetType())
1117 layoutBase = static_cast<QWidget*>(parent);
1118 else {
1119 Q_ASSERT( layout != nullptr );
1120 layoutBase = layout->parentWidget();
1121 }
1122
1123 LayoutInfo::Type layoutType = LayoutInfo::layoutType(layoutName);
1124 if (layoutType == LayoutInfo::NoLayout) {
1125 designerWarning(QCoreApplication::translate("QDesignerResource", "The layout type '%1' is not supported, defaulting to grid.").arg(layoutName));
1126 layoutType = LayoutInfo::Grid;
1127 }
1128 QLayout *lay = core()->widgetFactory()->createLayout(layoutBase, layout, layoutType);
1129 if (lay != nullptr)
1130 changeObjectName(lay, name);
1131
1132 return lay;
1133}
1134
1135// save
1136DomWidget *QDesignerResource::createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive)
1137{
1138 QDesignerMetaDataBaseItemInterface *item = core()->metaDataBase()->item(widget);
1139 if (!item)
1140 return nullptr;
1141
1142 if (qobject_cast<Spacer*>(widget) && !m_copyWidget)
1143 return nullptr;
1144
1145 const QDesignerWidgetDataBaseInterface *wdb = core()->widgetDataBase();
1146 QDesignerWidgetDataBaseItemInterface *widgetInfo = nullptr;
1147 const int widgetInfoIndex = wdb->indexOfObject(widget, false);
1148 if (widgetInfoIndex != -1) {
1149 widgetInfo = wdb->item(widgetInfoIndex);
1150 // Recursively add all dependent custom widgets
1151 QDesignerWidgetDataBaseItemInterface *customInfo = widgetInfo;
1152 while (customInfo && customInfo->isCustom()) {
1153 m_usedCustomWidgets.insert(customInfo, true);
1154 const QString extends = customInfo->extends();
1155 if (extends == customInfo->name())
1156 break; // There are faulty files around that have name==extends
1157 const int extendsIndex = wdb->indexOfClassName(customInfo->extends());
1158 customInfo = extendsIndex != -1 ? wdb->item(extendsIndex) : nullptr;
1159 }
1160 }
1161
1162 DomWidget *w = nullptr;
1163
1164 if (QTabWidget *tabWidget = qobject_cast<QTabWidget*>(widget))
1165 w = saveWidget(tabWidget, ui_parentWidget);
1166 else if (QStackedWidget *stackedWidget = qobject_cast<QStackedWidget*>(widget))
1167 w = saveWidget(stackedWidget, ui_parentWidget);
1168 else if (QToolBox *toolBox = qobject_cast<QToolBox*>(widget))
1169 w = saveWidget(toolBox, ui_parentWidget);
1170 else if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget))
1171 w = saveWidget(toolBar, ui_parentWidget);
1172 else if (QDesignerDockWidget *dockWidget = qobject_cast<QDesignerDockWidget*>(widget))
1173 w = saveWidget(dockWidget, ui_parentWidget);
1174 else if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), widget))
1175 w = saveWidget(widget, container, ui_parentWidget);
1176 else if (QWizardPage *wizardPage = qobject_cast<QWizardPage*>(widget))
1177 w = saveWidget(wizardPage, ui_parentWidget);
1178 else
1179 w = QAbstractFormBuilder::createDom(widget, ui_parentWidget, recursive);
1180
1181 Q_ASSERT( w != nullptr );
1182
1183 if (!qobject_cast<QLayoutWidget*>(widget) && w->attributeClass() == "QWidget"_L1)
1184 w->setAttributeNative(true);
1185
1186 const QString className = w->attributeClass();
1187 if (m_internal_to_qt.contains(className))
1188 w->setAttributeClass(m_internal_to_qt.value(className));
1189
1190 if (isPromoted( core(), widget)) { // is promoted?
1191 Q_ASSERT(widgetInfo != nullptr);
1192
1193 w->setAttributeClass(widgetInfo->name());
1194
1195 const auto &prop_list = w->elementProperty();
1196 for (DomProperty *prop : prop_list) {
1197 if (prop->attributeName() == "geometry"_L1) {
1198 if (DomRect *rect = prop->elementRect()) {
1199 rect->setElementX(widget->x());
1200 rect->setElementY(widget->y());
1201 }
1202 break;
1203 }
1204 }
1205 } else if (widgetInfo != nullptr && m_usedCustomWidgets.contains(widgetInfo)) {
1206 if (widgetInfo->name() != w->attributeClass())
1207 w->setAttributeClass(widgetInfo->name());
1208 }
1209 addExtensionDataToDOM(this, core(), w, widget);
1210 return w;
1211}
1212
1213DomLayout *QDesignerResource::createDom(QLayout *layout, DomLayout *ui_parentLayout, DomWidget *ui_parentWidget)
1214{
1215 QDesignerMetaDataBaseItemInterface *item = core()->metaDataBase()->item(layout);
1216
1217 if (item == nullptr) {
1218 layout = layout->findChild<QLayout*>();
1219 // refresh the meta database item
1220 item = core()->metaDataBase()->item(layout);
1221 }
1222
1223 if (item == nullptr) {
1224 // nothing to do.
1225 return nullptr;
1226 }
1227
1228 if (qobject_cast<QSplitter*>(layout->parentWidget()) != 0) {
1229 // nothing to do.
1230 return nullptr;
1231 }
1232
1233 m_chain.push(layout);
1234
1235 DomLayout *l = QAbstractFormBuilder::createDom(layout, ui_parentLayout, ui_parentWidget);
1236 Q_ASSERT(l != nullptr);
1238
1239 m_chain.pop();
1240
1241 return l;
1242}
1243
1244DomLayoutItem *QDesignerResource::createDom(QLayoutItem *item, DomLayout *ui_layout, DomWidget *ui_parentWidget)
1245{
1246 DomLayoutItem *ui_item = nullptr;
1247
1248 if (Spacer *s = qobject_cast<Spacer*>(item->widget())) {
1249 if (!core()->metaDataBase()->item(s))
1250 return nullptr;
1251
1252 DomSpacer *spacer = new DomSpacer();
1253 const QString objectName = s->objectName();
1254 if (!objectName.isEmpty())
1255 spacer->setAttributeName(objectName);
1256 // ### filter the properties
1257 spacer->setElementProperty(computeProperties(item->widget()));
1258
1259 ui_item = new DomLayoutItem();
1260 ui_item->setElementSpacer(spacer);
1261 d->m_laidout.insert(item->widget(), true);
1262 } else if (QLayoutWidget *layoutWidget = qobject_cast<QLayoutWidget*>(item->widget())) {
1263 // Do not save a QLayoutWidget if it is within a layout (else it is saved as "QWidget"
1264 Q_ASSERT(layoutWidget->layout());
1265 DomLayout *l = createDom(layoutWidget->layout(), ui_layout, ui_parentWidget);
1266 ui_item = new DomLayoutItem();
1267 ui_item->setElementLayout(l);
1268 d->m_laidout.insert(item->widget(), true);
1269 } else if (!item->spacerItem()) { // we use spacer as fake item in the Designer
1270 ui_item = QAbstractFormBuilder::createDom(item, ui_layout, ui_parentWidget);
1271 } else {
1272 return nullptr;
1273 }
1274 return ui_item;
1275}
1276
1277void QDesignerResource::createCustomWidgets(DomCustomWidgets *dom_custom_widgets)
1278{
1279 QSimpleResource::handleDomCustomWidgets(core(), dom_custom_widgets);
1280}
1281
1283{
1284 QDesignerMetaDataBaseItemInterface *item = core()->metaDataBase()->item(m_formWindow);
1285 Q_ASSERT(item);
1286
1287 QStringList tabStops;
1288 const QWidgetList &tabOrder = item->tabOrder();
1289 for (QWidget *widget : tabOrder) {
1290 if (m_formWindow->mainContainer()->isAncestorOf(widget))
1291 tabStops.append(widget->objectName());
1292 }
1293
1294 if (!tabStops.isEmpty()) {
1295 DomTabStops *dom = new DomTabStops;
1296 dom->setElementTabStop(tabStops);
1297 return dom;
1298 }
1299
1300 return nullptr;
1301}
1302
1303void QDesignerResource::applyTabStops(QWidget *widget, DomTabStops *tabStops)
1304{
1305 if (tabStops == nullptr || widget == nullptr)
1306 return;
1307
1308 QWidgetList tabOrder;
1309 const QStringList &elementTabStop = tabStops->elementTabStop();
1310 for (const QString &widgetName : elementTabStop) {
1311 if (QWidget *w = widget->findChild<QWidget*>(widgetName)) {
1312 tabOrder.append(w);
1313 }
1314 }
1315
1316 QDesignerMetaDataBaseItemInterface *item = core()->metaDataBase()->item(m_formWindow);
1317 Q_ASSERT(item);
1318 item->setTabOrder(tabOrder);
1319}
1320
1321/* Unmanaged container pages occur when someone adds a page in a custom widget
1322 * constructor. They don't have a meta DB entry which causes createDom
1323 * to return 0. */
1324inline QString msgUnmanagedPage(QDesignerFormEditorInterface *core,
1325 QWidget *container, int index, QWidget *page)
1326{
1327 return QCoreApplication::translate("QDesignerResource",
1328"The container extension of the widget '%1' (%2) returned a widget not managed by Designer '%3' (%4) when queried for page #%5.\n"
1329"Container pages should only be added by specifying them in XML returned by the domXml() method of the custom widget.").
1330 arg(container->objectName(), WidgetFactory::classNameOf(core, container),
1331 page->objectName(), WidgetFactory::classNameOf(core, page)).
1332 arg(index);
1333}
1334
1335DomWidget *QDesignerResource::saveWidget(QWidget *widget, QDesignerContainerExtension *container, DomWidget *ui_parentWidget)
1336{
1337 DomWidget *ui_widget = QAbstractFormBuilder::createDom(widget, ui_parentWidget, false);
1338 QList<DomWidget *> ui_widget_list;
1339
1340 for (int i=0; i<container->count(); ++i) {
1341 QWidget *page = container->widget(i);
1342 Q_ASSERT(page);
1343
1344 if (DomWidget *ui_page = createDom(page, ui_widget)) {
1345 ui_widget_list.append(ui_page);
1346 } else {
1347 designerWarning(msgUnmanagedPage(core(), widget, i, page));
1348 }
1349 }
1350
1351 ui_widget->setElementWidget(ui_widget_list);
1352
1353 return ui_widget;
1354}
1355
1356DomWidget *QDesignerResource::saveWidget(QStackedWidget *widget, DomWidget *ui_parentWidget)
1357{
1358 DomWidget *ui_widget = QAbstractFormBuilder::createDom(widget, ui_parentWidget, false);
1359 QList<DomWidget *> ui_widget_list;
1360 if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), widget)) {
1361 for (int i=0; i<container->count(); ++i) {
1362 QWidget *page = container->widget(i);
1363 Q_ASSERT(page);
1364 if (DomWidget *ui_page = createDom(page, ui_widget)) {
1365 ui_widget_list.append(ui_page);
1366 } else {
1367 designerWarning(msgUnmanagedPage(core(), widget, i, page));
1368 }
1369 }
1370 }
1371
1372 ui_widget->setElementWidget(ui_widget_list);
1373
1374 return ui_widget;
1375}
1376
1377DomWidget *QDesignerResource::saveWidget(QToolBar *toolBar, DomWidget *ui_parentWidget)
1378{
1379 DomWidget *ui_widget = QAbstractFormBuilder::createDom(toolBar, ui_parentWidget, false);
1380 if (const QMainWindow *mainWindow = qobject_cast<QMainWindow*>(toolBar->parentWidget())) {
1381 const bool toolBarBreak = mainWindow->toolBarBreak(toolBar);
1382 const Qt::ToolBarArea area = mainWindow->toolBarArea(toolBar);
1383
1384 auto attributes = ui_widget->elementAttribute();
1385
1386 DomProperty *attr = new DomProperty();
1387 attr->setAttributeName(u"toolBarArea"_s);
1388 attr->setElementEnum(QLatin1StringView(toolBarAreaMetaEnum().valueToKey(area)));
1389 attributes << attr;
1390
1391 attr = new DomProperty();
1392 attr->setAttributeName(u"toolBarBreak"_s);
1393 attr->setElementBool(toolBarBreak ? u"true"_s : u"false"_s);
1394 attributes << attr;
1395 ui_widget->setElementAttribute(attributes);
1396 }
1397
1398 return ui_widget;
1399}
1400
1401DomWidget *QDesignerResource::saveWidget(QDesignerDockWidget *dockWidget, DomWidget *ui_parentWidget)
1402{
1403 DomWidget *ui_widget = QAbstractFormBuilder::createDom(dockWidget, ui_parentWidget, true);
1404 if (QMainWindow *mainWindow = qobject_cast<QMainWindow*>(dockWidget->parentWidget())) {
1405 const Qt::DockWidgetArea area = mainWindow->dockWidgetArea(dockWidget);
1406 DomProperty *attr = new DomProperty();
1407 attr->setAttributeName(u"dockWidgetArea"_s);
1408 attr->setElementNumber(int(area));
1409 ui_widget->setElementAttribute(ui_widget->elementAttribute() << attr);
1410 }
1411
1412 return ui_widget;
1413}
1414
1415DomWidget *QDesignerResource::saveWidget(QTabWidget *widget, DomWidget *ui_parentWidget)
1416{
1417 DomWidget *ui_widget = QAbstractFormBuilder::createDom(widget, ui_parentWidget, false);
1418 QList<DomWidget *> ui_widget_list;
1419
1420 if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), widget)) {
1421 const int current = widget->currentIndex();
1422 for (int i=0; i<container->count(); ++i) {
1423 QWidget *page = container->widget(i);
1424 Q_ASSERT(page);
1425
1426 DomWidget *ui_page = createDom(page, ui_widget);
1427 if (!ui_page) {
1428 designerWarning(msgUnmanagedPage(core(), widget, i, page));
1429 continue;
1430 }
1431 QList<DomProperty*> ui_attribute_list;
1432
1433 // attribute `icon'
1434 widget->setCurrentIndex(i);
1435 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), widget);
1436 PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(u"currentTabIcon"_s)));
1437 DomProperty *p = resourceBuilder()->saveResource(workingDirectory(), QVariant::fromValue(icon));
1438 if (p) {
1439 p->setAttributeName(QFormBuilderStrings::iconAttribute);
1440 ui_attribute_list.append(p);
1441 }
1442 // attribute `title'
1443 p = textBuilder()->saveText(sheet->property(sheet->indexOf(u"currentTabText"_s)));
1444 if (p) {
1445 p->setAttributeName(QFormBuilderStrings::titleAttribute);
1446 ui_attribute_list.append(p);
1447 }
1448
1449 // attribute `toolTip'
1450 QVariant v = sheet->property(sheet->indexOf(u"currentTabToolTip"_s));
1451 if (!qvariant_cast<PropertySheetStringValue>(v).value().isEmpty()) {
1452 p = textBuilder()->saveText(v);
1453 if (p) {
1454 p->setAttributeName(QFormBuilderStrings::toolTipAttribute);
1455 ui_attribute_list.append(p);
1456 }
1457 }
1458
1459 // attribute `whatsThis'
1460 v = sheet->property(sheet->indexOf(u"currentTabWhatsThis"_s));
1461 if (!qvariant_cast<PropertySheetStringValue>(v).value().isEmpty()) {
1462 p = textBuilder()->saveText(v);
1463 if (p) {
1464 p->setAttributeName(QFormBuilderStrings::whatsThisAttribute);
1465 ui_attribute_list.append(p);
1466 }
1467 }
1468
1469 ui_page->setElementAttribute(ui_attribute_list);
1470
1471 ui_widget_list.append(ui_page);
1472 }
1473 widget->setCurrentIndex(current);
1474 }
1475
1476 ui_widget->setElementWidget(ui_widget_list);
1477
1478 return ui_widget;
1479}
1480
1481DomWidget *QDesignerResource::saveWidget(QToolBox *widget, DomWidget *ui_parentWidget)
1482{
1483 DomWidget *ui_widget = QAbstractFormBuilder::createDom(widget, ui_parentWidget, false);
1484 QList<DomWidget *> ui_widget_list;
1485
1486 if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), widget)) {
1487 const int current = widget->currentIndex();
1488 for (int i=0; i<container->count(); ++i) {
1489 QWidget *page = container->widget(i);
1490 Q_ASSERT(page);
1491
1492 DomWidget *ui_page = createDom(page, ui_widget);
1493 if (!ui_page) {
1494 designerWarning(msgUnmanagedPage(core(), widget, i, page));
1495 continue;
1496 }
1497
1498 // attribute `label'
1499 QList<DomProperty*> ui_attribute_list;
1500
1501 // attribute `icon'
1502 widget->setCurrentIndex(i);
1503 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), widget);
1504 PropertySheetIconValue icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(u"currentItemIcon"_s)));
1505 DomProperty *p = resourceBuilder()->saveResource(workingDirectory(), QVariant::fromValue(icon));
1506 if (p) {
1507 p->setAttributeName(QFormBuilderStrings::iconAttribute);
1508 ui_attribute_list.append(p);
1509 }
1510 p = textBuilder()->saveText(sheet->property(sheet->indexOf(u"currentItemText"_s)));
1511 if (p) {
1512 p->setAttributeName(QFormBuilderStrings::labelAttribute);
1513 ui_attribute_list.append(p);
1514 }
1515
1516 // attribute `toolTip'
1517 QVariant v = sheet->property(sheet->indexOf(u"currentItemToolTip"_s));
1518 if (!qvariant_cast<PropertySheetStringValue>(v).value().isEmpty()) {
1519 p = textBuilder()->saveText(v);
1520 if (p) {
1521 p->setAttributeName(QFormBuilderStrings::toolTipAttribute);
1522 ui_attribute_list.append(p);
1523 }
1524 }
1525
1526 ui_page->setElementAttribute(ui_attribute_list);
1527
1528 ui_widget_list.append(ui_page);
1529 }
1530 widget->setCurrentIndex(current);
1531 }
1532
1533 ui_widget->setElementWidget(ui_widget_list);
1534
1535 return ui_widget;
1536}
1537
1538DomWidget *QDesignerResource::saveWidget(QWizardPage *wizardPage, DomWidget *ui_parentWidget)
1539{
1540 DomWidget *ui_widget = QAbstractFormBuilder::createDom(wizardPage, ui_parentWidget, true);
1541 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), wizardPage);
1542 // Save the page id (string) attribute, append to existing attributes
1543 const QString pageIdPropertyName = QLatin1StringView(QWizardPagePropertySheet::pageIdProperty);
1544 const int pageIdIndex = sheet->indexOf(pageIdPropertyName);
1545 if (pageIdIndex != -1 && sheet->isChanged(pageIdIndex)) {
1546 DomProperty *property = variantToDomProperty(this, wizardPage->metaObject(), pageIdPropertyName, sheet->property(pageIdIndex));
1547 Q_ASSERT(property);
1548 property->elementString()->setAttributeNotr(u"true"_s);
1549 DomPropertyList attributes = ui_widget->elementAttribute();
1550 attributes.push_back(property);
1551 ui_widget->setElementAttribute(attributes);
1552 }
1553 return ui_widget;
1554}
1555
1556// Do not save the 'currentTabName' properties of containers
1557static inline bool checkContainerProperty(const QWidget *w, const QString &propertyName)
1558{
1559 if (qobject_cast<const QToolBox *>(w))
1560 return QToolBoxWidgetPropertySheet::checkProperty(propertyName);
1561 if (qobject_cast<const QTabWidget *>(w))
1562 return QTabWidgetPropertySheet::checkProperty(propertyName);
1563 if (qobject_cast<const QStackedWidget *>(w))
1564 return QStackedWidgetPropertySheet::checkProperty(propertyName);
1565 if (qobject_cast<const QMdiArea *>(w))
1566 return QMdiAreaPropertySheet::checkProperty(propertyName);
1567 return true;
1568}
1569
1570bool QDesignerResource::checkProperty(QObject *obj, const QString &prop) const
1571{
1572 const QDesignerMetaObjectInterface *meta = core()->introspection()->metaObject(obj);
1573
1574 const int pindex = meta->indexOfProperty(prop);
1575 if (pindex != -1 && !meta->property(pindex)->attributes().testFlag(QDesignerMetaPropertyInterface::StoredAttribute))
1576 return false;
1577
1578 if (prop == "objectName"_L1 || prop == "spacerName"_L1) // ### don't store the property objectName
1579 return false;
1580
1581 QWidget *check_widget = nullptr;
1582 if (obj->isWidgetType())
1583 check_widget = static_cast<QWidget*>(obj);
1584
1585 if (check_widget && prop == "geometry"_L1) {
1586 if (check_widget == m_formWindow->mainContainer())
1587 return true; // Save although maincontainer is technically laid-out by embedding container
1588 if (m_selected && m_selected == check_widget)
1589 return true;
1590
1591 return !LayoutInfo::isWidgetLaidout(core(), check_widget);
1592 }
1593
1594 if (check_widget && !checkContainerProperty(check_widget, prop))
1595 return false;
1596
1597 if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), obj)) {
1598 QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), obj);
1599 const int pindex = sheet->indexOf(prop);
1600 if (sheet->isAttribute(pindex))
1601 return false;
1602
1603 if (!dynamicSheet || !dynamicSheet->isDynamicProperty(pindex))
1604 return sheet->isChanged(pindex);
1605 if (!sheet->isVisible(pindex))
1606 return false;
1607 return true;
1608 }
1609
1610 return false;
1611}
1612
1613bool QDesignerResource::addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout)
1614{
1615 if (item->widget() == nullptr) {
1616 return false;
1617 }
1618
1619 QGridLayout *grid = qobject_cast<QGridLayout*>(layout);
1620 QBoxLayout *box = qobject_cast<QBoxLayout*>(layout);
1621
1622 if (grid != nullptr) {
1623 const int rowSpan = ui_item->hasAttributeRowSpan() ? ui_item->attributeRowSpan() : 1;
1624 const int colSpan = ui_item->hasAttributeColSpan() ? ui_item->attributeColSpan() : 1;
1625 grid->addWidget(item->widget(), ui_item->attributeRow(), ui_item->attributeColumn(), rowSpan, colSpan, item->alignment());
1626 return true;
1627 }
1628 if (box != nullptr) {
1629 box->addItem(item);
1630 return true;
1631 }
1632
1633 return QAbstractFormBuilder::addItem(ui_item, item, layout);
1634}
1635
1636bool QDesignerResource::addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget)
1637{
1638 core()->metaDataBase()->add(widget); // ensure the widget is in the meta database
1639
1640 if (! QAbstractFormBuilder::addItem(ui_widget, widget, parentWidget) || qobject_cast<QMainWindow*> (parentWidget)) {
1641 if (QDesignerContainerExtension *container = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), parentWidget))
1642 container->addWidget(widget);
1643 }
1644
1645 if (QTabWidget *tabWidget = qobject_cast<QTabWidget*>(parentWidget)) {
1646 const int tabIndex = tabWidget->count() - 1;
1647 const int current = tabWidget->currentIndex();
1648
1649 tabWidget->setCurrentIndex(tabIndex);
1650
1651 const auto &attributes = ui_widget->elementAttribute();
1652 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), parentWidget);
1653 if (auto *picon = QFBE::propertyByName(attributes, QFormBuilderStrings::iconAttribute)) {
1654 QVariant v = resourceBuilder()->loadResource(workingDirectory(), picon);
1655 sheet->setProperty(sheet->indexOf(u"currentTabIcon"_s), v);
1656 }
1657 if (auto *ptext = QFBE::propertyByName(attributes, QFormBuilderStrings::titleAttribute)) {
1658 QVariant v = textBuilder()->loadText(ptext);
1659 sheet->setProperty(sheet->indexOf(u"currentTabText"_s), v);
1660 }
1661 if (auto *ptext = QFBE::propertyByName(attributes, QFormBuilderStrings::toolTipAttribute)) {
1662 QVariant v = textBuilder()->loadText(ptext);
1663 sheet->setProperty(sheet->indexOf(u"currentTabToolTip"_s), v);
1664 }
1665 if (auto *ptext = QFBE::propertyByName(attributes, QFormBuilderStrings::whatsThisAttribute)) {
1666 QVariant v = textBuilder()->loadText(ptext);
1667 sheet->setProperty(sheet->indexOf(u"currentTabWhatsThis"_s), v);
1668 }
1669 tabWidget->setCurrentIndex(current);
1670 } else if (QToolBox *toolBox = qobject_cast<QToolBox*>(parentWidget)) {
1671 const int itemIndex = toolBox->count() - 1;
1672 const int current = toolBox->currentIndex();
1673
1674 toolBox->setCurrentIndex(itemIndex);
1675
1676 const auto &attributes = ui_widget->elementAttribute();
1677 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), parentWidget);
1678 if (auto *picon = QFBE::propertyByName(attributes, QFormBuilderStrings::iconAttribute)) {
1679 QVariant v = resourceBuilder()->loadResource(workingDirectory(), picon);
1680 sheet->setProperty(sheet->indexOf(u"currentItemIcon"_s), v);
1681 }
1682 if (auto *ptext = QFBE::propertyByName(attributes, QFormBuilderStrings::labelAttribute)) {
1683 QVariant v = textBuilder()->loadText(ptext);
1684 sheet->setProperty(sheet->indexOf(u"currentItemText"_s), v);
1685 }
1686 if (auto *ptext = QFBE::propertyByName(attributes, QFormBuilderStrings::toolTipAttribute)) {
1687 QVariant v = textBuilder()->loadText(ptext);
1688 sheet->setProperty(sheet->indexOf(u"currentItemToolTip"_s), v);
1689 }
1690 toolBox->setCurrentIndex(current);
1691 }
1692
1693 return true;
1694}
1695
1696bool QDesignerResource::copy(QIODevice *dev, const FormBuilderClipboard &selection)
1697{
1698 m_copyWidget = true;
1699
1700 DomUI *ui = copy(selection);
1701
1702 d->m_laidout.clear();
1703 m_copyWidget = false;
1704
1705 if (!ui)
1706 return false;
1707
1708 QXmlStreamWriter writer(dev);
1709 writer.setAutoFormatting(true);
1710 writer.setAutoFormattingIndent(1);
1711 writer.writeStartDocument();
1712 ui->write(writer);
1713 writer.writeEndDocument();
1714 delete ui;
1715 return true;
1716}
1717
1718DomUI *QDesignerResource::copy(const FormBuilderClipboard &selection)
1719{
1720 if (selection.empty())
1721 return nullptr;
1722
1723 m_copyWidget = true;
1724
1725 DomWidget *ui_widget = new DomWidget();
1726 ui_widget->setAttributeName(clipboardObjectName);
1727 bool hasItems = false;
1728 // Widgets
1729 if (!selection.m_widgets.isEmpty()) {
1730 QList<DomWidget *> ui_widget_list;
1731 for (auto *w : selection.m_widgets) {
1732 m_selected = w;
1733 DomWidget *ui_child = createDom(w, ui_widget);
1734 m_selected = nullptr;
1735 if (ui_child)
1736 ui_widget_list.append(ui_child);
1737 }
1738 if (!ui_widget_list.isEmpty()) {
1739 ui_widget->setElementWidget(ui_widget_list);
1740 hasItems = true;
1741 }
1742 }
1743 // actions
1744 if (!selection.m_actions.isEmpty()) {
1745 QList<DomAction *> domActions;
1746 for (QAction* action : std::as_const(selection.m_actions)) {
1747 if (DomAction *domAction = createDom(action))
1748 domActions += domAction;
1749 }
1750 if (!domActions.isEmpty()) {
1751 ui_widget-> setElementAction(domActions);
1752 hasItems = true;
1753 }
1754 }
1755
1756 d->m_laidout.clear();
1757 m_copyWidget = false;
1758
1759 if (!hasItems) {
1760 delete ui_widget;
1761 return nullptr;
1762 }
1763 // UI
1764 DomUI *ui = new DomUI();
1765 ui->setAttributeVersion(currentUiVersion);
1766 ui->setElementWidget(ui_widget);
1767 ui->setElementResources(saveResources(m_resourceBuilder->usedQrcFiles()));
1768 if (DomCustomWidgets *cws = saveCustomWidgets())
1769 ui->setElementCustomWidgets(cws);
1770 return ui;
1771}
1772
1773FormBuilderClipboard QDesignerResource::paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent)
1774{
1775 QDesignerWidgetItemInstaller wii; // Make sure we use QDesignerWidgetItem.
1776 const int saved = m_isMainWidget;
1777 m_isMainWidget = false;
1778
1780
1781 // Widgets
1782 const DomWidget *topLevel = ui->elementWidget();
1783 initialize(ui);
1784 const auto &domWidgets = topLevel->elementWidget();
1785 if (!domWidgets.isEmpty()) {
1786 const QPoint offset = m_formWindow->grid();
1787 for (DomWidget* domWidget : domWidgets) {
1788 if (QWidget *w = create(domWidget, widgetParent)) {
1789 w->move(w->pos() + offset);
1790 // ### change the init properties of w
1791 rc.m_widgets.append(w);
1792 }
1793 }
1794 }
1795 const auto domActions = topLevel->elementAction();
1796 for (DomAction *domAction : domActions) {
1797 if (QAction *a = create(domAction, actionParent))
1798 rc.m_actions .append(a);
1799 }
1800
1801 m_isMainWidget = saved;
1802
1803 if (QDesignerExtraInfoExtension *extra = qt_extension<QDesignerExtraInfoExtension*>(core()->extensionManager(), core()))
1804 extra->loadUiExtraInfo(ui);
1805
1806 createResources(ui->elementResources());
1807
1808 return rc;
1809}
1810
1811FormBuilderClipboard QDesignerResource::paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent)
1812{
1813 DomUI ui;
1814 QXmlStreamReader reader(dev);
1815 bool uiInitialized = false;
1816
1817 while (!reader.atEnd()) {
1818 if (reader.readNext() == QXmlStreamReader::StartElement) {
1819 if (reader.name().compare("ui"_L1, Qt::CaseInsensitive)) {
1820 ui.read(reader);
1821 uiInitialized = true;
1822 } else {
1823 //: Parsing clipboard contents
1824 reader.raiseError(QCoreApplication::translate("QDesignerResource", "Unexpected element <%1>").arg(reader.name().toString()));
1825 }
1826 }
1827 }
1828 if (reader.hasError()) {
1829 //: Parsing clipboard contents
1830 designerWarning(QCoreApplication::translate("QDesignerResource", "Error while pasting clipboard contents at line %1, column %2: %3")
1831 .arg(reader.lineNumber()).arg(reader.columnNumber())
1832 .arg(reader.errorString()));
1833 uiInitialized = false;
1834 } else if (!uiInitialized) {
1835 //: Parsing clipboard contents
1836 designerWarning(QCoreApplication::translate("QDesignerResource", "Error while pasting clipboard contents: The root element <ui> is missing."));
1837 }
1838
1839 if (!uiInitialized)
1840 return FormBuilderClipboard();
1841
1842 FormBuilderClipboard clipBoard = paste(&ui, widgetParent, actionParent);
1843
1844 return clipBoard;
1845}
1846
1847void QDesignerResource::layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing)
1848{
1849 QAbstractFormBuilder::layoutInfo(layout, parent, margin, spacing);
1850}
1851
1853{
1854 if (m_usedCustomWidgets.isEmpty())
1855 return nullptr;
1856
1857 // We would like the list to be in order of the widget database indexes
1858 // to ensure that base classes come first (nice optics)
1859 QDesignerFormEditorInterface *core = m_formWindow->core();
1860 QDesignerWidgetDataBaseInterface *db = core->widgetDataBase();
1861 const bool isInternalWidgetDataBase = qobject_cast<const WidgetDataBase *>(db);
1862 QMap<int, DomCustomWidget *> orderedMap;
1863
1864 for (auto it = m_usedCustomWidgets.cbegin(), end = m_usedCustomWidgets.cend(); it != end; ++it) {
1865 QDesignerWidgetDataBaseItemInterface *item = it.key();
1866 const QString name = item->name();
1867 DomCustomWidget *custom_widget = new DomCustomWidget;
1868
1869 custom_widget->setElementClass(name);
1870 if (item->isContainer())
1871 custom_widget->setElementContainer(item->isContainer());
1872
1873 if (!item->includeFile().isEmpty()) {
1874 DomHeader *header = new DomHeader;
1875 const IncludeSpecification spec = includeSpecification(item->includeFile());
1876 header->setText(spec.first);
1877 if (spec.second == IncludeGlobal) {
1878 header->setAttributeLocation(u"global"_s);
1879 }
1880 custom_widget->setElementHeader(header);
1881 custom_widget->setElementExtends(item->extends());
1882 }
1883
1884 if (isInternalWidgetDataBase) {
1885 WidgetDataBaseItem *internalItem = static_cast<WidgetDataBaseItem *>(item);
1886 const QStringList fakeSlots = internalItem->fakeSlots();
1887 const QStringList fakeSignals = internalItem->fakeSignals();
1888 if (!fakeSlots.isEmpty() || !fakeSignals.isEmpty()) {
1889 DomSlots *domSlots = new DomSlots();
1890 domSlots->setElementSlot(fakeSlots);
1891 domSlots->setElementSignal(fakeSignals);
1892 custom_widget->setElementSlots(domSlots);
1893 }
1894 const QString addPageMethod = internalItem->addPageMethod();
1895 if (!addPageMethod.isEmpty())
1896 custom_widget->setElementAddPageMethod(addPageMethod);
1897 }
1898
1899 orderedMap.insert(db->indexOfClassName(name), custom_widget);
1900 }
1901
1902 DomCustomWidgets *customWidgets = new DomCustomWidgets;
1903 customWidgets->setElementCustomWidget(orderedMap.values().toVector());
1904 return customWidgets;
1905}
1906
1907bool QDesignerResource::canCompressSpacings(QObject *object) const
1908{
1909 if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), object)) {
1910 if (qobject_cast<QGridLayout *>(object)) {
1911 const int h = sheet->property(sheet->indexOf(u"horizontalSpacing"_s)).toInt();
1912 const int v = sheet->property(sheet->indexOf(u"verticalSpacing"_s)).toInt();
1913 if (h == v)
1914 return true;
1915 }
1916 }
1917 return false;
1918}
1919
1921{
1922 QList<DomProperty*> properties;
1923 if (QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), object)) {
1924 QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(core()->extensionManager(), object);
1925 const int count = sheet->count();
1926 QList<DomProperty *> spacingProperties;
1927 const bool compressSpacings = canCompressSpacings(object);
1928 for (int index = 0; index < count; ++index) {
1929 if (!sheet->isChanged(index) && (!dynamicSheet || !dynamicSheet->isDynamicProperty(index)))
1930 continue;
1931
1932 const QString propertyName = sheet->propertyName(index);
1933 // Suppress windowModality in legacy forms that have it set on child widgets
1934 if (propertyName == "windowModality"_L1 && !sheet->isVisible(index))
1935 continue;
1936
1937 const QVariant value = sheet->property(index);
1938 if (DomProperty *p = createProperty(object, propertyName, value)) {
1939 if (compressSpacings && (propertyName == "horizontalSpacing"_L1
1940 || propertyName == "verticalSpacing"_L1)) {
1941 spacingProperties.append(p);
1942 } else {
1943 properties.append(p);
1944 }
1945 }
1946 }
1947 if (compressSpacings) {
1948 if (spacingProperties.size() == 2) {
1949 DomProperty *spacingProperty = spacingProperties.at(0);
1950 spacingProperty->setAttributeName(u"spacing"_s);
1951 properties.append(spacingProperty);
1952 delete spacingProperties.at(1);
1953 } else {
1954 properties += spacingProperties;
1955 }
1956 }
1957 }
1958 return properties;
1959}
1960
1961DomProperty *QDesignerResource::applyProperStdSetAttribute(QObject *object, const QString &propertyName, DomProperty *property)
1962{
1963 if (!property)
1964 return nullptr;
1965
1966 QExtensionManager *mgr = core()->extensionManager();
1967 if (const QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(mgr, object)) {
1968 const QDesignerDynamicPropertySheetExtension *dynamicSheet = qt_extension<QDesignerDynamicPropertySheetExtension*>(mgr, object);
1969 const QDesignerPropertySheet *designerSheet = qobject_cast<QDesignerPropertySheet*>(core()->extensionManager()->extension(object, Q_TYPEID(QDesignerPropertySheetExtension)));
1970 const int index = sheet->indexOf(propertyName);
1971 if ((dynamicSheet && dynamicSheet->isDynamicProperty(index)) || (designerSheet && designerSheet->isDefaultDynamicProperty(index)))
1972 property->setAttributeStdset(0);
1973 }
1974 return property;
1975}
1976
1977// Optimistic check for a standard setter function
1978static inline bool hasSetter(QDesignerFormEditorInterface *core, QObject *object, const QString &propertyName)
1979{
1980 const QDesignerMetaObjectInterface *meta = core->introspection()->metaObject(object);
1981 const int pindex = meta->indexOfProperty(propertyName);
1982 if (pindex == -1)
1983 return true;
1984 return meta->property(pindex)->hasSetter();
1985}
1986
1987DomProperty *QDesignerResource::createProperty(QObject *object, const QString &propertyName, const QVariant &value)
1988{
1989 if (!checkProperty(object, propertyName)) {
1990 return nullptr;
1991 }
1992
1993 if (value.canConvert<PropertySheetFlagValue>()) {
1994 const PropertySheetFlagValue f = qvariant_cast<PropertySheetFlagValue>(value);
1995 const auto mode = d->m_fullyQualifiedEnums
1996 ? DesignerMetaFlags::FullyQualified : DesignerMetaFlags::Qualified;
1997 const QString flagString = f.metaFlags.toString(f.value, mode);
1998 if (flagString.isEmpty())
1999 return nullptr;
2000
2001 DomProperty *p = new DomProperty;
2002 // check if we have a standard cpp set function
2003 if (!hasSetter(core(), object, propertyName))
2004 p->setAttributeStdset(0);
2005 p->setAttributeName(propertyName);
2006 p->setElementSet(flagString);
2007 return applyProperStdSetAttribute(object, propertyName, p);
2008 }
2009 if (value.canConvert<PropertySheetEnumValue>()) {
2010 const PropertySheetEnumValue e = qvariant_cast<PropertySheetEnumValue>(value);
2011 const auto mode = d->m_fullyQualifiedEnums
2012 ? DesignerMetaEnum::FullyQualified : DesignerMetaEnum::Qualified;
2013 bool ok;
2014 const QString id = e.metaEnum.toString(e.value, mode, &ok);
2015 if (!ok)
2016 designerWarning(e.metaEnum.messageToStringFailed(e.value));
2017 if (id.isEmpty())
2018 return nullptr;
2019
2020 DomProperty *p = new DomProperty;
2021 // check if we have a standard cpp set function
2022 if (!hasSetter(core(), object, propertyName))
2023 p->setAttributeStdset(0);
2024 p->setAttributeName(propertyName);
2025 p->setElementEnum(id);
2026 return applyProperStdSetAttribute(object, propertyName, p);
2027 }
2028 if (value.canConvert<PropertySheetStringValue>()) {
2029 const PropertySheetStringValue strVal = qvariant_cast<PropertySheetStringValue>(value);
2030 DomProperty *p = stringToDomProperty(strVal.value(), strVal);
2031 if (!hasSetter(core(), object, propertyName))
2032 p->setAttributeStdset(0);
2033
2034 p->setAttributeName(propertyName);
2035
2036 return applyProperStdSetAttribute(object, propertyName, p);
2037 }
2038 if (value.canConvert<PropertySheetStringListValue>()) {
2039 const PropertySheetStringListValue listValue = qvariant_cast<PropertySheetStringListValue>(value);
2040 DomProperty *p = new DomProperty;
2041 if (!hasSetter(core(), object, propertyName))
2042 p->setAttributeStdset(0);
2043
2044 p->setAttributeName(propertyName);
2045
2046 DomStringList *domStringList = new DomStringList();
2047 domStringList->setElementString(listValue.value());
2048 translationParametersToDom(listValue, domStringList);
2049 p->setElementStringList(domStringList);
2050 return applyProperStdSetAttribute(object, propertyName, p);
2051 }
2052 if (value.canConvert<PropertySheetKeySequenceValue>()) {
2053 const PropertySheetKeySequenceValue keyVal = qvariant_cast<PropertySheetKeySequenceValue>(value);
2054 DomProperty *p = stringToDomProperty(keyVal.value().toString(), keyVal);
2055 if (!hasSetter(core(), object, propertyName))
2056 p->setAttributeStdset(0);
2057
2058 p->setAttributeName(propertyName);
2059
2060 return applyProperStdSetAttribute(object, propertyName, p);
2061 }
2062
2063 return applyProperStdSetAttribute(object, propertyName, QAbstractFormBuilder::createProperty(object, propertyName, value));
2064}
2065
2066QStringList QDesignerResource::mergeWithLoadedPaths(const QStringList &paths) const
2067{
2068 QStringList newPaths = paths;
2070 const QStringList loadedPaths = m_resourceBuilder->loadedQrcFiles();
2071 std::remove_copy_if(loadedPaths.cbegin(), loadedPaths.cend(),
2072 std::back_inserter(newPaths),
2073 [&newPaths] (const QString &path) { return newPaths.contains(path); });
2074#endif
2075 return newPaths;
2076}
2077
2078
2079void QDesignerResource::createResources(DomResources *resources)
2080{
2081 QStringList paths;
2082 if (resources != nullptr) {
2083 const auto &dom_include = resources->elementInclude();
2084 for (DomResource *res : dom_include) {
2085 QString path = QDir::cleanPath(m_formWindow->absoluteDir().absoluteFilePath(res->attributeLocation()));
2086 while (!QFile::exists(path)) {
2087 QWidget *dialogParent = m_formWindow->core()->topLevel();
2088 const QString promptTitle = QCoreApplication::translate("qdesigner_internal::QDesignerResource", "Loading qrc file");
2089 const QString prompt = QCoreApplication::translate("qdesigner_internal::QDesignerResource", "The specified qrc file <p><b>%1</b></p><p>could not be found. Do you want to update the file location?</p>").arg(path);
2090
2091 const QMessageBox::StandardButton answer = core()->dialogGui()->message(dialogParent, QDesignerDialogGuiInterface::ResourceLoadFailureMessage,
2092 QMessageBox::Warning, promptTitle, prompt, QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
2093 if (answer == QMessageBox::Yes) {
2094 const QFileInfo fi(path);
2095 const QString fileDialogTitle = QCoreApplication::translate("qdesigner_internal::QDesignerResource", "New location for %1").arg(fi.fileName());
2096 const QString fileDialogPattern = QCoreApplication::translate("qdesigner_internal::QDesignerResource", "Resource files (*.qrc)");
2097 path = core()->dialogGui()->getOpenFileName(dialogParent, fileDialogTitle, fi.absolutePath(), fileDialogPattern);
2098 if (path.isEmpty())
2099 break;
2100 m_formWindow->setProperty("_q_resourcepathchanged", QVariant(true));
2101 } else {
2102 break;
2103 }
2104 }
2105 if (!path.isEmpty()) {
2106 paths << path;
2107 m_formWindow->addResourceFile(path);
2108 }
2109 }
2110 }
2111
2113 paths = mergeWithLoadedPaths(paths);
2114#endif
2115
2116 QtResourceSet *resourceSet = m_formWindow->resourceSet();
2117 if (resourceSet) {
2118 QStringList newPaths = resourceSet->activeResourceFilePaths();
2119 std::remove_copy_if(paths.cbegin(), paths.cend(),
2120 std::back_inserter(newPaths),
2121 [&newPaths] (const QString &path) { return newPaths.contains(path); });
2122 resourceSet->activateResourceFilePaths(newPaths);
2123 } else {
2124 resourceSet = m_formWindow->core()->resourceModel()->addResourceSet(paths);
2125 m_formWindow->setResourceSet(resourceSet);
2126 QObject::connect(m_formWindow->core()->resourceModel(), &QtResourceModel::resourceSetActivated,
2127 m_formWindow, &FormWindowBase::resourceSetActivated);
2128 }
2129}
2130
2132{
2133 QStringList paths;
2134 switch (m_formWindow->resourceFileSaveMode()) {
2135 case QDesignerFormWindowInterface::SaveAllResourceFiles:
2136 paths = m_formWindow->activeResourceFilePaths();
2137 break;
2138 case QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles:
2139 paths = m_resourceBuilder->usedQrcFiles();
2140 break;
2141 case QDesignerFormWindowInterface::DontSaveResourceFiles:
2142 break;
2143 }
2144 return saveResources(paths);
2145}
2146
2147DomResources *QDesignerResource::saveResources(const QStringList &qrcPaths)
2148{
2149 QtResourceSet *resourceSet = m_formWindow->resourceSet();
2150 QList<DomResource *> dom_include;
2151 if (resourceSet) {
2152 const QStringList activePaths = resourceSet->activeResourceFilePaths();
2153 for (const QString &path : activePaths) {
2154 if (qrcPaths.contains(path)) {
2155 DomResource *dom_res = new DomResource;
2156 QString conv_path = path;
2157 if (m_resourceBuilder->isSaveRelative())
2158 conv_path = m_formWindow->absoluteDir().relativeFilePath(path);
2159 conv_path.replace(QDir::separator(), u'/');
2160 dom_res->setAttributeLocation(conv_path);
2161 dom_include.append(dom_res);
2162 }
2163 }
2164 }
2165
2166 DomResources *dom_resources = new DomResources;
2167 dom_resources->setElementInclude(dom_include);
2168
2169 return dom_resources;
2170}
2171
2172DomAction *QDesignerResource::createDom(QAction *action)
2173{
2174 if (!core()->metaDataBase()->item(action) || action->menu())
2175 return nullptr;
2176
2178}
2179
2180DomActionGroup *QDesignerResource::createDom(QActionGroup *actionGroup)
2181{
2182 if (core()->metaDataBase()->item(actionGroup) != nullptr) {
2183 return QAbstractFormBuilder::createDom(actionGroup);
2184 }
2185
2186 return nullptr;
2187}
2188
2189QAction *QDesignerResource::create(DomAction *ui_action, QObject *parent)
2190{
2191 if (QAction *action = QAbstractFormBuilder::create(ui_action, parent)) {
2192 core()->metaDataBase()->add(action);
2193 return action;
2194 }
2195
2196 return nullptr;
2197}
2198
2199QActionGroup *QDesignerResource::create(DomActionGroup *ui_action_group, QObject *parent)
2200{
2201 if (QActionGroup *actionGroup = QAbstractFormBuilder::create(ui_action_group, parent)) {
2202 core()->metaDataBase()->add(actionGroup);
2203 return actionGroup;
2204 }
2205
2206 return nullptr;
2207}
2208
2209DomActionRef *QDesignerResource::createActionRefDom(QAction *action)
2210{
2211 if (!core()->metaDataBase()->item(action)
2212 || (!action->isSeparator() && !action->menu() && action->objectName().isEmpty()))
2213 return nullptr;
2214
2216}
2217
2218void QDesignerResource::addMenuAction(QAction *action)
2219{
2220 core()->metaDataBase()->add(action);
2221}
2222
2223QAction *QDesignerResource::createAction(QObject *parent, const QString &name)
2224{
2225 if (QAction *action = QAbstractFormBuilder::createAction(parent, name)) {
2226 core()->metaDataBase()->add(action);
2227 return action;
2228 }
2229
2230 return nullptr;
2231}
2232
2233QActionGroup *QDesignerResource::createActionGroup(QObject *parent, const QString &name)
2234{
2235 if (QActionGroup *actionGroup = QAbstractFormBuilder::createActionGroup(parent, name)) {
2236 core()->metaDataBase()->add(actionGroup);
2237 return actionGroup;
2238 }
2239
2240 return nullptr;
2241}
2242
2243/* Apply the attributes to a widget via property sheet where appropriate,
2244 * that is, the sheet handles attributive fake properties */
2245void QDesignerResource::applyAttributesToPropertySheet(const DomWidget *ui_widget, QWidget *widget)
2246{
2247 const DomPropertyList attributes = ui_widget->elementAttribute();
2248 if (attributes.isEmpty())
2249 return;
2250 QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(m_formWindow->core()->extensionManager(), widget);
2251 for (auto *prop : attributes) {
2252 const QString name = prop->attributeName();
2253 const int index = sheet->indexOf(name);
2254 if (index == -1) {
2255 const QString msg = "Unable to apply attributive property '%1' to '%2'. It does not exist."_L1.arg(name, widget->objectName());
2256 designerWarning(msg);
2257 } else {
2258 sheet->setProperty(index, domPropertyToVariant(this, widget->metaObject(), prop));
2259 sheet->setChanged(index, true);
2260 }
2261 }
2262}
2263
2264void QDesignerResource::loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget)
2265{
2266 QAbstractFormBuilder::loadExtraInfo(ui_widget, widget, parentWidget);
2267 // Apply the page id attribute of a QWizardPage (which is an attributive fake property)
2268 if (qobject_cast<const QWizardPage*>(widget))
2269 applyAttributesToPropertySheet(ui_widget, widget);
2270}
2271
2272}
2273
2274QT_END_NAMESPACE
virtual bool dynamicPropertiesAllowed() const =0
virtual bool isDynamicProperty(int index) const =0
virtual bool isLanguageResource(const QString &path) const =0
friend class QWidget
Definition qpainter.h:421
QDesignerFormEditorInterface * core() const override
Returns a pointer to \QD's current QDesignerFormEditorInterface object.
void layoutDefault(int *margin, int *spacing) override
Fills in the default margin and spacing for the form's default layout in the margin and spacing varia...
QWidget * mainContainer() const override
Returns the main container widget for the form window.
void manageWidget(QWidget *w) override
Instructs the form window to manage the specified widget.
int toolCount() const override
Returns the number of tools available.
static void markChangedStretchProperties(QDesignerFormEditorInterface *core, QLayout *lt, const DomLayout *domLayout)
static void stretchAttributesToDom(QDesignerFormEditorInterface *core, QLayout *lt, DomLayout *domLayout)
QVariant toNativeValue(const QVariant &value) const override
bool isResourceType(const QVariant &value) const override
QVariant loadResource(const QDir &workingDirectory, const DomProperty *icon) const override
QDesignerResourceBuilder(QDesignerFormEditorInterface *core, DesignerPixmapCache *pixmapCache, DesignerIconCache *iconCache)
DomProperty * saveResource(const QDir &workingDirectory, const QVariant &value) const override
void setIconCache(DesignerIconCache *iconCache)
void setPixmapCache(DesignerPixmapCache *pixmapCache)
DomActionGroup * createDom(QActionGroup *actionGroup) override
QWidget * load(QIODevice *dev, QWidget *parentWidget) override
Loads an XML representation of a widget from the given device, and constructs a new widget with the s...
bool addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout) override
DomLayoutItem * createDom(QLayoutItem *item, DomLayout *ui_layout, DomWidget *ui_parentWidget) override
DomLayout * createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget) override
void applyProperties(QObject *o, const QList< DomProperty * > &properties) override
void createCustomWidgets(DomCustomWidgets *) override
QLayout * create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget) override
void applyTabStops(QWidget *widget, DomTabStops *tabStops) override
DomWidget * saveWidget(QToolBar *toolBar, DomWidget *ui_parentWidget)
DomCustomWidgets * saveCustomWidgets() override
DomWidget * saveWidget(QDesignerDockWidget *dockWidget, DomWidget *ui_parentWidget)
DomUI * copy(const FormBuilderClipboard &selection) override
QAction * create(DomAction *ui_action, QObject *parent) override
QActionGroup * create(DomActionGroup *ui_action_group, QObject *parent) override
DomWidget * saveWidget(QWizardPage *wizardPage, DomWidget *ui_parentWidget)
void saveDom(DomUI *ui, QWidget *widget) override
void createResources(DomResources *) override
void save(QIODevice *dev, QWidget *widget) override
Saves an XML representation of the given widget to the specified device in the standard UI file forma...
QLayoutItem * create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget) override
QWidget * create(DomUI *ui, QWidget *parentWidget) override
QWidget * loadUi(DomUI *ui, QWidget *parentWidget)
void loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override
DomWidget * createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive=true) override
DomWidget * saveWidget(QTabWidget *widget, DomWidget *ui_parentWidget)
DomWidget * saveWidget(QToolBox *widget, DomWidget *ui_parentWidget)
FormBuilderClipboard paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent=nullptr) override
DomWidget * saveWidget(QWidget *widget, QDesignerContainerExtension *container, DomWidget *ui_parentWidget)
bool addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override
void layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing) override
FormBuilderClipboard paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent=nullptr) override
QList< DomProperty * > computeProperties(QObject *obj) override
DomWidget * saveWidget(QStackedWidget *widget, DomWidget *ui_parentWidget)
QWidget * create(DomWidget *ui_widget, QWidget *parentWidget) override
bool copy(QIODevice *dev, const FormBuilderClipboard &selection) override
QVariant toNativeValue(const QVariant &value) const override
DomProperty * saveText(const QVariant &value) const override
QVariant loadText(const DomProperty *icon) const override
static bool checkProperty(const QString &propertyName)
Auxiliary methods to store/retrieve settings.
static QString messageBoxTitle()
static void setIconPixmap(QIcon::Mode m, QIcon::State s, const QDir &workingDirectory, QString path, PropertySheetIconValue &icon, const QDesignerLanguageExtension *lang=nullptr)
static DomProperty * stringToDomProperty(const QString &value, const PropertySheetTranslatableData &translatableData)
QString msgUnmanagedPage(QDesignerFormEditorInterface *core, QWidget *container, int index, QWidget *page)
static DomProperty * stringToDomProperty(const QString &value)
void translationParametersToDom(const PropertySheetTranslatableData &data, DomElement *e)
static bool supportsQualifiedEnums(const QVersionNumber &qtVersion)
static bool hasSetter(QDesignerFormEditorInterface *core, QObject *object, const QString &propertyName)
static bool isDeprecatedQt5Property(const QObject *o, const DomProperty *p)
static bool readDomEnumerationValue(const DomProperty *p, const QDesignerPropertySheetExtension *sheet, int index, QVariant &v)
static bool checkContainerProperty(const QWidget *w, const QString &propertyName)
void translationParametersFromDom(const DomElement *e, PropertySheetTranslatableData *data)
#define OLD_RESOURCE_FORMAT
static constexpr auto clipboardObjectName
static constexpr auto currentUiVersion