diff --git a/python/gui/qgspropertyoverridebutton.sip b/python/gui/qgspropertyoverridebutton.sip index 07940dd991a..2f7bbe2908b 100644 --- a/python/gui/qgspropertyoverridebutton.sip +++ b/python/gui/qgspropertyoverridebutton.sip @@ -42,25 +42,29 @@ class QgsPropertyOverrideButton: QToolButton void init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, - const QgsVectorLayer *layer = 0 ); + const QgsVectorLayer *layer = 0, + bool auxiliaryStorageEnabled = false ); %Docstring Initialize a newly constructed property button (useful if button was included in a UI layout). \param propertyKey key for corresponding property \param property initial value of associated property to show in widget \param definitions properties definitions for corresponding collection \param layer associated vector layer + \param auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage %End void init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, - const QgsVectorLayer *layer = 0 ); + const QgsVectorLayer *layer = 0, + bool auxiliaryStorageEnabled = false ); %Docstring Initialize a newly constructed property button (useful if button was included in a UI layout). \param propertyKey key for corresponding property \param collection associated property collection \param definitions properties definitions for collection \param layer associated vector layer + \param auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage %End QgsProperty toProperty() const; diff --git a/src/app/qgsdiagramproperties.cpp b/src/app/qgsdiagramproperties.cpp index 078101b99f9..cb48f57ccfe 100644 --- a/src/app/qgsdiagramproperties.cpp +++ b/src/app/qgsdiagramproperties.cpp @@ -486,7 +486,7 @@ QgsDiagramProperties::~QgsDiagramProperties() void QgsDiagramProperties::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsDiagramLayerSettings::Property key ) { - button->init( key, mDataDefinedProperties, QgsDiagramLayerSettings::propertyDefinitions(), mLayer ); + button->init( key, mDataDefinedProperties, QgsDiagramLayerSettings::propertyDefinitions(), mLayer, true ); connect( button, &QgsPropertyOverrideButton::changed, this, &QgsDiagramProperties::updateProperty ); connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsDiagramProperties::createAuxiliaryField ); button->registerExpressionContextGenerator( this ); diff --git a/src/app/qgslabelinggui.cpp b/src/app/qgslabelinggui.cpp index d3fd2ae466d..f2e958cd2a3 100644 --- a/src/app/qgslabelinggui.cpp +++ b/src/app/qgslabelinggui.cpp @@ -46,7 +46,7 @@ QgsExpressionContext QgsLabelingGui::createExpressionContext() const void QgsLabelingGui::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key ) { - button->init( key, mDataDefinedProperties, QgsPalLayerSettings::propertyDefinitions(), mLayer ); + button->init( key, mDataDefinedProperties, QgsPalLayerSettings::propertyDefinitions(), mLayer, true ); connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLabelingGui::updateProperty ); connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsLabelingGui::createAuxiliaryField ); button->registerExpressionContextGenerator( this ); diff --git a/src/gui/qgspropertyoverridebutton.cpp b/src/gui/qgspropertyoverridebutton.cpp index 91c46b460d9..e0a1ea5751c 100644 --- a/src/gui/qgspropertyoverridebutton.cpp +++ b/src/gui/qgspropertyoverridebutton.cpp @@ -83,9 +83,10 @@ QgsPropertyOverrideButton::QgsPropertyOverrideButton( QWidget *parent, } -void QgsPropertyOverrideButton::init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer ) +void QgsPropertyOverrideButton::init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer, bool auxiliaryStorageEnabled ) { mVectorLayer = layer; + mAuxiliaryStorageEnabled = auxiliaryStorageEnabled; setToProperty( property ); mPropertyKey = propertyKey; @@ -126,9 +127,9 @@ void QgsPropertyOverrideButton::init( int propertyKey, const QgsProperty &proper updateGui(); } -void QgsPropertyOverrideButton::init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer ) +void QgsPropertyOverrideButton::init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, const QgsVectorLayer *layer, bool auxiliaryStorageEnabled ) { - init( propertyKey, collection.property( propertyKey ), definitions, layer ); + init( propertyKey, collection.property( propertyKey ), definitions, layer, auxiliaryStorageEnabled ); } @@ -334,18 +335,21 @@ void QgsPropertyOverrideButton::aboutToShowMenu() mDefineMenu->addSeparator(); // deactivate button if field already exists - mDefineMenu->addAction( mActionCreateAuxiliaryField ); - - const QgsAuxiliaryLayer *alayer = mVectorLayer->auxiliaryLayer(); - - mActionCreateAuxiliaryField->setEnabled( true ); - mActionCreateAuxiliaryField->setChecked( false ); - if ( alayer && alayer->exists( mDefinition ) ) + if ( mAuxiliaryStorageEnabled ) { - if ( mProperty.field() == QgsAuxiliaryField::nameFromProperty( mDefinition, true ) ) + mDefineMenu->addAction( mActionCreateAuxiliaryField ); + + const QgsAuxiliaryLayer *alayer = mVectorLayer->auxiliaryLayer(); + + mActionCreateAuxiliaryField->setEnabled( true ); + mActionCreateAuxiliaryField->setChecked( false ); + if ( alayer && alayer->exists( mDefinition ) ) { - mActionCreateAuxiliaryField->setEnabled( false ); - mActionCreateAuxiliaryField->setChecked( true ); + if ( mProperty.field() == QgsAuxiliaryField::nameFromProperty( mDefinition, true ) ) + { + mActionCreateAuxiliaryField->setEnabled( false ); + mActionCreateAuxiliaryField->setChecked( true ); + } } } diff --git a/src/gui/qgspropertyoverridebutton.h b/src/gui/qgspropertyoverridebutton.h index ada96d89d33..a0452fe2f4a 100644 --- a/src/gui/qgspropertyoverridebutton.h +++ b/src/gui/qgspropertyoverridebutton.h @@ -69,11 +69,13 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton * \param property initial value of associated property to show in widget * \param definitions properties definitions for corresponding collection * \param layer associated vector layer + * \param auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage */ void init( int propertyKey, const QgsProperty &property, const QgsPropertiesDefinition &definitions, - const QgsVectorLayer *layer = nullptr ); + const QgsVectorLayer *layer = nullptr, + bool auxiliaryStorageEnabled = false ); /** * Initialize a newly constructed property button (useful if button was included in a UI layout). @@ -81,11 +83,13 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton * \param collection associated property collection * \param definitions properties definitions for collection * \param layer associated vector layer + * \param auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage */ void init( int propertyKey, const QgsAbstractPropertyCollection &collection, const QgsPropertiesDefinition &definitions, - const QgsVectorLayer *layer = nullptr ); + const QgsVectorLayer *layer = nullptr, + bool auxiliaryStorageEnabled = false ); /** * Returns a QgsProperty object encapsulating the current state of the @@ -295,6 +299,8 @@ class GUI_EXPORT QgsPropertyOverrideButton: public QToolButton //! Internal property used for storing state of widget QgsProperty mProperty; + bool mAuxiliaryStorageEnabled = false; + std::shared_ptr< QgsSymbol > mSymbol; private slots: diff --git a/src/gui/symbology/qgssymbollayerwidget.cpp b/src/gui/symbology/qgssymbollayerwidget.cpp index 083e69d6560..aad649998d2 100644 --- a/src/gui/symbology/qgssymbollayerwidget.cpp +++ b/src/gui/symbology/qgssymbollayerwidget.cpp @@ -111,7 +111,7 @@ QgsSymbolWidgetContext QgsSymbolLayerWidget::context() const void QgsSymbolLayerWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsSymbolLayer::Property key ) { - button->init( key, symbolLayer()->dataDefinedProperties(), QgsSymbolLayer::propertyDefinitions(), mVectorLayer ); + button->init( key, symbolLayer()->dataDefinedProperties(), QgsSymbolLayer::propertyDefinitions(), mVectorLayer, true ); connect( button, &QgsPropertyOverrideButton::changed, this, &QgsSymbolLayerWidget::updateDataDefinedProperty ); connect( button, &QgsPropertyOverrideButton::createAuxiliaryField, this, &QgsSymbolLayerWidget::createAuxiliaryField ); diff --git a/src/gui/symbology/qgssymbolslistwidget.cpp b/src/gui/symbology/qgssymbolslistwidget.cpp index e4789fa0ff4..6a3d3bc0699 100644 --- a/src/gui/symbology/qgssymbolslistwidget.cpp +++ b/src/gui/symbology/qgssymbolslistwidget.cpp @@ -559,10 +559,10 @@ void QgsSymbolsListWidget::updateSymbolInfo() if ( mLayer ) { QgsProperty ddSize( markerSymbol->dataDefinedSize() ); - mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer ); + mSizeDDBtn->init( QgsSymbolLayer::PropertySize, ddSize, QgsSymbolLayer::propertyDefinitions(), mLayer, true ); spinSize->setEnabled( !mSizeDDBtn->isActive() ); QgsProperty ddAngle( markerSymbol->dataDefinedAngle() ); - mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer ); + mRotationDDBtn->init( QgsSymbolLayer::PropertyAngle, ddAngle, QgsSymbolLayer::propertyDefinitions(), mLayer, true ); spinAngle->setEnabled( !mRotationDDBtn->isActive() ); } else @@ -579,7 +579,7 @@ void QgsSymbolsListWidget::updateSymbolInfo() if ( mLayer ) { QgsProperty dd( lineSymbol->dataDefinedWidth() ); - mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer ); + mWidthDDBtn->init( QgsSymbolLayer::PropertyStrokeWidth, dd, QgsSymbolLayer::propertyDefinitions(), mLayer, true ); spinWidth->setEnabled( !mWidthDDBtn->isActive() ); } else