| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 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 |
|
|---|
| 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 |
|
|---|
| 124 | DomUI *Ui3Reader::generateUi4(const QDomElement &widget, bool implicitIncludes)
|
|---|
| 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 (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 (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.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
|
|---|
| 713 |
|
|---|
| 714 | QString name = e.attribute(QLatin1String("name")); // change the varname this widget
|
|---|
| 715 | if (name == QLatin1String("name"))
|
|---|
| 716 | ui_widget->setAttributeName(DomTool::readProperty(w, QLatin1String("name"), QVariant()).toString());
|
|---|
| 717 | } else if (t == QLatin1String("row")) {
|
|---|
| 718 | DomRow *row = new DomRow();
|
|---|
| 719 | row->read(e);
|
|---|
| 720 | ui_row_list.append(row);
|
|---|
| 721 | } else if (t == QLatin1String("column")) {
|
|---|
| 722 | DomColumn *column = new DomColumn();
|
|---|
| 723 | column->read(e);
|
|---|
| 724 | ui_column_list.append(column);
|
|---|
| 725 | } else if (isMenu && t == QLatin1String("item")) {
|
|---|
| 726 | QString text = e.attribute(QLatin1String("text"));
|
|---|
| 727 | QString name = e.attribute(QLatin1String("name"));
|
|---|
| 728 | QString accel = e.attribute(QLatin1String("accel"));
|
|---|
| 729 |
|
|---|
| 730 | QList<DomProperty*> properties;
|
|---|
| 731 |
|
|---|
| 732 | DomProperty *atitle = new DomProperty();
|
|---|
| 733 | atitle->setAttributeName(QLatin1String("title"));
|
|---|
| 734 | DomString *str = new DomString();
|
|---|
| 735 | str->setText(text);
|
|---|
| 736 | atitle->setElementString(str);
|
|---|
| 737 | properties.append(atitle);
|
|---|
| 738 |
|
|---|
| 739 | DomWidget *menu = createWidget(e, QLatin1String("QMenu"));
|
|---|
| 740 | menu->setAttributeName(name);
|
|---|
| 741 | menu->setElementProperty(properties);
|
|---|
| 742 | ui_child_list.append(menu);
|
|---|
| 743 |
|
|---|
| 744 | DomActionRef *a = new DomActionRef();
|
|---|
| 745 | a->setAttributeName(name);
|
|---|
| 746 | ui_action_list.append(a);
|
|---|
| 747 |
|
|---|
| 748 | } else if (t == QLatin1String("item")) {
|
|---|
| 749 | DomItem *item = new DomItem();
|
|---|
| 750 | item->read(e);
|
|---|
| 751 | ui_item_list.append(item);
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | e = e.nextSibling().toElement();
|
|---|
| 755 | }
|
|---|
| 756 |
|
|---|
| 757 | ui_widget->setElementProperty(ui_property_list);
|
|---|
| 758 | ui_widget->setElementAttribute(ui_attribute_list);
|
|---|
| 759 |
|
|---|
| 760 | if (ui_centralWidget != 0) {
|
|---|
| 761 | Q_ASSERT(ui_mainWindow != 0);
|
|---|
| 762 | ui_mainWindow->setElementWidget(ui_mainwindow_child_list);
|
|---|
| 763 | ui_widget = ui_centralWidget;
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | ui_widget->setElementWidget(ui_child_list);
|
|---|
| 767 | ui_widget->setElementAddAction(ui_action_list);
|
|---|
| 768 | ui_widget->setElementRow(ui_row_list);
|
|---|
| 769 | ui_widget->setElementColumn(ui_column_list);
|
|---|
| 770 | ui_widget->setElementItem(ui_item_list);
|
|---|
| 771 | ui_widget->setElementLayout(ui_layout_list);
|
|---|
| 772 |
|
|---|
| 773 | //ui_widget->setAttributeName(p->elementCstring());
|
|---|
| 774 |
|
|---|
| 775 | return ui_mainWindow ? ui_mainWindow : ui_widget;
|
|---|
| 776 | }
|
|---|
| 777 |
|
|---|
| 778 | DomLayout *Ui3Reader::createLayout(const QDomElement &w)
|
|---|
| 779 | {
|
|---|
| 780 | DomLayout *lay = new DomLayout();
|
|---|
| 781 |
|
|---|
| 782 | QList<DomLayoutItem*> ui_item_list;
|
|---|
| 783 | QList<DomProperty*> ui_property_list;
|
|---|
| 784 | QList<DomProperty*> ui_attribute_list;
|
|---|
| 785 |
|
|---|
| 786 | QString tagName = w.tagName().toLower();
|
|---|
| 787 |
|
|---|
| 788 | QString className;
|
|---|
| 789 | if (tagName == QLatin1String("vbox"))
|
|---|
| 790 | className = QLatin1String("QVBoxLayout");
|
|---|
| 791 | else if (tagName == QLatin1String("hbox"))
|
|---|
| 792 | className = QLatin1String("QHBoxLayout");
|
|---|
| 793 | else
|
|---|
| 794 | className = QLatin1String("QGridLayout");
|
|---|
| 795 |
|
|---|
| 796 | lay->setAttributeClass(className);
|
|---|
| 797 |
|
|---|
| 798 | createProperties(w, &ui_property_list, className);
|
|---|
| 799 | createAttributes(w, &ui_attribute_list, className);
|
|---|
| 800 |
|
|---|
| 801 | QDomElement e = w.firstChild().toElement();
|
|---|
| 802 | while (!e.isNull()) {
|
|---|
| 803 | QString t = e.tagName().toLower();
|
|---|
| 804 | if (t == QLatin1String("vbox")
|
|---|
| 805 | || t == QLatin1String("hbox")
|
|---|
| 806 | || t == QLatin1String("grid")
|
|---|
| 807 | || t == QLatin1String("spacer")
|
|---|
| 808 | || t == QLatin1String("widget")) {
|
|---|
| 809 | DomLayoutItem *lay_item = createLayoutItem(e);
|
|---|
| 810 | Q_ASSERT(lay_item != 0);
|
|---|
| 811 | ui_item_list.append(lay_item);
|
|---|
| 812 | }
|
|---|
| 813 |
|
|---|
| 814 | e = e.nextSibling().toElement();
|
|---|
| 815 | }
|
|---|
| 816 |
|
|---|
| 817 | lay->setElementItem(ui_item_list);
|
|---|
| 818 | lay->setElementProperty(ui_property_list);
|
|---|
| 819 | lay->setElementAttribute(ui_attribute_list);
|
|---|
| 820 |
|
|---|
| 821 | return lay;
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | DomLayoutItem *Ui3Reader::createLayoutItem(const QDomElement &e)
|
|---|
| 825 | {
|
|---|
| 826 | DomLayoutItem *lay_item = new DomLayoutItem;
|
|---|
| 827 |
|
|---|
| 828 | QString tagName = e.tagName().toLower();
|
|---|
| 829 | if (tagName == QLatin1String("widget")) {
|
|---|
| 830 | DomWidget *ui_widget = createWidget(e);
|
|---|
| 831 | Q_ASSERT(ui_widget != 0);
|
|---|
| 832 |
|
|---|
| 833 | if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget")
|
|---|
| 834 | && ui_widget->elementLayout().size() == 1) {
|
|---|
| 835 | QList<DomLayout*> layouts = ui_widget->elementLayout();
|
|---|
| 836 |
|
|---|
| 837 | ui_widget->setElementLayout(QList<DomLayout*>());
|
|---|
| 838 | delete ui_widget;
|
|---|
| 839 |
|
|---|
| 840 | DomLayout *layout = layouts.first();
|
|---|
| 841 | fixLayoutMargin(layout);
|
|---|
| 842 | lay_item->setElementLayout(layout);
|
|---|
| 843 | } else {
|
|---|
| 844 | if (ui_widget->attributeClass() == QLatin1String("QLayoutWidget"))
|
|---|
| 845 | ui_widget->setAttributeClass(QLatin1String("QWidget"));
|
|---|
| 846 |
|
|---|
| 847 | lay_item->setElementWidget(ui_widget);
|
|---|
| 848 | }
|
|---|
| 849 | } else if (tagName == QLatin1String("spacer")) {
|
|---|
| 850 | DomSpacer *ui_spacer = new DomSpacer();
|
|---|
| 851 | QList<DomProperty*> properties;
|
|---|
| 852 |
|
|---|
| 853 | QByteArray name = DomTool::readProperty(e, QLatin1String("name"), QLatin1String("spacer")).toByteArray();
|
|---|
| 854 |
|
|---|
| 855 | Variant var;
|
|---|
| 856 | var.createSize(0, 0);
|
|---|
| 857 |
|
|---|
| 858 | QVariant def = qVariantFromValue(var);
|
|---|
| 859 |
|
|---|
| 860 | Size size = asVariant(DomTool::readProperty(e, QLatin1String("sizeHint"), def)).size;
|
|---|
| 861 | QString sizeType = QLatin1String("QSizePolicy::") + DomTool::readProperty(e, QLatin1String("sizeType"), QLatin1String("Expanding")).toString();
|
|---|
| 862 | QString orientation = QLatin1String("Qt::") + DomTool::readProperty(e, QLatin1String("orientation"), QLatin1String("Horizontal")).toString();
|
|---|
| 863 |
|
|---|
| 864 | ui_spacer->setAttributeName(QLatin1String(name));
|
|---|
| 865 |
|
|---|
| 866 | DomProperty *prop = 0;
|
|---|
| 867 |
|
|---|
| 868 | // sizeHint
|
|---|
| 869 | prop = new DomProperty();
|
|---|
| 870 | prop->setAttributeName(QLatin1String("sizeHint"));
|
|---|
| 871 | prop->setElementSize(new DomSize());
|
|---|
| 872 | prop->elementSize()->setElementWidth(size.width);
|
|---|
| 873 | prop->elementSize()->setElementHeight(size.height);
|
|---|
| 874 | properties.append(prop);
|
|---|
| 875 |
|
|---|
| 876 | // sizeType
|
|---|
| 877 | prop = new DomProperty();
|
|---|
| 878 | prop->setAttributeName(QLatin1String("sizeType"));
|
|---|
| 879 | prop->setElementEnum(sizeType);
|
|---|
| 880 | properties.append(prop);
|
|---|
| 881 |
|
|---|
| 882 | // orientation
|
|---|
| 883 | prop = new DomProperty();
|
|---|
| 884 | prop->setAttributeName(QLatin1String("orientation"));
|
|---|
| 885 | prop->setElementEnum(orientation);
|
|---|
| 886 | properties.append(prop);
|
|---|
| 887 |
|
|---|
| 888 | ui_spacer->setElementProperty(properties);
|
|---|
| 889 | lay_item->setElementSpacer(ui_spacer);
|
|---|
| 890 | } else {
|
|---|
| 891 | DomLayout *ui_layout = createLayout(e);
|
|---|
| 892 | Q_ASSERT(ui_layout != 0);
|
|---|
| 893 |
|
|---|
| 894 | fixLayoutMargin(ui_layout);
|
|---|
| 895 | lay_item->setElementLayout(ui_layout);
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | if (e.hasAttribute(QLatin1String("row")))
|
|---|
| 899 | lay_item->setAttributeRow(e.attribute(QLatin1String("row")).toInt());
|
|---|
| 900 | if (e.hasAttribute(QLatin1String("column")))
|
|---|
| 901 | lay_item->setAttributeColumn(e.attribute(QLatin1String("column")).toInt());
|
|---|
| 902 | if (e.hasAttribute(QLatin1String("rowspan")))
|
|---|
| 903 | lay_item->setAttributeRowSpan(e.attribute(QLatin1String("rowspan")).toInt());
|
|---|
| 904 | if (e.hasAttribute(QLatin1String("colspan")))
|
|---|
| 905 | lay_item->setAttributeColSpan(e.attribute(QLatin1String("colspan")).toInt());
|
|---|
| 906 |
|
|---|
| 907 | return lay_item;
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | void Ui3Reader::fixLayoutMargin(DomLayout *ui_layout)
|
|---|
| 911 | {
|
|---|
| 912 | Q_UNUSED(ui_layout)
|
|---|
| 913 | }
|
|---|
| 914 |
|
|---|
| 915 | static void addBooleanFontSubProperty(QDomDocument &doc,
|
|---|
| 916 | const QString &name, const QString &value,
|
|---|
| 917 | QDomElement &fontElement)
|
|---|
| 918 | {
|
|---|
| 919 | if (value == QLatin1String("true") || value == QLatin1String("1")) {
|
|---|
| 920 | QDomElement child = doc.createElement(name);
|
|---|
| 921 | child.appendChild(doc.createTextNode(QLatin1String("true")));
|
|---|
| 922 | fontElement.appendChild(child);
|
|---|
| 923 | } else {
|
|---|
| 924 | if (value == QLatin1String("false") || value == QLatin1String("0")) {
|
|---|
| 925 | QDomElement child = doc.createElement(name);
|
|---|
| 926 | child.appendChild(doc.createTextNode(QLatin1String("false")));
|
|---|
| 927 | fontElement.appendChild(child);
|
|---|
| 928 | }
|
|---|
| 929 | }
|
|---|
| 930 | }
|
|---|
| 931 |
|
|---|
| 932 | QDomElement Ui3Reader::findDerivedFontProperties(const QDomElement &n) const
|
|---|
| 933 | {
|
|---|
| 934 | bool italic = false;
|
|---|
| 935 | bool bold = false;
|
|---|
| 936 | bool underline = false;
|
|---|
| 937 | bool strikeout = false;
|
|---|
| 938 | bool family = false;
|
|---|
| 939 | bool pointsize = false;
|
|---|
| 940 |
|
|---|
| 941 | QDomDocument doc = n.ownerDocument();
|
|---|
| 942 | QDomElement result = doc.createElement(QLatin1String("font"));
|
|---|
| 943 |
|
|---|
| 944 | QDomNode pn = n.parentNode();
|
|---|
| 945 | while (!pn.isNull()) {
|
|---|
| 946 | for (QDomElement e = pn.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
|
|---|
| 947 | if (e.tagName().toLower() == QLatin1String("property") &&
|
|---|
| 948 | e.attribute(QLatin1String("name")) == QLatin1String("font")) {
|
|---|
| 949 | QDomElement f = e.firstChild().toElement();
|
|---|
| 950 | for (QDomElement fp = f.firstChild().toElement(); !fp.isNull(); fp = fp.nextSibling().toElement()) {
|
|---|
| 951 | QString name = fp.tagName().toLower();
|
|---|
| 952 | QString text = fp.text();
|
|---|
| 953 | if (!italic && name == QLatin1String("italic")) {
|
|---|
| 954 | italic = true;
|
|---|
| 955 | addBooleanFontSubProperty(doc, name, text, result);
|
|---|
| 956 | } else if (!bold && name == QLatin1String("bold")) {
|
|---|
| 957 | bold = true;
|
|---|
| 958 | addBooleanFontSubProperty(doc, name, text, result);
|
|---|
| 959 | } else if (!underline && name == QLatin1String("underline")) {
|
|---|
| 960 | underline = true;
|
|---|
| 961 | addBooleanFontSubProperty(doc, name, text, result);
|
|---|
| 962 | } else if (!strikeout && name == QLatin1String("strikeout")) {
|
|---|
| 963 | strikeout = true;
|
|---|
| 964 | addBooleanFontSubProperty(doc, name, text, result);
|
|---|
| 965 | } else if (!family && name == QLatin1String("family")) {
|
|---|
| 966 | family = true;
|
|---|
| 967 | QDomElement child = doc.createElement(name);
|
|---|
| 968 | child.appendChild(doc.createTextNode(text));
|
|---|
| 969 | result.appendChild(child);
|
|---|
| 970 | } else if (!pointsize && name == QLatin1String("pointsize")) {
|
|---|
| 971 | pointsize = true;
|
|---|
| 972 | QDomElement child = doc.createElement(name);
|
|---|
| 973 | child.appendChild(doc.createTextNode(text));
|
|---|
| 974 | result.appendChild(child);
|
|---|
| 975 | }
|
|---|
| 976 | }
|
|---|
| 977 | }
|
|---|
| 978 | }
|
|---|
| 979 | pn = pn.parentNode();
|
|---|
| 980 | }
|
|---|
| 981 |
|
|---|
| 982 | return result;
|
|---|
| 983 | }
|
|---|
| 984 |
|
|---|
| 985 | void Ui3Reader::createProperties(const QDomElement &n, QList<DomProperty*> *properties,
|
|---|
| 986 | const QString &className)
|
|---|
| 987 | {
|
|---|
| 988 | QString objectName;
|
|---|
| 989 |
|
|---|
| 990 | bool wordWrapFound = false;
|
|---|
| 991 | bool wordWrapPropertyFound = false;
|
|---|
| 992 |
|
|---|
| 993 | for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
|
|---|
| 994 | if (e.tagName().toLower() == QLatin1String("property")) {
|
|---|
| 995 | QString name = e.attribute(QLatin1String("name"));
|
|---|
| 996 |
|
|---|
| 997 | // changes in QPalette
|
|---|
| 998 | if (name == QLatin1String("colorGroup")
|
|---|
| 999 | || name == QLatin1String("paletteForegroundColor")
|
|---|
| 1000 | || name == QLatin1String("paletteBackgroundColor")
|
|---|
| 1001 | || name == QLatin1String("backgroundMode")
|
|---|
| 1002 | || name == QLatin1String("backgroundOrigin")
|
|---|
| 1003 | || name == QLatin1String("paletteBackgroundPixmap")
|
|---|
| 1004 | || name == QLatin1String("backgroundBrush")) {
|
|---|
| 1005 | errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
|
|---|
| 1006 | continue;
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | // changes in QFrame
|
|---|
| 1010 | if (name == QLatin1String("contentsRect")) {
|
|---|
| 1011 | errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
|
|---|
| 1012 | continue;
|
|---|
| 1013 | }
|
|---|
| 1014 |
|
|---|
| 1015 | // changes in QWidget
|
|---|
| 1016 | if (name == QLatin1String("underMouse")
|
|---|
| 1017 | || name == QLatin1String("ownFont")) {
|
|---|
| 1018 | errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
|
|---|
| 1019 | continue;
|
|---|
| 1020 | }
|
|---|
| 1021 |
|
|---|
| 1022 | if (name == QLatin1String("font")) {
|
|---|
| 1023 | QDomElement f = e.firstChild().toElement();
|
|---|
| 1024 | e.appendChild(findDerivedFontProperties(f));
|
|---|
| 1025 | e.removeChild(f);
|
|---|
| 1026 | }
|
|---|
| 1027 |
|
|---|
| 1028 | DomProperty *prop = readProperty(e);
|
|---|
| 1029 | if (!prop)
|
|---|
| 1030 | continue;
|
|---|
| 1031 |
|
|---|
| 1032 | if (prop->kind() == DomProperty::String) {
|
|---|
| 1033 | QDomNodeList comments = e.elementsByTagName(QLatin1String("comment"));
|
|---|
| 1034 | if (comments.length()) {
|
|---|
| 1035 | QString comment = comments.item(0).firstChild().toText().data();
|
|---|
| 1036 | if (!comment.isEmpty())
|
|---|
| 1037 | prop->elementString()->setAttributeComment(comment);
|
|---|
| 1038 | }
|
|---|
| 1039 | }
|
|---|
| 1040 |
|
|---|
| 1041 | // objectName
|
|---|
| 1042 | if (name == QLatin1String("name")) {
|
|---|
| 1043 | objectName = prop->elementCstring();
|
|---|
| 1044 | continue;
|
|---|
| 1045 | }
|
|---|
| 1046 |
|
|---|
| 1047 | if (className == QLatin1String("Line")
|
|---|
| 1048 | && prop->attributeName() == QLatin1String("orientation")) {
|
|---|
| 1049 | delete prop;
|
|---|
| 1050 | continue;
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | if (className.mid(1) == QLatin1String("LineEdit")) {
|
|---|
| 1054 | if (name == QLatin1String("hasMarkedText")) {
|
|---|
| 1055 | prop->setAttributeName(QLatin1String("hasSelectedText"));
|
|---|
| 1056 | } else if (name == QLatin1String("edited")) {
|
|---|
| 1057 | prop->setAttributeName(QLatin1String("modified"));
|
|---|
| 1058 | } else if (name == QLatin1String("markedText")) {
|
|---|
| 1059 | prop->setAttributeName(QLatin1String("selectedText"));
|
|---|
| 1060 | }
|
|---|
| 1061 | }
|
|---|
| 1062 |
|
|---|
| 1063 | if (className.endsWith(QLatin1String("ComboBox"))) {
|
|---|
| 1064 | CONVERT_PROPERTY(QLatin1String("currentItem"), QLatin1String("currentIndex"));
|
|---|
| 1065 | CONVERT_PROPERTY(QLatin1String("insertionPolicy"), QLatin1String("insertPolicy"));
|
|---|
| 1066 | }
|
|---|
| 1067 |
|
|---|
| 1068 | if (className == QLatin1String("QToolBar")) {
|
|---|
| 1069 | if (name == QLatin1String("label")) {
|
|---|
| 1070 | prop->setAttributeName(QLatin1String("windowTitle"));
|
|---|
| 1071 | }
|
|---|
| 1072 | }
|
|---|
| 1073 |
|
|---|
| 1074 | CONVERT_PROPERTY(QLatin1String("customWhatsThis"), QLatin1String("whatsThis"));
|
|---|
| 1075 | CONVERT_PROPERTY(QLatin1String("icon"), QLatin1String("windowIcon"));
|
|---|
| 1076 | CONVERT_PROPERTY(QLatin1String("iconText"), QLatin1String("windowIconText"));
|
|---|
| 1077 | CONVERT_PROPERTY(QLatin1String("caption"), QLatin1String("windowTitle"));
|
|---|
| 1078 |
|
|---|
| 1079 | if (name == QLatin1String("name")) {
|
|---|
| 1080 | continue; // skip the property name
|
|---|
| 1081 | }
|
|---|
| 1082 |
|
|---|
| 1083 | if (name == QLatin1String("accel")) {
|
|---|
| 1084 | prop->setAttributeName(QLatin1String("shortcut"));
|
|---|
| 1085 | }
|
|---|
| 1086 |
|
|---|
| 1087 | CONVERT_PROPERTY(QLatin1String("pixmap"), QLatin1String("icon"));
|
|---|
| 1088 | CONVERT_PROPERTY(QLatin1String("iconSet"), QLatin1String("icon"));
|
|---|
| 1089 | CONVERT_PROPERTY(QLatin1String("textLabel"), QLatin1String("text"));
|
|---|
| 1090 |
|
|---|
| 1091 | CONVERT_PROPERTY(QLatin1String("toggleButton"), QLatin1String("checkable"));
|
|---|
| 1092 | CONVERT_PROPERTY(QLatin1String("on"), QLatin1String("checked"));
|
|---|
| 1093 |
|
|---|
| 1094 | CONVERT_PROPERTY(QLatin1String("maxValue"), QLatin1String("maximum"));
|
|---|
| 1095 | CONVERT_PROPERTY(QLatin1String("minValue"), QLatin1String("minimum"));
|
|---|
| 1096 | CONVERT_PROPERTY(QLatin1String("lineStep"), QLatin1String("singleStep"));
|
|---|
| 1097 |
|
|---|
| 1098 | // QSlider
|
|---|
| 1099 | CONVERT_PROPERTY(QLatin1String("tickmarks"), QLatin1String("tickPosition"));
|
|---|
| 1100 |
|
|---|
| 1101 | name = prop->attributeName(); // sync the name
|
|---|
| 1102 |
|
|---|
| 1103 | if (className == QLatin1String("QLabel")) {
|
|---|
| 1104 | if (name == QLatin1String("alignment")) {
|
|---|
| 1105 | const QString v = prop->elementSet();
|
|---|
| 1106 | if (v.contains(QRegExp(QLatin1String("\\bWordBreak\\b"))))
|
|---|
| 1107 | wordWrapFound = true;
|
|---|
| 1108 | } else if (name == QLatin1String("wordWrap")) {
|
|---|
| 1109 | wordWrapPropertyFound = true;
|
|---|
| 1110 | }
|
|---|
| 1111 | }
|
|---|
| 1112 |
|
|---|
| 1113 | // resolve the flags and enumerator
|
|---|
| 1114 | if (prop->kind() == DomProperty::Set) {
|
|---|
| 1115 | QStringList flags = prop->elementSet().split(QLatin1Char('|'));
|
|---|
| 1116 | QStringList v;
|
|---|
| 1117 | foreach (QString fl, flags) {
|
|---|
| 1118 | QString e = WidgetInfo::resolveEnumerator(className, fl);
|
|---|
| 1119 | if (e.isEmpty()) {
|
|---|
| 1120 | e = m_porting->renameEnumerator(className + QLatin1String("::") + fl);
|
|---|
| 1121 | }
|
|---|
| 1122 |
|
|---|
| 1123 | if (e.isEmpty()) {
|
|---|
| 1124 | fprintf(stderr, "uic3: flag '%s' for widget '%s' is not supported\n", fl.latin1(), className.latin1());
|
|---|
| 1125 | continue;
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 | v.append(e);
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | if (v.isEmpty()) {
|
|---|
| 1132 | delete prop;
|
|---|
| 1133 | continue;
|
|---|
| 1134 | }
|
|---|
| 1135 |
|
|---|
| 1136 | prop->setElementSet(v.join(QLatin1String("|")));
|
|---|
| 1137 | } else if (prop->kind() == DomProperty::Enum) {
|
|---|
| 1138 | QString e = WidgetInfo::resolveEnumerator(className, prop->elementEnum());
|
|---|
| 1139 | if (e.isEmpty()) {
|
|---|
| 1140 | e = m_porting->renameEnumerator(className + QLatin1String("::") + prop->elementEnum());
|
|---|
| 1141 | }
|
|---|
| 1142 |
|
|---|
| 1143 | if (e.isEmpty()) {
|
|---|
| 1144 | fprintf(stderr, "uic3: enumerator '%s' for widget '%s' is not supported\n",
|
|---|
| 1145 | prop->elementEnum().latin1(), className.latin1());
|
|---|
| 1146 |
|
|---|
| 1147 | delete prop;
|
|---|
| 1148 | continue;
|
|---|
| 1149 | }
|
|---|
| 1150 | prop->setElementEnum(e);
|
|---|
| 1151 | }
|
|---|
| 1152 |
|
|---|
| 1153 |
|
|---|
| 1154 | if (className.size()
|
|---|
| 1155 | && !(className == QLatin1String("QLabel") && name == QLatin1String("buddy"))
|
|---|
| 1156 | && !(name == QLatin1String("buttonGroupId"))
|
|---|
| 1157 | && !(name == QLatin1String("frameworkCode"))
|
|---|
| 1158 | && !(name == QLatin1String("database"))) {
|
|---|
| 1159 | if (!WidgetInfo::isValidProperty(className, name)) {
|
|---|
| 1160 | errorInvalidProperty(name, objectName, className, n.lineNumber(), n.columnNumber());
|
|---|
| 1161 | delete prop;
|
|---|
| 1162 | } else {
|
|---|
| 1163 | properties->append(prop);
|
|---|
| 1164 | }
|
|---|
| 1165 | } else {
|
|---|
| 1166 | properties->append(prop);
|
|---|
| 1167 | }
|
|---|
| 1168 | }
|
|---|
| 1169 | }
|
|---|
| 1170 | if (className == QLatin1String("QLabel") && !wordWrapPropertyFound) {
|
|---|
| 1171 | DomProperty *wordWrap = new DomProperty();
|
|---|
| 1172 | wordWrap->setAttributeName(QLatin1String("wordWrap"));
|
|---|
| 1173 | if (wordWrapFound)
|
|---|
| 1174 | wordWrap->setElementBool(QLatin1String("true"));
|
|---|
| 1175 | else
|
|---|
| 1176 | wordWrap->setElementBool(QLatin1String("false"));
|
|---|
| 1177 | properties->append(wordWrap);
|
|---|
| 1178 | }
|
|---|
| 1179 | }
|
|---|
| 1180 |
|
|---|
| 1181 | static int toQt4SizePolicy(int qt3SizePolicy)
|
|---|
| 1182 | {
|
|---|
| 1183 | if (qt3SizePolicy == 2) // qt 3 Ignored value
|
|---|
| 1184 | return QSizePolicy::Ignored;
|
|---|
| 1185 | return qt3SizePolicy;
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | DomProperty *Ui3Reader::readProperty(const QDomElement &e)
|
|---|
| 1189 | {
|
|---|
| 1190 | QString name = e.firstChild().toElement().tagName().toLower();
|
|---|
| 1191 |
|
|---|
| 1192 | if (name == QLatin1String("class")) // skip class
|
|---|
| 1193 | name = e.firstChild().nextSibling().toElement().tagName().toLower();
|
|---|
| 1194 |
|
|---|
| 1195 | DomProperty *p = new DomProperty;
|
|---|
| 1196 | p->read(e);
|
|---|
| 1197 |
|
|---|
| 1198 | if (p->kind() == DomProperty::Number) {
|
|---|
| 1199 | QString value = e.firstChild().toElement().firstChild().nodeValue();
|
|---|
| 1200 |
|
|---|
| 1201 | if (value.contains(QLatin1Char('.'))) {
|
|---|
| 1202 | p->setElementDouble(value.toDouble());
|
|---|
| 1203 | }
|
|---|
| 1204 | } else if (p->kind() == DomProperty::Pixmap) {
|
|---|
| 1205 | DomResourcePixmap *domPix = p->elementPixmap();
|
|---|
| 1206 | if (m_extractImages) {
|
|---|
| 1207 | QString imageFile = domPix->text() + QLatin1String(".xpm");
|
|---|
| 1208 | if (m_imageMap.contains(domPix->text()))
|
|---|
| 1209 | imageFile = m_imageMap.value(domPix->text());
|
|---|
| 1210 | domPix->setAttributeResource(m_qrcOutputFile);
|
|---|
| 1211 | domPix->setText(QLatin1String(":/") + nameOfClass + QLatin1String("/images/") + imageFile);
|
|---|
| 1212 | }
|
|---|
| 1213 | } else if (p->kind() == DomProperty::SizePolicy) {
|
|---|
| 1214 | DomSizePolicy *sp = p->elementSizePolicy();
|
|---|
| 1215 | if (sp) {
|
|---|
| 1216 | if (sp->hasElementHSizeType())
|
|---|
| 1217 | sp->setElementHSizeType(toQt4SizePolicy(sp->elementHSizeType()));
|
|---|
| 1218 | if (sp->hasElementVSizeType())
|
|---|
| 1219 | sp->setElementVSizeType(toQt4SizePolicy(sp->elementVSizeType()));
|
|---|
| 1220 | }
|
|---|
| 1221 | } else if (p->kind() == DomProperty::Unknown) {
|
|---|
| 1222 | delete p;
|
|---|
| 1223 | p = 0;
|
|---|
| 1224 | }
|
|---|
| 1225 |
|
|---|
| 1226 | return p;
|
|---|
| 1227 | }
|
|---|
| 1228 |
|
|---|
| 1229 | void Ui3Reader::createAttributes(const QDomElement &n, QList<DomProperty*> *properties,
|
|---|
| 1230 | const QString &className)
|
|---|
| 1231 | {
|
|---|
| 1232 | Q_UNUSED(className);
|
|---|
| 1233 |
|
|---|
| 1234 | for (QDomElement e=n.firstChild().toElement(); !e.isNull(); e = e.nextSibling().toElement()) {
|
|---|
| 1235 | if (e.tagName().toLower() == QLatin1String("attribute")) {
|
|---|
| 1236 | QString name = e.attribute(QLatin1String("name"));
|
|---|
| 1237 |
|
|---|
| 1238 | DomProperty *prop = readProperty(e);
|
|---|
| 1239 | if (!prop)
|
|---|
| 1240 | continue;
|
|---|
| 1241 |
|
|---|
| 1242 | properties->append(prop);
|
|---|
| 1243 | }
|
|---|
| 1244 | }
|
|---|
| 1245 | }
|
|---|
| 1246 |
|
|---|
| 1247 | QString Ui3Reader::fixDeclaration(const QString &d) const
|
|---|
| 1248 | {
|
|---|
| 1249 | QString text;
|
|---|
| 1250 |
|
|---|
| 1251 | int i = 0;
|
|---|
| 1252 | while (i < d.size()) {
|
|---|
| 1253 | QChar ch = d.at(i);
|
|---|
| 1254 |
|
|---|
| 1255 | if (ch.isLetter() || ch == QLatin1Char('_')) {
|
|---|
| 1256 | int start = i;
|
|---|
| 1257 | while (i < d.size() && (d.at(i).isLetterOrNumber() || d.at(i) == QLatin1Char('_')))
|
|---|
| 1258 | ++i;
|
|---|
| 1259 |
|
|---|
| 1260 | text += fixClassName(d.mid(start, i-start));
|
|---|
| 1261 | } else {
|
|---|
| 1262 | text += ch;
|
|---|
| 1263 | ++i;
|
|---|
| 1264 | }
|
|---|
| 1265 | }
|
|---|
| 1266 |
|
|---|
| 1267 | return text;
|
|---|
| 1268 | }
|
|---|
| 1269 |
|
|---|
| 1270 | /*
|
|---|
| 1271 | fixes a (possible composite) type name
|
|---|
| 1272 | */
|
|---|
| 1273 | QString Ui3Reader::fixType(const QString &t) const
|
|---|
| 1274 | {
|
|---|
| 1275 | QString newText = t;
|
|---|
| 1276 | //split type name on <>*& and whitespace
|
|---|
| 1277 | QStringList typeNames = t.split(QRegExp(QLatin1String("<|>|\\*|&| ")), QString::SkipEmptyParts);
|
|---|
| 1278 | foreach(QString typeName , typeNames) {
|
|---|
| 1279 | QString newName = fixClassName(typeName);
|
|---|
| 1280 | if( newName != typeName ) {
|
|---|
| 1281 | newText.replace(typeName, newName);
|
|---|
| 1282 | }
|
|---|
| 1283 | }
|
|---|
| 1284 | return newText;
|
|---|
| 1285 | }
|
|---|
| 1286 |
|
|---|
| 1287 | QString Ui3Reader::fixMethod(const QString &method) const
|
|---|
| 1288 | {
|
|---|
| 1289 | const QByteArray normalized = QMetaObject::normalizedSignature(method.toLatin1());
|
|---|
| 1290 | QByteArray result;
|
|---|
| 1291 | int index = normalized.indexOf('(');
|
|---|
| 1292 | if (index == -1)
|
|---|
| 1293 | return QLatin1String(normalized);
|
|---|
| 1294 | result.append(normalized.left(++index));
|
|---|
| 1295 | int limit = normalized.length()-1;
|
|---|
| 1296 | while (index < limit) {
|
|---|
| 1297 | QByteArray type;
|
|---|
| 1298 | while ((index < limit) && (normalized.at(index) != ','))
|
|---|
| 1299 | type.append(normalized.at(index++));
|
|---|
| 1300 | result.append(fixType(QLatin1String(type)).toLatin1());
|
|---|
| 1301 | if ((index < limit) && (normalized.at(index) == ','))
|
|---|
| 1302 | result.append(normalized.at(index++));
|
|---|
| 1303 | }
|
|---|
| 1304 | result.append(normalized.mid(index));
|
|---|
| 1305 | return QLatin1String(result);
|
|---|
| 1306 | }
|
|---|
| 1307 |
|
|---|
| 1308 | QT_END_NAMESPACE
|
|---|