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

📄 project.cpp

📁 Trolltech公司发布的基于C++图形开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000 Trolltech AS.  All rights reserved.****1 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.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** 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.** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Qt Commercial License Agreements.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "project.h"#include "formwindow.h"#include "designerappiface.h"#include "../interfaces/languageinterface.h"#include "pixmapcollection.h"#ifndef QT_NO_SQL#include "dbconnectionimpl.h"#endif#include "resource.h"#include <qwidgetfactory.h>#include "outputwindow.h"#include <qfile.h>#include <qtextstream.h>#include <qurl.h>#include <qobjectlist.h>#include <qfeatures.h>#include <qtextcodec.h>#include <qdom.h>#include <qmessagebox.h>#include <qapplication.h>#include "mainwindow.h"#include <qworkspace.h>#ifndef QT_NO_SQL#include <qsqldatabase.h>#include <qsqlrecord.h>#include <qdatatable.h>#endif#include <stdlib.h>#ifdef Q_OS_UNIX# include <unistd.h>#endif#ifndef QT_NO_SQLDatabaseConnection::~DatabaseConnection(){    delete iface;}bool DatabaseConnection::refreshCatalog(){#ifndef QT_NO_SQL    if ( loaded )	return TRUE;    if ( !open() )	return FALSE;    tbls = conn->tables( QSql::TableType( QSql::Tables | QSql::Views ) );    flds.clear();    for ( QStringList::Iterator it = tbls.begin(); it != tbls.end(); ++it ) {	QSqlRecord fil = conn->record( *it );	QStringList lst;	for ( uint j = 0; j < fil.count(); ++j )	    lst << fil.field( j )->name();	flds.insert( *it, lst );    }    loaded = TRUE;    conn->close();    return loaded;#else    return FALSE;#endif}#ifndef QT_NO_SQLvoid DatabaseConnection::remove(){    if ( nm == "(default)" )	QSqlDatabase::removeDatabase( QSqlDatabase::defaultConnection );    else	QSqlDatabase::removeDatabase( nm );    // the above will effectively delete the current connection    conn = 0;}#endifbool DatabaseConnection::open( bool suppressDialog ){#ifndef QT_NO_SQL    // register our name, if nec    if ( nm == "(default)" ) {	if ( !QSqlDatabase::contains() ) // default doesn't exists?	    conn = QSqlDatabase::addDatabase( drv );	else	    conn = QSqlDatabase::database();    } else {	if ( !QSqlDatabase::contains( nm ) )	    conn = QSqlDatabase::addDatabase( drv, nm );	else	    conn = QSqlDatabase::database( nm );    }    conn->setDatabaseName( dbName );    conn->setUserName( uname );    conn->setPassword( pword );    conn->setHostName( hname );    conn->setPort( prt );    bool success = conn->open();    for( ; suppressDialog == FALSE ; ) {	bool done = FALSE;	if ( !success ) {	    DatabaseConnectionEditor dia( this, 0  , 0 , TRUE );	    switch( dia.exec() ) {	    case QDialog::Accepted:		done = FALSE;		break;	    case QDialog::Rejected:		done = TRUE;		break;	    }	}	if ( done )	    break;	conn->setUserName( uname );	conn->setPassword( pword );	conn->setHostName( hname );	conn->setPort( prt );	success = conn->open();	if ( !success ) {	    switch( QMessageBox::warning( project->messageBoxParent(), QApplication::tr( "Connection" ),					  QApplication::tr( "Could not connect to the database.\n"							    "Press 'OK' to continue or 'Cancel' to "							    "specify different\nconnection information.\n" )					  + QString( "[" + conn->lastError().driverText() + "\n" +						     conn->lastError().databaseText() + "]\n" ),					  QApplication::tr( "&OK" ),					  QApplication::tr( "&Cancel" ), QString::null, 0, 1 ) ) {	    case 0: // OK or Enter		continue;	    case 1: // Cancel or Escape		done = TRUE;		break;	    }	} else	    break;	if ( done )	    break;    }    if ( !success ) {	dbErr = conn->lastError().driverText() + "\n" + conn->lastError().databaseText();	remove();    }    return success;#else    return FALSE;#endif}void DatabaseConnection::close(){    if ( !loaded )	return;#ifndef QT_NO_SQL    if ( conn ) {	conn->close();    }#endif}DesignerDatabase *DatabaseConnection::iFace(){    if ( !iface )	iface = new DesignerDatabaseImpl( this );    return iface;}#endif////////bool Project::isDummy() const{    return isDummyProject;}Project::Project( const QString &fn, const QString &pName,		  QPluginManager<ProjectSettingsInterface> *pm, bool isDummy,		  const QString &l )    : proName( pName ), projectSettingsPluginManager( pm ), isDummyProject( isDummy ){    modified = TRUE;    pixCollection = new PixmapCollection( this );    iface = 0;    lang = l;    is_cpp = lang == "C++";    cfg.insert( "(all)", "qt warn_on release" );    templ = "app";    setFileName( fn );    if ( !pName.isEmpty() )	proName = pName;    sourcefiles.setAutoDelete( TRUE );    modified = FALSE;    objs.setAutoDelete( FALSE );    fakeFormFiles.setAutoDelete( FALSE );}Project::~Project(){    if ( singleProjectMode() )	removeTempProject();    delete iface;    delete pixCollection;}void Project::setModified( bool b ){    modified = b;    emit projectModified();}#ifndef QT_NO_SQLDatabaseConnection *Project::databaseConnection( const QString &name ){    for ( DatabaseConnection *conn = dbConnections.first();	  conn;	  conn = dbConnections.next() ) {	if ( conn->name() == name )	    return conn;    }    return 0;}#endifvoid Project::setFileName( const QString &fn, bool doClear ){    if ( fn == filename )	return;    if ( singleProjectMode() ) {	QString qsa = QString( getenv( "HOME" ) ) + QString( "/.qsa" );	if ( !QFile::exists( qsa ) ) {	    QDir d;	    d.mkdir( qsa );	}	if ( fn == singleProFileName )	    return;	singleProFileName = fn;	static int counter = 0;	QString str_counter = QString::number( counter++ );	str_counter = "/.qsa/" + str_counter;	LanguageInterface *iface = MetaDataBase::languageInterface( language() );	filename = QString( getenv( "HOME" ) + str_counter + QString( "tmp_" ) +			    QFileInfo( fn ).baseName() + "/" + QFileInfo( fn ).baseName() + ".pro" );	removeTempProject();	if ( iface && iface->supports( LanguageInterface::CompressProject ) ) {	    filename = iface->uncompressProject( makeAbsolute( singleProFileName ),						 QString( getenv( "HOME" ) +							  str_counter + QString( "tmp_" ) +							  QFileInfo( fn ).baseName() ) );	    proName = makeAbsolute( singleProFileName );	}    } else {	filename = fn;	if ( !filename.endsWith( ".pro" ) )	    filename += ".pro";	proName = filename;    }    if ( proName.contains( '.' ) )	proName = proName.left( proName.find( '.' ) );    if ( !doClear )	return;    clear();    if ( QFile::exists( filename ) )	parse();}QString Project::fileName( bool singlePro ) const{    if ( singlePro )	return singleProFileName;    return filename;}QString Project::databaseDescription() const{    return dbFile;}QString Project::projectName() const{    return proName;}static QString parse_part( const QString &part ){    QString res;    bool inName = FALSE;    QString currName;    for ( int i = 0; i < (int)part.length(); ++i ) {	QChar c = part[ i ];	if ( !inName ) {	    if ( c != ' ' && c != '\t' && c != '\n' && c != '=' && c != '\\' && c != '+' )		inName = TRUE;	    else		continue;	}	if ( inName ) {	    if ( c == '\n' )		break;	    res += c;	}    }    return res;}QStringList parse_multiline_part( const QString &contents, const QString &key, int *start = 0 ){    if ( start )	*start = -1;    QString lastWord;    // Account for things like win32: SOURCES    int extraWhiteSpaceCount = 0;    int braceCount = 0;    for ( int i = 0; i < (int)contents.length(); ++i ) {	QChar c( contents[ i ] );	switch ( c ) {	case '{':	    braceCount++;	    lastWord = "";	    break;	case '}':	    braceCount--;	    lastWord = "";	    break;	case ' ': case '\t':	    if (!key.startsWith(lastWord)) {		lastWord = "";		extraWhiteSpaceCount = 0;	    } else {		extraWhiteSpaceCount++;	    }	    break;	case '\\': case '\n':	    lastWord = "";	    break;        case '#':            while ( contents[ i ] != '\n' && i < (int)contents.length() )                ++i;            break;	default:	    lastWord += c;	}	// ### we should read the 'bla { SOURCES= ... }' stuff as well (braceCount > 0)	if ( lastWord == key && braceCount == 0 ) {	    if ( start )		*start = i - lastWord.length() - extraWhiteSpaceCount + 1;	    QStringList lst;	    bool inName = FALSE;	    QString currName;	    bool hadEqual = FALSE;	    for ( ; i < (int)contents.length(); ++i ) {		c = contents[ i ];		if ( !hadEqual && c != '=' )		    continue;		if ( !hadEqual ) {		    hadEqual = TRUE;		    continue;		}		if ( ( c.isLetter() ||                       c.isDigit() ||                       c == '.' ||                       c == '/' ||                       c == '_' ||                       c == '\\' ||		       c == '\"' ||                       c == '\'' ||                       c == '=' ||                       c == '$' ||                       c == '-' ||                       c == '(' ||                       c == ')' ||                       c == ':' ||                       c == '+' ||                       c == ',' ||                       c == '~' ||                       c == '{' ||                       c == '}' ||                       c == '@' ) &&		     c != ' ' && c != '\t' && c != '\n' ) {		    if ( !inName )			currName = QString::null;		    if ( c != '\\' || contents[i+1] != '\n' ) {			currName += c;			inName = TRUE;		    }		} else {		    if ( inName ) {			inName = FALSE;			if ( currName.simplifyWhiteSpace() != "\\" )			    lst.append( currName );		    }		    if ( c == '\n' && i > 0 && contents[ (int)i - 1 ] != '\\' )			break;		}	    }	    return lst;	}    }    return QStringList();}void Project::parse(){    QFile f( filename );    if ( !f.exists() || !f.open( IO_ReadOnly ) )	return;    QTextStream ts( &f );    QString contents = ts.read();    f.close();    proName = QFileInfo( filename ).baseName();    QStringList::ConstIterator it;    int i = contents.find( "LANGUAGE" );    if ( i != -1 ) {	lang = "";	is_cpp = FALSE;	QString part = contents.mid( i + QString( "LANGUAGE" ).length() );	lang = parse_part( part );	is_cpp = lang == "C++";    }    i = contents.find( "DBFILE" );    if ( i != -1 ) {	dbFile = "";	QString part = contents.mid( i + QString( "DBFILE" ).length() );	dbFile = parse_part( part );    }    QStringList uifiles = parse_multiline_part( contents, "FORMS" );    uifiles += parse_multiline_part( contents, "INTERFACES" ); // compatibility    for ( it = uifiles.begin(); it != uifiles.end(); ++it ) {	if ( (*it).startsWith( "__APPOBJ" ) )	    continue;	(void) new FormFile( *it, FALSE, this );    }    i = contents.find( "TEMPLATE" );    if ( i != -1 ) {	templ = "";	QString part = contents.mid( i + QString( "TEMPLATE" ).length() );	templ = parse_part( part );    }    readPlatformSettings( contents, "CONFIG", cfg );    readPlatformSettings( contents, "LIBS", lbs );    readPlatformSettings( contents, "INCLUDEPATH", inclPath );    readPlatformSettings( contents, "DEFINES", defs );    readPlatformSettings( contents, "SOURCES", sources );    readPlatformSettings( contents, "HEADERS", headers );    LanguageInterface *iface = MetaDataBase::languageInterface( lang );    if ( iface ) {	QStringList sourceKeys;	iface->sourceProjectKeys( sourceKeys );	for ( QStringList::Iterator it = sourceKeys.begin(); it != sourceKeys.end(); ++it ) {	    QStringList lst = parse_multiline_part( contents, *it );	    for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it )		(void) new SourceFile( *it, FALSE, this );	}    }    updateCustomSettings();    for ( it = csList.begin(); it != csList.end(); ++it ) {	i = contents.find( *it );	if ( i != -1 ) {	    QString val = "";	    QString part = contents.mid( i + QString( *it ).length() );	    val = parse_part( part );	    customSettings.replace( *it, val );	}    }    loadConnections();    QStringList images = parse_multiline_part( contents, "IMAGES" );    // ### remove that for the final - this is beta-compatibility    if ( images.isEmpty() && QDir( QFileInfo( filename ).dirPath( TRUE ) + "/images" ).exists() ) {	    images = QDir( QFileInfo( filename ).dirPath( TRUE ) + "/images" ).entryList();	    for ( int i = 0; i < (int)images.count(); ++i )		images[ i ].prepend( "images/" );	    modified = TRUE;    }    for ( QStringList::ConstIterator pit = images.begin(); pit != images.end(); ++pit )	pixCollection->load( *pit );}void Project::clear(){    dbFile = "";    proName = "unnamed";

⌨️ 快捷键说明

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