Re: [QGIS-Developer] Adding Layer tree embedded widgets programmatically

2019-02-13 Thread Raymond Nijssen

Sorry, forgot to add the link :blush:

https://gis.stackexchange.com/questions/232367/showing-transparency-slider-by-default-in-layers-panel-of-qgis

On 13-02-19 12:59, Raymond Nijssen wrote:

Hi Richard,

Here is some example code. I will try to make it work now.

Groetjes!
Raymond


On 13-02-19 12:37, Richard Duivenvoorde wrote:

Hi Devs,

Thinking about creating a small plugin which would add a 'Layer tree
embedded widget' to a layer in the legend, I hit:

https://github.com/qgis/QGIS/pull/3170

with a nice example on how to create such a widget (with 2 minor tweaks
see below).

But my question is if it is possible (in the python plugin) to attach
such widget to a specific layer? Now it is working but you can only
activate it via the layerproperties dialog.

I could not find a example or hint for it.

Any pointers appreciated.

Regards,

Richard Duivenvoorde

PS

To make Martins example https://github.com/qgis/QGIS/pull/3170) work in
QGIS3:

from PyQt4.QtGui import QComboBox
becomes
from qgis.PyQt.QtWidgets import QComboBox

QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)
becomes
QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(provider)
___
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] Adding Layer tree embedded widgets programmatically

2019-02-13 Thread Ricardo Filipe Soares Garcia da
Hi Richard

You can add widgets to a specific layer if you know the widget provider's
id. It is simply a matter of setting up the relevant custom properties.

Take a look at the code in the PR you linked, more specifically here:

https://github.com/qgis/QGIS/pull/3170/files#diff-0c8d41d794f1b84a1291aa29bb39392aR114


For example, the standard widget that provides a transparency slider has an
id of "transparency". Lets imagine I select the current layer in the canvas
and then want to make this widgets appear in its legend:

```python
layer = iface.activeLayer()
layer.setCustomProperty("embeddedWidgets/count", 1)
layer.setCustomProperty("embeddedWidgets/0/id", "transparency")
iface.layerTreeView().refreshLayerSymbology(layer.id())
```

This code assumes that the layer doesn't currently have any embedded
widgets.


P.S. - Now that I've tried it, it seems that the transparency slider works
differently for raster and vector layers.


Richard Duivenvoorde  escreveu no dia quarta,
13/02/2019 à(s) 11:38:

> Hi Devs,
>
> Thinking about creating a small plugin which would add a 'Layer tree
> embedded widget' to a layer in the legend, I hit:
>
> https://github.com/qgis/QGIS/pull/3170
>
> with a nice example on how to create such a widget (with 2 minor tweaks
> see below).
>
> But my question is if it is possible (in the python plugin) to attach
> such widget to a specific layer? Now it is working but you can only
> activate it via the layerproperties dialog.
>
> I could not find a example or hint for it.
>
> Any pointers appreciated.
>
> Regards,
>
> Richard Duivenvoorde
>
> PS
>
> To make Martins example https://github.com/qgis/QGIS/pull/3170) work in
> QGIS3:
>
> from PyQt4.QtGui import QComboBox
> becomes
> from qgis.PyQt.QtWidgets import QComboBox
>
> QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)
> becomes
> QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(provider)
> ___
> 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



-- 
___ ___ __
Ricardo Garcia Silva
___
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] Adding Layer tree embedded widgets programmatically

2019-02-13 Thread Raymond Nijssen

Hi Richard,

Here is some example code. I will try to make it work now.

Groetjes!
Raymond


On 13-02-19 12:37, Richard Duivenvoorde wrote:

Hi Devs,

Thinking about creating a small plugin which would add a 'Layer tree
embedded widget' to a layer in the legend, I hit:

https://github.com/qgis/QGIS/pull/3170

with a nice example on how to create such a widget (with 2 minor tweaks
see below).

But my question is if it is possible (in the python plugin) to attach
such widget to a specific layer? Now it is working but you can only
activate it via the layerproperties dialog.

I could not find a example or hint for it.

Any pointers appreciated.

Regards,

Richard Duivenvoorde

PS

To make Martins example https://github.com/qgis/QGIS/pull/3170) work in
QGIS3:

from PyQt4.QtGui import QComboBox
becomes
from qgis.PyQt.QtWidgets import QComboBox

QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)
becomes
QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(provider)
___
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] Adding Layer tree embedded widgets programmatically

2019-02-13 Thread Richard Duivenvoorde
Hi Devs,

Thinking about creating a small plugin which would add a 'Layer tree
embedded widget' to a layer in the legend, I hit:

https://github.com/qgis/QGIS/pull/3170

with a nice example on how to create such a widget (with 2 minor tweaks
see below).

But my question is if it is possible (in the python plugin) to attach
such widget to a specific layer? Now it is working but you can only
activate it via the layerproperties dialog.

I could not find a example or hint for it.

Any pointers appreciated.

Regards,

Richard Duivenvoorde

PS

To make Martins example https://github.com/qgis/QGIS/pull/3170) work in
QGIS3:

from PyQt4.QtGui import QComboBox
becomes
from qgis.PyQt.QtWidgets import QComboBox

QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)
becomes
QgsGui.layerTreeEmbeddedWidgetRegistry().addProvider(provider)
___
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