Skip to content

Commit

Permalink
Merge pull request #5699 from m-kuhn/valueRelationMultiSelect
Browse files Browse the repository at this point in the history
Fixes for Value relation widget, multi select
  • Loading branch information
m-kuhn committed Nov 23, 2017
2 parents 9d8a39f + b448826 commit e98842e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
Expand Up @@ -29,7 +29,6 @@

QgsValueRelationWidgetWrapper::QgsValueRelationWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent )
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
, mUpdating( false )
{
}

Expand Down Expand Up @@ -150,7 +149,11 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
{
if ( mListWidget )
{
QStringList checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );
QStringList checkList;
if ( value.type() == QVariant::StringList )
checkList = value.toStringList();
else if ( value.type() == QVariant::String )
checkList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );

for ( int i = 0; i < mListWidget->count(); ++i )
{
Expand Down Expand Up @@ -198,12 +201,13 @@ void QgsValueRelationWidgetWrapper::showIndeterminateState()

void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
{
if ( mUpdating )
if ( mEnabled == enabled )
return;

mEnabled = enabled;

if ( mListWidget )
{
mUpdating = true;
for ( int i = 0; i < mListWidget->count(); ++i )
{
QListWidgetItem *item = mListWidget->item( i );
Expand All @@ -213,7 +217,6 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
else
item->setFlags( item->flags() & ~Qt::ItemIsEnabled );
}
mUpdating = false;
}
else
QgsEditorWidgetWrapper::setEnabled( enabled );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h
Expand Up @@ -78,7 +78,7 @@ class GUI_EXPORT QgsValueRelationWidgetWrapper : public QgsEditorWidgetWrapper
QgsValueRelationFieldFormatter::ValueRelationCache mCache;
QgsVectorLayer *mLayer = nullptr;

bool mUpdating;
bool mEnabled = false;

friend class QgsValueRelationWidgetFactory;
friend class TestQgsValueRelationWidgetWrapper;
Expand Down

0 comments on commit e98842e

Please sign in to comment.