📄 command.cpp
字号:
void DeleteCommand::unexecute(){ formWindow()->setPropertyShowingBlocked( TRUE ); formWindow()->clearSelection( FALSE ); for ( QWidget *w = widgets.first(); w; w = widgets.next() ) { w->show(); QString s = w->name(); s.remove( 0, QString( "qt_dead_widget_" ).length() ); w->setName( s ); formWindow()->widgets()->insert( w, w ); formWindow()->selectWidget( w ); QValueList<MetaDataBase::Connection> conns = *connections.find( w ); QValueList<MetaDataBase::Connection>::Iterator it = conns.begin(); for ( ; it != conns.end(); ++it ) { MetaDataBase::addConnection( formWindow(), (*it).sender, (*it).signal, (*it).receiver, (*it).slot ); } } formWindow()->setPropertyShowingBlocked( FALSE ); formWindow()->emitShowProperties(); formWindow()->mainWindow()->objectHierarchy()->widgetsInserted( widgets );}// ------------------------------------------------------------SetPropertyCommand::SetPropertyCommand( const QString &n, FormWindow *fw, QObject *w, PropertyEditor *e, const QString &pn, const QVariant &ov, const QVariant &nv, const QString &ncut, const QString &ocut, bool reset ) : Command( n, fw ), widget( w ), editor( e ), propName( pn ), oldValue( ov ), newValue( nv ), oldCurrentItemText( ocut ), newCurrentItemText( ncut ), wasChanged( TRUE ), isResetCommand( reset ){ wasChanged = MetaDataBase::isPropertyChanged( w, propName ); if ( oldCurrentItemText.isNull() ) oldCurrentItemText = ""; if ( newCurrentItemText.isNull() ) newCurrentItemText = "";}void SetPropertyCommand::execute(){ if ( !wasChanged ) MetaDataBase::setPropertyChanged( widget, propName, TRUE ); if ( isResetCommand ) { MetaDataBase::setPropertyChanged( widget, propName, FALSE ); if ( WidgetFactory::resetProperty( widget, propName ) ) { if ( !formWindow()->isWidgetSelected( widget ) && formWindow() != (QObject *)widget ) formWindow()->selectWidget( (QObject *)widget ); if ( editor->widget() != widget ) editor->setWidget( widget, formWindow() ); editor->propertyList()->setCurrentProperty( propName ); PropertyItem *i = (PropertyItem*)editor->propertyList()->currentItem(); if ( !i ) return; i->setValue( widget->property( propName ) ); i->setChanged( FALSE ); editor->refetchData(); editor->emitWidgetChanged(); return; } } setProperty( newValue, newCurrentItemText );}void SetPropertyCommand::unexecute(){ if ( !wasChanged ) MetaDataBase::setPropertyChanged( widget, propName, FALSE ); if ( isResetCommand ) MetaDataBase::setPropertyChanged( widget, propName, TRUE ); setProperty( oldValue, oldCurrentItemText );}bool SetPropertyCommand::canMerge( Command *c ){ SetPropertyCommand *cmd = (SetPropertyCommand*)c; if ( !widget ) return FALSE; const QMetaProperty *p = widget->metaObject()->property( widget->metaObject()->findProperty( propName, TRUE ), TRUE ); if ( !p ) { if ( propName == "toolTip" || propName == "whatsThis" ) return TRUE; if ( ::qt_cast<CustomWidget*>((QObject *)widget) ) { MetaDataBase::CustomWidget *cw = ((CustomWidget*)(QObject*)widget)->customWidget(); if ( !cw ) return FALSE; for ( QValueList<MetaDataBase::Property>::Iterator it = cw->lstProperties.begin(); it != cw->lstProperties.end(); ++it ) { if ( QString( (*it ).property ) == propName ) { if ( (*it).type == "String" || (*it).type == "CString" || (*it).type == "Int" || (*it).type == "UInt" ) return TRUE; } } } return FALSE; } QVariant::Type t = QVariant::nameToType( p->type() ); return ( cmd->propName == propName && t == QVariant::String || t == QVariant::CString || t == QVariant::Int || t == QVariant::UInt );}void SetPropertyCommand::merge( Command *c ){ SetPropertyCommand *cmd = (SetPropertyCommand*)c; newValue = cmd->newValue; newCurrentItemText = cmd->newCurrentItemText;}bool SetPropertyCommand::checkProperty(){ if ( propName == "name" /*|| propName == "itemName"*/ ) { // ### fix that QString s = newValue.toString(); if ( !formWindow()->unify( widget, s, FALSE ) ) { QMessageBox::information( formWindow()->mainWindow(), FormWindow::tr( "Set 'name' property" ), FormWindow::tr( "The name of a widget must be unique.\n" "'%1' is already used in form '%2',\n" "so the name has been reverted to '%3'." ). arg( newValue.toString() ). arg( formWindow()->name() ). arg( oldValue.toString() )); setProperty( oldValue, oldCurrentItemText, FALSE ); return FALSE; } if ( s.isEmpty() ) { QMessageBox::information( formWindow()->mainWindow(), FormWindow::tr( "Set 'name' property" ), FormWindow::tr( "The name of a widget must not be null.\n" "The name has been reverted to '%1'." ). arg( oldValue.toString() )); setProperty( oldValue, oldCurrentItemText, FALSE ); return FALSE; } if ( ::qt_cast<FormWindow*>(widget->parent()) ) formWindow()->mainWindow()->formNameChanged( (FormWindow*)((QWidget*)(QObject*)widget)->parentWidget() ); } return TRUE;}void SetPropertyCommand::setProperty( const QVariant &v, const QString ¤tItemText, bool select ){ if ( !widget ) return; if ( !formWindow()->isWidgetSelected( widget ) && !formWindow()->isMainContainer( widget ) && select ) formWindow()->selectWidget( widget ); if ( editor->widget() != widget && select ) editor->setWidget( widget, formWindow() ); if ( select ) editor->propertyList()->setCurrentProperty( propName ); const QMetaProperty *p = widget->metaObject()->property( widget->metaObject()->findProperty( propName, TRUE ), TRUE ); if ( !p ) { if ( propName == "hAlign" ) { p = widget->metaObject()->property( widget->metaObject()->findProperty( "alignment", TRUE ), TRUE ); int align = widget->property( "alignment" ).toInt(); align &= ~( AlignHorizontal_Mask ); align |= p->keyToValue( currentItemText ); widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "vAlign" ) { p = widget->metaObject()->property( widget->metaObject()->findProperty( "alignment", TRUE ), TRUE ); int align = widget->property( "alignment" ).toInt(); align &= ~( AlignVertical_Mask ); align |= p->keyToValue( currentItemText ); widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "wordwrap" ) { int align = widget->property( "alignment" ).toInt(); align &= ~WordBreak; if ( v.toBool() ) align |= WordBreak; widget->setProperty( "alignment", QVariant( align ) ); } else if ( propName == "layoutSpacing" ) { QVariant val = v; if ( val.toString() == "default" ) val = -1; MetaDataBase::setSpacing( WidgetFactory::containerOfWidget( (QWidget*)editor->widget() ), val.toInt() ); } else if ( propName == "layoutMargin" ) { QVariant val = v; if ( val.toString() == "default" ) val = -1; MetaDataBase::setMargin( WidgetFactory::containerOfWidget( (QWidget*)editor->widget() ), val.toInt() ); } else if ( propName == "resizeMode" ) { MetaDataBase::setResizeMode( WidgetFactory::containerOfWidget( (QWidget*)editor->widget() ), currentItemText ); } else if ( propName == "toolTip" || propName == "whatsThis" || propName == "database" || propName == "frameworkCode" ) { MetaDataBase::setFakeProperty( editor->widget(), propName, v ); } else if ( ::qt_cast<CustomWidget*>(editor->widget()) ) { MetaDataBase::CustomWidget *cw = ((CustomWidget *)(QObject *)widget)->customWidget(); if ( cw ) { MetaDataBase::setFakeProperty( editor->widget(), propName, v ); } } editor->refetchData(); editor->emitWidgetChanged(); ( ( PropertyItem* )editor->propertyList()->currentItem() )->setChanged( MetaDataBase::isPropertyChanged( widget, propName ) );#ifndef QT_NO_SQL if ( propName == "database" ) { formWindow()->mainWindow()->objectHierarchy()->databasePropertyChanged( (QWidget*)((QObject *)widget), MetaDataBase::fakeProperty( widget, "database" ).toStringList() ); }#endif return; } if ( p->isSetType() ) { QStrList strlst; QStringList lst = QStringList::split( "|", currentItemText ); QValueListConstIterator<QString> it = lst.begin(); for ( ; it != lst.end(); ++it ) strlst.append( (*it).latin1() ); widget->setProperty( propName, p->keysToValue( strlst ) ); } else if ( p->isEnumType() ) { widget->setProperty( propName, p->keyToValue( currentItemText ) ); } else if ( qstrcmp( p->name(), "buddy" ) == 0 ) { widget->setProperty( propName, currentItemText ); } else { QVariant ov; if ( propName == "name" || propName == "itemName" ) ov = widget->property( propName ); int oldSerNum = -1; if ( v.type() == QVariant::Pixmap ) oldSerNum = v.toPixmap().serialNumber(); widget->setProperty( propName, v ); if ( oldSerNum != -1 && oldSerNum != widget->property( propName ).toPixmap().serialNumber() ) MetaDataBase::setPixmapKey( formWindow(), widget->property( propName ).toPixmap().serialNumber(), MetaDataBase::pixmapKey( formWindow(), oldSerNum ) ); if ( propName == "cursor" ) { MetaDataBase::setCursor( (QWidget*)((QObject *)widget), v.toCursor() ); } if ( propName == "name" && widget->isWidgetType() ) { formWindow()->mainWindow()->objectHierarchy()->namePropertyChanged( ((QWidget*)(QObject *)widget), ov ); if ( formWindow()->isMainContainer( widget ) ) formWindow()->setName( v.toCString() ); } if ( propName == "name" && ::qt_cast<QAction*>((QObject *)widget) && ::qt_cast<QMainWindow*>(formWindow()->mainContainer()) ) { formWindow()->mainWindow()->actioneditor()->updateActionName( (QAction*)(QObject *)widget ); } if ( propName == "iconSet" && ::qt_cast<QAction*>((QObject *)widget) && ::qt_cast<QMainWindow*>(formWindow()->mainContainer()) ) { formWindow()->mainWindow()->actioneditor()->updateActionIcon( (QAction*)(QObject *)widget ); } if ( propName == "caption" ) { if ( formWindow()->isMainContainer( widget ) ) formWindow()->setCaption( v.toString() ); } if ( propName == "icon" ) { if ( formWindow()->isMainContainer( widget ) ) formWindow()->setIcon( v.toPixmap() ); } } editor->refetchData(); if ( editor->propertyList()->currentItem() && select ) { ( ( PropertyItem* )editor->propertyList()->currentItem() )->showEditor(); ( ( PropertyItem* )editor->propertyList()->currentItem() )->setChanged( MetaDataBase::isPropertyChanged( widget, propName ) ); } editor->emitWidgetChanged(); formWindow()->killAccels( widget );}// ------------------------------------------------------------LayoutHorizontalCommand::LayoutHorizontalCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase ){}void LayoutHorizontalCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutHorizontalCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutHorizontalSplitCommand::LayoutHorizontalSplitCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase, TRUE, TRUE ){}void LayoutHorizontalSplitCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutHorizontalSplitCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutVerticalCommand::LayoutVerticalCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase ){}void LayoutVerticalCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutVerticalCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutVerticalSplitCommand::LayoutVerticalSplitCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), layout( wl, parent, fw, layoutBase, TRUE, TRUE ){}void LayoutVerticalSplitCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutVerticalSplitCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------LayoutGridCommand::LayoutGridCommand( const QString &n, FormWindow *fw, QWidget *parent, QWidget *layoutBase, const QWidgetList &wl, int xres, int yres ) : Command( n, fw ), layout( wl, parent, fw, layoutBase, QSize( QMAX(5,xres), QMAX(5,yres) ) ){}void LayoutGridCommand::execute(){ formWindow()->clearSelection( FALSE ); layout.doLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}void LayoutGridCommand::unexecute(){ formWindow()->clearSelection( FALSE ); layout.undoLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild();}// ------------------------------------------------------------BreakLayoutCommand::BreakLayoutCommand( const QString &n, FormWindow *fw, QWidget *layoutBase, const QWidgetList &wl ) : Command( n, fw ), lb( layoutBase ), widgets( wl ){ WidgetFactory::LayoutType lay = WidgetFactory::layoutType( layoutBase ); spacing = MetaDataBase::spacing( layoutBase ); margin = MetaDataBase::margin( layoutBase ); layout = 0; if ( lay == WidgetFactory::HBox ) layout = new HorizontalLayout( wl, layoutBase, fw, layoutBase, FALSE, ::qt_cast<QSplitter*>(layoutBase) != 0 ); else if ( lay == WidgetFactory::VBox ) layout = new VerticalLayout( wl, layoutBase, fw, layoutBase, FALSE, ::qt_cast<QSplitter*>(layoutBase) != 0 ); else if ( lay == WidgetFactory::Grid ) layout = new GridLayout( wl, layoutBase, fw, layoutBase, QSize( QMAX( 5, fw->grid().x()), QMAX( 5, fw->grid().y()) ), FALSE );}void BreakLayoutCommand::execute(){ if ( !layout ) return; formWindow()->clearSelection( FALSE ); layout->breakLayout(); formWindow()->mainWindow()->objectHierarchy()->rebuild(); for ( QWidget *w = widgets.first(); w; w = widgets.next() ) w->resize( QMAX( 16, w->width() ), QMAX( 16, w->height() ) );}void BreakLayoutCommand::unexecute()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -