Skip to content

Commit

Permalink
Ensure that fields required by marker symbol backgrounds for labels
Browse files Browse the repository at this point in the history
are fetched when rendering

Fixes #36944
  • Loading branch information
nyalldawson committed Jun 4, 2020
1 parent 6b27958 commit 8fb8e45
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 0 deletions.
Expand Up @@ -599,6 +599,13 @@ Write settings into a DOM element.
Updates the format by evaluating current values of data defined properties.

.. versionadded:: 3.10
%End

QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
Returns all field names referenced by the configuration (e.g. from data defined properties).

.. versionadded:: 3.14
%End

};
Expand Down
Expand Up @@ -246,6 +246,13 @@ Sets the current paint ``effect`` for the buffer.
Updates the format by evaluating current values of data defined properties.

.. versionadded:: 3.10
%End

QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
Returns all field names referenced by the configuration (e.g. from data defined properties).

.. versionadded:: 3.14
%End

};
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/textrenderer/qgstextformat.sip.in
Expand Up @@ -473,6 +473,13 @@ Returns a reference to the format's property collection, used for data defined o
%End


QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
Returns all field names referenced by the configuration (e.g. from data defined properties).

.. versionadded:: 3.14
%End

void setDataDefinedProperties( const QgsPropertyCollection &collection );
%Docstring
Sets the format's property collection, used for data defined overrides.
Expand Down
Expand Up @@ -221,6 +221,13 @@ Sets the symbol layers that will be masked by this buffer.
void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties );
%Docstring
Updates the format by evaluating current values of data defined properties.
%End

QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
Returns all field names referenced by the configuration (e.g. from data defined properties).

.. versionadded:: 3.14
%End

};
Expand Down
Expand Up @@ -352,6 +352,13 @@ Write settings into a DOM element.
Updates the format by evaluating current values of data defined properties.

.. versionadded:: 3.10
%End

QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
Returns all field names referenced by the configuration (e.g. from data defined properties).

.. versionadded:: 3.14
%End

};
Expand Down
3 changes: 3 additions & 0 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -474,6 +474,7 @@ bool QgsPalLayerSettings::prepare( QgsRenderContext &context, QSet<QString> &att
attributeNames.insert( name );
}
}
attributeNames.unite( mFormat.referencedFields( context ) );

if ( mCallout )
{
Expand Down Expand Up @@ -502,6 +503,8 @@ QSet<QString> QgsPalLayerSettings::referencedFields( const QgsRenderContext &con
}
}

referenced.unite( mFormat.referencedFields( context ) );

// calling referencedFields() with ignoreContext=true because in our expression context
// we do not have valid QgsFields yet - because of that the field names from expressions
// wouldn't get reported
Expand Down
10 changes: 10 additions & 0 deletions src/core/textrenderer/qgstextbackgroundsettings.cpp
Expand Up @@ -767,3 +767,13 @@ void QgsTextBackgroundSettings::updateDataDefinedProperties( QgsRenderContext &c
}
}
}

QSet<QString> QgsTextBackgroundSettings::referencedFields( const QgsRenderContext &context ) const
{
QSet< QString > fields;
if ( d->markerSymbol )
{
fields.unite( d->markerSymbol->usedAttributes( context ) );
}
return fields;
}
6 changes: 6 additions & 0 deletions src/core/textrenderer/qgstextbackgroundsettings.h
Expand Up @@ -508,6 +508,12 @@ class CORE_EXPORT QgsTextBackgroundSettings
*/
void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties );

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields( const QgsRenderContext &context ) const;

private:

QSharedDataPointer<QgsTextBackgroundSettingsPrivate> d;
Expand Down
5 changes: 5 additions & 0 deletions src/core/textrenderer/qgstextbuffersettings.cpp
Expand Up @@ -202,6 +202,11 @@ void QgsTextBufferSettings::updateDataDefinedProperties( QgsRenderContext &conte
}
}

QSet<QString> QgsTextBufferSettings::referencedFields( const QgsRenderContext & ) const
{
return QSet< QString >(); // nothing for now
}

void QgsTextBufferSettings::readFromLayer( QgsVectorLayer *layer )
{
// text buffer
Expand Down
6 changes: 6 additions & 0 deletions src/core/textrenderer/qgstextbuffersettings.h
Expand Up @@ -227,6 +227,12 @@ class CORE_EXPORT QgsTextBufferSettings
*/
void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties );

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields( const QgsRenderContext &context ) const;

private:

QSharedDataPointer<QgsTextBufferSettingsPrivate> d;
Expand Down
10 changes: 10 additions & 0 deletions src/core/textrenderer/qgstextformat.cpp
Expand Up @@ -576,6 +576,16 @@ const QgsPropertyCollection &QgsTextFormat::dataDefinedProperties() const
return d->mDataDefinedProperties;
}

QSet<QString> QgsTextFormat::referencedFields( const QgsRenderContext &context ) const
{
QSet< QString > fields = d->mDataDefinedProperties.referencedFields( context.expressionContext(), true );
fields.unite( mBufferSettings.referencedFields( context ) );
fields.unite( mBackgroundSettings.referencedFields( context ) );
fields.unite( mShadowSettings.referencedFields( context ) );
fields.unite( mMaskSettings.referencedFields( context ) );
return fields;
}

void QgsTextFormat::setDataDefinedProperties( const QgsPropertyCollection &collection )
{
d->mDataDefinedProperties = collection;
Expand Down
6 changes: 6 additions & 0 deletions src/core/textrenderer/qgstextformat.h
Expand Up @@ -430,6 +430,12 @@ class CORE_EXPORT QgsTextFormat
*/
const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP;

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields( const QgsRenderContext &context ) const;

/**
* Sets the format's property collection, used for data defined overrides.
* \param collection property collection. Existing properties will be replaced.
Expand Down
5 changes: 5 additions & 0 deletions src/core/textrenderer/qgstextmasksettings.cpp
Expand Up @@ -165,6 +165,11 @@ void QgsTextMaskSettings::updateDataDefinedProperties( QgsRenderContext &context
}
}

QSet<QString> QgsTextMaskSettings::referencedFields( const QgsRenderContext & ) const
{
return QSet< QString >(); // nothing for now
}

void QgsTextMaskSettings::readXml( const QDomElement &elem )
{
QDomElement textMaskElem = elem.firstChildElement( QStringLiteral( "text-mask" ) );
Expand Down
6 changes: 6 additions & 0 deletions src/core/textrenderer/qgstextmasksettings.h
Expand Up @@ -209,6 +209,12 @@ class CORE_EXPORT QgsTextMaskSettings
*/
void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties );

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields( const QgsRenderContext &context ) const;

private:

QSharedDataPointer<QgsTextMaskSettingsPrivate> d;
Expand Down
5 changes: 5 additions & 0 deletions src/core/textrenderer/qgstextshadowsettings.cpp
Expand Up @@ -436,3 +436,8 @@ void QgsTextShadowSettings::updateDataDefinedProperties( QgsRenderContext &conte
d->blendMode = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
}
}

QSet<QString> QgsTextShadowSettings::referencedFields( const QgsRenderContext & ) const
{
return QSet< QString >(); // nothing for now
}
6 changes: 6 additions & 0 deletions src/core/textrenderer/qgstextshadowsettings.h
Expand Up @@ -306,6 +306,12 @@ class CORE_EXPORT QgsTextShadowSettings
*/
void updateDataDefinedProperties( QgsRenderContext &context, const QgsPropertyCollection &properties );

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields( const QgsRenderContext &context ) const;

private:

QSharedDataPointer<QgsTextShadowSettingsPrivate> d;
Expand Down

0 comments on commit 8fb8e45

Please sign in to comment.