⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uic.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.**** This file is part of Qt Designer.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "uic.h"#include "parser.h"#include "widgetdatabase.h"#include "domtool.h"#include <qfile.h>#include <qstringlist.h>#include <qdatetime.h>#define NO_STATIC_COLORS#include <globaldefs.h>#include <qregexp.h>#include <stdio.h>#include <stdlib.h>bool Uic::isMainWindow = FALSE;QString Uic::getComment( const QDomNode& n ){    QDomNode child = n.firstChild();    while ( !child.isNull() ) {	if ( child.toElement().tagName() == "comment" )	    return child.toElement().firstChild().toText().data();	child = child.nextSibling();    }    return QString::null;}QString Uic::mkBool( bool b ){    return b? "TRUE" : "FALSE";}QString Uic::mkBool( const QString& s ){    return mkBool( s == "true" || s == "1" );}bool Uic::toBool( const QString& s ){    return s == "true" || s.toInt() != 0;}QString Uic::fixString( const QString &str ){    QString s( str );    s.replace( "\\", "\\\\" );    s.replace( "\"", "\\\"" );    s.replace( "\r", "" );    s.replace( "\n", "\\n\"\n\"" );    return "\"" + s + "\"";}QString Uic::trcall( const QString& sourceText, const QString& comment ){    if ( sourceText.isEmpty() && comment.isEmpty() )	return "QString::null";    QString t = trmacro;    if ( t.isNull() ) {	t = "tr";	for ( int i = 0; i < (int) sourceText.length(); i++ ) {	    if ( sourceText[i].unicode() >= 0x80 ) {		t = "trUtf8";		break;	    }	}    }    if ( comment.isEmpty() ) {	return t + "( " + fixString( sourceText ) + " )";    } else {	return t + "( " + fixString( sourceText ) + ", " +	       fixString( comment ) + " )";    }}QString Uic::mkStdSet( const QString& prop ){    return QString( "set" ) + prop[0].upper() + prop.mid(1);}/*!  \class Uic uic.h  \brief User Interface Compiler  The class Uic encapsulates the user interface compiler (uic). */Uic::Uic( const QString &fn, const char *outputFn, QTextStream &outStream,	  QDomDocument doc, bool decl, bool subcl, const QString &trm,	  const QString& subClass, bool omitForwardDecls )    : out( outStream ), trout( &languageChangeBody ),      outputFileName( outputFn ), trmacro( trm ), nofwd( omitForwardDecls ){    fileName = fn;    writeFunctImpl = TRUE;    defMargin = BOXLAYOUT_DEFAULT_MARGIN;    defSpacing = BOXLAYOUT_DEFAULT_SPACING;    externPixmaps = FALSE;    indent = "    "; // default indent    item_used = cg_used = pal_used = 0;    layouts << "hbox" << "vbox" << "grid";    tags = layouts;    tags << "widget";    pixmapLoaderFunction = getPixmapLoaderFunction( doc.firstChild().toElement() );    nameOfClass = getFormClassName( doc.firstChild().toElement() );    stdsetdef = toBool( doc.firstChild().toElement().attribute("stdsetdef") );    if ( doc.firstChild().isNull() || doc.firstChild().firstChild().isNull() )	return;    QDomElement e = doc.firstChild().firstChild().toElement();    QDomElement widget;    while ( !e.isNull() ) {	if ( e.tagName() == "widget" ) {	    widget = e;	} else if ( e.tagName() == "pixmapinproject" ) {	    externPixmaps = TRUE;	} else if ( e.tagName() == "layoutdefaults" ) {	    defSpacing = e.attribute( "spacing", defSpacing.toString() );	    defMargin = e.attribute( "margin", defMargin.toString() );	} else if ( e.tagName() == "layoutfunctions" ) {	    defSpacing = e.attribute( "spacing", defSpacing.toString() );	    		    bool ok;	    defSpacing.toInt( &ok );	    if ( !ok ) {		QString buf = defSpacing.toString();		defSpacing = buf.append( "()" );	    }	    defMargin = e.attribute( "margin", defMargin.toString() );	    defMargin.toInt( &ok );	    if ( !ok ) {		QString buf = defMargin.toString();		defMargin = buf.append( "()" );	    }	}	e = e.nextSibling().toElement();    }    e = widget;    if ( nameOfClass.isEmpty() )	nameOfClass = getObjectName( e );    namespaces = QStringList::split( "::", nameOfClass );    bareNameOfClass = namespaces.last();    namespaces.remove( namespaces.fromLast() );    if ( subcl ) {	if ( decl )	    createSubDecl( e, subClass );	else	    createSubImpl( e, subClass );    } else {	if ( decl )	    createFormDecl( e );	else	    createFormImpl( e );    }}/*! Extracts a pixmap loader function from \a e */QString Uic::getPixmapLoaderFunction( const QDomElement& e ){    QDomElement n;    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	if ( n.tagName() == "pixmapfunction" )	    return n.firstChild().toText().data();    }    return QString::null;}/*! Extracts the forms class name from \a e */QString Uic::getFormClassName( const QDomElement& e ){    QDomElement n;    QString cn;    for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	if ( n.tagName() == "class" ) {	    QString s = n.firstChild().toText().data();	    int i;	    while ( ( i = s.find(' ' )) != -1 )		s[i] = '_';	    cn = s;	}    }    return cn;}/*! Extracts a class name from \a e. */QString Uic::getClassName( const QDomElement& e ){    QString s = e.attribute( "class" );    if ( s.isEmpty() && e.tagName() == "toolbar" )	s = "QToolBar";    else if ( s.isEmpty() && e.tagName() == "menubar" )	s = "QMenuBar";    return s;}/*! Returns TRUE if database framework code is generated, else FALSE.*/bool Uic::isFrameworkCodeGenerated( const QDomElement& e ){    QDomElement n = getObjectProperty( e, "frameworkCode" );    if ( n.attribute("name") == "frameworkCode" &&	 !DomTool::elementToVariant( n.firstChild().toElement(), QVariant( TRUE, 0 ) ).toBool() )	return FALSE;    return TRUE;}/*! Extracts an object name from \a e. It's stored in the 'name' property. */QString Uic::getObjectName( const QDomElement& e ){    QDomElement n = getObjectProperty( e, "name" );    if ( n.firstChild().toElement().tagName() == "cstring" )	return n.firstChild().toElement().firstChild().toText().data();    return QString::null;}/*! Extracts an layout name from \a e. It's stored in the 'name' property of the preceeding sibling (the first child of a QLayoutWidget). */QString Uic::getLayoutName( const QDomElement& e ){    QDomElement p = e.parentNode().toElement();    QString name;    if ( getClassName(p) != "QLayoutWidget" )	name = "Layout";    QDomElement n = getObjectProperty( p, "name" );    if ( n.firstChild().toElement().tagName() == "cstring" ) {	name.prepend( n.firstChild().toElement().firstChild().toText().data() );	return QStringList::split( "::", name ).last();    }    return e.tagName();}QString Uic::getDatabaseInfo( const QDomElement& e, const QString& tag ){    QDomElement n;    QDomElement n1;    int child = 0;    // database info is a stringlist stored in this order    if ( tag == "connection" )	child = 0;    else if ( tag == "table" )	child = 1;    else if ( tag == "field" )	child = 2;    else	return QString::null;    n = getObjectProperty( e, "database" );    if ( n.firstChild().toElement().tagName() == "stringlist" ) {	    // find correct stringlist entry	    QDomElement n1 = n.firstChild().firstChild().toElement();	    for ( int i = 0; i < child && !n1.isNull(); ++i )		n1 = n1.nextSibling().toElement();	    if ( n1.isNull() )		return QString::null;	    return n1.firstChild().toText().data();    }    return QString::null;}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() );}/*!  Returns include file for class \a className or a null string. */QString Uic::getInclude( const QString& className ){    int wid = WidgetDatabase::idFromClassName( className );    if ( wid != -1 )	return WidgetDatabase::includeFile( wid );    return QString::null;}void Uic::createActionDecl( const QDomElement& e ){    QString objClass = e.tagName() == "action" ? "QAction" : "QActionGroup";    QString objName = getObjectName( e );    if ( objName.isEmpty() )	return;    out << "    " << objClass << "* " << objName << ";" << endl;    if ( e.tagName() == "actiongroup" ) {	for ( QDomElement n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {	    if ( n.tagName() == "action" || n.tagName() == "actiongroup" )		createActionDecl( n );	}    }}void Uic::createToolbarDecl( const QDomElement &e ){    if ( e.tagName() == "toolbar" )	out << "    " << "QToolBar *" << getObjectName( e ) << ";" << endl;}void Uic::createMenuBarDecl( const QDomElement &e ){    if ( e.tagName() == "item" )	out << "    " << "QPopupMenu *" << e.attribute( "name" ) << ";" << endl;}

⌨️ 快捷键说明

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