📄 uic.cpp
字号:
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 << " virtual 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 << " virtual void " << (*it) << ";" << endl; out << endl; } bool needProtected = needEventHandler; for ( it = layouts.begin(); !needProtected && it != layouts.end(); ++it ) needProtected = e.elementsByTagName( *it ).count() > 0 ; if ( needProtected ) out << "protected:" << endl; // child layouts registerLayouts(e); // handle application font and palette changes is required if ( needEventHandler ) out << " bool event( QEvent* );" << endl; out << "};" << endl; out << endl; out << "#endif // " << protector << endl;}void Uic::registerLayouts( const QDomElement &e ){ if (layouts.contains(e.tagName())) createObjectDecl(e); QDomNodeList nl = e.childNodes(); for (int i = 0; i < (int) nl.length(); ++i) registerLayouts(nl.item(i).toElement());}/*! Creates an implementation ( cpp-file ) for the form given in \a e \sa createFormDecl(), createObjectImpl() */void Uic::createFormImpl( const QDomElement &e ){ QDomElement n; QDomNodeList nl; int i; QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; QString objName = getObjectName( e ); indent = " "; // default indent for child properties // generate local and local includes required QStringList globalIncludes, localIncludes; QStringList::Iterator it; // additional includes (local or global ) and forward declaractions nl = e.parentNode().toElement().elementsByTagName( "include" ); for ( i = 0; i < (int) nl.length(); i++ ) { QDomElement n2 = nl.item(i).toElement(); QString s = n2.firstChild().toText().data(); if ( n2.attribute( "location" ) != "local" ) globalIncludes += s; } // 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( "location" ) == "local" &&!globalIncludes.contains( s ) ) localIncludes += s; } // additional custom widget headers nl = e.parentNode().toElement().elementsByTagName( "header" ); for ( i = 0; i < (int) nl.length(); i++ ) { QDomElement n2 = nl.item(i).toElement(); QString s = n2.firstChild().toText().data(); if ( n2.attribute( "location" ) != "local" ) globalIncludes += s; else localIncludes += s; } // includes for child widgets for ( it = tags.begin(); it != tags.end(); ++it ) { nl = e.elementsByTagName( *it ); for ( i = 0; i < (int) nl.length(); i++ ) { QString name = getClassName( nl.item(i).toElement() ); if ( name != objClass ) globalIncludes += getInclude( name ); if ( name.mid( 1 ) == "ListView" ) globalIncludes += "qheader.h"; } } globalIncludes = unique( globalIncludes ); for ( it = globalIncludes.begin(); it != globalIncludes.end(); ++it ) { if ( !(*it).isEmpty() ) out << "#include <" << *it << ">" << endl; } localIncludes = unique( localIncludes ); for ( it = localIncludes.begin(); it != localIncludes.end(); ++it ) { if ( !(*it).isEmpty() ) out << "#include \"" << *it << "\"" << endl; } out << "#include <qlayout.h>" << endl; out << "#include <qvariant.h>" << endl; out << "#include <qtooltip.h>" << endl; out << "#include <qwhatsthis.h>" << endl; // find out what images are required QStringList requiredImages; nl = e.elementsByTagName( "pixmap" ); for ( int j = 0; j < (int) nl.length(); j++ ) { requiredImages += nl.item(j).firstChild().toText().data(); } if (!requiredImages.isEmpty() ) { out << "#include <qimage.h>" << endl; out << "#include <qpixmap.h>" << endl << endl; } QStringList images; QStringList xpmImages; if ( pixmapLoaderFunction.isEmpty() ) { // create images for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "images" ) { nl = n.elementsByTagName( "image" ); for ( i = 0; i < (int) nl.length(); i++ ) { QDomElement tmp = nl.item(i).firstChild().toElement(); QString img = registerObject( tmp.firstChild().toText().data() ); if ( !requiredImages.contains( img ) ) continue; tmp = tmp.nextSibling().toElement(); QString format = tmp.attribute("format", "PNG" ); QString data = tmp.firstChild().toText().data(); if ( format == "XPM.GZ" ) { xpmImages += img; ulong length = tmp.attribute("length").toULong(); QByteArray baunzip = unzipXPM( data, length ); int a = 0; out << "static const char* const " << img << "_data[] = { " << endl; while ( baunzip[a] != '\"' ) a++; for ( ; a < (int) length; a++ ) out << baunzip[a]; out << endl; } else { images += img; out << "static const unsigned char const " << img << "_data[] = { " << endl; out << " "; int a ; for ( a = 0; a < (int) (data.length()/2)-1; a++ ) { out << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << ","; if ( a % 12 == 11 ) out << endl << " "; else out << " "; } out << "0x" << QString(data[2*a]) << QString(data[2*a+1]) << endl; out << "};" << endl << endl; } } } } out << endl; } // register the object and unify its name objName = registerObject( objName ); // constructor if ( objClass == "QDialog" || objClass == "QWizard" ) { out << "/* " << endl; out << " * Constructs a " << nameOfClass << " 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 << nameOfClass << "::" << nameOfClass << "( QWidget* parent, const char* name, bool modal, WFlags fl )" << endl; out << " : " << objClass << "( parent, name, modal, fl )" << endl; } else if ( objClass == "QWidget" ) { // standard QWidget out << "/* " << endl; out << " * Constructs a " << nameOfClass << " which is a child of 'parent', with the " << endl; out << " * name 'name' and widget flags set to 'f' " << endl; out << " */" << endl; out << nameOfClass << "::" << nameOfClass << "( QWidget* parent, const char* name, WFlags fl )" << endl; out << " : " << objClass << "( parent, name, fl )" << endl; } else { out << "/* " << endl; out << " * Constructs a " << nameOfClass << " which is a child of 'parent', with the " << endl; out << " * name 'name'.' " << endl; out << " */" << endl; out << nameOfClass << "::" << nameOfClass << "( QWidget* parent, const char* name )" << endl; out << " : " << objClass << "( parent, name )" << endl; } out << "{" << endl; // create pixmaps for all images if ( !images.isEmpty() ) { out << indent << "QImage img;" << endl; out << indent << "QPixmap "; QStringList::Iterator it; for ( it = images.begin(); it != images.fromLast(); ++it ) out << (*it) << ", "; out << (*it) << ";" << endl; for ( it = images.begin(); it != images.end(); ++it ) { out << indent << "img.loadFromData( " << (*it) << "_data, sizeof( " << (*it) << "_data ), \"PNG\" );" << endl; out << indent << (*it) << " = img;" << endl; } } // create pixmaps for all images if ( !xpmImages.isEmpty() ) { for ( it = xpmImages.begin(); it != xpmImages.end(); ++it ) { out << indent << "QPixmap " << (*it) << "( ( const char** ) " << (*it) << "_data );" << endl; } } // set the properties for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "property" ) { bool stdset = toBool( n.attribute( "stdset" ) ); QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString prop = n2.firstChild().toText().data(); QString value = setObjectProperty( objClass, QString::null, prop, n2.nextSibling().toElement(), stdset ); if ( value.isEmpty() ) continue; if ( prop == "name" ) { out << " if ( !name )" << endl; out << "\t"; } else { out << indent; } if ( prop == "geometry" && n2.nextSibling().toElement().tagName() == "rect") { QDomElement n3 = n2.nextSibling().toElement().firstChild().toElement(); int w = 0, h = 0; while ( !n3.isNull() ) { if ( n3.tagName() == "width" ) w = n3.firstChild().toText().data().toInt(); else if ( n3.tagName() == "height" ) h = n3.firstChild().toText().data().toInt(); n3 = n3.nextSibling().toElement(); } out << "resize( " << w << ", " << h << " ); " << endl; } else { if ( stdset ) out << mkStdSet(prop ) << "( " << value << " );" << endl; else out << "setProperty( \"" << prop << "\", " << value << " );" << endl; } } } } // create all children, some forms have special requirements if ( objClass == "QWizard" ) { for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( tags.contains( n.tagName() ) ) { QString page = createObjectImpl( n, objClass, "this" ); QString label = DomTool::readAttribute( n, "title", "" ).toString(); out << indent << "addPage( " << page << ", "<< trmacro << "( " << fixString( label ) << " ) );" << endl; QVariant def( FALSE, 0 ); if ( DomTool::hasAttribute( n, "backEnabled" ) ) out << indent << "setBackEnabled( " << page << ", " << mkBool( DomTool::readAttribute( n, "backEnabled", def).toBool() ) << endl; if ( DomTool::hasAttribute( n, "nextEnabled" ) ) out << indent << "setNextEnabled( " << page << ", " << mkBool( DomTool::readAttribute( n, "nextEnabled", def).toBool() ) << endl; if ( DomTool::hasAttribute( n, "finishEnabled" ) ) out << indent << "setFinishEnabled( " << page << ", " << mkBool( DomTool::readAttribute( n, "finishEnabled", def).toBool() ) << " );" << endl; if ( DomTool::hasAttribute( n, "helpEnabled" ) ) out << indent << "setHelpEnabled( " << page << ", " << mkBool( DomTool::readAttribute( n, "helpEnabled", def).toBool() ) << endl; if ( DomTool::hasAttribute( n, "finish" ) ) out << indent << "setFinish( " << page << ", " << mkBool( DomTool::readAttribute( n, "finish", def).toBool() ) << endl; } } } else { // standard widgets for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( tags.contains( n.tagName() ) ) createObjectImpl( n, objName, "this" ); } } 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; 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; } } // end of constructor out << "}" << endl; out << endl; // destructor out << "/* " << endl; out << " * Destroys the object and frees any allocated resources" << endl; out << " */" << endl; out << nameOfClass << "::~" << nameOfClass << "()" << endl; out << "{" << endl; out << " // no need to delete child widgets, Qt does it all for us" << endl; out << "}" << endl; out << endl; // handle application font changes if required nl = e.elementsByTagName( "widget" ); bool needEventHandler = FALSE; for ( i = 0; i < (int) nl.length(); i++ ) { if ( DomTool::hasProperty( nl.item(i).toElement() , "font" ) ) { needEventHandler = TRUE; break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -