Skip to content

Commit 693c2e7

Browse files
committed
restore naming of generated attribute widgets
1 parent af7f036 commit 693c2e7

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

src/gui/qgsattributeform.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void QgsAttributeForm::init()
301301
{
302302
delete w;
303303
}
304-
delete this->layout();
304+
delete layout();
305305

306306
// Get a layout
307307
setLayout( new QGridLayout( this ) );
@@ -366,6 +366,7 @@ void QgsAttributeForm::init()
366366
formWidget->setLayout( gridLayout );
367367

368368
// put the form into a scroll area to nicely handle cases with lots of attributes
369+
369370
QScrollArea* scrollArea = new QScrollArea( this );
370371
scrollArea->setWidget( formWidget );
371372
scrollArea->setWidgetResizable( true );
@@ -383,29 +384,32 @@ void QgsAttributeForm::init()
383384

384385
const QString widgetType = mLayer->editorWidgetV2( idx );
385386

386-
if ( widgetType != "Hidden" )
387-
{
388-
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( idx );
389-
bool labelOnTop = mLayer->labelOnTop( idx );
387+
if ( widgetType == "Hidden" )
388+
continue;
390389

391-
// This will also create the widget
392-
QWidget *l = new QLabel( fieldName );
393-
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, idx, widgetConfig, 0, this, mContext );
394-
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 ) );
390+
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( idx );
391+
bool labelOnTop = mLayer->labelOnTop( idx );
395392

396-
if ( eww )
397-
addWidgetWrapper( eww );
393+
// This will also create the widget
394+
QWidget *l = new QLabel( fieldName );
395+
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, idx, widgetConfig, 0, this, mContext );
396+
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 ) );
398397

399-
if ( labelOnTop )
400-
{
401-
gridLayout->addWidget( l, row++, 0, 1, 2 );
402-
gridLayout->addWidget( w, row++, 0, 1, 2 );
403-
}
404-
else
405-
{
406-
gridLayout->addWidget( l, row, 0 );
407-
gridLayout->addWidget( w, row++, 1 );
408-
}
398+
if ( w )
399+
w->setObjectName( field.name() );
400+
401+
if ( eww )
402+
addWidgetWrapper( eww );
403+
404+
if ( labelOnTop )
405+
{
406+
gridLayout->addWidget( l, row++, 0, 1, 2 );
407+
gridLayout->addWidget( w, row++, 0, 1, 2 );
408+
}
409+
else
410+
{
411+
gridLayout->addWidget( l, row, 0 );
412+
gridLayout->addWidget( w, row++, 1 );
409413
}
410414
}
411415

@@ -524,10 +528,13 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement
524528
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0, this, mContext );
525529
newWidget = eww->widget();
526530
addWidgetWrapper( eww );
531+
532+
newWidget->setObjectName( mLayer->pendingFields()[ fldIdx ].name() );
527533
}
528534

529535
labelOnTop = mLayer->labelOnTop( fieldDef->idx() );
530536
labelText = mLayer->attributeDisplayName( fieldDef->idx() );
537+
531538
break;
532539
}
533540

@@ -628,8 +635,8 @@ void QgsAttributeForm::addWidgetWrapper( QgsEditorWidgetWrapper* eww )
628635
{
629636
if ( meww->field() == eww->field() )
630637
{
631-
connect( meww, SIGNAL(valueChanged(QVariant)), eww, SLOT(setValue(QVariant)) );
632-
connect( eww, SIGNAL(valueChanged(QVariant)), meww, SLOT(setValue(QVariant)) );
638+
connect( meww, SIGNAL( valueChanged( QVariant ) ), eww, SLOT( setValue( QVariant ) ) );
639+
connect( eww, SIGNAL( valueChanged( QVariant ) ), meww, SLOT( setValue( QVariant ) ) );
633640
break;
634641
}
635642
}

0 commit comments

Comments
 (0)