Mercurial > projects > qtd
annotate tools/duic/d/dwriteinitialization.cpp @ 82:420f2aab9ab6
temporary fix for "::" in duic for all types
author | eldar |
---|---|
date | Sun, 24 May 2009 17:07:11 +0000 |
parents | 3d465c0a4f98 |
children | c64698c80409 |
rev | line source |
---|---|
1 | 1 /**************************************************************************** |
2 ** | |
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). | |
4 ** Contact: Qt Software Information (qt-info@nokia.com) | |
5 ** | |
6 ** This file is part of the tools applications of the Qt Toolkit. | |
7 ** | |
8 ** Commercial Usage | |
9 ** Licensees holding valid Qt Commercial licenses may use this file in | |
10 ** accordance with the Qt Commercial License Agreement provided with the | |
11 ** Software or, alternatively, in accordance with the terms contained in | |
12 ** a written agreement between you and Nokia. | |
13 ** | |
14 ** | |
15 ** GNU General Public License Usage | |
16 ** Alternatively, this file may be used under the terms of the GNU | |
17 ** General Public License versions 2.0 or 3.0 as published by the Free | |
18 ** Software Foundation and appearing in the file LICENSE.GPL included in | |
19 ** the packaging of this file. Please review the following information | |
20 ** to ensure GNU General Public Licensing requirements will be met: | |
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
23 ** exception, Nokia gives you certain additional rights. These rights | |
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in | |
25 ** the file GPL_EXCEPTION.txt in this package. | |
26 ** | |
27 ** Qt for Windows(R) Licensees | |
28 ** As a special exception, Nokia, as the sole copyright holder for Qt | |
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the | |
30 ** right for the Qt/Eclipse Integration to link to functionality | |
31 ** provided by Qt Designer and its related libraries. | |
32 ** | |
33 ** If you are unsure which license is appropriate for your use, please | |
34 ** contact the sales department at qt-sales@nokia.com. | |
35 ** | |
36 ****************************************************************************/ | |
37 | |
38 #include "dwriteinitialization.h" | |
39 #include "dwriteiconinitialization.h" | |
40 #include "driver.h" | |
41 #include "ui4.h" | |
42 #include "utils.h" | |
43 #include "uic.h" | |
44 #include "databaseinfo.h" | |
45 #include "globaldefs.h" | |
46 | |
47 #include <QtCore/QTextStream> | |
48 #include <QtCore/QDebug> | |
49 | |
50 QT_BEGIN_NAMESPACE | |
51 | |
52 namespace { | |
53 // Fixup an enumeration name from class Qt. | |
54 // They are currently stored as "BottomToolBarArea" instead of "Qt::BottomToolBarArea". | |
55 // due to MO issues. This might be fixed in the future. | |
56 void fixQtEnumerationName(QString& name) { | |
48 | 57 static const QLatin1String prefix("Qt."); |
1 | 58 if (name.indexOf(prefix) != 0) |
59 name.prepend(prefix); | |
60 } | |
61 // figure out the toolbar area of a DOM attrib list. | |
62 // By legacy, it is stored as an integer. As of 4.3.0, it is the enumeration value. | |
63 QString toolBarAreaStringFromDOMAttributes(const D::WriteInitialization::DomPropertyMap &attributes) { | |
64 const DomProperty *pstyle = attributes.value(QLatin1String("toolBarArea")); | |
65 if (!pstyle) | |
66 return QString(); | |
67 | |
68 switch (pstyle->kind()) { | |
69 case DomProperty::Number: { | |
48 | 70 QString area = QLatin1String("(cast(Qt.ToolBarArea)("); |
1 | 71 area += QString::number(pstyle->elementNumber()); |
72 area += QLatin1String(")), "); | |
73 return area; | |
74 } | |
75 case DomProperty::Enum: { | |
76 QString area = pstyle->elementEnum(); | |
77 fixQtEnumerationName(area); | |
78 area += QLatin1String(", "); | |
79 return area; | |
80 } | |
81 default: | |
82 break; | |
83 } | |
84 return QString(); | |
85 } | |
86 | |
87 // Write a statement to create a spacer item. | |
88 void writeSpacerItem(const DomSpacer *node, QTextStream &output) { | |
89 const QHash<QString, DomProperty *> properties = propertyMap(node->elementProperty()); | |
90 output << "new QSpacerItem("; | |
91 | |
92 if (properties.contains(QLatin1String("sizeHint"))) { | |
93 const DomSize *sizeHint = properties.value(QLatin1String("sizeHint"))->elementSize(); | |
94 output << sizeHint->elementWidth() << ", " << sizeHint->elementHeight() << ", "; | |
95 } | |
96 | |
97 // size type | |
98 QString sizeType = properties.contains(QLatin1String("sizeType")) ? | |
99 properties.value(QLatin1String("sizeType"))->elementEnum() : | |
100 QString::fromLatin1("Expanding"); | |
101 | |
48 | 102 if (!sizeType.startsWith(QLatin1String("QSizePolicy."))) |
103 sizeType.prepend(QLatin1String("QSizePolicy.")); | |
1 | 104 // orientation |
105 bool isVspacer = false; | |
106 if (properties.contains(QLatin1String("orientation"))) { | |
107 const QString orientation = properties.value(QLatin1String("orientation"))->elementEnum(); | |
48 | 108 if (orientation == QLatin1String("Qt.Vertical") || orientation == QLatin1String("Vertical")) isVspacer = true; |
1 | 109 } |
110 | |
111 if (isVspacer) | |
48 | 112 output << "QSizePolicy.Minimum, " << sizeType << ')'; |
1 | 113 else |
48 | 114 output << sizeType << ", QSizePolicy.Minimum)"; |
1 | 115 } |
116 | |
117 | |
118 // Helper for implementing comparison functions for integers. | |
119 int compareInt(int i1, int i2) { | |
120 if (i1 < i2) return -1; | |
121 if (i1 > i2) return 1; | |
122 return 0; | |
123 } | |
124 | |
125 // Write object->setFoo(x); | |
126 template <class Value> | |
127 void writeSetter(const QString &indent, const QString &varName,const QString &setter, Value v, QTextStream &str) { | |
128 str << indent << varName << "." << setter << '(' << v << ");\n"; | |
129 } | |
130 | |
131 void writeSetupUIScriptVariableDeclarations(const QString &indent, QTextStream &str) { | |
132 str << indent << "ScriptContext scriptContext;\n" | |
133 << indent << "QWidgetList childWidgets;\n"; | |
134 } | |
135 | |
136 static inline bool isIconFormat44(const DomResourceIcon *i) { | |
137 return i->hasElementNormalOff() || i->hasElementNormalOn() || | |
138 i->hasElementDisabledOff() || i->hasElementDisabledOn() || | |
139 i->hasElementActiveOff() || i->hasElementActiveOn() || | |
140 i->hasElementSelectedOff() || i->hasElementSelectedOn(); | |
141 } | |
142 | |
143 // Check on properties. Filter out empty legacy pixmap/icon properties | |
144 // as Designer pre 4.4 used to remove missing resource references. | |
145 // This can no longer be handled by the code as we have 'setIcon(QIcon())' as well as 'QIcon icon' | |
146 static bool checkProperty(const QString &fileName, const DomProperty *p) { | |
147 switch (p->kind()) { | |
148 case DomProperty::IconSet: | |
149 if (const DomResourceIcon *dri = p->elementIconSet()) { | |
150 if (!isIconFormat44(dri)) { | |
151 if (dri->text().isEmpty()) { | |
152 const QString msg = QString::fromUtf8("%1: An invalid icon property '%2' was encountered.").arg(fileName).arg(p->attributeName()); | |
153 qWarning("%s", qPrintable(msg)); | |
154 return false; | |
155 } | |
156 } | |
157 } | |
158 break; | |
159 case DomProperty::Pixmap: | |
160 if (const DomResourcePixmap *drp = p->elementPixmap()) | |
161 if (drp->text().isEmpty()) { | |
162 const QString msg = QString::fromUtf8("%1: An invalid pixmap property '%2' was encountered.").arg(fileName).arg(p->attributeName()); | |
163 qWarning("%s", qPrintable(msg)); | |
164 return false; | |
165 } | |
166 break; | |
167 default: | |
168 break; | |
169 } | |
170 return true; | |
171 } | |
172 | |
173 inline void openIfndef(QTextStream &str, const QString &symbol) { str << endl << QLatin1String("#ifndef ") << symbol << endl; } | |
174 inline void closeIfdef(QTextStream &str, const QString &symbol) { str << QLatin1String("#endif // ") << symbol << endl << endl; } | |
175 | |
176 const char *accessibilityDefineC = "QT_NO_ACCESSIBILITY"; | |
177 const char *toolTipDefineC = "QT_NO_TOOLTIP"; | |
178 const char *whatsThisDefineC = "QT_NO_WHATSTHIS"; | |
179 const char *statusTipDefineC = "QT_NO_STATUSTIP"; | |
180 const char *shortcutDefineC = "QT_NO_SHORTCUT"; | |
181 } | |
182 | |
183 namespace D { | |
184 | |
185 FontHandle::FontHandle(const DomFont *domFont) : | |
186 m_domFont(domFont) | |
187 { | |
188 } | |
189 | |
190 int FontHandle::compare(const FontHandle &rhs) const | |
191 { | |
192 const QString family = m_domFont->hasElementFamily() ? m_domFont->elementFamily() : QString(); | |
193 const QString rhsFamily = rhs.m_domFont->hasElementFamily() ? rhs.m_domFont->elementFamily() : QString(); | |
194 | |
195 if (const int frc = family.compare(rhsFamily)) | |
196 return frc; | |
197 | |
198 const int pointSize = m_domFont->hasElementPointSize() ? m_domFont->elementPointSize() : -1; | |
199 const int rhsPointSize = rhs.m_domFont->hasElementPointSize() ? rhs.m_domFont->elementPointSize() : -1; | |
200 | |
201 if (const int crc = compareInt(pointSize, rhsPointSize)) | |
202 return crc; | |
203 | |
204 const int bold = m_domFont->hasElementBold() ? (m_domFont->elementBold() ? 1 : 0) : -1; | |
205 const int rhsBold = rhs.m_domFont->hasElementBold() ? (rhs.m_domFont->elementBold() ? 1 : 0) : -1; | |
206 if (const int crc = compareInt(bold, rhsBold)) | |
207 return crc; | |
208 | |
209 const int italic = m_domFont->hasElementItalic() ? (m_domFont->elementItalic() ? 1 : 0) : -1; | |
210 const int rhsItalic = rhs.m_domFont->hasElementItalic() ? (rhs.m_domFont->elementItalic() ? 1 : 0) : -1; | |
211 if (const int crc = compareInt(italic, rhsItalic)) | |
212 return crc; | |
213 | |
214 const int underline = m_domFont->hasElementUnderline() ? (m_domFont->elementUnderline() ? 1 : 0) : -1; | |
215 const int rhsUnderline = rhs.m_domFont->hasElementUnderline() ? (rhs.m_domFont->elementUnderline() ? 1 : 0) : -1; | |
216 if (const int crc = compareInt(underline, rhsUnderline)) | |
217 return crc; | |
218 | |
219 const int weight = m_domFont->hasElementWeight() ? m_domFont->elementWeight() : -1; | |
220 const int rhsWeight = rhs.m_domFont->hasElementWeight() ? rhs.m_domFont->elementWeight() : -1; | |
221 if (const int crc = compareInt(weight, rhsWeight)) | |
222 return crc; | |
223 | |
224 const int strikeOut = m_domFont->hasElementStrikeOut() ? (m_domFont->elementStrikeOut() ? 1 : 0) : -1; | |
225 const int rhsStrikeOut = rhs.m_domFont->hasElementStrikeOut() ? (rhs.m_domFont->elementStrikeOut() ? 1 : 0) : -1; | |
226 if (const int crc = compareInt(strikeOut, rhsStrikeOut)) | |
227 return crc; | |
228 | |
229 const int kerning = m_domFont->hasElementKerning() ? (m_domFont->elementKerning() ? 1 : 0) : -1; | |
230 const int rhsKerning = rhs.m_domFont->hasElementKerning() ? (rhs.m_domFont->elementKerning() ? 1 : 0) : -1; | |
231 if (const int crc = compareInt(kerning, rhsKerning)) | |
232 return crc; | |
233 | |
234 const int antialiasing = m_domFont->hasElementAntialiasing() ? (m_domFont->elementAntialiasing() ? 1 : 0) : -1; | |
235 const int rhsAntialiasing = rhs.m_domFont->hasElementAntialiasing() ? (rhs.m_domFont->elementAntialiasing() ? 1 : 0) : -1; | |
236 if (const int crc = compareInt(antialiasing, rhsAntialiasing)) | |
237 return crc; | |
238 | |
239 const QString styleStrategy = m_domFont->hasElementStyleStrategy() ? m_domFont->elementStyleStrategy() : QString(); | |
240 const QString rhsStyleStrategy = rhs.m_domFont->hasElementStyleStrategy() ? rhs.m_domFont->elementStyleStrategy() : QString(); | |
241 | |
242 if (const int src = styleStrategy.compare(rhsStyleStrategy)) | |
243 return src; | |
244 | |
245 return 0; | |
246 } | |
247 | |
248 IconHandle::IconHandle(const DomResourceIcon *domIcon) : | |
249 m_domIcon(domIcon) | |
250 { | |
251 } | |
252 | |
253 int IconHandle::compare(const IconHandle &rhs) const | |
254 { | |
255 const QString normalOff = m_domIcon->hasElementNormalOff() ? m_domIcon->elementNormalOff()->text() : QString(); | |
256 const QString rhsNormalOff = rhs.m_domIcon->hasElementNormalOff() ? rhs.m_domIcon->elementNormalOff()->text() : QString(); | |
257 if (const int comp = normalOff.compare(rhsNormalOff)) | |
258 return comp; | |
259 | |
260 const QString normalOn = m_domIcon->hasElementNormalOn() ? m_domIcon->elementNormalOn()->text() : QString(); | |
261 const QString rhsNormalOn = rhs.m_domIcon->hasElementNormalOn() ? rhs.m_domIcon->elementNormalOn()->text() : QString(); | |
262 if (const int comp = normalOn.compare(rhsNormalOn)) | |
263 return comp; | |
264 | |
265 const QString disabledOff = m_domIcon->hasElementDisabledOff() ? m_domIcon->elementDisabledOff()->text() : QString(); | |
266 const QString rhsDisabledOff = rhs.m_domIcon->hasElementDisabledOff() ? rhs.m_domIcon->elementDisabledOff()->text() : QString(); | |
267 if (const int comp = disabledOff.compare(rhsDisabledOff)) | |
268 return comp; | |
269 | |
270 const QString disabledOn = m_domIcon->hasElementDisabledOn() ? m_domIcon->elementDisabledOn()->text() : QString(); | |
271 const QString rhsDisabledOn = rhs.m_domIcon->hasElementDisabledOn() ? rhs.m_domIcon->elementDisabledOn()->text() : QString(); | |
272 if (const int comp = disabledOn.compare(rhsDisabledOn)) | |
273 return comp; | |
274 | |
275 const QString activeOff = m_domIcon->hasElementActiveOff() ? m_domIcon->elementActiveOff()->text() : QString(); | |
276 const QString rhsActiveOff = rhs.m_domIcon->hasElementActiveOff() ? rhs.m_domIcon->elementActiveOff()->text() : QString(); | |
277 if (const int comp = activeOff.compare(rhsActiveOff)) | |
278 return comp; | |
279 | |
280 const QString activeOn = m_domIcon->hasElementActiveOn() ? m_domIcon->elementActiveOn()->text() : QString(); | |
281 const QString rhsActiveOn = rhs.m_domIcon->hasElementActiveOn() ? rhs.m_domIcon->elementActiveOn()->text() : QString(); | |
282 if (const int comp = activeOn.compare(rhsActiveOn)) | |
283 return comp; | |
284 | |
285 const QString selectedOff = m_domIcon->hasElementSelectedOff() ? m_domIcon->elementSelectedOff()->text() : QString(); | |
286 const QString rhsSelectedOff = rhs.m_domIcon->hasElementSelectedOff() ? rhs.m_domIcon->elementSelectedOff()->text() : QString(); | |
287 if (const int comp = selectedOff.compare(rhsSelectedOff)) | |
288 return comp; | |
289 | |
290 const QString selectedOn = m_domIcon->hasElementSelectedOn() ? m_domIcon->elementSelectedOn()->text() : QString(); | |
291 const QString rhsSelectedOn = rhs.m_domIcon->hasElementSelectedOn() ? rhs.m_domIcon->elementSelectedOn()->text() : QString(); | |
292 if (const int comp = selectedOn.compare(rhsSelectedOn)) | |
293 return comp; | |
294 // Pre 4.4 Legacy | |
295 if (const int comp = m_domIcon->text().compare(rhs.m_domIcon->text())) | |
296 return comp; | |
297 | |
298 return 0; | |
299 } | |
300 | |
301 | |
302 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) | |
303 inline uint qHash(const SizePolicyHandle &handle) { return qHash(handle.m_domSizePolicy); } | |
304 inline uint qHash(const FontHandle &handle) { return qHash(handle.m_domFont); } | |
305 inline uint qHash(const IconHandle &handle) { return qHash(handle.m_domIcon); } | |
306 #endif | |
307 | |
308 SizePolicyHandle::SizePolicyHandle(const DomSizePolicy *domSizePolicy) : | |
309 m_domSizePolicy(domSizePolicy) | |
310 { | |
311 } | |
312 | |
313 int SizePolicyHandle::compare(const SizePolicyHandle &rhs) const | |
314 { | |
315 | |
316 const int hSizeType = m_domSizePolicy->hasElementHSizeType() ? m_domSizePolicy->elementHSizeType() : -1; | |
317 const int rhsHSizeType = rhs.m_domSizePolicy->hasElementHSizeType() ? rhs.m_domSizePolicy->elementHSizeType() : -1; | |
318 if (const int crc = compareInt(hSizeType, rhsHSizeType)) | |
319 return crc; | |
320 | |
321 const int vSizeType = m_domSizePolicy->hasElementVSizeType() ? m_domSizePolicy->elementVSizeType() : -1; | |
322 const int rhsVSizeType = rhs.m_domSizePolicy->hasElementVSizeType() ? rhs.m_domSizePolicy->elementVSizeType() : -1; | |
323 if (const int crc = compareInt(vSizeType, rhsVSizeType)) | |
324 return crc; | |
325 | |
326 const int hStretch = m_domSizePolicy->hasElementHorStretch() ? m_domSizePolicy->elementHorStretch() : -1; | |
327 const int rhsHStretch = rhs.m_domSizePolicy->hasElementHorStretch() ? rhs.m_domSizePolicy->elementHorStretch() : -1; | |
328 if (const int crc = compareInt(hStretch, rhsHStretch)) | |
329 return crc; | |
330 | |
331 const int vStretch = m_domSizePolicy->hasElementVerStretch() ? m_domSizePolicy->elementVerStretch() : -1; | |
332 const int rhsVStretch = rhs.m_domSizePolicy->hasElementVerStretch() ? rhs.m_domSizePolicy->elementVerStretch() : -1; | |
333 if (const int crc = compareInt(vStretch, rhsVStretch)) | |
334 return crc; | |
335 | |
336 const QString attributeHSizeType = m_domSizePolicy->hasAttributeHSizeType() ? m_domSizePolicy->attributeHSizeType() : QString(); | |
337 const QString rhsAttributeHSizeType = rhs.m_domSizePolicy->hasAttributeHSizeType() ? rhs.m_domSizePolicy->attributeHSizeType() : QString(); | |
338 | |
339 if (const int hrc = attributeHSizeType.compare(rhsAttributeHSizeType)) | |
340 return hrc; | |
341 | |
342 const QString attributeVSizeType = m_domSizePolicy->hasAttributeVSizeType() ? m_domSizePolicy->attributeVSizeType() : QString(); | |
343 const QString rhsAttributeVSizeType = rhs.m_domSizePolicy->hasAttributeVSizeType() ? rhs.m_domSizePolicy->attributeVSizeType() : QString(); | |
344 | |
345 return attributeVSizeType.compare(rhsAttributeVSizeType); | |
346 } | |
347 | |
348 // --- WriteInitialization: LayoutDefaultHandler | |
349 | |
350 WriteInitialization::LayoutDefaultHandler::LayoutDefaultHandler() | |
351 { | |
352 qFill(m_state, m_state + NumProperties, 0u); | |
353 qFill(m_defaultValues, m_defaultValues + NumProperties, 0); | |
354 } | |
355 | |
356 | |
357 | |
358 void WriteInitialization::LayoutDefaultHandler::acceptLayoutDefault(DomLayoutDefault *node) | |
359 { | |
360 if (!node) | |
361 return; | |
362 if (node->hasAttributeMargin()) { | |
363 m_state[Margin] |= HasDefaultValue; | |
364 m_defaultValues[Margin] = node->attributeMargin(); | |
365 } | |
366 if (node->hasAttributeSpacing()) { | |
367 m_state[Spacing] |= HasDefaultValue; | |
368 m_defaultValues[Spacing] = node->attributeSpacing(); | |
369 } | |
370 } | |
371 | |
372 void WriteInitialization::LayoutDefaultHandler::acceptLayoutFunction(DomLayoutFunction *node) | |
373 { | |
374 if (!node) | |
375 return; | |
376 if (node->hasAttributeMargin()) { | |
377 m_state[Margin] |= HasDefaultFunction; | |
378 m_functions[Margin] = node->attributeMargin(); | |
379 m_functions[Margin] += QLatin1String("()"); | |
380 } | |
381 if (node->hasAttributeSpacing()) { | |
382 m_state[Spacing] |= HasDefaultFunction; | |
383 m_functions[Spacing] = node->attributeSpacing(); | |
384 m_functions[Spacing] += QLatin1String("()"); | |
385 } | |
386 } | |
387 | |
388 void WriteInitialization::LayoutDefaultHandler::writeProperty(int p, const QString &indent, const QString &objectName, | |
389 const DomPropertyMap &properties, const QString &propertyName, const QString &setter, | |
390 int defaultStyleValue, bool suppressDefault, QTextStream &str) const | |
391 { | |
392 // User value | |
393 const DomPropertyMap::const_iterator mit = properties.constFind(propertyName); | |
394 const bool found = mit != properties.constEnd(); | |
395 if (found) { | |
396 const int value = mit.value()->elementNumber(); | |
397 // Emulate the pre 4.3 behaviour: The value form default value was only used to determine | |
398 // the default value, layout properties were always written | |
399 const bool useLayoutFunctionPre43 = !suppressDefault && (m_state[p] == (HasDefaultFunction|HasDefaultValue)) && value == m_defaultValues[p]; | |
400 if (!useLayoutFunctionPre43) { | |
401 bool ifndefMac = (!(m_state[p] & (HasDefaultFunction|HasDefaultValue)) | |
402 && value == defaultStyleValue); | |
403 if (ifndefMac) | |
404 str << "#ifndef Q_OS_MAC\n"; | |
405 writeSetter(indent, objectName, setter, value, str); | |
406 if (ifndefMac) | |
407 str << "#endif\n"; | |
408 return; | |
409 } | |
410 } | |
411 if (suppressDefault) | |
412 return; | |
413 // get default | |
414 if (m_state[p] & HasDefaultFunction) { | |
415 writeSetter(indent, objectName, setter, m_functions[p], str); | |
416 return; | |
417 } | |
418 if (m_state[p] & HasDefaultValue) { | |
419 writeSetter(indent, objectName, setter, m_defaultValues[p], str); | |
420 } | |
421 return; | |
422 } | |
423 | |
424 | |
425 void WriteInitialization::LayoutDefaultHandler::writeProperties(const QString &indent, const QString &varName, | |
426 const DomPropertyMap &properties, int marginType, | |
427 bool suppressMarginDefault, | |
428 QTextStream &str) const { | |
429 // Write out properties and ignore the ones found in | |
430 // subsequent writing of the property list. | |
431 int defaultSpacing = marginType == WriteInitialization::Use43UiFile ? -1 : 6; | |
432 writeProperty(Spacing, indent, varName, properties, QLatin1String("spacing"), QLatin1String("setSpacing"), | |
433 defaultSpacing, false, str); | |
434 // We use 9 as TopLevelMargin, since Designer seem to always use 9. | |
435 static const int layoutmargins[4] = {-1, 9, 9, 0}; | |
436 writeProperty(Margin, indent, varName, properties, QLatin1String("margin"), QLatin1String("setMargin"), | |
437 layoutmargins[marginType], suppressMarginDefault, str); | |
438 } | |
439 | |
440 // --- WriteInitialization | |
441 WriteInitialization::WriteInitialization(Uic *uic, bool activateScripts) : | |
442 m_uic(uic), | |
443 m_driver(uic->driver()), m_output(uic->output()), m_option(uic->option()), | |
444 m_layoutMarginType(TopLevelMargin), | |
445 m_delayedOut(&m_delayedInitialization, QIODevice::WriteOnly), | |
446 m_refreshOut(&m_refreshInitialization, QIODevice::WriteOnly), | |
447 m_actionOut(&m_delayedActionInitialization, QIODevice::WriteOnly), | |
448 m_activateScripts(activateScripts), m_layoutWidget(false) | |
449 { | |
450 } | |
451 | |
452 void WriteInitialization::acceptUI(DomUI *node) | |
453 { | |
454 m_registeredImages.clear(); | |
455 m_actionGroupChain.push(0); | |
456 m_widgetChain.push(0); | |
457 m_layoutChain.push(0); | |
458 | |
459 acceptLayoutDefault(node->elementLayoutDefault()); | |
460 acceptLayoutFunction(node->elementLayoutFunction()); | |
461 | |
462 if (node->elementCustomWidgets()) | |
463 TreeWalker::acceptCustomWidgets(node->elementCustomWidgets()); | |
464 | |
465 if (node->elementImages()) | |
466 TreeWalker::acceptImages(node->elementImages()); | |
467 | |
468 if (m_option.generateImplemetation) | |
469 m_output << "#include <" << m_driver->headerFileName() << ">\n\n"; | |
470 | |
471 m_stdsetdef = true; | |
472 if (node->hasAttributeStdSetDef()) | |
473 m_stdsetdef = node->attributeStdSetDef(); | |
474 | |
475 const QString className = node->elementClass() + m_option.postfix; | |
476 m_generatedClass = className; | |
477 | |
478 const QString varName = m_driver->findOrInsertWidget(node->elementWidget()); | |
479 m_registeredWidgets.insert(varName, node->elementWidget()); // register the main widget | |
480 | |
481 const QString widgetClassName = node->elementWidget()->attributeClass(); | |
482 | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
483 m_output << m_option.indent << "void " << "setupUi(" << widgetClassName << " " << varName << ")\n" |
1 | 484 << m_option.indent << "{\n"; |
485 | |
486 if (m_activateScripts) | |
487 writeSetupUIScriptVariableDeclarations( m_option.indent, m_output); | |
488 | |
489 const QStringList connections = m_uic->databaseInfo()->connections(); | |
490 for (int i=0; i<connections.size(); ++i) { | |
491 QString connection = connections.at(i); | |
492 | |
493 if (connection == QLatin1String("(default)")) | |
494 continue; | |
495 | |
496 const QString varConn = connection + QLatin1String("Connection"); | |
497 m_output << m_option.indent << varConn << " = QSqlDatabase::database(" << fixString(connection, m_option.indent) << ");\n"; | |
498 } | |
499 | |
500 acceptWidget(node->elementWidget()); | |
501 | |
502 if (m_buddies.size() > 0) | |
503 openIfndef(m_output, QLatin1String(shortcutDefineC)); | |
504 for (int i=0; i<m_buddies.size(); ++i) { | |
505 const Buddy &b = m_buddies.at(i); | |
506 | |
507 if (!m_registeredWidgets.contains(b.objName)) { | |
508 fprintf(stderr, "'%s' isn't a valid widget\n", b.objName.toLatin1().data()); | |
509 continue; | |
510 } else if (!m_registeredWidgets.contains(b.buddy)) { | |
511 fprintf(stderr, "'%s' isn't a valid widget\n", b.buddy.toLatin1().data()); | |
512 continue; | |
513 } | |
514 | |
515 m_output << m_option.indent << b.objName << ".setBuddy(" << b.buddy << ");\n"; | |
516 } | |
517 if (m_buddies.size() > 0) | |
518 closeIfdef(m_output, QLatin1String(shortcutDefineC)); | |
519 | |
520 if (node->elementTabStops()) | |
521 acceptTabStops(node->elementTabStops()); | |
522 | |
523 if (m_delayedActionInitialization.size()) | |
524 m_output << "\n" << m_delayedActionInitialization; | |
525 | |
526 m_output << "\n" << m_option.indent << "retranslateUi(" << varName << ");\n"; | |
527 | |
528 if (node->elementConnections()) | |
529 acceptConnections(node->elementConnections()); | |
530 | |
531 if (!m_delayedInitialization.isEmpty()) | |
532 m_output << "\n" << m_delayedInitialization << "\n"; | |
533 | |
534 if (m_option.autoConnection) | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
535 m_output << "\n" << m_option.indent << "// QMetaObject.connectSlotsByName(" << varName << ");\n"; |
1 | 536 |
537 m_output << m_option.indent << "} // setupUi\n\n"; | |
538 | |
539 if (m_delayedActionInitialization.isEmpty()) { | |
540 m_refreshInitialization += m_option.indent; | |
541 m_refreshInitialization += QLatin1String("Q_UNUSED("); | |
542 m_refreshInitialization += varName ; | |
543 m_refreshInitialization +=QLatin1String(");\n"); | |
544 } | |
545 | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
546 m_output << m_option.indent << "void " << "retranslateUi(" << widgetClassName << " " << varName << ")\n" |
1 | 547 << m_option.indent << "{\n" |
548 << m_refreshInitialization | |
549 << m_option.indent << "} // retranslateUi\n\n"; | |
550 | |
551 m_layoutChain.pop(); | |
552 m_widgetChain.pop(); | |
553 m_actionGroupChain.pop(); | |
554 } | |
555 | |
556 void WriteInitialization::acceptWidget(DomWidget *node) | |
557 { | |
558 m_layoutMarginType = m_widgetChain.count() == 1 ? TopLevelMargin : ChildMargin; | |
559 const QString className = node->attributeClass(); | |
560 const QString varName = m_driver->findOrInsertWidget(node); | |
561 m_registeredWidgets.insert(varName, node); // register the current widget | |
562 | |
563 QString parentWidget, parentClass; | |
564 if (m_widgetChain.top()) { | |
565 parentWidget = m_driver->findOrInsertWidget(m_widgetChain.top()); | |
566 parentClass = m_widgetChain.top()->attributeClass(); | |
567 } | |
568 | |
569 const QString savedParentWidget = parentWidget; | |
570 | |
571 if (m_uic->isContainer(parentClass) || m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("Q3ToolBar"))) | |
572 parentWidget.clear(); | |
573 | |
574 if (m_widgetChain.size() != 1) | |
575 m_output << m_option.indent << varName << " = new " << m_uic->customWidgetsInfo()->realClassName(className) << '(' << parentWidget << ");\n"; | |
576 | |
577 parentWidget = savedParentWidget; | |
578 | |
579 if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QComboBox"))) { | |
580 initializeComboBox(node); | |
581 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) { | |
582 initializeListWidget(node); | |
583 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTreeWidget"))) { | |
584 initializeTreeWidget(node); | |
585 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTableWidget"))) { | |
586 initializeTableWidget(node); | |
587 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3ListBox"))) { | |
588 initializeQ3ListBox(node); | |
589 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3ListView"))) { | |
590 initializeQ3ListView(node); | |
591 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3IconView"))) { | |
592 initializeQ3IconView(node); | |
593 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3Table"))) { | |
594 initializeQ3Table(node); | |
595 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3DataTable"))) { | |
596 initializeQ3SqlDataTable(node); | |
597 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("Q3DataBrowser"))) { | |
598 initializeQ3SqlDataBrowser(node); | |
599 } | |
600 | |
601 if (m_uic->isButton(className)) { | |
602 const DomPropertyMap attributes = propertyMap(node->elementAttribute()); | |
603 if (const DomProperty *prop = attributes.value(QLatin1String("buttonGroup"))) { | |
604 const QString groupName = toString(prop->elementString()); | |
605 if (!m_buttonGroups.contains(groupName)) { | |
606 m_buttonGroups.insert(groupName, m_driver->findOrInsertName(groupName)); | |
607 const QString g = m_buttonGroups.value(groupName); | |
608 m_output << m_option.indent << "QButtonGroup *" << g << " = new QButtonGroup(" << m_generatedClass << ");\n"; | |
609 } | |
610 | |
611 const QString g = m_buttonGroups.value(groupName); | |
612 m_output << m_option.indent << g << ".addButton(" << varName << ");\n"; | |
613 } | |
614 } | |
615 | |
616 writeProperties(varName, className, node->elementProperty()); | |
617 | |
618 if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QMenu")) && parentWidget.size()) { | |
619 initializeMenu(node, parentWidget); | |
620 } | |
621 | |
622 if (node->elementLayout().isEmpty()) | |
623 m_layoutChain.push(0); | |
624 | |
625 m_layoutWidget = false; | |
626 if (className == QLatin1String("QWidget") && !node->hasAttributeNative()) { | |
627 if (m_widgetChain.top() | |
628 && m_widgetChain.top()->attributeClass() != QLatin1String("QMainWindow") | |
629 && !m_uic->isContainer(m_widgetChain.top()->attributeClass())) | |
630 m_layoutWidget = true; | |
631 } | |
632 m_widgetChain.push(node); | |
633 m_layoutChain.push(0); | |
634 TreeWalker::acceptWidget(node); | |
635 m_layoutChain.pop(); | |
636 m_widgetChain.pop(); | |
637 m_layoutWidget = false; | |
638 | |
639 const DomPropertyMap attributes = propertyMap(node->elementAttribute()); | |
640 | |
641 QString title = QLatin1String("Page"); | |
642 if (const DomProperty *ptitle = attributes.value(QLatin1String("title"))) { | |
643 title = toString(ptitle->elementString()); | |
644 } | |
645 | |
646 QString label = QLatin1String("Page"); | |
647 if (const DomProperty *plabel = attributes.value(QLatin1String("label"))) { | |
648 label = toString(plabel->elementString()); | |
649 } | |
650 | |
651 int id = -1; | |
652 if (const DomProperty *pid = attributes.value(QLatin1String("id"))) { | |
653 id = pid->elementNumber(); | |
654 } | |
655 | |
656 if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QMainWindow")) | |
657 || m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("Q3MainWindow"))) { | |
658 | |
659 if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QMenuBar"))) { | |
660 if (!m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("Q3MainWindow"))) | |
661 m_output << m_option.indent << parentWidget << ".setMenuBar(" << varName <<");\n"; | |
662 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBar"))) { | |
663 m_output << m_option.indent << parentWidget << ".addToolBar(" | |
664 << toolBarAreaStringFromDOMAttributes(attributes) << varName << ");\n"; | |
665 | |
666 if (const DomProperty *pbreak = attributes.value(QLatin1String("toolBarBreak"))) { | |
667 if (pbreak->elementBool() == QLatin1String("true")) { | |
668 m_output << m_option.indent << parentWidget << ".insertToolBarBreak(" << varName << ");\n"; | |
669 } | |
670 } | |
671 | |
672 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QDockWidget"))) { | |
673 QString area; | |
674 if (DomProperty *pstyle = attributes.value(QLatin1String("dockWidgetArea"))) { | |
48 | 675 area += QLatin1String("(cast(Qt.DockWidgetArea)("); |
1 | 676 area += QString::number(pstyle->elementNumber()); |
677 area += QLatin1String(")), "); | |
678 } | |
679 | |
680 m_output << m_option.indent << parentWidget << ".addDockWidget(" << area << varName << ");\n"; | |
681 } else if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStatusBar"))) { | |
682 m_output << m_option.indent << parentWidget << ".setStatusBar(" << varName << ");\n"; | |
683 } else if (className == QLatin1String("QWidget")) { | |
684 m_output << m_option.indent << parentWidget << ".setCentralWidget(" << varName << ");\n"; | |
685 } | |
686 } | |
687 | |
688 // Check for addPageMethod of a custom plugin first | |
689 const QString addPageMethod = m_uic->customWidgetsInfo()->customWidgetAddPageMethod(parentClass); | |
690 if (!addPageMethod.isEmpty()) { | |
691 m_output << m_option.indent << parentWidget << "." << addPageMethod << '(' << varName << ");\n"; | |
692 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QStackedWidget"))) { | |
693 m_output << m_option.indent << parentWidget << ".addWidget(" << varName << ");\n"; | |
694 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QToolBar"))) { | |
695 m_output << m_option.indent << parentWidget << ".addWidget(" << varName << ");\n"; | |
696 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("Q3WidgetStack"))) { | |
697 m_output << m_option.indent << parentWidget << ".addWidget(" << varName << ", " << id << ");\n"; | |
698 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QDockWidget"))) { | |
699 m_output << m_option.indent << parentWidget << ".setWidget(" << varName << ");\n"; | |
700 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QScrollArea"))) { | |
701 m_output << m_option.indent << parentWidget << ".setWidget(" << varName << ");\n"; | |
702 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QSplitter"))) { | |
703 m_output << m_option.indent << parentWidget << ".addWidget(" << varName << ");\n"; | |
704 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QMdiArea"))) { | |
705 m_output << m_option.indent << parentWidget << ".addSubWindow(" << varName << ");\n"; | |
706 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QWorkspace"))) { | |
707 m_output << m_option.indent << parentWidget << ".addWindow(" << varName << ");\n"; | |
708 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QWizard"))) { | |
709 m_output << m_option.indent << parentWidget << ".addPage(" << varName << ");\n"; | |
710 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QToolBox"))) { | |
711 QString icon; | |
712 if (const DomProperty *picon = attributes.value(QLatin1String("icon"))) { | |
713 icon += QLatin1String(", ") ; | |
714 icon += iconCall(picon); | |
715 } | |
716 | |
717 m_output << m_option.indent << parentWidget << ".addItem(" << varName << icon << ", " << trCall(label) << ");\n"; | |
718 | |
719 m_refreshOut << m_option.indent << parentWidget << ".setItemText(" | |
720 << parentWidget << ".indexOf(" << varName << "), " << trCall(label) << ");\n"; | |
721 | |
722 #ifndef QT_NO_TOOLTIP | |
723 if (DomProperty *ptoolTip = attributes.value(QLatin1String("toolTip"))) { | |
724 m_refreshOut << m_option.indent << parentWidget << ".setItemToolTip(" | |
725 << parentWidget << ".indexOf(" << varName << "), " << trCall(ptoolTip->elementString()) << ");\n"; | |
726 } | |
727 #endif // QT_NO_TOOLTIP | |
728 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("QTabWidget"))) { | |
729 QString icon; | |
730 if (const DomProperty *picon = attributes.value(QLatin1String("icon"))) { | |
731 icon += QLatin1String(", "); | |
732 icon += iconCall(picon); | |
733 } | |
734 | |
78 | 735 m_output << m_option.indent << parentWidget << ".addTab(" << varName << icon << ", " << "null);\n"; |
1 | 736 |
737 m_refreshOut << m_option.indent << parentWidget << ".setTabText(" | |
738 << parentWidget << ".indexOf(" << varName << "), " << trCall(title) << ");\n"; | |
739 | |
740 #ifndef QT_NO_TOOLTIP | |
741 if (const DomProperty *ptoolTip = attributes.value(QLatin1String("toolTip"))) { | |
742 m_refreshOut << m_option.indent << parentWidget << ".setTabToolTip(" | |
743 << parentWidget << ".indexOf(" << varName << "), " << trCall(ptoolTip->elementString()) << ");\n"; | |
744 } | |
745 #endif // QT_NO_TOOLTIP | |
746 } else if (m_uic->customWidgetsInfo()->extends(parentClass, QLatin1String("Q3Wizard"))) { | |
747 m_output << m_option.indent << parentWidget << ".addPage(" << varName << ", " << trCall(title) << ");\n"; | |
748 | |
749 m_refreshOut << m_option.indent << parentWidget << ".setTitle(" | |
750 << varName << ", " << trCall(title) << ");\n"; | |
751 | |
752 } | |
753 | |
754 if (node->elementLayout().isEmpty()) | |
755 m_layoutChain.pop(); | |
756 | |
757 const QStringList zOrder = node->elementZOrder(); | |
758 for (int i = 0; i < zOrder.size(); ++i) { | |
759 const QString name = zOrder.at(i); | |
760 | |
761 if (!m_registeredWidgets.contains(name)) { | |
762 fprintf(stderr, "'%s' isn't a valid widget\n", name.toLatin1().data()); | |
763 continue; | |
764 } | |
765 | |
766 if (name.isEmpty()) { | |
767 continue; | |
768 } | |
769 | |
770 m_output << m_option.indent << name << ".raise();\n"; | |
771 } | |
772 } | |
773 | |
774 | |
775 void WriteInitialization::acceptLayout(DomLayout *node) | |
776 { | |
777 const QString className = node->attributeClass(); | |
778 const QString varName = m_driver->findOrInsertLayout(node); | |
779 | |
780 const DomPropertyMap properties = propertyMap(node->elementProperty()); | |
781 const bool oldLayoutProperties = properties.constFind(QLatin1String("margin")) != properties.constEnd(); | |
782 | |
783 bool isGroupBox = false; | |
784 | |
785 if (m_widgetChain.top()) { | |
786 const QString parentWidget = m_widgetChain.top()->attributeClass(); | |
787 | |
788 if (!m_layoutChain.top() && (m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3GroupBox")) | |
789 || m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3ButtonGroup")))) { | |
790 const QString parent = m_driver->findOrInsertWidget(m_widgetChain.top()); | |
791 | |
792 isGroupBox = true; | |
793 // special case for group box | |
794 | |
48 | 795 m_output << m_option.indent << parent << ".setColumnLayout(0, Qt.Vertical);\n"; |
1 | 796 QString objectName = parent; |
797 objectName += QLatin1String(".layout()"); | |
798 int marginType = Use43UiFile; | |
799 if (oldLayoutProperties) | |
800 marginType = m_layoutMarginType; | |
801 | |
802 m_LayoutDefaultHandler.writeProperties(m_option.indent, | |
803 objectName, properties, marginType, false, m_output); | |
804 } | |
805 } | |
806 | |
807 m_output << m_option.indent << varName << " = new " << className << '('; | |
808 | |
809 if (!m_layoutChain.top() && !isGroupBox) | |
810 m_output << m_driver->findOrInsertWidget(m_widgetChain.top()); | |
811 | |
812 m_output << ");\n"; | |
813 | |
814 if (isGroupBox) { | |
815 const QString tempName = m_driver->unique(QLatin1String("boxlayout")); | |
48 | 816 m_output << m_option.indent << "QBoxLayout " << tempName << " = qobject_cast<QBoxLayout *>(" << |
1 | 817 m_driver->findOrInsertWidget(m_widgetChain.top()) << ".layout());\n"; |
818 m_output << m_option.indent << "if (" << tempName << ")\n"; | |
819 m_output << m_option.indent << " " << tempName << ".addLayout(" << varName << ");\n"; | |
820 } | |
821 | |
822 if (isGroupBox) { | |
48 | 823 m_output << m_option.indent << varName << ".setAlignment(Qt.AlignTop);\n"; |
1 | 824 } else { |
825 // Suppress margin on a read child layout | |
826 const bool suppressMarginDefault = m_layoutChain.top(); | |
827 int marginType = Use43UiFile; | |
828 if (oldLayoutProperties) | |
829 marginType = m_layoutMarginType; | |
830 m_LayoutDefaultHandler.writeProperties(m_option.indent, varName, properties, marginType, suppressMarginDefault, m_output); | |
831 } | |
832 | |
833 m_layoutMarginType = SubLayoutMargin; | |
834 | |
835 DomPropertyList propList = node->elementProperty(); | |
836 if (m_layoutWidget) { | |
837 bool left, top, right, bottom; | |
838 left = top = right = bottom = false; | |
839 for (int i = 0; i < propList.size(); ++i) { | |
840 const DomProperty *p = propList.at(i); | |
841 const QString propertyName = p->attributeName(); | |
842 if (propertyName == QLatin1String("leftMargin") && p->kind() == DomProperty::Number) | |
843 left = true; | |
844 else if (propertyName == QLatin1String("topMargin") && p->kind() == DomProperty::Number) | |
845 top = true; | |
846 else if (propertyName == QLatin1String("rightMargin") && p->kind() == DomProperty::Number) | |
847 right = true; | |
848 else if (propertyName == QLatin1String("bottomMargin") && p->kind() == DomProperty::Number) | |
849 bottom = true; | |
850 } | |
851 if (!left) { | |
852 DomProperty *p = new DomProperty(); | |
853 p->setAttributeName(QLatin1String("leftMargin")); | |
854 p->setElementNumber(0); | |
855 propList.append(p); | |
856 } | |
857 if (!top) { | |
858 DomProperty *p = new DomProperty(); | |
859 p->setAttributeName(QLatin1String("topMargin")); | |
860 p->setElementNumber(0); | |
861 propList.append(p); | |
862 } | |
863 if (!right) { | |
864 DomProperty *p = new DomProperty(); | |
865 p->setAttributeName(QLatin1String("rightMargin")); | |
866 p->setElementNumber(0); | |
867 propList.append(p); | |
868 } | |
869 if (!bottom) { | |
870 DomProperty *p = new DomProperty(); | |
871 p->setAttributeName(QLatin1String("bottomMargin")); | |
872 p->setElementNumber(0); | |
873 propList.append(p); | |
874 } | |
875 m_layoutWidget = false; | |
876 } | |
877 | |
878 writeProperties(varName, className, propList, WritePropertyIgnoreMargin|WritePropertyIgnoreSpacing); | |
879 | |
880 m_layoutChain.push(node); | |
881 TreeWalker::acceptLayout(node); | |
882 m_layoutChain.pop(); | |
883 } | |
884 | |
885 void WriteInitialization::acceptSpacer(DomSpacer *node) | |
886 { | |
887 m_output << m_option.indent << m_driver->findOrInsertSpacer(node) << " = "; | |
888 writeSpacerItem(node, m_output); | |
889 m_output << ";\n"; | |
890 } | |
891 | |
892 void WriteInitialization::acceptLayoutItem(DomLayoutItem *node) | |
893 { | |
894 TreeWalker::acceptLayoutItem(node); | |
895 | |
896 DomLayout *layout = m_layoutChain.top(); | |
897 | |
898 if (!layout) | |
899 return; | |
900 | |
901 const QString layoutName = m_driver->findOrInsertLayout(layout); | |
902 const QString itemName = m_driver->findOrInsertLayoutItem(node); | |
903 | |
904 QString addArgs; | |
905 QString methodPrefix = QLatin1String("add"); //Consistent API-design galore! | |
906 if (layout->attributeClass() == QLatin1String("QGridLayout")) { | |
907 const int row = node->attributeRow(); | |
908 const int col = node->attributeColumn(); | |
909 | |
910 int rowSpan = 1; | |
911 if (node->hasAttributeRowSpan()) | |
912 rowSpan = node->attributeRowSpan(); | |
913 | |
914 int colSpan = 1; | |
915 if (node->hasAttributeColSpan()) | |
916 colSpan = node->attributeColSpan(); | |
917 | |
918 addArgs = QString::fromLatin1("%1, %2, %3, %4, %5").arg(itemName).arg(row).arg(col).arg(rowSpan).arg(colSpan); | |
919 } else { | |
920 if (layout->attributeClass() == QLatin1String("QFormLayout")) { | |
921 methodPrefix = QLatin1String("set"); | |
922 const int row = node->attributeRow(); | |
48 | 923 const QString role = node->attributeColumn() == 0 ? QLatin1String("QFormLayout.LabelRole") : QLatin1String("QFormLayout.FieldRole"); |
1 | 924 addArgs = QString::fromLatin1("%1, %2, %3").arg(row).arg(role).arg(itemName); |
925 } else { | |
926 addArgs = itemName; | |
927 } | |
928 } | |
929 | |
930 // figure out "add" method | |
931 m_output << "\n" << m_option.indent << layoutName << "."; | |
932 switch (node->kind()) { | |
933 case DomLayoutItem::Widget: | |
934 m_output << methodPrefix << "Widget(" << addArgs; | |
935 break; | |
936 case DomLayoutItem::Layout: | |
937 m_output << methodPrefix << "Layout(" << addArgs; | |
938 break; | |
939 case DomLayoutItem::Spacer: | |
940 m_output << methodPrefix << "Item(" << addArgs; | |
941 break; | |
942 case DomLayoutItem::Unknown: | |
943 Q_ASSERT( 0 ); | |
944 break; | |
945 } | |
946 m_output << ");\n\n"; | |
947 } | |
948 | |
949 void WriteInitialization::acceptActionGroup(DomActionGroup *node) | |
950 { | |
951 const QString actionName = m_driver->findOrInsertActionGroup(node); | |
952 QString varName = m_driver->findOrInsertWidget(m_widgetChain.top()); | |
953 | |
954 if (m_actionGroupChain.top()) | |
955 varName = m_driver->findOrInsertActionGroup(m_actionGroupChain.top()); | |
956 | |
957 m_output << m_option.indent << actionName << " = new QActionGroup(" << varName << ");\n"; | |
958 writeProperties(actionName, QLatin1String("QActionGroup"), node->elementProperty()); | |
959 | |
960 m_actionGroupChain.push(node); | |
961 TreeWalker::acceptActionGroup(node); | |
962 m_actionGroupChain.pop(); | |
963 } | |
964 | |
965 void WriteInitialization::acceptAction(DomAction *node) | |
966 { | |
967 if (node->hasAttributeMenu()) | |
968 return; | |
969 | |
970 const QString actionName = m_driver->findOrInsertAction(node); | |
971 m_registeredActions.insert(actionName, node); | |
972 QString varName = m_driver->findOrInsertWidget(m_widgetChain.top()); | |
973 | |
974 if (m_actionGroupChain.top()) | |
975 varName = m_driver->findOrInsertActionGroup(m_actionGroupChain.top()); | |
976 | |
977 m_output << m_option.indent << actionName << " = new QAction(" << varName << ");\n"; | |
978 writeProperties(actionName, QLatin1String("QAction"), node->elementProperty()); | |
979 } | |
980 | |
981 void WriteInitialization::acceptActionRef(DomActionRef *node) | |
982 { | |
983 QString actionName = node->attributeName(); | |
984 const bool isSeparator = actionName == QLatin1String("separator"); | |
985 bool isMenu = false; | |
986 | |
987 QString varName = m_driver->findOrInsertWidget(m_widgetChain.top()); | |
988 | |
989 if (actionName.isEmpty() || !m_widgetChain.top()) { | |
990 return; | |
991 } else if (m_driver->actionGroupByName(actionName)) { | |
992 return; | |
993 } else if (DomWidget *w = m_driver->widgetByName(actionName)) { | |
994 isMenu = m_uic->isMenu(w->attributeClass()); | |
995 bool inQ3ToolBar = m_uic->customWidgetsInfo()->extends(m_widgetChain.top()->attributeClass(), QLatin1String("Q3ToolBar")); | |
996 if (!isMenu && inQ3ToolBar) { | |
997 m_actionOut << m_option.indent << actionName << ".setParent(" << varName << ");\n"; | |
998 return; | |
999 } | |
1000 } else if (!(m_driver->actionByName(actionName) || isSeparator)) { | |
1001 fprintf(stderr, "Warning: action `%s' not declared\n", actionName.toLatin1().data()); | |
1002 return; | |
1003 } | |
1004 | |
1005 if (m_widgetChain.top() && isSeparator) { | |
1006 // separator is always reserved! | |
1007 m_actionOut << m_option.indent << varName << ".addSeparator();\n"; | |
1008 return; | |
1009 } | |
1010 | |
1011 if (isMenu) | |
1012 actionName += QLatin1String(".menuAction()"); | |
1013 | |
1014 m_actionOut << m_option.indent << varName << ".addAction(" << actionName << ");\n"; | |
1015 } | |
1016 | |
1017 void WriteInitialization::writeProperties(const QString &varName, | |
1018 const QString &className, | |
1019 const DomPropertyList &lst, | |
1020 unsigned flags) | |
1021 { | |
1022 const bool isTopLevel = m_widgetChain.count() == 1; | |
1023 | |
1024 if (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) { | |
1025 DomPropertyMap properties = propertyMap(lst); | |
1026 if (properties.contains(QLatin1String("control"))) { | |
1027 DomProperty *p = properties.value(QLatin1String("control")); | |
48 | 1028 m_output << m_option.indent << varName << ".setControl(QString.fromUtf8(" |
1 | 1029 << fixString(toString(p->elementString()), m_option.indent) << "));\n"; |
1030 } | |
1031 } | |
1032 | |
1033 DomWidget *buttonGroupWidget = findWidget(QLatin1String("Q3ButtonGroup")); | |
1034 | |
1035 QString indent; | |
1036 if (!m_widgetChain.top()) { | |
1037 indent = QLatin1String(" "); | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
1038 m_output << m_option.indent << "if (" << varName << ".objectName().length == 0)\n"; |
1 | 1039 } |
48 | 1040 m_output << m_option.indent << indent << varName << ".setObjectName(QString.fromUtf8(" << fixString(varName, m_option.indent) << "));\n"; |
1 | 1041 |
1042 int leftMargin, topMargin, rightMargin, bottomMargin; | |
1043 leftMargin = topMargin = rightMargin = bottomMargin = -1; | |
1044 bool frameShadowEncountered = false; | |
1045 | |
1046 for (int i=0; i<lst.size(); ++i) { | |
1047 const DomProperty *p = lst.at(i); | |
1048 if (!checkProperty(m_option.inputFile, p)) | |
1049 continue; | |
1050 const QString propertyName = p->attributeName(); | |
1051 QString propertyValue; | |
1052 | |
1053 // special case for the property `geometry': Do not use position | |
1054 if (isTopLevel && propertyName == QLatin1String("geometry") && p->elementRect()) { | |
1055 const DomRect *r = p->elementRect(); | |
1056 m_output << m_option.indent << varName << ".resize(" << r->elementWidth() << ", " << r->elementHeight() << ");\n"; | |
1057 continue; | |
1058 } else if (propertyName == QLatin1String("buttonGroupId") && buttonGroupWidget) { // Q3ButtonGroup support | |
1059 m_output << m_option.indent << m_driver->findOrInsertWidget(buttonGroupWidget) << ".insert(" | |
1060 << varName << ", " << p->elementNumber() << ");\n"; | |
1061 continue; | |
1062 } else if (propertyName == QLatin1String("currentRow") // QListWidget::currentRow | |
1063 && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QListWidget"))) { | |
1064 m_delayedOut << m_option.indent << varName << ".setCurrentRow(" | |
1065 << p->elementNumber() << ");\n"; | |
1066 continue; | |
1067 } else if (propertyName == QLatin1String("currentIndex") // set currentIndex later | |
1068 && (m_uic->customWidgetsInfo()->extends(className, QLatin1String("QComboBox")) | |
1069 || m_uic->customWidgetsInfo()->extends(className, QLatin1String("QStackedWidget")) | |
1070 || m_uic->customWidgetsInfo()->extends(className, QLatin1String("QTabWidget")) | |
1071 || m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox")))) { | |
1072 m_delayedOut << m_option.indent << varName << ".setCurrentIndex(" | |
1073 << p->elementNumber() << ");\n"; | |
1074 continue; | |
1075 } else if (propertyName == QLatin1String("tabSpacing") | |
1076 && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QToolBox"))) { | |
1077 m_delayedOut << m_option.indent << varName << ".layout()->setSpacing(" | |
1078 << p->elementNumber() << ");\n"; | |
1079 continue; | |
1080 } else if (propertyName == QLatin1String("control") // ActiveQt support | |
1081 && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QAxWidget"))) { | |
1082 // already done ;) | |
1083 continue; | |
1084 } else if (propertyName == QLatin1String("database") | |
1085 && p->elementStringList()) { | |
1086 // Sql support | |
1087 continue; | |
1088 } else if (propertyName == QLatin1String("frameworkCode") | |
1089 && p->kind() == DomProperty::Bool) { | |
1090 // Sql support | |
1091 continue; | |
1092 } else if (propertyName == QLatin1String("orientation") | |
1093 && m_uic->customWidgetsInfo()->extends(className, QLatin1String("Line"))) { | |
1094 // Line support | |
48 | 1095 QString shape = QLatin1String("QFrame.HLine"); |
1096 if (p->elementEnum() == QLatin1String("Qt.Vertical")) | |
1097 shape = QLatin1String("QFrame.VLine"); | |
1 | 1098 |
1099 m_output << m_option.indent << varName << ".setFrameShape(" << shape << ");\n"; | |
1100 // QFrame Default is 'Plain'. Make the line 'Sunken' unless otherwise specified | |
1101 if (!frameShadowEncountered) | |
48 | 1102 m_output << m_option.indent << varName << ".setFrameShadow(QFrame.Sunken);\n"; |
1 | 1103 continue; |
1104 } else if ((flags & WritePropertyIgnoreMargin) && propertyName == QLatin1String("margin")) { | |
1105 continue; | |
1106 } else if ((flags & WritePropertyIgnoreSpacing) && propertyName == QLatin1String("spacing")) { | |
1107 continue; | |
1108 } else if (propertyName == QLatin1String("leftMargin") && p->kind() == DomProperty::Number) { | |
1109 leftMargin = p->elementNumber(); | |
1110 continue; | |
1111 } else if (propertyName == QLatin1String("topMargin") && p->kind() == DomProperty::Number) { | |
1112 topMargin = p->elementNumber(); | |
1113 continue; | |
1114 } else if (propertyName == QLatin1String("rightMargin") && p->kind() == DomProperty::Number) { | |
1115 rightMargin = p->elementNumber(); | |
1116 continue; | |
1117 } else if (propertyName == QLatin1String("bottomMargin") && p->kind() == DomProperty::Number) { | |
1118 bottomMargin = p->elementNumber(); | |
1119 continue; | |
1120 } else if (propertyName == QLatin1String("frameShadow")) | |
1121 frameShadowEncountered = true; | |
1122 | |
1123 bool stdset = m_stdsetdef; | |
1124 if (p->hasAttributeStdset()) | |
1125 stdset = p->attributeStdset(); | |
1126 | |
1127 QString setFunction; | |
1128 | |
1129 if (stdset) { | |
1130 setFunction = QLatin1String(".set"); | |
1131 setFunction += propertyName.left(1).toUpper(); | |
1132 setFunction += propertyName.mid(1); | |
1133 setFunction += QLatin1Char('('); | |
1134 } else { | |
1135 setFunction = QLatin1String(".setProperty(\""); | |
1136 setFunction += propertyName; | |
1137 setFunction += QLatin1String("\", QVariant("); | |
1138 } | |
1139 | |
1140 QString varNewName = varName; | |
1141 | |
1142 switch (p->kind()) { | |
1143 case DomProperty::Bool: { | |
1144 propertyValue = p->elementBool(); | |
1145 break; | |
1146 } | |
1147 case DomProperty::Color: | |
1148 propertyValue = domColor2QString(p->elementColor()); | |
1149 break; | |
1150 case DomProperty::Cstring: | |
1151 if (propertyName == QLatin1String("buddy") && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QLabel"))) { | |
1152 m_buddies.append(Buddy(varName, p->elementCstring())); | |
1153 } else { | |
1154 if (stdset) | |
1155 propertyValue = fixString(p->elementCstring(), m_option.indent); | |
1156 else { | |
1157 propertyValue = QLatin1String("QByteArray("); | |
1158 propertyValue += fixString(p->elementCstring(), m_option.indent); | |
1159 propertyValue += QLatin1Char(')'); | |
1160 } | |
1161 } | |
1162 break; | |
1163 case DomProperty::Cursor: | |
48 | 1164 propertyValue = QString::fromLatin1("QCursor(cast(Qt.CursorShape)(%1))") |
1 | 1165 .arg(p->elementCursor()); |
1166 break; | |
1167 case DomProperty::CursorShape: | |
1168 if (p->hasAttributeStdset() && !p->attributeStdset()) | |
1169 varNewName += QLatin1String(".viewport()"); | |
48 | 1170 propertyValue = QString::fromLatin1("QCursor(Qt.%1)") |
1 | 1171 .arg(p->elementCursorShape()); |
1172 break; | |
1173 case DomProperty::Enum: | |
1174 propertyValue = p->elementEnum(); | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
1175 if (!propertyValue.contains(QLatin1String("::"))) { |
1 | 1176 QString scope = className; |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
1177 scope += QLatin1String("::"); |
1 | 1178 propertyValue.prepend(scope); |
1179 } | |
1180 break; | |
1181 case DomProperty::Set: | |
1182 propertyValue = p->elementSet(); | |
1183 break; | |
1184 case DomProperty::Font: | |
1185 propertyValue = writeFontProperties(p->elementFont()); | |
1186 break; | |
1187 case DomProperty::IconSet: | |
1188 propertyValue = writeIconProperties(p->elementIconSet()); | |
1189 break; | |
1190 case DomProperty::Pixmap: | |
1191 propertyValue = pixCall(p); | |
1192 break; | |
1193 case DomProperty::Palette: { | |
1194 const DomPalette *pal = p->elementPalette(); | |
1195 const QString paletteName = m_driver->unique(QLatin1String("palette")); | |
1196 m_output << m_option.indent << "QPalette " << paletteName << ";\n"; | |
1197 | |
48 | 1198 writeColorGroup(pal->elementActive(), QLatin1String("QPalette.Active"), paletteName); |
1199 writeColorGroup(pal->elementInactive(), QLatin1String("QPalette.Inactive"), paletteName); | |
1200 writeColorGroup(pal->elementDisabled(), QLatin1String("QPalette.Disabled"), paletteName); | |
1 | 1201 |
1202 propertyValue = paletteName; | |
1203 break; | |
1204 } | |
1205 case DomProperty::Point: { | |
1206 const DomPoint *po = p->elementPoint(); | |
48 | 1207 propertyValue = QString::fromLatin1("QPoint(%1, %2)") |
1 | 1208 .arg(po->elementX()).arg(po->elementY()); |
1209 break; | |
1210 } | |
1211 case DomProperty::PointF: { | |
1212 const DomPointF *pof = p->elementPointF(); | |
48 | 1213 propertyValue = QString::fromLatin1("QPointF(%1, %2)") |
1 | 1214 .arg(pof->elementX()).arg(pof->elementY()); |
1215 break; | |
1216 } | |
1217 case DomProperty::Rect: { | |
1218 const DomRect *r = p->elementRect(); | |
48 | 1219 propertyValue = QString::fromLatin1("QRect(%1, %2, %3, %4)") |
1 | 1220 .arg(r->elementX()).arg(r->elementY()) |
1221 .arg(r->elementWidth()).arg(r->elementHeight()); | |
1222 break; | |
1223 } | |
1224 case DomProperty::RectF: { | |
1225 const DomRectF *rf = p->elementRectF(); | |
48 | 1226 propertyValue = QString::fromLatin1("QRectF(%1, %2, %3, %4)") |
1 | 1227 .arg(rf->elementX()).arg(rf->elementY()) |
1228 .arg(rf->elementWidth()).arg(rf->elementHeight()); | |
1229 break; | |
1230 } | |
1231 case DomProperty::Locale: { | |
1232 const DomLocale *locale = p->elementLocale(); | |
48 | 1233 propertyValue = QString::fromLatin1("QLocale(QLocale.%1, QLocale.%2)") |
1 | 1234 .arg(locale->attributeLanguage()).arg(locale->attributeCountry()); |
1235 break; | |
1236 } | |
1237 case DomProperty::SizePolicy: { | |
1238 const QString spName = writeSizePolicy( p->elementSizePolicy()); | |
1239 m_output << m_option.indent << spName << QString::fromLatin1( | |
1240 ".setHeightForWidth(%1.sizePolicy().hasHeightForWidth());\n") | |
1241 .arg(varName); | |
1242 | |
1243 propertyValue = spName; | |
1244 break; | |
1245 } | |
1246 case DomProperty::Size: { | |
1247 const DomSize *s = p->elementSize(); | |
48 | 1248 propertyValue = QString::fromLatin1("QSize(%1, %2)") |
1 | 1249 .arg(s->elementWidth()).arg(s->elementHeight()); |
1250 break; | |
1251 } | |
1252 case DomProperty::SizeF: { | |
1253 const DomSizeF *sf = p->elementSizeF(); | |
48 | 1254 propertyValue = QString::fromLatin1("QSizeF(%1, %2)") |
1 | 1255 .arg(sf->elementWidth()).arg(sf->elementHeight()); |
1256 break; | |
1257 } | |
1258 case DomProperty::String: { | |
1259 if (propertyName == QLatin1String("objectName")) { | |
1260 const QString v = p->elementString()->text(); | |
1261 if (v == varName) | |
1262 break; | |
1263 | |
1264 // ### qWarning("Deprecated: the property `objectName' is different from the variable name"); | |
1265 } | |
1266 | |
1267 if (p->elementString()->hasAttributeNotr() | |
1268 && toBool(p->elementString()->attributeNotr())) { | |
1269 propertyValue = QLatin1String("QString.fromUtf8("); | |
1270 propertyValue += fixString(p->elementString()->text(), m_option.indent); | |
1271 propertyValue += QLatin1Char(')'); | |
1272 } else { | |
1273 propertyValue = trCall(p->elementString()); | |
1274 } | |
1275 break; | |
1276 } | |
1277 case DomProperty::Number: | |
1278 propertyValue = QString::number(p->elementNumber()); | |
1279 break; | |
1280 case DomProperty::UInt: | |
1281 propertyValue = QString::number(p->elementUInt()); | |
1282 propertyValue += QLatin1Char('u'); | |
1283 break; | |
1284 case DomProperty::LongLong: | |
1285 propertyValue = QLatin1String("Q_INT64_C("); | |
1286 propertyValue += QString::number(p->elementLongLong()); | |
1287 propertyValue += QLatin1Char(')');; | |
1288 break; | |
1289 case DomProperty::ULongLong: | |
1290 propertyValue = QLatin1String("Q_UINT64_C("); | |
1291 propertyValue += QString::number(p->elementULongLong()); | |
1292 propertyValue += QLatin1Char(')'); | |
1293 break; | |
1294 case DomProperty::Float: | |
1295 propertyValue = QString::number(p->elementFloat()); | |
1296 break; | |
1297 case DomProperty::Double: | |
1298 propertyValue = QString::number(p->elementDouble()); | |
1299 break; | |
1300 case DomProperty::Char: { | |
1301 const DomChar *c = p->elementChar(); | |
48 | 1302 propertyValue = QString::fromLatin1("QChar(%1)") |
1 | 1303 .arg(c->elementUnicode()); |
1304 break; | |
1305 } | |
1306 case DomProperty::Date: { | |
1307 const DomDate *d = p->elementDate(); | |
48 | 1308 propertyValue = QString::fromLatin1("QDate(%1, %2, %3)") |
1 | 1309 .arg(d->elementYear()) |
1310 .arg(d->elementMonth()) | |
1311 .arg(d->elementDay()); | |
1312 break; | |
1313 } | |
1314 case DomProperty::Time: { | |
1315 const DomTime *t = p->elementTime(); | |
48 | 1316 propertyValue = QString::fromLatin1("QTime(%1, %2, %3)") |
1 | 1317 .arg(t->elementHour()) |
1318 .arg(t->elementMinute()) | |
1319 .arg(t->elementSecond()); | |
1320 break; | |
1321 } | |
1322 case DomProperty::DateTime: { | |
1323 const DomDateTime *dt = p->elementDateTime(); | |
48 | 1324 propertyValue = QString::fromLatin1("QDateTime(QDate(%1, %2, %3), QTime(%4, %5, %6))") |
1 | 1325 .arg(dt->elementYear()) |
1326 .arg(dt->elementMonth()) | |
1327 .arg(dt->elementDay()) | |
1328 .arg(dt->elementHour()) | |
1329 .arg(dt->elementMinute()) | |
1330 .arg(dt->elementSecond()); | |
1331 break; | |
1332 } | |
1333 case DomProperty::StringList: | |
48 | 1334 propertyValue = QLatin1String("QStringList()"); |
1 | 1335 if (p->elementStringList()->elementString().size()) { |
1336 const QStringList lst = p->elementStringList()->elementString(); | |
1337 for (int i=0; i<lst.size(); ++i) { | |
1338 propertyValue += QLatin1String(" << "); | |
1339 propertyValue +=fixString(lst.at(i), m_option.indent); | |
1340 } | |
1341 } | |
1342 break; | |
1343 | |
1344 case DomProperty::Url: { | |
1345 const DomUrl* u = p->elementUrl(); | |
48 | 1346 propertyValue = QString::fromLatin1("QUrl(%1)") |
1 | 1347 .arg(fixString(u->elementString()->text(), m_option.indent)); |
1348 break; | |
1349 } | |
1350 case DomProperty::Brush: | |
1351 propertyValue = writeBrushInitialization(p->elementBrush()); | |
1352 break; | |
1353 case DomProperty::Unknown: | |
1354 break; | |
1355 } | |
82 | 1356 |
1357 propertyValue = propertyValue.replace("::", "."); // qtd | |
1 | 1358 |
1359 if (propertyValue.size()) { | |
1360 const char* defineC = 0; | |
1361 if (propertyName == QLatin1String("toolTip")) | |
1362 defineC = toolTipDefineC; | |
1363 if (propertyName == QLatin1String("whatsThis")) | |
1364 defineC = whatsThisDefineC; | |
1365 if (propertyName == QLatin1String("statusTip")) | |
1366 defineC = statusTipDefineC; | |
1367 const bool needsTranslation = p->kind() == DomProperty::String && (!p->elementString()->hasAttributeNotr() || !toBool(p->elementString()->attributeNotr())); | |
1368 if (propertyName == QLatin1String("accessibleName") || propertyName == QLatin1String("accessibleDescription")) | |
1369 defineC = accessibilityDefineC; | |
1370 | |
1371 QTextStream &o = needsTranslation ? m_refreshOut : m_output; | |
1372 | |
1373 if (defineC) | |
1374 openIfndef(o, QLatin1String(defineC)); | |
1375 o << m_option.indent << varNewName << setFunction << propertyValue; | |
1376 if (!stdset) | |
1377 o << ')'; | |
1378 o << ");\n"; | |
1379 if (defineC) | |
1380 closeIfdef(o, QLatin1String(defineC)); | |
1381 } | |
1382 } | |
1383 if (leftMargin != -1 || topMargin != -1 || rightMargin != -1 || bottomMargin != -1) { | |
1384 QString objectName = varName; | |
1385 if (m_widgetChain.top()) { | |
1386 const QString parentWidget = m_widgetChain.top()->attributeClass(); | |
1387 | |
1388 if (!m_layoutChain.top() && (m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3GroupBox")) | |
1389 || m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3ButtonGroup")))) { | |
1390 objectName = m_driver->findOrInsertWidget(m_widgetChain.top()) + QLatin1String(".layout()"); | |
1391 } | |
1392 } | |
1393 m_output << m_option.indent << objectName << QLatin1String(".setContentsMargins(") | |
1394 << leftMargin << QLatin1String(", ") | |
1395 << topMargin << QLatin1String(", ") | |
1396 << rightMargin << QLatin1String(", ") | |
1397 << bottomMargin << QLatin1String(");\n"); | |
1398 } | |
1399 } | |
1400 | |
1401 QString WriteInitialization::writeSizePolicy(const DomSizePolicy *sp) | |
1402 { | |
1403 | |
1404 // check cache | |
1405 const SizePolicyHandle sizePolicyHandle(sp); | |
1406 const SizePolicyNameMap::const_iterator it = m_sizePolicyNameMap.constFind(sizePolicyHandle); | |
1407 if ( it != m_sizePolicyNameMap.constEnd()) { | |
1408 return it.value(); | |
1409 } | |
1410 | |
1411 | |
1412 // insert with new name | |
1413 const QString spName = m_driver->unique(QLatin1String("sizePolicy")); | |
1414 m_sizePolicyNameMap.insert(sizePolicyHandle, spName); | |
1415 | |
48 | 1416 m_output << m_option.indent << "QSizePolicy " << spName; |
1 | 1417 do { |
1418 if (sp->hasElementHSizeType() && sp->hasElementVSizeType()) { | |
48 | 1419 m_output << "(cast(QSizePolicy.Policy)(" << sp->elementHSizeType() |
1420 << "), cast(QSizePolicy.Policy)(" << sp->elementVSizeType() << "));\n"; | |
1 | 1421 break; |
1422 } | |
1423 if (sp->hasAttributeHSizeType() && sp->hasAttributeVSizeType()) { | |
48 | 1424 m_output << "(QSizePolicy." << sp->attributeHSizeType() << ", QSizePolicy." |
1 | 1425 << sp->attributeVSizeType() << ");\n"; |
1426 break; | |
1427 } | |
1428 m_output << ";\n"; | |
1429 } while (false); | |
1430 | |
1431 m_output << m_option.indent << spName << ".setHorizontalStretch(" | |
1432 << sp->elementHorStretch() << ");\n"; | |
1433 m_output << m_option.indent << spName << ".setVerticalStretch(" | |
1434 << sp->elementVerStretch() << ");\n"; | |
1435 return spName; | |
1436 } | |
1437 // Check for a font with the given properties in the FontPropertiesNameMap | |
1438 // or create a new one. Returns the name. | |
1439 | |
1440 QString WriteInitialization::writeFontProperties(const DomFont *f) | |
1441 { | |
1442 // check cache | |
1443 const FontHandle fontHandle(f); | |
1444 const FontPropertiesNameMap::const_iterator it = m_fontPropertiesNameMap.constFind(fontHandle); | |
1445 if ( it != m_fontPropertiesNameMap.constEnd()) { | |
1446 return it.value(); | |
1447 } | |
1448 | |
1449 // insert with new name | |
1450 const QString fontName = m_driver->unique(QLatin1String("font")); | |
1451 m_fontPropertiesNameMap.insert(FontHandle(f), fontName); | |
1452 | |
1453 m_output << m_option.indent << "QFont " << fontName << ";\n"; | |
1454 if (f->hasElementFamily() && !f->elementFamily().isEmpty()) { | |
48 | 1455 m_output << m_option.indent << fontName << ".setFamily(QString.fromUtf8(" << fixString(f->elementFamily(), m_option.indent) |
1 | 1456 << "));\n"; |
1457 } | |
1458 if (f->hasElementPointSize() && f->elementPointSize() > 0) { | |
1459 m_output << m_option.indent << fontName << ".setPointSize(" << f->elementPointSize() | |
1460 << ");\n"; | |
1461 } | |
1462 | |
1463 if (f->hasElementBold()) { | |
1464 m_output << m_option.indent << fontName << ".setBold(" | |
1465 << (f->elementBold() ? "true" : "false") << ");\n"; | |
1466 } | |
1467 if (f->hasElementItalic()) { | |
1468 m_output << m_option.indent << fontName << ".setItalic(" | |
1469 << (f->elementItalic() ? "true" : "false") << ");\n"; | |
1470 } | |
1471 if (f->hasElementUnderline()) { | |
1472 m_output << m_option.indent << fontName << ".setUnderline(" | |
1473 << (f->elementUnderline() ? "true" : "false") << ");\n"; | |
1474 } | |
1475 if (f->hasElementWeight() && f->elementWeight() > 0) { | |
1476 m_output << m_option.indent << fontName << ".setWeight(" | |
1477 << f->elementWeight() << ");" << endl; | |
1478 } | |
1479 if (f->hasElementStrikeOut()) { | |
1480 m_output << m_option.indent << fontName << ".setStrikeOut(" | |
1481 << (f->elementStrikeOut() ? "true" : "false") << ");\n"; | |
1482 } | |
1483 if (f->hasElementKerning()) { | |
1484 m_output << m_option.indent << fontName << ".setKerning(" | |
1485 << (f->elementKerning() ? "true" : "false") << ");\n"; | |
1486 } | |
1487 if (f->hasElementAntialiasing()) { | |
1488 m_output << m_option.indent << fontName << ".setStyleStrategy(" | |
48 | 1489 << (f->elementAntialiasing() ? "QFont.PreferDefault" : "QFont.NoAntialias") << ");\n"; |
1 | 1490 } |
1491 if (f->hasElementStyleStrategy()) { | |
48 | 1492 m_output << m_option.indent << fontName << ".setStyleStrategy(QFont." |
1 | 1493 << f->elementStyleStrategy() << ");\n"; |
1494 } | |
1495 return fontName; | |
1496 } | |
1497 | |
1498 QString WriteInitialization::writeIconProperties(const DomResourceIcon *i) | |
1499 { | |
1500 // check cache | |
1501 const IconHandle iconHandle(i); | |
1502 const IconPropertiesNameMap::const_iterator it = m_iconPropertiesNameMap.constFind(iconHandle); | |
1503 if (it != m_iconPropertiesNameMap.constEnd()) { | |
1504 return it.value(); | |
1505 } | |
1506 | |
1507 // insert with new name | |
1508 const QString iconName = m_driver->unique(QLatin1String("icon")); | |
1509 m_iconPropertiesNameMap.insert(IconHandle(i), iconName); | |
1510 if (isIconFormat44(i)) { | |
48 | 1511 const QString pixmap = QLatin1String("QPixmap"); |
1512 m_output << m_option.indent << "QIcon " << iconName << ";\n"; | |
1 | 1513 if (i->hasElementNormalOff()) |
48 | 1514 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementNormalOff()->text()) << ", QIcon.Normal, QIcon.Off);\n"; |
1 | 1515 if (i->hasElementNormalOn()) |
48 | 1516 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementNormalOn()->text()) << ", QIcon.Normal, QIcon.On);\n"; |
1 | 1517 if (i->hasElementDisabledOff()) |
48 | 1518 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementDisabledOff()->text()) << ", QIcon.Disabled, QIcon.Off);\n"; |
1 | 1519 if (i->hasElementDisabledOn()) |
48 | 1520 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementDisabledOn()->text()) << ", QIcon.Disabled, QIcon.On);\n"; |
1 | 1521 if (i->hasElementActiveOff()) |
48 | 1522 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementActiveOff()->text()) << ", QIcon.Active, QIcon.Off);\n"; |
1 | 1523 if (i->hasElementActiveOn()) |
48 | 1524 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementActiveOn()->text()) << ", QIcon.Active, QIcon.On);\n"; |
1 | 1525 if (i->hasElementSelectedOff()) |
48 | 1526 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementSelectedOff()->text()) << ", QIcon.Selected, QIcon.Off);\n"; |
1 | 1527 if (i->hasElementSelectedOn()) |
48 | 1528 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementSelectedOn()->text()) << ", QIcon.Selected, QIcon.On);\n"; |
1 | 1529 } else { // pre-4.4 legacy |
48 | 1530 m_output << m_option.indent << "const QIcon " << iconName << " = " << pixCall(QLatin1String("QIcon"), i->text())<< ";\n"; |
1 | 1531 } |
1532 return iconName; | |
1533 } | |
1534 | |
1535 QString WriteInitialization::domColor2QString(const DomColor *c) | |
1536 { | |
1537 if (c->hasAttributeAlpha()) | |
48 | 1538 return QString::fromLatin1("QColor(%1, %2, %3, %4)") |
1 | 1539 .arg(c->elementRed()) |
1540 .arg(c->elementGreen()) | |
1541 .arg(c->elementBlue()) | |
1542 .arg(c->attributeAlpha()); | |
48 | 1543 return QString::fromLatin1("QColor(%1, %2, %3)") |
1 | 1544 .arg(c->elementRed()) |
1545 .arg(c->elementGreen()) | |
1546 .arg(c->elementBlue()); | |
1547 } | |
1548 | |
1549 void WriteInitialization::writeColorGroup(DomColorGroup *colorGroup, const QString &group, const QString &paletteName) | |
1550 { | |
1551 if (!colorGroup) | |
1552 return; | |
1553 | |
1554 // old format | |
1555 const QList<DomColor*> colors = colorGroup->elementColor(); | |
1556 for (int i=0; i<colors.size(); ++i) { | |
1557 const DomColor *color = colors.at(i); | |
1558 | |
1559 m_output << m_option.indent << paletteName << ".setColor(" << group | |
48 | 1560 << ", " << "cast(QPalette.ColorRole)(" << QString::number(i) << ')' |
1 | 1561 << ", " << domColor2QString(color) |
1562 << ");\n"; | |
1563 } | |
1564 | |
1565 // new format | |
1566 const QList<DomColorRole *> colorRoles = colorGroup->elementColorRole(); | |
1567 QListIterator<DomColorRole *> itRole(colorRoles); | |
1568 while (itRole.hasNext()) { | |
1569 const DomColorRole *colorRole = itRole.next(); | |
1570 if (colorRole->hasAttributeRole()) { | |
1571 const QString brushName = writeBrushInitialization(colorRole->elementBrush()); | |
1572 m_output << m_option.indent << paletteName << ".setBrush(" << group | |
48 | 1573 << ", " << "QPalette." << colorRole->attributeRole() |
1 | 1574 << ", " << brushName << ");\n"; |
1575 } | |
1576 } | |
1577 } | |
1578 | |
1579 // Write initialization for brush unless it is found in the cache. Returns the name to use | |
1580 // in an expression. | |
1581 QString WriteInitialization::writeBrushInitialization(const DomBrush *brush) | |
1582 { | |
1583 // Simple solid, colored brushes are cached | |
1584 const bool solidColoredBrush = !brush->hasAttributeBrushStyle() || brush->attributeBrushStyle() == QLatin1String("SolidPattern"); | |
1585 uint rgb = 0; | |
1586 if (solidColoredBrush) { | |
1587 if (const DomColor *color = brush->elementColor()) { | |
1588 rgb = ((color->elementRed() & 0xFF) << 24) | | |
1589 ((color->elementGreen() & 0xFF) << 16) | | |
1590 ((color->elementBlue() & 0xFF) << 8) | | |
1591 ((color->attributeAlpha() & 0xFF)); | |
1592 const ColorBrushHash::const_iterator cit = m_colorBrushHash.constFind(rgb); | |
1593 if (cit != m_colorBrushHash.constEnd()) | |
1594 return cit.value(); | |
1595 } | |
1596 } | |
1597 // Create and enter into cache if simple | |
1598 const QString brushName = m_driver->unique(QLatin1String("brush")); | |
1599 writeBrush(brush, brushName); | |
1600 if (solidColoredBrush) | |
1601 m_colorBrushHash.insert(rgb, brushName); | |
1602 return brushName; | |
1603 } | |
1604 | |
1605 void WriteInitialization::writeBrush(const DomBrush *brush, const QString &brushName) | |
1606 { | |
1607 QString style = QLatin1String("SolidPattern"); | |
1608 if (brush->hasAttributeBrushStyle()) | |
1609 style = brush->attributeBrushStyle(); | |
1610 | |
1611 if (style == QLatin1String("LinearGradientPattern") || | |
1612 style == QLatin1String("RadialGradientPattern") || | |
1613 style == QLatin1String("ConicalGradientPattern")) { | |
1614 const DomGradient *gradient = brush->elementGradient(); | |
1615 const QString gradientType = gradient->attributeType(); | |
1616 const QString gradientName = m_driver->unique(QLatin1String("gradient")); | |
1617 if (gradientType == QLatin1String("LinearGradient")) { | |
1618 m_output << m_option.indent << "QLinearGradient " << gradientName | |
1619 << '(' << gradient->attributeStartX() | |
1620 << ", " << gradient->attributeStartY() | |
1621 << ", " << gradient->attributeEndX() | |
1622 << ", " << gradient->attributeEndY() << ");\n"; | |
1623 } else if (gradientType == QLatin1String("RadialGradient")) { | |
1624 m_output << m_option.indent << "QRadialGradient " << gradientName | |
1625 << '(' << gradient->attributeCentralX() | |
1626 << ", " << gradient->attributeCentralY() | |
1627 << ", " << gradient->attributeRadius() | |
1628 << ", " << gradient->attributeFocalX() | |
1629 << ", " << gradient->attributeFocalY() << ");\n"; | |
1630 } else if (gradientType == QLatin1String("ConicalGradient")) { | |
1631 m_output << m_option.indent << "QConicalGradient " << gradientName | |
1632 << '(' << gradient->attributeCentralX() | |
1633 << ", " << gradient->attributeCentralY() | |
1634 << ", " << gradient->attributeAngle() << ");\n"; | |
1635 } | |
1636 | |
48 | 1637 m_output << m_option.indent << gradientName << ".setSpread(QGradient." |
1 | 1638 << gradient->attributeSpread() << ");\n"; |
1639 | |
1640 if (gradient->hasAttributeCoordinateMode()) { | |
48 | 1641 m_output << m_option.indent << gradientName << ".setCoordinateMode(QGradient." |
1 | 1642 << gradient->attributeCoordinateMode() << ");\n"; |
1643 } | |
1644 | |
1645 const QList<DomGradientStop *> stops = gradient->elementGradientStop(); | |
1646 QListIterator<DomGradientStop *> it(stops); | |
1647 while (it.hasNext()) { | |
1648 const DomGradientStop *stop = it.next(); | |
1649 const DomColor *color = stop->elementColor(); | |
1650 m_output << m_option.indent << gradientName << ".setColorAt(" | |
1651 << stop->attributePosition() << ", " | |
1652 << domColor2QString(color) << ");\n"; | |
1653 } | |
1654 m_output << m_option.indent << "QBrush " << brushName << '(' | |
1655 << gradientName << ");\n"; | |
1656 } else if (style == QLatin1String("TexturePattern")) { | |
1657 const DomProperty *property = brush->elementTexture(); | |
1658 const QString iconValue = iconCall(property); | |
1659 | |
1660 m_output << m_option.indent << "QBrush " << brushName << " = QBrush(" | |
1661 << iconValue << ");\n"; | |
1662 } else { | |
1663 const DomColor *color = brush->elementColor(); | |
1664 m_output << m_option.indent << "QBrush " << brushName << '(' | |
1665 << domColor2QString(color) << ");\n"; | |
1666 | |
1667 m_output << m_option.indent << brushName << ".setStyle(" | |
48 | 1668 << "Qt." << style << ");\n"; |
1 | 1669 } |
1670 } | |
1671 | |
1672 void WriteInitialization::acceptCustomWidget(DomCustomWidget *node) | |
1673 { | |
1674 Q_UNUSED(node); | |
1675 } | |
1676 | |
1677 void WriteInitialization::acceptCustomWidgets(DomCustomWidgets *node) | |
1678 { | |
1679 Q_UNUSED(node); | |
1680 } | |
1681 | |
1682 void WriteInitialization::acceptTabStops(DomTabStops *tabStops) | |
1683 { | |
1684 QString lastName; | |
1685 | |
1686 const QStringList l = tabStops->elementTabStop(); | |
1687 for (int i=0; i<l.size(); ++i) { | |
1688 const QString name = l.at(i); | |
1689 | |
1690 if (!m_registeredWidgets.contains(name)) { | |
1691 fprintf(stderr, "'%s' isn't a valid widget\n", name.toLatin1().data()); | |
1692 continue; | |
1693 } | |
1694 | |
1695 if (i == 0) { | |
1696 lastName = name; | |
1697 continue; | |
1698 } else if (name.isEmpty() || lastName.isEmpty()) { | |
1699 continue; | |
1700 } | |
1701 | |
48 | 1702 m_output << m_option.indent << "QWidget.setTabOrder(" << lastName << ", " << name << ");\n"; |
1 | 1703 |
1704 lastName = name; | |
1705 } | |
1706 } | |
1707 | |
1708 void WriteInitialization::initializeQ3ListBox(DomWidget *w) | |
1709 { | |
1710 const QString varName = m_driver->findOrInsertWidget(w); | |
1711 const QString className = w->attributeClass(); | |
1712 | |
1713 const QList<DomItem*> items = w->elementItem(); | |
1714 | |
1715 if (items.isEmpty()) | |
1716 return; | |
1717 | |
1718 m_refreshOut << m_option.indent << varName << ".clear();\n"; | |
1719 | |
1720 for (int i=0; i<items.size(); ++i) { | |
1721 const DomItem *item = items.at(i); | |
1722 | |
1723 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
1724 const DomProperty *text = properties.value(QLatin1String("text")); | |
1725 const DomProperty *pixmap = properties.value(QLatin1String("pixmap")); | |
1726 if (!(text || pixmap)) | |
1727 continue; | |
1728 | |
1729 m_refreshOut << m_option.indent << varName << ".insertItem("; | |
1730 if (pixmap) { | |
1731 m_refreshOut << pixCall(pixmap); | |
1732 | |
1733 if (text) | |
1734 m_refreshOut << ", "; | |
1735 } | |
1736 if (text) | |
1737 m_refreshOut << trCall(text->elementString()); | |
1738 m_refreshOut << ");\n"; | |
1739 } | |
1740 } | |
1741 | |
1742 void WriteInitialization::initializeQ3IconView(DomWidget *w) | |
1743 { | |
1744 const QString varName = m_driver->findOrInsertWidget(w); | |
1745 const QString className = w->attributeClass(); | |
1746 | |
1747 const QList<DomItem*> items = w->elementItem(); | |
1748 | |
1749 if (items.isEmpty()) | |
1750 return; | |
1751 | |
1752 m_refreshOut << m_option.indent << varName << ".clear();\n"; | |
1753 | |
1754 for (int i=0; i<items.size(); ++i) { | |
1755 const DomItem *item = items.at(i); | |
1756 | |
1757 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
1758 const DomProperty *text = properties.value(QLatin1String("text")); | |
1759 const DomProperty *pixmap = properties.value(QLatin1String("pixmap")); | |
1760 if (!(text || pixmap)) | |
1761 continue; | |
1762 | |
1763 const QString itemName = m_driver->unique(QLatin1String("__item")); | |
1764 m_refreshOut << "\n"; | |
1765 m_refreshOut << m_option.indent << "Q3IconViewItem *" << itemName << " = new Q3IconViewItem(" << varName << ");\n"; | |
1766 | |
1767 if (pixmap) { | |
1768 m_refreshOut << m_option.indent << itemName << ".setPixmap(" << pixCall(pixmap) << ");\n"; | |
1769 } | |
1770 | |
1771 if (text) { | |
1772 m_refreshOut << m_option.indent << itemName << ".setText(" << trCall(text->elementString()) << ");\n"; | |
1773 } | |
1774 } | |
1775 } | |
1776 | |
1777 void WriteInitialization::initializeQ3ListView(DomWidget *w) | |
1778 { | |
1779 const QString varName = m_driver->findOrInsertWidget(w); | |
1780 const QString className = w->attributeClass(); | |
1781 | |
1782 // columns | |
1783 const QList<DomColumn*> columns = w->elementColumn(); | |
1784 for (int i=0; i<columns.size(); ++i) { | |
1785 const DomColumn *column = columns.at(i); | |
1786 | |
1787 const DomPropertyMap properties = propertyMap(column->elementProperty()); | |
1788 const DomProperty *text = properties.value(QLatin1String("text")); | |
1789 const DomProperty *pixmap = properties.value(QLatin1String("pixmap")); | |
1790 const DomProperty *clickable = properties.value(QLatin1String("clickable")); | |
1791 const DomProperty *resizable = properties.value(QLatin1String("resizable")); | |
1792 | |
1793 const QString txt = trCall(text->elementString()); | |
1794 m_output << m_option.indent << varName << ".addColumn(" << txt << ");\n"; | |
48 | 1795 m_refreshOut << m_option.indent << varName << ".header().setLabel(" << i << ", " << txt << ");\n"; |
1 | 1796 |
1797 if (pixmap) { | |
48 | 1798 m_output << m_option.indent << varName << ".header().>setLabel(" |
1 | 1799 << varName << ".header()->count() - 1, " << pixCall(pixmap) << ", " << txt << ");\n"; |
1800 } | |
1801 | |
1802 if (clickable != 0) { | |
48 | 1803 m_output << m_option.indent << varName << ".header().setClickEnabled(" << clickable->elementBool() << ", " << varName << ".header()->count() - 1);\n"; |
1 | 1804 } |
1805 | |
1806 if (resizable != 0) { | |
48 | 1807 m_output << m_option.indent << varName << ".header().setResizeEnabled(" << resizable->elementBool() << ", " << varName << ".header()->count() - 1);\n"; |
1 | 1808 } |
1809 } | |
1810 | |
1811 if (w->elementItem().size()) { | |
1812 m_refreshOut << m_option.indent << varName << ".clear();\n"; | |
1813 | |
1814 initializeQ3ListViewItems(className, varName, w->elementItem()); | |
1815 } | |
1816 } | |
1817 | |
1818 void WriteInitialization::initializeQ3ListViewItems(const QString &className, const QString &varName, const QList<DomItem *> &items) | |
1819 { | |
1820 if (items.isEmpty()) | |
1821 return; | |
1822 | |
1823 // items | |
1824 for (int i=0; i<items.size(); ++i) { | |
1825 const DomItem *item = items.at(i); | |
1826 | |
1827 const QString itemName = m_driver->unique(QLatin1String("__item")); | |
1828 m_refreshOut << "\n"; | |
1829 m_refreshOut << m_option.indent << "Q3ListViewItem *" << itemName << " = new Q3ListViewItem(" << varName << ");\n"; | |
1830 | |
1831 int textCount = 0, pixCount = 0; | |
1832 const DomPropertyList properties = item->elementProperty(); | |
1833 for (int i=0; i<properties.size(); ++i) { | |
1834 const DomProperty *p = properties.at(i); | |
1835 if (p->attributeName() == QLatin1String("text")) | |
1836 m_refreshOut << m_option.indent << itemName << ".setText(" << textCount++ << ", " | |
1837 << trCall(p->elementString()) << ");\n"; | |
1838 | |
1839 if (p->attributeName() == QLatin1String("pixmap")) | |
1840 m_refreshOut << m_option.indent << itemName << ".setPixmap(" << pixCount++ << ", " | |
1841 << pixCall(p) << ");\n"; | |
1842 } | |
1843 | |
1844 if (item->elementItem().size()) { | |
1845 m_refreshOut << m_option.indent << itemName << ".setOpen(true);\n"; | |
1846 initializeQ3ListViewItems(className, itemName, item->elementItem()); | |
1847 } | |
1848 } | |
1849 } | |
1850 | |
1851 | |
1852 void WriteInitialization::initializeQ3Table(DomWidget *w) | |
1853 { | |
1854 const QString varName = m_driver->findOrInsertWidget(w); | |
1855 const QString className = w->attributeClass(); | |
1856 | |
1857 // columns | |
1858 const QList<DomColumn*> columns = w->elementColumn(); | |
1859 | |
1860 for (int i=0; i<columns.size(); ++i) { | |
1861 const DomColumn *column = columns.at(i); | |
1862 | |
1863 const DomPropertyMap properties = propertyMap(column->elementProperty()); | |
1864 const DomProperty *text = properties.value(QLatin1String("text")); | |
1865 const DomProperty *pixmap = properties.value(QLatin1String("pixmap")); | |
1866 | |
48 | 1867 m_refreshOut << m_option.indent << varName << ".horizontalHeader().setLabel(" << i << ", "; |
1 | 1868 if (pixmap) { |
1869 m_refreshOut << pixCall(pixmap) << ", "; | |
1870 } | |
1871 m_refreshOut << trCall(text->elementString()) << ");\n"; | |
1872 } | |
1873 | |
1874 // rows | |
1875 const QList<DomRow*> rows = w->elementRow(); | |
1876 for (int i=0; i<rows.size(); ++i) { | |
1877 const DomRow *row = rows.at(i); | |
1878 | |
1879 const DomPropertyMap properties = propertyMap(row->elementProperty()); | |
1880 const DomProperty *text = properties.value(QLatin1String("text")); | |
1881 const DomProperty *pixmap = properties.value(QLatin1String("pixmap")); | |
1882 | |
48 | 1883 m_refreshOut << m_option.indent << varName << ".verticalHeader().setLabel(" << i << ", "; |
1 | 1884 if (pixmap) { |
1885 m_refreshOut << pixCall(pixmap) << ", "; | |
1886 } | |
1887 m_refreshOut << trCall(text->elementString()) << ");\n"; | |
1888 } | |
1889 | |
1890 | |
1891 //initializeQ3TableItems(className, varName, w->elementItem()); | |
1892 } | |
1893 | |
1894 void WriteInitialization::initializeQ3TableItems(const QString &className, const QString &varName, const QList<DomItem *> &items) | |
1895 { | |
1896 Q_UNUSED(className); | |
1897 Q_UNUSED(varName); | |
1898 Q_UNUSED(items); | |
1899 } | |
1900 | |
1901 QString WriteInitialization::iconCall(const DomProperty *icon) | |
1902 { | |
1903 if (icon->kind() == DomProperty::IconSet) | |
1904 return writeIconProperties(icon->elementIconSet()); | |
1905 return pixCall(icon); | |
1906 } | |
1907 | |
1908 QString WriteInitialization::pixCall(const DomProperty *p) const | |
1909 { | |
1910 QString type, s; | |
1911 switch (p->kind()) { | |
1912 case DomProperty::IconSet: | |
1913 type = QLatin1String("QIcon"); | |
1914 s = p->elementIconSet()->text(); | |
1915 break; | |
1916 case DomProperty::Pixmap: | |
1917 type = QLatin1String("QPixmap"); | |
1918 s = p->elementPixmap()->text(); | |
1919 break; | |
1920 default: | |
1921 qWarning() << "Warning: Unknown icon format encountered. The ui-file was generated with a too-recent version of Designer."; | |
1922 return QLatin1String("QIcon()"); | |
1923 break; | |
1924 } | |
1925 return pixCall(type, s); | |
1926 } | |
1927 | |
1928 QString WriteInitialization::pixCall(const QString &t, const QString &text) const | |
1929 { | |
1930 QString type = t; | |
1931 if (text.isEmpty()) { | |
1932 type += QLatin1String("()"); | |
1933 return type; | |
1934 } | |
1935 if (const DomImage *image = findImage(text)) { | |
1936 if (m_option.extractImages) { | |
1937 const QString format = image->elementData()->attributeFormat(); | |
1938 const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower(); | |
48 | 1939 QString rc = QLatin1String("QPixmap(QString.fromUtf8(\":/"); |
1 | 1940 rc += m_generatedClass; |
1941 rc += QLatin1String("/images/"); | |
1942 rc += text; | |
1943 rc += QLatin1Char('.'); | |
1944 rc += extension; | |
1945 rc += QLatin1String("\"))"); | |
1946 return rc; | |
1947 } | |
1948 QString rc = WriteIconInitialization::iconFromDataFunction(); | |
1949 rc += QLatin1Char('('); | |
1950 rc += text; | |
1951 rc += QLatin1String("_ID)"); | |
1952 return rc; | |
1953 } | |
1954 | |
1955 QString pixFunc = m_uic->pixmapFunction(); | |
1956 if (pixFunc.isEmpty()) | |
48 | 1957 pixFunc = QLatin1String("QString.fromUtf8"); |
1 | 1958 |
1959 type += QLatin1Char('('); | |
1960 type += pixFunc; | |
1961 type += QLatin1Char('('); | |
1962 type += fixString(text, m_option.indent); | |
1963 type += QLatin1String("))"); | |
1964 return type; | |
1965 } | |
1966 | |
1967 void WriteInitialization::initializeComboBox(DomWidget *w) | |
1968 { | |
1969 const QString varName = m_driver->findOrInsertWidget(w); | |
1970 const QString className = w->attributeClass(); | |
1971 | |
1972 const QList<DomItem*> items = w->elementItem(); | |
1973 | |
1974 if (items.isEmpty()) | |
1975 return; | |
1976 | |
1977 // If possible use qcombobox's addItems() which is much faster then a bunch of addItem() calls | |
1978 bool noIcons = true; | |
1979 QStringList list; | |
1980 for (int i=0; i<items.size(); ++i) { | |
1981 const DomItem *item = items.at(i); | |
1982 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
1983 const DomProperty *text = properties.value(QLatin1String("text")); | |
1984 const DomProperty *pixmap = properties.value(QLatin1String("icon")); | |
1985 if (pixmap != 0) { | |
1986 noIcons = false; | |
1987 break; | |
1988 } | |
1989 list.append(trCall(text->elementString())); | |
1990 } | |
1991 | |
1992 if (noIcons) { | |
1993 m_refreshOut << m_option.indent << varName << ".clear();\n"; | |
1994 m_refreshOut << m_option.indent << varName << ".insertItems(0, QStringList()" << '\n'; | |
1995 for (int i = 0; i < list.size(); ++i) | |
1996 m_refreshOut << m_option.indent << " << " << list.at(i) << "\n"; | |
1997 m_refreshOut << m_option.indent << ");\n"; | |
1998 } else { | |
1999 for (int i = 0; i < items.size(); ++i) { | |
2000 const DomItem *item = items.at(i); | |
2001 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
2002 const DomProperty *text = properties.value(QLatin1String("text")); | |
2003 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2004 | |
2005 QString iconValue; | |
2006 if (icon) | |
2007 iconValue = iconCall(icon); | |
2008 | |
2009 m_output << m_option.indent << varName << ".addItem("; | |
2010 if (icon) | |
2011 m_output << iconValue << ", "; | |
78 | 2012 m_output << "null);\n"; |
1 | 2013 |
2014 if (!toString(text->elementString()).isEmpty()) | |
2015 m_refreshOut << m_option.indent << varName << ".setItemText(" << i << ", " << trCall(text->elementString()) << ");\n"; | |
2016 } | |
2017 m_refreshOut << "\n"; | |
2018 } | |
2019 } | |
2020 | |
2021 QString WriteInitialization::disableSorting(DomWidget *w, const QString &varName) | |
2022 { | |
2023 // turn off sortingEnabled to force programmatic item order (setItem()) | |
2024 QString tempName; | |
2025 if (!w->elementItem().isEmpty()) { | |
2026 tempName = m_driver->unique(QLatin1String("__sortingEnabled")); | |
2027 m_refreshOut << "\n"; | |
2028 m_refreshOut << m_option.indent << "const bool " << tempName | |
2029 << " = " << varName << ".isSortingEnabled();\n"; | |
2030 m_refreshOut << m_option.indent << varName << ".setSortingEnabled(false);\n"; | |
2031 } | |
2032 return tempName; | |
2033 } | |
2034 | |
2035 void WriteInitialization::enableSorting(DomWidget *w, const QString &varName, const QString &tempName) | |
2036 { | |
2037 if (!w->elementItem().isEmpty()) { | |
2038 m_refreshOut << "\n"; | |
2039 m_refreshOut << m_option.indent << varName << ".setSortingEnabled(" << tempName << ");\n"; | |
2040 } | |
2041 } | |
2042 | |
2043 void WriteInitialization::initializeListWidget(DomWidget *w) | |
2044 { | |
2045 const QString varName = m_driver->findOrInsertWidget(w); | |
2046 const QString className = w->attributeClass(); | |
2047 | |
2048 const QList<DomItem*> items = w->elementItem(); | |
2049 | |
2050 if (items.isEmpty()) | |
2051 return; | |
2052 | |
2053 QString tempName = disableSorting(w, varName); | |
2054 // items | |
2055 for (int i = 0; i < items.size(); ++i) { | |
2056 const DomItem *item = items.at(i); | |
2057 | |
2058 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
2059 const DomProperty *text = properties.value(QLatin1String("text")); | |
2060 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2061 | |
2062 QString itemCreation = QLatin1String("new QListWidgetItem(") + varName + QLatin1String(");\n"); | |
2063 if (icon) { | |
2064 const QString iconValue = iconCall(icon); | |
2065 const QString itemName = m_driver->unique(QLatin1String("__listItem")); | |
48 | 2066 m_output << m_option.indent << "QListWidgetItem " << itemName << " = " << itemCreation; |
1 | 2067 m_output << m_option.indent << itemName << ".setIcon(" << iconValue << ");\n"; |
2068 } else { | |
2069 m_output << m_option.indent << itemCreation; | |
2070 } | |
2071 | |
2072 if (!toString(text->elementString()).isEmpty()) { | |
48 | 2073 m_refreshOut << m_option.indent << varName << ".item(" << i << ").setText(" << trCall(text->elementString()) << ");\n"; |
1 | 2074 } |
2075 } | |
2076 enableSorting(w, varName, tempName); | |
2077 } | |
2078 | |
2079 void WriteInitialization::initializeTreeWidget(DomWidget *w) | |
2080 { | |
2081 const QString varName = m_driver->findOrInsertWidget(w); | |
2082 const QString className = w->attributeClass(); | |
2083 | |
2084 // columns | |
2085 const QList<DomColumn*> columns = w->elementColumn(); | |
2086 for (int i = 0; i < columns.size(); ++i) { | |
2087 const DomColumn *column = columns.at(i); | |
2088 | |
2089 const DomPropertyMap properties = propertyMap(column->elementProperty()); | |
2090 const DomProperty *text = properties.value(QLatin1String("text")); | |
2091 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2092 | |
2093 if (!toString(text->elementString()).isEmpty()) { | |
2094 const QString txt = trCall(text->elementString()); | |
48 | 2095 m_refreshOut << m_option.indent << varName << ".headerItem().setText(" << i << ", " << txt << ");\n"; |
1 | 2096 } |
2097 | |
2098 if (icon) { | |
2099 const QString iconValue = iconCall(icon); | |
48 | 2100 m_output << m_option.indent << varName << ".headerItem().setIcon(" |
1 | 2101 << i << ", " << iconValue << ");\n"; |
2102 } | |
2103 } | |
2104 | |
2105 if (w->elementItem().size()) { | |
2106 QString tempName = disableSorting(w, varName); | |
2107 | |
2108 initializeTreeWidgetItems(className, varName, w->elementItem(), varName + QLatin1String(".topLevelItem(")); | |
2109 | |
2110 enableSorting(w, varName, tempName); | |
2111 } | |
2112 } | |
2113 | |
2114 void WriteInitialization::initializeTreeWidgetItems(const QString &className, const QString &varName, const QList<DomItem *> &items, const QString &parentPath) | |
2115 { | |
2116 if (items.isEmpty()) | |
2117 return; | |
2118 | |
2119 // items | |
2120 for (int i = 0; i < items.size(); ++i) { | |
2121 const DomItem *item = items.at(i); | |
2122 | |
2123 int textCount = 0; | |
2124 const DomPropertyList properties = item->elementProperty(); | |
2125 QStringList icons; | |
2126 for (int j = 0; j < properties.size(); ++j) { | |
2127 const DomProperty *p = properties.at(j); | |
2128 if (p->attributeName() == QLatin1String("text")) { | |
2129 if (!toString(p->elementString()).isEmpty()) { | |
48 | 2130 m_refreshOut << m_option.indent << parentPath << i << ").setText(" << textCount << ", " |
1 | 2131 << trCall(p->elementString()) << ");\n"; |
2132 } | |
2133 textCount++; | |
2134 } | |
2135 | |
2136 if (p->attributeName() == QLatin1String("icon")) { | |
2137 const QString iconValue = iconCall(p); | |
2138 icons << QLatin1String(".setIcon(") | |
2139 + QString::number(textCount - 1) | |
2140 + QLatin1String(", ") + iconValue + QLatin1String(");\n"); | |
2141 } | |
2142 } | |
2143 if (icons.isEmpty() && (item->elementItem().size() == 0)) { | |
2144 m_output << m_option.indent << "new QTreeWidgetItem(" << varName << ");\n"; | |
2145 } else { | |
2146 const QString itemName = m_driver->unique(QLatin1String("__treeItem")); | |
48 | 2147 m_output << m_option.indent << "QTreeWidgetItem " << itemName << " = new QTreeWidgetItem(" << varName << ");\n"; |
1 | 2148 |
2149 QStringListIterator it(icons); | |
2150 while (it.hasNext()) | |
2151 m_output << m_option.indent << itemName << it.next(); | |
2152 | |
2153 if (item->elementItem().size()) { | |
2154 const QString childPath = parentPath + QString::number(i) + QLatin1String(")->child("); | |
2155 initializeTreeWidgetItems(className, itemName, item->elementItem(), childPath); | |
2156 } | |
2157 } | |
2158 | |
2159 } | |
2160 m_output << "\n"; | |
2161 } | |
2162 | |
2163 void WriteInitialization::initializeTableWidget(DomWidget *w) | |
2164 { | |
2165 const QString varName = m_driver->findOrInsertWidget(w); | |
2166 const QString className = w->attributeClass(); | |
2167 | |
2168 // columns | |
2169 const QList<DomColumn *> columns = w->elementColumn(); | |
2170 | |
2171 if (columns.size() != 0) { | |
2172 m_output << m_option.indent << "if (" << varName << ".columnCount() < " << columns.size() << ")\n" | |
2173 << m_option.indent << m_option.indent << varName << ".setColumnCount(" << columns.size() << ");\n"; | |
2174 } | |
2175 | |
2176 for (int i = 0; i < columns.size(); ++i) { | |
2177 const DomColumn *column = columns.at(i); | |
2178 | |
2179 const DomPropertyMap properties = propertyMap(column->elementProperty()); | |
2180 const DomProperty *text = properties.value(QLatin1String("text")); | |
2181 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2182 if (text || icon) { | |
2183 const QString itemName = m_driver->unique(QLatin1String("__colItem")); | |
2184 m_output << m_option.indent << "QTableWidgetItem *" | |
2185 << itemName << " = new QTableWidgetItem();\n"; | |
2186 | |
2187 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty()) | |
2188 m_refreshOut << m_option.indent << varName << ".horizontalHeaderItem(" << i << ")->setText(" | |
2189 << trCall(text->elementString()) << ");\n"; | |
2190 | |
2191 if (icon && icon->attributeName() == QLatin1String("icon")) { | |
2192 const QString iconValue = iconCall(icon); | |
2193 m_output << m_option.indent << itemName << ".setIcon(" | |
2194 << iconValue << ");\n"; | |
2195 } | |
2196 m_output << m_option.indent << varName << ".setHorizontalHeaderItem(" | |
2197 << i << ", " << itemName << ");\n"; | |
2198 } | |
2199 } | |
2200 | |
2201 // rows | |
2202 const QList<DomRow *> rows = w->elementRow(); | |
2203 | |
2204 if (rows.size() != 0) { | |
2205 m_output << m_option.indent << "if (" << varName << ".rowCount() < " << rows.size() << ")\n" | |
2206 << m_option.indent << m_option.indent << varName << ".setRowCount(" << rows.size() << ");\n"; | |
2207 } | |
2208 | |
2209 for (int i = 0; i < rows.size(); ++i) { | |
2210 const DomRow *row = rows.at(i); | |
2211 | |
2212 const DomPropertyMap properties = propertyMap(row->elementProperty()); | |
2213 const DomProperty *text = properties.value(QLatin1String("text")); | |
2214 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2215 if (text || icon) { | |
2216 const QString itemName = m_driver->unique(QLatin1String("__rowItem")); | |
48 | 2217 m_output << m_option.indent << "QTableWidgetItem " |
1 | 2218 << itemName << " = new QTableWidgetItem();\n"; |
2219 | |
2220 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty()) | |
48 | 2221 m_refreshOut << m_option.indent << varName << ".verticalHeaderItem(" << i << ").setText(" |
1 | 2222 << trCall(text->elementString()) << ");\n"; |
2223 | |
2224 if (icon && icon->attributeName() == QLatin1String("icon")) { | |
2225 const QString iconValue = iconCall(icon); | |
2226 m_output << m_option.indent << itemName << ".setIcon(" | |
2227 << iconValue << ");\n"; | |
2228 } | |
2229 m_output << m_option.indent << varName << ".setVerticalHeaderItem(" | |
2230 << i << ", " << itemName << ");\n"; | |
2231 } | |
2232 } | |
2233 | |
2234 // items | |
2235 QString tempName = disableSorting(w, varName); | |
2236 | |
2237 const QList<DomItem *> items = w->elementItem(); | |
2238 for (int i = 0; i < items.size(); ++i) { | |
2239 const DomItem *item = items.at(i); | |
2240 if (item->hasAttributeRow() && item->hasAttributeColumn()) { | |
2241 const DomPropertyMap properties = propertyMap(item->elementProperty()); | |
2242 const DomProperty *text = properties.value(QLatin1String("text")); | |
2243 const DomProperty *icon = properties.value(QLatin1String("icon")); | |
2244 if (text || icon) { | |
2245 const QString itemName = m_driver->unique(QLatin1String("__tableItem")); | |
48 | 2246 m_output << m_option.indent << "QTableWidgetItem " |
1 | 2247 << itemName << " = new QTableWidgetItem();\n"; |
2248 | |
2249 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty()) | |
2250 m_refreshOut << m_option.indent << varName << ".item(" << item->attributeRow() | |
48 | 2251 << ", " << item->attributeColumn() << ").setText(" |
1 | 2252 << trCall(text->elementString()) << ");\n"; |
2253 | |
2254 if (icon && icon->attributeName() == QLatin1String("icon")) { | |
2255 const QString iconValue = iconCall(icon); | |
2256 m_output << m_option.indent << itemName << ".setIcon(" | |
2257 << iconValue << ");\n"; | |
2258 } | |
2259 | |
2260 m_output << m_option.indent << varName << ".setItem(" | |
2261 << item->attributeRow() << ", " | |
2262 << item->attributeColumn() << ", " | |
2263 << itemName << ");\n"; | |
2264 } | |
2265 } | |
2266 } | |
2267 enableSorting(w, varName, tempName); | |
2268 } | |
2269 | |
2270 QString WriteInitialization::trCall(const QString &str, const QString &commentHint) const | |
2271 { | |
2272 if (str.isEmpty()) | |
78 | 2273 return QLatin1String("null"); |
1 | 2274 |
2275 QString result; | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2276 const QString comment = commentHint.isEmpty() ? QString("null") : fixString(commentHint, m_option.indent); |
1 | 2277 |
2278 if (m_option.translateFunction.isEmpty()) { | |
48 | 2279 result = QLatin1String("QApplication.translate(\""); |
1 | 2280 result += m_generatedClass; |
2281 result += QLatin1Char('"'); | |
2282 result += QLatin1String(", "); | |
2283 } else { | |
2284 result = m_option.translateFunction; | |
2285 result += QLatin1Char('('); | |
2286 } | |
2287 | |
2288 result += fixString(str, m_option.indent); | |
2289 result += QLatin1String(", "); | |
2290 result += comment; | |
2291 | |
2292 if (m_option.translateFunction.isEmpty()) { | |
2293 result += QLatin1String(", "); | |
48 | 2294 result += QLatin1String("QApplication.UnicodeUTF8"); |
1 | 2295 } |
2296 | |
2297 result += QLatin1Char(')'); | |
2298 return result; | |
2299 } | |
2300 | |
2301 void WriteInitialization::initializeQ3SqlDataTable(DomWidget *w) | |
2302 { | |
2303 const DomPropertyMap properties = propertyMap(w->elementProperty()); | |
2304 | |
2305 const DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode"), 0); | |
2306 if (frameworkCode && toBool(frameworkCode->elementBool()) == false) | |
2307 return; | |
2308 | |
2309 QString connection; | |
2310 QString table; | |
2311 QString field; | |
2312 | |
2313 const DomProperty *db = properties.value(QLatin1String("database"), 0); | |
2314 if (db && db->elementStringList()) { | |
2315 const QStringList info = db->elementStringList()->elementString(); | |
2316 connection = info.size() > 0 ? info.at(0) : QString(); | |
2317 table = info.size() > 1 ? info.at(1) : QString(); | |
2318 field = info.size() > 2 ? info.at(2) : QString(); | |
2319 } | |
2320 | |
2321 if (table.isEmpty() || connection.isEmpty()) { | |
2322 fprintf(stderr, "invalid database connection\n"); | |
2323 return; | |
2324 } | |
2325 | |
2326 const QString varName = m_driver->findOrInsertWidget(w); | |
2327 | |
2328 m_output << m_option.indent << "if (!" << varName << ".sqlCursor()) {\n"; | |
2329 | |
2330 m_output << m_option.indent << m_option.indent << varName << ".setSqlCursor("; | |
2331 | |
2332 if (connection == QLatin1String("(default)")) { | |
2333 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << "), false, true);\n"; | |
2334 } else { | |
2335 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << ", true, " << connection << "Connection" << "), false, true);\n"; | |
2336 } | |
2337 m_output << m_option.indent << m_option.indent << varName << ".refresh(qt.qt3support.Q3DataTable.RefreshAll);\n"; | |
2338 m_output << m_option.indent << "}\n"; | |
2339 } | |
2340 | |
2341 void WriteInitialization::initializeQ3SqlDataBrowser(DomWidget *w) | |
2342 { | |
2343 const DomPropertyMap properties = propertyMap(w->elementProperty()); | |
2344 | |
2345 const DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode"), 0); | |
2346 if (frameworkCode && toBool(frameworkCode->elementBool()) == false) | |
2347 return; | |
2348 | |
2349 QString connection; | |
2350 QString table; | |
2351 QString field; | |
2352 | |
2353 const DomProperty *db = properties.value(QLatin1String("database"), 0); | |
2354 if (db && db->elementStringList()) { | |
2355 const QStringList info = db->elementStringList()->elementString(); | |
2356 connection = info.size() > 0 ? info.at(0) : QString(); | |
2357 table = info.size() > 1 ? info.at(1) : QString(); | |
2358 field = info.size() > 2 ? info.at(2) : QString(); | |
2359 } | |
2360 | |
2361 if (table.isEmpty() || connection.isEmpty()) { | |
2362 fprintf(stderr, "invalid database connection\n"); | |
2363 return; | |
2364 } | |
2365 | |
2366 const QString varName = m_driver->findOrInsertWidget(w); | |
2367 | |
2368 m_output << m_option.indent << "if (!" << varName << ".sqlCursor()) {\n"; | |
2369 | |
2370 m_output << m_option.indent << m_option.indent << varName << ".setSqlCursor("; | |
2371 | |
2372 if (connection == QLatin1String("(default)")) { | |
2373 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << "), true);\n"; | |
2374 } else { | |
2375 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << ", true, " << connection << "Connection" << "), false, true);\n"; | |
2376 } | |
2377 m_output << m_option.indent << m_option.indent << varName << ".refresh();\n"; | |
2378 m_output << m_option.indent << "}\n"; | |
2379 } | |
2380 | |
2381 void WriteInitialization::initializeMenu(DomWidget *w, const QString &/*parentWidget*/) | |
2382 { | |
2383 const QString menuName = m_driver->findOrInsertWidget(w); | |
2384 const QString menuAction = menuName + QLatin1String("Action"); | |
2385 | |
2386 const DomAction *action = m_driver->actionByName(menuAction); | |
2387 if (action && action->hasAttributeMenu()) { | |
2388 m_output << m_option.indent << menuAction << " = " << menuName << ".menuAction();\n"; | |
2389 } | |
2390 } | |
2391 | |
2392 QString WriteInitialization::trCall(DomString *str) const | |
2393 { | |
2394 return trCall(toString(str), str->attributeComment()); | |
2395 } | |
2396 | |
2397 bool WriteInitialization::isValidObject(const QString &name) const | |
2398 { | |
2399 return m_registeredWidgets.contains(name) | |
2400 || m_registeredActions.contains(name); | |
2401 } | |
2402 | |
2403 QString WriteInitialization::findDeclaration(const QString &name) | |
2404 { | |
2405 const QString normalized = Driver::normalizedName(name); | |
2406 | |
2407 if (DomWidget *widget = m_driver->widgetByName(normalized)) | |
2408 return m_driver->findOrInsertWidget(widget); | |
2409 else if (DomAction *action = m_driver->actionByName(normalized)) | |
2410 return m_driver->findOrInsertAction(action); | |
2411 | |
2412 return QString(); | |
2413 } | |
2414 | |
2415 void WriteInitialization::acceptConnection(DomConnection *connection) | |
2416 { | |
2417 const QString sender = findDeclaration(connection->elementSender()); | |
2418 const QString receiver = findDeclaration(connection->elementReceiver()); | |
2419 | |
2420 if (sender.isEmpty() || receiver.isEmpty()) | |
2421 return; | |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2422 // qtd signal |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2423 QRegExp excl_brackets("\\((.*)\\)"); |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2424 QString stripped_signal = connection->elementSignal().remove(excl_brackets); |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2425 QString stripped_slot = connection->elementSlot().remove(excl_brackets); |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2426 m_output << m_option.indent |
1 | 2427 << sender |
56
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2428 << "." << stripped_signal |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2429 << ".connect" |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2430 << "(&" << receiver << "." |
d5a6b6269f44
duic is working now on the first testcase, if there are any issues with it please report
eldar
parents:
48
diff
changeset
|
2431 << stripped_slot << ");\n"; |
1 | 2432 } |
2433 | |
2434 DomImage *WriteInitialization::findImage(const QString &name) const | |
2435 { | |
2436 return m_registeredImages.value(name); | |
2437 } | |
2438 | |
2439 DomWidget *WriteInitialization::findWidget(const QString &widgetClass) | |
2440 { | |
2441 for (int i = m_widgetChain.count() - 1; i >= 0; --i) { | |
2442 DomWidget *widget = m_widgetChain.at(i); | |
2443 | |
2444 if (widget && m_uic->customWidgetsInfo()->extends(widget->attributeClass(), widgetClass)) | |
2445 return widget; | |
2446 } | |
2447 | |
2448 return 0; | |
2449 } | |
2450 | |
2451 void WriteInitialization::acceptImage(DomImage *image) | |
2452 { | |
2453 if (!image->hasAttributeName()) | |
2454 return; | |
2455 | |
2456 m_registeredImages.insert(image->attributeName(), image); | |
2457 } | |
2458 | |
2459 void WriteInitialization::acceptWidgetScripts(const DomScripts &widgetScripts, DomWidget *node, const DomWidgets &childWidgets) | |
2460 { | |
2461 // Add the per-class custom scripts to the per-widget ones. | |
2462 DomScripts scripts(widgetScripts); | |
2463 | |
2464 if (DomScript *customWidgetScript = m_uic->customWidgetsInfo()->customWidgetScript(node->attributeClass())) | |
2465 scripts.push_front(customWidgetScript); | |
2466 | |
2467 if (scripts.empty()) | |
2468 return; | |
2469 | |
2470 // concatenate script snippets | |
2471 QString script; | |
2472 foreach (const DomScript *domScript, scripts) { | |
2473 const QString snippet = domScript->text(); | |
2474 if (!snippet.isEmpty()) { | |
2475 script += snippet.trimmed(); | |
2476 script += QLatin1Char('\n'); | |
2477 } | |
2478 } | |
2479 if (script.isEmpty()) | |
2480 return; | |
2481 | |
2482 // Build the list of children and insert call | |
2483 m_output << m_option.indent << "childWidgets.clear();\n"; | |
2484 if (!childWidgets.empty()) { | |
2485 m_output << m_option.indent << "childWidgets"; | |
2486 foreach (DomWidget *child, childWidgets) { | |
2487 m_output << " << " << m_driver->findOrInsertWidget(child); | |
2488 } | |
2489 m_output << ";\n"; | |
2490 } | |
48 | 2491 m_output << m_option.indent << "scriptContext.run(QString.fromUtf8(" |
1 | 2492 << fixString(script, m_option.indent) << "), " |
2493 << m_driver->findOrInsertWidget(node) << ", childWidgets);\n"; | |
2494 } | |
2495 | |
2496 } // namespace D | |
2497 | |
2498 QT_END_NAMESPACE |