📄 project.cpp
字号:
for ( QStringList::Iterator it = tables.begin(); it != tables.end(); ++it ) { ts << makeIndent( indent ) << "<table>" << endl; ++indent; saveSingleProperty( ts, "name", (*it), indent ); /* tables fields */ QStringList fields = conn->fields( *it ); for ( QStringList::Iterator it2 = fields.begin(); it2 != fields.end(); ++it2 ) { ts << makeIndent( indent ) << "<field>" << endl; ++indent; saveSingleProperty( ts, "name", (*it2), indent ); --indent; ts << makeIndent( indent ) << "</field>" << endl; } --indent; ts << makeIndent( indent ) << "</table>" << endl; } --indent; ts << makeIndent( indent ) << "</connection>" << endl; } ts << "</DB>" << endl; f.close(); } inSaveConnections = FALSE;#endif}#ifndef QT_NO_SQLstatic QDomElement loadSingleProperty( QDomElement e, const QString& name ){ QDomElement n; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "property" && n.toElement().attribute("name") == name ) return n; } return n;}#endifvoid Project::loadConnections(){#ifndef QT_NO_SQL if ( dbFile.isEmpty() || !QFile::exists( makeAbsolute( dbFile ) ) ) return; QFile f( makeAbsolute( dbFile ) ); if ( f.open( IO_ReadOnly ) ) { QDomDocument doc; QString errMsg; int errLine; if ( doc.setContent( &f, &errMsg, &errLine ) ) { QDomElement e; e = doc.firstChild().toElement(); /* connections */ QDomNodeList connections = e.toElement().elementsByTagName( "connection" ); for ( uint i = 0; i < connections.length(); i++ ) { QDomElement connection = connections.item(i).toElement(); QDomElement connectionName = loadSingleProperty( connection, "name" ); QDomElement connectionDriver = loadSingleProperty( connection, "driver" ); QDomElement connectionDatabase = loadSingleProperty( connection, "database" ); QDomElement connectionUsername = loadSingleProperty( connection, "username" ); QDomElement connectionHostname = loadSingleProperty( connection, "hostname" ); QDomElement connectionPort = loadSingleProperty( connection, "port" ); DatabaseConnection *conn = new DatabaseConnection( this ); conn->setName( connectionName.firstChild().firstChild().toText().data() ); conn->setDriver( connectionDriver.firstChild().firstChild().toText().data() ); conn->setDatabase( connectionDatabase.firstChild().firstChild().toText().data() ); conn->setUsername( connectionUsername.firstChild().firstChild().toText().data() ); conn->setHostname( connectionHostname.firstChild().firstChild().toText().data() ); conn->setPort( QString( connectionPort.firstChild().firstChild().toText().data() ).toInt() ); /* connection tables */ QDomNodeList tables = connection.toElement().elementsByTagName( "table" ); for ( uint j = 0; j < tables.length(); j++ ) { QDomElement table = tables.item(j).toElement(); QDomElement tableName = loadSingleProperty( table, "name" ); conn->addTable( tableName.firstChild().firstChild().toText().data() ); /* table fields */ QStringList fieldList; QDomNodeList fields = table.toElement().elementsByTagName( "field" ); for ( uint k = 0; k < fields.length(); k++ ) { QDomElement field = fields.item(k).toElement(); QDomElement fieldName = loadSingleProperty( field, "name" ); fieldList.append( fieldName.firstChild().firstChild().toText().data() ); } conn->setFields( tableName.firstChild().firstChild().toText().data(), fieldList ); } dbConnections.append( conn ); } } else { qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine ); } f.close(); }#endif}/*! Opens the database \a connection. The connection remains open andcan be closed again with closeDatabase().*/bool Project::openDatabase( const QString &connection, bool suppressDialog ){#ifndef QT_NO_SQL DatabaseConnection *conn = databaseConnection( connection ); if ( connection.isEmpty() && !conn ) conn = databaseConnection( "(default)" ); if ( !conn ) return FALSE; bool b = conn->open( suppressDialog ); return b;#else Q_UNUSED( connection ); Q_UNUSED( suppressDialog ); return FALSE;#endif}/*! Closes the database \a connection.*/void Project::closeDatabase( const QString &connection ){#ifndef QT_NO_SQL DatabaseConnection *conn = databaseConnection( connection ); if ( connection.isEmpty() && !conn ) conn = databaseConnection( "(default)" ); if ( !conn ) return; conn->close();#else Q_UNUSED( connection );#endif}// void Project::formClosed( FormWindow *fw )// {// formWindows.remove( fw );// }QObjectList *Project::formList( bool resolveFakeObjects ) const{ QObjectList *l = new QObjectList; for ( QPtrListIterator<FormFile> forms(formfiles); forms.current(); ++forms ) { FormFile* f = forms.current(); if ( f->formWindow() ) { if ( resolveFakeObjects && f->formWindow()->isFake() ) l->append( objectForFakeForm( f->formWindow() ) ); else l->append( f->formWindow()->child( 0, "QWidget" ) ); } else if ( f->isFake() ) { l->append( objectForFakeFormFile( f ) ); } } return l;}DesignerProject *Project::iFace(){ if ( !iface ) iface = new DesignerProjectImpl( this ); return iface;}void Project::setLanguage( const QString &l ){ if ( l == lang ) return; lang = l; is_cpp = lang == "C++"; updateCustomSettings(); modified = TRUE;}QString Project::language() const{ return lang;}void Project::setCustomSetting( const QString &key, const QString &value ){ customSettings.remove( key ); customSettings.insert( key, value ); modified = TRUE;}QString Project::customSetting( const QString &key ) const{ return *customSettings.find( key );}void Project::updateCustomSettings(){ if ( !projectSettingsPluginManager ) return;/* ProjectSettingsInterface *iface = 0; projectSettingsPluginManager->queryInterface( lang, (QUnknownInterface**)&iface ); if ( !iface ) return; csList = iface->projectSettings(); iface->release();*/ QInterfacePtr<ProjectSettingsInterface> iface; projectSettingsPluginManager->queryInterface( lang, &iface ); if ( !iface ) return; csList = iface->projectSettings(); customSettings.clear();}void Project::setActive( bool b ){ pixCollection->setActive( b );}void Project::addSourceFile( SourceFile *sf ){ sourcefiles.append( sf ); modified = TRUE; emit sourceFileAdded( sf );}SourceFile* Project::findSourceFile( const QString& filename, SourceFile *ignore ) const{ QPtrListIterator<SourceFile> it(sourcefiles); while ( it.current() ) { if ( it.current() != ignore && it.current()->fileName() == filename ) return it.current(); ++it; } return 0;}FormFile* Project::findFormFile( const QString& filename, FormFile *ignore ) const{ QPtrListIterator<FormFile> it(formfiles); while ( it.current() ) { if ( it.current() != ignore && it.current()->fileName() == filename ) return it.current(); ++it; } return 0;}void Project::setIncludePath( const QString &platform, const QString &path ){ if ( inclPath[platform] == path ) return; inclPath.replace( platform, path ); modified = TRUE;}void Project::setLibs( const QString &platform, const QString &path ){ lbs.replace( platform, path );}void Project::setDefines( const QString &platform, const QString &path ){ defs.replace( platform, path );}void Project::setConfig( const QString &platform, const QString &config ){ cfg.replace( platform, config );}QString Project::config( const QString &platform ) const{ return cfg[ platform ];}QString Project::libs( const QString &platform ) const{ return lbs[ platform ];}QString Project::defines( const QString &platform ) const{ return defs[ platform ];}QString Project::includePath( const QString &platform ) const{ return inclPath[ platform ];}QString Project::templte() const{ return templ;}void Project::setTemplate( const QString &t ){ templ = t;}void Project::readPlatformSettings( const QString &contents, const QString &setting, QMap<QString, QString> &res ){ const QString platforms[] = { "", "win32", "unix", "mac", QString::null }; for ( int i = 0; platforms[ i ] != QString::null; ++i ) { QString p = platforms[ i ]; if ( !p.isEmpty() ) p += ":"; QStringList lst = parse_multiline_part( contents, p + setting ); QString s = lst.join( " " ); QString key = platforms[ i ]; if ( key.isEmpty() ) key = "(all)"; res.replace( key, s ); }}void Project::removePlatformSettings( QString &contents, const QString &setting ){ const QString platforms[] = { "win32", "unix", "mac", "", QString::null }; for ( int i = 0; platforms[ i ] != QString::null; ++i ) { QString p = platforms[ i ]; if ( !p.isEmpty() ) p += ":"; remove_multiline_contents( contents, p + setting ); }}void Project::writePlatformSettings( QString &contents, const QString &setting, const QMap<QString, QString> &input ){ const QString platforms[] = { "", "win32", "unix", "mac", QString::null }; for ( int i = 0; platforms[ i ] != QString::null; ++i ) { QString p = platforms[ i ]; if ( !p.isEmpty() ) p += ":"; QString key = platforms[ i ]; if ( key.isEmpty() ) key = "(all)"; QMap<QString, QString>::ConstIterator it = input.find( key ); if ( it == input.end() || (*it).isEmpty() ) continue; contents += p + setting + "\t+= " + *it + "\n"; }}void Project::addFormFile( FormFile *ff ){ formfiles.append( ff ); modified = TRUE; emit formFileAdded( ff );}bool Project::removeFormFile( FormFile *ff ){ if ( !formfiles.containsRef( ff ) ) return FALSE; if ( !ff->close() ) return FALSE; formfiles.removeRef( ff ); modified = TRUE; emit formFileRemoved( ff ); return TRUE;}void Project::addObject( QObject *o ){ bool wasModified = modified; objs.append( o ); FormFile *ff = new FormFile( "", FALSE, this, "qt_fakewindow" ); ff->setFileName( "__APPOBJ" + QString( o->name() ) + ".ui" ); fakeFormFiles.insert( (void*)o, ff ); MetaDataBase::addEntry( o ); if ( hasGUI() ) { QWidget *parent = MainWindow::self ? MainWindow::self->qWorkspace() : 0; FormWindow *fw = new FormWindow( ff, MainWindow::self, parent, "qt_fakewindow" ); fw->setProject( this ); if ( QFile::exists( ff->absFileName() ) ) Resource::loadExtraSource( ff, ff->absFileName(), MetaDataBase::languageInterface( language() ), FALSE ); if ( MainWindow::self ) fw->setMainWindow( MainWindow::self ); if ( MainWindow::self ) { QApplication::sendPostedEvents( MainWindow::self->qWorkspace(), QEvent::ChildInserted ); connect( fw, SIGNAL( undoRedoChanged( bool, bool, const QString &, const QString & ) ), MainWindow::self, SLOT( updateUndoRedo( bool, bool, const QString &, const QString & ) ) ); } if ( fw->parentWidget() ) { fw->parentWidget()->setFixedSize( 1, 1 ); fw->show(); } } else { if ( QFile::exists( ff->absFileName() ) ) Resource::loadExtraSource( ff, ff->absFileName(), MetaDataBase::languageInterface( language() ), FALSE ); } emit objectAdded( o ); modified = wasModified;}void Project::setObjects( const QObjectList &ol ){ for ( QObjectListIt it( ol ); it.current(); ++it ) addObject( it.current() );}void Project::removeObject( QObject *o ){ bool wasModified = modified; objs.removeRef( o ); MetaDataBase::removeEntry( o ); fakeFormFiles.remove( (void*)o ); emit objectRemoved( o ); modified = wasModified;}QObjectList Project::objects() const{ return objs;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -