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