1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef UI3READER_H
|
---|
43 | #define UI3READER_H
|
---|
44 |
|
---|
45 | #include <QDomDocument>
|
---|
46 | #include <QString>
|
---|
47 | #include <QStringList>
|
---|
48 | #include <QMap>
|
---|
49 | #include <QTextStream>
|
---|
50 | #include <QVariant>
|
---|
51 | #include <QByteArray>
|
---|
52 | #include <QPair>
|
---|
53 |
|
---|
54 | QT_BEGIN_NAMESPACE
|
---|
55 |
|
---|
56 | class DomUI;
|
---|
57 | class DomFont;
|
---|
58 | class DomWidget;
|
---|
59 | class DomProperty;
|
---|
60 | class DomLayout;
|
---|
61 | class DomLayoutItem;
|
---|
62 | class DomActionGroup;
|
---|
63 | class Porting;
|
---|
64 | struct Color;
|
---|
65 |
|
---|
66 | typedef QList<QPair<int, Color> > ColorGroup;
|
---|
67 |
|
---|
68 | class Ui3Reader
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | enum Options { CustomWidgetForwardDeclarations = 0x1, ImplicitIncludes = 0x2,
|
---|
72 | PreserveLayoutNames = 0x4, LimitXPM_LineLength = 0x8 };
|
---|
73 |
|
---|
74 | explicit Ui3Reader(QTextStream &stream, unsigned options);
|
---|
75 | ~Ui3Reader();
|
---|
76 |
|
---|
77 | void computeDeps(const QDomElement &e, QStringList &globalIncludes, QStringList &localIncludes, bool impl = false);
|
---|
78 | void generateUi4(const QString &fn, const QString &outputFn, QDomDocument doc);
|
---|
79 |
|
---|
80 | void generate(const QString &fn, const QString &outputFn,
|
---|
81 | QDomDocument doc, bool decl, bool subcl, const QString &trm,
|
---|
82 | const QString& subclname, const QString &convertedUiFile);
|
---|
83 |
|
---|
84 | void embed(const char *project, const QStringList &images);
|
---|
85 |
|
---|
86 | void setTrMacro(const QString &trmacro);
|
---|
87 | void setOutputFileName(const QString &fileName);
|
---|
88 |
|
---|
89 | void createFormDecl(const QDomElement &e);
|
---|
90 | void createFormImpl(const QDomElement &e);
|
---|
91 |
|
---|
92 | void createWrapperDecl(const QDomElement &e, const QString &convertedUiFile);
|
---|
93 |
|
---|
94 | void createSubDecl(const QDomElement &e, const QString& subclname);
|
---|
95 | void createSubImpl(const QDomElement &e, const QString& subclname);
|
---|
96 |
|
---|
97 | void createColorGroupImpl(const QString& cg, const QDomElement& e);
|
---|
98 | ColorGroup loadColorGroup(const QDomElement &e);
|
---|
99 |
|
---|
100 | QDomElement getObjectProperty(const QDomElement& e, const QString& name);
|
---|
101 | QString getPixmapLoaderFunction(const QDomElement& e);
|
---|
102 | QString getFormClassName(const QDomElement& e);
|
---|
103 | QString getClassName(const QDomElement& e);
|
---|
104 | QString getObjectName(const QDomElement& e);
|
---|
105 | QString getLayoutName(const QDomElement& e);
|
---|
106 |
|
---|
107 | QString registerObject(const QString& name);
|
---|
108 | QString registeredName(const QString& name);
|
---|
109 | bool isObjectRegistered(const QString& name);
|
---|
110 | QStringList unique(const QStringList&);
|
---|
111 |
|
---|
112 | QString trcall(const QString& sourceText, const QString& comment = QString());
|
---|
113 |
|
---|
114 | QDomElement parse(const QDomDocument &doc);
|
---|
115 |
|
---|
116 | void setExtractImages(bool extract, const QString &qrcOutputFile);
|
---|
117 |
|
---|
118 | private:
|
---|
119 | void init();
|
---|
120 |
|
---|
121 | void createWrapperDeclContents(const QDomElement &e);
|
---|
122 |
|
---|
123 | void errorInvalidProperty(const QString &propertyName, const QString &widgetName, const QString &widgetClass,
|
---|
124 | int line, int col);
|
---|
125 | void errorInvalidSignal(const QString &signal, const QString &widgetName, const QString &widgetClass,
|
---|
126 | int line, int col);
|
---|
127 | void errorInvalidSlot(const QString &slot, const QString &widgetName, const QString &widgetClass,
|
---|
128 | int line, int col);
|
---|
129 |
|
---|
130 | DomUI *generateUi4(const QDomElement &e);
|
---|
131 | DomWidget *createWidget(const QDomElement &w, const QString &widgetClass = QString());
|
---|
132 | void createProperties(const QDomElement &e, QList<DomProperty*> *properties, const QString &className);
|
---|
133 | void createAttributes(const QDomElement &e, QList<DomProperty*> *properties, const QString &className);
|
---|
134 | DomLayout *createLayout(const QDomElement &e);
|
---|
135 | DomLayoutItem *createLayoutItem(const QDomElement &e);
|
---|
136 | DomProperty *readProperty(const QDomElement &e);
|
---|
137 | void fixActionGroup(DomActionGroup *g);
|
---|
138 | QString fixActionProperties(QList<DomProperty*> &properties, bool isActionGroup = false);
|
---|
139 |
|
---|
140 | QString fixHeaderName(const QString &headerName) const;
|
---|
141 | QString fixClassName(const QString &className) const;
|
---|
142 | QString fixDeclaration(const QString &declaration) const;
|
---|
143 | QString fixType(const QString &type) const;
|
---|
144 | QString fixMethod(const QString &method) const;
|
---|
145 |
|
---|
146 | QDomElement findDerivedFontProperties(const QDomElement &n) const;
|
---|
147 |
|
---|
148 | void fixLayoutMargin(DomLayout *ui_layout);
|
---|
149 |
|
---|
150 | const unsigned m_options;
|
---|
151 |
|
---|
152 | QTextStream &out;
|
---|
153 | QTextOStream trout;
|
---|
154 | QString languageChangeBody;
|
---|
155 | QString outputFileName;
|
---|
156 | QStringList objectNames;
|
---|
157 | QMap<QString,QString> objectMapper;
|
---|
158 | QString indent;
|
---|
159 | QStringList tags;
|
---|
160 | QStringList layouts;
|
---|
161 | QString formName;
|
---|
162 | QString lastItem;
|
---|
163 | QString trmacro;
|
---|
164 |
|
---|
165 | struct Buddy
|
---|
166 | {
|
---|
167 | Buddy(const QString& k, const QString& b)
|
---|
168 | : key(k), buddy(b) {}
|
---|
169 | Buddy(){} // for valuelist
|
---|
170 | QString key;
|
---|
171 | QString buddy;
|
---|
172 | bool operator==(const Buddy& other) const
|
---|
173 | { return (key == other.key); }
|
---|
174 | };
|
---|
175 | struct CustomInclude
|
---|
176 | {
|
---|
177 | QString header;
|
---|
178 | QString location;
|
---|
179 | Q_DUMMY_COMPARISON_OPERATOR(CustomInclude)
|
---|
180 | };
|
---|
181 | QList<Buddy> buddies;
|
---|
182 |
|
---|
183 | QStringList layoutObjects;
|
---|
184 | bool isLayout(const QString& name) const;
|
---|
185 |
|
---|
186 | uint item_used : 1;
|
---|
187 | uint cg_used : 1;
|
---|
188 | uint pal_used : 1;
|
---|
189 | uint stdsetdef : 1;
|
---|
190 | uint externPixmaps : 1;
|
---|
191 |
|
---|
192 | QString uiFileVersion;
|
---|
193 | QString nameOfClass;
|
---|
194 | QStringList namespaces;
|
---|
195 | QString bareNameOfClass;
|
---|
196 | QString pixmapLoaderFunction;
|
---|
197 |
|
---|
198 | void registerDatabases(const QDomElement& e);
|
---|
199 | bool isWidgetInTable(const QDomElement& e, const QString& connection, const QString& table);
|
---|
200 | bool isFrameworkCodeGenerated(const QDomElement& e);
|
---|
201 | QString getDatabaseInfo(const QDomElement& e, const QString& tag);
|
---|
202 | void createFormImpl(const QDomElement& e, const QString& form, const QString& connection, const QString& table);
|
---|
203 | void writeFunctionsDecl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst);
|
---|
204 | void writeFunctionsSubDecl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst);
|
---|
205 | void writeFunctionsSubImpl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst,
|
---|
206 | const QString &subClass, const QString &descr);
|
---|
207 | QStringList dbConnections;
|
---|
208 | QMap<QString, QStringList> dbCursors;
|
---|
209 | QMap<QString, QStringList> dbForms;
|
---|
210 |
|
---|
211 | static bool isMainWindow;
|
---|
212 | static QString mkBool(bool b);
|
---|
213 | static QString mkBool(const QString& s);
|
---|
214 | bool toBool(const QString& s);
|
---|
215 | static QString fixString(const QString &str, bool encode = false);
|
---|
216 | static bool onlyAscii;
|
---|
217 | static QString mkStdSet(const QString& prop);
|
---|
218 | static QString getComment(const QDomNode& n);
|
---|
219 | QVariant defSpacing, defMargin;
|
---|
220 | QString fileName;
|
---|
221 | bool writeFunctImpl;
|
---|
222 |
|
---|
223 | QDomElement root;
|
---|
224 | QDomElement widget;
|
---|
225 |
|
---|
226 | QMap<QString, bool> candidateCustomWidgets;
|
---|
227 | Porting *m_porting;
|
---|
228 |
|
---|
229 | bool m_extractImages;
|
---|
230 | QString m_qrcOutputFile;
|
---|
231 | QMap<QString, QString> m_imageMap;
|
---|
232 | };
|
---|
233 |
|
---|
234 | QT_END_NAMESPACE
|
---|
235 |
|
---|
236 | #endif // UI3READER_H
|
---|