Generalise editor widget config saving/restoring props from gui

This commit is contained in:
Nyall Dawson 2017-03-10 07:31:11 +10:00 committed by Matthias Kuhn
parent bea83775f8
commit c11ef583ce
4 changed files with 47 additions and 5 deletions

View File

@ -32,5 +32,7 @@ class QgsEditorConfigWidget : QWidget
protected:
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsWidgetWrapper::Property key );
void updateDataDefinedButtons();
void updateDataDefinedButton( QgsPropertyOverrideButton *button );
};

View File

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

View File

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

View File

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