|
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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef CPPWRITEINITIALIZATION_H |
|
43 #define CPPWRITEINITIALIZATION_H |
|
44 |
|
45 #include "treewalker.h" |
|
46 #include <QtCore/QPair> |
|
47 #include <QtCore/QHash> |
|
48 #include <QtCore/QSet> |
|
49 #include <QtCore/QMap> |
|
50 #include <QtCore/QStack> |
|
51 #include <QtCore/QTextStream> |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 class Driver; |
|
56 class Uic; |
|
57 class DomBrush; |
|
58 class DomFont; |
|
59 class DomResourceIcon; |
|
60 class DomSizePolicy; |
|
61 struct Option; |
|
62 |
|
63 namespace CPP { |
|
64 // Handle for a flat DOM font to get comparison functionality required for maps |
|
65 class FontHandle { |
|
66 public: |
|
67 FontHandle(const DomFont *domFont); |
|
68 int compare(const FontHandle &) const; |
|
69 private: |
|
70 const DomFont *m_domFont; |
|
71 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) |
|
72 friend uint qHash(const FontHandle &); |
|
73 #endif |
|
74 }; |
|
75 inline bool operator ==(const FontHandle &f1, const FontHandle &f2) { return f1.compare(f2) == 0; } |
|
76 inline bool operator <(const FontHandle &f1, const FontHandle &f2) { return f1.compare(f2) < 0; } |
|
77 |
|
78 // Handle for a flat DOM icon to get comparison functionality required for maps |
|
79 class IconHandle { |
|
80 public: |
|
81 IconHandle(const DomResourceIcon *domIcon); |
|
82 int compare(const IconHandle &) const; |
|
83 private: |
|
84 const DomResourceIcon *m_domIcon; |
|
85 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) |
|
86 friend uint qHash(const IconHandle &); |
|
87 #endif |
|
88 }; |
|
89 inline bool operator ==(const IconHandle &i1, const IconHandle &i2) { return i1.compare(i2) == 0; } |
|
90 inline bool operator <(const IconHandle &i1, const IconHandle &i2) { return i1.compare(i2) < 0; } |
|
91 |
|
92 // Handle for a flat DOM size policy to get comparison functionality required for maps |
|
93 class SizePolicyHandle { |
|
94 public: |
|
95 SizePolicyHandle(const DomSizePolicy *domSizePolicy); |
|
96 int compare(const SizePolicyHandle &) const; |
|
97 private: |
|
98 const DomSizePolicy *m_domSizePolicy; |
|
99 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) |
|
100 friend uint qHash(const SizePolicyHandle &); |
|
101 #endif |
|
102 }; |
|
103 inline bool operator ==(const SizePolicyHandle &f1, const SizePolicyHandle &f2) { return f1.compare(f2) == 0; } |
|
104 #if !(defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3)) |
|
105 inline bool operator <(const SizePolicyHandle &f1, const SizePolicyHandle &f2) { return f1.compare(f2) < 0; } |
|
106 #endif |
|
107 |
|
108 |
|
109 |
|
110 struct WriteInitialization : public TreeWalker |
|
111 { |
|
112 typedef QList<DomProperty*> DomPropertyList; |
|
113 typedef QHash<QString, DomProperty*> DomPropertyMap; |
|
114 |
|
115 WriteInitialization(Uic *uic, bool activateScripts); |
|
116 |
|
117 // |
|
118 // widgets |
|
119 // |
|
120 void acceptUI(DomUI *node); |
|
121 void acceptWidget(DomWidget *node); |
|
122 void acceptWidgetScripts(const DomScripts &, DomWidget *node, const DomWidgets &childWidgets); |
|
123 |
|
124 void acceptLayout(DomLayout *node); |
|
125 void acceptSpacer(DomSpacer *node); |
|
126 void acceptLayoutItem(DomLayoutItem *node); |
|
127 |
|
128 // |
|
129 // actions |
|
130 // |
|
131 void acceptActionGroup(DomActionGroup *node); |
|
132 void acceptAction(DomAction *node); |
|
133 void acceptActionRef(DomActionRef *node); |
|
134 |
|
135 // |
|
136 // tab stops |
|
137 // |
|
138 void acceptTabStops(DomTabStops *tabStops); |
|
139 |
|
140 // |
|
141 // custom widgets |
|
142 // |
|
143 void acceptCustomWidgets(DomCustomWidgets *node); |
|
144 void acceptCustomWidget(DomCustomWidget *node); |
|
145 |
|
146 // |
|
147 // layout defaults/functions |
|
148 // |
|
149 void acceptLayoutDefault(DomLayoutDefault *node) { m_LayoutDefaultHandler.acceptLayoutDefault(node); } |
|
150 void acceptLayoutFunction(DomLayoutFunction *node) { m_LayoutDefaultHandler.acceptLayoutFunction(node); } |
|
151 |
|
152 // |
|
153 // signal/slot connections |
|
154 // |
|
155 void acceptConnection(DomConnection *connection); |
|
156 |
|
157 // |
|
158 // images |
|
159 // |
|
160 void acceptImage(DomImage *image); |
|
161 |
|
162 enum { |
|
163 Use43UiFile = 0, |
|
164 TopLevelMargin, |
|
165 ChildMargin, |
|
166 SubLayoutMargin |
|
167 }; |
|
168 |
|
169 private: |
|
170 static QString domColor2QString(const DomColor *c); |
|
171 |
|
172 QString iconCall(const DomProperty *prop); |
|
173 QString pixCall(const DomProperty *prop) const; |
|
174 QString pixCall(const QString &type, const QString &text) const; |
|
175 QString trCall(const QString &str, const QString &comment = QString()) const; |
|
176 QString trCall(DomString *str, const QString &defaultString = QString()) const; |
|
177 QString noTrCall(DomString *str, const QString &defaultString = QString()) const; |
|
178 QString autoTrCall(DomString *str, const QString &defaultString = QString()) const; |
|
179 QTextStream &autoTrOutput(DomString *str, const QString &defaultString = QString()); |
|
180 // Apply a comma-separated list of values using a function "setSomething(int idx, value)" |
|
181 void writePropertyList(const QString &varName, const QString &setFunction, const QString &value, const QString &defaultValue); |
|
182 |
|
183 enum { WritePropertyIgnoreMargin = 1, WritePropertyIgnoreSpacing = 2, WritePropertyIgnoreObjectName = 4 }; |
|
184 void writeProperties(const QString &varName, const QString &className, const DomPropertyList &lst, unsigned flags = 0); |
|
185 void writeColorGroup(DomColorGroup *colorGroup, const QString &group, const QString &paletteName); |
|
186 void writeBrush(const DomBrush *brush, const QString &brushName); |
|
187 |
|
188 // |
|
189 // special initialization |
|
190 // |
|
191 class Item { |
|
192 public: |
|
193 Item(const QString &itemClassName, const QString &indent, QTextStream &setupUiStream, QTextStream &retranslateUiStream, Driver *driver); |
|
194 ~Item(); |
|
195 enum EmptyItemPolicy { |
|
196 DontConstruct, |
|
197 ConstructItemOnly, |
|
198 ConstructItemAndVariable |
|
199 }; |
|
200 QString writeSetupUi(const QString &parent, EmptyItemPolicy emptyItemPolicy = ConstructItemOnly); |
|
201 void writeRetranslateUi(const QString &parentPath); |
|
202 void addSetter(const QString &setter, const QString &directive = QString(), bool translatable = false); // don't call it if you already added *this as a child of another Item |
|
203 void addChild(Item *child); // all setters should already been added |
|
204 int setupUiCount() const { return m_setupUiData.setters.count(); } |
|
205 int retranslateUiCount() const { return m_retranslateUiData.setters.count(); } |
|
206 private: |
|
207 struct ItemData { |
|
208 ItemData() : policy(DontGenerate) {} |
|
209 QMultiMap<QString, QString> setters; // directive to setter |
|
210 QSet<QString> directives; |
|
211 enum TemporaryVariableGeneratorPolicy { // policies with priority, number describes the priority |
|
212 DontGenerate = 1, |
|
213 GenerateWithMultiDirective = 2, |
|
214 Generate = 3 |
|
215 } policy; |
|
216 }; |
|
217 ItemData m_setupUiData; |
|
218 ItemData m_retranslateUiData; |
|
219 QList<Item *> m_children; |
|
220 Item *m_parent; |
|
221 |
|
222 const QString m_itemClassName; |
|
223 const QString m_indent; |
|
224 QTextStream &m_setupUiStream; |
|
225 QTextStream &m_retranslateUiStream; |
|
226 Driver *m_driver; |
|
227 }; |
|
228 |
|
229 void addInitializer(Item *item, |
|
230 const QString &name, int column, const QString &value, const QString &directive = QString(), bool translatable = false) const; |
|
231 void addQtFlagsInitializer(Item *item, const DomPropertyMap &properties, |
|
232 const QString &name, int column = -1) const; |
|
233 void addQtEnumInitializer(Item *item, |
|
234 const DomPropertyMap &properties, const QString &name, int column = -1) const; |
|
235 void addBrushInitializer(Item *item, |
|
236 const DomPropertyMap &properties, const QString &name, int column = -1); |
|
237 void addStringInitializer(Item *item, |
|
238 const DomPropertyMap &properties, const QString &name, int column = -1, const QString &directive = QString()) const; |
|
239 void addCommonInitializers(Item *item, |
|
240 const DomPropertyMap &properties, int column = -1); |
|
241 |
|
242 void initializeMenu(DomWidget *w, const QString &parentWidget); |
|
243 void initializeComboBox(DomWidget *w); |
|
244 void initializeComboBox3(DomWidget *w); |
|
245 void initializeListWidget(DomWidget *w); |
|
246 void initializeTreeWidget(DomWidget *w); |
|
247 QList<Item *> initializeTreeWidgetItems(const QList<DomItem *> &domItems); |
|
248 void initializeTableWidget(DomWidget *w); |
|
249 |
|
250 QString disableSorting(DomWidget *w, const QString &varName); |
|
251 void enableSorting(DomWidget *w, const QString &varName, const QString &tempName); |
|
252 |
|
253 // |
|
254 // special initialization for the Q3 support classes |
|
255 // |
|
256 void initializeQ3ListBox(DomWidget *w); |
|
257 void initializeQ3IconView(DomWidget *w); |
|
258 void initializeQ3ListView(DomWidget *w); |
|
259 void initializeQ3ListViewItems(const QString &className, const QString &varName, const QList<DomItem*> &items); |
|
260 void initializeQ3Table(DomWidget *w); |
|
261 void initializeQ3TableItems(const QString &className, const QString &varName, const QList<DomItem*> &items); |
|
262 |
|
263 // |
|
264 // Sql |
|
265 // |
|
266 void initializeQ3SqlDataTable(DomWidget *w); |
|
267 void initializeQ3SqlDataBrowser(DomWidget *w); |
|
268 |
|
269 QString findDeclaration(const QString &name); |
|
270 DomWidget *findWidget(const QLatin1String &widgetClass); |
|
271 DomImage *findImage(const QString &name) const; |
|
272 |
|
273 bool isValidObject(const QString &name) const; |
|
274 |
|
275 private: |
|
276 QString writeFontProperties(const DomFont *f); |
|
277 QString writeIconProperties(const DomResourceIcon *i); |
|
278 QString writeSizePolicy(const DomSizePolicy *sp); |
|
279 QString writeBrushInitialization(const DomBrush *brush); |
|
280 void addButtonGroup(const DomWidget *node, const QString &varName); |
|
281 void addWizardPage(const QString &pageVarName, const DomWidget *page, const QString &parentWidget); |
|
282 |
|
283 const Uic *m_uic; |
|
284 Driver *m_driver; |
|
285 QTextStream &m_output; |
|
286 const Option &m_option; |
|
287 QString m_indent; |
|
288 QString m_dindent; |
|
289 bool m_stdsetdef; |
|
290 |
|
291 struct Buddy |
|
292 { |
|
293 Buddy(const QString &oN, const QString &b) |
|
294 : objName(oN), buddy(b) {} |
|
295 QString objName; |
|
296 QString buddy; |
|
297 }; |
|
298 |
|
299 QStack<DomWidget*> m_widgetChain; |
|
300 QStack<DomLayout*> m_layoutChain; |
|
301 QStack<DomActionGroup*> m_actionGroupChain; |
|
302 QList<Buddy> m_buddies; |
|
303 |
|
304 QSet<QString> m_buttonGroups; |
|
305 QHash<QString, DomWidget*> m_registeredWidgets; |
|
306 QHash<QString, DomImage*> m_registeredImages; |
|
307 QHash<QString, DomAction*> m_registeredActions; |
|
308 typedef QHash<uint, QString> ColorBrushHash; |
|
309 ColorBrushHash m_colorBrushHash; |
|
310 // Map from font properties to font variable name for reuse |
|
311 // Map from size policy to variable for reuse |
|
312 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) |
|
313 typedef QHash<FontHandle, QString> FontPropertiesNameMap; |
|
314 typedef QHash<IconHandle, QString> IconPropertiesNameMap; |
|
315 typedef QHash<SizePolicyHandle, QString> SizePolicyNameMap; |
|
316 #else |
|
317 typedef QMap<FontHandle, QString> FontPropertiesNameMap; |
|
318 typedef QMap<IconHandle, QString> IconPropertiesNameMap; |
|
319 typedef QMap<SizePolicyHandle, QString> SizePolicyNameMap; |
|
320 #endif |
|
321 FontPropertiesNameMap m_fontPropertiesNameMap; |
|
322 IconPropertiesNameMap m_iconPropertiesNameMap; |
|
323 SizePolicyNameMap m_sizePolicyNameMap; |
|
324 |
|
325 class LayoutDefaultHandler { |
|
326 public: |
|
327 LayoutDefaultHandler(); |
|
328 void acceptLayoutDefault(DomLayoutDefault *node); |
|
329 void acceptLayoutFunction(DomLayoutFunction *node); |
|
330 |
|
331 // Write out the layout margin and spacing properties applying the defaults. |
|
332 void writeProperties(const QString &indent, const QString &varName, |
|
333 const DomPropertyMap &pm, int marginType, |
|
334 bool suppressMarginDefault, QTextStream &str) const; |
|
335 private: |
|
336 void writeProperty(int p, const QString &indent, const QString &objectName, const DomPropertyMap &pm, |
|
337 const QString &propertyName, const QString &setter, int defaultStyleValue, |
|
338 bool suppressDefault, QTextStream &str) const; |
|
339 |
|
340 enum Properties { Margin, Spacing, NumProperties }; |
|
341 enum StateFlags { HasDefaultValue = 1, HasDefaultFunction = 2}; |
|
342 unsigned m_state[NumProperties]; |
|
343 int m_defaultValues[NumProperties]; |
|
344 QString m_functions[NumProperties]; |
|
345 }; |
|
346 |
|
347 // layout defaults |
|
348 LayoutDefaultHandler m_LayoutDefaultHandler; |
|
349 int m_layoutMarginType; |
|
350 |
|
351 QString m_generatedClass; |
|
352 QString m_mainFormVarName; |
|
353 bool m_mainFormUsedInRetranslateUi; |
|
354 |
|
355 QString m_delayedInitialization; |
|
356 QTextStream m_delayedOut; |
|
357 |
|
358 QString m_refreshInitialization; |
|
359 QTextStream m_refreshOut; |
|
360 |
|
361 QString m_delayedActionInitialization; |
|
362 QTextStream m_actionOut; |
|
363 const bool m_activateScripts; |
|
364 |
|
365 bool m_layoutWidget; |
|
366 }; |
|
367 |
|
368 } // namespace CPP |
|
369 |
|
370 QT_END_NAMESPACE |
|
371 |
|
372 #endif // CPPWRITEINITIALIZATION_H |