Skip to content
Permalink
Browse files

Auxiliary fields are linked to data defined for all subproviders

  • Loading branch information
pblottiere committed Oct 9, 2017
1 parent 9cb3ff3 commit 67cff3ddd7e144117811be72aaad855d8dc45742
@@ -183,14 +183,13 @@ class QgsAuxiliaryLayer : QgsVectorLayer
:rtype: QgsPropertyDefinition
%End

static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer, const QString &providerId = QString() );
static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );
%Docstring
Creates if necessary a new auxiliary field for a PAL property and
activate this property in settings.

\param property The property to create
\param vlayer The vector layer
\param providerId The id of the provider to use

:return: The index of the auxiliary field or -1
:rtype: int
@@ -744,7 +744,7 @@ bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexe
}
else
{
index = QgsAuxiliaryLayer::createProperty( p, vlayer, providerId );
index = QgsAuxiliaryLayer::createProperty( p, vlayer );
}

indexes[p] = index;
@@ -215,26 +215,32 @@ bool QgsAuxiliaryLayer::save()
return rc;
}

int QgsAuxiliaryLayer::createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *layer, const QString &providerId )
int QgsAuxiliaryLayer::createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *layer )
{
int index = -1;

if ( layer && layer->labeling() && layer->auxiliaryLayer() )
{
const QgsPropertyDefinition def = layer->labeling()->settings( providerId ).propertyDefinitions()[property];
// property definition are identical whatever the provider id
const QgsPropertyDefinition def = layer->labeling()->settings().propertyDefinitions()[property];
const QString fieldName = nameFromProperty( def, true );

if ( layer->auxiliaryLayer()->addAuxiliaryField( def ) )
layer->auxiliaryLayer()->addAuxiliaryField( def );

if ( layer->auxiliaryLayer()->indexOfPropertyDefinition( def ) >= 0 )
{
const QgsProperty prop = QgsProperty::fromField( fieldName );

QgsPalLayerSettings *settings = new QgsPalLayerSettings( layer->labeling()->settings( providerId ) );
for ( const QString &providerId : layer->labeling()->subProviders() )
{
QgsPalLayerSettings *settings = new QgsPalLayerSettings( layer->labeling()->settings( providerId ) );

QgsPropertyCollection c = settings->dataDefinedProperties();
c.setProperty( property, prop );
settings->setDataDefinedProperties( c );
QgsPropertyCollection c = settings->dataDefinedProperties();
c.setProperty( property, prop );
settings->setDataDefinedProperties( c );

layer->labeling()->setSettings( settings, providerId );
layer->labeling()->setSettings( settings, providerId );
}
}

index = layer->fields().lookupField( fieldName );
@@ -200,11 +200,10 @@ class CORE_EXPORT QgsAuxiliaryLayer : public QgsVectorLayer
*
* \param property The property to create
* \param vlayer The vector layer
* \param providerId The id of the provider to use
*
* \returns The index of the auxiliary field or -1
*/
static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer, const QString &providerId = QString() );
static int createProperty( QgsPalLayerSettings::Property property, QgsVectorLayer *vlayer );

/**
* Creates if necessary a new auxiliary field for a diagram's property and

0 comments on commit 67cff3d

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