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

📄 ui3reader.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 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://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** 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 <QFile>#include <QDateTime>#include <QRegExp>#include <QtDebug>#include <stdio.h>#include <stdlib.h>bool Ui3Reader::isMainWindow = false;static QString lineColDebug(int line, int col){    if (line >= 0) {        const QString ret = QString::fromLatin1("Line: %1%2");        return ret.arg(line).arg(col >= 0 ? QString::fromLatin1(" Column: %1").arg(col) : QString());    }    return QString();}void Ui3Reader::errorInvalidProperty(const QString &propertyName, const QString &widgetName, const QString &widgetClass, int line, int col){    fprintf(stderr, "uic3: property `%s' for widget `%s' of type `%s' is not supported. %s\n",            propertyName.toLatin1().constData(),            widgetName.toLatin1().constData(),            widgetClass.toLatin1().constData(),            lineColDebug(line, col).toLocal8Bit().constData());}void Ui3Reader::errorInvalidSignal(const QString &signal, const QString &widgetName, const QString &widgetClass, int line, int col){    fprintf(stderr, "uic3: signal `%s' for widget `%s' of type `%s' is not supported; connection may fail. %s\n",            signal.toLatin1().constData(), widgetName.toLatin1().constData(),            widgetClass.toLatin1().constData(),            lineColDebug(line, col).toLocal8Bit().constData());}void Ui3Reader::errorInvalidSlot(const QString &slot, const QString &widgetName, const QString &widgetClass, int line, int col){    fprintf(stderr, "uic3: slot `%s' for widget `%s' of type `%s' is not supported; connection may fail. %s\n",            slot.toLatin1().constData(),            widgetName.toLatin1().constData(),            widgetClass.toLatin1().constData(),            lineColDebug(line, col).toLocal8Bit().constData());}QString Ui3Reader::getComment(const QDomNode& n){    QDomNode child = n.firstChild();    while (!child.isNull()) {        if (child.toElement().tagName() == QLatin1String("comment"))            return child.toElement().firstChild().toText().data();        child = child.nextSibling();    }    return QString();}QString Ui3Reader::mkBool(bool b){    return b ? QLatin1String("true") : QLatin1String("false");}QString Ui3Reader::mkBool(const QString& s){    return mkBool(s == QLatin1String("true") || s == QLatin1String("1"));}bool Ui3Reader::toBool(const QString& s){    return s == QLatin1String("true") || s.toInt() != 0;}QString Ui3Reader::fixString(const QString &str, bool encode){    QString s;    if (!encode) {        s = str;        s.replace(QLatin1String("\\"), QLatin1String("\\\\"));        s.replace(QLatin1String("\""), QLatin1String("\\\""));        s.replace(QLatin1String("\r"), QLatin1String(""));        s.replace(QLatin1String("\n"), QLatin1String("\\n\"\n\""));    } else {        QByteArray utf8 = str.utf8();        const int l = utf8.length();        for (int i = 0; i < l; ++i)            s += QLatin1String("\\x") + QString::number((uchar)utf8[i], 16);    }    return QLatin1String("\"") + s + QLatin1String("\"");}QString Ui3Reader::trcall(const QString& sourceText, const QString& comment){    if (sourceText.isEmpty() && comment.isEmpty())        return QLatin1String("QString()");    QString t = trmacro;    bool encode = false;    if (t.isNull()) {        t = QLatin1String("tr");        for (int i = 0; i < (int) sourceText.length(); i++) {            if (sourceText[i].unicode() >= 0x80) {                t = QLatin1String("trUtf8");                encode = true;                break;            }        }    }    if (comment.isEmpty()) {        return t + QLatin1String("(") + fixString(sourceText, encode) + QLatin1String(")");    } else {        return t + QLatin1String("(")            + fixString(sourceText, encode)            + QLatin1String(", ")            + fixString(comment, encode) + QLatin1String(")");    }}QString Ui3Reader::mkStdSet(const QString& prop){    return QLatin1String("set") + prop[0].toUpper() + prop.mid(1);}void Ui3Reader::init(){    outputFileName.clear();    trmacro.clear();    nofwd = false;    fileName.clear();    writeFunctImpl = true;    defMargin = BOXLAYOUT_DEFAULT_MARGIN;    defSpacing = BOXLAYOUT_DEFAULT_SPACING;    externPixmaps = false;    indent = QLatin1String("    "); // default indent    item_used = cg_used = pal_used = 0;    layouts.clear();    layouts << QLatin1String("hbox") << QLatin1String("vbox") << QLatin1String("grid");    tags = layouts;    tags << QLatin1String("widget");    nameOfClass.clear();    namespaces.clear();    bareNameOfClass.clear();}QDomElement Ui3Reader::parse(const QDomDocument &doc){    root = doc.firstChild().toElement();    widget = QDomElement();    pixmapLoaderFunction = getPixmapLoaderFunction(doc.firstChild().toElement());    nameOfClass = getFormClassName(doc.firstChild().toElement());    uiFileVersion = doc.firstChild().toElement().attribute(QLatin1String("version"));    stdsetdef = toBool(doc.firstChild().toElement().attribute(QLatin1String("stdsetdef")));    if (doc.firstChild().isNull() || doc.firstChild().firstChild().isNull())        return widget;    QDomElement e = doc.firstChild().firstChild().toElement();    while (!e.isNull()) {        if (e.tagName() == QLatin1String("widget")) {            widget = e;        } else if (e.tagName() == QLatin1String("pixmapinproject")) {            externPixmaps = true;        } else if (e.tagName() == QLatin1String("layoutdefaults")) {            defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString());            defMargin = e.attribute(QLatin1String("margin"), defMargin.toString());        } else if (e.tagName() == QLatin1String("layoutfunctions")) {            defSpacing = e.attribute(QLatin1String("spacing"), defSpacing.toString());            bool ok;            defSpacing.toInt(&ok);            if (!ok) {                QString buf = defSpacing.toString();                defSpacing = buf.append(QLatin1String("()"));            }            defMargin = e.attribute(QLatin1String("margin"), defMargin.toString());            defMargin.toInt(&ok);            if (!ok) {                QString buf = defMargin.toString();                defMargin = buf.append(QLatin1String("()"));            }        }        e = e.nextSibling().toElement();    }    return widget;}Ui3Reader::Ui3Reader(QTextStream &outStream)   : out(outStream), trout(&languageChangeBody){    m_porting = new Porting();    m_extractImages = false;}Ui3Reader::~Ui3Reader(){    delete m_porting;}void Ui3Reader::generate(const QString &fn, const QString &outputFn,          QDomDocument doc, bool decl, bool subcl, const QString &trm,          const QString& subClass, bool omitForwardDecls, bool implicitIncludes, const QString &convertedUiFile){    init();    fileName = fn;    outputFileName = outputFn;    trmacro = trm;    nofwd = omitForwardDecls;    QDomElement e = parse(doc);    if (nameOfClass.isEmpty())        nameOfClass = getObjectName(e);    namespaces = nameOfClass.split(QLatin1String("::"));    bareNameOfClass = namespaces.last();    namespaces.removeLast();    if (!convertedUiFile.isEmpty()) {        createWrapperDecl(e, convertedUiFile);    } else if (subcl) {        if (decl)            createSubDecl(e, subClass);        else            createSubImpl(e, subClass);    } else {        if (decl)            createFormDecl(e, implicitIncludes);        else            createFormImpl(e);    }}void Ui3Reader::generateUi4(const QString &fn, const QString &outputFn, QDomDocument doc, bool implicitIncludes){    init();    fileName = fn;    outputFileName = outputFn;    DomUI *ui = generateUi4(parse(doc), implicitIncludes);    if (!ui)        return;    if (pixmapLoaderFunction.size())        ui->setElementPixmapFunction(pixmapLoaderFunction);    QDomDocument outputDoc;    outputDoc.appendChild(ui->write(outputDoc));    out << outputDoc.toString(2);    delete ui;}void Ui3Reader::setTrMacro(const QString &trmacro){    this->trmacro = trmacro;}void Ui3Reader::setForwardDeclarationsEnabled(bool b){    nofwd = !b;}

⌨️ 快捷键说明

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