📄 uic.cpp
字号:
void Uic::createActionImpl( const QDomElement &n, const QString &parent ){ for ( QDomElement ae = n; !ae.isNull(); ae = ae.nextSibling().toElement() ) { QString objName = registerObject( getObjectName( ae ) ); if ( ae.tagName() == "action" ) out << indent << objName << " = new QAction( " << parent << ", \"" << objName << "\" );" << endl; else if ( ae.tagName() == "actiongroup" ) out << indent << objName << " = new QActionGroup( " << parent << ", \"" << objName << "\" );" << endl; else continue; bool subActionsDone = FALSE; for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "property" ) { bool stdset = stdsetdef; if ( n2.hasAttribute( "stdset" ) ) stdset = toBool( n2.attribute( "stdset" ) ); QString prop = n2.attribute("name"); if ( prop == "name" ) continue; QString value = setObjectProperty( "QAction", objName, prop, n2.firstChild().toElement(), stdset ); if ( value.isEmpty() ) continue; QString call = objName + "->"; if ( stdset ) { call += mkStdSet( prop ) + "( "; } else { call += "setProperty( \"" + prop + "\", "; } call += value + " );"; if ( n2.firstChild().toElement().tagName() == "string" ) { trout << indent << call << endl; } else { out << indent << call << endl; } } else if ( !subActionsDone && ( n2.tagName() == "actiongroup" || n2.tagName() == "action" ) ) { createActionImpl( n2, objName ); subActionsDone = TRUE; } } }}QString get_dock( const QString &d ){ if ( d == "0" ) return "DockUnmanaged"; if ( d == "1" ) return "DockTornOff"; if ( d == "2" ) return "DockTop"; if ( d == "3" ) return "DockBottom"; if ( d == "4" ) return "DockRight"; if ( d == "5" ) return "DockLeft"; if ( d == "6" ) return "DockMinimized"; return "";}void Uic::createToolbarImpl( const QDomElement &n, const QString &parentClass, const QString &parent ){ QDomNodeList nl = n.elementsByTagName( "toolbar" ); for ( int i = 0; i < (int) nl.length(); i++ ) { QDomElement ae = nl.item( i ).toElement(); QString dock = get_dock( ae.attribute( "dock" ) ); QString objName = getObjectName( ae ); out << indent << objName << " = new QToolBar( \"\", this, " << dock << " ); " << endl; createObjectImpl( ae, parentClass, parent ); for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "action" ) { out << indent << n2.attribute( "name" ) << "->addTo( " << objName << " );" << endl; } else if ( n2.tagName() == "separator" ) { out << indent << objName << "->addSeparator();" << endl; } else if ( n2.tagName() == "widget" ) { if ( n2.attribute( "class" ) != "Spacer" ) { createObjectImpl( n2, "QToolBar", objName ); } else { QString child = createSpacerImpl( n, parentClass, parent, objName ); out << indent << "QApplication::sendPostedEvents( " << objName << ", QEvent::ChildInserted );" << endl; out << indent << objName << "->boxLayout()->addItem( " << child << " );" << endl; } } } }}void Uic::createMenuBarImpl( const QDomElement &n, const QString &parentClass, const QString &parent ){ QString objName = getObjectName( n ); out << indent << objName << " = new QMenuBar( this, \"" << objName << "\" );" << endl; createObjectImpl( n, parentClass, parent ); QDomNodeList nl = n.elementsByTagName( "item" ); for ( int i = 0; i < (int) nl.length(); i++ ) { QDomElement ae = nl.item( i ).toElement(); QString itemName = ae.attribute( "name" ); out << indent << itemName << " = new QPopupMenu( this );" << endl; out << endl; for ( QDomElement n2 = ae.firstChild().toElement(); !n2.isNull(); n2 = n2.nextSibling().toElement() ) { if ( n2.tagName() == "action" ) out << indent << n2.attribute( "name" ) << "->addTo( " << itemName << " );" << endl; else if ( n2.tagName() == "separator" ) out << indent << itemName << "->insertSeparator();" << endl; } out << indent << objName << "->insertItem( \"\", " << itemName << ", " << i << " );" << endl; trout << indent << objName << "->findItem( " << i << " )->setText( " << trcall( ae.attribute( "text" ) ) << " );" << endl; }}/*! Creates implementation of an listbox item tag.*/QString Uic::createListBoxItemImpl( const QDomElement &e, const QString &parent, QString *value ){ QDomElement n = e.firstChild().toElement(); QString txt; QString com; QString pix; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) { txt = v.toString(); com = getComment( n ); } else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } } n = n.nextSibling().toElement(); } if ( value ) *value = trcall( txt, com ); if ( pix.isEmpty() ) { return parent + "->insertItem( " + trcall( txt, com ) + " );"; } else { return parent + "->insertItem( " + pix + ", " + trcall( txt, com ) + " );"; }}/*! Creates implementation of an iconview item tag.*/QString Uic::createIconViewItemImpl( const QDomElement &e, const QString &parent ){ QDomElement n = e.firstChild().toElement(); QString txt; QString com; QString pix; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) { txt = v.toString(); com = getComment( n ); } else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } } n = n.nextSibling().toElement(); } if ( pix.isEmpty() ) return "(void) new QIconViewItem( " + parent + ", " + trcall( txt, com ) + " );"; else return "(void) new QIconViewItem( " + parent + ", " + trcall( txt, com ) + ", " + pix + " );";}/*! Creates implementation of an listview item tag.*/QString Uic::createListViewItemImpl( const QDomElement &e, const QString &parent, const QString &parentItem ){ QString s; QDomElement n = e.firstChild().toElement(); bool hasChildren = e.elementsByTagName( "item" ).count() > 0; QString item; if ( hasChildren ) { item = registerObject( "item" ); s = indent + "QListViewItem * " + item + " = "; } else { item = "item"; if ( item_used ) s = indent + item + " = "; else s = indent + "QListViewItem * " + item + " = "; item_used = TRUE; } if ( !parentItem.isEmpty() ) s += "new QListViewItem( " + parentItem + ", " + lastItem + " );\n"; else s += "new QListViewItem( " + parent + ", " + lastItem + " );\n"; QStringList texts; QStringList pixmaps; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute("name"); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) texts << v.toString(); else if ( attrib == "pixmap" ) { QString pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } pixmaps << pix; } } else if ( n.tagName() == "item" ) { s += indent + item + "->setOpen( TRUE );\n"; s += createListViewItemImpl( n, parent, item ); } n = n.nextSibling().toElement(); } for ( int i = 0; i < (int)texts.count(); ++i ) { if ( !texts[ i ].isEmpty() ) s += indent + item + "->setText( " + QString::number( i ) + ", " + trcall( texts[ i ] ) + " );\n"; if ( !pixmaps[ i ].isEmpty() ) s += indent + item + "->setPixmap( " + QString::number( i ) + ", " + pixmaps[ i ] + " );\n"; } lastItem = item; return s;}/*! Creates implementation of an listview column tag.*/QString Uic::createListViewColumnImpl( const QDomElement &e, const QString &parent, QString *value ){ QDomElement n = e.firstChild().toElement(); QString txt; QString com; QString pix; bool clickable = FALSE, resizable = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute("name"); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) { txt = v.toString(); com = getComment( n ); } else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizable" || attrib == "resizeable" ) resizable = v.toBool(); } n = n.nextSibling().toElement(); } if ( value ) *value = trcall( txt, com ); QString s; s = indent + parent + "->addColumn( " + trcall( txt, com ) + " );\n"; if ( !pix.isEmpty() ) s += indent + parent + "->header()->setLabel( " + parent + "->header()->count() - 1, " + pix + ", " + trcall( txt, com ) + " );\n"; if ( !clickable ) s += indent + parent + "->header()->setClickEnabled( FALSE, " + parent + "->header()->count() - 1 );\n"; if ( !resizable ) s += indent + parent + "->header()->setResizeEnabled( FALSE, " + parent + "->header()->count() - 1 );\n"; return s;}QString Uic::createTableRowColumnImpl( const QDomElement &e, const QString &parent, QString *value ){ QString objClass = getClassName( e.parentNode().toElement() ); QDomElement n = e.firstChild().toElement(); QString txt; QString com; QString pix; QString field; bool isRow = e.tagName() == "row"; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute("name"); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) { txt = v.toString(); com = getComment( n ); } else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pix.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } } else if ( attrib == "field" ) field = v.toString(); } n = n.nextSibling().toElement(); } if ( value ) *value = trcall( txt, com ); // ### This generated code sucks! We have to set the number of // rows/cols before and then only do setLabel/() // ### careful, though, since QDataTable has an API which makes this code pretty good QString s; if ( isRow ) { s = indent + parent + "->setNumRows( " + parent + "->numRows() + 1 );\n"; if ( pix.isEmpty() ) s += indent + parent + "->verticalHeader()->setLabel( " + parent + "->numRows() - 1, " + trcall( txt, com ) + " );\n"; else s += indent + parent + "->verticalHeader()->setLabel( " + parent + "->numRows() - 1, " + pix + ", " + trcall( txt, com ) + " );\n";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -