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
|
|
483 m_output << m_option.indent << "void " << "setupUi(" << widgetClassName << " *" << varName << ")\n"
|
|
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)
|
|
535 m_output << "\n" << m_option.indent << "QMetaObject.connectSlotsByName(" << varName << ");\n";
|
|
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
|
|
546 m_output << m_option.indent << "void " << "retranslateUi(" << widgetClassName << " *" << varName << ")\n"
|
|
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
|
|
735 m_output << m_option.indent << parentWidget << ".addTab(" << varName << icon << ", " << "QString());\n";
|
|
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(" ");
|
|
1038 m_output << m_option.indent << "if (" << varName << ".objectName().isEmpty())\n";
|
|
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();
|
|
1175 if (!propertyValue.contains(QLatin1String("."))) {
|
|
1176 QString scope = className;
|
|
1177 scope += QLatin1String(".");
|
|
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 }
|
|
1356
|
|
1357 if (propertyValue.size()) {
|
|
1358 const char* defineC = 0;
|
|
1359 if (propertyName == QLatin1String("toolTip"))
|
|
1360 defineC = toolTipDefineC;
|
|
1361 if (propertyName == QLatin1String("whatsThis"))
|
|
1362 defineC = whatsThisDefineC;
|
|
1363 if (propertyName == QLatin1String("statusTip"))
|
|
1364 defineC = statusTipDefineC;
|
|
1365 const bool needsTranslation = p->kind() == DomProperty::String && (!p->elementString()->hasAttributeNotr() || !toBool(p->elementString()->attributeNotr()));
|
|
1366 if (propertyName == QLatin1String("accessibleName") || propertyName == QLatin1String("accessibleDescription"))
|
|
1367 defineC = accessibilityDefineC;
|
|
1368
|
|
1369 QTextStream &o = needsTranslation ? m_refreshOut : m_output;
|
|
1370
|
|
1371 if (defineC)
|
|
1372 openIfndef(o, QLatin1String(defineC));
|
|
1373 o << m_option.indent << varNewName << setFunction << propertyValue;
|
|
1374 if (!stdset)
|
|
1375 o << ')';
|
|
1376 o << ");\n";
|
|
1377 if (defineC)
|
|
1378 closeIfdef(o, QLatin1String(defineC));
|
|
1379 }
|
|
1380 }
|
|
1381 if (leftMargin != -1 || topMargin != -1 || rightMargin != -1 || bottomMargin != -1) {
|
|
1382 QString objectName = varName;
|
|
1383 if (m_widgetChain.top()) {
|
|
1384 const QString parentWidget = m_widgetChain.top()->attributeClass();
|
|
1385
|
|
1386 if (!m_layoutChain.top() && (m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3GroupBox"))
|
|
1387 || m_uic->customWidgetsInfo()->extends(parentWidget, QLatin1String("Q3ButtonGroup")))) {
|
|
1388 objectName = m_driver->findOrInsertWidget(m_widgetChain.top()) + QLatin1String(".layout()");
|
|
1389 }
|
|
1390 }
|
|
1391 m_output << m_option.indent << objectName << QLatin1String(".setContentsMargins(")
|
|
1392 << leftMargin << QLatin1String(", ")
|
|
1393 << topMargin << QLatin1String(", ")
|
|
1394 << rightMargin << QLatin1String(", ")
|
|
1395 << bottomMargin << QLatin1String(");\n");
|
|
1396 }
|
|
1397 }
|
|
1398
|
|
1399 QString WriteInitialization::writeSizePolicy(const DomSizePolicy *sp)
|
|
1400 {
|
|
1401
|
|
1402 // check cache
|
|
1403 const SizePolicyHandle sizePolicyHandle(sp);
|
|
1404 const SizePolicyNameMap::const_iterator it = m_sizePolicyNameMap.constFind(sizePolicyHandle);
|
|
1405 if ( it != m_sizePolicyNameMap.constEnd()) {
|
|
1406 return it.value();
|
|
1407 }
|
|
1408
|
|
1409
|
|
1410 // insert with new name
|
|
1411 const QString spName = m_driver->unique(QLatin1String("sizePolicy"));
|
|
1412 m_sizePolicyNameMap.insert(sizePolicyHandle, spName);
|
|
1413
|
48
|
1414 m_output << m_option.indent << "QSizePolicy " << spName;
|
1
|
1415 do {
|
|
1416 if (sp->hasElementHSizeType() && sp->hasElementVSizeType()) {
|
48
|
1417 m_output << "(cast(QSizePolicy.Policy)(" << sp->elementHSizeType()
|
|
1418 << "), cast(QSizePolicy.Policy)(" << sp->elementVSizeType() << "));\n";
|
1
|
1419 break;
|
|
1420 }
|
|
1421 if (sp->hasAttributeHSizeType() && sp->hasAttributeVSizeType()) {
|
48
|
1422 m_output << "(QSizePolicy." << sp->attributeHSizeType() << ", QSizePolicy."
|
1
|
1423 << sp->attributeVSizeType() << ");\n";
|
|
1424 break;
|
|
1425 }
|
|
1426 m_output << ";\n";
|
|
1427 } while (false);
|
|
1428
|
|
1429 m_output << m_option.indent << spName << ".setHorizontalStretch("
|
|
1430 << sp->elementHorStretch() << ");\n";
|
|
1431 m_output << m_option.indent << spName << ".setVerticalStretch("
|
|
1432 << sp->elementVerStretch() << ");\n";
|
|
1433 return spName;
|
|
1434 }
|
|
1435 // Check for a font with the given properties in the FontPropertiesNameMap
|
|
1436 // or create a new one. Returns the name.
|
|
1437
|
|
1438 QString WriteInitialization::writeFontProperties(const DomFont *f)
|
|
1439 {
|
|
1440 // check cache
|
|
1441 const FontHandle fontHandle(f);
|
|
1442 const FontPropertiesNameMap::const_iterator it = m_fontPropertiesNameMap.constFind(fontHandle);
|
|
1443 if ( it != m_fontPropertiesNameMap.constEnd()) {
|
|
1444 return it.value();
|
|
1445 }
|
|
1446
|
|
1447 // insert with new name
|
|
1448 const QString fontName = m_driver->unique(QLatin1String("font"));
|
|
1449 m_fontPropertiesNameMap.insert(FontHandle(f), fontName);
|
|
1450
|
|
1451 m_output << m_option.indent << "QFont " << fontName << ";\n";
|
|
1452 if (f->hasElementFamily() && !f->elementFamily().isEmpty()) {
|
48
|
1453 m_output << m_option.indent << fontName << ".setFamily(QString.fromUtf8(" << fixString(f->elementFamily(), m_option.indent)
|
1
|
1454 << "));\n";
|
|
1455 }
|
|
1456 if (f->hasElementPointSize() && f->elementPointSize() > 0) {
|
|
1457 m_output << m_option.indent << fontName << ".setPointSize(" << f->elementPointSize()
|
|
1458 << ");\n";
|
|
1459 }
|
|
1460
|
|
1461 if (f->hasElementBold()) {
|
|
1462 m_output << m_option.indent << fontName << ".setBold("
|
|
1463 << (f->elementBold() ? "true" : "false") << ");\n";
|
|
1464 }
|
|
1465 if (f->hasElementItalic()) {
|
|
1466 m_output << m_option.indent << fontName << ".setItalic("
|
|
1467 << (f->elementItalic() ? "true" : "false") << ");\n";
|
|
1468 }
|
|
1469 if (f->hasElementUnderline()) {
|
|
1470 m_output << m_option.indent << fontName << ".setUnderline("
|
|
1471 << (f->elementUnderline() ? "true" : "false") << ");\n";
|
|
1472 }
|
|
1473 if (f->hasElementWeight() && f->elementWeight() > 0) {
|
|
1474 m_output << m_option.indent << fontName << ".setWeight("
|
|
1475 << f->elementWeight() << ");" << endl;
|
|
1476 }
|
|
1477 if (f->hasElementStrikeOut()) {
|
|
1478 m_output << m_option.indent << fontName << ".setStrikeOut("
|
|
1479 << (f->elementStrikeOut() ? "true" : "false") << ");\n";
|
|
1480 }
|
|
1481 if (f->hasElementKerning()) {
|
|
1482 m_output << m_option.indent << fontName << ".setKerning("
|
|
1483 << (f->elementKerning() ? "true" : "false") << ");\n";
|
|
1484 }
|
|
1485 if (f->hasElementAntialiasing()) {
|
|
1486 m_output << m_option.indent << fontName << ".setStyleStrategy("
|
48
|
1487 << (f->elementAntialiasing() ? "QFont.PreferDefault" : "QFont.NoAntialias") << ");\n";
|
1
|
1488 }
|
|
1489 if (f->hasElementStyleStrategy()) {
|
48
|
1490 m_output << m_option.indent << fontName << ".setStyleStrategy(QFont."
|
1
|
1491 << f->elementStyleStrategy() << ");\n";
|
|
1492 }
|
|
1493 return fontName;
|
|
1494 }
|
|
1495
|
|
1496 QString WriteInitialization::writeIconProperties(const DomResourceIcon *i)
|
|
1497 {
|
|
1498 // check cache
|
|
1499 const IconHandle iconHandle(i);
|
|
1500 const IconPropertiesNameMap::const_iterator it = m_iconPropertiesNameMap.constFind(iconHandle);
|
|
1501 if (it != m_iconPropertiesNameMap.constEnd()) {
|
|
1502 return it.value();
|
|
1503 }
|
|
1504
|
|
1505 // insert with new name
|
|
1506 const QString iconName = m_driver->unique(QLatin1String("icon"));
|
|
1507 m_iconPropertiesNameMap.insert(IconHandle(i), iconName);
|
|
1508 if (isIconFormat44(i)) {
|
48
|
1509 const QString pixmap = QLatin1String("QPixmap");
|
|
1510 m_output << m_option.indent << "QIcon " << iconName << ";\n";
|
1
|
1511 if (i->hasElementNormalOff())
|
48
|
1512 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementNormalOff()->text()) << ", QIcon.Normal, QIcon.Off);\n";
|
1
|
1513 if (i->hasElementNormalOn())
|
48
|
1514 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementNormalOn()->text()) << ", QIcon.Normal, QIcon.On);\n";
|
1
|
1515 if (i->hasElementDisabledOff())
|
48
|
1516 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementDisabledOff()->text()) << ", QIcon.Disabled, QIcon.Off);\n";
|
1
|
1517 if (i->hasElementDisabledOn())
|
48
|
1518 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementDisabledOn()->text()) << ", QIcon.Disabled, QIcon.On);\n";
|
1
|
1519 if (i->hasElementActiveOff())
|
48
|
1520 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementActiveOff()->text()) << ", QIcon.Active, QIcon.Off);\n";
|
1
|
1521 if (i->hasElementActiveOn())
|
48
|
1522 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementActiveOn()->text()) << ", QIcon.Active, QIcon.On);\n";
|
1
|
1523 if (i->hasElementSelectedOff())
|
48
|
1524 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementSelectedOff()->text()) << ", QIcon.Selected, QIcon.Off);\n";
|
1
|
1525 if (i->hasElementSelectedOn())
|
48
|
1526 m_output << m_option.indent << iconName << ".addPixmap(" << pixCall(pixmap, i->elementSelectedOn()->text()) << ", QIcon.Selected, QIcon.On);\n";
|
1
|
1527 } else { // pre-4.4 legacy
|
48
|
1528 m_output << m_option.indent << "const QIcon " << iconName << " = " << pixCall(QLatin1String("QIcon"), i->text())<< ";\n";
|
1
|
1529 }
|
|
1530 return iconName;
|
|
1531 }
|
|
1532
|
|
1533 QString WriteInitialization::domColor2QString(const DomColor *c)
|
|
1534 {
|
|
1535 if (c->hasAttributeAlpha())
|
48
|
1536 return QString::fromLatin1("QColor(%1, %2, %3, %4)")
|
1
|
1537 .arg(c->elementRed())
|
|
1538 .arg(c->elementGreen())
|
|
1539 .arg(c->elementBlue())
|
|
1540 .arg(c->attributeAlpha());
|
48
|
1541 return QString::fromLatin1("QColor(%1, %2, %3)")
|
1
|
1542 .arg(c->elementRed())
|
|
1543 .arg(c->elementGreen())
|
|
1544 .arg(c->elementBlue());
|
|
1545 }
|
|
1546
|
|
1547 void WriteInitialization::writeColorGroup(DomColorGroup *colorGroup, const QString &group, const QString &paletteName)
|
|
1548 {
|
|
1549 if (!colorGroup)
|
|
1550 return;
|
|
1551
|
|
1552 // old format
|
|
1553 const QList<DomColor*> colors = colorGroup->elementColor();
|
|
1554 for (int i=0; i<colors.size(); ++i) {
|
|
1555 const DomColor *color = colors.at(i);
|
|
1556
|
|
1557 m_output << m_option.indent << paletteName << ".setColor(" << group
|
48
|
1558 << ", " << "cast(QPalette.ColorRole)(" << QString::number(i) << ')'
|
1
|
1559 << ", " << domColor2QString(color)
|
|
1560 << ");\n";
|
|
1561 }
|
|
1562
|
|
1563 // new format
|
|
1564 const QList<DomColorRole *> colorRoles = colorGroup->elementColorRole();
|
|
1565 QListIterator<DomColorRole *> itRole(colorRoles);
|
|
1566 while (itRole.hasNext()) {
|
|
1567 const DomColorRole *colorRole = itRole.next();
|
|
1568 if (colorRole->hasAttributeRole()) {
|
|
1569 const QString brushName = writeBrushInitialization(colorRole->elementBrush());
|
|
1570 m_output << m_option.indent << paletteName << ".setBrush(" << group
|
48
|
1571 << ", " << "QPalette." << colorRole->attributeRole()
|
1
|
1572 << ", " << brushName << ");\n";
|
|
1573 }
|
|
1574 }
|
|
1575 }
|
|
1576
|
|
1577 // Write initialization for brush unless it is found in the cache. Returns the name to use
|
|
1578 // in an expression.
|
|
1579 QString WriteInitialization::writeBrushInitialization(const DomBrush *brush)
|
|
1580 {
|
|
1581 // Simple solid, colored brushes are cached
|
|
1582 const bool solidColoredBrush = !brush->hasAttributeBrushStyle() || brush->attributeBrushStyle() == QLatin1String("SolidPattern");
|
|
1583 uint rgb = 0;
|
|
1584 if (solidColoredBrush) {
|
|
1585 if (const DomColor *color = brush->elementColor()) {
|
|
1586 rgb = ((color->elementRed() & 0xFF) << 24) |
|
|
1587 ((color->elementGreen() & 0xFF) << 16) |
|
|
1588 ((color->elementBlue() & 0xFF) << 8) |
|
|
1589 ((color->attributeAlpha() & 0xFF));
|
|
1590 const ColorBrushHash::const_iterator cit = m_colorBrushHash.constFind(rgb);
|
|
1591 if (cit != m_colorBrushHash.constEnd())
|
|
1592 return cit.value();
|
|
1593 }
|
|
1594 }
|
|
1595 // Create and enter into cache if simple
|
|
1596 const QString brushName = m_driver->unique(QLatin1String("brush"));
|
|
1597 writeBrush(brush, brushName);
|
|
1598 if (solidColoredBrush)
|
|
1599 m_colorBrushHash.insert(rgb, brushName);
|
|
1600 return brushName;
|
|
1601 }
|
|
1602
|
|
1603 void WriteInitialization::writeBrush(const DomBrush *brush, const QString &brushName)
|
|
1604 {
|
|
1605 QString style = QLatin1String("SolidPattern");
|
|
1606 if (brush->hasAttributeBrushStyle())
|
|
1607 style = brush->attributeBrushStyle();
|
|
1608
|
|
1609 if (style == QLatin1String("LinearGradientPattern") ||
|
|
1610 style == QLatin1String("RadialGradientPattern") ||
|
|
1611 style == QLatin1String("ConicalGradientPattern")) {
|
|
1612 const DomGradient *gradient = brush->elementGradient();
|
|
1613 const QString gradientType = gradient->attributeType();
|
|
1614 const QString gradientName = m_driver->unique(QLatin1String("gradient"));
|
|
1615 if (gradientType == QLatin1String("LinearGradient")) {
|
|
1616 m_output << m_option.indent << "QLinearGradient " << gradientName
|
|
1617 << '(' << gradient->attributeStartX()
|
|
1618 << ", " << gradient->attributeStartY()
|
|
1619 << ", " << gradient->attributeEndX()
|
|
1620 << ", " << gradient->attributeEndY() << ");\n";
|
|
1621 } else if (gradientType == QLatin1String("RadialGradient")) {
|
|
1622 m_output << m_option.indent << "QRadialGradient " << gradientName
|
|
1623 << '(' << gradient->attributeCentralX()
|
|
1624 << ", " << gradient->attributeCentralY()
|
|
1625 << ", " << gradient->attributeRadius()
|
|
1626 << ", " << gradient->attributeFocalX()
|
|
1627 << ", " << gradient->attributeFocalY() << ");\n";
|
|
1628 } else if (gradientType == QLatin1String("ConicalGradient")) {
|
|
1629 m_output << m_option.indent << "QConicalGradient " << gradientName
|
|
1630 << '(' << gradient->attributeCentralX()
|
|
1631 << ", " << gradient->attributeCentralY()
|
|
1632 << ", " << gradient->attributeAngle() << ");\n";
|
|
1633 }
|
|
1634
|
48
|
1635 m_output << m_option.indent << gradientName << ".setSpread(QGradient."
|
1
|
1636 << gradient->attributeSpread() << ");\n";
|
|
1637
|
|
1638 if (gradient->hasAttributeCoordinateMode()) {
|
48
|
1639 m_output << m_option.indent << gradientName << ".setCoordinateMode(QGradient."
|
1
|
1640 << gradient->attributeCoordinateMode() << ");\n";
|
|
1641 }
|
|
1642
|
|
1643 const QList<DomGradientStop *> stops = gradient->elementGradientStop();
|
|
1644 QListIterator<DomGradientStop *> it(stops);
|
|
1645 while (it.hasNext()) {
|
|
1646 const DomGradientStop *stop = it.next();
|
|
1647 const DomColor *color = stop->elementColor();
|
|
1648 m_output << m_option.indent << gradientName << ".setColorAt("
|
|
1649 << stop->attributePosition() << ", "
|
|
1650 << domColor2QString(color) << ");\n";
|
|
1651 }
|
|
1652 m_output << m_option.indent << "QBrush " << brushName << '('
|
|
1653 << gradientName << ");\n";
|
|
1654 } else if (style == QLatin1String("TexturePattern")) {
|
|
1655 const DomProperty *property = brush->elementTexture();
|
|
1656 const QString iconValue = iconCall(property);
|
|
1657
|
|
1658 m_output << m_option.indent << "QBrush " << brushName << " = QBrush("
|
|
1659 << iconValue << ");\n";
|
|
1660 } else {
|
|
1661 const DomColor *color = brush->elementColor();
|
|
1662 m_output << m_option.indent << "QBrush " << brushName << '('
|
|
1663 << domColor2QString(color) << ");\n";
|
|
1664
|
|
1665 m_output << m_option.indent << brushName << ".setStyle("
|
48
|
1666 << "Qt." << style << ");\n";
|
1
|
1667 }
|
|
1668 }
|
|
1669
|
|
1670 void WriteInitialization::acceptCustomWidget(DomCustomWidget *node)
|
|
1671 {
|
|
1672 Q_UNUSED(node);
|
|
1673 }
|
|
1674
|
|
1675 void WriteInitialization::acceptCustomWidgets(DomCustomWidgets *node)
|
|
1676 {
|
|
1677 Q_UNUSED(node);
|
|
1678 }
|
|
1679
|
|
1680 void WriteInitialization::acceptTabStops(DomTabStops *tabStops)
|
|
1681 {
|
|
1682 QString lastName;
|
|
1683
|
|
1684 const QStringList l = tabStops->elementTabStop();
|
|
1685 for (int i=0; i<l.size(); ++i) {
|
|
1686 const QString name = l.at(i);
|
|
1687
|
|
1688 if (!m_registeredWidgets.contains(name)) {
|
|
1689 fprintf(stderr, "'%s' isn't a valid widget\n", name.toLatin1().data());
|
|
1690 continue;
|
|
1691 }
|
|
1692
|
|
1693 if (i == 0) {
|
|
1694 lastName = name;
|
|
1695 continue;
|
|
1696 } else if (name.isEmpty() || lastName.isEmpty()) {
|
|
1697 continue;
|
|
1698 }
|
|
1699
|
48
|
1700 m_output << m_option.indent << "QWidget.setTabOrder(" << lastName << ", " << name << ");\n";
|
1
|
1701
|
|
1702 lastName = name;
|
|
1703 }
|
|
1704 }
|
|
1705
|
|
1706 void WriteInitialization::initializeQ3ListBox(DomWidget *w)
|
|
1707 {
|
|
1708 const QString varName = m_driver->findOrInsertWidget(w);
|
|
1709 const QString className = w->attributeClass();
|
|
1710
|
|
1711 const QList<DomItem*> items = w->elementItem();
|
|
1712
|
|
1713 if (items.isEmpty())
|
|
1714 return;
|
|
1715
|
|
1716 m_refreshOut << m_option.indent << varName << ".clear();\n";
|
|
1717
|
|
1718 for (int i=0; i<items.size(); ++i) {
|
|
1719 const DomItem *item = items.at(i);
|
|
1720
|
|
1721 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
1722 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1723 const DomProperty *pixmap = properties.value(QLatin1String("pixmap"));
|
|
1724 if (!(text || pixmap))
|
|
1725 continue;
|
|
1726
|
|
1727 m_refreshOut << m_option.indent << varName << ".insertItem(";
|
|
1728 if (pixmap) {
|
|
1729 m_refreshOut << pixCall(pixmap);
|
|
1730
|
|
1731 if (text)
|
|
1732 m_refreshOut << ", ";
|
|
1733 }
|
|
1734 if (text)
|
|
1735 m_refreshOut << trCall(text->elementString());
|
|
1736 m_refreshOut << ");\n";
|
|
1737 }
|
|
1738 }
|
|
1739
|
|
1740 void WriteInitialization::initializeQ3IconView(DomWidget *w)
|
|
1741 {
|
|
1742 const QString varName = m_driver->findOrInsertWidget(w);
|
|
1743 const QString className = w->attributeClass();
|
|
1744
|
|
1745 const QList<DomItem*> items = w->elementItem();
|
|
1746
|
|
1747 if (items.isEmpty())
|
|
1748 return;
|
|
1749
|
|
1750 m_refreshOut << m_option.indent << varName << ".clear();\n";
|
|
1751
|
|
1752 for (int i=0; i<items.size(); ++i) {
|
|
1753 const DomItem *item = items.at(i);
|
|
1754
|
|
1755 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
1756 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1757 const DomProperty *pixmap = properties.value(QLatin1String("pixmap"));
|
|
1758 if (!(text || pixmap))
|
|
1759 continue;
|
|
1760
|
|
1761 const QString itemName = m_driver->unique(QLatin1String("__item"));
|
|
1762 m_refreshOut << "\n";
|
|
1763 m_refreshOut << m_option.indent << "Q3IconViewItem *" << itemName << " = new Q3IconViewItem(" << varName << ");\n";
|
|
1764
|
|
1765 if (pixmap) {
|
|
1766 m_refreshOut << m_option.indent << itemName << ".setPixmap(" << pixCall(pixmap) << ");\n";
|
|
1767 }
|
|
1768
|
|
1769 if (text) {
|
|
1770 m_refreshOut << m_option.indent << itemName << ".setText(" << trCall(text->elementString()) << ");\n";
|
|
1771 }
|
|
1772 }
|
|
1773 }
|
|
1774
|
|
1775 void WriteInitialization::initializeQ3ListView(DomWidget *w)
|
|
1776 {
|
|
1777 const QString varName = m_driver->findOrInsertWidget(w);
|
|
1778 const QString className = w->attributeClass();
|
|
1779
|
|
1780 // columns
|
|
1781 const QList<DomColumn*> columns = w->elementColumn();
|
|
1782 for (int i=0; i<columns.size(); ++i) {
|
|
1783 const DomColumn *column = columns.at(i);
|
|
1784
|
|
1785 const DomPropertyMap properties = propertyMap(column->elementProperty());
|
|
1786 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1787 const DomProperty *pixmap = properties.value(QLatin1String("pixmap"));
|
|
1788 const DomProperty *clickable = properties.value(QLatin1String("clickable"));
|
|
1789 const DomProperty *resizable = properties.value(QLatin1String("resizable"));
|
|
1790
|
|
1791 const QString txt = trCall(text->elementString());
|
|
1792 m_output << m_option.indent << varName << ".addColumn(" << txt << ");\n";
|
48
|
1793 m_refreshOut << m_option.indent << varName << ".header().setLabel(" << i << ", " << txt << ");\n";
|
1
|
1794
|
|
1795 if (pixmap) {
|
48
|
1796 m_output << m_option.indent << varName << ".header().>setLabel("
|
1
|
1797 << varName << ".header()->count() - 1, " << pixCall(pixmap) << ", " << txt << ");\n";
|
|
1798 }
|
|
1799
|
|
1800 if (clickable != 0) {
|
48
|
1801 m_output << m_option.indent << varName << ".header().setClickEnabled(" << clickable->elementBool() << ", " << varName << ".header()->count() - 1);\n";
|
1
|
1802 }
|
|
1803
|
|
1804 if (resizable != 0) {
|
48
|
1805 m_output << m_option.indent << varName << ".header().setResizeEnabled(" << resizable->elementBool() << ", " << varName << ".header()->count() - 1);\n";
|
1
|
1806 }
|
|
1807 }
|
|
1808
|
|
1809 if (w->elementItem().size()) {
|
|
1810 m_refreshOut << m_option.indent << varName << ".clear();\n";
|
|
1811
|
|
1812 initializeQ3ListViewItems(className, varName, w->elementItem());
|
|
1813 }
|
|
1814 }
|
|
1815
|
|
1816 void WriteInitialization::initializeQ3ListViewItems(const QString &className, const QString &varName, const QList<DomItem *> &items)
|
|
1817 {
|
|
1818 if (items.isEmpty())
|
|
1819 return;
|
|
1820
|
|
1821 // items
|
|
1822 for (int i=0; i<items.size(); ++i) {
|
|
1823 const DomItem *item = items.at(i);
|
|
1824
|
|
1825 const QString itemName = m_driver->unique(QLatin1String("__item"));
|
|
1826 m_refreshOut << "\n";
|
|
1827 m_refreshOut << m_option.indent << "Q3ListViewItem *" << itemName << " = new Q3ListViewItem(" << varName << ");\n";
|
|
1828
|
|
1829 int textCount = 0, pixCount = 0;
|
|
1830 const DomPropertyList properties = item->elementProperty();
|
|
1831 for (int i=0; i<properties.size(); ++i) {
|
|
1832 const DomProperty *p = properties.at(i);
|
|
1833 if (p->attributeName() == QLatin1String("text"))
|
|
1834 m_refreshOut << m_option.indent << itemName << ".setText(" << textCount++ << ", "
|
|
1835 << trCall(p->elementString()) << ");\n";
|
|
1836
|
|
1837 if (p->attributeName() == QLatin1String("pixmap"))
|
|
1838 m_refreshOut << m_option.indent << itemName << ".setPixmap(" << pixCount++ << ", "
|
|
1839 << pixCall(p) << ");\n";
|
|
1840 }
|
|
1841
|
|
1842 if (item->elementItem().size()) {
|
|
1843 m_refreshOut << m_option.indent << itemName << ".setOpen(true);\n";
|
|
1844 initializeQ3ListViewItems(className, itemName, item->elementItem());
|
|
1845 }
|
|
1846 }
|
|
1847 }
|
|
1848
|
|
1849
|
|
1850 void WriteInitialization::initializeQ3Table(DomWidget *w)
|
|
1851 {
|
|
1852 const QString varName = m_driver->findOrInsertWidget(w);
|
|
1853 const QString className = w->attributeClass();
|
|
1854
|
|
1855 // columns
|
|
1856 const QList<DomColumn*> columns = w->elementColumn();
|
|
1857
|
|
1858 for (int i=0; i<columns.size(); ++i) {
|
|
1859 const DomColumn *column = columns.at(i);
|
|
1860
|
|
1861 const DomPropertyMap properties = propertyMap(column->elementProperty());
|
|
1862 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1863 const DomProperty *pixmap = properties.value(QLatin1String("pixmap"));
|
|
1864
|
48
|
1865 m_refreshOut << m_option.indent << varName << ".horizontalHeader().setLabel(" << i << ", ";
|
1
|
1866 if (pixmap) {
|
|
1867 m_refreshOut << pixCall(pixmap) << ", ";
|
|
1868 }
|
|
1869 m_refreshOut << trCall(text->elementString()) << ");\n";
|
|
1870 }
|
|
1871
|
|
1872 // rows
|
|
1873 const QList<DomRow*> rows = w->elementRow();
|
|
1874 for (int i=0; i<rows.size(); ++i) {
|
|
1875 const DomRow *row = rows.at(i);
|
|
1876
|
|
1877 const DomPropertyMap properties = propertyMap(row->elementProperty());
|
|
1878 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1879 const DomProperty *pixmap = properties.value(QLatin1String("pixmap"));
|
|
1880
|
48
|
1881 m_refreshOut << m_option.indent << varName << ".verticalHeader().setLabel(" << i << ", ";
|
1
|
1882 if (pixmap) {
|
|
1883 m_refreshOut << pixCall(pixmap) << ", ";
|
|
1884 }
|
|
1885 m_refreshOut << trCall(text->elementString()) << ");\n";
|
|
1886 }
|
|
1887
|
|
1888
|
|
1889 //initializeQ3TableItems(className, varName, w->elementItem());
|
|
1890 }
|
|
1891
|
|
1892 void WriteInitialization::initializeQ3TableItems(const QString &className, const QString &varName, const QList<DomItem *> &items)
|
|
1893 {
|
|
1894 Q_UNUSED(className);
|
|
1895 Q_UNUSED(varName);
|
|
1896 Q_UNUSED(items);
|
|
1897 }
|
|
1898
|
|
1899 QString WriteInitialization::iconCall(const DomProperty *icon)
|
|
1900 {
|
|
1901 if (icon->kind() == DomProperty::IconSet)
|
|
1902 return writeIconProperties(icon->elementIconSet());
|
|
1903 return pixCall(icon);
|
|
1904 }
|
|
1905
|
|
1906 QString WriteInitialization::pixCall(const DomProperty *p) const
|
|
1907 {
|
|
1908 QString type, s;
|
|
1909 switch (p->kind()) {
|
|
1910 case DomProperty::IconSet:
|
|
1911 type = QLatin1String("QIcon");
|
|
1912 s = p->elementIconSet()->text();
|
|
1913 break;
|
|
1914 case DomProperty::Pixmap:
|
|
1915 type = QLatin1String("QPixmap");
|
|
1916 s = p->elementPixmap()->text();
|
|
1917 break;
|
|
1918 default:
|
|
1919 qWarning() << "Warning: Unknown icon format encountered. The ui-file was generated with a too-recent version of Designer.";
|
|
1920 return QLatin1String("QIcon()");
|
|
1921 break;
|
|
1922 }
|
|
1923 return pixCall(type, s);
|
|
1924 }
|
|
1925
|
|
1926 QString WriteInitialization::pixCall(const QString &t, const QString &text) const
|
|
1927 {
|
|
1928 QString type = t;
|
|
1929 if (text.isEmpty()) {
|
|
1930 type += QLatin1String("()");
|
|
1931 return type;
|
|
1932 }
|
|
1933 if (const DomImage *image = findImage(text)) {
|
|
1934 if (m_option.extractImages) {
|
|
1935 const QString format = image->elementData()->attributeFormat();
|
|
1936 const QString extension = format.left(format.indexOf(QLatin1Char('.'))).toLower();
|
48
|
1937 QString rc = QLatin1String("QPixmap(QString.fromUtf8(\":/");
|
1
|
1938 rc += m_generatedClass;
|
|
1939 rc += QLatin1String("/images/");
|
|
1940 rc += text;
|
|
1941 rc += QLatin1Char('.');
|
|
1942 rc += extension;
|
|
1943 rc += QLatin1String("\"))");
|
|
1944 return rc;
|
|
1945 }
|
|
1946 QString rc = WriteIconInitialization::iconFromDataFunction();
|
|
1947 rc += QLatin1Char('(');
|
|
1948 rc += text;
|
|
1949 rc += QLatin1String("_ID)");
|
|
1950 return rc;
|
|
1951 }
|
|
1952
|
|
1953 QString pixFunc = m_uic->pixmapFunction();
|
|
1954 if (pixFunc.isEmpty())
|
48
|
1955 pixFunc = QLatin1String("QString.fromUtf8");
|
1
|
1956
|
|
1957 type += QLatin1Char('(');
|
|
1958 type += pixFunc;
|
|
1959 type += QLatin1Char('(');
|
|
1960 type += fixString(text, m_option.indent);
|
|
1961 type += QLatin1String("))");
|
|
1962 return type;
|
|
1963 }
|
|
1964
|
|
1965 void WriteInitialization::initializeComboBox(DomWidget *w)
|
|
1966 {
|
|
1967 const QString varName = m_driver->findOrInsertWidget(w);
|
|
1968 const QString className = w->attributeClass();
|
|
1969
|
|
1970 const QList<DomItem*> items = w->elementItem();
|
|
1971
|
|
1972 if (items.isEmpty())
|
|
1973 return;
|
|
1974
|
|
1975 // If possible use qcombobox's addItems() which is much faster then a bunch of addItem() calls
|
|
1976 bool noIcons = true;
|
|
1977 QStringList list;
|
|
1978 for (int i=0; i<items.size(); ++i) {
|
|
1979 const DomItem *item = items.at(i);
|
|
1980 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
1981 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
1982 const DomProperty *pixmap = properties.value(QLatin1String("icon"));
|
|
1983 if (pixmap != 0) {
|
|
1984 noIcons = false;
|
|
1985 break;
|
|
1986 }
|
|
1987 list.append(trCall(text->elementString()));
|
|
1988 }
|
|
1989
|
|
1990 if (noIcons) {
|
|
1991 m_refreshOut << m_option.indent << varName << ".clear();\n";
|
|
1992 m_refreshOut << m_option.indent << varName << ".insertItems(0, QStringList()" << '\n';
|
|
1993 for (int i = 0; i < list.size(); ++i)
|
|
1994 m_refreshOut << m_option.indent << " << " << list.at(i) << "\n";
|
|
1995 m_refreshOut << m_option.indent << ");\n";
|
|
1996 } else {
|
|
1997 for (int i = 0; i < items.size(); ++i) {
|
|
1998 const DomItem *item = items.at(i);
|
|
1999 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
2000 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2001 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2002
|
|
2003 QString iconValue;
|
|
2004 if (icon)
|
|
2005 iconValue = iconCall(icon);
|
|
2006
|
|
2007 m_output << m_option.indent << varName << ".addItem(";
|
|
2008 if (icon)
|
|
2009 m_output << iconValue << ", ";
|
|
2010 m_output << "QString());\n";
|
|
2011
|
|
2012 if (!toString(text->elementString()).isEmpty())
|
|
2013 m_refreshOut << m_option.indent << varName << ".setItemText(" << i << ", " << trCall(text->elementString()) << ");\n";
|
|
2014 }
|
|
2015 m_refreshOut << "\n";
|
|
2016 }
|
|
2017 }
|
|
2018
|
|
2019 QString WriteInitialization::disableSorting(DomWidget *w, const QString &varName)
|
|
2020 {
|
|
2021 // turn off sortingEnabled to force programmatic item order (setItem())
|
|
2022 QString tempName;
|
|
2023 if (!w->elementItem().isEmpty()) {
|
|
2024 tempName = m_driver->unique(QLatin1String("__sortingEnabled"));
|
|
2025 m_refreshOut << "\n";
|
|
2026 m_refreshOut << m_option.indent << "const bool " << tempName
|
|
2027 << " = " << varName << ".isSortingEnabled();\n";
|
|
2028 m_refreshOut << m_option.indent << varName << ".setSortingEnabled(false);\n";
|
|
2029 }
|
|
2030 return tempName;
|
|
2031 }
|
|
2032
|
|
2033 void WriteInitialization::enableSorting(DomWidget *w, const QString &varName, const QString &tempName)
|
|
2034 {
|
|
2035 if (!w->elementItem().isEmpty()) {
|
|
2036 m_refreshOut << "\n";
|
|
2037 m_refreshOut << m_option.indent << varName << ".setSortingEnabled(" << tempName << ");\n";
|
|
2038 }
|
|
2039 }
|
|
2040
|
|
2041 void WriteInitialization::initializeListWidget(DomWidget *w)
|
|
2042 {
|
|
2043 const QString varName = m_driver->findOrInsertWidget(w);
|
|
2044 const QString className = w->attributeClass();
|
|
2045
|
|
2046 const QList<DomItem*> items = w->elementItem();
|
|
2047
|
|
2048 if (items.isEmpty())
|
|
2049 return;
|
|
2050
|
|
2051 QString tempName = disableSorting(w, varName);
|
|
2052 // items
|
|
2053 for (int i = 0; i < items.size(); ++i) {
|
|
2054 const DomItem *item = items.at(i);
|
|
2055
|
|
2056 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
2057 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2058 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2059
|
|
2060 QString itemCreation = QLatin1String("new QListWidgetItem(") + varName + QLatin1String(");\n");
|
|
2061 if (icon) {
|
|
2062 const QString iconValue = iconCall(icon);
|
|
2063 const QString itemName = m_driver->unique(QLatin1String("__listItem"));
|
48
|
2064 m_output << m_option.indent << "QListWidgetItem " << itemName << " = " << itemCreation;
|
1
|
2065 m_output << m_option.indent << itemName << ".setIcon(" << iconValue << ");\n";
|
|
2066 } else {
|
|
2067 m_output << m_option.indent << itemCreation;
|
|
2068 }
|
|
2069
|
|
2070 if (!toString(text->elementString()).isEmpty()) {
|
48
|
2071 m_refreshOut << m_option.indent << varName << ".item(" << i << ").setText(" << trCall(text->elementString()) << ");\n";
|
1
|
2072 }
|
|
2073 }
|
|
2074 enableSorting(w, varName, tempName);
|
|
2075 }
|
|
2076
|
|
2077 void WriteInitialization::initializeTreeWidget(DomWidget *w)
|
|
2078 {
|
|
2079 const QString varName = m_driver->findOrInsertWidget(w);
|
|
2080 const QString className = w->attributeClass();
|
|
2081
|
|
2082 // columns
|
|
2083 const QList<DomColumn*> columns = w->elementColumn();
|
|
2084 for (int i = 0; i < columns.size(); ++i) {
|
|
2085 const DomColumn *column = columns.at(i);
|
|
2086
|
|
2087 const DomPropertyMap properties = propertyMap(column->elementProperty());
|
|
2088 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2089 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2090
|
|
2091 if (!toString(text->elementString()).isEmpty()) {
|
|
2092 const QString txt = trCall(text->elementString());
|
48
|
2093 m_refreshOut << m_option.indent << varName << ".headerItem().setText(" << i << ", " << txt << ");\n";
|
1
|
2094 }
|
|
2095
|
|
2096 if (icon) {
|
|
2097 const QString iconValue = iconCall(icon);
|
48
|
2098 m_output << m_option.indent << varName << ".headerItem().setIcon("
|
1
|
2099 << i << ", " << iconValue << ");\n";
|
|
2100 }
|
|
2101 }
|
|
2102
|
|
2103 if (w->elementItem().size()) {
|
|
2104 QString tempName = disableSorting(w, varName);
|
|
2105
|
|
2106 initializeTreeWidgetItems(className, varName, w->elementItem(), varName + QLatin1String(".topLevelItem("));
|
|
2107
|
|
2108 enableSorting(w, varName, tempName);
|
|
2109 }
|
|
2110 }
|
|
2111
|
|
2112 void WriteInitialization::initializeTreeWidgetItems(const QString &className, const QString &varName, const QList<DomItem *> &items, const QString &parentPath)
|
|
2113 {
|
|
2114 if (items.isEmpty())
|
|
2115 return;
|
|
2116
|
|
2117 // items
|
|
2118 for (int i = 0; i < items.size(); ++i) {
|
|
2119 const DomItem *item = items.at(i);
|
|
2120
|
|
2121 int textCount = 0;
|
|
2122 const DomPropertyList properties = item->elementProperty();
|
|
2123 QStringList icons;
|
|
2124 for (int j = 0; j < properties.size(); ++j) {
|
|
2125 const DomProperty *p = properties.at(j);
|
|
2126 if (p->attributeName() == QLatin1String("text")) {
|
|
2127 if (!toString(p->elementString()).isEmpty()) {
|
48
|
2128 m_refreshOut << m_option.indent << parentPath << i << ").setText(" << textCount << ", "
|
1
|
2129 << trCall(p->elementString()) << ");\n";
|
|
2130 }
|
|
2131 textCount++;
|
|
2132 }
|
|
2133
|
|
2134 if (p->attributeName() == QLatin1String("icon")) {
|
|
2135 const QString iconValue = iconCall(p);
|
|
2136 icons << QLatin1String(".setIcon(")
|
|
2137 + QString::number(textCount - 1)
|
|
2138 + QLatin1String(", ") + iconValue + QLatin1String(");\n");
|
|
2139 }
|
|
2140 }
|
|
2141 if (icons.isEmpty() && (item->elementItem().size() == 0)) {
|
|
2142 m_output << m_option.indent << "new QTreeWidgetItem(" << varName << ");\n";
|
|
2143 } else {
|
|
2144 const QString itemName = m_driver->unique(QLatin1String("__treeItem"));
|
48
|
2145 m_output << m_option.indent << "QTreeWidgetItem " << itemName << " = new QTreeWidgetItem(" << varName << ");\n";
|
1
|
2146
|
|
2147 QStringListIterator it(icons);
|
|
2148 while (it.hasNext())
|
|
2149 m_output << m_option.indent << itemName << it.next();
|
|
2150
|
|
2151 if (item->elementItem().size()) {
|
|
2152 const QString childPath = parentPath + QString::number(i) + QLatin1String(")->child(");
|
|
2153 initializeTreeWidgetItems(className, itemName, item->elementItem(), childPath);
|
|
2154 }
|
|
2155 }
|
|
2156
|
|
2157 }
|
|
2158 m_output << "\n";
|
|
2159 }
|
|
2160
|
|
2161 void WriteInitialization::initializeTableWidget(DomWidget *w)
|
|
2162 {
|
|
2163 const QString varName = m_driver->findOrInsertWidget(w);
|
|
2164 const QString className = w->attributeClass();
|
|
2165
|
|
2166 // columns
|
|
2167 const QList<DomColumn *> columns = w->elementColumn();
|
|
2168
|
|
2169 if (columns.size() != 0) {
|
|
2170 m_output << m_option.indent << "if (" << varName << ".columnCount() < " << columns.size() << ")\n"
|
|
2171 << m_option.indent << m_option.indent << varName << ".setColumnCount(" << columns.size() << ");\n";
|
|
2172 }
|
|
2173
|
|
2174 for (int i = 0; i < columns.size(); ++i) {
|
|
2175 const DomColumn *column = columns.at(i);
|
|
2176
|
|
2177 const DomPropertyMap properties = propertyMap(column->elementProperty());
|
|
2178 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2179 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2180 if (text || icon) {
|
|
2181 const QString itemName = m_driver->unique(QLatin1String("__colItem"));
|
|
2182 m_output << m_option.indent << "QTableWidgetItem *"
|
|
2183 << itemName << " = new QTableWidgetItem();\n";
|
|
2184
|
|
2185 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty())
|
|
2186 m_refreshOut << m_option.indent << varName << ".horizontalHeaderItem(" << i << ")->setText("
|
|
2187 << trCall(text->elementString()) << ");\n";
|
|
2188
|
|
2189 if (icon && icon->attributeName() == QLatin1String("icon")) {
|
|
2190 const QString iconValue = iconCall(icon);
|
|
2191 m_output << m_option.indent << itemName << ".setIcon("
|
|
2192 << iconValue << ");\n";
|
|
2193 }
|
|
2194 m_output << m_option.indent << varName << ".setHorizontalHeaderItem("
|
|
2195 << i << ", " << itemName << ");\n";
|
|
2196 }
|
|
2197 }
|
|
2198
|
|
2199 // rows
|
|
2200 const QList<DomRow *> rows = w->elementRow();
|
|
2201
|
|
2202 if (rows.size() != 0) {
|
|
2203 m_output << m_option.indent << "if (" << varName << ".rowCount() < " << rows.size() << ")\n"
|
|
2204 << m_option.indent << m_option.indent << varName << ".setRowCount(" << rows.size() << ");\n";
|
|
2205 }
|
|
2206
|
|
2207 for (int i = 0; i < rows.size(); ++i) {
|
|
2208 const DomRow *row = rows.at(i);
|
|
2209
|
|
2210 const DomPropertyMap properties = propertyMap(row->elementProperty());
|
|
2211 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2212 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2213 if (text || icon) {
|
|
2214 const QString itemName = m_driver->unique(QLatin1String("__rowItem"));
|
48
|
2215 m_output << m_option.indent << "QTableWidgetItem "
|
1
|
2216 << itemName << " = new QTableWidgetItem();\n";
|
|
2217
|
|
2218 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty())
|
48
|
2219 m_refreshOut << m_option.indent << varName << ".verticalHeaderItem(" << i << ").setText("
|
1
|
2220 << trCall(text->elementString()) << ");\n";
|
|
2221
|
|
2222 if (icon && icon->attributeName() == QLatin1String("icon")) {
|
|
2223 const QString iconValue = iconCall(icon);
|
|
2224 m_output << m_option.indent << itemName << ".setIcon("
|
|
2225 << iconValue << ");\n";
|
|
2226 }
|
|
2227 m_output << m_option.indent << varName << ".setVerticalHeaderItem("
|
|
2228 << i << ", " << itemName << ");\n";
|
|
2229 }
|
|
2230 }
|
|
2231
|
|
2232 // items
|
|
2233 QString tempName = disableSorting(w, varName);
|
|
2234
|
|
2235 const QList<DomItem *> items = w->elementItem();
|
|
2236 for (int i = 0; i < items.size(); ++i) {
|
|
2237 const DomItem *item = items.at(i);
|
|
2238 if (item->hasAttributeRow() && item->hasAttributeColumn()) {
|
|
2239 const DomPropertyMap properties = propertyMap(item->elementProperty());
|
|
2240 const DomProperty *text = properties.value(QLatin1String("text"));
|
|
2241 const DomProperty *icon = properties.value(QLatin1String("icon"));
|
|
2242 if (text || icon) {
|
|
2243 const QString itemName = m_driver->unique(QLatin1String("__tableItem"));
|
48
|
2244 m_output << m_option.indent << "QTableWidgetItem "
|
1
|
2245 << itemName << " = new QTableWidgetItem();\n";
|
|
2246
|
|
2247 if (text && text->attributeName() == QLatin1String("text") && !toString(text->elementString()).isEmpty())
|
|
2248 m_refreshOut << m_option.indent << varName << ".item(" << item->attributeRow()
|
48
|
2249 << ", " << item->attributeColumn() << ").setText("
|
1
|
2250 << trCall(text->elementString()) << ");\n";
|
|
2251
|
|
2252 if (icon && icon->attributeName() == QLatin1String("icon")) {
|
|
2253 const QString iconValue = iconCall(icon);
|
|
2254 m_output << m_option.indent << itemName << ".setIcon("
|
|
2255 << iconValue << ");\n";
|
|
2256 }
|
|
2257
|
|
2258 m_output << m_option.indent << varName << ".setItem("
|
|
2259 << item->attributeRow() << ", "
|
|
2260 << item->attributeColumn() << ", "
|
|
2261 << itemName << ");\n";
|
|
2262 }
|
|
2263 }
|
|
2264 }
|
|
2265 enableSorting(w, varName, tempName);
|
|
2266 }
|
|
2267
|
|
2268 QString WriteInitialization::trCall(const QString &str, const QString &commentHint) const
|
|
2269 {
|
|
2270 if (str.isEmpty())
|
|
2271 return QLatin1String("QString()");
|
|
2272
|
|
2273 QString result;
|
|
2274 const QString comment = commentHint.isEmpty() ? QString(QLatin1Char('0')) : fixString(commentHint, m_option.indent);
|
|
2275
|
|
2276 if (m_option.translateFunction.isEmpty()) {
|
48
|
2277 result = QLatin1String("QApplication.translate(\"");
|
1
|
2278 result += m_generatedClass;
|
|
2279 result += QLatin1Char('"');
|
|
2280 result += QLatin1String(", ");
|
|
2281 } else {
|
|
2282 result = m_option.translateFunction;
|
|
2283 result += QLatin1Char('(');
|
|
2284 }
|
|
2285
|
|
2286 result += fixString(str, m_option.indent);
|
|
2287 result += QLatin1String(", ");
|
|
2288 result += comment;
|
|
2289
|
|
2290 if (m_option.translateFunction.isEmpty()) {
|
|
2291 result += QLatin1String(", ");
|
48
|
2292 result += QLatin1String("QApplication.UnicodeUTF8");
|
1
|
2293 }
|
|
2294
|
|
2295 result += QLatin1Char(')');
|
|
2296 return result;
|
|
2297 }
|
|
2298
|
|
2299 void WriteInitialization::initializeQ3SqlDataTable(DomWidget *w)
|
|
2300 {
|
|
2301 const DomPropertyMap properties = propertyMap(w->elementProperty());
|
|
2302
|
|
2303 const DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode"), 0);
|
|
2304 if (frameworkCode && toBool(frameworkCode->elementBool()) == false)
|
|
2305 return;
|
|
2306
|
|
2307 QString connection;
|
|
2308 QString table;
|
|
2309 QString field;
|
|
2310
|
|
2311 const DomProperty *db = properties.value(QLatin1String("database"), 0);
|
|
2312 if (db && db->elementStringList()) {
|
|
2313 const QStringList info = db->elementStringList()->elementString();
|
|
2314 connection = info.size() > 0 ? info.at(0) : QString();
|
|
2315 table = info.size() > 1 ? info.at(1) : QString();
|
|
2316 field = info.size() > 2 ? info.at(2) : QString();
|
|
2317 }
|
|
2318
|
|
2319 if (table.isEmpty() || connection.isEmpty()) {
|
|
2320 fprintf(stderr, "invalid database connection\n");
|
|
2321 return;
|
|
2322 }
|
|
2323
|
|
2324 const QString varName = m_driver->findOrInsertWidget(w);
|
|
2325
|
|
2326 m_output << m_option.indent << "if (!" << varName << ".sqlCursor()) {\n";
|
|
2327
|
|
2328 m_output << m_option.indent << m_option.indent << varName << ".setSqlCursor(";
|
|
2329
|
|
2330 if (connection == QLatin1String("(default)")) {
|
|
2331 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << "), false, true);\n";
|
|
2332 } else {
|
|
2333 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << ", true, " << connection << "Connection" << "), false, true);\n";
|
|
2334 }
|
|
2335 m_output << m_option.indent << m_option.indent << varName << ".refresh(qt.qt3support.Q3DataTable.RefreshAll);\n";
|
|
2336 m_output << m_option.indent << "}\n";
|
|
2337 }
|
|
2338
|
|
2339 void WriteInitialization::initializeQ3SqlDataBrowser(DomWidget *w)
|
|
2340 {
|
|
2341 const DomPropertyMap properties = propertyMap(w->elementProperty());
|
|
2342
|
|
2343 const DomProperty *frameworkCode = properties.value(QLatin1String("frameworkCode"), 0);
|
|
2344 if (frameworkCode && toBool(frameworkCode->elementBool()) == false)
|
|
2345 return;
|
|
2346
|
|
2347 QString connection;
|
|
2348 QString table;
|
|
2349 QString field;
|
|
2350
|
|
2351 const DomProperty *db = properties.value(QLatin1String("database"), 0);
|
|
2352 if (db && db->elementStringList()) {
|
|
2353 const QStringList info = db->elementStringList()->elementString();
|
|
2354 connection = info.size() > 0 ? info.at(0) : QString();
|
|
2355 table = info.size() > 1 ? info.at(1) : QString();
|
|
2356 field = info.size() > 2 ? info.at(2) : QString();
|
|
2357 }
|
|
2358
|
|
2359 if (table.isEmpty() || connection.isEmpty()) {
|
|
2360 fprintf(stderr, "invalid database connection\n");
|
|
2361 return;
|
|
2362 }
|
|
2363
|
|
2364 const QString varName = m_driver->findOrInsertWidget(w);
|
|
2365
|
|
2366 m_output << m_option.indent << "if (!" << varName << ".sqlCursor()) {\n";
|
|
2367
|
|
2368 m_output << m_option.indent << m_option.indent << varName << ".setSqlCursor(";
|
|
2369
|
|
2370 if (connection == QLatin1String("(default)")) {
|
|
2371 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << "), true);\n";
|
|
2372 } else {
|
|
2373 m_output << "new Q3SqlCursor(" << fixString(table, m_option.indent) << ", true, " << connection << "Connection" << "), false, true);\n";
|
|
2374 }
|
|
2375 m_output << m_option.indent << m_option.indent << varName << ".refresh();\n";
|
|
2376 m_output << m_option.indent << "}\n";
|
|
2377 }
|
|
2378
|
|
2379 void WriteInitialization::initializeMenu(DomWidget *w, const QString &/*parentWidget*/)
|
|
2380 {
|
|
2381 const QString menuName = m_driver->findOrInsertWidget(w);
|
|
2382 const QString menuAction = menuName + QLatin1String("Action");
|
|
2383
|
|
2384 const DomAction *action = m_driver->actionByName(menuAction);
|
|
2385 if (action && action->hasAttributeMenu()) {
|
|
2386 m_output << m_option.indent << menuAction << " = " << menuName << ".menuAction();\n";
|
|
2387 }
|
|
2388 }
|
|
2389
|
|
2390 QString WriteInitialization::trCall(DomString *str) const
|
|
2391 {
|
|
2392 return trCall(toString(str), str->attributeComment());
|
|
2393 }
|
|
2394
|
|
2395 bool WriteInitialization::isValidObject(const QString &name) const
|
|
2396 {
|
|
2397 return m_registeredWidgets.contains(name)
|
|
2398 || m_registeredActions.contains(name);
|
|
2399 }
|
|
2400
|
|
2401 QString WriteInitialization::findDeclaration(const QString &name)
|
|
2402 {
|
|
2403 const QString normalized = Driver::normalizedName(name);
|
|
2404
|
|
2405 if (DomWidget *widget = m_driver->widgetByName(normalized))
|
|
2406 return m_driver->findOrInsertWidget(widget);
|
|
2407 else if (DomAction *action = m_driver->actionByName(normalized))
|
|
2408 return m_driver->findOrInsertAction(action);
|
|
2409
|
|
2410 return QString();
|
|
2411 }
|
|
2412
|
|
2413 void WriteInitialization::acceptConnection(DomConnection *connection)
|
|
2414 {
|
|
2415 const QString sender = findDeclaration(connection->elementSender());
|
|
2416 const QString receiver = findDeclaration(connection->elementReceiver());
|
|
2417
|
|
2418 if (sender.isEmpty() || receiver.isEmpty())
|
|
2419 return;
|
|
2420
|
|
2421 m_output << m_option.indent << "QObject.connect("
|
|
2422 << sender
|
|
2423 << ", "
|
|
2424 << "SIGNAL(" << connection->elementSignal() << ')'
|
|
2425 << ", "
|
|
2426 << receiver
|
|
2427 << ", "
|
|
2428 << "SLOT(" << connection->elementSlot() << ')'
|
|
2429 << ");\n";
|
|
2430 }
|
|
2431
|
|
2432 DomImage *WriteInitialization::findImage(const QString &name) const
|
|
2433 {
|
|
2434 return m_registeredImages.value(name);
|
|
2435 }
|
|
2436
|
|
2437 DomWidget *WriteInitialization::findWidget(const QString &widgetClass)
|
|
2438 {
|
|
2439 for (int i = m_widgetChain.count() - 1; i >= 0; --i) {
|
|
2440 DomWidget *widget = m_widgetChain.at(i);
|
|
2441
|
|
2442 if (widget && m_uic->customWidgetsInfo()->extends(widget->attributeClass(), widgetClass))
|
|
2443 return widget;
|
|
2444 }
|
|
2445
|
|
2446 return 0;
|
|
2447 }
|
|
2448
|
|
2449 void WriteInitialization::acceptImage(DomImage *image)
|
|
2450 {
|
|
2451 if (!image->hasAttributeName())
|
|
2452 return;
|
|
2453
|
|
2454 m_registeredImages.insert(image->attributeName(), image);
|
|
2455 }
|
|
2456
|
|
2457 void WriteInitialization::acceptWidgetScripts(const DomScripts &widgetScripts, DomWidget *node, const DomWidgets &childWidgets)
|
|
2458 {
|
|
2459 // Add the per-class custom scripts to the per-widget ones.
|
|
2460 DomScripts scripts(widgetScripts);
|
|
2461
|
|
2462 if (DomScript *customWidgetScript = m_uic->customWidgetsInfo()->customWidgetScript(node->attributeClass()))
|
|
2463 scripts.push_front(customWidgetScript);
|
|
2464
|
|
2465 if (scripts.empty())
|
|
2466 return;
|
|
2467
|
|
2468 // concatenate script snippets
|
|
2469 QString script;
|
|
2470 foreach (const DomScript *domScript, scripts) {
|
|
2471 const QString snippet = domScript->text();
|
|
2472 if (!snippet.isEmpty()) {
|
|
2473 script += snippet.trimmed();
|
|
2474 script += QLatin1Char('\n');
|
|
2475 }
|
|
2476 }
|
|
2477 if (script.isEmpty())
|
|
2478 return;
|
|
2479
|
|
2480 // Build the list of children and insert call
|
|
2481 m_output << m_option.indent << "childWidgets.clear();\n";
|
|
2482 if (!childWidgets.empty()) {
|
|
2483 m_output << m_option.indent << "childWidgets";
|
|
2484 foreach (DomWidget *child, childWidgets) {
|
|
2485 m_output << " << " << m_driver->findOrInsertWidget(child);
|
|
2486 }
|
|
2487 m_output << ";\n";
|
|
2488 }
|
48
|
2489 m_output << m_option.indent << "scriptContext.run(QString.fromUtf8("
|
1
|
2490 << fixString(script, m_option.indent) << "), "
|
|
2491 << m_driver->findOrInsertWidget(node) << ", childWidgets);\n";
|
|
2492 }
|
|
2493
|
|
2494 } // namespace D
|
|
2495
|
|
2496 QT_END_NAMESPACE
|