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

📄 form.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** 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 "globaldefs.h"// uic4#include "uic.h"#include "ui4.h"#include "driver.h"#include "option.h"#include <QStringList>#include <QFile>#include <QFileInfo>#include <QDir>#include <QRegExp>#include <QtDebug>QByteArray combinePath(const char *infile, const char *outfile){    QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile));    QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile));    int numCommonComponents = 0;    QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/'));    QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/'));    while (!inSplitted.isEmpty() && !outSplitted.isEmpty() &&            inSplitted.first() == outSplitted.first()) {        inSplitted.erase(inSplitted.begin());        outSplitted.erase(outSplitted.begin());        numCommonComponents++;    }    if (numCommonComponents < 2) {        /*          The paths don't have the same drive, or they don't have the          same root directory. Use an absolute path.        */        return QFile::encodeName(inFileInfo.absoluteFilePath());    } else {        /*          The paths have something in common. Use a path relative to          the output file.        */        while (!outSplitted.isEmpty()) {            outSplitted.erase(outSplitted.begin());            inSplitted.prepend(QLatin1String(".."));        }        inSplitted.append(inFileInfo.fileName());        return QFile::encodeName(inSplitted.join(QLatin1String("/")));    }}/*!  Creates a declaration (header file) for the form given in \a e  \sa createFormImpl()*/void Ui3Reader::createFormDecl(const QDomElement &e, bool implicitIncludes){    QDomElement body = e;    QDomElement n;    QDomNodeList nl;    int i;    QString objClass = getClassName(e);    if (objClass.isEmpty())        return;    QString objName = getObjectName(e);    QStringList typeDefs;    QMap<QString, CustomInclude> customWidgetIncludes;    /*      We are generating a few QImage members that are not strictly      necessary in some cases. Ideally, we would use requiredImage,      which is computed elsewhere, to keep the generated .h and .cpp      files synchronized.    */    // at first the images    QMap<QString, int> customWidgets;    QStringList forwardDecl;    QStringList forwardDecl2;    for (n = e; !n.isNull(); n = n.nextSibling().toElement()) {        if (n.tagName().toLower() == QLatin1String("customwidgets")) {            QDomElement n2 = n.firstChild().toElement();            while (!n2.isNull()) {                if (n2.tagName().toLower() == QLatin1String("customwidget")) {                    QDomElement n3 = n2.firstChild().toElement();                    QString cl;                    while (!n3.isNull()) {                        QString tagName = n3.tagName().toLower();                        if (tagName == QLatin1String("class")) {                            cl = n3.firstChild().toText().data();                            if (!nofwd)                                forwardDecl << cl;                            customWidgets.insert(cl, 0);                        } else if (tagName == QLatin1String("header")) {                            CustomInclude ci;                            ci.header = n3.firstChild().toText().data();                            ci.location = n3.attribute(QLatin1String("location"), QLatin1String("global"));                            if (!ci.header.isEmpty())                                forwardDecl.removeAll(cl);                            customWidgetIncludes.insert(cl, ci);                        }                        n3 = n3.nextSibling().toElement();                    }                }                n2 = n2.nextSibling().toElement();            }        }    }    // register the object and unify its name    objName = registerObject(objName);    QString protector = objName.toUpper() + QLatin1String("_H");    protector.replace(QLatin1String("::"), QLatin1String("_"));    out << "#ifndef " << protector << endl;    out << "#define " << protector << endl;    out << endl;    out << "#include <qvariant.h>" << endl; // for broken HP-UX compilers    QStringList globalIncludes, localIncludes;    {        QMap<QString, CustomInclude>::Iterator it = customWidgetIncludes.find(objClass);        if (it != customWidgetIncludes.end()) {            if ((*it).location == QLatin1String("global"))                globalIncludes += (*it).header;            else                localIncludes += (*it).header;        }    }    QStringList::ConstIterator it;    globalIncludes = unique(globalIncludes);    for (it = globalIncludes.constBegin(); it != globalIncludes.constEnd(); ++it) {        if (!(*it).isEmpty()) {            QString header = fixHeaderName(*it);            out << "#include <" << header << ">" << endl;        }    }    localIncludes = unique(localIncludes);    for (it = localIncludes.constBegin(); it != localIncludes.constEnd(); ++it) {        if (!(*it).isEmpty()) {            QString header = fixHeaderName(*it);            out << "#include \"" << header << "\"" << endl;        }    }    out << endl;    bool dbForm = false;    registerDatabases(e);    dbConnections = unique(dbConnections);    if (dbForms[QLatin1String("(default)")].count())        dbForm = true;    bool subDbForms = false;    for (it = dbConnections.constBegin(); it != dbConnections.constEnd(); ++it) {        if (!(*it).isEmpty() && (*it) != QLatin1String("(default)")) {            if (dbForms[(*it)].count()) {                subDbForms = true;                break;            }        }    }    // some typedefs, maybe    typeDefs = unique(typeDefs);    for (it = typeDefs.constBegin(); it != typeDefs.constEnd(); ++it) {        if (!(*it).isEmpty())            out << "typedef " << *it << ";" << endl;    }    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("forward"));    for (i = 0; i < (int) nl.length(); i++)        forwardDecl2 << fixDeclaration(nl.item(i).toElement().firstChild().toText().data());    forwardDecl = unique(forwardDecl);    for (it = forwardDecl.constBegin(); it != forwardDecl.constEnd(); ++it) {        if (!(*it).isEmpty() && (*it) != objClass) {            QString forwardName = *it;            QStringList forwardNamespaces = forwardName.split(QLatin1String("::"));            forwardName = forwardNamespaces.last();            forwardNamespaces.removeAt(forwardNamespaces.size()-1);            QStringList::ConstIterator ns = forwardNamespaces.constBegin();            while (ns != forwardNamespaces.constEnd()) {                out << "namespace " << *ns << " {" << endl;                ++ns;            }            out << "class " << forwardName << ";" << endl;            for (int i = 0; i < (int) forwardNamespaces.count(); i++)                out << "}" << endl;        }    }    for (it = forwardDecl2.constBegin(); it != forwardDecl2.constEnd(); ++it) {        QString fd = *it;        fd = fd.trimmed();        if (!fd.endsWith(QLatin1String(";")))            fd += QLatin1String(";");        out << fd << endl;    }    out << endl;    Driver d;    d.option().headerProtection = false;    d.option().copyrightHeader = false;    d.option().extractImages = m_extractImages;    d.option().qrcOutputFile = m_qrcOutputFile;    d.option().implicitIncludes = implicitIncludes;    if (trmacro.size())        d.option().translateFunction = trmacro;    DomUI *ui = generateUi4(e, implicitIncludes);    d.uic(fileName, ui, &out);    delete ui;    createWrapperDeclContents(e);    out << "#endif // " << protector << endl;}void Ui3Reader::createWrapperDecl(const QDomElement &e, const QString &convertedUiFile){    QString objName = getObjectName(e);    objName = registerObject(objName);    QString protector = objName.toUpper() + QLatin1String("_H");    protector.replace(QLatin1String("::"), QLatin1String("_"));    out << "#ifndef " << protector << endl;    out << "#define " << protector << endl;    out << endl;    out << "#include \"" << convertedUiFile << "\"" << endl;    createWrapperDeclContents(e);    out << endl;    out << "#endif // " << protector << endl;}void Ui3Reader::createWrapperDeclContents(const QDomElement &e){    QString objClass = getClassName(e);    if (objClass.isEmpty())        return;    QDomNodeList nl;    QString exportMacro;    int i;    QDomElement n;    QStringList::ConstIterator it;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("exportmacro"));    if (nl.length() == 1)        exportMacro = nl.item(0).firstChild().toText().data();    QStringList::ConstIterator ns = namespaces.constBegin();    while (ns != namespaces.constEnd()) {        out << "namespace " << *ns << " {" << endl;        ++ns;    }    out << "class ";    if (!exportMacro.isEmpty())        out << exportMacro << " ";

⌨️ 快捷键说明

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