📄 editfunctionsimpl.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 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 "editfunctionsimpl.h"#include "formwindow.h"#include "metadatabase.h"#include "asciivalidator.h"#include "mainwindow.h"#include "hierarchyview.h"#include "project.h"#include <qlistview.h>#include <qpushbutton.h>#include <qlineedit.h>#include <qcombobox.h>#include <qstrlist.h>#include <qmessagebox.h>#include <qlayout.h>#include <qlabel.h>#include <qgroupbox.h>#include <qheader.h>#include <qcheckbox.h>EditFunctions::EditFunctions( QWidget *parent, FormWindow *fw, bool justSlots ) : EditFunctionsBase( parent, 0, TRUE ), formWindow( fw ){ connect( helpButton, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) ); id = 0; functList.clear(); QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( fw ); for ( QValueList<MetaDataBase::Function>::Iterator it = functionList.begin(); it != functionList.end(); ++it ) { QListViewItem *i = new QListViewItem( functionListView ); i->setPixmap( 0, QPixmap::fromMimeSource( "editslots.png" ) ); i->setText( 0, (*it).function ); i->setText( 1, (*it).returnType ); i->setText( 2, (*it).specifier ); i->setText( 3, (*it).access ); i->setText( 4, (*it).type ); FunctItem fui; fui.id = id; fui.oldName = (*it).function; fui.newName = fui.oldName; fui.oldRetTyp = (*it).returnType; fui.retTyp = fui.oldRetTyp; fui.oldSpec = (*it).specifier; fui.spec = fui.oldSpec; fui.oldAccess = (*it).access; fui.access = fui.oldAccess; fui.oldType = (*it).type; fui.type = fui.oldType; functList.append( fui ); functionIds.insert( i, id ); id++; if ( (*it).type == "slot" ) { if ( MetaDataBase::isSlotUsed( formWindow, MetaDataBase::normalizeFunction( (*it).function ).latin1() ) ) i->setText( 5, tr( "Yes" ) ); else i->setText( 5, tr( "No" ) ); } else { i->setText( 5, "---" ); } } boxProperties->setEnabled( FALSE ); functionName->setValidator( new AsciiValidator( TRUE, functionName ) ); if ( functionListView->firstChild() ) functionListView->setCurrentItem( functionListView->firstChild() ); showOnlySlots->setChecked( justSlots ); lastType = "function"; // Enable rename for all QListViewItems QListViewItemIterator lvit = functionListView->firstChild(); for ( ; *lvit; lvit++ ) (*lvit)->setRenameEnabled( 0, TRUE ); // Connect listview signal to signal-relay QObject::connect( functionListView, SIGNAL( itemRenamed( QListViewItem*, int, const QString & ) ), this, SLOT( emitItemRenamed(QListViewItem*, int, const QString&) ) ); // Connect signal-relay to QLineEdit "functionName" QObjectList *l = parent->queryList( "QLineEdit", "functionName" ); QObject *obj; QObjectListIt itemsLineEditIt( *l ); while ( (obj = itemsLineEditIt.current()) != 0 ) { ++itemsLineEditIt; QObject::connect( this, SIGNAL( itemRenamed( const QString & ) ), obj, SLOT( setText( const QString & ) ) ); } delete l;}void EditFunctions::okClicked(){ QValueList<MetaDataBase::Function> functionList = MetaDataBase::functionList( formWindow ); QString n = tr( "Add/Remove functions of '%1'" ).arg( formWindow->name() ); QPtrList<Command> commands; QValueList<MetaDataBase::Function>::Iterator fit; if ( !functionList.isEmpty() ) { for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) { bool functionFound = FALSE; QValueList<FunctItem>::Iterator it = functList.begin(); for ( ; it != functList.end(); ++it ) { if ( MetaDataBase::normalizeFunction( (*it).oldName ) == MetaDataBase::normalizeFunction( (*fit).function ) ) { functionFound = TRUE; break; } } if ( !functionFound ) commands.append( new RemoveFunctionCommand( tr( "Remove function" ), formWindow, (*fit).function, (*fit).specifier, (*fit).access, (*fit).type, formWindow->project()->language(), (*fit).returnType ) ); } } bool invalidFunctions = FALSE; QValueList<FunctItem> invalidItems; if ( !functList.isEmpty() ) { QStrList lst; QValueList<FunctItem>::Iterator it = functList.begin(); for ( ; it != functList.end(); ++it ) { MetaDataBase::Function function; function.function = (*it).newName; function.returnType = (*it).retTyp; function.specifier = (*it).spec; function.access = (*it).access; function.type = (*it).type; function.language = formWindow->project()->language(); if ( function.returnType.isEmpty() ) function.returnType = "void"; QString s = function.function; s = s.simplifyWhiteSpace(); bool startNum = s[ 0 ] >= '0' && s[ 0 ] <= '9'; bool noParens = s.contains( '(' ) != 1 || s.contains( ')' ) != 1; bool illegalSpace = s.find( ' ' ) != -1 && s.find( ' ' ) < s.find( '(' ); if ( startNum || noParens || illegalSpace || lst.find( function.function ) != -1 ) { invalidFunctions = TRUE; invalidItems.append( (*it) ); continue; } bool functionFound = FALSE; for ( fit = functionList.begin(); fit != functionList.end(); ++fit ) { if ( MetaDataBase::normalizeFunction( (*fit).function ) == MetaDataBase::normalizeFunction( (*it).oldName ) ) { functionFound = TRUE; break; } } if ( !functionFound ) commands.append( new AddFunctionCommand( tr( "Add function" ), formWindow, function.function, function.specifier, function.access, function.type, formWindow->project()->language(), function.returnType ) ); if ( MetaDataBase::normalizeFunction( (*it).newName ) != MetaDataBase::normalizeFunction( (*it).oldName ) || (*it).spec != (*it).oldSpec || (*it).access != (*it).oldAccess || (*it).type != (*it).oldType || (*it).retTyp != (*it).oldRetTyp ) commands.append( new ChangeFunctionAttribCommand( tr( "Change function attributes" ), formWindow, function, MetaDataBase::normalizeFunction( (*it).oldName ), (*it).oldSpec, (*it).oldAccess, (*it).oldType, formWindow->project()->language(), (*it).oldRetTyp ) ); lst.append( function.function ); } } if ( invalidFunctions ) { if ( QMessageBox::information( this, tr( "Edit Functions" ), tr( "Some syntactically incorrect functions have been defined.\n" "Remove these functions?" ), tr( "&Yes" ), tr( "&No" ) ) == 0 ) { QValueList<FunctItem>::Iterator it = functList.begin(); while ( it != functList.end() ) { bool found = FALSE; QValueList<FunctItem>::Iterator vit = invalidItems.begin(); for ( ; vit != invalidItems.end(); ++vit ) { if ( (*vit).newName == (*it).newName ) { invalidItems.remove( vit ); found = TRUE; break; } } if ( found ) { int delId = (*it).id; it = functList.remove( it ); QMap<QListViewItem*, int>::Iterator fit = functionIds.begin(); while ( fit != functionIds.end() ) { if ( *fit == delId ) { QListViewItem *litem = fit.key(); functionIds.remove( fit ); delete litem; if ( functionListView->currentItem() ) functionListView->setSelected( functionListView->currentItem(), TRUE ); currentItemChanged( functionListView->currentItem() ); break; } ++fit; } } else ++it; } if ( functionListView->firstChild() ) { functionListView->setCurrentItem( functionListView->firstChild() ); functionListView->setSelected( functionListView->firstChild(), TRUE ); } } formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView(); return; } if ( !commands.isEmpty() ) { MacroCommand *cmd = new MacroCommand( n, formWindow, commands ); formWindow->commandHistory()->addCommand( cmd ); cmd->execute(); } formWindow->mainWindow()->objectHierarchy()->updateFormDefinitionView(); accept();}void EditFunctions::functionAdd( const QString &access, const QString &type ){ QListViewItem *i = new QListViewItem( functionListView ); i->setPixmap( 0, QPixmap::fromMimeSource( "editslots.png" ) ); i->setRenameEnabled( 0, TRUE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -