QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapper* editorWidget, QgsAttributeForm* form )
    : QWidget( form )
    , mWidget( editorWidget )
    , mForm( form )
    , mMode( DefaultMode )
    , mMultiEditButton( new QgsMultiEditToolButton() )
    , mBlockValueUpdate( false )
    , mIsMixed( false )
    , mIsChanged( false )
{
  if ( !mWidget || !mForm )
    return;

  QLayout* l = new QHBoxLayout();
  l->setMargin( 0 );
  l->setContentsMargins( 0, 0, 0, 0 );
  l->addWidget( mWidget->widget() );

  if ( mWidget->widget() )
  {
    mWidget->widget()->setObjectName( mWidget->field().name() );
  }
  connect( mWidget, SIGNAL( valueChanged( const QVariant& ) ), this, SLOT( editorWidgetChanged( const QVariant & ) ) );
  connect( mMultiEditButton, SIGNAL( resetFieldValueTriggered() ), this, SLOT( resetValue() ) );
  connect( mMultiEditButton, SIGNAL( setFieldValueTriggered() ), this, SLOT( setFieldTriggered() ) );

  mMultiEditButton->setField( mWidget->field() );

  setLayout( l );
  updateWidgets();
}
void QgsMultiEditToolButton::setFieldTriggered()
{
  mIsChanged = true;
  updateState();
  emit setFieldValueTriggered();
}