source: trunk/src/tools/uic3/converter.cpp@ 1147

Last change on this file since 1147 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 50.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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
65QT_BEGIN_NAMESPACE
66
67enum { 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
78static 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
107static 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
124DomUI *Ui3Reader::generateUi4(const QDomElement &widget)
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
404 foreach (const QString &cs, ui_custom_slots) {
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)
477 if ((m_options & ImplicitIncludes) && isKDEClass(customClass)) {
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.limitXPM_LineLength = (m_options & LimitXPM_LineLength) ? 1 : 0;
522 opt.qrcOutputFile = m_qrcOutputFile;
523 CPP::ExtractImages(opt).acceptUI(ui);
524
525 ui->clearElementImages();
526
527 DomResources *res = ui->elementResources();
528 if (!res) {
529 res = new DomResources();
530 }
531 DomResource *incl = new DomResource();
532 incl->setAttributeLocation(m_qrcOutputFile);
533 QList<DomResource *> inclList = res->elementInclude();
534 inclList.append(incl);
535 res->setElementInclude(inclList);
536 if (!ui->elementResources())
537 ui->setElementResources(res);
538 }
539
540 return ui;
541}
542
543
544
545QString Ui3Reader::fixActionProperties(QList<DomProperty*> &properties,
546 bool isActionGroup)
547{
548 QString objectName;
549
550 QMutableListIterator<DomProperty*> it(properties);
551 while (it.hasNext()) {
552 DomProperty *prop = it.next();
553 QString name = prop->attributeName();
554
555 if (name == QLatin1String("name")) {
556 objectName = prop->elementCstring();
557 } else if (isActionGroup && name == QLatin1String("exclusive")) {
558 // continue
559 } else if (isActionGroup) {
560 errorInvalidProperty(name, objectName, isActionGroup ? QLatin1String("QActionGroup") : QLatin1String("QAction"), -1, -1);
561 delete prop;
562 it.remove();
563 } else if (name == QLatin1String("menuText")) {
564 prop->setAttributeName(QLatin1String("text"));
565 } else if (name == QLatin1String("text")) {
566 prop->setAttributeName(QLatin1String("iconText"));
567 } else if (name == QLatin1String("iconSet")) {
568 prop->setAttributeName(QLatin1String("icon"));
569 } else if (name == QLatin1String("accel")) {
570 prop->setAttributeName(QLatin1String("shortcut"));
571 } else if (name == QLatin1String("toggleAction")) {
572 prop->setAttributeName(QLatin1String("checkable"));
573 } else if (name == QLatin1String("on")) {
574 prop->setAttributeName(QLatin1String("checked"));
575 } else if (!WidgetInfo::isValidProperty(QLatin1String("QAction"), name)) {
576 errorInvalidProperty(name, objectName, isActionGroup ? QLatin1String("QActionGroup") : QLatin1String("QAction"), -1, -1);
577 delete prop;
578 it.remove();
579 }
580 }
581
582 return objectName;
583}
584
585void Ui3Reader::fixActionGroup(DomActionGroup *g)
586{
587 QList<DomActionGroup*> groups = g->elementActionGroup();
588 for (int i=0; i<groups.size(); ++i) {
589 fixActionGroup(groups.at(i));
590 }
591
592 QList<DomAction*> actions = g->elementAction();
593 for (int i=0; i<actions.size(); ++i) {
594 DomAction *a = actions.at(i);
595
596 QList<DomProperty*> properties = a->elementProperty();
597 QString name = fixActionProperties(properties);
598 a->setElementProperty(properties);
599
600 if (name.size())
601 a->setAttributeName(name);
602 }
603
604 QList<DomProperty*> properties = g->elementProperty();
605 QString name = fixActionProperties(properties, true);
606 g->setElementProperty(properties);
607
608 if (name.size())
609 g->setAttributeName(name);
610}
611
612QString Ui3Reader::fixClassName(const QString &className) const
613{
614 return m_porting->renameClass(className);
615}
616
617QString Ui3Reader::fixHeaderName(const QString &headerName) const
618{
619 return m_porting->renameHeader(headerName);
620}
621
622DomWidget *Ui3Reader::createWidget(const QDomElement &w, const QString &widgetClass)
623{
624 DomWidget *ui_widget = new DomWidget;
625
626 QString className = widgetClass;
627 if (className.isEmpty())
628 className = w.attribute(QLatin1String("class"));
629 className = fixClassName(className);
630
631 if ((className.endsWith(QLatin1String("ListView")) && className != QLatin1String("Q3ListView"))
632 || (className.endsWith(QLatin1String("ListBox")) && className != QLatin1String("Q3ListBox"))
633 || (className.endsWith(QLatin1String("ComboBox")) && className != QLatin1String("QComboBox"))
634 || (className.endsWith(QLatin1String("IconView")) && className != QLatin1String("Q3IconView")))
635 candidateCustomWidgets.insert(className, true);
636
637 bool isMenu = (className == QLatin1String("QMenuBar") || className == QLatin1String("QMenu"));
638
639 ui_widget->setAttributeClass(className);
640
641 QList<DomWidget*> ui_child_list;
642 QList<DomRow*> ui_row_list;
643 QList<DomColumn*> ui_column_list;
644 QList<DomItem*> ui_item_list;
645 QList<DomProperty*> ui_property_list;
646 QList<DomProperty*> ui_attribute_list;
647 QList<DomLayout*> ui_layout_list;
648 QList<DomActionRef*> ui_action_list;
649 QList<DomWidget*> ui_mainwindow_child_list;
650
651 createProperties(w, &ui_property_list, className);
652 createAttributes(w, &ui_attribute_list, className);
653
654 DomWidget *ui_mainWindow = 0;
655 DomWidget *ui_centralWidget = 0;
656 if (className == QLatin1String("QMainWindow") || className == QLatin1String("Q3MainWindow")) {
657 ui_centralWidget = new DomWidget;
658 ui_centralWidget->setAttributeClass(QLatin1String("QWidget"));
659 ui_mainwindow_child_list.append(ui_centralWidget);
660 ui_mainWindow = ui_widget;
661 }
662
663 QDomElement e = w.firstChild().toElement();
664 const bool inQ3ToolBar = className == QLatin1String("Q3ToolBar");
665 while (!e.isNull()) {
666 QString t = e.tagName().toLower();
667 if (t == QLatin1String("vbox") || t == QLatin1String("hbox") || t == QLatin1String("grid")) {
668 DomLayout *lay = createLayout(e);
669 Q_ASSERT(lay != 0);
670
671 if (ui_layout_list.isEmpty()) {
672 ui_layout_list.append(lay);
673 } else {
674 // it's not possible to have more than one layout for widget!
675 delete lay;
676 }
677 } else if (t == QLatin1String("spacer")) {
678 // hmm, spacer as child of a widget.. it doesn't make sense, so skip it!
679 } else if (t == QLatin1String("widget")) {
680 DomWidget *ui_child = createWidget(e);
681 Q_ASSERT(ui_child != 0);
682
683 bool isLayoutWidget = ui_child->attributeClass() == QLatin1String("QLayoutWidget");
684 if (isLayoutWidget)
685 ui_child->setAttributeClass(QLatin1String("QWidget"));
686
687 foreach (DomLayout *layout, ui_child->elementLayout()) {
688 fixLayoutMargin(layout);
689 }
690
691 QString widgetClass = ui_child->attributeClass();
692 if (widgetClass == QLatin1String("QMenuBar") || widgetClass == QLatin1String("QToolBar")
693 || widgetClass == QLatin1String("QStatusBar")) {
694 ui_mainwindow_child_list.append(ui_child);
695 } else {
696 ui_child_list.append(ui_child);
697 }
698
699 if (inQ3ToolBar) {
700 DomActionRef *ui_action_ref = new DomActionRef();
701 ui_action_ref->setAttributeName(ui_child->attributeName());
702 ui_action_list.append(ui_action_ref);
703 }
704 } else if (t == QLatin1String("action")) {
705 DomActionRef *a = new DomActionRef();
706 a->read(e);
707 ui_action_list.append(a);
708 } else if (t == QLatin1String("separator")) {
709 DomActionRef *a = new DomActionRef();
710 a->setAttributeName(QLatin1String("separator"));
711 ui_action_list.append(a);
712 } else if (t == QLatin1String("property")) {
713 // skip the property it is already handled by createProperties
714 const QString name = e.attribute(QLatin1String("name")); // change the varname this widget
715 if (name == QLatin1String("name")) {
716 // Do not name QLayoutWidget if layout names are to be used.
717 const bool applyName = !(m_options & PreserveLayoutNames) || className != QLatin1String("QLayoutWidget");
718 if (applyName)
719 ui_widget->setAttributeName(DomTool::readProperty(w, QLatin1String("name"), QVariant()).toString());
720 }
721 } else if (t == QLatin1String("row")) {
722 DomRow *row = new DomRow();
723 row->read(e);
724 ui_row_list.append(row);
725 } else if (t == QLatin1String("column")) {
726 DomColumn *column = new DomColumn();
727 column->read(e);
728 ui_column_list.append(column);
729 } else if (isMenu && t == QLatin1String("item")) {
730 QString text = e.attribute(QLatin1String("text"));
731 QString name = e.attribute(QLatin1String("name"));
732 QString accel = e.attribute(QLatin1String("accel"));
733
734 QList<DomProperty*> properties;
735
736 DomProperty *atitle = new DomProperty();
737 atitle->setAttributeName(QLatin1String("title"));
738 DomString *str = new DomString();
739 str->setText(text);
740 atitle->setElementString(str);
741 properties.append(atitle);
742
743 DomWidget *menu = createWidget(e, QLatin1String("QMenu"));
744 menu->setAttributeName(name);
745 menu->setElementProperty(properties);
746 ui_child_list.append(menu);
747
748 DomActionRef *a = new DomActionRef();
749 a->setAttributeName(name);
750 ui_action_list.append(a);
751
752 } else if (t == QLatin1String("item")) {
753 DomItem *item = new DomItem();
754 item->read(e);
755 ui_item_list.append(item);
756 }
757
758 e = e.nextSibling().toElement();
759 }
760
761 ui_widget->setElementProperty(ui_property_list);
762 ui_widget->setElementAttribute(ui_attribute_list);
763
764 if (ui_centralWidget != 0) {
765 Q_ASSERT(ui_mainWindow != 0);
766 ui_mainWindow->setElementWidget(ui_mainwindow_child_list);
767 ui_widget = ui_centralWidget;
768 }
769
770 ui_widget->setElementWidget(ui_child_list);
771 ui_widget->setElementAddAction(ui_action_list);
772 ui_widget->setElementRow(ui_row_list);
773 ui_widget->setElementColumn(ui_column_list);
774 ui_widget->setElementItem(ui_item_list);
775 ui_widget->setElementLayout(ui_layout_list);
776
777 //ui_widget->setAttributeName(p->elementCstring());
778
779 return ui_mainWindow ? ui_mainWindow : ui_widget;
780}
781
782DomLayout *Ui3Reader::createLayout(const QDomElement &w)
783{
784 DomLayout *lay = new DomLayout();
785
786 QList<DomLayoutItem*> ui_item_list;
787 QList<DomProperty*> ui_property_list;
788 QList<DomProperty*> ui_attribute_list;
789
790 QString tagName = w.tagName().toLower();
791
792 QString className;
793 if (tagName == QLatin1String("vbox"))
794 className = QLatin1String("QVBoxLayout");
795 else if (tagName == QLatin1String("hbox"))
796 className = QLatin1String("QHBoxLayout");
797 else
798 className = QLatin1String("QGridLayout");
799
800 lay->setAttributeClass(className);
801
802 createProperties(w, &ui_property_list, className);
803 createAttributes(w, &ui_attribute_list, className);
804 if (m_options & PreserveLayoutNames) {
805 const QString layoutName = getLayoutName(w);
806 if (!layoutName.isEmpty())
807 lay->setAttributeName(layoutName);
808 }
809
810 QDomElement e = w.firstChild().toElement();
811 while (!e.isNull()) {
812 QString t = e.tagName().toLower();
813 if (t == QLatin1String("vbox")
814 || t == QLatin1String("hbox")
815 || t == QLatin1String("grid")
816 || t == QLatin1String("spacer")
817 || t == QLatin1String("widget")) {
818 DomLayoutItem *lay_item = createLayoutItem(e);
819 Q_ASSERT(lay_item != 0);
820 ui_item_list.append(lay_item);
821 }
822
823 e = e.nextSibling().toElement();
824 }
825
826 lay->setElementItem(ui_item_list);
827 lay->setElementProperty(ui_property_list);
828 lay->setElementAttribute(ui_attribute_list);
829
830 return lay;
831}
832
833DomLayoutItem *Ui3Reader::createLayoutItem(const QDomElement &e)
834{
835 DomLayoutItem *lay_item = new DomLayoutItem;
836
837 QString tagName = e.tagName().toLower();
838 if (tagName == QLatin1String("widget")) {
839 DomWidget *ui_widget = createWidget(e);
840 Q_ASSERT(ui_widget != 0);
841
842 if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget")
843 && ui_widget->elementLayout().size() == 1) {
844 QList<DomLayout*> layouts = ui_widget->elementLayout();
845
846 ui_widget->setElementLayout(QList<DomLayout*>());
847 delete ui_widget;
848
849 DomLayout *layout = layouts.first();
850 fixLayoutMargin(layout);
851 lay_item->setElementLayout(layout);
852 } else {
853 if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget"))
854 ui_widget->setAttributeClass(QLatin1String("QWidget"));
855
856 lay_item->setElementWidget(ui_widget);
857 }
858 } else if (tagName == QLatin1String("spacer")) {
859 DomSpacer *ui_spacer = new DomSpacer();
860 QList<DomProperty*> properties;
861
862 QByteArray name = DomTool::readProperty(e, QLatin1String("name"), QLatin1String("spacer")).toByteArray();
863
864 Variant var;
865 var.createSize(0, 0);
866
867 QVariant def = qVariantFromValue(var);
868
869 Size size = asVariant(DomTool::readProperty(e, QLatin1String("sizeHint"), def)).size;
870 QString sizeType = QLatin1String("QSizePolicy::") + DomTool::readProperty(e, QLatin1String("sizeType"), QLatin1String("Expanding")).toString();
871 QString orientation = QLatin1String("Qt::") + DomTool::readProperty(e, QLatin1String("orientation"), QLatin1String("Horizontal")).toString();
872
873 ui_spacer->setAttributeName(QLatin1String(name));
874
875 DomProperty *prop = 0;
876
877 // sizeHint
878 prop = new DomProperty();
879 prop->setAttributeName(QLatin1String("sizeHint"));
880 prop->setElementSize(new DomSize());
881 prop->elementSize()->setElementWidth(size.width);
882 prop->elementSize()->setElementHeight(size.height);
883 properties.append(prop);
884
885 // sizeType
886 prop = new DomProperty();
887 prop->setAttributeName(QLatin1String("sizeType"));
888 prop->setElementEnum(sizeType);
889 properties.append(prop);
890
891 // orientation
892 prop = new DomProperty();
893 prop->setAttributeName(QLatin1String("orientation"));
894 prop->setElementEnum(orientation);
895 properties.append(prop);
896
897 ui_spacer->setElementProperty(properties);
898 lay_item->setElementSpacer(ui_spacer);
899 } else {
900 DomLayout *ui_layout = createLayout(e);
901 Q_ASSERT(ui_layout != 0);
902
903 fixLayoutMargin(ui_layout);
904 lay_item->setElementLayout(ui_layout);
905 }
906
907 if (e.hasAttribute(QLatin1String("row")))
908 lay_item->setAttributeRow(e.attribute(QLatin1String("row")).toInt());
909 if (e.hasAttribute(QLatin1String("column")))
910 lay_item->setAttributeColumn(e.attribute(QLatin1String("column")).toInt());
911 if (e.hasAttribute(QLatin1String("rowspan")))
912 lay_item->setAttributeRowSpan(e.attribute(QLatin1String("rowspan")).toInt());
913 if (e.hasAttribute(QLatin1String("colspan")))
914 lay_item->setAttributeColSpan(e.attribute(QLatin1String("colspan")).toInt());
915
916 return lay_item;
917}
918
919void Ui3Reader::fixLayoutMargin(DomLayout *ui_layout)
920{
921 Q_UNUSED(ui_layout)
922}
923
924static void addBooleanFontSubProperty(QDomDocument &doc,
925 const QString &name, const QString &value,
926 QDomElement &fontElement)
927{
928 if (value == QLatin1String("true") || value == QLatin1String("1")) {
929 QDomElement child = doc.createElement(name);
930 child.appendChild(doc.createTextNode(QLatin1String("true")));
931 fontElement.appendChild(child);
932 } else {
933 if (value == QLatin1String("false") || value == QLatin1String("0")) {
934 QDomElement child = doc.createElement(name);
935 child.appendChild(doc.createTextNode(QLatin1String("false")));
936 fontElement.appendChild(child);
937 }
938 }
939}
940
941QDomElement Ui3Reader::findDerivedFontProperties(const QDomElement &n) const
942{
943 bool italic = false;
944 bool bold = false;
945 bool underline = false;
946 bool strikeout = false;
947 bool family = false;
948 bool pointsize = false;
949
950 QDomDocument doc = n.ownerDocument();
951 QDomElement result = doc.createElement(QLatin1String("font"));
952
953 QDomNode pn = n.parentNode();
954 while (!pn.isNull()) {
955 for (QDomElement e = pn.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
956 if (e.tagName().toLower() == QLatin1String("property") &&
957 e.attribute(QLatin1String("name")) == QLatin1String("font")) {
958 QDomElement f = e.firstChild().toElement();
959 for (QDomElement fp = f.firstChild().toElement(); !fp.isNull(); fp = fp.nextSibling().toElement()) {
960 QString name = fp.tagName().toLower();
961 QString text = fp.text();
962 if (!italic && name == QLatin1String("italic")) {
963 italic = true;
964 addBooleanFontSubProperty(doc, name, text, result);
965 } else if (!bold && name == QLatin1String("bold")) {
966 bold = true;
967 addBooleanFontSubProperty(doc, name, text, result);
968 } else if (!underline && name == QLatin1String("underline")) {
969 underline = true;
970 addBooleanFontSubProperty(doc, name, text, result);
971 } else if (!strikeout && name == QLatin1String("strikeout")) {
972 strikeout = true;
973 addBooleanFontSubProperty(doc, name, text, result);
974 } else if (!family && name == QLatin1String("family")) {
975 family = true;
976 QDomElement child = doc.createElement(name);
977 child.appendChild(doc.createTextNode(text));
978 result.appendChild(child);
979 } else if (!pointsize && name == QLatin1String("pointsize")) {
980 pointsize = true;
981 QDomElement child = doc.createElement(name);
982 child.appendChild(doc.createTextNode(text));
983 result.appendChild(child);
984 }
985 }
986 }
987 }
988 pn = pn.parentNode();
989 }
990
991 return result;
992}
993
994void Ui3Reader::createProperties(const QDomElement &n, QList<DomProperty*> *properties,
995 const QString &className)
996{
997 QString objectName;
998
999 bool wordWrapFound = false;
1000 bool wordWrapPropertyFound = false;
1001
1002 for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
1003 if (e.tagName().toLower() == QLatin1String("property")) {
1004 QString name = e.attribute(QLatin1String("name"));
1005
1006 // changes in QPalette
1007 if (name == QLatin1String("colorGroup")
1008 || name == QLatin1String("paletteForegroundColor")
1009 || name == QLatin1String("paletteBackgroundColor")
1010 || name == QLatin1String("backgroundMode")
1011 || name == QLatin1String("backgroundOrigin")
1012 || name == QLatin1String("paletteBackgroundPixmap")
1013 || name == QLatin1String("backgroundBrush")) {
1014 errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
1015 continue;
1016 }
1017
1018 // changes in QFrame
1019 if (name == QLatin1String("contentsRect")) {
1020 errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
1021 continue;
1022 }
1023
1024 // changes in QWidget
1025 if (name == QLatin1String("underMouse")
1026 || name == QLatin1String("ownFont")) {
1027 errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
1028 continue;
1029 }
1030
1031 if (name == QLatin1String("font")) {
1032 QDomElement f = e.firstChild().toElement();
1033 e.appendChild(findDerivedFontProperties(f));
1034 e.removeChild(f);
1035 }
1036
1037 DomProperty *prop = readProperty(e);
1038 if (!prop)
1039 continue;
1040
1041 if (prop->kind() == DomProperty::String) {
1042 QDomNodeList comments = e.elementsByTagName(QLatin1String("comment"));
1043 if (comments.length()) {
1044 QString comment = comments.item(0).firstChild().toText().data();
1045 if (!comment.isEmpty())
1046 prop->elementString()->setAttributeComment(comment);
1047 }
1048 }
1049
1050 // objectName
1051 if (name == QLatin1String("name")) {
1052 objectName = prop->elementCstring();
1053 continue;
1054 }
1055
1056 if (className == QLatin1String("Line")
1057 && prop->attributeName() == QLatin1String("orientation")) {
1058 delete prop;
1059 continue;
1060 }
1061
1062 if (className.mid(1) == QLatin1String("LineEdit")) {
1063 if (name == QLatin1String("hasMarkedText")) {
1064 prop->setAttributeName(QLatin1String("hasSelectedText"));
1065 } else if (name == QLatin1String("edited")) {
1066 prop->setAttributeName(QLatin1String("modified"));
1067 } else if (name == QLatin1String("markedText")) {
1068 prop->setAttributeName(QLatin1String("selectedText"));
1069 }
1070 }
1071
1072 if (className.endsWith(QLatin1String("ComboBox"))) {
1073 CONVERT_PROPERTY(QLatin1String("currentItem"), QLatin1String("currentIndex"));
1074 CONVERT_PROPERTY(QLatin1String("insertionPolicy"), QLatin1String("insertPolicy"));
1075 }
1076
1077 if (className == QLatin1String("QToolBar")) {
1078 if (name == QLatin1String("label")) {
1079 prop->setAttributeName(QLatin1String("windowTitle"));
1080 }
1081 }
1082
1083 CONVERT_PROPERTY(QLatin1String("customWhatsThis"), QLatin1String("whatsThis"));
1084 CONVERT_PROPERTY(QLatin1String("icon"), QLatin1String("windowIcon"));
1085 CONVERT_PROPERTY(QLatin1String("iconText"), QLatin1String("windowIconText"));
1086 CONVERT_PROPERTY(QLatin1String("caption"), QLatin1String("windowTitle"));
1087
1088 if (name == QLatin1String("name")) {
1089 continue; // skip the property name
1090 }
1091
1092 if (name == QLatin1String("accel")) {
1093 prop->setAttributeName(QLatin1String("shortcut"));
1094 }
1095
1096 CONVERT_PROPERTY(QLatin1String("pixmap"), QLatin1String("icon"));
1097 CONVERT_PROPERTY(QLatin1String("iconSet"), QLatin1String("icon"));
1098 CONVERT_PROPERTY(QLatin1String("textLabel"), QLatin1String("text"));
1099
1100 CONVERT_PROPERTY(QLatin1String("toggleButton"), QLatin1String("checkable"));
1101 CONVERT_PROPERTY(QLatin1String("on"), QLatin1String("checked"));
1102
1103 CONVERT_PROPERTY(QLatin1String("maxValue"), QLatin1String("maximum"));
1104 CONVERT_PROPERTY(QLatin1String("minValue"), QLatin1String("minimum"));
1105 CONVERT_PROPERTY(QLatin1String("lineStep"), QLatin1String("singleStep"));
1106
1107 // QSlider
1108 CONVERT_PROPERTY(QLatin1String("tickmarks"), QLatin1String("tickPosition"));
1109
1110 name = prop->attributeName(); // sync the name
1111
1112 if (className == QLatin1String("QLabel")) {
1113 if (name == QLatin1String("alignment")) {
1114 const QString v = prop->elementSet();
1115 if (v.contains(QRegExp(QLatin1String("\\bWordBreak\\b"))))
1116 wordWrapFound = true;
1117 } else if (name == QLatin1String("wordWrap")) {
1118 wordWrapPropertyFound = true;
1119 }
1120 }
1121
1122 // resolve the flags and enumerator
1123 if (prop->kind() == DomProperty::Set) {
1124 QStringList flags = prop->elementSet().split(QLatin1Char('|'));
1125 QStringList v;
1126 foreach (const QString &fl, flags) {
1127 QString e = WidgetInfo::resolveEnumerator(className, fl);
1128 if (e.isEmpty()) {
1129 e = m_porting->renameEnumerator(className + QLatin1String("::") + fl);
1130 }
1131
1132 if (e.isEmpty()) {
1133 fprintf(stderr, "uic3: flag '%s' for widget '%s' is not supported\n", fl.latin1(), className.latin1());
1134 continue;
1135 }
1136
1137 v.append(e);
1138 }
1139
1140 if (v.isEmpty()) {
1141 delete prop;
1142 continue;
1143 }
1144
1145 prop->setElementSet(v.join(QLatin1String("|")));
1146 } else if (prop->kind() == DomProperty::Enum) {
1147 QString e = WidgetInfo::resolveEnumerator(className, prop->elementEnum());
1148 if (e.isEmpty()) {
1149 e = m_porting->renameEnumerator(className + QLatin1String("::") + prop->elementEnum());
1150 }
1151
1152 if (e.isEmpty()) {
1153 fprintf(stderr, "uic3: enumerator '%s' for widget '%s' is not supported\n",
1154 prop->elementEnum().latin1(), className.latin1());
1155
1156 delete prop;
1157 continue;
1158 }
1159 prop->setElementEnum(e);
1160 }
1161
1162
1163 if (className.size()
1164 && !(className == QLatin1String("QLabel") && name == QLatin1String("buddy"))
1165 && !(name == QLatin1String("buttonGroupId"))
1166 && !(name == QLatin1String("frameworkCode"))
1167 && !(name == QLatin1String("database"))) {
1168 if (!WidgetInfo::isValidProperty(className, name)) {
1169 errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
1170 delete prop;
1171 } else {
1172 properties->append(prop);
1173 }
1174 } else {
1175 properties->append(prop);
1176 }
1177 }
1178 }
1179 if (className == QLatin1String("QLabel") && !wordWrapPropertyFound) {
1180 DomProperty *wordWrap = new DomProperty();
1181 wordWrap->setAttributeName(QLatin1String("wordWrap"));
1182 if (wordWrapFound)
1183 wordWrap->setElementBool(QLatin1String("true"));
1184 else
1185 wordWrap->setElementBool(QLatin1String("false"));
1186 properties->append(wordWrap);
1187 }
1188}
1189
1190static int toQt4SizePolicy(int qt3SizePolicy)
1191{
1192 if (qt3SizePolicy == 2) // qt 3 Ignored value
1193 return QSizePolicy::Ignored;
1194 return qt3SizePolicy;
1195}
1196
1197DomProperty *Ui3Reader::readProperty(const QDomElement &e)
1198{
1199 QString name = e.firstChild().toElement().tagName().toLower();
1200
1201 if (name == QLatin1String("class")) // skip class
1202 name = e.firstChild().nextSibling().toElement().tagName().toLower();
1203
1204 DomProperty *p = new DomProperty;
1205 p->read(e);
1206
1207 if (p->kind() == DomProperty::Number) {
1208 QString value = e.firstChild().toElement().firstChild().nodeValue();
1209
1210 if (value.contains(QLatin1Char('.'))) {
1211 p->setElementDouble(value.toDouble());
1212 }
1213 } else if (p->kind() == DomProperty::Pixmap) {
1214 DomResourcePixmap *domPix = p->elementPixmap();
1215 if (m_extractImages) {
1216 QString imageFile = domPix->text() + QLatin1String(".xpm");
1217 if (m_imageMap.contains(domPix->text()))
1218 imageFile = m_imageMap.value(domPix->text());
1219 domPix->setAttributeResource(m_qrcOutputFile);
1220 domPix->setText(QLatin1String(":/") + nameOfClass + QLatin1String("/images/") + imageFile);
1221 }
1222 } else if (p->kind() == DomProperty::SizePolicy) {
1223 DomSizePolicy *sp = p->elementSizePolicy();
1224 if (sp) {
1225 if (sp->hasElementHSizeType())
1226 sp->setElementHSizeType(toQt4SizePolicy(sp->elementHSizeType()));
1227 if (sp->hasElementVSizeType())
1228 sp->setElementVSizeType(toQt4SizePolicy(sp->elementVSizeType()));
1229 }
1230 } else if (p->kind() == DomProperty::Unknown) {
1231 delete p;
1232 p = 0;
1233 }
1234
1235 return p;
1236}
1237
1238void Ui3Reader::createAttributes(const QDomElement &n, QList<DomProperty*> *properties,
1239 const QString &className)
1240{
1241 Q_UNUSED(className);
1242
1243 for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
1244 if (e.tagName().toLower() == QLatin1String("attribute")) {
1245 QString name = e.attribute(QLatin1String("name"));
1246
1247 DomProperty *prop = readProperty(e);
1248 if (!prop)
1249 continue;
1250
1251 properties->append(prop);
1252 }
1253 }
1254}
1255
1256QString Ui3Reader::fixDeclaration(const QString &d) const
1257{
1258 QString text;
1259
1260 int i = 0;
1261 while (i < d.size()) {
1262 QChar ch = d.at(i);
1263
1264 if (ch.isLetter() || ch == QLatin1Char('_')) {
1265 int start = i;
1266 while (i < d.size() && (d.at(i).isLetterOrNumber() || d.at(i) == QLatin1Char('_')))
1267 ++i;
1268
1269 text += fixClassName(d.mid(start, i-start));
1270 } else {
1271 text += ch;
1272 ++i;
1273 }
1274 }
1275
1276 return text;
1277}
1278
1279/*
1280 fixes a (possible composite) type name
1281*/
1282QString Ui3Reader::fixType(const QString &t) const
1283{
1284 QString newText = t;
1285 //split type name on <>*& and whitespace
1286 QStringList typeNames = t.split(QRegExp(QLatin1String("<|>|\\*|&| ")), QString::SkipEmptyParts);
1287 foreach(const QString &typeName , typeNames) {
1288 QString newName = fixClassName(typeName);
1289 if( newName != typeName ) {
1290 newText.replace(typeName, newName);
1291 }
1292 }
1293 return newText;
1294}
1295
1296QString Ui3Reader::fixMethod(const QString &method) const
1297{
1298 const QByteArray normalized = QMetaObject::normalizedSignature(method.toLatin1());
1299 QByteArray result;
1300 int index = normalized.indexOf('(');
1301 if (index == -1)
1302 return QLatin1String(normalized);
1303 result.append(normalized.left(++index));
1304 int limit = normalized.length()-1;
1305 while (index < limit) {
1306 QByteArray type;
1307 while ((index < limit) && (normalized.at(index) != ','))
1308 type.append(normalized.at(index++));
1309 result.append(fixType(QLatin1String(type)).toLatin1());
1310 if ((index < limit) && (normalized.at(index) == ','))
1311 result.append(normalized.at(index++));
1312 }
1313 result.append(normalized.mid(index));
1314 return QLatin1String(result);
1315}
1316
1317QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.