uic.cpp
来自「Qt/Embedded是一个多平台的C++图形用户界面应用程序框架」· C++ 代码 · 共 1,993 行 · 第 1/5 页
CPP
1,993 行
r++; cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) ); } n = n.nextSibling().toElement(); } return cg;}/*! Registers an object with name \a name. The returned name is a valid variable identifier, as similar to \a name as possible and guaranteed to be unique within the form. \sa registeredName(), isObjectRegistered() */QString Uic::registerObject( const QString& name ){ if ( objectNames.isEmpty() ) { // some temporary variables we need objectNames += "img"; objectNames += "item"; objectNames += "cg"; objectNames += "pal"; } QString result = name; int i; while ( ( i = result.find(' ' )) != -1 ) { result[i] = '_'; } if ( objectNames.contains( result ) ) { int i = 2; while ( objectNames.contains( result + "_" + QString::number(i) ) ) i++; result += "_"; result += QString::number(i); } objectNames += result; objectMapper.insert( name, result ); return result;}/*! Returns the registered name for the original name \a name or \a name if \a name wasn't registered. \sa registerObject(), isObjectRegistered() */QString Uic::registeredName( const QString& name ){ if ( !objectMapper.contains( name ) ) return name; return objectMapper[name];}/*! Returns whether the object \a name was registered yet or not. */bool Uic::isObjectRegistered( const QString& name ){ return objectMapper.contains( name );}/*! Unifies the entries in stringlist \a list. Should really be a QStringList feature. */QStringList Uic::unique( const QStringList& list ){ QStringList result; if (list.isEmpty() ) return result; QStringList l = list; l.sort(); result += l.first(); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { if ( *it != result.last() ) result += *it; } return result;}/*! Creates an instance of class \a objClass, with parent \a parent and name \a objName */QString Uic::createObjectInstance( const QString& objClass, const QString& parent, const QString& objName ){ if ( objClass == "QComboBox" ) { return objClass + "( FALSE, " + parent + ", \"" + objName + "\" )"; } return objClass + "( " + parent + ", \"" + objName + "\" )";}bool Uic::isLayout( const QString& name ) const{ return layoutObjects.contains( name );}/*! Creates a declaration ( headerfile ) for a subclass \a subClass of the form given in \a e \sa createSubImpl() */void Uic::createSubDecl( const QDomElement &e, const QString& subClass ){ QDomElement n; QStringList::Iterator it; QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; out << "class " << subClass << " : public " << nameOfClass << endl; out << "{ " << endl;/* tmake ignore Q_OBJECT */ out << " Q_OBJECT" << endl; out << endl; out << "public:" << endl; // constructor if ( objClass == "QDialog" || objClass == "QWizard" ) { out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );" << endl; } else { // standard QWidget out << " " << subClass << "( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );" << endl; } // destructor out << " ~" << subClass << "();" << endl; out << endl; // find additional slots QStringList publicSlots, protectedSlots; for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "connections" ) { for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "slot" ) { QString access = n2.attribute( "access" ); if ( access == "protected" ) protectedSlots += n2.firstChild().toText().data(); else publicSlots += n2.firstChild().toText().data(); } } } } // create public additional slots as pure-virtual functions if ( !publicSlots.isEmpty() ) { out << "public slots:" << endl; for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) out << " void " << (*it) << ";" << endl; out << endl; } // create protected additional slots as pure-virtual functions if ( !protectedSlots.isEmpty() ) { out << "protected slots:" << endl; for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) out << " void " << (*it) << ";" << endl; out << endl; } out << "};" << endl;}/*! Creates an implementation for a subclass \a subClass of the form given in \a e \sa createSubDecl() */void Uic::createSubImpl( const QDomElement &e, const QString& subClass ){ QDomElement n; QStringList::Iterator it; QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; // constructor if ( objClass == "QDialog" || objClass == "QWizard" ) { out << "/* " << endl; out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl; out << " * name 'name' and widget flags set to 'f' " << endl; out << " *" << endl; out << " * The " << objClass.mid(1).lower() << " will by default be modeless, unless you set 'modal' to" << endl; out << " * TRUE to construct a modal " << objClass.mid(1).lower() << "." << endl; out << " */" << endl; out << subClass << "::" << subClass << "( QWidget* parent, const char* name, bool modal, WFlags fl )" << endl; out << " : " << nameOfClass << "( parent, name, modal, fl )" << endl; } else { // standard QWidget out << "/* " << endl; out << " * Constructs a " << subClass << " which is a child of 'parent', with the " << endl; out << " * name 'name' and widget flags set to 'f' " << endl; out << " */" << endl; out << subClass << "::" << subClass << "( QWidget* parent, const char* name, WFlags fl )" << endl; out << " : " << nameOfClass << "( parent, name, fl )" << endl; } out << "{" << endl; out << "}" << endl; out << endl; // destructor out << "/* " << endl; out << " * Destroys the object and frees any allocated resources" << endl; out << " */" << endl; out << subClass << "::~" << subClass << "()" << endl; out << "{" << endl; out << " // no need to delete child widgets, Qt does it all for us" << endl; out << "}" << endl; out << endl; // find additional slots QStringList publicSlots, protectedSlots; for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "connections" ) { for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "slot" ) { QString access = n2.attribute( "access" ); if ( access == "protected" ) protectedSlots += n2.firstChild().toText().data(); else publicSlots += n2.firstChild().toText().data(); } } } } // create stubs for public additional slots if ( !publicSlots.isEmpty() ) { for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) { out << "/* " << endl; out << " * public slot" << endl; out << " */" << endl; out << "void " << subClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << subClass << "::" << (*it) << " not yet implemented!\" ); " << endl; out << "}" << endl; } out << endl; } // create stubs for protected additional slots if ( !protectedSlots.isEmpty() ) { for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) { out << "/* " << endl; out << " * protected slot" << endl; out << " */" << endl; out << "void " << subClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << subClass << "::" << (*it) << " not yet implemented!\" ); " << endl; out << "}" << endl; } out << endl; }}int main( int argc, char * argv[] ){ bool impl = FALSE; bool subcl = FALSE; const char *error = 0; const char* fileName = 0; const char* className = 0; const char* headerFile = 0; const char* outputFile = 0; const char* trmacro = 0; for ( int n = 1; n < argc && error == 0; n++ ) { QCString arg = argv[n]; if ( arg[0] == '-' ) { // option QCString opt = &arg[1]; if ( opt[0] == 'o' ) { // output redirection if ( opt[1] == '\0' ) { if ( !(n < argc-1) ) { error = "Missing output-file name"; break; } outputFile = argv[++n]; } else outputFile = &opt[1]; } else if ( opt[0] == 'i' || opt == "impl" ) { impl = TRUE; if ( opt == "impl" || opt[1] == '\0' ) { if ( !(n < argc-1) ) { error = "Missing name of header file."; break; } headerFile = argv[++n]; } else headerFile = &opt[1]; } else if ( opt == "subdecl" ) { subcl = TRUE; if ( !(n < argc-2) ) { error = "Missing arguments."; break; } className = argv[++n]; headerFile = argv[++n]; } else if ( opt == "subimpl" ) { subcl = TRUE; impl = TRUE; if ( !(n < argc-2) ) { error = "Missing arguments."; break; } className = argv[++n]; headerFile = argv[++n]; } else if ( opt == "tr" ) { if ( opt == "tr" || opt[1] == '\0' ) { if ( !(n < argc-1) ) { error = "Missing tr macro."; break; } trmacro = argv[++n]; } else { trmacro = &opt[1]; } } } else { if ( fileName) // can handle only one file error = "Too many input files specified"; else fileName = argv[n]; } } if ( argc < 2 || error || !fileName ) { fprintf( stderr, "Qt user interface compiler\n" ); if ( error ) fprintf( stderr, "uic: %s\n", error ); fprintf( stderr, "Usage: %s [options] [mode] <uifile>\n" "\nGenerate declaration:\n" " %s [options] <uifile>\n" "Generate implementation:\n" " %s [options] -impl <headerfile> <uifile>\n" "\t<headerfile> name of the declaration file\n" "Generate subclass declaration:\n" " %s [options] -subdecl <classname> <headerfile> <uifile>\n" "\t<classname> name of the subclass to generate\n" "\t<headerfile> declaration file of the baseclass\n" "Generate subclass implementation:\n" " %s [options] -subimpl <classname> <headerfile> <uifile>\n" "\t<classname> name of the subclass to generate\n" "\t<headerfile> declaration file of the subclass\n" "Options:\n" "\t-o file Write output to file rather than stdout\n" "\t-tr func Use func(...) rather than tr(...) for i18n\n" , argv[0], argv[0], argv[0], argv[0], argv[0]); exit( 1 ); } QFile file( fileName ); if ( !file.open( IO_ReadOnly ) ) qFatal( "uic: Could not open file '%s' ", fileName ); QFile fileOut; if (outputFile ) { fileOut.setName( outputFile ); if (!fileOut.open( IO_WriteOnly ) ) qFatal( "uic: Could not open output file '%s'", outputFile ); } else { fileOut.open( IO_WriteOnly, stdout ); } QTextStream out( &fileOut ); QDomDocument doc; if ( !doc.setContent( &file ) ) qFatal( "uic: Failed to parse %s\n", fileName ); if ( !subcl ) { out << "/****************************************************************************" << endl; out << "** Form "<< (impl? "implementation" : "interface") << " generated from reading ui file '" << fileName << "'" << endl; out << "**" << endl; out << "** Created: " << QDateTime::currentDateTime().toString() << endl; out << "** by: The User Interface Compiler (uic)" << endl; out << "**" << endl; out << "** WARNING! All changes made in this file will be lost!" << endl; out << "****************************************************************************/" << endl; } QString protector; if ( subcl && clas
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?