QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap<int, QWidget*> &proxyWidgets ) { Q_UNUSED( proxyWidgets ) QgsAttributeEditorContext context; return createAttributeEditor( parent, editor, vl, idx, value, context ); }
QWidget* QgsAttributeEditor::createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeMap &attrs, QMap<int, QWidget*> &proxyWidgets, bool createGroupBox ) { QWidget *newWidget = 0; switch ( widgetDef->type() ) { case QgsAttributeEditorElement::AeTypeField: { const QgsAttributeEditorField* fieldDef = dynamic_cast<const QgsAttributeEditorField*>( widgetDef ); newWidget = createAttributeEditor( parent, 0, vl, fieldDef->idx(), attrs.value( fieldDef->idx(), QVariant() ), proxyWidgets ); if ( vl->editType( fieldDef->idx() ) != QgsVectorLayer::Immutable ) { newWidget->setEnabled( newWidget->isEnabled() && vl->isEditable() ); } break; } case QgsAttributeEditorElement::AeTypeContainer: { const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef ); QWidget* myContainer; if ( createGroupBox ) { QGroupBox* groupBox = new QGroupBox( parent ); groupBox->setTitle( container->name() ); myContainer = groupBox; } else { myContainer = new QWidget( parent ); } QGridLayout* gbLayout = new QGridLayout( myContainer ); int index = 0; QList<QgsAttributeEditorElement*>children = container->children(); for ( QList<QgsAttributeEditorElement*>::const_iterator it = children.begin(); it != children.end(); ++it ) { QgsAttributeEditorElement* childDef = *it; QWidget* editor = createWidgetFromDef( childDef, myContainer, vl, attrs, proxyWidgets, true ); if ( childDef->type() == QgsAttributeEditorElement::AeTypeContainer ) { gbLayout->addWidget( editor, index, 0, 1, 2 ); } else { QLabel * mypLabel = new QLabel( myContainer ); gbLayout->addWidget( mypLabel, index, 0 ); mypLabel->setText( childDef->name() ); gbLayout->addWidget( editor, index, 1 ); } ++index; } gbLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding ), index , 0 ); newWidget = myContainer; break; } default: QgsDebugMsg( "Unknown attribute editor widget type encountered..." ); break; } return newWidget; }
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { QgsAttributeEditorContext context; return createAttributeEditor( parent, editor, vl, idx, value, context ); }
QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value ) { QMap<int, QWidget*> dummyProxyWidgets; return createAttributeEditor( parent, editor, vl, idx, value, dummyProxyWidgets ); }