📄 command.cpp
字号:
} toLasts.pop(); toLasts.push( ni ); if ( pi ) pi->setOpen( TRUE ); } else { if ( i->parent() == fromLast ) { fromParents.push( fromLast ); toParents.push( toLasts.top() ); toLasts.push( 0 ); QListViewItem *pi = toParents.top(); QListViewItem *ni = 0; if ( pi ) ni = new QListViewItem( pi ); else ni = new QListViewItem( to ); for ( int c = 0; c < cols; ++c ) { ni->setText( c, i->text( c ) ); if ( i->pixmap( c ) ) ni->setPixmap( c, *i->pixmap( c ) ); } toLasts.pop(); toLasts.push( ni ); if ( pi ) pi->setOpen( TRUE ); } else { while ( fromParents.top() != i->parent() ) { fromParents.pop(); toParents.pop(); toLasts.pop(); } QListViewItem *pi = toParents.top(); QListViewItem *ni = 0; if ( pi ) ni = new QListViewItem( pi, toLasts.top() ); else ni = new QListViewItem( to, toLasts.top() ); for ( int c = 0; c < cols; ++c ) { ni->setText( c, i->text( c ) ); if ( i->pixmap( c ) ) ni->setPixmap( c, *i->pixmap( c ) ); } if ( pi ) pi->setOpen( TRUE ); toLasts.pop(); toLasts.push( ni ); } } fromLast = i; }}// ------------------------------------------------------------PopulateMultiLineEditCommand::PopulateMultiLineEditCommand( const QString &n, FormWindow *fw, QTextEdit *mle, const QString &txt ) : Command( n, fw ), newText( txt ), mlined( mle ){ oldText = mlined->text(); wasChanged = MetaDataBase::isPropertyChanged( mlined, "text" );}void PopulateMultiLineEditCommand::execute(){ mlined->setText( newText ); MetaDataBase::setPropertyChanged( mlined, "text", TRUE ); formWindow()->emitUpdateProperties( mlined );}void PopulateMultiLineEditCommand::unexecute(){ mlined->setText( oldText ); MetaDataBase::setPropertyChanged( mlined, "text", wasChanged ); formWindow()->emitUpdateProperties( mlined );}// ------------------------------------------------------------PopulateTableCommand::PopulateTableCommand( const QString &n, FormWindow *fw, QTable *t, const QValueList<Row> &rows, const QValueList<Column> &columns ) : Command( n, fw ), newRows( rows ), newColumns( columns ), table( t ){#ifndef QT_NO_TABLE int i = 0; QMap<QString, QString> columnFields = MetaDataBase::columnFields( table ); for ( i = 0; i < table->horizontalHeader()->count(); ++i ) { PopulateTableCommand::Column col; col.text = table->horizontalHeader()->label( i ); if ( table->horizontalHeader()->iconSet( i ) ) col.pix = table->horizontalHeader()->iconSet( i )->pixmap(); col.field = *columnFields.find( col.text ); oldColumns.append( col ); } for ( i = 0; i < table->verticalHeader()->count(); ++i ) { PopulateTableCommand::Row row; row.text = table->verticalHeader()->label( i ); if ( table->verticalHeader()->iconSet( i ) ) row.pix = table->verticalHeader()->iconSet( i )->pixmap(); oldRows.append( row ); }#endif}void PopulateTableCommand::execute(){#ifndef QT_NO_TABLE QMap<QString, QString> columnFields; table->setNumCols( newColumns.count() ); int i = 0; for ( QValueList<Column>::Iterator cit = newColumns.begin(); cit != newColumns.end(); ++cit, ++i ) { table->horizontalHeader()->setLabel( i, (*cit).pix, (*cit).text ); if ( !(*cit).field.isEmpty() ) columnFields.insert( (*cit).text, (*cit).field ); } MetaDataBase::setColumnFields( table, columnFields ); table->setNumRows( newRows.count() ); i = 0; for ( QValueList<Row>::Iterator rit = newRows.begin(); rit != newRows.end(); ++rit, ++i ) table->verticalHeader()->setLabel( i, (*rit).pix, (*rit).text );#endif}void PopulateTableCommand::unexecute(){#ifndef QT_NO_TABLE QMap<QString, QString> columnFields; table->setNumCols( oldColumns.count() ); int i = 0; for ( QValueList<Column>::Iterator cit = oldColumns.begin(); cit != oldColumns.end(); ++cit, ++i ) { table->horizontalHeader()->setLabel( i, (*cit).pix, (*cit).text ); if ( !(*cit).field.isEmpty() ) columnFields.insert( (*cit).text, (*cit).field ); } MetaDataBase::setColumnFields( table, columnFields ); table->setNumRows( oldRows.count() ); i = 0; for ( QValueList<Row>::Iterator rit = oldRows.begin(); rit != oldRows.end(); ++rit, ++i ) table->verticalHeader()->setLabel( i, (*rit).pix, (*rit).text );#endif}// ------------------------------------------------------------AddActionToToolBarCommand::AddActionToToolBarCommand( const QString &n, FormWindow *fw, QAction *a, QDesignerToolBar *tb, int idx ) : Command( n, fw ), action( a ), toolBar( tb ), index( idx ){}void AddActionToToolBarCommand::execute(){ action->addTo( toolBar ); if ( ::qt_cast<QDesignerAction*>(action) ) { QString s = ( (QDesignerAction*)action )->widget()->name(); if ( s.startsWith( "qt_dead_widget_" ) ) { s.remove( 0, QString( "qt_dead_widget_" ).length() ); ( (QDesignerAction*)action )->widget()->setName( s ); } toolBar->insertAction( ( (QDesignerAction*)action )->widget(), action ); ( (QDesignerAction*)action )->widget()->installEventFilter( toolBar ); } else if ( ::qt_cast<QDesignerActionGroup*>(action) ) { if ( ( (QDesignerActionGroup*)action )->usesDropDown() ) { toolBar->insertAction( ( (QDesignerActionGroup*)action )->widget(), action ); ( (QDesignerActionGroup*)action )->widget()->installEventFilter( toolBar ); } } else if ( ::qt_cast<QSeparatorAction*>(action) ) { toolBar->insertAction( ( (QSeparatorAction*)action )->widget(), action ); ( (QSeparatorAction*)action )->widget()->installEventFilter( toolBar ); } if ( !::qt_cast<QActionGroup*>(action) || ( (QActionGroup*)action )->usesDropDown()) { if ( index == -1 ) toolBar->appendAction( action ); else toolBar->insertAction( index, action ); toolBar->reInsert(); QObject::connect( action, SIGNAL( destroyed() ), toolBar, SLOT( actionRemoved() ) ); } else { if ( action->children() ) { QObjectListIt it( *action->children() ); int i = 0; while ( it.current() ) { QObject *o = it.current(); ++it; if ( !::qt_cast<QAction*>(o) ) continue; // ### fix it for nested actiongroups if ( ::qt_cast<QDesignerAction*>(o) ) { QDesignerAction *ac = (QDesignerAction*)o; toolBar->insertAction( ac->widget(), ac ); ac->widget()->installEventFilter( toolBar ); if ( index == -1 ) toolBar->appendAction( ac ); else toolBar->insertAction( index + (i++), ac ); } QObject::connect( o, SIGNAL( destroyed() ), toolBar, SLOT( actionRemoved() ) ); } } toolBar->reInsert(); QObject::connect( action, SIGNAL( destroyed() ), toolBar, SLOT( actionRemoved() ) ); } formWindow()->mainWindow()->objectHierarchy()->rebuild();}void AddActionToToolBarCommand::unexecute(){ if ( ::qt_cast<QDesignerAction*>(action) ) { QString s = ( (QDesignerAction*)action )->widget()->name(); s.prepend( "qt_dead_widget_" ); ( (QDesignerAction*)action )->widget()->setName( s ); } toolBar->removeAction( action ); action->removeFrom( toolBar ); QObject::disconnect( action, SIGNAL( destroyed() ), toolBar, SLOT( actionRemoved() ) ); if ( !::qt_cast<QActionGroup*>(action) || ( (QActionGroup*)action )->usesDropDown()) { action->removeEventFilter( toolBar ); } else { if ( action->children() ) { QObjectListIt it( *action->children() ); while ( it.current() ) { QObject *o = it.current(); ++it; if ( !::qt_cast<QAction*>(o) ) continue; if ( ::qt_cast<QDesignerAction*>(o) ) { o->removeEventFilter( toolBar ); toolBar->removeAction( (QAction*)o ); } QObject::disconnect( o, SIGNAL( destroyed() ), toolBar, SLOT( actionRemoved() ) ); } } } formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------AddToolBarCommand::AddToolBarCommand( const QString &n, FormWindow *fw, QMainWindow *mw ) : Command( n, fw ), toolBar( 0 ), mainWindow( mw ){}void AddToolBarCommand::execute(){ if ( !toolBar ) { toolBar = new QDesignerToolBar( mainWindow ); QString n = "Toolbar"; formWindow()->unify( toolBar, n, TRUE ); toolBar->setName( n ); mainWindow->addToolBar( toolBar, n ); } else { toolBar->show(); QString s = toolBar->name(); s.remove( 0, QString( "qt_dead_widget_" ).length() ); toolBar->setName( s ); } formWindow()->mainWindow()->objectHierarchy()->rebuild();}void AddToolBarCommand::unexecute(){ toolBar->hide(); QString s = toolBar->name(); s.prepend( "qt_dead_widget_" ); toolBar->setName( s ); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------#ifdef QT_CONTAINER_CUSTOM_WIDGETSAddContainerPageCommand::AddContainerPageCommand( const QString &n, FormWindow *fw, QWidget *c, const QString &label ) : Command( n, fw ), container( c ), index( -1 ), pageLabel( label ), page( 0 ){ WidgetInterface *iface = 0; widgetManager()->queryInterface( WidgetFactory::classNameOf( container ), &iface ); if ( !iface ) return; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&wiface ); if ( !wiface ) return; wClassName = WidgetFactory::classNameOf( container );}AddContainerPageCommand::~AddContainerPageCommand(){ if ( wiface ) wiface->release();}void AddContainerPageCommand::execute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; if ( index == -1 ) index = wiface->count( wClassName, container ); if ( !page ) page = wiface->addPage( wClassName, container, pageLabel, index ); else wiface->insertPage( wClassName, container, pageLabel, index, page ); MetaDataBase::addEntry( page ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); // #### show and update pages in object hierarchy view}void AddContainerPageCommand::unexecute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; wiface->removePage( wClassName, container, index ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); // #### show and update pages in object hierarchy view}// ------------------------------------------------------------DeleteContainerPageCommand::DeleteContainerPageCommand( const QString &n, FormWindow *fw, QWidget *c, int idx ) : Command( n, fw ), container( c ), index( idx ){ WidgetInterface *iface = 0; widgetManager()->queryInterface( WidgetFactory::classNameOf( container ), &iface ); if ( !iface ) return; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&wiface ); if ( !wiface ) return; wClassName = WidgetFactory::classNameOf( container ); page = wiface->page( wClassName, container, index ); pageLabel = wiface->pageLabel( wClassName, container, index );}DeleteContainerPageCommand::~DeleteContainerPageCommand(){ if ( wiface ) wiface->release();}void DeleteContainerPageCommand::execute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; wiface->removePage( wClassName, container, index ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); // #### show and update pages in object hierarchy view}void DeleteContainerPageCommand::unexecute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; if ( index == -1 ) index = wiface->count( wClassName, container ); wiface->insertPage( wClassName, container, pageLabel, index, page ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); // #### show and update pages in object hierarchy view}// ------------------------------------------------------------RenameContainerPageCommand::RenameContainerPageCommand( const QString &n, FormWindow *fw, QWidget *c, int idx, const QString &label ) : Command( n, fw ), container( c ), index( idx ), newLabel( label ){ WidgetInterface *iface = 0; widgetManager()->queryInterface( WidgetFactory::classNameOf( container ), &iface ); if ( !iface ) return; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&wiface ); if ( !wiface ) return; wClassName = WidgetFactory::classNameOf( container ); oldLabel = wiface->pageLabel( wClassName, container, index );}RenameContainerPageCommand::~RenameContainerPageCommand(){ if ( wiface ) wiface->release();}void RenameContainerPageCommand::execute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; wiface->renamePage( wClassName, container, index, newLabel ); formWindow()->emitUpdateProperties( formWindow()->currentWidget() ); // #### show and update pages in object hierarchy view}void RenameContainerPageCommand::unexecute(){ if ( !wiface || !wiface->supportsPages( wClassName ) ) return; wiface->renamePage( wClassName, container, index, oldLabel )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -