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

📄 formfile.cpp

📁 Linux下的基于X11的图形开发环境。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return FALSE;	    createFormCode();	}	setModified( TRUE );    }    codeFileStat = FormFile::Ok;    return TRUE;}SourceEditor *FormFile::showEditor( bool askForUih ){    if ( !MainWindow::self )	return 0;    showFormWindow();    if ( !setupUihFile( askForUih ) )	return 0;    SourceEditor *e = MainWindow::self->openSourceEdior();    return e;}static int ui_counter = 0;QString FormFile::createUnnamedFileName(){    return QString( "unnamed" ) + QString::number( ++ui_counter ) + QString( ".ui" );}QString FormFile::codeExtension() const{    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( iface )	return iface->formCodeExtension();    return "";}QString FormFile::codeComment() const{    return QString( "/****************************************************************************\n"    "** ui.h extension file, included from the uic-generated form implementation.\n"    "**\n"    "** If you wish to add, delete or rename functions or slots use\n"    "** Qt Designer which will update this file, preserving your code. Create an\n"    "** init() function in place of a constructor, and a destroy() function in\n"    "** place of a destructor.\n"    "*****************************************************************************/\n" );}bool FormFile::hasFormCode() const{    return !cod.isEmpty() && cod != QString( codeComment() );}int FormFile::codeFileState() const{    return codeFileStat;}void FormFile::setCodeFileState( UihState s ){    codeFileStat = s;}void FormFile::createFormCode(){    if ( !formWindow() )	return;    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( !iface )	return;    if ( pro->isCpp() )	cod = codeComment();    QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( formWindow() );    for ( QValueList<MetaDataBase::Function>::Iterator it = functionList.begin(); it != functionList.end(); ++it ) {	cod += (!cod.isEmpty() ? "\n\n" : "") +	       iface->createFunctionStart( formWindow()->name(), make_func_pretty((*it).function),					   (*it).returnType.isEmpty() ?					   QString( "void" ) :					   (*it).returnType, (*it).access ) +	       "\n" + iface->createEmptyFunction();    }    parseCode( cod, FALSE );}void FormFile::load(){    showFormWindow();    code();}bool FormFile::loadCode(){    QFile f( pro->makeAbsolute( codeFile() ) );    if ( !f.open( IO_ReadOnly ) ) {	cod = "";	setCodeFileState( FormFile::None );	return FALSE;    }    QTextStream ts( &f );    cod = ts.read();    parseCode( cod, FALSE );    if ( hasFormCode() && codeFileStat != FormFile::Ok )	    setCodeFileState( FormFile::Deleted );    timeStamp.update();    return TRUE;}bool FormFile::isCodeEdited() const{    return codeEdited;}void FormFile::setCodeEdited( bool b ){    codeEdited = b;}void FormFile::parseCode( const QString &txt, bool allowModify ){    if ( !formWindow() )	return;    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( !iface )	return;    QValueList<LanguageInterface::Function> functions;    QValueList<MetaDataBase::Function> newFunctions, oldFunctions;    oldFunctions = MetaDataBase::functionList( formWindow() );    iface->functions( txt, &functions );    QMap<QString, QString> funcs;    for ( QValueList<LanguageInterface::Function>::Iterator it = functions.begin();	  it != functions.end(); ++it ) {	bool found = FALSE;	for ( QValueList<MetaDataBase::Function>::Iterator fit = oldFunctions.begin();	      fit != oldFunctions.end(); ++fit ) {	    QString f( (*fit).function );	    if ( MetaDataBase::normalizeFunction( f ) ==		 MetaDataBase::normalizeFunction( (*it).name ) ) {		found = TRUE;		MetaDataBase::Function function;		function.function = make_func_pretty( (*it).name );		function.specifier = (*fit).specifier;		function.type = (*fit).type;		if ( !pro->isCpp() )		    function.access = (*it).access;		else		    function.access = (*fit).access;		function.language = (*fit).language;		function.returnType = (*it).returnType;		newFunctions << function;		funcs.insert( (*it).name, (*it).body );		oldFunctions.remove( fit );		break;	    }	}	if ( !found ) {	    MetaDataBase::Function function;	    function.function = make_func_pretty( (*it).name );	    function.specifier = "virtual";	    function.access = "public";	    function.language = pro->language();	    function.returnType = (*it).returnType;	    if ( function.returnType == "void" )		function.type = "slot";	    else		function.type = "function";	    if ( function.function == "init()" || function.function == "destroy()" ) {		function.type = "function";		function.access = "private";		function.specifier = "non virtual";	    }	    newFunctions << function;	    funcs.insert( (*it).name, (*it).body );	    if ( allowModify )		setFormWindowModified( TRUE );	}    }    if ( allowModify && oldFunctions.count() > 0 )	setFormWindowModified( TRUE );    MetaDataBase::setFunctionList( formWindow(), newFunctions );}void FormFile::syncCode(){    if ( !editor() )	return;    parseCode( editor()->editorInterface()->text(), TRUE );    cod = editor()->editorInterface()->text();}void FormFile::checkTimeStamp(){    if ( timeStamp.isUpToDate() )	return;    timeStamp.update();    if ( codeEdited ) {	if ( QMessageBox::information( MainWindow::self, tr( "Qt Designer" ),				       tr( "File '%1' has been changed outside Qt Designer.\n"					   "Do you want to reload it?" ).arg( timeStamp.fileName() ),				       tr( "&Yes" ), tr( "&No" ) ) == 0 ) {	    QFile f( timeStamp.fileName() );	    if ( f.open( IO_ReadOnly ) ) {		QTextStream ts( &f );		editor()->editorInterface()->setText( ts.read() );		editor()->save();		if ( MainWindow::self )		    MainWindow::self->functionsChanged();	    }	}    } else {	loadCode();    }}void FormFile::addFunctionCode( MetaDataBase::Function function ){    if ( pro->isCpp() && !hasFormCode() && !codeEdited )	return;    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( !iface )	return;    QValueList<LanguageInterface::Function> funcs;    iface->functions( cod, &funcs );    bool hasFunc = FALSE;    for ( QValueList<LanguageInterface::Function>::Iterator it = funcs.begin();	  it != funcs.end(); ++it ) {	if ( MetaDataBase::normalizeFunction( (*it).name ) == MetaDataBase::normalizeFunction( function.function ) ) {	    hasFunc = TRUE;	    break;	}    }    if ( !hasFunc ) {	if ( !codeEdited && !timeStamp.isUpToDate() )	    loadCode();	MetaDataBase::MetaInfo mi = MetaDataBase::metaInfo( formWindow() );	QString cn;	if ( mi.classNameChanged )	    cn = mi.className;	if ( cn.isEmpty() )	    cn = formWindow()->name();	QString body = "\n\n" + iface->createFunctionStart( cn,							    make_func_pretty( function.function ),							    function.returnType.isEmpty() ?							    QString( "void" ) :							    function.returnType, function.access ) +		       "\n" + iface->createEmptyFunction();	cod += body;	if ( codeEdited ) {	    setModified( TRUE );	    emit somethingChanged( this );	}    }}void FormFile::removeFunctionCode( MetaDataBase::Function function ){    if ( pro->isCpp() && !hasFormCode() && !codeEdited )	return;    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( !iface )	return;    checkTimeStamp();    QString sourceCode = code();    if ( sourceCode.isEmpty() )	return;    QValueList<LanguageInterface::Function> functions;    iface->functions( sourceCode, &functions );    QString fu = MetaDataBase::normalizeFunction( function.function );    for ( QValueList<LanguageInterface::Function>::Iterator fit = functions.begin(); fit != functions.end(); ++fit ) {	if ( MetaDataBase::normalizeFunction( (*fit).name ) == fu ) {	    int line = 0;	    int start = 0;	    while ( line < (*fit).start - 1 ) {		start = sourceCode.find( '\n', start );		if ( start == -1 )		    return;		start++;		line++;	    }	    if ( start == -1 )	        return;	    int end = start;	    while ( line < (*fit).end + 1 ) {		end = sourceCode.find( '\n', end );		if ( end == -1 ) {		    if ( line <= (*fit).end )			end = sourceCode.length() - 1;		    else		        return;		}		end++;		line++;	    }	    if ( end < start )		return;	    sourceCode.remove( start, end - start );	    setCode( sourceCode );	}    }}void FormFile::functionNameChanged( const QString &oldName, const QString &newName ){    if ( !cod.isEmpty() ) {	QString funcStart = QString( formWindow()->name() ) + QString( "::" );	int i = cod.find( funcStart + oldName );	if ( i != -1 ) {	    cod.remove( i + funcStart.length(), oldName.length() );	    cod.insert( i + funcStart.length(), newName );	}    }}void FormFile::functionRetTypeChanged( const QString &fuName, const QString &oldType, const QString &newType ){    if ( !cod.isEmpty() ) {	QString oldFunct = oldType + " " + QString( formWindow()->name() ) + "::" + fuName;	QString newFunct = newType + " " + QString( formWindow()->name() ) + "::" + fuName;	int i = cod.find( oldFunct );	if ( i != -1 ) {	    cod.remove( i, oldFunct.length() );	    cod.insert( i, newFunct );	}    }}QString FormFile::formName() const{    FormFile* that = (FormFile*) this;    if ( formWindow() ) {	that->cachedFormName = formWindow()->name();	return cachedFormName;    }    if ( !cachedFormName.isNull() )	return cachedFormName;    QFile f( pro->makeAbsolute( filename ) );    if ( f.open( IO_ReadOnly ) ) {	QTextStream ts( &f );	QString line;	QString className;	while ( !ts.eof() ) {	    line = ts.readLine();	    if ( !className.isEmpty() ) {		int end = line.find( "</class>" );		if ( end == -1 ) {		    className += line;		} else {		    className += line.left( end );		    break;		}		continue;	    }	    int start;	    if ( ( start = line.find( "<class>" ) ) != -1 ) {		int end = line.find( "</class>" );		if ( end == -1 ) {		    className = line.mid( start + 7 );		} else {		    className = line.mid( start + 7, end - ( start + 7 ) );		    break;		}	    }	}	that->cachedFormName =  className;    }    if ( cachedFormName.isEmpty() )	that->cachedFormName = filename;    return cachedFormName;}void FormFile::formWindowChangedSomehow(){    emit somethingChanged( this );}bool FormFile::checkFileName( bool allowBreak ){    FormFile *ff = pro->findFormFile( filename, this );    if ( ff )	QMessageBox::warning( MainWindow::self, tr( "Invalid Filename" ),			      tr( "The project already contains a form with a\n"				  "filename of '%1'. Please choose a new filename." ).arg( filename ) );    while ( ff ) {	QString fn;	while ( fn.isEmpty() ) {	    fn = QFileDialog::getSaveFileName( pro->makeAbsolute( fileName() ),					       tr( "Qt User-Interface Files (*.ui)" ) + ";;" +					       tr( "All Files (*)" ), MainWindow::self, 0,					       tr( "Save Form '%1' As ...").					       arg( formWindow()->name() ),					       MainWindow::self ? &MainWindow::self->lastSaveFilter : 0 );	    if ( allowBreak && fn.isEmpty() )		return FALSE;	}	filename = pro->makeRelative( fn );	ff = pro->findFormFile( filename, this );     }    return TRUE;}void FormFile::addConnection( const QString &sender, const QString &signal,			      const QString &receiver, const QString &slot ){    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( iface )	iface->addConnection( sender, signal, receiver, slot, &cod );    if ( ed )	ed->editorInterface()->setText( cod );}void FormFile::removeConnection( const QString &sender, const QString &signal,				 const QString &receiver, const QString &slot ){    LanguageInterface *iface = MetaDataBase::languageInterface( pro->language() );    if ( iface )	iface->removeConnection( sender, signal, receiver, slot, &cod );    if ( ed )	ed->editorInterface()->setText( cod );}void FormFile::notifyFormWindowChange(){    if ( fw )	pro->formOpened( fw );}

⌨️ 快捷键说明

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