📄 form.cpp
字号:
globalIncludes += s; } } registerDatabases(e); dbConnections = unique(dbConnections); bool dbForm = false; if (dbForms[QLatin1String("(default)")].count()) dbForm = true; bool subDbForms = false; for (it = dbConnections.begin(); it != dbConnections.end(); ++it) { if (!(*it).isEmpty() && (*it) != QLatin1String("(default)")) { if (dbForms[(*it)].count()) { subDbForms = true; break; } } } // do the local includes afterwards, since global includes have priority on clashes 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") && !globalIncludes.contains(s)) { if (s.right(5) == QLatin1String(".ui.h") && !QFile::exists(s)) continue; if (n2.attribute(QLatin1String("impldecl"), QLatin1String("in implementation")) != QLatin1String("in implementation")) continue; localIncludes += s; } } // additional custom widget headers nl = e.parentNode().toElement().elementsByTagName(QLatin1String("header")); 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")) globalIncludes += s; else localIncludes += s; } out << "#include <qvariant.h>" << endl; // first for gcc 2.7.2 globalIncludes = unique(globalIncludes); for (it = globalIncludes.begin(); it != globalIncludes.end(); ++it) { if (!(*it).isEmpty()) out << "#include <" << fixHeaderName(*it) << ">" << endl; } if (externPixmaps) { out << "#include <qimage.h>" << endl; out << "#include <qpixmap.h>" << endl << endl; } /* Put local includes after all global includes */ localIncludes = unique(localIncludes); for (it = localIncludes.begin(); it != localIncludes.end(); ++it) { if (!(*it).isEmpty() && *it != QFileInfo(fileName + QLatin1String(".h")).fileName()) out << "#include \"" << fixHeaderName(*it) << "\"" << endl; } QString uiDotH = fileName + QLatin1String(".h"); if (QFile::exists(uiDotH)) { if (!outputFileName.isEmpty()) uiDotH = QString::fromUtf8(combinePath(uiDotH.ascii(), outputFileName.ascii())); out << "#include \"" << uiDotH << "\"" << endl; writeFunctImpl = false; } // register the object and unify its name objName = registerObject(objName); if (externPixmaps) { pixmapLoaderFunction = QLatin1String("QPixmap::fromMimeSource"); } // constructor if (objClass == QLatin1String("QDialog") || objClass == QLatin1String("QWizard")) { out << "/*" << endl; out << " * Constructs a " << nameOfClass << " as a child of 'parent', with the" << endl; out << " * name 'name' and widget flags set to 'f'." << endl; out << " *" << endl; out << " * The " << objClass.mid(1).toLower() << " will by default be modeless, unless you set 'modal' to" << endl; out << " * true to construct a modal " << objClass.mid(1).toLower() << "." << endl; out << " */" << endl; out << nameOfClass << "::" << bareNameOfClass << "(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)" << endl; out << " : " << objClass << "(parent, name, modal, fl)"; } else if (objClass == QLatin1String("QWidget")) { out << "/*" << endl; out << " * Constructs a " << nameOfClass << " as a child of 'parent', with the" << endl; out << " * name 'name' and widget flags set to 'f'." << endl; out << " */" << endl; out << nameOfClass << "::" << bareNameOfClass << "(QWidget* parent, const char* name, Qt::WindowFlags fl)" << endl; out << " : " << objClass << "(parent, name, fl)"; } else if (objClass == QLatin1String("QMainWindow") || objClass == QLatin1String("Q3MainWindow")) { out << "/*" << endl; out << " * Constructs a " << nameOfClass << " as a child of 'parent', with the" << endl; out << " * name 'name' and widget flags set to 'f'." << endl; out << " *" << endl; out << " */" << endl; out << nameOfClass << "::" << bareNameOfClass << "(QWidget* parent, const char* name, Qt::WindowFlags fl)" << endl; out << " : " << objClass << "(parent, name, fl)"; isMainWindow = true; } else { out << "/*" << endl; out << " * Constructs a " << nameOfClass << " which is a child of 'parent', with the" << endl; out << " * name 'name'.' " << endl; out << " */" << endl; out << nameOfClass << "::" << bareNameOfClass << "(QWidget* parent, const char* name)" << endl; out << " : " << objClass << "(parent, name)"; } out << endl; out << "{" << endl;//// setup the gui// out << indent << "setupUi(this);" << endl << endl; if (isMainWindow) out << indent << "(void)statusBar();" << endl; // database support dbConnections = unique(dbConnections); if (dbConnections.count()) out << endl; for (it = dbConnections.begin(); it != dbConnections.end(); ++it) { if (!(*it).isEmpty() && (*it) != QLatin1String("(default)")) { out << indent << (*it) << "Connection = QSqlDatabase::database(\"" <<(*it) << "\");" << endl; } } nl = e.parentNode().toElement().elementsByTagName(QLatin1String("widget")); for (i = 1; i < (int) nl.length(); i++) { // start at 1, 0 is the toplevel widget n = nl.item(i).toElement(); QString s = getClassName(n); if ((dbForm || subDbForms) && (s == QLatin1String("QDataBrowser") || s == QLatin1String("QDataView"))) { QString objName = getObjectName(n); QString tab = getDatabaseInfo(n, QLatin1String("table")); QString con = getDatabaseInfo(n, QLatin1String("connection")); out << indent << "QSqlForm* " << objName << "Form = new QSqlForm(this);" << endl; out << indent << objName << "Form->setObjectName(\"" << objName << "Form\");" << endl; QDomElement n2; for (n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement()) createFormImpl(n2, objName, con, tab); out << indent << objName << "->setForm(" << objName << "Form);" << endl; } } if (extraFuncts.contains(QLatin1String("init()"))) out << indent << "init();" << endl; // end of constructor out << "}" << endl; out << endl; // destructor out << "/*" << endl; out << " * Destroys the object and frees any allocated resources" << endl; out << " */" << endl; out << nameOfClass << "::~" << bareNameOfClass << "()" << endl; out << "{" << endl; if (extraFuncts.contains(QLatin1String("destroy()"))) out << indent << "destroy();" << endl; out << indent << "// no need to delete child widgets, Qt does it all for us" << endl; out << "}" << endl; out << endl; // handle application events if required bool needFontEventHandler = false; bool needSqlTableEventHandler = false; bool needSqlDataBrowserEventHandler = false; nl = e.elementsByTagName(QLatin1String("widget")); for (i = 0; i < (int) nl.length(); i++) { if (!DomTool::propertiesOfType(nl.item(i).toElement() , QLatin1String("font")).isEmpty()) needFontEventHandler = true; QString s = getClassName(nl.item(i).toElement()); if (s == QLatin1String("QDataTable") || s == QLatin1String("QDataBrowser")) { if (!isFrameworkCodeGenerated(nl.item(i).toElement())) continue; if (s == QLatin1String("QDataTable")) needSqlTableEventHandler = true; if (s == QLatin1String("QDataBrowser")) needSqlDataBrowserEventHandler = true; } if (needFontEventHandler && needSqlTableEventHandler && needSqlDataBrowserEventHandler) break; } out << "/*" << endl; out << " * Sets the strings of the subwidgets using the current" << endl; out << " * language." << endl; out << " */" << endl; out << "void " << nameOfClass << "::languageChange()" << endl; out << "{" << endl; out << " retranslateUi(this);" << endl; out << "}" << endl; out << endl; // create stubs for additional slots if necessary if (!extraFuncts.isEmpty() && writeFunctImpl) { it = extraFuncts.begin(); QStringList::Iterator it2 = extraFunctTyp.begin(); QStringList::Iterator it3 = extraFunctSpecifier.begin(); while (it != extraFuncts.end()) { QString type = fixDeclaration(*it2); if (type.isEmpty()) type = QLatin1String("void"); type = type.simplified(); QString fname = fixDeclaration(Parser::cleanArgs(*it)); if (!(*it3).startsWith(QLatin1String("pure"))) { // "pure virtual" or "pureVirtual" out << type << " " << nameOfClass << "::" << fname << endl; out << "{" << endl; if (*it != QLatin1String("init()") && *it != QLatin1String("destroy()")) { QRegExp numeric(QLatin1String("^(?:signed|unsigned|u?char|u?short|u?int" "|u?long|Q_U?INT(?:8|16|32)|Q_U?LONG|float" "|double)$")); QString retVal; /* We return some kind of dummy value to shut the compiler up. 1. If the type is 'void', we return nothing. 2. If the type is 'bool', we return 'false'. 3. If the type is 'unsigned long' or 'quint16' or 'double' or similar, we return '0'. 4. If the type is 'Foo *', we return '0'. 5. If the type is 'Foo &', we create a static variable of type 'Foo' and return it. 6. If the type is 'Foo', we assume there's a default constructor and use it. */ if (type != QLatin1String("void")) { QStringList toks = type.split(QLatin1String(" ")); bool isBasicNumericType = (toks.filter(numeric).count() == toks.count()); if (type == QLatin1String("bool")) { retVal = QLatin1String("false"); } else if (isBasicNumericType || type.endsWith(QLatin1String("*"))) { retVal = QLatin1String("0"); } else if (type.endsWith(QLatin1String("&"))) { do { type.chop(1); } while (type.endsWith(QLatin1String(" "))); retVal = QLatin1String("uic_temp_var"); out << indent << "static " << type << " " << retVal << ";" << endl; } else { retVal = type + QLatin1String("()"); } } out << indent << "qWarning(\"" << nameOfClass << "::" << fname << ": Not implemented yet\");" << endl; if (!retVal.isEmpty()) out << indent << "return " << retVal << ";" << endl; } out << "}" << endl; out << endl; } ++it; ++it2; ++it3; } }}/*! Creates form support implementation code for the widgets given in \a e. Traverses recursively over all children. */void Ui3Reader::createFormImpl(const QDomElement& e, const QString& form, const QString& connection, const QString& table){ if (e.tagName() == QLatin1String("widget") && e.attribute(QLatin1String("class")) != QLatin1String("QDataTable")) { QString field = getDatabaseInfo(e, QLatin1String("field")); if (!field.isEmpty()) { if (isWidgetInTable(e, connection, table)) out << indent << form << "Form->insert(" << getObjectName(e) << ", " << fixString(field) << ");" << endl; } } QDomElement n; for (n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement()) { createFormImpl(n, form, connection, table); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -