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

📄 form.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    out << bareNameOfClass << " : public " << objClass << ", public Ui::" << bareNameOfClass << endl << "{" << endl;    /* qmake ignore Q_OBJECT */    out << "    Q_OBJECT" << endl;    out << endl;    out << "public:" << endl;    // constructor    if (objClass == QLatin1String("QDialog") || objClass == QLatin1String("QWizard")) {        out << "    " << bareNameOfClass << "(QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WindowFlags fl = 0);" << endl;    } else if (objClass == QLatin1String("QWidget")) {        out << "    " << bareNameOfClass << "(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = 0);" << endl;    } else if (objClass == QLatin1String("QMainWindow") || objClass == QLatin1String("Q3MainWindow")) {        out << "    " << bareNameOfClass << "(QWidget* parent = 0, const char* name = 0, Qt::WindowFlags fl = Qt::WType_TopLevel);" << endl;        isMainWindow = true;    } else {        out << "    " << bareNameOfClass << "(QWidget* parent = 0, const char* name = 0);" << endl;    }    // destructor    out << "    ~" << bareNameOfClass << "();" << endl;    out << endl;    // database connections    dbConnections = unique(dbConnections);    bool hadOutput = false;    for (it = dbConnections.constBegin(); it != dbConnections.constEnd(); ++it) {        if (!(*it).isEmpty()) {            // only need pointers to non-default connections            if ((*it) != QLatin1String("(default)") && !(*it).isEmpty()) {                out << indent << "QSqlDatabase* " << *it << "Connection;" << endl;                hadOutput = true;            }        }    }    if (hadOutput)        out << endl;    QStringList publicSlots, protectedSlots, privateSlots;    QStringList publicSlotTypes, protectedSlotTypes, privateSlotTypes;    QStringList publicSlotSpecifier, protectedSlotSpecifier, privateSlotSpecifier;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("slot"));    for (i = 0; i < (int) nl.length(); i++) {        n = nl.item(i).toElement();        if (n.parentNode().toElement().tagName() != QLatin1String("slots")             && n.parentNode().toElement().tagName() != QLatin1String("connections"))            continue;        if (n.attribute(QLatin1String("language"), QLatin1String("C++")) != QLatin1String("C++"))            continue;        QString returnType = n.attribute(QLatin1String("returnType"), QLatin1String("void"));        QString functionName = n.firstChild().toText().data().trimmed();        if (functionName.endsWith(QLatin1String(";")))            functionName = functionName.left(functionName.length() - 1);        QString specifier = n.attribute(QLatin1String("specifier"));        QString access = n.attribute(QLatin1String("access"));        if (access == QLatin1String(QLatin1String("protected"))) {            protectedSlots += functionName;            protectedSlotTypes += returnType;            protectedSlotSpecifier += specifier;        } else if (access == QLatin1String("private")) {            privateSlots += functionName;            privateSlotTypes += returnType;            privateSlotSpecifier += specifier;        } else {            publicSlots += functionName;            publicSlotTypes += returnType;            publicSlotSpecifier += specifier;        }    }    QStringList publicFuncts, protectedFuncts, privateFuncts;    QStringList publicFunctRetTyp, protectedFunctRetTyp, privateFunctRetTyp;    QStringList publicFunctSpec, protectedFunctSpec, privateFunctSpec;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("function"));    for (i = 0; i < (int) nl.length(); i++) {        n = nl.item(i).toElement();        if (n.parentNode().toElement().tagName() != QLatin1String("functions"))            continue;        if (n.attribute(QLatin1String("language"), QLatin1String("C++")) != QLatin1String("C++"))            continue;        QString returnType = n.attribute(QLatin1String("returnType"), QLatin1String("void"));        QString functionName = n.firstChild().toText().data().trimmed();        if (functionName.endsWith(QLatin1String(";")))            functionName = functionName.left(functionName.length() - 1);        QString specifier = n.attribute(QLatin1String("specifier"));        QString access = n.attribute(QLatin1String("access"));        if (access == QLatin1String("protected")) {            protectedFuncts += functionName;            protectedFunctRetTyp += returnType;            protectedFunctSpec += specifier;        } else if (access == QLatin1String("private")) {            privateFuncts += functionName;            privateFunctRetTyp += returnType;            privateFunctSpec += specifier;        } else {            publicFuncts += functionName;            publicFunctRetTyp += returnType;            publicFunctSpec += specifier;        }    }    QStringList publicVars, protectedVars, privateVars;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("variable"));    for (i = 0; i < (int)nl.length(); i++) {        n = nl.item(i).toElement();        // Because of compatibility the next lines have to be commented out.        // Someday it should be uncommented.        //if (n.parentNode().toElement().tagName() != QLatin1String("variables"))        //    continue;        QString access = n.attribute(QLatin1String("access"), QLatin1String("protected"));        QString var = fixDeclaration(n.firstChild().toText().data().trimmed());        if (!var.endsWith(QLatin1String(";")))            var += QLatin1String(";");        if (access == QLatin1String("public"))            publicVars += var;        else if (access == QLatin1String("private"))            privateVars += var;        else            protectedVars += var;    }    if (!publicVars.isEmpty()) {        for (it = publicVars.constBegin(); it != publicVars.constEnd(); ++it)            out << indent << *it << endl;        out << endl;    }    if (!publicFuncts.isEmpty())        writeFunctionsDecl(publicFuncts, publicFunctRetTyp, publicFunctSpec);    if (!publicSlots.isEmpty()) {        out << "public slots:" << endl;        if (!publicSlots.isEmpty())            writeFunctionsDecl(publicSlots, publicSlotTypes, publicSlotSpecifier);    }    // find signals    QStringList extraSignals;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("signal"));    for (i = 0; i < (int) nl.length(); i++) {        n = nl.item(i).toElement();        if (n.parentNode().toElement().tagName() != QLatin1String("signals")             && n.parentNode().toElement().tagName() != QLatin1String("connections"))            continue;        if (n.attribute(QLatin1String("language"), QLatin1String("C++")) != QLatin1String("C++"))            continue;        QString sigName = n.firstChild().toText().data().trimmed();        if (sigName.endsWith(QLatin1String(";")))            sigName = sigName.left(sigName.length() - 1);        extraSignals += fixDeclaration(sigName);    }    // create signals    if (!extraSignals.isEmpty()) {        out << "signals:" << endl;        for (it = extraSignals.constBegin(); it != extraSignals.constEnd(); ++it)            out << "    void " << (*it) << ";" << endl;        out << endl;    }    if (!protectedVars.isEmpty()) {        out << "protected:" << endl;        for (it = protectedVars.constBegin(); it != protectedVars.constEnd(); ++it)            out << indent << *it << endl;        out << endl;    }    if (!protectedFuncts.isEmpty()) {        if (protectedVars.isEmpty())            out << "protected:" << endl;        writeFunctionsDecl(protectedFuncts, protectedFunctRetTyp, protectedFunctSpec);    }    out << "protected slots:" << endl;    out << "    virtual void languageChange();" << endl;    if (!protectedSlots.isEmpty()) {        out << endl;        writeFunctionsDecl(protectedSlots, protectedSlotTypes, protectedSlotSpecifier);    }    out << endl;    // create all private stuff    if (!privateFuncts.isEmpty() || !privateVars.isEmpty()) {        out << "private:" << endl;        if (!privateVars.isEmpty()) {            for (it = privateVars.constBegin(); it != privateVars.constEnd(); ++it)                out << indent << *it << endl;            out << endl;        }        if (!privateFuncts.isEmpty())            writeFunctionsDecl(privateFuncts, privateFunctRetTyp, privateFunctSpec);    }    if (!privateSlots.isEmpty()) {        out << "private slots:" << endl;        writeFunctionsDecl(privateSlots, privateSlotTypes, privateSlotSpecifier);    }    out << "};" << endl;    for (i = 0; i < (int) namespaces.count(); i++)        out << "}" << endl;    out << endl;}void Ui3Reader::writeFunctionsDecl(const QStringList &fuLst, const QStringList &typLst, const QStringList &specLst){    QStringList::ConstIterator it, it2, it3;    for (it = fuLst.begin(), it2 = typLst.begin(), it3 = specLst.begin();          it != fuLst.end(); ++it, ++it2, ++it3) {        QString signature = *it;        QString specifier;        QString pure;        QString type = *it2;        if (type.isEmpty())            type = QLatin1String("void");        if (*it3 == QLatin1String("static")) {            specifier = QLatin1String("static ");        } else {            if (*it3 != QLatin1String("non virtual") && *it3 != QLatin1String("nonVirtual"))                specifier = QLatin1String("virtual ");            if (*it3 == QLatin1String("pure virtual") || *it3 == QLatin1String("pureVirtual"))                pure = QLatin1String(" = 0");        }        type.replace(QLatin1String(">>"), QLatin1String("> >"));        if (!signature.contains(QLatin1String("operator")))            signature.replace(QLatin1String(">>"), QLatin1String("> >"));        signature = fixDeclaration(signature);        type = fixType(type);        out << "    " << specifier << type << " " << signature << pure << ";" << endl;    }    out << endl;}/*!  Creates an implementation (cpp-file) for the form given in \a e.  \sa createFormDecl(), createObjectImpl() */void Ui3Reader::createFormImpl(const QDomElement &e){    QDomElement n;    QDomNodeList nl;    int i;    QString objClass = getClassName(e);    if (objClass.isEmpty())        return;    QString objName = getObjectName(e);    // generate local and local includes required    QStringList globalIncludes, localIncludes;    QStringList::Iterator it;    QMap<QString, CustomInclude> customWidgetIncludes;    // find additional slots and functions    QStringList extraFuncts;    QStringList extraFunctTyp;    QStringList extraFunctSpecifier;    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("slot"));    for (i = 0; i < (int) nl.length(); i++) {        n = nl.item(i).toElement();        if (n.parentNode().toElement().tagName() != QLatin1String("slots")             && n.parentNode().toElement().tagName() != QLatin1String("connections"))            continue;        if (n.attribute(QLatin1String("language"), QLatin1String("C++")) != QLatin1String("C++"))            continue;        QString functionName = n.firstChild().toText().data().trimmed();        if (functionName.endsWith(QLatin1String(";")))            functionName = functionName.left(functionName.length() - 1);        extraFuncts += functionName;        extraFunctTyp += n.attribute(QLatin1String("returnType"), QLatin1String("void"));        extraFunctSpecifier += n.attribute(QLatin1String("specifier"), QLatin1String("virtual"));    }    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("function"));    for (i = 0; i < (int) nl.length(); i++) {        n = nl.item(i).toElement();        if (n.parentNode().toElement().tagName() != QLatin1String("functions"))            continue;        if (n.attribute(QLatin1String("language"), QLatin1String("C++")) != QLatin1String("C++"))            continue;        QString functionName = n.firstChild().toText().data().trimmed();        if (functionName.endsWith(QLatin1String(";")))            functionName = functionName.left(functionName.length() - 1);        extraFuncts += functionName;        extraFunctTyp += n.attribute(QLatin1String("returnType"), QLatin1String("void"));        extraFunctSpecifier += n.attribute(QLatin1String("specifier"), QLatin1String("virtual"));    }    // additional includes (local or global) and forward declaractions    nl = e.parentNode().toElement().elementsByTagName(QLatin1String("include"));    for (i = 0; i < (int) nl.length(); i++) {        QDomElement n2 = nl.item(i).toElement();        QString s = n2.firstChild().toText().data();        if (n2.attribute(QLatin1String("location")) != QLatin1String("local")) {            if (s.right(5) == QLatin1String(".ui.h") && !QFile::exists(s))                continue;            if (n2.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) != QLatin1String("in implementation"))                continue;

⌨️ 快捷键说明

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