Skip to content

Commit

Permalink
re-add support for top labeled editor widgets in default forms (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 9, 2014
1 parent 4ff233e commit a59b54e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/app/qgsfieldsproperties.cpp
Expand Up @@ -407,9 +407,11 @@ void QgsFieldsProperties::attributeTypeDialog()
if ( index == -1 )
return;


QgsAttributeTypeDialog attributeTypeDialog( mLayer, index );

attributeTypeDialog.setFieldEditable( cfg.mEditable );
attributeTypeDialog.setLabelOnTop( cfg.mLabelOnTop );

attributeTypeDialog.setWidgetV2Config( cfg.mEditorWidgetV2Config );
attributeTypeDialog.setWidgetV2Type( cfg.mEditorWidgetV2Type );

Expand Down Expand Up @@ -737,6 +739,9 @@ void QgsFieldsProperties::apply()
int idx = mFieldsList->item( i, attrIdCol )->text().toInt();
FieldConfig cfg = configForRow( i );

mLayer->setFieldEditable( i, cfg.mEditable );
mLayer->setLabelOnTop( i, cfg.mLabelOnTop );

mLayer->setEditorWidgetV2( idx, cfg.mEditorWidgetV2Type );
mLayer->setEditorWidgetV2Config( idx, cfg.mEditorWidgetV2Config );

Expand Down
25 changes: 17 additions & 8 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -349,10 +349,11 @@ void QgsAttributeForm::init()
if ( !formWidget )
{
formWidget = new QWidget( this );
QFormLayout* formLayout = new QFormLayout( formWidget );
formWidget->setLayout( formLayout );
QGridLayout* gridLayout = new QGridLayout( formWidget );
formWidget->setLayout( gridLayout );
layout()->addWidget( formWidget );

int row = 0;
Q_FOREACH( const QgsField& field, mLayer->pendingFields().toList() )
{
int idx = mLayer->fieldNameIndex( field.name() );
Expand All @@ -361,25 +362,33 @@ void QgsAttributeForm::init()

const QString widgetType = mLayer->editorWidgetV2( idx );
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( idx );
bool labelOnTop = mLayer->labelOnTop( idx );

// This will also create the widget
QWidget *l = new QLabel( fieldName );
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, idx, widgetConfig, 0, this, mContext );
QWidget *w = eww ? eww->widget() : new QLabel( QString( "<p style=\"color: red; font-style: italic;\">Failed to create widget with type '%1'</p>" ).arg( widgetType ) );

if ( eww )
{
mWidgets.append( eww );
formLayout->addRow( new QLabel( fieldName ), eww->widget() );

if ( labelOnTop )
{
gridLayout->addWidget( l, row++, 0, 1, 2 );
gridLayout->addWidget( w, row++, 0, 1, 2 );
}
else
{
formLayout->addRow( new QLabel( fieldName ), new QLabel( QString( "<p style=\"color: red; font-style: italic;\">Failed to create widget with type '%1'</p>" ).arg( widgetType ) ) );
gridLayout->addWidget( l, row, 0 );
gridLayout->addWidget( w, row++, 1 );
}
}

Q_FOREACH( const QgsRelation& rel, QgsProject::instance()->relationManager()->referencedRelations( mLayer ) )
{
QgsRelationWidgetWrapper* rww = new QgsRelationWidgetWrapper( mLayer, rel, 0, this );
rww->setContext( mContext );
formLayout->addRow( rww->widget() );
gridLayout->addWidget( rww->widget(), row++, 0, 1, 2 );
mWidgets.append( rww );
}
}
Expand Down Expand Up @@ -472,7 +481,7 @@ void QgsAttributeForm::initPython()
}
}

QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeEditorContext& context, QString& labelText, bool& labelOnTop )
QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, QgsAttributeEditorContext &context, QString &labelText, bool &labelOnTop )
{
QWidget *newWidget = 0;

Expand Down Expand Up @@ -548,7 +557,7 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement*
bool labelOnTop;
QWidget* editor = createWidgetFromDef( childDef, myContainer, vl, context, labelText, labelOnTop );

if ( labelText == QString::null )
if ( labelText.isNull() )
{
gbLayout->addWidget( editor, index, 0, 1, 2 );
}
Expand Down

0 comments on commit a59b54e

Please sign in to comment.