form.cpp

来自「qt-x11-free-3.0.3.tar.gz minigui图形界面工具」· C++ 代码 · 共 1,243 行 · 第 1/3 页

CPP
1,243
字号
	      it != publicSlots.end(); ++it, ++it2, ++it3 ) {	    bool createDecl = TRUE;	    QString specifier;	    QString pure;	    QString type = *it2;	    if ( type.isEmpty() )		type = "void";	    if ( *it3 != "non virtual" && *it3 != "nonVirtual" )		specifier = "virtual ";	    if ( *it3 == "pure virtual" || *it3 == "pureVirtual" )		pure = " = 0";	    QString fname = Parser::cleanArgs( *it );	    QMap<QString, QString>::Iterator fit = functionImpls.find( fname );	    if ( fit != functionImpls.end() ) {		int begin = (*fit).find( "{" );		QString body = (*fit).mid( begin + 1, (*fit).find( "}" ) - begin - 1 );		createDecl = body.simplifyWhiteSpace().isEmpty();	    }	    if ( createDecl )		out << "    " << specifier << type << " " << (*it) << pure << ";" << endl;	}	if ( needPolish )	    out << indent << "void polish();" << endl;	out << endl;    }    // create protected additional slots    if ( !protectedSlots.isEmpty() ) {	out << "protected slots:" << endl;	for ( it = protectedSlots.begin(), it2 = protectedSlotTypes.begin(), it3 = protectedSlotSpecifier.begin();	      it != protectedSlots.end(); ++it, ++it2, ++it3 ) {	    bool createDecl = TRUE;	    QString specifier;	    QString pure;	    QString type = *it2;	    if ( type.isEmpty() )		type = "void";	    if ( *it3 != "non virtual" && *it3 != "nonVirtual" )		specifier = "virtual ";	    if ( *it3 == "pure virtual" || *it3 == "pureVirtual" )		pure = " = 0";	    QString fname = Parser::cleanArgs( *it );	    QMap<QString, QString>::Iterator fit = functionImpls.find( fname );	    if ( fit != functionImpls.end() ) {		int begin = (*fit).find( "{" );		QString body = (*fit).mid( begin + 1, (*fit).find( "}" ) - begin - 1 );		createDecl = body.simplifyWhiteSpace().isEmpty();	    }	    if ( createDecl )		out << "    " << specifier << type << " " << (*it) << pure << ";" << endl;	}	out << endl;    }    // create protected additional slots    if ( !privateSlots.isEmpty() ) {	out << "private slots:" << endl;	for ( it = privateSlots.begin(), it2 = privateSlotTypes.begin(), it3 = privateSlotSpecifier.begin();	      it != privateSlots.end(); ++it, ++it2, ++it3 ) {	    bool createDecl = TRUE;	    QString specifier;	    QString pure;	    QString type = *it2;	    if ( type.isEmpty() )		type = "void";	    if ( *it3 != "non virtual" && *it3 != "nonVirtual" )		specifier = "virtual ";	    if ( *it3 == "pure virtual" || *it3 == "pureVirtual" )		pure = " = 0";	    QString fname = Parser::cleanArgs( *it );	    QMap<QString, QString>::Iterator fit = functionImpls.find( fname );	    if ( fit != functionImpls.end() ) {		int begin = (*fit).find( "{" );		QString body = (*fit).mid( begin + 1, (*fit).find( "}" ) - begin - 1 );		createDecl = body.simplifyWhiteSpace().isEmpty();	    }	    if ( createDecl )		out << "    " << specifier << type << " " << (*it) << pure << ";" << endl;	}	out << endl;    }    bool needProtected = needEventHandler;    for ( it = layouts.begin(); !needProtected && it != layouts.end(); ++it )	needProtected = needProtected || e.elementsByTagName( *it ).count() > 0 ;    if ( needProtected )	out << "protected:" << endl;    // child layouts    registerLayouts(e);    // handle application events    if ( needEventHandler && FALSE )	out << "    bool event( QEvent* );" << endl;    //## multiple ctor initialization, needed anymore?    //    out << indent << "void init" << nameOfClass << "();" << endl;    nl = e.parentNode().toElement().elementsByTagName( "variable" );    if ( nl.length() > 0 ) {	if ( !needProtected )	    out << "protected:" << endl;	out << endl;	for ( i = 0; i < (int) nl.length(); i++ ) {	    QString v = nl.item( i ).firstChild().toText().data().stripWhiteSpace();	    if ( !v.endsWith( ";" ) )		v += ";";	    out << indent << v << endl;	}    }    out << "};" << endl;    out << endl;    out << "#endif // " << protector << endl;}/*!  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 );    // generate local and local includes required    QStringList globalIncludes, localIncludes;    QStringList::Iterator it;    QMap<QString, CustomInclude> customWidgetIncludes;    QMap<QString, QString> functionImpls;    // find additional slots and functions    QStringList extraSlots;    QStringList extraSlotTypes;    nl = e.parentNode().toElement().elementsByTagName( "slot" );    for ( i = 0; i < (int) nl.length(); i++ ) {	n = nl.item(i).toElement();	if ( n.parentNode().toElement().tagName() != "slots"	     && n.parentNode().toElement().tagName() != "connections" )	    continue;	if ( n.attribute( "language", "C++" ) != "C++" )	    continue;	QString slotName = n.firstChild().toText().data().stripWhiteSpace();	if ( slotName.endsWith( ";" ) )	    slotName = slotName.left( slotName.length() - 1 );	extraSlots += slotName;	extraSlotTypes += n.attribute( "returnType", "void" );    }    for ( n = e; !n.isNull(); n = n.nextSibling().toElement() ) {	if ( n.tagName() == "functions" ) { // compatibility	    for ( QDomElement n2 = n.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) {		if ( n2.tagName() == "function" ) {		    QString fname = n2.attribute( "name" );		    fname = Parser::cleanArgs( fname );		    functionImpls.insert( fname, n2.firstChild().toText().data() );		}	    }	} else if ( n.tagName() == "customwidgets" ) {	    QDomElement n2 = n.firstChild().toElement();	    while ( !n2.isNull() ) {		if ( n2.tagName() == "customwidget" ) {		    QDomElement n3 = n2.firstChild().toElement();		    QString cl;		    WidgetDatabaseRecord *r = new WidgetDatabaseRecord;		    while ( !n3.isNull() ) {			if ( n3.tagName() == "class" ) {			    cl = n3.firstChild().toText().data();			    r->name = cl;			} else if ( n3.tagName() == "header" ) {			    CustomInclude ci;			    ci.header = n3.firstChild().toText().data();			    ci.location = n3.attribute( "location", "global" );			    r->includeFile = ci.header;			    customWidgetIncludes.insert( cl, ci );			}			WidgetDatabase::append( r );			n3 = n3.nextSibling().toElement();		    }		}		n2 = n2.nextSibling().toElement();	    }	}    }    // 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" ) {	    if ( s.right( 5 ) == ".ui.h" && !QFile::exists( s ) )		continue;	    if ( n2.attribute( "impldecl", "in implementation" ) != "in implementation" )		continue;	    globalIncludes += s;	}    }    registerDatabases( e );    dbConnections = unique( dbConnections );    if ( dbConnections.count() )	globalIncludes += "qsqldatabase.h";    if ( dbCursors.count() )	globalIncludes += "qsqlcursor.h";    bool dbForm = FALSE;    if ( dbForms[ "(default)" ].count() )	dbForm = TRUE;    bool subDbForms = FALSE;    for ( it = dbConnections.begin(); it != dbConnections.end(); ++it ) {	if ( !(*it).isEmpty()  && (*it) != "(default)" ) {	    if ( dbForms[ (*it) ].count() ) {		subDbForms = TRUE;		break;	    }	}    }    if ( dbForm || subDbForms ) {	globalIncludes += "qsqlform.h";	globalIncludes += "qsqlrecord.h";    }    // 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 ) ) {	    if ( s.right( 5 ) == ".ui.h" && !QFile::exists( s ) )		continue;	    if ( n2.attribute( "impldecl", "in implementation" ) != "in implementation" )		continue;	    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.parentNode().toElement().elementsByTagName( *it );	for ( i = 1; i < (int) nl.length(); i++ ) { // start at 1, 0 is the toplevel widget	    QString name = getClassName( nl.item(i).toElement() );	    if ( name == "Spacer" ) {		globalIncludes += "qlayout.h";		globalIncludes += "qapplication.h";		continue;	    }	    if ( name.mid( 1 ) == "ListView" )		globalIncludes += "qheader.h";	    if ( name != objClass ) {		int wid = WidgetDatabase::idFromClassName( name );		QMap<QString, CustomInclude>::Iterator it = customWidgetIncludes.find( name );		if ( it == customWidgetIncludes.end() )		    globalIncludes += WidgetDatabase::includeFile( wid );	    }	}    }    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 <" << *it << ">" << endl;    }    if ( externPixmaps ) {	out << "#include <qmime.h>" << endl;	out << "#include <qdragobject.h>" << endl;    }    out << "#include <qlayout.h>" << endl;    out << "#include <qtooltip.h>" << endl;    out << "#include <qwhatsthis.h>" << endl;    if ( objClass == "QMainWindow" ) {	out << "#include <qaction.h>" << endl;	out << "#include <qmenubar.h>" << endl;	out << "#include <qpopupmenu.h>" << endl;	out << "#include <qtoolbar.h>" << endl;    }    // find out what images are required    QStringList requiredImages;    static const char *imgTags[] = { "pixmap", "iconset", 0 };    for ( i = 0; imgTags[i] != 0; i++ ) {	nl = e.parentNode().toElement().elementsByTagName( imgTags[i] );	for ( int j = 0; j < (int) nl.length(); j++ )	    requiredImages += nl.item(j).firstChild().toText().data();    }    if ( !requiredImages.isEmpty() || 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 + ".h" ).fileName() )	    out << "#include \"" << *it << "\"" << endl;    }    if ( QFile::exists( fileName + ".h" ) ) {	out << "#include \"" << QFileInfo(fileName).fileName() << ".h\"" << endl;	writeSlotImpl = FALSE;    }    // register the object and unify its name    objName = registerObject( objName );    QStringList images;    QStringList xpmImages;    if ( pixmapLoaderFunction.isEmpty() && !externPixmaps ) {	// 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++ ) {		    QString img = registerObject(  nl.item(i).toElement().attribute( "name" ) );		    if ( !requiredImages.contains( img ) )			continue;		    QDomElement tmp = nl.item(i).firstChild().toElement();		    if ( tmp.tagName() != "data" )			continue;		    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 );			// shouldn't we test the initial 'length' against the			// resulting 'length' to catch corrupt UIC files?			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;    } else if ( externPixmaps ) {	out << "static QPixmap uic_load_pixmap_" << objName << "( const QString &name )" << endl;	out << "{" << endl;	out << "    const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( name );" << endl;	out << "    if ( !m )" << endl;	out << "\treturn QPixmap();" << endl;	out << "    QPixmap pix;" << endl;	out << "    QImageDrag::decode( m, pix );" << endl;	out << "    return pix;" << endl;	out << "}" << endl;	pixmapLoaderFunction = "uic_load_pixmap_" + objName;    }    // constructor(s)    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" )  {	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 if ( objClass == "QMainWindow" ) {	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;

⌨️ 快捷键说明

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