source: trunk/src/tools/uic3/ui3reader.h@ 706

Last change on this file since 706 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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
54QT_BEGIN_NAMESPACE
55
56class DomUI;
57class DomFont;
58class DomWidget;
59class DomProperty;
60class DomLayout;
61class DomLayoutItem;
62class DomActionGroup;
63class Porting;
64struct Color;
65
66typedef QList<QPair<int, Color> > ColorGroup;
67
68class Ui3Reader
69{
70public:
71 enum Options { CustomWidgetForwardDeclarations = 0x1, ImplicitIncludes = 0x2, PreserveLayoutNames = 0x4 };
72
73 explicit Ui3Reader(QTextStream &stream, unsigned options);
74 ~Ui3Reader();
75
76 void computeDeps(const QDomElement &e, QStringList &globalIncludes, QStringList &localIncludes, bool impl = false);
77 void generateUi4(const QString &fn, const QString &outputFn, QDomDocument doc);
78
79 void generate(const QString &fn, const QString &outputFn,
80 QDomDocument doc, bool decl, bool subcl, const QString &trm,
81 const QString& subclname, const QString &convertedUiFile);
82
83 void embed(const char *project, const QStringList &images);
84
85 void setTrMacro(const QString &trmacro);
86 void setOutputFileName(const QString &fileName);
87
88 void createFormDecl(const QDomElement &e);
89 void createFormImpl(const QDomElement &e);
90
91 void createWrapperDecl(const QDomElement &e, const QString &convertedUiFile);
92
93 void createSubDecl(const QDomElement &e, const QString& subclname);
94 void createSubImpl(const QDomElement &e, const QString& subclname);
95
96 void createColorGroupImpl(const QString& cg, const QDomElement& e);
97 ColorGroup loadColorGroup(const QDomElement &e);
98
99 QDomElement getObjectProperty(const QDomElement& e, const QString& name);
100 QString getPixmapLoaderFunction(const QDomElement& e);
101 QString getFormClassName(const QDomElement& e);
102 QString getClassName(const QDomElement& e);
103 QString getObjectName(const QDomElement& e);
104 QString getLayoutName(const QDomElement& e);
105
106 QString registerObject(const QString& name);
107 QString registeredName(const QString& name);
108 bool isObjectRegistered(const QString& name);
109 QStringList unique(const QStringList&);
110
111 QString trcall(const QString& sourceText, const QString& comment = QString());
112
113 QDomElement parse(const QDomDocument &doc);
114
115 void setExtractImages(bool extract, const QString &qrcOutputFile);
116
117private:
118 void init();
119
120 void createWrapperDeclContents(const QDomElement &e);
121
122 void errorInvalidProperty(const QString &propertyName, const QString &widgetName, const QString &widgetClass,
123 int line, int col);
124 void errorInvalidSignal(const QString &signal, const QString &widgetName, const QString &widgetClass,
125 int line, int col);
126 void errorInvalidSlot(const QString &slot, const QString &widgetName, const QString &widgetClass,
127 int line, int col);
128
129 DomUI *generateUi4(const QDomElement &e);
130 DomWidget *createWidget(const QDomElement &w, const QString &widgetClass = QString());
131 void createProperties(const QDomElement &e, QList<DomProperty*> *properties, const QString &className);
132 void createAttributes(const QDomElement &e, QList<DomProperty*> *properties, const QString &className);
133 DomLayout *createLayout(const QDomElement &e);
134 DomLayoutItem *createLayoutItem(const QDomElement &e);
135 DomProperty *readProperty(const QDomElement &e);
136 void fixActionGroup(DomActionGroup *g);
137 QString fixActionProperties(QList<DomProperty*> &properties, bool isActionGroup = false);
138
139 QString fixHeaderName(const QString &headerName) const;
140 QString fixClassName(const QString &className) const;
141 QString fixDeclaration(const QString &declaration) const;
142 QString fixType(const QString &type) const;
143 QString fixMethod(const QString &method) const;
144
145 QDomElement findDerivedFontProperties(const QDomElement &n) const;
146
147 void fixLayoutMargin(DomLayout *ui_layout);
148
149 const unsigned m_options;
150
151 QTextStream &out;
152 QTextOStream trout;
153 QString languageChangeBody;
154 QString outputFileName;
155 QStringList objectNames;
156 QMap<QString,QString> objectMapper;
157 QString indent;
158 QStringList tags;
159 QStringList layouts;
160 QString formName;
161 QString lastItem;
162 QString trmacro;
163
164 struct Buddy
165 {
166 Buddy(const QString& k, const QString& b)
167 : key(k), buddy(b) {}
168 Buddy(){} // for valuelist
169 QString key;
170 QString buddy;
171 bool operator==(const Buddy& other) const
172 { return (key == other.key); }
173 };
174 struct CustomInclude
175 {
176 QString header;
177 QString location;
178 Q_DUMMY_COMPARISON_OPERATOR(CustomInclude)
179 };
180 QList<Buddy> buddies;
181
182 QStringList layoutObjects;
183 bool isLayout(const QString& name) const;
184
185 uint item_used : 1;
186 uint cg_used : 1;
187 uint pal_used : 1;
188 uint stdsetdef : 1;
189 uint externPixmaps : 1;
190
191 QString uiFileVersion;
192 QString nameOfClass;
193 QStringList namespaces;
194 QString bareNameOfClass;
195 QString pixmapLoaderFunction;
196
197 void registerDatabases(const QDomElement& e);
198 bool isWidgetInTable(const QDomElement& e, const QString& connection, const QString& table);
199 bool isFrameworkCodeGenerated(const QDomElement& e);
200 QString getDatabaseInfo(const QDomElement& e, const QString& tag);
201 void createFormImpl(const QDomElement& e, const QString& form, const QString& connection, const QString& table);
202 void writeFunctionsDecl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst);
203 void writeFunctionsSubDecl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst);
204 void writeFunctionsSubImpl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst,
205 const QString &subClass, const QString &descr);
206 QStringList dbConnections;
207 QMap<QString, QStringList> dbCursors;
208 QMap<QString, QStringList> dbForms;
209
210 static bool isMainWindow;
211 static QString mkBool(bool b);
212 static QString mkBool(const QString& s);
213 bool toBool(const QString& s);
214 static QString fixString(const QString &str, bool encode = false);
215 static bool onlyAscii;
216 static QString mkStdSet(const QString& prop);
217 static QString getComment(const QDomNode& n);
218 QVariant defSpacing, defMargin;
219 QString fileName;
220 bool writeFunctImpl;
221
222 QDomElement root;
223 QDomElement widget;
224
225 QMap<QString, bool> candidateCustomWidgets;
226 Porting *m_porting;
227
228 bool m_extractImages;
229 QString m_qrcOutputFile;
230 QMap<QString, QString> m_imageMap;
231};
232
233QT_END_NAMESPACE
234
235#endif // UI3READER_H
Note: See TracBrowser for help on using the repository browser.