📄 uic.cpp
字号:
// create public additional slots as pure-virtual functions if ( !publicSlots.isEmpty() ) { for ( it = publicSlots.begin(); it != publicSlots.end(); ++it ) { out << "void " << nameOfClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << nameOfClass << "::" << (*it) << ": Not implemented yet!\" );" << endl; out << "}" << endl; out << endl; } } // create protected additional slots as pure-virtual functions if ( !protectedSlots.isEmpty() ) { for ( it = protectedSlots.begin(); it != protectedSlots.end(); ++it ) { out << "void " << nameOfClass << "::" << (*it) << endl; out << "{" << endl; out << " qWarning( \"" << nameOfClass << "::" << (*it) << ": Not implemented yet!\" );" << endl; out << "}" << endl; out << endl; } }}/*! Returns include file for class \a className or a null string. */QString Uic::getInclude( const QString& className ){ int wid = WidgetDatabase::idFromClassName( className ); if ( wid != -1 ) return WidgetDatabase::includeFile( wid ); return QString::null;}/*! Creates a declaration for the object given in \a e. Any children are ignored, this function does _not_ travesere recursively. \sa createObjectImpl() */void Uic::createObjectDecl( const QDomElement& e ){ if ( e.tagName() == "vbox" ) { out << " QVBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl; } else if ( e.tagName() == "hbox" ) { out << " QHBoxLayout* " << registerObject(getLayoutName(e) ) << ";" << endl; } else if ( e.tagName() == "grid" ) { out << " QGridLayout* " << registerObject(getLayoutName(e) ) << ";" << endl; } else { QString objClass = getClassName( e ); if ( objClass.isEmpty() ) return; QString objName = getObjectName( e ); if ( objName.isEmpty() ) return; // ignore QLayoutWidgets if ( objClass == "QLayoutWidget" ) return; // register the object and unify its name objName = registerObject( objName ); if ( objClass == "Line" ) objClass = "QFrame"; out << " " << objClass << "* " << objName << ";" << endl; }}/*! Creates an implementation for the object given in \a e. Traverses recursively over all children. Returns the name of the generated child object. \sa createObjectDecl() */QString Uic::createObjectImpl( const QDomElement &e, const QString& parentClass, const QString& parent, const QString& layout ){ QDomElement n; QString objClass, objName; if ( layouts.contains( e.tagName() ) ) return createLayoutImpl( e, parentClass, parent, layout ); objClass = getClassName( e ); if ( objClass.isEmpty() ) return objName; objName = getObjectName( e ); bool isTmpObject = objName.isEmpty(); if ( isTmpObject ) { if ( objClass[0] == 'Q' ) objName = objClass[1].lower() + objClass.mid(2); else objName = objClass.lower(); } bool isLine = objClass == "Line"; if ( isLine ) objClass = "QFrame"; // register the object and unify its name if (objClass != "QLayoutWidget" || layout.isEmpty()) objName = registerObject( objName ); out << endl; if ( objClass == "QLayoutWidget" ) { if ( layout.isEmpty() ) { out << " QWidget* " << objName << " = new QWidget( " << parent << ", \"" << objName << "\" );" << endl; } else { // the layout widget is not necessary, hide it by creating its child in the parent QString result; for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if (tags.contains( n.tagName() ) ) result = createObjectImpl( n, parentClass, parent, layout ); } return result; } } else { out << " "; if ( isTmpObject ) out << objClass << "* "; out << objName << " = new " << createObjectInstance( objClass, parent, objName ) << ";" << endl; } lastItem = "0"; // set the properties and insert items for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( n.tagName() == "property" ) { bool stdset = toBool( n.attribute( "stdset" ) ); QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString prop = n2.firstChild().toText().data(); QString value = setObjectProperty( objClass, objName, prop, n2.nextSibling().toElement(), stdset ); if ( value.isEmpty() ) continue; if ( prop == "name" ) continue; if ( prop == "buddy" && value[0] == '\"' && value[(int)value.length()-1] == '\"' ) { buddies << Buddy( objName, value.mid(1, value.length() - 2 ) ); continue; } if ( isLine && prop == "orientation" ) { prop = "frameStyle"; if ( value.right(10) == "Horizontal" ) value = "QFrame::HLine | QFrame::Sunken"; else value = "QFrame::VLine | QFrame::Sunken"; } if ( prop == "buttonGroupId" ) { if ( parentClass == "QButtonGroup" ) out << indent << parent << "->insert( " << objName << ", " << value << " );" << endl; continue; } if ( prop == "geometry") { out << indent << objName << "->setGeometry( " << value << " ); " << endl; } else { if ( stdset ) out << indent << objName << "->" << mkStdSet(prop ) << "( " << value << " );" << endl; else out << indent << objName << "->setProperty( \"" << prop << "\", " << value << " );" << endl; } } } else if ( n.tagName() == "item" ) { if ( objClass.mid( 1 ) == "ListBox" ) { QString s = createListBoxItemImpl( n, objName ); if ( !s.isEmpty() ) out << indent << s << endl; } else if ( objClass.mid( 1 ) == "ComboBox" ) { QString s = createListBoxItemImpl( n, objName ); if ( !s.isEmpty() ) out << indent << s << endl; } else if ( objClass.mid( 1 ) == "IconView" ) { QString s = createIconViewItemImpl( n, objName ); if ( !s.isEmpty() ) out << indent << s << endl; } else if ( objClass.mid( 1 ) == "ListView" ) { QString s = createListViewItemImpl( n, objName, QString::null ); if ( !s.isEmpty() ) out << s << endl; } } else if ( n.tagName() == "column" ) { if ( objClass.mid( 1 ) == "ListView" ) { QString s = createListViewColumnImpl( n, objName ); if ( !s.isEmpty() ) out << s; } } } // create all children, some widgets have special requirements if ( objClass == "QTabWidget" ) { for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( tags.contains( n.tagName() ) ) { QString page = createObjectImpl( n, objClass, objName ); QString label = DomTool::readAttribute( n, "title", "" ).toString(); out << indent << objName << "->insertTab( " << page << ", " << trmacro << "( \"" << fixString( label ) << "\" ) );" << endl; } } } else { // standard widgets for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) { if ( tags.contains( n.tagName() ) ) createObjectImpl( n, objClass, objName ); } } return objName;}/*! Creates implementation of an listbox item tag.*/QString Uic::createListBoxItemImpl( const QDomElement &e, const QString &parent ){ QDomElement n = e.firstChild().toElement(); QString txt; QString pix; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " ); pix.append( " )" ); } } } } n = n.nextSibling().toElement(); } if ( pix.isEmpty() ) return parent + "->insertItem( " + trmacro + "( \"" + fixString( txt ) + "\" ) );"; else return parent + "->insertItem( " + pix + ", " + trmacro + "( \"" + fixString( txt ) + "\" ) );"; return QString::null;}/*! Creates implementation of an iconview item tag.*/QString Uic::createIconViewItemImpl( const QDomElement &e, const QString &parent ){ QDomElement n = e.firstChild().toElement(); QString txt; QString pix; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " ); pix.append( " )" ); } } } } n = n.nextSibling().toElement(); } if ( pix.isEmpty() ) return "(void) new QIconViewItem( " + parent + ", " + trmacro + "( \"" + fixString( txt ) + "\" ) );"; return "(void) new QIconViewItem( " + parent + ", " + trmacro + "( \"" + fixString( txt ) + "\" ), " + 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 textes; QStringList pixmaps; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) textes << v.toString(); else if ( attrib == "pixmap" ) { QString pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " ); pix.append( " )" ); } 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)textes.count(); ++i ) { if ( !textes[ i ].isEmpty() ) s += indent + item + "->setText( " + QString::number( i ) + ", " + trmacro + "( \"" + fixString( textes[ 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 ){ QDomElement n = e.firstChild().toElement(); QString txt; QString pix; bool clickable = FALSE, resizeable = FALSE; while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QDomElement n2 = n.firstChild().toElement(); if ( n2.tagName() == "name" ) { QString attrib = n2.firstChild().toText().data(); QVariant v = DomTool::elementToVariant( n2.nextSibling().toElement(), QVariant() ); if ( attrib == "text" ) txt = v.toString(); else if ( attrib == "pixmap" ) { pix = v.toString(); if ( !pix.isEmpty() && !pixmapLoaderFunction.isEmpty() ) { pix.prepend( pixmapLoaderFunction + "( " ); pix.append( " )" ); } } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizeable" ) resizeable = v.toBool(); } } n = n.nextSibling().toElement(); } QString s; s = indent + parent + "->addColumn( " + trmacro + "( \"" + fixString( txt ) + "\" ) );\n"; if ( !pix.isEmpty() ) s += indent + parent + "->header()->setLabel( " + parent + "->header()->count() - 1, " + pix + ", " + trmacro + "( \"" + fixString( txt ) + "\" ) );\n"; if ( !clickable ) s += indent + parent + "->header()->setClickEnabled( FALSE, " + parent + "->header()->count() - 1 );\n"; if ( !resizeable ) s += indent + parent + "->header()->setResizeEnabled( FALSE, " + parent + "->header()->count() - 1 );\n";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -