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

2018-10-18 Thread Raymond Nijssen

On 16-10-18 04:19, Nyall Dawson wrote:

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




Thanks Nyall, that works!

And now I know the property name, I could also find the other 
properties. And then I started searching the code for more and found the 
ones listed below. Possibly there are more.


It was apparently too hard for me finding these property names and I 
wonder if others are struggling as well. Where could we put this in a 
way where people can find it and where it will be easily to maintain? 
The cookbook?


Regards,
Raymond



QgsAbstract3DSymbol
  PropertyHeight = 0,   //!< Height (altitude)
  PropertyExtrusionHeight,  //!< Extrusion height (zero means no 
extrusion)


QgsLayoutObject
  NoProperty = 0, //!< No property
  AllProperties, //!< All properties for item
  TestProperty, //!< Dummy property with no effect on item
  //composer page properties
  PresetPaperSize, //!< Preset paper size for composition
  PaperWidth, //!< Paper width (deprecated)
  PaperHeight, //!< Paper height (deprecated)
  NumPages, //!< Number of pages in composition (deprecated)
  PaperOrientation, //!< Paper orientation
  //general composer item properties
  PageNumber, //!< Page number for item placement
  PositionX, //!< X position on page
  PositionY, //!< Y position on page
  ItemWidth, //!< Width of item
  ItemHeight, //!< Height of item
  ItemRotation, //!< Rotation of item
  Transparency, //!< Item transparency (deprecated)
  Opacity, //!< Item opacity
  BlendMode, //!< Item blend mode
  ExcludeFromExports, //!< Exclude item from exports
  FrameColor, //!< Item frame color
  BackgroundColor, //!< Item background color
  //composer map
  MapRotation, //!< Map rotation
  MapScale, //!< Map scale
  MapXMin, //!< Map extent x minimum
  MapYMin, //!< Map extent y minimum
  MapXMax, //!< Map extent x maximum
  MapYMax, //!< Map extent y maximum
  MapAtlasMargin, //!< Map atlas margin
  MapLayers, //!< Map layer set
  MapStylePreset, //!< Layer and style map theme
  //composer picture
  PictureSource, //!< Picture source url
  PictureSvgBackgroundColor, //!< SVG background color
  PictureSvgStrokeColor, //!< SVG stroke color
  PictureSvgStrokeWidth, //!< SVG stroke width
  //html item
  SourceUrl, //!< Html source url
  //legend item
  LegendTitle, //!< Legend title
  LegendColumnCount, //!< Legend column count
  //scalebar item
  ScalebarFillColor, //!< Scalebar fill color
  ScalebarFillColor2, //!< Scalebar secondary fill color
  ScalebarLineColor, //!< Scalebar line color
  ScalebarLineWidth, //!< Scalebar line width,
  //table item
  AttributeTableSourceLayer, //!< Attribute table source layer

QgsDiagramLayerSettings
  BackgroundColor, //!< Diagram background color
  StrokeColor, //!< Stroke color
  StrokeWidth, //!< Stroke width
  PositionX, //! x-coordinate data defined diagram position
  PositionY, //! y-coordinate data defined diagram position
  Distance, //! Distance to diagram from feature
  Priority, //! Diagram priority (between 0 and 10)
  ZIndex, //! Z-index for diagram ordering
  IsObstacle, //! Whether diagram features act as obstacles for 
other diagrams/labels

  Show, //! Whether to show the diagram
  AlwaysShow, //! Whether the diagram should always be shown, even 
if it overlaps other diagrams/labels

  StartAngle, //! Angle offset for pie diagram

QgsPalLayerSettings
  Size = 0, //!< Label size
  Bold = 1, //!< Use bold style
  Italic = 2, //!< Use italic style
  Underline = 3, //!< Use underline
  Color = 4, //!< Text color
  Strikeout = 5, //!< Use strikeout
  Family = 6, //!< Font family
  FontStyle = 21, //!< Font style name
  FontSizeUnit = 22, //!< Font size units
  FontTransp = 18, //!< Text transparency (deprecated)
  FontOpacity = 92, //!< Text opacity
  FontCase = 27, //!< Label text case
  FontLetterSpacing = 28, //!< Letter spacing
  FontWordSpacing = 29, //!< Word spacing
  FontBlendMode = 30, //! Text blend mode

  // text formatting
  MultiLineWrapChar = 31,
  AutoWrapLength = 101,
  MultiLineHeight = 32,
  MultiLineAlignment = 33,
  DirSymbDraw = 34,
  DirSymbLeft = 35,
  DirSymbRight = 36,
  DirSymbPlacement = 37,
  DirSymbReverse = 38,
  NumFormat = 39,
  NumDecimals = 40,
  NumPlusSign = 41,

  // text buffer
  BufferDraw = 42,
  BufferSize = 7,
  BufferUnit = 43,
  BufferColor = 8,
  BufferTransp 

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

2018-10-15 Thread Nyall Dawson
On Tue, 16 Oct 2018 at 05:06, Raymond Nijssen  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 
> >> 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@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@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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2018-10-15 Thread Raymond Nijssen
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.


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  
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@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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2018-08-22 Thread Raymond Nijssen
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  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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

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

2018-08-21 Thread Nyall Dawson
On Wed, 22 Aug 2018 at 01:41, Raymond Nijssen  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@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer