Skip to content
Permalink
Browse files
Synchronize values of repeating widgets on forms
Fix #10877
  • Loading branch information
m-kuhn committed Jul 22, 2014
1 parent 9f07383 commit 55c6f8f1b34178a5c222236b757bf02568288994
Showing with 24 additions and 3 deletions.
  1. +22 −3 src/gui/qgsattributeform.cpp
  2. +2 −0 src/gui/qgsattributeform.h
@@ -393,7 +393,7 @@ void QgsAttributeForm::init()
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 );
addWidgetWrapper( eww );

if ( labelOnTop )
{
@@ -522,7 +522,7 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement

QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, fldIdx, widgetConfig, 0, this, mContext );
newWidget = eww->widget();
mWidgets.append( eww );
addWidgetWrapper( eww );
}

labelOnTop = mLayer->labelOnTop( fieldDef->idx() );
@@ -618,6 +618,25 @@ QWidget* QgsAttributeForm::createWidgetFromDef( const QgsAttributeEditorElement
return newWidget;
}

void QgsAttributeForm::addWidgetWrapper( QgsEditorWidgetWrapper* eww )
{
Q_FOREACH( QgsWidgetWrapper* ww, mWidgets )
{
QgsEditorWidgetWrapper* meww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
if ( meww )
{
if ( meww->field() == eww->field() )
{
connect( meww, SIGNAL(valueChanged(QVariant)), eww, SLOT(setValue(QVariant)) );
connect( eww, SIGNAL(valueChanged(QVariant)), meww, SLOT(setValue(QVariant)) );
break;
}
}
}

mWidgets.append( eww );
}

void QgsAttributeForm::createWrappers()
{
QList<QWidget*> myWidgets = findChildren<QWidget*>();
@@ -650,7 +669,7 @@ void QgsAttributeForm::createWrappers()
int idx = mLayer->fieldNameIndex( field.name() );

QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, mLayer, idx, widgetConfig, myWidget, this, mContext );
mWidgets.append( eww );
addWidgetWrapper( eww );
}
}
}
@@ -174,6 +174,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget

QWidget* createWidgetFromDef( const QgsAttributeEditorElement* widgetDef, QWidget* parent, QgsVectorLayer* vl, QgsAttributeEditorContext& context, QString& labelText, bool& labelOnTop );

void addWidgetWrapper( QgsEditorWidgetWrapper* eww );

/**
* Creates widget wrappers for all suitable widgets found.
* Called once maximally.

0 comments on commit 55c6f8f

Please sign in to comment.