[QGIS-Developer] set data defined override expression with python?

Nyall Dawson nyall.dawson at gmail.com
Mon Oct 15 19:19:03 PDT 2018


On Tue, 16 Oct 2018 at 05:06, Raymond Nijssen <r.nijssen at terglobo.nl> wrote:
>
> So now I'd like to set another expression, quite similar, but this time
> the svg-path to a QgsSvgMarkerSymbolLayer.
>
> Where can I find the name of that property? I found the
> QgsLayoutObject.PictureSource here:
>
> https://github.com/qgis/QGIS/blob/c89a542365eb46317468135cb33236ecc0c3768c/src/core/layout/qgslayoutobject.h#L47
>
> But I don't know what class should hold the data defined property
> enumeration for an svgMarkerSymbolLayer. Searching for "enum
> DataDefinedProperty" in the qgis code doesn't get me any other result.

The API uses ints instead of the direct DataDefinedProperty enums, as
the enums vary by part of code (there's separate enums for symbology,
labelling, layouts, etc)

For symbology:

layer = QgsSvgMarkerSymbolLayer(...)
...
layer.setDataDefinedProperty( QgsSymbolLayer.PropertyName,
QgsProperty.fromExpression( " some expression ") )

Nyall


>
> Hope anyone can help me out here!
>
> Kind regards,
> Raymond
>
>
>
> On 22-08-18 08:39, Raymond Nijssen wrote:
> > Thank you Nyall! Does exactly what I need. Will add it to the python
> > cookbook.
> >
> > Raymond
> >
> >
> >
> > On 22-08-18 00:10, Nyall Dawson wrote:
> >> On Wed, 22 Aug 2018 at 01:41, Raymond Nijssen <r.nijssen at terglobo.nl>
> >> wrote:
> >>>
> >>> Hi devs!
> >>>
> >>> I'd like my python plugin to set an expression for overriding a property
> >>> and I have no clue how to do so. I expect there must be some generic way
> >>> to set expressions.
> >>>
> >>> Specifically, I want to set the expression for the "Image source" of a
> >>> QgsLayoutItemPicture to:
> >>>
> >>> '/path/to/pictures/' || attribute(@atlas_feature, 'ID') || '.svg'
> >>>
> >>
> >> Try
> >>
> >>      property = QgsProperty.fromExpression( "'/path/to/pictures/' ||
> >> attribute(@atlas_feature, 'ID') || '.svg'")
> >>
> >> item.dataDefinedProperties().setProperty(QgsLayoutObject.PictureSource,
> >> property)
> >>
> >> Nyall
> >>
> >
> >
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list