Do not activate auxiliary data button everywhere

This commit is contained in:
Blottiere Paul 2017-09-02 14:53:51 +01:00
parent 429b1ec3c2
commit 703fbde035
7 changed files with 37 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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