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