⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the tools applications of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "ui3reader.h"#include "parser.h"#include "domtool.h"#include "ui4.h"#include "widgetinfo.h"#include "globaldefs.h"#include "qt3to4.h"#include "utils.h"#include <QtDebug>#include <QFile>#include <QHash>#include <QStringList>#include <QDateTime>#include <QRegExp>#include <stdio.h>#include <stdlib.h>#define CONVERT_PROPERTY(o, n) \    do { \        if (name == QLatin1String(o) \                && !WidgetInfo::isValidProperty(className, (o)) \                && WidgetInfo::isValidProperty(className, (n))) { \            prop->setAttributeName((n)); \        } \    } while (0)static QString classNameForObjectName(const QDomElement &widget, const QString &objectName){    QList<QDomElement> widgetStack;    widgetStack.append(widget);    while (!widgetStack.isEmpty()) {        QDomElement w = widgetStack.takeFirst();        QDomElement child = w.firstChild().toElement();        while (!child.isNull()) {            if (child.tagName() == QLatin1String("property")                && child.attribute(QLatin1String("name")) == QLatin1String("name")) {                QDomElement name = child.firstChild().toElement();                DomString str;                str.read(name);                if (str.text() == objectName)                    return w.attribute(QLatin1String("class"));            } else if (child.tagName() == QLatin1String("widget")) {                widgetStack.prepend(child);            }            child = child.nextSibling().toElement();        }    }    return QString();}DomUI *Ui3Reader::generateUi4(const QDomElement &widget){    QDomNodeList nl;    candidateCustomWidgets.clear();    QString objClass = getClassName(widget);    if (objClass.isEmpty())        return 0;    DomUI *ui = new DomUI;    ui->setAttributeVersion(QLatin1String("4.0"));    QString pixmapFunction = QLatin1String("qPixmapFromMimeSource");    QStringList ui_tabstops;    QList<DomInclude*> ui_includes;    QList<DomWidget*> ui_toolbars;    QList<DomWidget*> ui_menubars;    QList<DomAction*> ui_action_list;    QList<DomActionGroup*> ui_action_group_list;    QList<DomCustomWidget*> ui_customwidget_list;    QList<DomConnection*> ui_connection_list;    QString author, comment, exportMacro;    QString klass;    for (QDomElement n = root.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) {        QString tagName = n.tagName().toLower();        if (tagName == QLatin1String("tabstops")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("tabstop")) {                    QString name = n2.firstChild().toText().data();                    ui_tabstops.append(name);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("pixmapfunction")) {            pixmapFunction = n.firstChild().toText().data();        } else if (tagName == QLatin1String("class")) {            klass = n.firstChild().toText().data();        } else if (tagName == QLatin1String("author")) {            author = n.firstChild().toText().data();        } else if (tagName == QLatin1String("comment")) {            comment = n.firstChild().toText().data();        } else if (tagName == QLatin1String("exportMacro")) {            exportMacro = n.firstChild().toText().data();        } else if (tagName == QLatin1String("includes")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("include")) {                    QString name = n2.firstChild().toText().data();                    if (n2.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) {                        if (name.right(5) == QLatin1String(".ui.h"))                            continue;                        DomInclude *incl = new DomInclude();                        incl->setText(fixHeaderName(name));                        incl->setAttributeLocation(n2.attribute(QLatin1String("location"), QLatin1String("global")));                        ui_includes.append(incl);                    }                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("include")) {            QString name = n.firstChild().toText().data();            if (n.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) == QLatin1String("in declaration")) {                if (name.right(5) == QLatin1String(".ui.h"))                    continue;                DomInclude *incl = new DomInclude();                incl->setText(fixHeaderName(name));                incl->setAttributeLocation(n.attribute(QLatin1String("location"), QLatin1String("global")));                ui_includes.append(incl);            }        } else if (tagName == QLatin1String("layoutdefaults")) {            QString margin = n.attribute(QLatin1String("margin"));            QString spacing = n.attribute(QLatin1String("spacing"));            DomLayoutDefault *layoutDefault = new DomLayoutDefault();            if (!margin.isEmpty())                layoutDefault->setAttributeMargin(margin.toInt());            if (!spacing.isEmpty())                layoutDefault->setAttributeSpacing(spacing.toInt());            ui->setElementLayoutDefault(layoutDefault);        } else if (tagName == QLatin1String("layoutfunctions")) {            QString margin = n.attribute(QLatin1String("margin"));            QString spacing = n.attribute(QLatin1String("spacing"));            DomLayoutFunction *layoutDefault = new DomLayoutFunction();            if (!margin.isEmpty())                layoutDefault->setAttributeMargin(margin);            if (!spacing.isEmpty())                layoutDefault->setAttributeSpacing(spacing);            ui->setElementLayoutFunction(layoutDefault);        } else if (tagName == QLatin1String("images")) {            QDomNodeList nl = n.elementsByTagName(QLatin1String("image"));            QList<DomImage*> ui_image_list;            for (int i=0; i<(int)nl.length(); i++) {                QDomElement e = nl.item(i).toElement();                QDomElement tmp = e.firstChild().toElement();                if (tmp.tagName().toLower() != QLatin1String("data"))                    continue;                // create the image                DomImage *img = new DomImage();                img->setAttributeName(e.attribute(QLatin1String("name")));                // create the data                DomImageData *data = new DomImageData();                img->setElementData(data);                if (tmp.hasAttribute(QLatin1String("format")))                    data->setAttributeFormat(tmp.attribute(QLatin1String("format"), QLatin1String("PNG")));                if (tmp.hasAttribute(QLatin1String("length")))                    data->setAttributeLength(tmp.attribute(QLatin1String("length")).toInt());                data->setText(tmp.firstChild().toText().data());                ui_image_list.append(img);            }            if (ui_image_list.size()) {                DomImages *images = new DomImages();                images->setElementImage(ui_image_list);                ui->setElementImages(images);            }        } else if (tagName == QLatin1String("actions")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                QString tag = n2.tagName().toLower();                if (tag == QLatin1String("action")) {                    DomAction *action = new DomAction();                    action->read(n2);                    QList<DomProperty*> properties = action->elementProperty();                    QString actionName = fixActionProperties(properties);                    action->setAttributeName(actionName);                    action->setElementProperty(properties);                    if (actionName.isEmpty()) {                        delete action;                    } else                        ui_action_list.append(action);                } else if (tag == QLatin1String("actiongroup")) {                    DomActionGroup *g= new DomActionGroup();                    g->read(n2);                    fixActionGroup(g);                    ui_action_group_list.append(g);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("toolbars")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("toolbar")) {                    DomWidget *tb = createWidget(n2, QLatin1String("QToolBar"));                    ui_toolbars.append(tb);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("menubar")) {            DomWidget *tb = createWidget(n, QLatin1String("QMenuBar"));            ui_menubars.append(tb);        } else if (tagName == QLatin1String("customwidgets")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("customwidget")) {                    DomCustomWidget *customWidget = new DomCustomWidget;                    customWidget->read(n2);                    QDomElement n3 = n2.firstChild().toElement();                    QString cl;                    QList<DomPropertyData*> ui_property_list;                    while (!n3.isNull()) {                        QString tagName = n3.tagName().toLower();                        if (tagName == QLatin1String("property")) {                            DomPropertyData *p = new DomPropertyData();                            p->read(n3);                            ui_property_list.append(p);                        }                        n3 = n3.nextSibling().toElement();                    }                    if (ui_property_list.size()) {                        DomProperties *properties = new DomProperties();                        properties->setElementProperty(ui_property_list);                        customWidget->setElementProperties(properties);                    }                    ui_customwidget_list.append(customWidget);                }                n2 = n2.nextSibling().toElement();            }        } else if (tagName == QLatin1String("connections")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("connection")) {                    DomConnection *connection = new DomConnection;                    connection->read(n2);                    QString sender = connection->elementSender();                    QString senderClass = fixClassName(classNameForObjectName(widget, sender));                    QString signal = fixMethod(connection->elementSignal());                    QString receiver = connection->elementReceiver();                    QString receiverClass = fixClassName(classNameForObjectName(widget, receiver));                    QString slot = fixMethod(connection->elementSlot());                    // make sure that the signal and slot are present in Qt4                    if (!WidgetInfo::isValidSignal(senderClass, signal)) {                        errorInvalidSignal(signal, sender, senderClass);                        delete connection;                    }                    else if (!WidgetInfo::isValidSlot(receiverClass, slot)) {                        errorInvalidSlot(slot, receiver, receiverClass);                        delete connection;                    } else {                        connection->setElementSignal(signal);                        connection->setElementSlot(slot);                        ui_connection_list.append(connection);                    }                }                n2 = n2.nextSibling().toElement();            }        }    }    DomWidget *w = createWidget(widget);    Q_ASSERT(w != 0);    QList<DomWidget*> l = w->elementWidget();    l += ui_toolbars;    l += ui_menubars;    w->setElementWidget(l);    if (ui_action_group_list.size())        w->setElementActionGroup(ui_action_group_list);    if (ui_action_list.size())        w->setElementAction(ui_action_list);    ui->setElementWidget(w);    if (klass.isEmpty())        klass = w->attributeName();    w->setAttributeName(klass);    ui->setElementClass(klass);    ui->setElementAuthor(author);    ui->setElementComment(comment);    ui->setElementExportMacro(exportMacro);    if (!ui->elementImages())        ui->setElementPixmapFunction(pixmapFunction);    for (int i=0; i<ui_customwidget_list.size(); ++i) {        QString name = ui_customwidget_list.at(i)->elementClass();        if (candidateCustomWidgets.contains(name))            candidateCustomWidgets.remove(name);    }    QMapIterator<QString, bool> it(candidateCustomWidgets);    while (it.hasNext()) {        it.next();        QString customClass = it.key();        QString baseClass;        if (customClass.endsWith(QLatin1String("ListView")))            baseClass = QLatin1String("Q3ListView");        else if (customClass.endsWith(QLatin1String("ListBox")))            baseClass = QLatin1String("Q3ListBox");        else if (customClass.endsWith(QLatin1String("IconView")))            baseClass = QLatin1String("Q3IconView");        else if (customClass.endsWith(QLatin1String("ComboBox")))            baseClass = QLatin1String("QComboBox");        if (baseClass.isEmpty())            continue;        DomHeader *header = new DomHeader;        header->setText(customClass.toLower() + QLatin1String(".h"));        DomCustomWidget *customWidget = new DomCustomWidget();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -