📄 form.cpp
字号:
createFormImpl( n2, objName, con, tab ); out << indent << objName << "->setForm( " << objName << "Form );" << endl; } } // actions, toolbars, menubar bool needEndl = FALSE; for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "actions" ) { if ( !needEndl ) out << endl << indent << "// actions" << endl; createActionImpl( n.firstChild().toElement(), "this" ); needEndl = TRUE; } } if ( needEndl ) out << endl; needEndl = FALSE; for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "toolbars" ) { if ( !needEndl ) out << endl << indent << "// toolbars" << endl; createToolbarImpl( n, objClass, objName ); needEndl = TRUE; } } if ( needEndl ) out << endl; needEndl = FALSE; for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "menubar" ) { if ( !needEndl ) out << endl << indent << "// menubar" << endl; createMenuBarImpl( n, objClass, objName ); needEndl = TRUE; } } if ( needEndl ) out << endl; out << indent << "languageChange();" << endl; // take minimumSizeHint() into account, for height-for-width widgets if ( !geometry.isNull() ) { out << indent << "resize( QSize(" << geometry.width() << ", " << geometry.height() << ").expandedTo(minimumSizeHint()) );" << endl; out << indent << "clearWState( WState_Polished );" << endl; } for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "connections" ) { // setup signals and slots connections out << endl << indent << "// signals and slots connections" << endl; nl = n.elementsByTagName( "connection" ); for ( i = 0; i < (int) nl.length(); i++ ) { QString sender, receiver, signal, slot; for ( QDomElement n2 = nl.item(i).firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "sender" ) sender = n2.firstChild().toText().data(); else if ( n2.tagName() == "receiver" ) receiver = n2.firstChild().toText().data(); else if ( n2.tagName() == "signal" ) signal = n2.firstChild().toText().data(); else if ( n2.tagName() == "slot" ) slot = n2.firstChild().toText().data(); } if ( sender.isEmpty() || receiver.isEmpty() || signal.isEmpty() || slot.isEmpty() ) continue; if ( sender[0] == '<' || receiver[0] == '<' || signal[0] == '<' || slot[0] == '<' ) continue; sender = registeredName( sender ); receiver = registeredName( receiver ); // translate formwindow name to "this" if ( sender == objName ) sender = "this"; if ( receiver == objName ) receiver = "this"; out << indent << "connect( " << sender << ", SIGNAL( " << signal << " ), " << receiver << ", SLOT( " << slot << " ) );" << endl; } } else if ( n.tagName() == "tabstops" ) { // setup tab order out << endl << indent << "// tab order" << endl; QString lastName; QDomElement n2 = n.firstChild().toElement(); while ( !n2.isNull() ) { if ( n2.tagName() == "tabstop" ) { QString name = n2.firstChild().toText().data(); name = registeredName( name ); if ( !lastName.isEmpty() ) out << indent << "setTabOrder( " << lastName << ", " << name << " );" << endl; lastName = name; } n2 = n2.nextSibling().toElement(); } } } // buddies bool firstBuddy = TRUE; for ( QValueList<Buddy>::Iterator buddy = buddies.begin(); buddy != buddies.end(); ++buddy ) { if ( isObjectRegistered( (*buddy).buddy ) ) { if ( firstBuddy ) { out << endl << indent << "// buddies" << endl; } out << indent << (*buddy).key << "->setBuddy( " << registeredName( (*buddy).buddy ) << " );" << endl; firstBuddy = FALSE; } } if ( extraFuncts.find( "init()" ) != extraFuncts.end() ) 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.find( "destroy()" ) != extraFuncts.end() ) 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( "widget" ); for ( i = 0; i < (int) nl.length(); i++ ) { if ( !DomTool::propertiesOfType( nl.item(i).toElement() , "font" ).isEmpty() ) needFontEventHandler = TRUE; QString s = getClassName( nl.item(i).toElement() ); if ( s == "QDataTable" || s == "QDataBrowser" ) { if ( !isFrameworkCodeGenerated( nl.item(i).toElement() ) ) continue; if ( s == "QDataTable" ) needSqlTableEventHandler = TRUE; if ( s == "QDataBrowser" ) needSqlDataBrowserEventHandler = TRUE; } if ( needFontEventHandler && needSqlTableEventHandler && needSqlDataBrowserEventHandler ) break; } if ( needFontEventHandler && FALSE ) { // indent = "\t"; // increase indentation for if-clause below out << "/*" << endl; out << " * Main event handler. Reimplemented to handle" << endl; out << " * application font changes"; out << " */" << endl; out << "bool " << nameOfClass << "::event( QEvent* ev )" << endl; out << "{" << endl; out << " bool ret = " << objClass << "::event( ev ); " << endl; if ( needFontEventHandler ) { indent += "\t"; out << " if ( ev->type() == QEvent::ApplicationFontChange ) {" << endl; for ( i = 0; i < (int) nl.length(); i++ ) { n = nl.item(i).toElement(); QStringList list = DomTool::propertiesOfType( n, "font" ); for ( it = list.begin(); it != list.end(); ++it ) createExclusiveProperty( n, *it ); } out << " }" << endl; indent = " "; } out << "}" << endl; out << endl; } if ( needSqlTableEventHandler || needSqlDataBrowserEventHandler ) { out << "/*" << endl; out << " * Widget polish. Reimplemented to handle" << endl; if ( needSqlTableEventHandler ) out << " * default data table initialization" << endl; if ( needSqlDataBrowserEventHandler ) out << " * default data browser initialization" << endl; out << " */" << endl; out << "void " << nameOfClass << "::polish()" << endl; out << "{" << endl; if ( needSqlTableEventHandler ) { for ( i = 0; i < (int) nl.length(); i++ ) { QString s = getClassName( nl.item(i).toElement() ); if ( s == "QDataTable" ) { n = nl.item(i).toElement(); QString c = getObjectName( n ); QString conn = getDatabaseInfo( n, "connection" ); QString tab = getDatabaseInfo( n, "table" ); if ( !( conn.isEmpty() || tab.isEmpty() || !isFrameworkCodeGenerated( nl.item(i).toElement() ) ) ) { out << indent << "if ( " << c << " ) {" << endl; out << indent << indent << "QSqlCursor* cursor = " << c << "->sqlCursor();" << endl; out << indent << indent << "if ( !cursor ) {" << endl; if ( conn == "(default)" ) out << indent << indent << indent << "cursor = new QSqlCursor( \"" << tab << "\" );" << endl; else out << indent << indent << indent << "cursor = new QSqlCursor( \"" << tab << "\", TRUE, " << conn << "Connection );" << endl; out << indent << indent << indent << "if ( " << c << "->isReadOnly() ) " << endl; out << indent << indent << indent << indent << "cursor->setMode( QSqlCursor::ReadOnly );" << endl; out << indent << indent << indent << c << "->setSqlCursor( cursor, FALSE, TRUE );" << endl; out << indent << indent << "}" << endl; out << indent << indent << "if ( !cursor->isActive() )" << endl; out << indent << indent << indent << c << "->refresh( QDataTable::RefreshAll );" << endl; out << indent << "}" << endl; } } } } if ( needSqlDataBrowserEventHandler ) { nl = e.elementsByTagName( "widget" ); for ( i = 0; i < (int) nl.length(); i++ ) { QString s = getClassName( nl.item(i).toElement() ); if ( s == "QDataBrowser" ) { QString obj = getObjectName( nl.item(i).toElement() ); QString tab = getDatabaseInfo( nl.item(i).toElement(), "table" ); QString conn = getDatabaseInfo( nl.item(i).toElement(), "connection" ); if ( !(tab.isEmpty() || !isFrameworkCodeGenerated( nl.item(i).toElement() ) ) ) { out << indent << "if ( " << obj << " ) {" << endl; out << indent << indent << "if ( !" << obj << "->sqlCursor() ) {" << endl; if ( conn == "(default)" ) out << indent << indent << indent << "QSqlCursor* cursor = new QSqlCursor( \"" << tab << "\" );" << endl; else out << indent << indent << indent << "QSqlCursor* cursor = new QSqlCursor( \"" << tab << "\", TRUE, " << conn << "Connection );" << endl; out << indent << indent << indent << obj << "->setSqlCursor( cursor, TRUE );" << endl; out << indent << indent << indent << obj << "->refresh();" << endl; out << indent << indent << indent << obj << "->first();" << endl; out << indent << indent << "}" << endl; out << indent << "}" << endl; } } } } out << indent << objClass << "::polish();" << endl; out << "}" << endl; out << endl; } 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 << languageChangeBody; 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 = *it2; if ( type.isEmpty() ) type = "void"; type = type.simplifyWhiteSpace(); QString fname = Parser::cleanArgs( *it ); if ( !(*it3).startsWith("pure") ) { // "pure virtual" or "pureVirtual" out << type << " " << nameOfClass << "::" << fname << endl; out << "{" << endl; if ( *it != "init()" && *it != "destroy()" ) { QRegExp numeric( "^(?: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 'Q_UINT16' 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 != "void" ) { QStringList toks = QStringList::split( " ", type ); bool isBasicNumericType = ( toks.grep(numeric).count() == toks.count() ); if ( type == "bool" ) { retVal = "FALSE"; } else if ( isBasicNumericType || type.endsWith("*") ) { retVal = "0"; } else if ( type.endsWith("&") ) { do { type.truncate( type.length() - 1 ); } while ( type.endsWith(" ") ); retVal = "uic_temp_var"; out << indent << "static " << type << " " << retVal << ";" << endl; } else { retVal = type + "()"; } } 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 Uic::createFormImpl( const QDomElement& e, const QString& form, const QString& connection, const QString& table ){ if ( e.tagName() == "widget" && e.attribute( "class" ) != "QDataTable" ) { QString field = getDatabaseInfo( e, "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 + -