1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef ABSTRACTFORMBUILDERPRIVATE_H
43 #define ABSTRACTFORMBUILDERPRIVATE_H
44 
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "uilib_global.h"
57 
58 #ifndef QT_FORMBUILDER_NO_SCRIPT
59 #    include "formscriptrunner_p.h"
60 #endif
61 
62 #include <QtCore/QHash>
63 #include <QtCore/QPointer>
64 #include <QtCore/QString>
65 
66 QT_BEGIN_NAMESPACE
67 
68 class QObject;
69 class QVariant;
70 class QWidget;
71 class QObject;
72 class QLabel;
73 class QButtonGroup;
74 
75 class QBoxLayout;
76 class QGridLayout;
77 
78 #ifdef QFORMINTERNAL_NAMESPACE
79 namespace QFormInternal
80 {
81 #endif
82 
83 class DomButtonGroups;
84 class DomButtonGroup;
85 class DomCustomWidget;
86 
87 class QAbstractFormBuilder;
88 class QResourceBuilder;
89 class QTextBuilder;
90 
91 class QDESIGNER_UILIB_EXPORT QFormBuilderExtra
92 {
93     QFormBuilderExtra();
94     ~QFormBuilderExtra();
95 public:
96     struct CustomWidgetData {
97         CustomWidgetData();
98         explicit CustomWidgetData(const DomCustomWidget *dc);
99 
100         QString addPageMethod;
101         QString script;
102         QString baseClass;
103         bool isContainer;
104     };
105 
106     void clear();
107 
108     bool applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value);
109 
110     enum BuddyMode { BuddyApplyAll, BuddyApplyVisibleOnly };
111 
112     void applyInternalProperties() const;
113     static bool applyBuddy(const QString &buddyName, BuddyMode applyMode, QLabel *label);
114 
115     const QPointer<QWidget> &parentWidget() const;
116     bool parentWidgetIsSet() const;
117     void setParentWidget(const QPointer<QWidget> &w);
118 
119 #ifndef QT_FORMBUILDER_NO_SCRIPT
120     QFormScriptRunner &formScriptRunner();
121     QString customWidgetScript(const QString &className) const;
122 #endif
123 
124     void setProcessingLayoutWidget(bool processing);
125     bool processingLayoutWidget() const;
126 
127     void setResourceBuilder(QResourceBuilder *builder);
128     QResourceBuilder *resourceBuilder() const;
129 
130     void setTextBuilder(QTextBuilder *builder);
131     QTextBuilder *textBuilder() const;
132 
133     static QFormBuilderExtra *instance(const QAbstractFormBuilder *afb);
134     static void removeInstance(const QAbstractFormBuilder *afb);
135 
136     void storeCustomWidgetData(const QString &className, const DomCustomWidget *d);
137     QString customWidgetAddPageMethod(const QString &className) const;
138     QString customWidgetBaseClass(const QString &className) const;
139     bool isCustomWidgetContainer(const QString &className) const;
140 
141     // --- Hash used in creating button groups on demand. Store a map of name and pair of dom group and real group
142     void registerButtonGroups(const DomButtonGroups *groups);
143 
144     typedef QPair<DomButtonGroup *, QButtonGroup*> ButtonGroupEntry;
145     typedef QHash<QString, ButtonGroupEntry> ButtonGroupHash;
buttonGroups()146     const ButtonGroupHash &buttonGroups() const { return m_buttonGroups; }
buttonGroups()147     ButtonGroupHash &buttonGroups()  { return m_buttonGroups; }
148 
149     // return stretch as a comma-separated list
150     static QString boxLayoutStretch(const QBoxLayout*);
151     // apply stretch
152     static bool setBoxLayoutStretch(const QString &, QBoxLayout*);
153     static void clearBoxLayoutStretch(QBoxLayout*);
154 
155     static QString gridLayoutRowStretch(const QGridLayout *);
156     static bool setGridLayoutRowStretch(const QString &, QGridLayout *);
157     static void clearGridLayoutRowStretch(QGridLayout *);
158 
159     static QString gridLayoutColumnStretch(const QGridLayout *);
160     static bool setGridLayoutColumnStretch(const QString &, QGridLayout *);
161     static void clearGridLayoutColumnStretch(QGridLayout *);
162 
163     // return the row/column sizes as  comma-separated lists
164     static QString gridLayoutRowMinimumHeight(const QGridLayout *);
165     static bool setGridLayoutRowMinimumHeight(const QString &, QGridLayout *);
166     static void clearGridLayoutRowMinimumHeight(QGridLayout *);
167 
168     static QString gridLayoutColumnMinimumWidth(const QGridLayout *);
169     static bool setGridLayoutColumnMinimumWidth(const QString &, QGridLayout *);
170     static void clearGridLayoutColumnMinimumWidth(QGridLayout *);
171 
172 private:
173     void clearResourceBuilder();
174     void clearTextBuilder();
175 
176     typedef QHash<QLabel*, QString> BuddyHash;
177     BuddyHash m_buddies;
178 
179 #ifndef QT_FORMBUILDER_NO_SCRIPT
180     QFormScriptRunner m_FormScriptRunner;
181 #endif
182 
183     QHash<QString, CustomWidgetData> m_customWidgetDataHash;
184 
185     ButtonGroupHash m_buttonGroups;
186 
187     bool m_layoutWidget;
188     QResourceBuilder *m_resourceBuilder;
189     QTextBuilder *m_textBuilder;
190 
191     QPointer<QWidget> m_parentWidget;
192     bool m_parentWidgetIsSet;
193 };
194 
195 void uiLibWarning(const QString &message);
196 
197 // Struct with static accessor that provides most strings used in the form builder.
198 struct QDESIGNER_UILIB_EXPORT QFormBuilderStrings {
199     QFormBuilderStrings();
200 
201     static const QFormBuilderStrings &instance();
202 
203     const QString buddyProperty;
204     const QString cursorProperty;
205     const QString objectNameProperty;
206     const QString trueValue;
207     const QString falseValue;
208     const QString horizontalPostFix;
209     const QString separator;
210     const QString defaultTitle;
211     const QString titleAttribute;
212     const QString labelAttribute;
213     const QString toolTipAttribute;
214     const QString whatsThisAttribute;
215     const QString flagsAttribute;
216     const QString iconAttribute;
217     const QString pixmapAttribute;
218     const QString textAttribute;
219     const QString currentIndexProperty;
220     const QString toolBarAreaAttribute;
221     const QString toolBarBreakAttribute;
222     const QString dockWidgetAreaAttribute;
223     const QString marginProperty;
224     const QString spacingProperty;
225     const QString leftMarginProperty;
226     const QString topMarginProperty;
227     const QString rightMarginProperty;
228     const QString bottomMarginProperty;
229     const QString horizontalSpacingProperty;
230     const QString verticalSpacingProperty;
231     const QString sizeHintProperty;
232     const QString sizeTypeProperty;
233     const QString orientationProperty;
234     const QString styleSheetProperty;
235     const QString qtHorizontal;
236     const QString qtVertical;
237     const QString currentRowProperty;
238     const QString tabSpacingProperty;
239     const QString qWidgetClass;
240     const QString lineClass;
241     const QString geometryProperty;
242     const QString scriptWidgetVariable;
243     const QString scriptChildWidgetsVariable;
244 
245     typedef QPair<Qt::ItemDataRole, QString> RoleNName;
246     QList<RoleNName> itemRoles;
247     QHash<QString, Qt::ItemDataRole> treeItemRoleHash;
248 
249     // first.first is primary role, first.second is shadow role.
250     // Shadow is used for either the translation source or the designer
251     // representation of the string value.
252     typedef QPair<QPair<Qt::ItemDataRole, Qt::ItemDataRole>, QString> TextRoleNName;
253     QList<TextRoleNName> itemTextRoles;
254     QHash<QString, QPair<Qt::ItemDataRole, Qt::ItemDataRole> > treeItemTextRoleHash;
255 };
256 #ifdef QFORMINTERNAL_NAMESPACE
257 }
258 #endif
259 
260 QT_END_NAMESPACE
261 
262 #endif // ABSTRACTFORMBUILDERPRIVATE_H
263