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 ABSTRACTFORMBUILDERPRIVATE_H
52#define ABSTRACTFORMBUILDERPRIVATE_H
53
54//
55// W A R N I N G
56// -------------
57//
58// This file is not part of the Qt API. It exists purely as an
59// implementation detail. This header file may change from version to
60// version without notice, or even be removed.
61//
62// We mean it.
63//
64
65#include "uilib_global.h"
66
67#include <QtCore/qhash.h>
68#include <QtCore/qpointer.h>
69#include <QtCore/qstringlist.h>
70#include <QtCore/qmap.h>
71#include <QtCore/qdir.h>
72#include <QtGui/qpalette.h>
73
74QT_BEGIN_NAMESPACE
75
76class QDesignerCustomWidgetInterface;
77class QObject;
78class QVariant;
79class QWidget;
80class QObject;
81class QLabel;
82class QButtonGroup;
83class QBoxLayout;
84class QGridLayout;
85class QAction;
86class QActionGroup;
87
88#ifdef QFORMINTERNAL_NAMESPACE
89namespace QFormInternal
90{
91#endif
92
93class DomBrush;
94class DomButtonGroups;
95class DomButtonGroup;
96class DomColorGroup;
97class DomCustomWidget;
98class DomPalette;
99class DomProperty;
100class DomUI;
101
102class QAbstractFormBuilder;
103class QResourceBuilder;
104class QTextBuilder;
105
106class QDESIGNER_UILIB_EXPORT QFormBuilderExtra
107{
108public:
109 QFormBuilderExtra();
110 ~QFormBuilderExtra();
111
112 struct CustomWidgetData {
113 CustomWidgetData();
114 explicit CustomWidgetData(const DomCustomWidget *dc);
115
116 QString addPageMethod;
117 QString script;
118 QString baseClass;
119 bool isContainer = false;
120 };
121
122 void clear();
123
124 DomUI *readUi(QIODevice *dev);
125 static QString msgInvalidUiFile();
126
127 bool applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value);
128
129 enum BuddyMode { BuddyApplyAll, BuddyApplyVisibleOnly };
130
131 void applyInternalProperties() const;
132 static bool applyBuddy(const QString &buddyName, BuddyMode applyMode, QLabel *label);
133
134 const QPointer<QWidget> &parentWidget() const;
135 bool parentWidgetIsSet() const;
136 void setParentWidget(const QPointer<QWidget> &w);
137
138 void setProcessingLayoutWidget(bool processing);
139 bool processingLayoutWidget() const;
140
141 void setResourceBuilder(QResourceBuilder *builder);
142 QResourceBuilder *resourceBuilder() const;
143
144 void setTextBuilder(QTextBuilder *builder);
145 QTextBuilder *textBuilder() const;
146
147 void storeCustomWidgetData(const QString &className, const DomCustomWidget *d);
148 QString customWidgetAddPageMethod(const QString &className) const;
149 QString customWidgetBaseClass(const QString &className) const;
150 bool isCustomWidgetContainer(const QString &className) const;
151
152 // --- Hash used in creating button groups on demand. Store a map of name and pair of dom group and real group
153 void registerButtonGroups(const DomButtonGroups *groups);
154
155 using ButtonGroupEntry = QPair<DomButtonGroup *, QButtonGroup*>;
156 using ButtonGroupHash = QHash<QString, ButtonGroupEntry>;
157 const ButtonGroupHash &buttonGroups() const { return m_buttonGroups; }
158 ButtonGroupHash &buttonGroups() { return m_buttonGroups; }
159
160 // return stretch as a comma-separated list
161 static QString boxLayoutStretch(const QBoxLayout*);
162 // apply stretch
163 static bool setBoxLayoutStretch(const QString &, QBoxLayout*);
164 static void clearBoxLayoutStretch(QBoxLayout*);
165
166 static QString gridLayoutRowStretch(const QGridLayout *);
167 static bool setGridLayoutRowStretch(const QString &, QGridLayout *);
168 static void clearGridLayoutRowStretch(QGridLayout *);
169
170 static QString gridLayoutColumnStretch(const QGridLayout *);
171 static bool setGridLayoutColumnStretch(const QString &, QGridLayout *);
172 static void clearGridLayoutColumnStretch(QGridLayout *);
173
174 // return the row/column sizes as comma-separated lists
175 static QString gridLayoutRowMinimumHeight(const QGridLayout *);
176 static bool setGridLayoutRowMinimumHeight(const QString &, QGridLayout *);
177 static void clearGridLayoutRowMinimumHeight(QGridLayout *);
178
179 static QString gridLayoutColumnMinimumWidth(const QGridLayout *);
180 static bool setGridLayoutColumnMinimumWidth(const QString &, QGridLayout *);
181 static void clearGridLayoutColumnMinimumWidth(QGridLayout *);
182
183 static void setPixmapProperty(DomProperty *p, const QPair<QString, QString> &ip);
184 static QPalette loadPalette(const DomPalette *dom);
185 static void setupColorGroup(QPalette *palette, QPalette::ColorGroup colorGroup,
186 const DomColorGroup *group);
187 static DomColorGroup *saveColorGroup(const QPalette &palette,
188 QPalette::ColorGroup colorGroup);
189 static DomPalette *savePalette(const QPalette &palette);
190 static QBrush setupBrush(const DomBrush *brush);
191 static DomBrush *saveBrush(const QBrush &br);
192
193 QStringList m_pluginPaths;
194 QMap<QString, QDesignerCustomWidgetInterface*> m_customWidgets;
195
196 QHash<QObject*, bool> m_laidout;
197 QHash<QString, QAction*> m_actions;
198 QHash<QString, QActionGroup*> m_actionGroups;
199 int m_defaultMargin;
200 int m_defaultSpacing;
201 QDir m_workingDirectory;
202 QString m_errorString;
203 QString m_language;
204
205private:
206 void clearResourceBuilder();
207 void clearTextBuilder();
208
209 using BuddyHash = QHash<QLabel*, QString>;
210 BuddyHash m_buddies;
211
212 QHash<QString, CustomWidgetData> m_customWidgetDataHash;
213
214 ButtonGroupHash m_buttonGroups;
215
216 bool m_layoutWidget = false;
217 QResourceBuilder *m_resourceBuilder = nullptr;
218 QTextBuilder *m_textBuilder = nullptr;
219
220 QPointer<QWidget> m_parentWidget;
221 bool m_parentWidgetIsSet = false;
222};
223
224void uiLibWarning(const QString &message);
225
226// Struct with static accessor that provides most strings used in the form builder.
227struct QDESIGNER_UILIB_EXPORT QFormBuilderStrings {
228 QFormBuilderStrings();
229
230 static const QFormBuilderStrings &instance();
231
232 const QString buddyProperty;
233 const QString cursorProperty;
234 const QString objectNameProperty;
235 const QString trueValue;
236 const QString falseValue;
237 const QString horizontalPostFix;
238 const QString separator;
239 const QString defaultTitle;
240 const QString titleAttribute;
241 const QString labelAttribute;
242 const QString toolTipAttribute;
243 const QString whatsThisAttribute;
244 const QString flagsAttribute;
245 const QString iconAttribute;
246 const QString pixmapAttribute;
247 const QString textAttribute;
248 const QString currentIndexProperty;
249 const QString toolBarAreaAttribute;
250 const QString toolBarBreakAttribute;
251 const QString dockWidgetAreaAttribute;
252 const QString marginProperty;
253 const QString spacingProperty;
254 const QString leftMarginProperty;
255 const QString topMarginProperty;
256 const QString rightMarginProperty;
257 const QString bottomMarginProperty;
258 const QString horizontalSpacingProperty;
259 const QString verticalSpacingProperty;
260 const QString sizeHintProperty;
261 const QString sizeTypeProperty;
262 const QString orientationProperty;
263 const QString styleSheetProperty;
264 const QString qtHorizontal;
265 const QString qtVertical;
266 const QString currentRowProperty;
267 const QString tabSpacingProperty;
268 const QString qWidgetClass;
269 const QString lineClass;
270 const QString geometryProperty;
271 const QString scriptWidgetVariable;
272 const QString scriptChildWidgetsVariable;
273
274 using RoleNName = QPair<Qt::ItemDataRole, QString>;
275 QList<RoleNName> itemRoles;
276 QHash<QString, Qt::ItemDataRole> treeItemRoleHash;
277
278 // first.first is primary role, first.second is shadow role.
279 // Shadow is used for either the translation source or the designer
280 // representation of the string value.
281 using TextRoleNName = QPair<QPair<Qt::ItemDataRole, Qt::ItemDataRole>, QString>;
282 QList<TextRoleNName> itemTextRoles;
283 QHash<QString, QPair<Qt::ItemDataRole, Qt::ItemDataRole> > treeItemTextRoleHash;
284};
285#ifdef QFORMINTERNAL_NAMESPACE
286}
287#endif
288
289QT_END_NAMESPACE
290
291#endif // ABSTRACTFORMBUILDERPRIVATE_H
292

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