Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Generalise editor widget config saving/restoring props from gui
  • Loading branch information
nyalldawson authored and m-kuhn committed Mar 10, 2017
1 parent bea8377 commit c11ef58
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 2 additions & 0 deletions python/gui/editorwidgets/core/qgseditorconfigwidget.sip
Expand Up @@ -32,5 +32,7 @@ class QgsEditorConfigWidget : QWidget

protected:
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key );
void updateDataDefinedButtons();
void updateDataDefinedButton( QgsPropertyOverrideButton *button );
};

30 changes: 29 additions & 1 deletion src/gui/editorwidgets/core/qgseditorconfigwidget.cpp
Expand Up @@ -43,8 +43,36 @@ void QgsEditorConfigWidget::initializeDataDefinedButton( QgsPropertyOverrideButt
{
button->blockSignals( true );
button->init( key, mPropertyCollection, QgsWidgetWrapper::propertyDefinitions(), mLayer );
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::changed );
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsEditorConfigWidget::updateProperty );
button->registerExpressionContextGenerator( this );
button->blockSignals( false );
}

void QgsEditorConfigWidget::updateDataDefinedButtons()
{
Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() )
{
updateDataDefinedButton( button );
}
}

void QgsEditorConfigWidget::updateDataDefinedButton( QgsPropertyOverrideButton *button )
{
if ( !button )
return;

if ( button->propertyKey() < 0 )
return;

QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
whileBlocking( button )->setToProperty( mPropertyCollection.property( key ) );
}

void QgsEditorConfigWidget::updateProperty()
{
QgsPropertyOverrideButton *button = qobject_cast<QgsPropertyOverrideButton *>( sender() );
QgsWidgetWrapper::Property key = static_cast< QgsWidgetWrapper::Property >( button->propertyKey() );
mPropertyCollection.setProperty( key, button->toProperty() );
emit changed();
}

14 changes: 14 additions & 0 deletions src/gui/editorwidgets/core/qgseditorconfigwidget.h
Expand Up @@ -92,9 +92,23 @@ class GUI_EXPORT QgsEditorConfigWidget : public QWidget, public QgsExpressionCon
*/
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key );

/**
* Updates all property override buttons to reflect the widgets's current properties.
*/
void updateDataDefinedButtons();

/**
* Updates a specific property override \a button to reflect the widgets's current properties.
*/
void updateDataDefinedButton( QgsPropertyOverrideButton *button );

//! Temporary property collection for config widgets
QgsPropertyCollection mPropertyCollection;

private slots:

void updateProperty();

private:
QgsVectorLayer *mLayer = nullptr;
int mField;
Expand Down
6 changes: 2 additions & 4 deletions src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp
Expand Up @@ -100,7 +100,6 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath()
void QgsExternalResourceConfigDlg::rootPathPropertyChanged()
{
QgsProperty prop = mRootPathPropertyOverrideButton->toProperty();
mPropertyCollection.setProperty( QgsWidgetWrapper::RootPath, prop );
setRootPathExpression( prop );

mRootPathExpression->setVisible( prop.isActive() );
Expand Down Expand Up @@ -152,8 +151,6 @@ QVariantMap QgsExternalResourceConfigDlg::config()
if ( !mRootPath->text().isEmpty() )
cfg.insert( QStringLiteral( "DefaultRoot" ), mRootPath->text() );

cfg.insert( QStringLiteral( "RootPathProperty" ), mRootPathPropertyOverrideButton->toProperty().toVariant() );

// Save Storage Mode
cfg.insert( QStringLiteral( "StorageMode" ), mStorageButtonGroup->checkedId() );

Expand Down Expand Up @@ -205,6 +202,8 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )
}

mPropertyCollection.loadVariant( config.value( QStringLiteral( "PropertyCollection" ) ), QgsWidgetWrapper::propertyDefinitions() );
updateDataDefinedButtons();

setRootPathExpression( mPropertyCollection.property( QgsWidgetWrapper::RootPath ) );
mRootPath->setText( config.value( QStringLiteral( "DefaultRoot" ) ).toString() );

Expand Down Expand Up @@ -255,7 +254,6 @@ void QgsExternalResourceConfigDlg::setConfig( const QVariantMap &config )

void QgsExternalResourceConfigDlg::setRootPathExpression( const QgsProperty &property )
{
mRootPathPropertyOverrideButton->setToProperty( property );
mRootPathExpression->setToolTip( property.asExpression() );

QgsExpressionContext ctx = layer()->createExpressionContext();
Expand Down

0 comments on commit c11ef58

Please sign in to comment.