📄 resource.cpp
字号:
|| isPlugin#endif ) ) MetaDataBase::addEntry( w ); } } while ( !n.isNull() ) { if ( n.tagName() == "spacer" ) { createSpacer( n, w, layout, Qt::Horizontal ); } else if ( n.tagName() == "widget" ) { createObject( n, w, layout ); } else if ( n.tagName() == "hbox" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::HBox ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "grid" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::Grid ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "vbox" ) { layout = WidgetFactory::createLayout( w, layout, WidgetFactory::VBox ); obj = layout; n = n.firstChild().toElement(); continue; } else if ( n.tagName() == "property" && obj ) { setObjectProperty( obj, n.attribute( "name" ), n.firstChild().toElement() ); } else if ( n.tagName() == "attribute" && w ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( parent->inherits( "QTabWidget" ) ) { if ( attrib == "title" ) ( (QTabWidget*)parent )->insertTab( w, v.toString() ); } else if ( parent->inherits( "QWidgetStack" ) ) { if ( attrib == "id" ) ( (QDesignerWidgetStack*)parent )->insertPage( w, v.toInt() ); } else if ( parent->inherits( "QWizard" ) ) { if ( attrib == "title" ) ( (QWizard*)parent )->addPage( w, v.toString() );#ifdef QT_CONTAINER_CUSTOM_WIDGETS } else if ( isPlugin ) { if ( attrib == "label" ) { WidgetInterface *iface = 0; widgetManager()->queryInterface( parentClassName, &iface ); if ( iface ) { QWidgetContainerInterfacePrivate *iface2 = 0; iface->queryInterface( IID_QWidgetContainer, (QUnknownInterface**)&iface2 ); if ( iface2 ) { iface2->insertPage( parentClassName, (QWidget*)parent, v.toString(), -1, w ); iface2->release(); } iface->release(); } }#endif } } else if ( n.tagName() == "item" ) { createItem( n, w ); } else if ( n.tagName() == "column" || n.tagName() =="row" ) { createColumn( n, w ); } n = n.nextSibling().toElement(); } if ( w->isWidgetType() ) widgets.insert( w->name(), w ); return w;}void Resource::createColumn( const QDomElement &e, QWidget *widget ){ if ( !widget ) return; if ( widget->inherits( "QListView" ) && e.tagName() == "column" ) { QListView *lv = (QListView*)widget; QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; bool clickable = TRUE, resizable = TRUE; 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(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement().toElement() ); hasPixmap = !pix.isNull(); } else if ( attrib == "clickable" ) clickable = v.toBool(); else if ( attrib == "resizable" ) resizable = v.toBool(); } n = n.nextSibling().toElement(); } lv->addColumn( txt ); int i = lv->header()->count() - 1; if ( hasPixmap ) { lv->header()->setLabel( i, pix, txt ); } if ( !clickable ) lv->header()->setClickEnabled( clickable, i ); if ( !resizable ) lv->header()->setResizeEnabled( resizable, i ); }#ifndef QT_NO_TABLE else if ( widget->inherits( "QTable" ) ) { QTable *table = (QTable*)widget; bool isRow; if ( ( isRow = e.tagName() == "row" ) ) table->setNumRows( table->numRows() + 1 ); else table->setNumCols( table->numCols() + 1 ); QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; QString field; QMap<QString, QString> fieldMap = MetaDataBase::columnFields( table ); 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(); else if ( attrib == "pixmap" ) { hasPixmap = !n.firstChild().firstChild().toText().data().isEmpty(); if ( hasPixmap ) pix = loadPixmap( n.firstChild().toElement() ); } else if ( attrib == "field" ) field = v.toString(); } n = n.nextSibling().toElement(); } int i = isRow ? table->numRows() - 1 : table->numCols() - 1; QHeader *h = !isRow ? table->horizontalHeader() : table->verticalHeader(); if ( hasPixmap ) h->setLabel( i, pix, txt ); else h->setLabel( i, txt ); if ( !isRow && !field.isEmpty() ) fieldMap.insert( txt, field ); MetaDataBase::setColumnFields( table, fieldMap ); }#endif}void Resource::loadItem( const QDomElement &e, QPixmap &pix, QString &txt, bool &hasPixmap ){ QDomElement n = e; hasPixmap = 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(); else if ( attrib == "pixmap" ) { pix = loadPixmap( n.firstChild().toElement() ); hasPixmap = !pix.isNull(); } } n = n.nextSibling().toElement(); }}void Resource::createItem( const QDomElement &e, QWidget *widget, QListViewItem *i ){ if ( !widget || !WidgetFactory::hasItems( WidgetDatabase::idFromClassName( WidgetFactory::classNameOf( widget ) ) ) ) return; if ( widget->inherits( "QListBox" ) || widget->inherits( "QComboBox" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; loadItem( n, pix, txt, hasPixmap ); QListBox *lb = 0; if ( widget->inherits( "QListBox" ) ) lb = (QListBox*)widget; else lb = ( (QComboBox*)widget)->listBox(); if ( hasPixmap ) { new QListBoxPixmap( lb, pix, txt ); } else { new QListBoxText( lb, txt ); } } else if ( widget->inherits( "QIconView" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; bool hasPixmap = FALSE; QString txt; loadItem( n, pix, txt, hasPixmap ); QIconView *iv = (QIconView*)widget; if ( hasPixmap ) new QIconViewItem( iv, txt, pix ); else new QIconViewItem( iv, txt ); } else if ( widget->inherits( "QListView" ) ) { QDomElement n = e.firstChild().toElement(); QPixmap pix; QValueList<QPixmap> pixmaps; QStringList textes; QListViewItem *item = 0; QListView *lv = (QListView*)widget; if ( i ) item = new QListViewItem( i, lastItem ); else item = new QListViewItem( lv, lastItem ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) { QString attrib = n.attribute( "name" ); QVariant v = DomTool::elementToVariant( n.firstChild().toElement(), QVariant() ); if ( attrib == "text" ) textes << v.toString(); else if ( attrib == "pixmap" ) { QString s = v.toString(); if ( s.isEmpty() ) { pixmaps << QPixmap(); } else { pix = loadPixmap( n.firstChild().toElement() ); pixmaps << pix; } } } else if ( n.tagName() == "item" ) { item->setOpen( TRUE ); createItem( n, widget, item ); } n = n.nextSibling().toElement(); } for ( int i = 0; i < lv->columns(); ++i ) { item->setText( i, textes[ i ] ); item->setPixmap( i, pixmaps[ i ] ); } lastItem = item; }}QWidget *Resource::createSpacer( const QDomElement &e, QWidget *parent, QLayout *layout, Qt::Orientation o ){ QDomElement n = e.firstChild().toElement(); int row = e.attribute( "row" ).toInt(); int col = e.attribute( "column" ).toInt(); int rowspan = e.attribute( "rowspan" ).toInt(); int colspan = e.attribute( "colspan" ).toInt(); if ( rowspan < 1 ) rowspan = 1; if ( colspan < 1 ) colspan = 1; Spacer *spacer = (Spacer*) WidgetFactory::create( WidgetDatabase::idFromClassName("Spacer"), parent, "spacer", FALSE); spacer->setOrientation( o ); spacer->setInteraciveMode( FALSE ); while ( !n.isNull() ) { if ( n.tagName() == "property" ) setObjectProperty( spacer, n.attribute( "name" ), n.firstChild().toElement() ); n = n.nextSibling().toElement(); } spacer->setInteraciveMode( TRUE ); if ( formwindow ) formwindow->insertWidget( spacer, pasting ); if ( layout ) { if ( layout->inherits( "QBoxLayout" ) ) ( (QBoxLayout*)layout )->addWidget( spacer, 0, spacer->alignment() ); else ( (QDesignerGridLayout*)layout )->addMultiCellWidget( spacer, row, row + rowspan - 1, col, col + colspan - 1, spacer->alignment() ); } return spacer;}/*! Attention: this function has to be in sync with Uic::setObjectProperty(). If you change one, change both.*/void Resource::setObjectProperty( QObject* obj, const QString &prop, const QDomElement &e ){ const QMetaProperty *p = obj->metaObject()->property( obj->metaObject()->findProperty( prop, TRUE ), TRUE ); if ( !obj->inherits( "QLayout" ) ) {// no layouts in metadatabase... (RS) if ( obj->inherits( "CustomWidget" ) ) { MetaDataBase::CustomWidget *cw = ( (CustomWidget*)obj )->customWidget(); if ( cw && !cw->hasProperty( prop.latin1() ) && !p && prop != "toolTip" && prop != "whatsThis" ) return; } MetaDataBase::setPropertyChanged( obj, prop, TRUE ); } QVariant defVarient; if ( e.tagName() == "font" ) { QFont f( qApp->font() ); if ( obj->isWidgetType() && ( (QWidget*)obj )->parentWidget() ) f = ( (QWidget*)obj )->parentWidget()->font(); defVarient = QVariant( f ); } QString comment; QVariant v( DomTool::elementToVariant( e, defVarient, comment ) ); if ( !comment.isEmpty() ) { MetaDataBase::addEntry( obj ); MetaDataBase::setPropertyComment( obj, prop, comment ); } if ( e.tagName() == "pixmap" ) { QPixmap pix = loadPixmap( e ); if ( pix.isNull() ) return; v = QVariant( pix ); } else if ( e.tagName() == "iconset" ) { QPixmap pix = loadPixmap( e, "iconset" ); if ( pix.isNull() ) return; v = QVariant( QIconSet( pix ) ); } else if ( e.tagName() == "image" ) { v = QVariant( loadFromCollection( v.toString() ) ); } if ( !p ) { MetaDataBase::setFakeProperty( obj, prop, v ); if ( obj->isWidgetType() ) { if ( prop == "database" && obj != toplevel ) { QStringList lst = MetaDataBase::fakeProperty( obj, "database" ).toStringList(); if ( lst.count() > 2 ) dbControls.insert( obj->name(), lst[ 2 ] ); else if ( lst.count() == 2 ) dbTables.insert( obj->name(), lst ); } return; } } if ( e.tagName() == "palette" ) { QDomElement n = e.firstChild().toElement(); QPalette p; while ( !n.isNull() ) { QColorGroup cg; if ( n.tagName() == "active" ) { cg = loadColorGroup( n ); p.setActive( cg ); } else if ( n.tagName() == "inactive" ) { cg = loadColorGroup( n ); p.setInactive( cg ); } else if ( n.tagName() == "disabled" ) { cg = loadColorGroup( n ); p.setDisabled( cg ); } n = n.nextSibling().toElement(); } v = QPalette( p ); } else if ( e.tagName() == "enum" && p && p->isEnumType() ) { QString key( v.toString() ); int vi = p->keyToValue( key ); if ( p->valueToKey( vi ) != key ) return; // ignore invalid properties v = QVariant( vi ); } else if ( e.tagName() == "set" && p && p->isSetType() ) { QString keys( v.toString() ); QStringList lst = QStringList::split( '|', keys ); QStrList l; for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) l.append( *it ); v = QVariant( p->keysToValue( l ) ); } if ( prop == "caption" ) { QCString s1 = v.toCString(); QString s2 = v.toStri
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -