author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 "ui3reader.h" |
|
43 |
#include "parser.h" |
|
44 |
#include "domtool.h" |
|
45 |
#include "ui4.h" |
|
46 |
#include "widgetinfo.h" |
|
47 |
#include "globaldefs.h" |
|
48 |
#include "qt3to4.h" |
|
49 |
#include "utils.h" |
|
50 |
#include "option.h" |
|
51 |
#include "cppextractimages.h" |
|
52 |
||
53 |
#include <QtDebug> |
|
54 |
#include <QFile> |
|
55 |
#include <QHash> |
|
56 |
#include <QPair> |
|
57 |
#include <QStringList> |
|
58 |
#include <QDateTime> |
|
59 |
#include <QRegExp> |
|
60 |
#include <QSizePolicy> |
|
61 |
||
62 |
#include <stdio.h> |
|
63 |
#include <stdlib.h> |
|
64 |
||
65 |
QT_BEGIN_NAMESPACE |
|
66 |
||
67 |
enum { warnHeaderGeneration = 0 }; |
|
68 |
||
69 |
#define CONVERT_PROPERTY(o, n) \ |
|
70 |
do { \ |
|
71 |
if (name == QLatin1String(o) \ |
|
72 |
&& !WidgetInfo::isValidProperty(className, (o)) \ |
|
73 |
&& WidgetInfo::isValidProperty(className, (n))) { \ |
|
74 |
prop->setAttributeName((n)); \ |
|
75 |
} \ |
|
76 |
} while (0) |
|
77 |
||
78 |
static QString classNameForObjectName(const QDomElement &widget, const QString &objectName) |
|
79 |
{ |
|
80 |
QList<QDomElement> widgetStack; |
|
81 |
widgetStack.append(widget); |
|
82 |
while (!widgetStack.isEmpty()) { |
|
83 |
QDomElement w = widgetStack.takeFirst(); |
|
84 |
QDomElement child = w.firstChild().toElement(); |
|
85 |
while (!child.isNull()) { |
|
86 |
if (child.tagName() == QLatin1String("property") |
|
87 |
&& child.attribute(QLatin1String("name")) == QLatin1String("name")) { |
|
88 |
QDomElement name = child.firstChild().toElement(); |
|
89 |
DomString str; |
|
90 |
str.read(name); |
|
91 |
if (str.text() == objectName) |
|
92 |
return w.attribute(QLatin1String("class")); |
|
93 |
} else if (child.tagName() == QLatin1String("widget") |
|
94 |
|| child.tagName() == QLatin1String("vbox") |
|
95 |
|| child.tagName() == QLatin1String("hbox") |
|
96 |
|| child.tagName() == QLatin1String("grid")) { |
|
97 |
widgetStack.prepend(child); |
|
98 |
} |
|
99 |
child = child.nextSibling().toElement(); |
|
100 |
} |
|
101 |
} |
|
102 |
return QString(); |
|
103 |
} |
|
104 |
||
105 |
// Check for potential KDE classes like |
|
106 |
// K3ListView or KLineEdit as precise as possible |
|
107 |
static inline bool isKDEClass(const QString &className) |
|
108 |
{ |
|
109 |
if (className.indexOf(QLatin1Char(':')) != -1) |
|
110 |
return false; |
|
111 |
const int size = className.size(); |
|
112 |
if (size < 3 || className.at(0) != QLatin1Char('K')) |
|
113 |
return false; |
|
114 |
// K3ListView |
|
115 |
if (className.at(1) == QLatin1Char('3')) { |
|
116 |
if (size < 4) |
|
117 |
return false; |
|
118 |
return className.at(2).isUpper() && className.at(3).isLower(); |
|
119 |
} |
|
120 |
// KLineEdit |
|
121 |
return className.at(1) .isUpper() && className.at(2).isLower(); |
|
122 |
} |
|
123 |
||
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
124 |
DomUI *Ui3Reader::generateUi4(const QDomElement &widget) |
0 | 125 |
{ |
126 |
QDomNodeList nl; |
|
127 |
candidateCustomWidgets.clear(); |
|
128 |
||
129 |
QString objClass = getClassName(widget); |
|
130 |
if (objClass.isEmpty()) |
|
131 |
return 0; |
|
132 |
QString objName = getObjectName(widget); |
|
133 |
||
134 |
DomUI *ui = new DomUI; |
|
135 |
ui->setAttributeVersion(QLatin1String("4.0")); |
|
136 |
||
137 |
QString pixmapFunction = QLatin1String("qPixmapFromMimeSource"); |
|
138 |
QStringList ui_tabstops; |
|
139 |
QStringList ui_custom_slots; |
|
140 |
QList<DomInclude*> ui_includes; |
|
141 |
QList<DomWidget*> ui_toolbars; |
|
142 |
QList<DomWidget*> ui_menubars; |
|
143 |
QList<DomAction*> ui_action_list; |
|
144 |
QList<DomActionGroup*> ui_action_group_list; |
|
145 |
QList<DomCustomWidget*> ui_customwidget_list; |
|
146 |
QList<DomConnection*> ui_connection_list; |
|
147 |
QList<QPair<int, int> > ui_connection_lineinfo_list; |
|
148 |
QString author, comment, exportMacro; |
|
149 |
QString klass; |
|
150 |
||
151 |
for (QDomElement n = root.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { |
|
152 |
QString tagName = n.tagName().toLower(); |
|
153 |
||
154 |
if (tagName == QLatin1String("tabstops")) { |
|
155 |
QDomElement n2 = n.firstChild().toElement(); |
|
156 |
while (!n2.isNull()) { |
|
157 |
if (n2.tagName().toLower() == QLatin1String("tabstop")) { |
|
158 |
QString name = n2.firstChild().toText().data(); |
|
159 |
ui_tabstops.append(name); |
|
160 |
} |
|
161 |
n2 = n2.nextSibling().toElement(); |
|
162 |
} |
|
163 |
} else if (tagName == QLatin1String("pixmapfunction")) { |
|
164 |
pixmapFunction = n.firstChild().toText().data(); |
|
165 |
} else if (tagName == QLatin1String("class")) { |
|
166 |
klass = n.firstChild().toText().data(); |
|
167 |
} else if (tagName == QLatin1String("author")) { |
|
168 |
author = n.firstChild().toText().data(); |
|
169 |
} else if (tagName == QLatin1String("comment")) { |
|
170 |
comment = n.firstChild().toText().data(); |
|
171 |
} else if (tagName == QLatin1String("exportmacro")) { |
|
172 |
exportMacro = n.firstChild().toText().data(); |
|
173 |
} else if ( n.tagName() == QLatin1String("includehints") ) { |
|
174 |
QDomElement n2 = n.firstChild().toElement(); |
|
175 |
while ( !n2.isNull() ) { |
|
176 |
if ( n2.tagName() == QLatin1String("includehint") ) { |
|
177 |
QString name = n2.firstChild().toText().data(); |
|
178 |
||
179 |
DomInclude *incl = new DomInclude(); |
|
180 |
incl->setText(fixHeaderName(name)); |
|
181 |
incl->setAttributeLocation(n.attribute(QLatin1String("location"), QLatin1String("local"))); |
|
182 |
ui_includes.append(incl); |
|
183 |
} |
|
184 |
n2 = n2.nextSibling().toElement(); |
|
185 |
} |
|
186 |
} else if (tagName == QLatin1String("includes")) { |
|
187 |
QDomElement n2 = n.firstChild().toElement(); |
|
188 |
while (!n2.isNull()) { |
|
189 |
if (n2.tagName().toLower() == QLatin1String("include")) { |
|
190 |
QString name = n2.firstChild().toText().data(); |
|
191 |
if (n2.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) { |
|
192 |
if (name.right(5) == QLatin1String(".ui.h")) |
|
193 |
continue; |
|
194 |
||
195 |
DomInclude *incl = new DomInclude(); |
|
196 |
incl->setText(fixHeaderName(name)); |
|
197 |
incl->setAttributeLocation(n2.attribute(QLatin1String("location"), QLatin1String("global"))); |
|
198 |
ui_includes.append(incl); |
|
199 |
} |
|
200 |
} |
|
201 |
n2 = n2.nextSibling().toElement(); |
|
202 |
} |
|
203 |
} else if (tagName == QLatin1String("include")) { |
|
204 |
QString name = n.firstChild().toText().data(); |
|
205 |
if (n.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) { |
|
206 |
if (name.right(5) == QLatin1String(".ui.h")) |
|
207 |
continue; |
|
208 |
||
209 |
DomInclude *incl = new DomInclude(); |
|
210 |
incl->setText(fixHeaderName(name)); |
|
211 |
incl->setAttributeLocation(n.attribute(QLatin1String("location"), QLatin1String("global"))); |
|
212 |
ui_includes.append(incl); |
|
213 |
} |
|
214 |
} else if (tagName == QLatin1String("layoutdefaults")) { |
|
215 |
QString margin = n.attribute(QLatin1String("margin")); |
|
216 |
QString spacing = n.attribute(QLatin1String("spacing")); |
|
217 |
||
218 |
DomLayoutDefault *layoutDefault = new DomLayoutDefault(); |
|
219 |
||
220 |
if (!margin.isEmpty()) |
|
221 |
layoutDefault->setAttributeMargin(margin.toInt()); |
|
222 |
||
223 |
if (!spacing.isEmpty()) |
|
224 |
layoutDefault->setAttributeSpacing(spacing.toInt()); |
|
225 |
||
226 |
ui->setElementLayoutDefault(layoutDefault); |
|
227 |
} else if (tagName == QLatin1String("layoutfunctions")) { |
|
228 |
QString margin = n.attribute(QLatin1String("margin")); |
|
229 |
QString spacing = n.attribute(QLatin1String("spacing")); |
|
230 |
||
231 |
DomLayoutFunction *layoutDefault = new DomLayoutFunction(); |
|
232 |
||
233 |
if (!margin.isEmpty()) |
|
234 |
layoutDefault->setAttributeMargin(margin); |
|
235 |
||
236 |
if (!spacing.isEmpty()) |
|
237 |
layoutDefault->setAttributeSpacing(spacing); |
|
238 |
||
239 |
ui->setElementLayoutFunction(layoutDefault); |
|
240 |
} else if (tagName == QLatin1String("images")) { |
|
241 |
QDomNodeList nl = n.elementsByTagName(QLatin1String("image")); |
|
242 |
QList<DomImage*> ui_image_list; |
|
243 |
for (int i=0; i<(int)nl.length(); i++) { |
|
244 |
QDomElement e = nl.item(i).toElement(); |
|
245 |
||
246 |
QDomElement tmp = e.firstChild().toElement(); |
|
247 |
if (tmp.tagName().toLower() != QLatin1String("data")) |
|
248 |
continue; |
|
249 |
||
250 |
// create the image |
|
251 |
DomImage *img = new DomImage(); |
|
252 |
img->setAttributeName(e.attribute(QLatin1String("name"))); |
|
253 |
||
254 |
// create the data |
|
255 |
DomImageData *data = new DomImageData(); |
|
256 |
img->setElementData(data); |
|
257 |
||
258 |
if (tmp.hasAttribute(QLatin1String("format"))) |
|
259 |
data->setAttributeFormat(tmp.attribute(QLatin1String("format"), QLatin1String("PNG"))); |
|
260 |
||
261 |
if (tmp.hasAttribute(QLatin1String("length"))) |
|
262 |
data->setAttributeLength(tmp.attribute(QLatin1String("length")).toInt()); |
|
263 |
||
264 |
data->setText(tmp.firstChild().toText().data()); |
|
265 |
||
266 |
ui_image_list.append(img); |
|
267 |
QString format = img->elementData()->attributeFormat(); |
|
268 |
QString extension = format.left(format.indexOf('.')).toLower(); |
|
269 |
m_imageMap[img->attributeName()] = img->attributeName() + QLatin1Char('.') + extension; |
|
270 |
} |
|
271 |
||
272 |
if (ui_image_list.size()) { |
|
273 |
DomImages *images = new DomImages(); |
|
274 |
images->setElementImage(ui_image_list); |
|
275 |
ui->setElementImages(images); |
|
276 |
} |
|
277 |
} else if (tagName == QLatin1String("actions")) { |
|
278 |
QDomElement n2 = n.firstChild().toElement(); |
|
279 |
while (!n2.isNull()) { |
|
280 |
QString tag = n2.tagName().toLower(); |
|
281 |
||
282 |
if (tag == QLatin1String("action")) { |
|
283 |
DomAction *action = new DomAction(); |
|
284 |
action->read(n2); |
|
285 |
||
286 |
QList<DomProperty*> properties = action->elementProperty(); |
|
287 |
QString actionName = fixActionProperties(properties); |
|
288 |
action->setAttributeName(actionName); |
|
289 |
action->setElementProperty(properties); |
|
290 |
||
291 |
if (actionName.isEmpty()) { |
|
292 |
delete action; |
|
293 |
} else |
|
294 |
ui_action_list.append(action); |
|
295 |
} else if (tag == QLatin1String("actiongroup")) { |
|
296 |
DomActionGroup *g= new DomActionGroup(); |
|
297 |
g->read(n2); |
|
298 |
||
299 |
fixActionGroup(g); |
|
300 |
ui_action_group_list.append(g); |
|
301 |
} |
|
302 |
n2 = n2.nextSibling().toElement(); |
|
303 |
} |
|
304 |
} else if (tagName == QLatin1String("toolbars")) { |
|
305 |
QDomElement n2 = n.firstChild().toElement(); |
|
306 |
while (!n2.isNull()) { |
|
307 |
if (n2.tagName().toLower() == QLatin1String("toolbar")) { |
|
308 |
DomWidget *tb = createWidget(n2, QLatin1String("QToolBar")); |
|
309 |
ui_toolbars.append(tb); |
|
310 |
} |
|
311 |
n2 = n2.nextSibling().toElement(); |
|
312 |
} |
|
313 |
} else if (tagName == QLatin1String("menubar")) { |
|
314 |
DomWidget *tb = createWidget(n, QLatin1String("QMenuBar")); |
|
315 |
ui_menubars.append(tb); |
|
316 |
} else if (tagName == QLatin1String("customwidgets")) { |
|
317 |
QDomElement n2 = n.firstChild().toElement(); |
|
318 |
while (!n2.isNull()) { |
|
319 |
if (n2.tagName().toLower() == QLatin1String("customwidget")) { |
|
320 |
||
321 |
DomCustomWidget *customWidget = new DomCustomWidget; |
|
322 |
customWidget->read(n2); |
|
323 |
||
324 |
if (!customWidget->hasElementExtends()) |
|
325 |
customWidget->setElementExtends(QLatin1String("QWidget")); |
|
326 |
||
327 |
QDomElement n3 = n2.firstChild().toElement(); |
|
328 |
QString cl; |
|
329 |
||
330 |
QList<DomPropertyData*> ui_property_list; |
|
331 |
||
332 |
while (!n3.isNull()) { |
|
333 |
QString tagName = n3.tagName().toLower(); |
|
334 |
||
335 |
if (tagName == QLatin1String("property")) { |
|
336 |
DomPropertyData *p = new DomPropertyData(); |
|
337 |
p->read(n3); |
|
338 |
||
339 |
ui_property_list.append(p); |
|
340 |
} |
|
341 |
||
342 |
n3 = n3.nextSibling().toElement(); |
|
343 |
} |
|
344 |
||
345 |
if (ui_property_list.size()) { |
|
346 |
DomProperties *properties = new DomProperties(); |
|
347 |
properties->setElementProperty(ui_property_list); |
|
348 |
customWidget->setElementProperties(properties); |
|
349 |
} |
|
350 |
||
351 |
ui_customwidget_list.append(customWidget); |
|
352 |
} |
|
353 |
n2 = n2.nextSibling().toElement(); |
|
354 |
} |
|
355 |
} else if (tagName == QLatin1String("connections")) { |
|
356 |
QDomElement n2 = n.firstChild().toElement(); |
|
357 |
while (!n2.isNull()) { |
|
358 |
if (n2.tagName().toLower() == QLatin1String("connection")) { |
|
359 |
||
360 |
DomConnection *connection = new DomConnection; |
|
361 |
connection->read(n2); |
|
362 |
||
363 |
QString signal = fixMethod(connection->elementSignal()); |
|
364 |
QString slot = fixMethod(connection->elementSlot()); |
|
365 |
connection->setElementSignal(signal); |
|
366 |
connection->setElementSlot(slot); |
|
367 |
||
368 |
ui_connection_list.append(connection); |
|
369 |
ui_connection_lineinfo_list.append( |
|
370 |
QPair<int, int>(n2.lineNumber(), n2.columnNumber())); |
|
371 |
} |
|
372 |
n2 = n2.nextSibling().toElement(); |
|
373 |
} |
|
374 |
} else if (tagName == QLatin1String("slots")) { |
|
375 |
QDomElement n2 = n.firstChild().toElement(); |
|
376 |
while (!n2.isNull()) { |
|
377 |
if (n2.tagName().toLower() == QLatin1String("slot")) { |
|
378 |
QString name = n2.firstChild().toText().data(); |
|
379 |
ui_custom_slots.append(fixMethod(Parser::cleanArgs(name))); |
|
380 |
} |
|
381 |
n2 = n2.nextSibling().toElement(); |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
385 |
||
386 |
// validate the connections |
|
387 |
for (int i = 0; i < ui_connection_list.size(); ++i) { |
|
388 |
DomConnection *conn = ui_connection_list.at(i); |
|
389 |
QPair<int, int> lineinfo = ui_connection_lineinfo_list.at(i); |
|
390 |
QString sender = conn->elementSender(); |
|
391 |
QString senderClass = fixClassName(classNameForObjectName(widget, sender)); |
|
392 |
QString signal = conn->elementSignal(); |
|
393 |
QString receiver = conn->elementReceiver(); |
|
394 |
QString receiverClass = fixClassName(classNameForObjectName(widget, receiver)); |
|
395 |
QString slot = conn->elementSlot(); |
|
396 |
||
397 |
if (!WidgetInfo::isValidSignal(senderClass, signal)) { |
|
398 |
errorInvalidSignal(signal, sender, senderClass, |
|
399 |
lineinfo.first, lineinfo.second); |
|
400 |
} else if (!WidgetInfo::isValidSlot(receiverClass, slot)) { |
|
401 |
bool resolved = false; |
|
402 |
if (objName == receiver) { |
|
403 |
// see if it's a custom slot |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
404 |
foreach (const QString &cs, ui_custom_slots) { |
0 | 405 |
if (cs == slot) { |
406 |
resolved = true; |
|
407 |
break; |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
if (!resolved) { |
|
412 |
errorInvalidSlot(slot, receiver, receiverClass, |
|
413 |
lineinfo.first, lineinfo.second); |
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
DomWidget *w = createWidget(widget); |
|
419 |
Q_ASSERT(w != 0); |
|
420 |
||
421 |
QList<DomWidget*> l = w->elementWidget(); |
|
422 |
l += ui_toolbars; |
|
423 |
l += ui_menubars; |
|
424 |
w->setElementWidget(l); |
|
425 |
||
426 |
if (ui_action_group_list.size()) |
|
427 |
w->setElementActionGroup(ui_action_group_list); |
|
428 |
||
429 |
if (ui_action_list.size()) |
|
430 |
w->setElementAction(ui_action_list); |
|
431 |
||
432 |
ui->setElementWidget(w); |
|
433 |
||
434 |
if (klass.isEmpty()) |
|
435 |
klass = w->attributeName(); |
|
436 |
||
437 |
ui->setElementClass(klass); |
|
438 |
ui->setElementAuthor(author); |
|
439 |
ui->setElementComment(comment); |
|
440 |
ui->setElementExportMacro(exportMacro); |
|
441 |
||
442 |
if (!ui->elementImages()) |
|
443 |
ui->setElementPixmapFunction(pixmapFunction); |
|
444 |
||
445 |
for (int i=0; i<ui_customwidget_list.size(); ++i) { |
|
446 |
const QString name = ui_customwidget_list.at(i)->elementClass(); |
|
447 |
if (candidateCustomWidgets.contains(name)) |
|
448 |
candidateCustomWidgets.remove(name); |
|
449 |
} |
|
450 |
||
451 |
||
452 |
QMapIterator<QString, bool> it(candidateCustomWidgets); |
|
453 |
while (it.hasNext()) { |
|
454 |
it.next(); |
|
455 |
||
456 |
const QString customClass = it.key(); |
|
457 |
QString baseClass; |
|
458 |
||
459 |
if (customClass.endsWith(QLatin1String("ListView"))) |
|
460 |
baseClass = QLatin1String("Q3ListView"); |
|
461 |
else if (customClass.endsWith(QLatin1String("ListBox"))) |
|
462 |
baseClass = QLatin1String("Q3ListBox"); |
|
463 |
else if (customClass.endsWith(QLatin1String("IconView"))) |
|
464 |
baseClass = QLatin1String("Q3IconView"); |
|
465 |
else if (customClass.endsWith(QLatin1String("ComboBox"))) |
|
466 |
baseClass = QLatin1String("QComboBox"); |
|
467 |
||
468 |
if (baseClass.isEmpty()) |
|
469 |
continue; |
|
470 |
||
471 |
DomCustomWidget *customWidget = new DomCustomWidget(); |
|
472 |
customWidget->setElementClass(customClass); |
|
473 |
customWidget->setElementExtends(baseClass); |
|
474 |
||
475 |
// Magic header generation feature for legacy KDE forms |
|
476 |
// (for example, filesharing/advanced/kcm_sambaconf/share.ui) |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
477 |
if ((m_options & ImplicitIncludes) && isKDEClass(customClass)) { |
0 | 478 |
QString header = customClass.toLower(); |
479 |
header += QLatin1String(".h"); |
|
480 |
DomHeader *domHeader = new DomHeader; |
|
481 |
domHeader->setText(header); |
|
482 |
domHeader->setAttributeLocation(QLatin1String("global")); |
|
483 |
customWidget->setElementHeader(domHeader); |
|
484 |
if (warnHeaderGeneration) { |
|
485 |
const QString msg = QString::fromUtf8("Warning: generated header '%1' for class '%2'.").arg(header).arg(customClass); |
|
486 |
qWarning("%s", qPrintable(msg)); |
|
487 |
} |
|
488 |
} |
|
489 |
ui_customwidget_list.append(customWidget); |
|
490 |
} |
|
491 |
||
492 |
if (ui_customwidget_list.size()) { |
|
493 |
DomCustomWidgets *customWidgets = new DomCustomWidgets(); |
|
494 |
customWidgets->setElementCustomWidget(ui_customwidget_list); |
|
495 |
ui->setElementCustomWidgets(customWidgets); |
|
496 |
} |
|
497 |
||
498 |
if (ui_tabstops.size()) { |
|
499 |
DomTabStops *tabStops = new DomTabStops(); |
|
500 |
tabStops->setElementTabStop(ui_tabstops); |
|
501 |
ui->setElementTabStops(tabStops); |
|
502 |
} |
|
503 |
||
504 |
if (ui_includes.size()) { |
|
505 |
DomIncludes *includes = new DomIncludes(); |
|
506 |
includes->setElementInclude(ui_includes); |
|
507 |
ui->setElementIncludes(includes); |
|
508 |
} |
|
509 |
||
510 |
if (ui_connection_list.size()) { |
|
511 |
DomConnections *connections = new DomConnections(); |
|
512 |
connections->setElementConnection(ui_connection_list); |
|
513 |
ui->setElementConnections(connections); |
|
514 |
} |
|
515 |
||
516 |
ui->setAttributeStdSetDef(stdsetdef); |
|
517 |
||
518 |
if (m_extractImages) { |
|
519 |
Option opt; |
|
520 |
opt.extractImages = m_extractImages; |
|
521 |
opt.qrcOutputFile = m_qrcOutputFile; |
|
522 |
CPP::ExtractImages(opt).acceptUI(ui); |
|
523 |
||
524 |
ui->clearElementImages(); |
|
525 |
||
526 |
DomResources *res = ui->elementResources(); |
|
527 |
if (!res) { |
|
528 |
res = new DomResources(); |
|
529 |
} |
|
530 |
DomResource *incl = new DomResource(); |
|
531 |
incl->setAttributeLocation(m_qrcOutputFile); |
|
532 |
QList<DomResource *> inclList = res->elementInclude(); |
|
533 |
inclList.append(incl); |
|
534 |
res->setElementInclude(inclList); |
|
535 |
if (!ui->elementResources()) |
|
536 |
ui->setElementResources(res); |
|
537 |
} |
|
538 |
||
539 |
return ui; |
|
540 |
} |
|
541 |
||
542 |
||
543 |
||
544 |
QString Ui3Reader::fixActionProperties(QList<DomProperty*> &properties, |
|
545 |
bool isActionGroup) |
|
546 |
{ |
|
547 |
QString objectName; |
|
548 |
||
549 |
QMutableListIterator<DomProperty*> it(properties); |
|
550 |
while (it.hasNext()) { |
|
551 |
DomProperty *prop = it.next(); |
|
552 |
QString name = prop->attributeName(); |
|
553 |
||
554 |
if (name == QLatin1String("name")) { |
|
555 |
objectName = prop->elementCstring(); |
|
556 |
} else if (isActionGroup && name == QLatin1String("exclusive")) { |
|
557 |
// continue |
|
558 |
} else if (isActionGroup) { |
|
559 |
errorInvalidProperty(name, objectName, isActionGroup ? QLatin1String("QActionGroup") : QLatin1String("QAction"), -1, -1); |
|
560 |
delete prop; |
|
561 |
it.remove(); |
|
562 |
} else if (name == QLatin1String("menuText")) { |
|
563 |
prop->setAttributeName(QLatin1String("text")); |
|
564 |
} else if (name == QLatin1String("text")) { |
|
565 |
prop->setAttributeName(QLatin1String("iconText")); |
|
566 |
} else if (name == QLatin1String("iconSet")) { |
|
567 |
prop->setAttributeName(QLatin1String("icon")); |
|
568 |
} else if (name == QLatin1String("accel")) { |
|
569 |
prop->setAttributeName(QLatin1String("shortcut")); |
|
570 |
} else if (name == QLatin1String("toggleAction")) { |
|
571 |
prop->setAttributeName(QLatin1String("checkable")); |
|
572 |
} else if (name == QLatin1String("on")) { |
|
573 |
prop->setAttributeName(QLatin1String("checked")); |
|
574 |
} else if (!WidgetInfo::isValidProperty(QLatin1String("QAction"), name)) { |
|
575 |
errorInvalidProperty(name, objectName, isActionGroup ? QLatin1String("QActionGroup") : QLatin1String("QAction"), -1, -1); |
|
576 |
delete prop; |
|
577 |
it.remove(); |
|
578 |
} |
|
579 |
} |
|
580 |
||
581 |
return objectName; |
|
582 |
} |
|
583 |
||
584 |
void Ui3Reader::fixActionGroup(DomActionGroup *g) |
|
585 |
{ |
|
586 |
QList<DomActionGroup*> groups = g->elementActionGroup(); |
|
587 |
for (int i=0; i<groups.size(); ++i) { |
|
588 |
fixActionGroup(groups.at(i)); |
|
589 |
} |
|
590 |
||
591 |
QList<DomAction*> actions = g->elementAction(); |
|
592 |
for (int i=0; i<actions.size(); ++i) { |
|
593 |
DomAction *a = actions.at(i); |
|
594 |
||
595 |
QList<DomProperty*> properties = a->elementProperty(); |
|
596 |
QString name = fixActionProperties(properties); |
|
597 |
a->setElementProperty(properties); |
|
598 |
||
599 |
if (name.size()) |
|
600 |
a->setAttributeName(name); |
|
601 |
} |
|
602 |
||
603 |
QList<DomProperty*> properties = g->elementProperty(); |
|
604 |
QString name = fixActionProperties(properties, true); |
|
605 |
g->setElementProperty(properties); |
|
606 |
||
607 |
if (name.size()) |
|
608 |
g->setAttributeName(name); |
|
609 |
} |
|
610 |
||
611 |
QString Ui3Reader::fixClassName(const QString &className) const |
|
612 |
{ |
|
613 |
return m_porting->renameClass(className); |
|
614 |
} |
|
615 |
||
616 |
QString Ui3Reader::fixHeaderName(const QString &headerName) const |
|
617 |
{ |
|
618 |
return m_porting->renameHeader(headerName); |
|
619 |
} |
|
620 |
||
621 |
DomWidget *Ui3Reader::createWidget(const QDomElement &w, const QString &widgetClass) |
|
622 |
{ |
|
623 |
DomWidget *ui_widget = new DomWidget; |
|
624 |
||
625 |
QString className = widgetClass; |
|
626 |
if (className.isEmpty()) |
|
627 |
className = w.attribute(QLatin1String("class")); |
|
628 |
className = fixClassName(className); |
|
629 |
||
630 |
if ((className.endsWith(QLatin1String("ListView")) && className != QLatin1String("Q3ListView")) |
|
631 |
|| (className.endsWith(QLatin1String("ListBox")) && className != QLatin1String("Q3ListBox")) |
|
632 |
|| (className.endsWith(QLatin1String("ComboBox")) && className != QLatin1String("QComboBox")) |
|
633 |
|| (className.endsWith(QLatin1String("IconView")) && className != QLatin1String("Q3IconView"))) |
|
634 |
candidateCustomWidgets.insert(className, true); |
|
635 |
||
636 |
bool isMenu = (className == QLatin1String("QMenuBar") || className == QLatin1String("QMenu")); |
|
637 |
||
638 |
ui_widget->setAttributeClass(className); |
|
639 |
||
640 |
QList<DomWidget*> ui_child_list; |
|
641 |
QList<DomRow*> ui_row_list; |
|
642 |
QList<DomColumn*> ui_column_list; |
|
643 |
QList<DomItem*> ui_item_list; |
|
644 |
QList<DomProperty*> ui_property_list; |
|
645 |
QList<DomProperty*> ui_attribute_list; |
|
646 |
QList<DomLayout*> ui_layout_list; |
|
647 |
QList<DomActionRef*> ui_action_list; |
|
648 |
QList<DomWidget*> ui_mainwindow_child_list; |
|
649 |
||
650 |
createProperties(w, &ui_property_list, className); |
|
651 |
createAttributes(w, &ui_attribute_list, className); |
|
652 |
||
653 |
DomWidget *ui_mainWindow = 0; |
|
654 |
DomWidget *ui_centralWidget = 0; |
|
655 |
if (className == QLatin1String("QMainWindow") || className == QLatin1String("Q3MainWindow")) { |
|
656 |
ui_centralWidget = new DomWidget; |
|
657 |
ui_centralWidget->setAttributeClass(QLatin1String("QWidget")); |
|
658 |
ui_mainwindow_child_list.append(ui_centralWidget); |
|
659 |
ui_mainWindow = ui_widget; |
|
660 |
} |
|
661 |
||
662 |
QDomElement e = w.firstChild().toElement(); |
|
663 |
const bool inQ3ToolBar = className == QLatin1String("Q3ToolBar"); |
|
664 |
while (!e.isNull()) { |
|
665 |
QString t = e.tagName().toLower(); |
|
666 |
if (t == QLatin1String("vbox") || t == QLatin1String("hbox") || t == QLatin1String("grid")) { |
|
667 |
DomLayout *lay = createLayout(e); |
|
668 |
Q_ASSERT(lay != 0); |
|
669 |
||
670 |
if (ui_layout_list.isEmpty()) { |
|
671 |
ui_layout_list.append(lay); |
|
672 |
} else { |
|
673 |
// it's not possible to have more than one layout for widget! |
|
674 |
delete lay; |
|
675 |
} |
|
676 |
} else if (t == QLatin1String("spacer")) { |
|
677 |
// hmm, spacer as child of a widget.. it doesn't make sense, so skip it! |
|
678 |
} else if (t == QLatin1String("widget")) { |
|
679 |
DomWidget *ui_child = createWidget(e); |
|
680 |
Q_ASSERT(ui_child != 0); |
|
681 |
||
682 |
bool isLayoutWidget = ui_child->attributeClass() == QLatin1String("QLayoutWidget"); |
|
683 |
if (isLayoutWidget) |
|
684 |
ui_child->setAttributeClass(QLatin1String("QWidget")); |
|
685 |
||
686 |
foreach (DomLayout *layout, ui_child->elementLayout()) { |
|
687 |
fixLayoutMargin(layout); |
|
688 |
} |
|
689 |
||
690 |
QString widgetClass = ui_child->attributeClass(); |
|
691 |
if (widgetClass == QLatin1String("QMenuBar") || widgetClass == QLatin1String("QToolBar") |
|
692 |
|| widgetClass == QLatin1String("QStatusBar")) { |
|
693 |
ui_mainwindow_child_list.append(ui_child); |
|
694 |
} else { |
|
695 |
ui_child_list.append(ui_child); |
|
696 |
} |
|
697 |
||
698 |
if (inQ3ToolBar) { |
|
699 |
DomActionRef *ui_action_ref = new DomActionRef(); |
|
700 |
ui_action_ref->setAttributeName(ui_child->attributeName()); |
|
701 |
ui_action_list.append(ui_action_ref); |
|
702 |
} |
|
703 |
} else if (t == QLatin1String("action")) { |
|
704 |
DomActionRef *a = new DomActionRef(); |
|
705 |
a->read(e); |
|
706 |
ui_action_list.append(a); |
|
707 |
} else if (t == QLatin1String("separator")) { |
|
708 |
DomActionRef *a = new DomActionRef(); |
|
709 |
a->setAttributeName(QLatin1String("separator")); |
|
710 |
ui_action_list.append(a); |
|
711 |
} else if (t == QLatin1String("property")) { |
|
712 |
// skip the property it is already handled by createProperties |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
713 |
const QString name = e.attribute(QLatin1String("name")); // change the varname this widget |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
714 |
if (name == QLatin1String("name")) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
715 |
// Do not name QLayoutWidget if layout names are to be used. |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
716 |
const bool applyName = !(m_options & PreserveLayoutNames) || className != QLatin1String("QLayoutWidget"); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
717 |
if (applyName) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
718 |
ui_widget->setAttributeName(DomTool::readProperty(w, QLatin1String("name"), QVariant()).toString()); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
719 |
} |
0 | 720 |
} else if (t == QLatin1String("row")) { |
721 |
DomRow *row = new DomRow(); |
|
722 |
row->read(e); |
|
723 |
ui_row_list.append(row); |
|
724 |
} else if (t == QLatin1String("column")) { |
|
725 |
DomColumn *column = new DomColumn(); |
|
726 |
column->read(e); |
|
727 |
ui_column_list.append(column); |
|
728 |
} else if (isMenu && t == QLatin1String("item")) { |
|
729 |
QString text = e.attribute(QLatin1String("text")); |
|
730 |
QString name = e.attribute(QLatin1String("name")); |
|
731 |
QString accel = e.attribute(QLatin1String("accel")); |
|
732 |
||
733 |
QList<DomProperty*> properties; |
|
734 |
||
735 |
DomProperty *atitle = new DomProperty(); |
|
736 |
atitle->setAttributeName(QLatin1String("title")); |
|
737 |
DomString *str = new DomString(); |
|
738 |
str->setText(text); |
|
739 |
atitle->setElementString(str); |
|
740 |
properties.append(atitle); |
|
741 |
||
742 |
DomWidget *menu = createWidget(e, QLatin1String("QMenu")); |
|
743 |
menu->setAttributeName(name); |
|
744 |
menu->setElementProperty(properties); |
|
745 |
ui_child_list.append(menu); |
|
746 |
||
747 |
DomActionRef *a = new DomActionRef(); |
|
748 |
a->setAttributeName(name); |
|
749 |
ui_action_list.append(a); |
|
750 |
||
751 |
} else if (t == QLatin1String("item")) { |
|
752 |
DomItem *item = new DomItem(); |
|
753 |
item->read(e); |
|
754 |
ui_item_list.append(item); |
|
755 |
} |
|
756 |
||
757 |
e = e.nextSibling().toElement(); |
|
758 |
} |
|
759 |
||
760 |
ui_widget->setElementProperty(ui_property_list); |
|
761 |
ui_widget->setElementAttribute(ui_attribute_list); |
|
762 |
||
763 |
if (ui_centralWidget != 0) { |
|
764 |
Q_ASSERT(ui_mainWindow != 0); |
|
765 |
ui_mainWindow->setElementWidget(ui_mainwindow_child_list); |
|
766 |
ui_widget = ui_centralWidget; |
|
767 |
} |
|
768 |
||
769 |
ui_widget->setElementWidget(ui_child_list); |
|
770 |
ui_widget->setElementAddAction(ui_action_list); |
|
771 |
ui_widget->setElementRow(ui_row_list); |
|
772 |
ui_widget->setElementColumn(ui_column_list); |
|
773 |
ui_widget->setElementItem(ui_item_list); |
|
774 |
ui_widget->setElementLayout(ui_layout_list); |
|
775 |
||
776 |
//ui_widget->setAttributeName(p->elementCstring()); |
|
777 |
||
778 |
return ui_mainWindow ? ui_mainWindow : ui_widget; |
|
779 |
} |
|
780 |
||
781 |
DomLayout *Ui3Reader::createLayout(const QDomElement &w) |
|
782 |
{ |
|
783 |
DomLayout *lay = new DomLayout(); |
|
784 |
||
785 |
QList<DomLayoutItem*> ui_item_list; |
|
786 |
QList<DomProperty*> ui_property_list; |
|
787 |
QList<DomProperty*> ui_attribute_list; |
|
788 |
||
789 |
QString tagName = w.tagName().toLower(); |
|
790 |
||
791 |
QString className; |
|
792 |
if (tagName == QLatin1String("vbox")) |
|
793 |
className = QLatin1String("QVBoxLayout"); |
|
794 |
else if (tagName == QLatin1String("hbox")) |
|
795 |
className = QLatin1String("QHBoxLayout"); |
|
796 |
else |
|
797 |
className = QLatin1String("QGridLayout"); |
|
798 |
||
799 |
lay->setAttributeClass(className); |
|
800 |
||
801 |
createProperties(w, &ui_property_list, className); |
|
802 |
createAttributes(w, &ui_attribute_list, className); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
803 |
if (m_options & PreserveLayoutNames) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
804 |
const QString layoutName = getLayoutName(w); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
805 |
if (!layoutName.isEmpty()) |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
806 |
lay->setAttributeName(layoutName); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
807 |
} |
0 | 808 |
|
809 |
QDomElement e = w.firstChild().toElement(); |
|
810 |
while (!e.isNull()) { |
|
811 |
QString t = e.tagName().toLower(); |
|
812 |
if (t == QLatin1String("vbox") |
|
813 |
|| t == QLatin1String("hbox") |
|
814 |
|| t == QLatin1String("grid") |
|
815 |
|| t == QLatin1String("spacer") |
|
816 |
|| t == QLatin1String("widget")) { |
|
817 |
DomLayoutItem *lay_item = createLayoutItem(e); |
|
818 |
Q_ASSERT(lay_item != 0); |
|
819 |
ui_item_list.append(lay_item); |
|
820 |
} |
|
821 |
||
822 |
e = e.nextSibling().toElement(); |
|
823 |
} |
|
824 |
||
825 |
lay->setElementItem(ui_item_list); |
|
826 |
lay->setElementProperty(ui_property_list); |
|
827 |
lay->setElementAttribute(ui_attribute_list); |
|
828 |
||
829 |
return lay; |
|
830 |
} |
|
831 |
||
832 |
DomLayoutItem *Ui3Reader::createLayoutItem(const QDomElement &e) |
|
833 |
{ |
|
834 |
DomLayoutItem *lay_item = new DomLayoutItem; |
|
835 |
||
836 |
QString tagName = e.tagName().toLower(); |
|
837 |
if (tagName == QLatin1String("widget")) { |
|
838 |
DomWidget *ui_widget = createWidget(e); |
|
839 |
Q_ASSERT(ui_widget != 0); |
|
840 |
||
841 |
if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget") |
|
842 |
&& ui_widget->elementLayout().size() == 1) { |
|
843 |
QList<DomLayout*> layouts = ui_widget->elementLayout(); |
|
844 |
||
845 |
ui_widget->setElementLayout(QList<DomLayout*>()); |
|
846 |
delete ui_widget; |
|
847 |
||
848 |
DomLayout *layout = layouts.first(); |
|
849 |
fixLayoutMargin(layout); |
|
850 |
lay_item->setElementLayout(layout); |
|
851 |
} else { |
|
852 |
if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget")) |
|
853 |
ui_widget->setAttributeClass(QLatin1String("QWidget")); |
|
854 |
||
855 |
lay_item->setElementWidget(ui_widget); |
|
856 |
} |
|
857 |
} else if (tagName == QLatin1String("spacer")) { |
|
858 |
DomSpacer *ui_spacer = new DomSpacer(); |
|
859 |
QList<DomProperty*> properties; |
|
860 |
||
861 |
QByteArray name = DomTool::readProperty(e, QLatin1String("name"), QLatin1String("spacer")).toByteArray(); |
|
862 |
||
863 |
Variant var; |
|
864 |
var.createSize(0, 0); |
|
865 |
||
866 |
QVariant def = qVariantFromValue(var); |
|
867 |
||
868 |
Size size = asVariant(DomTool::readProperty(e, QLatin1String("sizeHint"), def)).size; |
|
869 |
QString sizeType = QLatin1String("QSizePolicy::") + DomTool::readProperty(e, QLatin1String("sizeType"), QLatin1String("Expanding")).toString(); |
|
870 |
QString orientation = QLatin1String("Qt::") + DomTool::readProperty(e, QLatin1String("orientation"), QLatin1String("Horizontal")).toString(); |
|
871 |
||
872 |
ui_spacer->setAttributeName(QLatin1String(name)); |
|
873 |
||
874 |
DomProperty *prop = 0; |
|
875 |
||
876 |
// sizeHint |
|
877 |
prop = new DomProperty(); |
|
878 |
prop->setAttributeName(QLatin1String("sizeHint")); |
|
879 |
prop->setElementSize(new DomSize()); |
|
880 |
prop->elementSize()->setElementWidth(size.width); |
|
881 |
prop->elementSize()->setElementHeight(size.height); |
|
882 |
properties.append(prop); |
|
883 |
||
884 |
// sizeType |
|
885 |
prop = new DomProperty(); |
|
886 |
prop->setAttributeName(QLatin1String("sizeType")); |
|
887 |
prop->setElementEnum(sizeType); |
|
888 |
properties.append(prop); |
|
889 |
||
890 |
// orientation |
|
891 |
prop = new DomProperty(); |
|
892 |
prop->setAttributeName(QLatin1String("orientation")); |
|
893 |
prop->setElementEnum(orientation); |
|
894 |
properties.append(prop); |
|
895 |
||
896 |
ui_spacer->setElementProperty(properties); |
|
897 |
lay_item->setElementSpacer(ui_spacer); |
|
898 |
} else { |
|
899 |
DomLayout *ui_layout = createLayout(e); |
|
900 |
Q_ASSERT(ui_layout != 0); |
|
901 |
||
902 |
fixLayoutMargin(ui_layout); |
|
903 |
lay_item->setElementLayout(ui_layout); |
|
904 |
} |
|
905 |
||
906 |
if (e.hasAttribute(QLatin1String("row"))) |
|
907 |
lay_item->setAttributeRow(e.attribute(QLatin1String("row")).toInt()); |
|
908 |
if (e.hasAttribute(QLatin1String("column"))) |
|
909 |
lay_item->setAttributeColumn(e.attribute(QLatin1String("column")).toInt()); |
|
910 |
if (e.hasAttribute(QLatin1String("rowspan"))) |
|
911 |
lay_item->setAttributeRowSpan(e.attribute(QLatin1String("rowspan")).toInt()); |
|
912 |
if (e.hasAttribute(QLatin1String("colspan"))) |
|
913 |
lay_item->setAttributeColSpan(e.attribute(QLatin1String("colspan")).toInt()); |
|
914 |
||
915 |
return lay_item; |
|
916 |
} |
|
917 |
||
918 |
void Ui3Reader::fixLayoutMargin(DomLayout *ui_layout) |
|
919 |
{ |
|
920 |
Q_UNUSED(ui_layout) |
|
921 |
} |
|
922 |
||
923 |
static void addBooleanFontSubProperty(QDomDocument &doc, |
|
924 |
const QString &name, const QString &value, |
|
925 |
QDomElement &fontElement) |
|
926 |
{ |
|
927 |
if (value == QLatin1String("true") || value == QLatin1String("1")) { |
|
928 |
QDomElement child = doc.createElement(name); |
|
929 |
child.appendChild(doc.createTextNode(QLatin1String("true"))); |
|
930 |
fontElement.appendChild(child); |
|
931 |
} else { |
|
932 |
if (value == QLatin1String("false") || value == QLatin1String("0")) { |
|
933 |
QDomElement child = doc.createElement(name); |
|
934 |
child.appendChild(doc.createTextNode(QLatin1String("false"))); |
|
935 |
fontElement.appendChild(child); |
|
936 |
} |
|
937 |
} |
|
938 |
} |
|
939 |
||
940 |
QDomElement Ui3Reader::findDerivedFontProperties(const QDomElement &n) const |
|
941 |
{ |
|
942 |
bool italic = false; |
|
943 |
bool bold = false; |
|
944 |
bool underline = false; |
|
945 |
bool strikeout = false; |
|
946 |
bool family = false; |
|
947 |
bool pointsize = false; |
|
948 |
||
949 |
QDomDocument doc = n.ownerDocument(); |
|
950 |
QDomElement result = doc.createElement(QLatin1String("font")); |
|
951 |
||
952 |
QDomNode pn = n.parentNode(); |
|
953 |
while (!pn.isNull()) { |
|
954 |
for (QDomElement e = pn.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) { |
|
955 |
if (e.tagName().toLower() == QLatin1String("property") && |
|
956 |
e.attribute(QLatin1String("name")) == QLatin1String("font")) { |
|
957 |
QDomElement f = e.firstChild().toElement(); |
|
958 |
for (QDomElement fp = f.firstChild().toElement(); !fp.isNull(); fp = fp.nextSibling().toElement()) { |
|
959 |
QString name = fp.tagName().toLower(); |
|
960 |
QString text = fp.text(); |
|
961 |
if (!italic && name == QLatin1String("italic")) { |
|
962 |
italic = true; |
|
963 |
addBooleanFontSubProperty(doc, name, text, result); |
|
964 |
} else if (!bold && name == QLatin1String("bold")) { |
|
965 |
bold = true; |
|
966 |
addBooleanFontSubProperty(doc, name, text, result); |
|
967 |
} else if (!underline && name == QLatin1String("underline")) { |
|
968 |
underline = true; |
|
969 |
addBooleanFontSubProperty(doc, name, text, result); |
|
970 |
} else if (!strikeout && name == QLatin1String("strikeout")) { |
|
971 |
strikeout = true; |
|
972 |
addBooleanFontSubProperty(doc, name, text, result); |
|
973 |
} else if (!family && name == QLatin1String("family")) { |
|
974 |
family = true; |
|
975 |
QDomElement child = doc.createElement(name); |
|
976 |
child.appendChild(doc.createTextNode(text)); |
|
977 |
result.appendChild(child); |
|
978 |
} else if (!pointsize && name == QLatin1String("pointsize")) { |
|
979 |
pointsize = true; |
|
980 |
QDomElement child = doc.createElement(name); |
|
981 |
child.appendChild(doc.createTextNode(text)); |
|
982 |
result.appendChild(child); |
|
983 |
} |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
pn = pn.parentNode(); |
|
988 |
} |
|
989 |
||
990 |
return result; |
|
991 |
} |
|
992 |
||
993 |
void Ui3Reader::createProperties(const QDomElement &n, QList<DomProperty*> *properties, |
|
994 |
const QString &className) |
|
995 |
{ |
|
996 |
QString objectName; |
|
997 |
||
998 |
bool wordWrapFound = false; |
|
999 |
bool wordWrapPropertyFound = false; |
|
1000 |
||
1001 |
for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) { |
|
1002 |
if (e.tagName().toLower() == QLatin1String("property")) { |
|
1003 |
QString name = e.attribute(QLatin1String("name")); |
|
1004 |
||
1005 |
// changes in QPalette |
|
1006 |
if (name == QLatin1String("colorGroup") |
|
1007 |
|| name == QLatin1String("paletteForegroundColor") |
|
1008 |
|| name == QLatin1String("paletteBackgroundColor") |
|
1009 |
|| name == QLatin1String("backgroundMode") |
|
1010 |
|| name == QLatin1String("backgroundOrigin") |
|
1011 |
|| name == QLatin1String("paletteBackgroundPixmap") |
|
1012 |
|| name == QLatin1String("backgroundBrush")) { |
|
1013 |
errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber()); |
|
1014 |
continue; |
|
1015 |
} |
|
1016 |
||
1017 |
// changes in QFrame |
|
1018 |
if (name == QLatin1String("contentsRect")) { |
|
1019 |
errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber()); |
|
1020 |
continue; |
|
1021 |
} |
|
1022 |
||
1023 |
// changes in QWidget |
|
1024 |
if (name == QLatin1String("underMouse") |
|
1025 |
|| name == QLatin1String("ownFont")) { |
|
1026 |
errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber()); |
|
1027 |
continue; |
|
1028 |
} |
|
1029 |
||
1030 |
if (name == QLatin1String("font")) { |
|
1031 |
QDomElement f = e.firstChild().toElement(); |
|
1032 |
e.appendChild(findDerivedFontProperties(f)); |
|
1033 |
e.removeChild(f); |
|
1034 |
} |
|
1035 |
||
1036 |
DomProperty *prop = readProperty(e); |
|
1037 |
if (!prop) |
|
1038 |
continue; |
|
1039 |
||
1040 |
if (prop->kind() == DomProperty::String) { |
|
1041 |
QDomNodeList comments = e.elementsByTagName(QLatin1String("comment")); |
|
1042 |
if (comments.length()) { |
|
1043 |
QString comment = comments.item(0).firstChild().toText().data(); |
|
1044 |
if (!comment.isEmpty()) |
|
1045 |
prop->elementString()->setAttributeComment(comment); |
|
1046 |
} |
|
1047 |
} |
|
1048 |
||
1049 |
// objectName |
|
1050 |
if (name == QLatin1String("name")) { |
|
1051 |
objectName = prop->elementCstring(); |
|
1052 |
continue; |
|
1053 |
} |
|
1054 |
||
1055 |
if (className == QLatin1String("Line") |
|
1056 |
&& prop->attributeName() == QLatin1String("orientation")) { |
|
1057 |
delete prop; |
|
1058 |
continue; |
|
1059 |
} |
|
1060 |
||
1061 |
if (className.mid(1) == QLatin1String("LineEdit")) { |
|
1062 |
if (name == QLatin1String("hasMarkedText")) { |
|
1063 |
prop->setAttributeName(QLatin1String("hasSelectedText")); |
|
1064 |
} else if (name == QLatin1String("edited")) { |
|
1065 |
prop->setAttributeName(QLatin1String("modified")); |
|
1066 |
} else if (name == QLatin1String("markedText")) { |
|
1067 |
prop->setAttributeName(QLatin1String("selectedText")); |
|
1068 |
} |
|
1069 |
} |
|
1070 |
||
1071 |
if (className.endsWith(QLatin1String("ComboBox"))) { |
|
1072 |
CONVERT_PROPERTY(QLatin1String("currentItem"), QLatin1String("currentIndex")); |
|
1073 |
CONVERT_PROPERTY(QLatin1String("insertionPolicy"), QLatin1String("insertPolicy")); |
|
1074 |
} |
|
1075 |
||
1076 |
if (className == QLatin1String("QToolBar")) { |
|
1077 |
if (name == QLatin1String("label")) { |
|
1078 |
prop->setAttributeName(QLatin1String("windowTitle")); |
|
1079 |
} |
|
1080 |
} |
|
1081 |
||
1082 |
CONVERT_PROPERTY(QLatin1String("customWhatsThis"), QLatin1String("whatsThis")); |
|
1083 |
CONVERT_PROPERTY(QLatin1String("icon"), QLatin1String("windowIcon")); |
|
1084 |
CONVERT_PROPERTY(QLatin1String("iconText"), QLatin1String("windowIconText")); |
|
1085 |
CONVERT_PROPERTY(QLatin1String("caption"), QLatin1String("windowTitle")); |
|
1086 |
||
1087 |
if (name == QLatin1String("name")) { |
|
1088 |
continue; // skip the property name |
|
1089 |
} |
|
1090 |
||
1091 |
if (name == QLatin1String("accel")) { |
|
1092 |
prop->setAttributeName(QLatin1String("shortcut")); |
|
1093 |
} |
|
1094 |
||
1095 |
CONVERT_PROPERTY(QLatin1String("pixmap"), QLatin1String("icon")); |
|
1096 |
CONVERT_PROPERTY(QLatin1String("iconSet"), QLatin1String("icon")); |
|
1097 |
CONVERT_PROPERTY(QLatin1String("textLabel"), QLatin1String("text")); |
|
1098 |
||
1099 |
CONVERT_PROPERTY(QLatin1String("toggleButton"), QLatin1String("checkable")); |
|
1100 |
CONVERT_PROPERTY(QLatin1String("on"), QLatin1String("checked")); |
|
1101 |
||
1102 |
CONVERT_PROPERTY(QLatin1String("maxValue"), QLatin1String("maximum")); |
|
1103 |
CONVERT_PROPERTY(QLatin1String("minValue"), QLatin1String("minimum")); |
|
1104 |
CONVERT_PROPERTY(QLatin1String("lineStep"), QLatin1String("singleStep")); |
|
1105 |
||
1106 |
// QSlider |
|
1107 |
CONVERT_PROPERTY(QLatin1String("tickmarks"), QLatin1String("tickPosition")); |
|
1108 |
||
1109 |
name = prop->attributeName(); // sync the name |
|
1110 |
||
1111 |
if (className == QLatin1String("QLabel")) { |
|
1112 |
if (name == QLatin1String("alignment")) { |
|
1113 |
const QString v = prop->elementSet(); |
|
1114 |
if (v.contains(QRegExp(QLatin1String("\\bWordBreak\\b")))) |
|
1115 |
wordWrapFound = true; |
|
1116 |
} else if (name == QLatin1String("wordWrap")) { |
|
1117 |
wordWrapPropertyFound = true; |
|
1118 |
} |
|
1119 |
} |
|
1120 |
||
1121 |
// resolve the flags and enumerator |
|
1122 |
if (prop->kind() == DomProperty::Set) { |
|
1123 |
QStringList flags = prop->elementSet().split(QLatin1Char('|')); |
|
1124 |
QStringList v; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1125 |
foreach (const QString &fl, flags) { |
0 | 1126 |
QString e = WidgetInfo::resolveEnumerator(className, fl); |
1127 |
if (e.isEmpty()) { |
|
1128 |
e = m_porting->renameEnumerator(className + QLatin1String("::") + fl); |
|
1129 |
} |
|
1130 |
||
1131 |
if (e.isEmpty()) { |
|
1132 |
fprintf(stderr, "uic3: flag '%s' for widget '%s' is not supported\n", fl.latin1(), className.latin1()); |
|
1133 |
continue; |
|
1134 |
} |
|
1135 |
||
1136 |
v.append(e); |
|
1137 |
} |
|
1138 |
||
1139 |
if (v.isEmpty()) { |
|
1140 |
delete prop; |
|
1141 |
continue; |
|
1142 |
} |
|
1143 |
||
1144 |
prop->setElementSet(v.join(QLatin1String("|"))); |
|
1145 |
} else if (prop->kind() == DomProperty::Enum) { |
|
1146 |
QString e = WidgetInfo::resolveEnumerator(className, prop->elementEnum()); |
|
1147 |
if (e.isEmpty()) { |
|
1148 |
e = m_porting->renameEnumerator(className + QLatin1String("::") + prop->elementEnum()); |
|
1149 |
} |
|
1150 |
||
1151 |
if (e.isEmpty()) { |
|
1152 |
fprintf(stderr, "uic3: enumerator '%s' for widget '%s' is not supported\n", |
|
1153 |
prop->elementEnum().latin1(), className.latin1()); |
|
1154 |
||
1155 |
delete prop; |
|
1156 |
continue; |
|
1157 |
} |
|
1158 |
prop->setElementEnum(e); |
|
1159 |
} |
|
1160 |
||
1161 |
||
1162 |
if (className.size() |
|
1163 |
&& !(className == QLatin1String("QLabel") && name == QLatin1String("buddy")) |
|
1164 |
&& !(name == QLatin1String("buttonGroupId")) |
|
1165 |
&& !(name == QLatin1String("frameworkCode")) |
|
1166 |
&& !(name == QLatin1String("database"))) { |
|
1167 |
if (!WidgetInfo::isValidProperty(className, name)) { |
|
1168 |
errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber()); |
|
1169 |
delete prop; |
|
1170 |
} else { |
|
1171 |
properties->append(prop); |
|
1172 |
} |
|
1173 |
} else { |
|
1174 |
properties->append(prop); |
|
1175 |
} |
|
1176 |
} |
|
1177 |
} |
|
1178 |
if (className == QLatin1String("QLabel") && !wordWrapPropertyFound) { |
|
1179 |
DomProperty *wordWrap = new DomProperty(); |
|
1180 |
wordWrap->setAttributeName(QLatin1String("wordWrap")); |
|
1181 |
if (wordWrapFound) |
|
1182 |
wordWrap->setElementBool(QLatin1String("true")); |
|
1183 |
else |
|
1184 |
wordWrap->setElementBool(QLatin1String("false")); |
|
1185 |
properties->append(wordWrap); |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
static int toQt4SizePolicy(int qt3SizePolicy) |
|
1190 |
{ |
|
1191 |
if (qt3SizePolicy == 2) // qt 3 Ignored value |
|
1192 |
return QSizePolicy::Ignored; |
|
1193 |
return qt3SizePolicy; |
|
1194 |
} |
|
1195 |
||
1196 |
DomProperty *Ui3Reader::readProperty(const QDomElement &e) |
|
1197 |
{ |
|
1198 |
QString name = e.firstChild().toElement().tagName().toLower(); |
|
1199 |
||
1200 |
if (name == QLatin1String("class")) // skip class |
|
1201 |
name = e.firstChild().nextSibling().toElement().tagName().toLower(); |
|
1202 |
||
1203 |
DomProperty *p = new DomProperty; |
|
1204 |
p->read(e); |
|
1205 |
||
1206 |
if (p->kind() == DomProperty::Number) { |
|
1207 |
QString value = e.firstChild().toElement().firstChild().nodeValue(); |
|
1208 |
||
1209 |
if (value.contains(QLatin1Char('.'))) { |
|
1210 |
p->setElementDouble(value.toDouble()); |
|
1211 |
} |
|
1212 |
} else if (p->kind() == DomProperty::Pixmap) { |
|
1213 |
DomResourcePixmap *domPix = p->elementPixmap(); |
|
1214 |
if (m_extractImages) { |
|
1215 |
QString imageFile = domPix->text() + QLatin1String(".xpm"); |
|
1216 |
if (m_imageMap.contains(domPix->text())) |
|
1217 |
imageFile = m_imageMap.value(domPix->text()); |
|
1218 |
domPix->setAttributeResource(m_qrcOutputFile); |
|
1219 |
domPix->setText(QLatin1String(":/") + nameOfClass + QLatin1String("/images/") + imageFile); |
|
1220 |
} |
|
1221 |
} else if (p->kind() == DomProperty::SizePolicy) { |
|
1222 |
DomSizePolicy *sp = p->elementSizePolicy(); |
|
1223 |
if (sp) { |
|
1224 |
if (sp->hasElementHSizeType()) |
|
1225 |
sp->setElementHSizeType(toQt4SizePolicy(sp->elementHSizeType())); |
|
1226 |
if (sp->hasElementVSizeType()) |
|
1227 |
sp->setElementVSizeType(toQt4SizePolicy(sp->elementVSizeType())); |
|
1228 |
} |
|
1229 |
} else if (p->kind() == DomProperty::Unknown) { |
|
1230 |
delete p; |
|
1231 |
p = 0; |
|
1232 |
} |
|
1233 |
||
1234 |
return p; |
|
1235 |
} |
|
1236 |
||
1237 |
void Ui3Reader::createAttributes(const QDomElement &n, QList<DomProperty*> *properties, |
|
1238 |
const QString &className) |
|
1239 |
{ |
|
1240 |
Q_UNUSED(className); |
|
1241 |
||
1242 |
for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) { |
|
1243 |
if (e.tagName().toLower() == QLatin1String("attribute")) { |
|
1244 |
QString name = e.attribute(QLatin1String("name")); |
|
1245 |
||
1246 |
DomProperty *prop = readProperty(e); |
|
1247 |
if (!prop) |
|
1248 |
continue; |
|
1249 |
||
1250 |
properties->append(prop); |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |
|
1254 |
||
1255 |
QString Ui3Reader::fixDeclaration(const QString &d) const |
|
1256 |
{ |
|
1257 |
QString text; |
|
1258 |
||
1259 |
int i = 0; |
|
1260 |
while (i < d.size()) { |
|
1261 |
QChar ch = d.at(i); |
|
1262 |
||
1263 |
if (ch.isLetter() || ch == QLatin1Char('_')) { |
|
1264 |
int start = i; |
|
1265 |
while (i < d.size() && (d.at(i).isLetterOrNumber() || d.at(i) == QLatin1Char('_'))) |
|
1266 |
++i; |
|
1267 |
||
1268 |
text += fixClassName(d.mid(start, i-start)); |
|
1269 |
} else { |
|
1270 |
text += ch; |
|
1271 |
++i; |
|
1272 |
} |
|
1273 |
} |
|
1274 |
||
1275 |
return text; |
|
1276 |
} |
|
1277 |
||
1278 |
/* |
|
1279 |
fixes a (possible composite) type name |
|
1280 |
*/ |
|
1281 |
QString Ui3Reader::fixType(const QString &t) const |
|
1282 |
{ |
|
1283 |
QString newText = t; |
|
1284 |
//split type name on <>*& and whitespace |
|
1285 |
QStringList typeNames = t.split(QRegExp(QLatin1String("<|>|\\*|&| ")), QString::SkipEmptyParts); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1286 |
foreach(const QString &typeName , typeNames) { |
0 | 1287 |
QString newName = fixClassName(typeName); |
1288 |
if( newName != typeName ) { |
|
1289 |
newText.replace(typeName, newName); |
|
1290 |
} |
|
1291 |
} |
|
1292 |
return newText; |
|
1293 |
} |
|
1294 |
||
1295 |
QString Ui3Reader::fixMethod(const QString &method) const |
|
1296 |
{ |
|
1297 |
const QByteArray normalized = QMetaObject::normalizedSignature(method.toLatin1()); |
|
1298 |
QByteArray result; |
|
1299 |
int index = normalized.indexOf('('); |
|
1300 |
if (index == -1) |
|
1301 |
return QLatin1String(normalized); |
|
1302 |
result.append(normalized.left(++index)); |
|
1303 |
int limit = normalized.length()-1; |
|
1304 |
while (index < limit) { |
|
1305 |
QByteArray type; |
|
1306 |
while ((index < limit) && (normalized.at(index) != ',')) |
|
1307 |
type.append(normalized.at(index++)); |
|
1308 |
result.append(fixType(QLatin1String(type)).toLatin1()); |
|
1309 |
if ((index < limit) && (normalized.at(index) == ',')) |
|
1310 |
result.append(normalized.at(index++)); |
|
1311 |
} |
|
1312 |
result.append(normalized.mid(index)); |
|
1313 |
return QLatin1String(result); |
|
1314 |
} |
|
1315 |
||
1316 |
QT_END_NAMESPACE |