Skip to content

Commit

Permalink
restore naming of generated attribute widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 24, 2014
1 parent af7f036 commit 693c2e7
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -301,7 +301,7 @@ void QgsAttributeForm::init()
{
delete w;
}
delete this->layout();
delete layout();

// Get a layout
setLayout( new QGridLayout( this ) );
Expand Down Expand Up @@ -366,6 +366,7 @@ void QgsAttributeForm::init()
formWidget->setLayout( gridLayout );

// put the form into a scroll area to nicely handle cases with lots of attributes

QScrollArea* scrollArea = new QScrollArea( this );
scrollArea->setWidget( formWidget );
scrollArea->setWidgetResizable( true );
Expand All @@ -383,29 +384,32 @@ void QgsAttributeForm::init()

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

if ( widgetType != "Hidden" )
{
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( idx );
bool labelOnTop = mLayer->labelOnTop( idx );
if ( widgetType == "Hidden" )
continue;

// 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 ) );
const QgsEditorWidgetConfig widgetConfig = mLayer->editorWidgetV2Config( idx );
bool labelOnTop = mLayer->labelOnTop( idx );

if ( eww )
addWidgetWrapper( eww );
// 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 ( labelOnTop )
{
gridLayout->addWidget( l, row++, 0, 1, 2 );
gridLayout->addWidget( w, row++, 0, 1, 2 );
}
else
{
gridLayout->addWidget( l, row, 0 );
gridLayout->addWidget( w, row++, 1 );
}
if ( w )
w->setObjectName( field.name() );

if ( eww )
addWidgetWrapper( eww );

if ( labelOnTop )
{
gridLayout->addWidget( l, row++, 0, 1, 2 );
gridLayout->addWidget( w, row++, 0, 1, 2 );
}
else
{
gridLayout->addWidget( l, row, 0 );
gridLayout->addWidget( w, row++, 1 );
}
}

Expand Down Expand Up @@ -524,10 +528,13 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement
QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0, this, mContext );
newWidget = eww->widget();
addWidgetWrapper( eww );

newWidget->setObjectName( mLayer->pendingFields()[ fldIdx ].name() );
}

labelOnTop = mLayer->labelOnTop( fieldDef->idx() );
labelText = mLayer->attributeDisplayName( fieldDef->idx() );

break;
}

Expand Down Expand Up @@ -628,8 +635,8 @@ void QgsAttributeForm::addWidgetWrapper( QgsEditorWidgetWrapper* eww )
{
if ( meww->field() == eww->field() )
{
connect( meww, SIGNAL(valueChanged(QVariant)), eww, SLOT(setValue(QVariant)) );
connect( eww, SIGNAL(valueChanged(QVariant)), meww, SLOT(setValue(QVariant)) );
connect( meww, SIGNAL( valueChanged( QVariant ) ), eww, SLOT( setValue( QVariant ) ) );
connect( eww, SIGNAL( valueChanged( QVariant ) ), meww, SLOT( setValue( QVariant ) ) );
break;
}
}
Expand Down

0 comments on commit 693c2e7

Please sign in to comment.