Skip to content
Permalink
Browse files

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 c11ef583ce97b1f8dda4b64e640d55545fbf9b6a
@@ -32,5 +32,7 @@ class QgsEditorConfigWidget : QWidget

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

@@ -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();
}

@@ -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;
@@ -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() );
@@ -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() );

@@ -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() );

@@ -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();

0 comments on commit c11ef58

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