📄 uic.cpp
字号:
} else { if ( objClass == "QTable" ) { s = indent + parent + "->setNumCols( " + parent + "->numCols() + 1 );\n"; if ( pix.isEmpty() ) s += indent + parent + "->horizontalHeader()->setLabel( " + parent + "->numCols() - 1, " + trcall( txt, com ) + " );\n"; else s += indent + parent + "->horizontalHeader()->setLabel( " + parent + "->numCols() - 1, " + pix + ", " + trcall( txt, com ) + " );\n"; } else if ( objClass == "QDataTable" ) { if ( !txt.isEmpty() && !field.isEmpty() ) { if ( pix.isEmpty() ) out << indent << parent << "->addColumn( " << fixString( field ) << ", " << trcall( txt, com ) << " );" << endl; else out << indent << parent << "->addColumn( " << fixString( field ) << ", " << trcall( txt, com ) << ", " << pix << " );" << endl; } } } return s;}/*! Creates the implementation of a layout tag. Called from createObjectImpl(). */QString Uic::createLayoutImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout ){ QDomElement n; QString objClass, objName; objClass = e.tagName(); QString qlayout = "QVBoxLayout"; if ( objClass == "hbox" ) qlayout = "QHBoxLayout"; else if ( objClass == "grid" ) qlayout = "QGridLayout"; bool isGrid = e.tagName() == "grid" ; objName = registerObject( getLayoutName( e ) ); layoutObjects += objName; QString margin = DomTool::readProperty( e, "margin", defMargin ).toString(); QString spacing = DomTool::readProperty( e, "spacing", defSpacing ).toString(); QString optcells; if ( isGrid ) optcells = "1, 1, "; if ( (parentClass == "QGroupBox" || parentClass == "QButtonGroup") && layout.isEmpty() ) { // special case for group box out << indent << parent << "->setColumnLayout(0, Qt::Vertical );" << endl; out << indent << parent << "->layout()->setSpacing( " << spacing << " );" << endl; out << indent << parent << "->layout()->setMargin( " << margin << " );" << endl; out << indent << objName << " = new " << qlayout << "( " << parent << "->layout() );" << endl; out << indent << objName << "->setAlignment( Qt::AlignTop );" << endl; } else { out << indent << objName << " = new " << qlayout << "( "; if ( layout.isEmpty() ) out << parent; else { out << "0"; if ( !DomTool::hasProperty( e, "margin" ) ) margin = "0"; } out << ", " << optcells << margin << ", " << spacing << ", \"" << objName << "\"); " << endl; } if ( !isGrid ) { for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "spacer" ) { QString child = createSpacerImpl( n, parentClass, parent, objName ); out << indent << objName << "->addItem( " << child << " );" << endl; } else if ( tags.contains( n.tagName() ) ) { QString child = createObjectImpl( n, parentClass, parent, objName ); if ( isLayout( child ) ) out << indent << objName << "->addLayout( " << child << " );" << endl; else out << indent << objName << "->addWidget( " << child << " );" << endl; } } } else { for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { QDomElement ae = n; int row = ae.attribute( "row" ).toInt(); int col = ae.attribute( "column" ).toInt(); int rowspan = ae.attribute( "rowspan" ).toInt(); int colspan = ae.attribute( "colspan" ).toInt(); if ( rowspan < 1 ) rowspan = 1; if ( colspan < 1 ) colspan = 1; if ( n.tagName() == "spacer" ) { QString child = createSpacerImpl( n, parentClass, parent, objName ); if ( rowspan * colspan != 1 ) out << indent << objName << "->addMultiCell( " << child << ", " << row << ", " << ( row + rowspan - 1 ) << ", " << col << ", " << ( col + colspan - 1 ) << " );" << endl; else out << indent << objName << "->addItem( " << child << ", " << row << ", " << col << " );" << endl; } else if ( tags.contains( n.tagName() ) ) { QString child = createObjectImpl( n, parentClass, parent, objName ); out << endl; QString o = "Widget"; if ( isLayout( child ) ) o = "Layout"; if ( rowspan * colspan != 1 ) out << indent << objName << "->addMultiCell" << o << "( " << child << ", " << row << ", " << ( row + rowspan - 1 ) << ", " << col << ", " << ( col + colspan - 1 ) << " );" << endl; else out << indent << objName << "->add" << o << "( " << child << ", " << row << ", " << col << " );" << endl; } } } return objName;}QString Uic::createSpacerImpl( const QDomElement &e, const QString& /*parentClass*/, const QString& /*parent*/, const QString& /*layout*/){ QDomElement n; QString objClass, objName; objClass = e.tagName(); objName = registerObject( "spacer" ); QSize size = DomTool::readProperty( e, "sizeHint", QSize( 0, 0 ) ).toSize(); QString sizeType = DomTool::readProperty( e, "sizeType", "Expanding" ).toString(); bool isVspacer = DomTool::readProperty( e, "orientation", "Horizontal" ) == "Vertical"; if ( sizeType != "Expanding" && sizeType != "MinimumExpanding" && DomTool::hasProperty( e, "geometry" ) ) { // compatibility Qt 2.2 QRect geom = DomTool::readProperty( e, "geometry", QRect(0,0,0,0) ).toRect(); size = geom.size(); } if ( isVspacer ) out << " QSpacerItem* " << objName << " = new QSpacerItem( " << size.width() << ", " << size.height() << ", QSizePolicy::Minimum, QSizePolicy::" << sizeType << " );" << endl; else out << " QSpacerItem* " << objName << " = new QSpacerItem( " << size.width() << ", " << size.height() << ", QSizePolicy::" << sizeType << ", QSizePolicy::Minimum );" << endl; return objName;}static const char* const ColorRole[] = { "Foreground", "Button", "Light", "Midlight", "Dark", "Mid", "Text", "BrightText", "ButtonText", "Base", "Background", "Shadow", "Highlight", "HighlightedText", "Link", "LinkVisited", 0};/*! Creates a colorgroup with name \a name from the color group \a cg */void Uic::createColorGroupImpl( const QString& name, const QDomElement& e ){ QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QString color; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; QColor col = DomTool::readColor( n ); color = "QColor( %1, %2, %3)"; color = color.arg( col.red() ).arg( col.green() ).arg( col.blue() ); if ( col == white ) color = "white"; else if ( col == black ) color = "black"; if ( n.nextSibling().toElement().tagName() != "pixmap" ) { out << indent << name << ".setColor( QColorGroup::" << ColorRole[r] << ", " << color << " );" << endl; } } else if ( n.tagName() == "pixmap" ) { QString pixmap = n.firstChild().toText().data(); if ( !pixmapLoaderFunction.isEmpty() ) { pixmap.prepend( pixmapLoaderFunction + "( " + QString( externPixmaps ? "\"" : "" ) ); pixmap.append( QString( externPixmaps ? "\"" : "" ) + " )" ); } out << indent << name << ".setBrush( QColorGroup::" << ColorRole[r] << ", QBrush( " << color << ", " << pixmap << " ) );" << endl; } n = n.nextSibling().toElement(); }}/*! Auxiliary function to load a color group. The colorgroup must not contain pixmaps. */QColorGroup Uic::loadColorGroup( const QDomElement &e ){ QColorGroup cg; int r = -1; QDomElement n = e.firstChild().toElement(); QColor col; while ( !n.isNull() ) { if ( n.tagName() == "color" ) { r++; cg.setColor( (QColorGroup::ColorRole)r, (col = DomTool::readColor( n ) ) ); } n = n.nextSibling().toElement(); } return cg;}/*! Returns TRUE if the widget properties specify that it belongs to the database \a connection and \a table.*/bool Uic::isWidgetInTable( const QDomElement& e, const QString& connection, const QString& table ){ QString conn = getDatabaseInfo( e, "connection" ); QString tab = getDatabaseInfo( e, "table" ); if ( conn == connection && tab == table ) return TRUE; return FALSE;}/*! Registers all database connections, cursors and forms.*/void Uic::registerDatabases( const QDomElement& e ){ QDomElement n; QDomNodeList nl; int i; nl = e.parentNode().toElement().elementsByTagName( "widget" ); for ( i = 0; i < (int) nl.length(); ++i ) { n = nl.item(i).toElement(); QString conn = getDatabaseInfo( n, "connection" ); QString tab = getDatabaseInfo( n, "table" ); QString fld = getDatabaseInfo( n, "field" ); if ( !conn.isNull() ) { dbConnections += conn; if ( !tab.isNull() ) { dbCursors[conn] += tab; if ( !fld.isNull() ) dbForms[conn] += tab; } } }}/*! Registers an object with name \a name. The returned name is a valid variable identifier, as similar to \a name as possible and guaranteed to be unique within the form. \sa registeredName(), isObjectRegistered() */QString Uic::registerObject( const QString& name ){ if ( objectNames.isEmpty() ) { // some temporary variables we need objectNames += "img"; objectNames += "item"; objectNames += "cg"; objectNames += "pal"; } QString result = name; int i; while ( ( i = result.find(' ' )) != -1 ) { result[i] = '_'; } if ( objectNames.contains( result ) ) { int i = 2; while ( objectNames.contains( result + "_" + QString::number(i) ) ) i++; result += "_"; result += QString::number(i); } objectNames += result; objectMapper.insert( name, result ); return result;}/*! Returns the registered name for the original name \a name or \a name if \a name wasn't registered. \sa registerObject(), isObjectRegistered() */QString Uic::registeredName( const QString& name ){ if ( !objectMapper.contains( name ) ) return name; return objectMapper[name];}/*! Returns whether the object \a name was registered yet or not. */bool Uic::isObjectRegistered( const QString& name ){ return objectMapper.contains( name );}/*! Unifies the entries in stringlist \a list. Should really be a QStringList feature. */QStringList Uic::unique( const QStringList& list ){ QStringList result; if ( list.isEmpty() ) return result; QStringList l = list; l.sort(); result += l.first(); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { if ( *it != result.last() ) result += *it; } return result;}/*! Creates an instance of class \a objClass, with parent \a parent and name \a objName */QString Uic::createObjectInstance( const QString& objClass, const QString& parent, const QString& objName ){ if ( objClass.mid( 1 ) == "ComboBox" ) { return objClass + "( FALSE, " + parent + ", \"" + objName + "\" )"; } return objClass + "( " + parent + ", \"" + objName + "\" )";}bool Uic::isLayout( const QString& name ) const{ return layoutObjects.contains( name );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -