Skip to content
Permalink
Browse files

Merge pull request #3704 from pvalsecc/fix_collapsing

Fix saving of the collapsed state for relations
  • Loading branch information
nyalldawson committed Nov 2, 2016
2 parents 5d877fd + 28457ed commit 4f5337fce5b6def103a34fb89e21b0c648711c86
@@ -86,6 +86,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
, mRubberBand( nullptr )
, mCurrentSearchWidgetWrapper( nullptr )
{
setObjectName( QStringLiteral( "QgsAttributeTableDialog/" ) + theLayer->id() );
setupUi( this );

Q_FOREACH ( const QgsField& field, mLayer->fields() )
@@ -195,6 +195,7 @@ void QgsRelationReferenceWidget::setRelation( const QgsRelation& relation, bool
mReferencedLayer = relation.referencedLayer();
mReferencedFieldIdx = mReferencedLayer->fields().lookupField( relation.fieldPairs().at( 0 ).second );
mReferencingFieldIdx = mReferencingLayer->fields().lookupField( relation.fieldPairs().at( 0 ).first );
mAttributeEditorFrame->setObjectName( QStringLiteral( "referencing/" ) + relation.name() );

QgsAttributeEditorContext context( mEditorContext, relation, QgsAttributeEditorContext::Single, QgsAttributeEditorContext::Embed );

@@ -76,6 +76,7 @@ void QgsRelationReferenceWidgetWrapper::initWidget( QWidget* editor )
mWidget->setEmbedForm( false );
mWidget->setReadOnlySelector( false );
mWidget->setAllowMapIdentification( false );
break;
}
ctx = ctx->parentContext();
}
@@ -522,6 +522,8 @@ void QgsCollapsibleGroupBox::init()
// in multiple places or used as options for different parent objects
mSaveCheckedState = false;
mSettingGroup = QLatin1String( "" ); // if not set, use window object name

connect( this, &QObject::objectNameChanged, this, &QgsCollapsibleGroupBox::loadState );
}

void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
@@ -547,6 +549,9 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )

QString QgsCollapsibleGroupBox::saveKey() const
{
if ( objectName().isEmpty() || ( mSettingGroup.isEmpty() && window()->objectName().isEmpty() ) )
return QString(); // cannot get a valid key

// save key for load/save state
// currently QgsCollapsibleGroupBox/window()/object
QString saveKey = '/' + objectName();
@@ -558,9 +563,9 @@ QString QgsCollapsibleGroupBox::saveKey() const
// }
// if ( parent() )
// saveKey = "/" + parent()->objectName() + saveKey;
QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup;
const QString setgrp = mSettingGroup.isEmpty() ? window()->objectName() : mSettingGroup;
saveKey = '/' + setgrp + saveKey;
saveKey = "QgsCollapsibleGroupBox" + saveKey;
saveKey = QStringLiteral( "QgsCollapsibleGroupBox" ) + saveKey;
return saveKey;
}

@@ -572,19 +577,21 @@ void QgsCollapsibleGroupBox::loadState()
if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
return;

const QString key = saveKey();
if ( key.isEmpty() )
return;

setUpdatesEnabled( false );

QString key = saveKey();
QVariant val;
if ( mSaveCheckedState )
{
val = mSettings->value( key + "/checked" );
QVariant val = mSettings->value( key + "/checked" );
if ( ! val.isNull() )
setChecked( val.toBool() );
}
if ( mSaveCollapsedState )
{
val = mSettings->value( key + "/collapsed" );
QVariant val = mSettings->value( key + "/collapsed" );
if ( ! val.isNull() )
setCollapsed( val.toBool() );
}
@@ -597,14 +604,16 @@ void QgsCollapsibleGroupBox::saveState() const
if ( !mSettings )
return;

if ( !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
if ( !mShown || !isEnabled() || ( !mSaveCollapsedState && !mSaveCheckedState ) )
return;

QString key = saveKey();
const QString key = saveKey();
if ( key.isEmpty() )
return;

if ( mSaveCheckedState )
mSettings->setValue( key + "/checked", isChecked() );
mSettings->setValue( key + QStringLiteral( "/checked" ), isChecked() );
if ( mSaveCollapsedState )
mSettings->setValue( key + "/collapsed", isCollapsed() );
mSettings->setValue( key + QStringLiteral( "/collapsed" ), isCollapsed() );
}

@@ -170,8 +170,7 @@ void QgsRelationEditorWidget::setRelationFeature( const QgsRelation& relation, c
mToggleEditingButton->setEnabled( false );
}

setObjectName( mRelation.name() );
loadState();
setObjectName( QStringLiteral( "referenced/" ) + mRelation.name() );

// If not yet initialized, it is not (yet) visible, so we don't load it to be faster (lazy loading)
// If it is already initialized, it has been set visible before and the currently shown feature is changing
@@ -240,8 +239,7 @@ void QgsRelationEditorWidget::setRelations( const QgsRelation& relation, const Q
mToggleEditingButton->setEnabled( false );
}

setObjectName( mRelation.name() );
loadState();
setObjectName( QStringLiteral( "referenced/" ) + mRelation.name() );

updateUi();
}

0 comments on commit 4f5337f

Please sign in to comment.
You can’t perform that action at this time.