1/****************************************************************************
2**
3** Copyright (C) 2018 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** BSD License Usage
18** Alternatively, you may use this file under the terms of the BSD license
19** as follows:
20**
21** "Redistribution and use in source and binary forms, with or without
22** modification, are permitted provided that the following conditions are
23** met:
24** * Redistributions of source code must retain the above copyright
25** notice, this list of conditions and the following disclaimer.
26** * Redistributions in binary form must reproduce the above copyright
27** notice, this list of conditions and the following disclaimer in
28** the documentation and/or other materials provided with the
29** distribution.
30** * Neither the name of The Qt Company Ltd nor the names of its
31** contributors may be used to endorse or promote products derived
32** from this software without specific prior written permission.
33**
34**
35** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46**
47** $QT_END_LICENSE$
48**
49****************************************************************************/
50
51#ifndef ABSTRACTFORMBUILDER_H
52#define ABSTRACTFORMBUILDER_H
53
54#include "uilib_global.h"
55
56#include <QtCore/qlist.h>
57#include <QtCore/qhash.h>
58#include <QtCore/qdir.h>
59#include <QtCore/qscopedpointer.h>
60
61#include <QtWidgets/qsizepolicy.h>
62#include <QtGui/qpalette.h>
63
64QT_BEGIN_NAMESPACE
65#if 0
66// pragma for syncqt, don't remove.
67
68#pragma qt_class(QAbstractFormBuilder)
69#endif
70
71class QAction;
72class QButtonGroup;
73class QActionGroup;
74class QComboBox;
75class QIODevice;
76class QIcon;
77class QLayout;
78class QLayoutItem;
79class QListWidget;
80class QObject;
81class QSpacerItem;
82class QTreeWidget;
83class QTableWidget;
84class QVariant;
85class QWidget;
86class QAbstractButton;
87class QAbstractItemView;
88
89#ifdef QFORMINTERNAL_NAMESPACE
90namespace QFormInternal
91{
92#endif
93
94class DomAction;
95class DomActionGroup;
96class DomButtonGroup;
97class DomButtonGroups;
98class DomActionRef;
99class DomBrush;
100class DomColorGroup;
101class DomConnections;
102class DomCustomWidgets;
103class DomLayout;
104class DomLayoutItem;
105class DomProperty;
106class DomResources;
107class DomSpacer;
108class DomString;
109class DomTabStops;
110class DomUI;
111class DomWidget;
112class DomResourcePixmap;
113
114class QResourceBuilder;
115class QTextBuilder;
116class QFormBuilderExtra;
117
118class QDESIGNER_UILIB_EXPORT QAbstractFormBuilder
119{
120public:
121 Q_DISABLE_COPY(QAbstractFormBuilder)
122
123 QAbstractFormBuilder();
124 virtual ~QAbstractFormBuilder();
125
126 QDir workingDirectory() const;
127 void setWorkingDirectory(const QDir &directory);
128
129 virtual QWidget *load(QIODevice *dev, QWidget *parentWidget = nullptr);
130 virtual void save(QIODevice *dev, QWidget *widget);
131
132 QString errorString() const;
133
134protected:
135//
136// load
137//
138 virtual void loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget);
139
140 virtual QWidget *create(DomUI *ui, QWidget *parentWidget);
141 virtual QWidget *create(DomWidget *ui_widget, QWidget *parentWidget);
142 virtual QLayout *create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget);
143 virtual QLayoutItem *create(DomLayoutItem *ui_layoutItem, QLayout *layout, QWidget *parentWidget);
144
145 virtual QAction *create(DomAction *ui_action, QObject *parent);
146 virtual QActionGroup *create(DomActionGroup *ui_action_group, QObject *parent);
147 virtual void addMenuAction(QAction *action);
148
149 virtual void applyProperties(QObject *o, const QList<DomProperty*> &properties);
150 bool applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value);
151
152 virtual void applyTabStops(QWidget *widget, DomTabStops *tabStops);
153
154 virtual QWidget *createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name);
155 virtual QLayout *createLayout(const QString &layoutName, QObject *parent, const QString &name);
156 virtual QAction *createAction(QObject *parent, const QString &name);
157 virtual QActionGroup *createActionGroup(QObject *parent, const QString &name);
158
159 virtual void createCustomWidgets(DomCustomWidgets *) {}
160 virtual void createConnections(DomConnections *, QWidget *) {}
161 virtual void createResources(DomResources*) {}
162
163 virtual bool addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout);
164 virtual bool addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget);
165
166//
167// save
168//
169 virtual void saveExtraInfo(QWidget *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
170
171 virtual void saveDom(DomUI *ui, QWidget *widget);
172
173 virtual DomActionRef *createActionRefDom(QAction *action);
174
175 virtual DomWidget *createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive = true);
176 virtual DomLayout *createDom(QLayout *layout, DomLayout *ui_layout, DomWidget *ui_parentWidget);
177 virtual DomLayoutItem *createDom(QLayoutItem *item, DomLayout *ui_parentLayout, DomWidget *ui_parentWidget);
178 virtual DomSpacer *createDom(QSpacerItem *spacer, DomLayout *ui_parentLayout, DomWidget *ui_parentWidget);
179
180 virtual DomAction *createDom(QAction *action);
181 virtual DomActionGroup *createDom(QActionGroup *actionGroup);
182 DomButtonGroup *createDom(QButtonGroup *buttonGroup);
183
184 virtual DomConnections *saveConnections();
185 virtual DomCustomWidgets *saveCustomWidgets();
186 virtual DomTabStops *saveTabStops();
187 virtual DomResources *saveResources();
188 DomButtonGroups *saveButtonGroups(const QWidget *mainContainer);
189 virtual QList<DomProperty*> computeProperties(QObject *obj);
190 virtual bool checkProperty(QObject *obj, const QString &prop) const;
191 virtual DomProperty *createProperty(QObject *object, const QString &propertyName, const QVariant &value);
192
193 virtual void layoutInfo(DomLayout *layout, QObject *parent, int *margin, int *spacing);
194
195 void loadListWidgetExtraInfo(DomWidget *ui_widget, QListWidget *listWidget, QWidget *parentWidget);
196 void loadTreeWidgetExtraInfo(DomWidget *ui_widget, QTreeWidget *treeWidget, QWidget *parentWidget);
197 void loadTableWidgetExtraInfo(DomWidget *ui_widget, QTableWidget *tableWidget, QWidget *parentWidget);
198 void loadComboBoxExtraInfo(DomWidget *ui_widget, QComboBox *comboBox, QWidget *parentWidget);
199 void loadButtonExtraInfo(const DomWidget *ui_widget, QAbstractButton *button, QWidget *parentWidget);
200 void loadItemViewExtraInfo(DomWidget *ui_widget, QAbstractItemView *itemView, QWidget *parentWidget);
201
202 void saveListWidgetExtraInfo(QListWidget *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
203 void saveTreeWidgetExtraInfo(QTreeWidget *treeWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
204 void saveTableWidgetExtraInfo(QTableWidget *tablWidget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
205 void saveComboBoxExtraInfo(QComboBox *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
206 void saveButtonExtraInfo(const QAbstractButton *widget, DomWidget *ui_widget, DomWidget *ui_parentWidget);
207 void saveItemViewExtraInfo(const QAbstractItemView *itemView, DomWidget *ui_widget, DomWidget *ui_parentWidget);
208
209 void setResourceBuilder(QResourceBuilder *builder);
210 QResourceBuilder *resourceBuilder() const;
211 DomProperty *saveResource(const QVariant &v) const;
212
213 void setTextBuilder(QTextBuilder *builder);
214 QTextBuilder *textBuilder() const;
215 DomProperty *saveText(const QString &attributeName, const QVariant &v) const;
216//
217// utils
218//
219
220 QVariant toVariant(const QMetaObject *meta, DomProperty *property);
221 static QString toString(const DomString *str);
222
223 using DomPropertyHash = QHash<QString, DomProperty*>;
224 static DomPropertyHash propertyMap(const QList<DomProperty*> &properties);
225
226 void setupColorGroup(QPalette &palette, QPalette::ColorGroup colorGroup, DomColorGroup *group);
227 DomColorGroup *saveColorGroup(const QPalette &palette);
228 QBrush setupBrush(DomBrush *brush);
229 DomBrush *saveBrush(const QBrush &brush);
230
231 void reset();
232 void initialize(const DomUI *ui);
233
234//
235// utils
236//
237
238 static QMetaEnum toolBarAreaMetaEnum();
239
240//
241// Icon/pixmap stuff
242//
243 // A Pair of icon path/qrc path.
244 using IconPaths = QPair<QString, QString>;
245
246 void setIconProperty(DomProperty &, const IconPaths &) const;
247 void setPixmapProperty(DomProperty &, const IconPaths &) const;
248
249 static const DomResourcePixmap *domPixmap(const DomProperty* p);
250
251#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
252 IconPaths iconPaths(const QIcon &) const;
253 IconPaths pixmapPaths(const QPixmap &) const;
254 DomProperty* iconToDomProperty(const QIcon &) const;
255 QIcon domPropertyToIcon(const DomResourcePixmap *);
256 QIcon domPropertyToIcon(const DomProperty* p);
257 QPixmap domPropertyToPixmap(const DomResourcePixmap* p);
258 QPixmap domPropertyToPixmap(const DomProperty* p);
259#endif
260
261private:
262//
263// utils
264//
265 static Qt::ToolBarArea toolbarAreaFromDOMAttributes(const DomPropertyHash &attributeMap);
266
267 friend QDESIGNER_UILIB_EXPORT DomProperty *variantToDomProperty(QAbstractFormBuilder *abstractFormBuilder, const QMetaObject *meta, const QString &propertyName, const QVariant &value);
268 friend QDESIGNER_UILIB_EXPORT QVariant domPropertyToVariant(QAbstractFormBuilder *abstractFormBuilder,const QMetaObject *meta, const DomProperty *property);
269
270protected:
271 QScopedPointer<QFormBuilderExtra> d;
272};
273
274#ifdef QFORMINTERNAL_NAMESPACE
275}
276#endif
277
278QT_END_NAMESPACE
279
280#endif // ABSTRACTFORMBUILDER_H
281

source code of qttools/src/designer/src/lib/uilib/abstractformbuilder.h