📄 project.cpp
字号:
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 ); 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"; desc = "";}bool Project::removeSourceFile( SourceFile *sf ){ if ( !sourcefiles.containsRef( sf ) ) return FALSE; if ( !sf->close() ) return FALSE; sourcefiles.removeRef( sf ); modified = TRUE; emit sourceFileRemoved( sf ); return TRUE;}void Project::setDatabaseDescription( const QString &db ){ dbFile = db;}void Project::setDescription( const QString &s ){ desc = s;}QString Project::description() const{ return desc;}bool Project::isValid() const{ // #### do more checking here? if ( filename.isEmpty() || proName.isEmpty() ) return FALSE; return TRUE;}QString Project::makeAbsolute( const QString &f ){ if ( isDummy() ) return f; QUrl u( QFileInfo( filename ).dirPath( TRUE ), f ); return u.path();}QString Project::makeRelative( const QString &f ){ if ( isDummy() ) return f; QString p = QFileInfo( filename ).dirPath( TRUE ); QString f2 = f; if ( f2.left( p.length() ) == p ) f2.remove( 0, p.length() + 1 ); return f2;}static void remove_contents( QString &contents, const QString &s ){ int i = contents.find( s ); if ( i != -1 ) { int start = i; int end = contents.find( '\n', i ); if ( end == -1 ) end = contents.length() - 1; contents.remove( start, end - start + 1 ); }}static void remove_multiline_contents( QString &contents, const QString &s, int *strt = 0 ){ int i; parse_multiline_part( contents, s, &i ); if ( strt ) *strt = i; int start = i; bool lastWasBackspash = FALSE; if ( i != -1 && ( i == 0 || contents[ i - 1 ] != '{' || contents[ i - 1 ] != ':' ) ) { for ( ; i < (int)contents.length(); ++i ) { if ( contents[ i ] == '\n' && !lastWasBackspash ) break; lastWasBackspash = ( contents[ i ] == '\\' || lastWasBackspash && ( contents[ i ] == ' ' || contents[ i ] == '\t' ) ); } contents.remove( start, i - start + 1 ); }}void Project::save( bool onlyProjectFile ){ bool anythingModified = FALSE; if ( !onlyProjectFile ) { for ( SourceFile *sf = sourcefiles.first(); sf; sf = sourcefiles.next() ) { anythingModified = anythingModified || sf->isModified(); if ( !sf->save() ) return; } for ( FormFile *ff = formfiles.first(); ff; ff = formfiles.next() ) { anythingModified = anythingModified || ff->isModified(); if ( !ff->save() ) return; } } if ( isDummy() || filename.isEmpty() ) return; if ( !modified ) { if ( singleProjectMode() ) { LanguageInterface *iface = MetaDataBase::languageInterface( language() ); if ( iface && iface->supports( LanguageInterface::CompressProject ) ) iface->compressProject( makeAbsolute( filename ), singleProFileName, anythingModified ); } return; } QFile f( filename ); QString contents; if ( f.open( IO_ReadOnly ) ) { QTextStream ts( &f ); contents = ts.read(); f.close(); } else { // initial contents contents = "unix {\n" " UI_DIR = .ui\n" " MOC_DIR = .moc\n" " OBJECTS_DIR = .obj\n" "}\n"; } remove_multiline_contents( contents, "FORMS" ); remove_multiline_contents( contents, "INTERFACES" ); // compatibility if ( !formfiles.isEmpty() ) { contents += "FORMS\t= "; for ( QPtrListIterator<FormFile> fit = formfiles; fit.current(); ++fit ) { contents += fit.current()->fileName() + (fit != formfiles.last() ? " \\\n\t" : ""); } contents += "\n"; } remove_multiline_contents( contents, "IMAGES" ); if ( !pixCollection->isEmpty() ) { contents += "IMAGES\t= "; QValueList<PixmapCollection::Pixmap> pixmaps = pixCollection->pixmaps(); for ( QValueList<PixmapCollection::Pixmap>::Iterator it = pixmaps.begin(); it != pixmaps.end(); ++it ) { contents += makeRelative( (*it).absname ) + (++it != pixmaps.end() ? " \\\n\t" : ""); --it; } contents += "\n"; } remove_contents( contents, "{SOURCES+=" ); // ### compatibility with early 3.0 betas remove_contents( contents, "DBFILE" ); remove_contents( contents, "LANGUAGE" ); remove_contents( contents, "TEMPLATE" ); removePlatformSettings( contents, "CONFIG" ); removePlatformSettings( contents, "DEFINES" ); removePlatformSettings( contents, "LIBS" ); removePlatformSettings( contents, "INCLUDEPATH" ); contents += "TEMPLATE\t=" + templ + "\n"; writePlatformSettings( contents, "CONFIG", cfg ); LanguageInterface *iface = MetaDataBase::languageInterface( lang ); if ( iface ) { QStringList sourceKeys; iface->sourceProjectKeys( sourceKeys ); for ( QStringList::Iterator spit = sourceKeys.begin(); spit != sourceKeys.end(); ++spit ) remove_multiline_contents( contents, *spit ); } writePlatformSettings( contents, "DEFINES", defs ); writePlatformSettings( contents, "INCLUDEPATH", inclPath ); writePlatformSettings( contents, "LIBS", lbs ); if ( !dbFile.isEmpty() ) contents += "DBFILE\t= " + dbFile + "\n"; contents += "LANGUAGE\t= " + lang + "\n"; if ( !sourcefiles.isEmpty() && iface ) { QMap<QString, QStringList> sourceToKey; for ( SourceFile *f = sourcefiles.first(); f; f = sourcefiles.next() ) { QString key = iface->projectKeyForExtension( QFileInfo( f->fileName() ).extension() ); QStringList lst = sourceToKey[ key ]; lst << makeRelative( f->fileName() ); sourceToKey.replace( key, lst ); } for ( QMap<QString, QStringList>::Iterator skit = sourceToKey.begin(); skit != sourceToKey.end(); ++skit ) { QString part = skit.key() + "\t+= "; QStringList lst = *skit; for ( QStringList::Iterator sit = lst.begin(); sit != lst.end(); ++sit ) { part += *sit; part += ++sit != lst.end() ? " \\\n\t" : ""; --sit; } contents.insert( 0, part + "\n" ); } } for ( QStringList::Iterator it = csList.begin(); it != csList.end(); ++it ) { remove_contents( contents, *it ); QString val = *customSettings.find( *it ); if ( !val.isEmpty() ) contents += *it + "\t= " + val + "\n"; } if ( !f.open( IO_WriteOnly | IO_Translate ) ) { QMessageBox::warning( messageBoxParent(), "Save Project Failed", "Couldn't write project file " + filename ); return; } QTextStream os( &f ); os << contents; f.close(); saveConnections(); setModified( FALSE ); if ( singleProjectMode() ) { LanguageInterface *iface = MetaDataBase::languageInterface( language() ); if ( iface && iface->supports( LanguageInterface::CompressProject ) ) iface->compressProject( makeAbsolute( filename ), singleProFileName, TRUE ); }}#ifndef QT_NO_SQLQPtrList<DatabaseConnection> Project::databaseConnections() const{ return dbConnections;}#endif#ifndef QT_NO_SQLvoid Project::setDatabaseConnections( const QPtrList<DatabaseConnection> &lst ){ dbConnections = lst;}#endif#ifndef QT_NO_SQLvoid Project::addDatabaseConnection( DatabaseConnection *conn ){ dbConnections.append( conn ); modified = TRUE;}#endif#ifndef QT_NO_SQLvoid Project::removeDatabaseConnection( const QString &c ){ for ( DatabaseConnection *conn = dbConnections.first(); conn; conn = dbConnections.next() ) { if ( conn->name() == c ) { conn->remove(); dbConnections.removeRef( conn ); delete conn; return; } }}#endif#ifndef QT_NO_SQLQStringList Project::databaseConnectionList(){ QStringList lst; for ( DatabaseConnection *conn = dbConnections.first(); conn; conn = dbConnections.next() ) lst << conn->name(); return lst;}#endif#ifndef QT_NO_SQLQStringList Project::databaseTableList( const QString &connection ){ DatabaseConnection *conn = databaseConnection( connection ); if ( !conn ) { return QStringList(); } return conn->tables();}#endif#ifndef QT_NO_SQLQStringList Project::databaseFieldList( const QString &connection, const QString &table ){ DatabaseConnection *conn = databaseConnection( connection ); if ( !conn ) return QStringList(); return conn->fields( table );}#endif#ifndef QT_NO_SQLstatic QString makeIndent( int indent ){ QString s; s.fill( ' ', indent * 4 ); return s;}#endif#ifndef QT_NO_SQLstatic void saveSingleProperty( QTextStream &ts, const QString& name, const QString& value, int indent ){ ts << makeIndent( indent ) << "<property name=\"" << name << "\">" << endl; ++indent; ts << makeIndent( indent ) << "<string>" << value << "</string>" << endl; --indent; ts << makeIndent( indent ) << "</property>" << endl;}#endif#ifndef QT_NO_SQLstatic bool inSaveConnections = FALSE;#endifvoid Project::saveConnections(){#ifndef QT_NO_SQL if ( inSaveConnections ) return; inSaveConnections = TRUE; if ( dbFile.isEmpty() ) { QFileInfo fi( fileName() ); setDatabaseDescription( fi.baseName() + ".db" ); } QFile f( makeAbsolute( dbFile ) ); if ( dbConnections.isEmpty() ) { if ( f.exists() ) f.remove(); setDatabaseDescription( "" ); modified = TRUE; save( TRUE ); inSaveConnections = FALSE; return; } save( TRUE ); /* .db xml */ if ( f.open( IO_WriteOnly | IO_Translate ) ) { QTextStream ts( &f ); ts.setCodec( QTextCodec::codecForName( "UTF-8" ) ); ts << "<!DOCTYPE DB><DB version=\"1.0\">" << endl; /* db connections */ int indent = 0; for ( DatabaseConnection *conn = dbConnections.first(); conn; conn = dbConnections.next() ) { ts << makeIndent( indent ) << "<connection>" << endl; ++indent; saveSingleProperty( ts, "name", conn->name(), indent ); saveSingleProperty( ts, "driver", conn->driver(), indent ); saveSingleProperty( ts, "database", conn->database(), indent ); saveSingleProperty( ts, "username", conn->username(), indent ); saveSingleProperty( ts, "hostname", conn->hostname(), indent ); saveSingleProperty( ts, "port", QString::number( conn->port() ), indent ); /* connection tables */ QStringList tables = conn->tables();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -