📄 resource.cpp
字号:
function.access = n.attribute( "access", "public" ); if ( function.access.isEmpty() ) function.access = "public"; function.language = n.attribute( "language", "C++" ); function.returnType = n.attribute( "returnType", "void" ); if ( function.returnType.isEmpty() ) function.returnType = "void"; function.type = "slot"; function.function = n.firstChild().toText().data(); if ( !MetaDataBase::hasFunction( formwindow, function.function, TRUE ) ) MetaDataBase::addFunction( formwindow, function.function, function.specifier, function.access, "slot", function.language, function.returnType ); else MetaDataBase::changeFunctionAttributes( formwindow, function.function, function.function, function.specifier, function.access, "slot", function.language, function.returnType ); } } if ( !functions.isNull() ) { for ( QDomElement n = functions.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "function" ) { MetaDataBase::Function function; function.specifier = n.attribute( "specifier", "virtual" ); if ( function.specifier.isEmpty() ) function.specifier = "virtual"; function.access = n.attribute( "access", "public" ); if ( function.access.isEmpty() ) function.access = "public"; function.type = n.attribute( "type", "function" ); function.type = "function"; function.language = n.attribute( "language", "C++" ); function.returnType = n.attribute( "returnType", "void" ); if ( function.returnType.isEmpty() ) function.returnType = "void"; function.function = n.firstChild().toText().data(); if ( !MetaDataBase::hasFunction( formwindow, function.function, TRUE ) ) MetaDataBase::addFunction( formwindow, function.function, function.specifier, function.access, function.type, function.language, function.returnType ); else MetaDataBase::changeFunctionAttributes( formwindow, function.function, function.function, function.specifier, function.access, function.type, function.language, function.returnType ); } } } if ( !actions.isNull() ) loadActions( actions ); if ( !toolbars.isNull() ) loadToolBars( toolbars ); if ( !menubar.isNull() ) loadMenuBar( menubar ); if ( !connections.isNull() ) loadConnections( connections ); if ( !tabOrder.isNull() ) loadTabOrder( tabOrder ); if ( formwindow ) { MetaDataBase::setIncludes( formwindow, metaIncludes ); MetaDataBase::setForwards( formwindow, metaForwards ); MetaDataBase::setVariables( formwindow, metaVariables ); MetaDataBase::setSignalList( formwindow, metaSignals ); metaInfo.classNameChanged = metaInfo.className != QString( formwindow->name() ); MetaDataBase::setMetaInfo( formwindow, metaInfo ); MetaDataBase::setExportMacro( formwindow->mainContainer(), exportMacro ); } loadExtraSource( formwindow->formFile(), currFileName, langIface, hasFunctions ); if ( mainwindow && formwindow ) mainwindow->insertFormWindow( formwindow ); if ( formwindow ) { formwindow->killAccels( formwindow ); if ( formwindow->layout() ) formwindow->layout()->activate(); if ( hadGeometry ) formwindow->resize( formwindow->size().expandedTo( formwindow->minimumSize(). expandedTo( formwindow->minimumSizeHint() ) ) ); else formwindow->resize( formwindow->size().expandedTo( formwindow->sizeHint() ) ); } return TRUE;}bool Resource::save( const QString& filename, bool formCodeOnly ){ if ( !formwindow || filename.isEmpty() ) return FALSE; if (!langIface) { QString lang = "Qt Script"; if ( mainwindow ) lang = mainwindow->currProject()->language(); langIface = MetaDataBase::languageInterface( lang ); if ( langIface ) langIface->addRef(); } if ( formCodeOnly && langIface ) { saveFormCode( formwindow->formFile(), langIface ); return TRUE; // missing error checking in saveFormCode ? } currFileName = filename; QFile f( filename ); if ( !f.open( IO_WriteOnly | IO_Translate ) ) return FALSE; bool b = save( &f ); f.close(); return b;}bool Resource::save( QIODevice* dev ){ if ( !formwindow ) return FALSE; if ( !langIface ) { QString lang = "Qt Script"; if ( mainwindow ) lang = mainwindow->currProject()->language(); langIface = MetaDataBase::languageInterface( lang ); if ( langIface ) langIface->addRef(); } QTextStream ts( dev ); ts.setCodec( QTextCodec::codecForName( "UTF-8" ) ); ts << "<!DOCTYPE UI><UI version=\"3.1\" stdsetdef=\"1\">" << endl; saveMetaInfoBefore( ts, 0 ); saveObject( formwindow->mainContainer(), 0, ts, 0 ); if ( formwindow->mainContainer()->inherits( "QMainWindow" ) ) { saveMenuBar( (QMainWindow*)formwindow->mainContainer(), ts, 0 ); saveToolBars( (QMainWindow*)formwindow->mainContainer(), ts, 0 ); } if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() ) saveCustomWidgets( ts, 0 ); if ( formwindow->mainContainer()->inherits( "QMainWindow" ) ) saveActions( formwindow->actionList(), ts, 0 ); if ( !images.isEmpty() ) saveImageCollection( ts, 0 ); if ( !MetaDataBase::connections( formwindow ).isEmpty() || !MetaDataBase::slotList( formwindow ).isEmpty() ) saveConnections( ts, 0 ); saveTabOrder( ts, 0 ); saveMetaInfoAfter( ts, 0 ); saveIncludeHints( ts, 0 ); ts << "</UI>" << endl; saveFormCode( formwindow->formFile(), langIface ); images.clear(); return TRUE;}QString Resource::copy(){ if ( !formwindow ) return QString::null; copying = TRUE; QString s; QTextOStream ts( &s ); ts << "<!DOCTYPE UI-SELECTION><UI-SELECTION>" << endl; QWidgetList widgets = formwindow->selectedWidgets(); QWidgetList tmp( widgets ); for ( QWidget *w = widgets.first(); w; w = widgets.next() ) { QWidget *p = w->parentWidget(); bool save = TRUE; while ( p ) { if ( tmp.findRef( p ) != -1 ) { save = FALSE; break; } p = p->parentWidget(); } if ( save ) saveObject( w, 0, ts, 0 ); } if ( !MetaDataBase::customWidgets()->isEmpty() && !usedCustomWidgets.isEmpty() ) saveCustomWidgets( ts, 0 ); if ( !images.isEmpty() ) saveImageCollection( ts, 0 ); ts << "</UI-SELECTION>" << endl; return s;}void Resource::paste( const QString &cb, QWidget *parent ){ if ( !formwindow ) return; mainContainerSet = TRUE; pasting = TRUE; QDomDocument doc; QString errMsg; int errLine; if ( !doc.setContent( cb, &errMsg, &errLine ) ) { qDebug( QString("Parse error: ") + errMsg + QString(" in line %d"), errLine ); } QDomElement firstWidget = doc.firstChild().toElement().firstChild().toElement(); QDomElement imageCollection = firstWidget; images.clear(); while ( imageCollection.tagName() != "images" && !imageCollection.isNull() ) imageCollection = imageCollection.nextSibling().toElement(); QDomElement customWidgets = firstWidget; while ( customWidgets.tagName() != "customwidgets" && !customWidgets.isNull() ) customWidgets = customWidgets.nextSibling().toElement(); if ( !imageCollection.isNull() ) loadImageCollection( imageCollection ); if ( !customWidgets.isNull() ) loadCustomWidgets( customWidgets, this ); QWidgetList widgets; formwindow->clearSelection( FALSE ); formwindow->setPropertyShowingBlocked( TRUE ); formwindow->clearSelection( FALSE ); while ( !firstWidget.isNull() ) { if ( firstWidget.tagName() == "widget" ) { QWidget *w = (QWidget*)createObject( firstWidget, parent, 0 ); if ( !w ) continue; widgets.append( w ); int x = w->x() + formwindow->grid().x(); int y = w->y() + formwindow->grid().y(); if ( w->x() + w->width() > parent->width() ) x = QMAX( 0, parent->width() - w->width() ); if ( w->y() + w->height() > parent->height() ) y = QMAX( 0, parent->height() - w->height() ); if ( x != w->x() || y != w->y() ) w->move( x, y ); formwindow->selectWidget( w ); } else if ( firstWidget.tagName() == "spacer" ) { QWidget *w = createSpacer( firstWidget, parent, 0, firstWidget.tagName() == "vspacer" ? Qt::Vertical : Qt::Horizontal ); if ( !w ) continue; widgets.append( w ); int x = w->x() + formwindow->grid().x(); int y = w->y() + formwindow->grid().y(); if ( w->x() + w->width() > parent->width() ) x = QMAX( 0, parent->width() - w->width() ); if ( w->y() + w->height() > parent->height() ) y = QMAX( 0, parent->height() - w->height() ); if ( x != w->x() || y != w->y() ) w->move( x, y ); formwindow->selectWidget( w ); } firstWidget = firstWidget.nextSibling().toElement(); } formwindow->setPropertyShowingBlocked( FALSE ); formwindow->emitShowProperties(); PasteCommand *cmd = new PasteCommand( FormWindow::tr( "Paste" ), formwindow, widgets ); formwindow->commandHistory()->addCommand( cmd );}void Resource::saveObject( QObject *obj, QDesignerGridLayout* grid, QTextStream &ts, int indent ){ if ( obj && obj->isWidgetType() && ( (QWidget*)obj )->isHidden() ) return; QString closeTag; const char* className = WidgetFactory::classNameOf( obj ); if ( obj->isWidgetType() ) { if ( obj->isA( "CustomWidget" ) ) usedCustomWidgets << QString( className ); if ( WidgetDatabase:: isCustomWidget( WidgetDatabase::idFromClassName( className ) ) || WidgetDatabase:: isCustomPluginWidget( WidgetDatabase::idFromClassName( className ) ) ) includeHints << WidgetDatabase::includeFile( WidgetDatabase::idFromClassName( className ) ); if ( obj != formwindow && !formwindow->widgets()->find( (QWidget*)obj ) ) return; // we don't know anything about this thing QString attributes; if ( grid ) { QDesignerGridLayout::Item item = grid->items[ (QWidget*)obj ]; attributes += QString(" row=\"") + QString::number(item.row) + "\""; attributes += QString(" column=\"") + QString::number(item.column) + "\""; if ( item.rowspan * item.colspan != 1 ) { attributes += QString(" rowspan=\"") + QString::number(item.rowspan) + "\""; attributes += QString(" colspan=\"") + QString::number(item.colspan) + "\""; } } if ( qstrcmp( className, "Spacer" ) == 0 ) { closeTag = makeIndent( indent ) + "</spacer>\n"; ts << makeIndent( indent ) << "<spacer" << attributes << ">" << endl; ++indent; } else { closeTag = makeIndent( indent ) + "</widget>\n"; ts << makeIndent( indent ) << "<widget class=\"" << className << "\"" << attributes << ">" << endl; ++indent; } if ( WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( obj ) ) ) ) saveItems( obj, ts, indent ); saveObjectProperties( obj, ts, indent ); } else { // test for other objects we created. Nothing so far. return; } if ( obj->inherits( "QTabWidget" ) ) { QTabWidget* tw = (QTabWidget*) obj; QObjectList* tmpl = tw->queryList( "QWidgetStack" ); QWidgetStack *ws = (QWidgetStack*)tmpl->first(); QTabBar *tb = ( (QDesignerTabWidget*)obj )->tabBar(); for ( int i = 0; i < tb->count(); ++i ) { QTab *t = tb->tabAt( i ); if ( !t ) continue; QWidget *w = ws->widget( t->identifier() ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl; ++indent; ts << makeIndent( indent ) << "<property name=\"name\">" << endl; indent++; ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl; indent--; ts << makeIndent( indent ) << "</property>" << endl; ts << makeIndent( indent ) << "<attribute name=\"title\">" << endl; indent++; ts << makeIndent( indent ) << "<string>" << entitize( t->text() ) << "</string>" << endl; indent--; ts << makeIndent( indent ) << "</attribute>" << endl; saveChildrenOf( w, ts, indent ); --indent; ts << makeIndent( indent ) << "</widget>" << endl; } delete tmpl; } else if ( obj->inherits( "QWidgetStack" ) ) { QDesignerWidgetStack* ws = (QDesignerWidgetStack*) obj; for ( int i = 0; i < ws->count(); ++i ) { QWidget *w = ws->page( i ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl; ++indent; ts << makeIndent( indent ) << "<property name=\"name\">" << endl; indent++; ts << makeIndent( indent ) << "<cstring>" << entitize( w->name() ) << "</cstring>" << endl; indent--; ts << makeIndent( indent ) << "</property>" << endl; ts << makeIndent( indent ) << "<attribute name=\"id\">" << endl; indent++; ts << makeIndent( indent ) << "<number>" << QString::number(i) << "</number>" << endl; indent--; ts << makeIndent( indent ) << "</attribute>" << endl; saveChildrenOf( w, ts, indent ); --indent; ts << makeIndent( indent ) << "</widget>" << endl; } } else if ( obj->inherits( "QWizard" ) ) { QWizard* wiz = (QWizard*)obj; for ( int i = 0; i < wiz->pageCount(); ++i ) { QWidget *w = wiz->page( i ); if ( !w ) continue; if ( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( w ) ) == -1 ) continue; // we don't know this widget ts << makeIndent( indent ) << "<widget class=\"QWidget\">" << endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -