QGIS-Documentation icon indicating copy to clipboard operation
QGIS-Documentation copied to clipboard

Add map layers custom properties to the information tab (Request in QGIS)

Open qgis-bot opened this issue 1 year ago • 4 comments

Request for documentation

From pull request QGIS/qgis#55493 Author: @jadsilva QGIS version: 3.36

Add map layers custom properties to the information tab

PR Description:

Fixes qgis#52243

Description

288438378-fc901c20-37fd-4b34-b8d3-90fafc52f5d0

Commits tagged with [need-docs] or [FEATURE]

qgis-bot avatar Dec 06 '23 05:12 qgis-bot

A new list item to add in the layer properties --> information section of the "working with..." chapters.

DelazJ avatar Dec 28 '23 21:12 DelazJ

@jadsilva @rduivenvoorde what do these custom properties refer to? Where do they come from or how can we create them?

DelazJ avatar Feb 03 '24 15:02 DelazJ

@DelazJ you can set, using python, so called 'custom properties' on some objects: https://qgis.org/pyqgis/master/search.html?q=setCustomProperty

In this case these are custom properties on a MapLayer: https://qgis.org/pyqgis/master/core/QgsMapLayer.html#qgis.core.QgsMapLayer.setCustomProperty

Let me create an example and screenie...

rduivenvoorde avatar Feb 03 '24 17:02 rduivenvoorde

These custom properties are being saved into the projects xml too. So it is for example possible to 'save' some state information into a project. I use it for example to save an object with some info about last used layers etc.

To see it:

# first load 'world', via easter egg, by typing 'world' in the coordinate input
# then open the python console
# make sure the world layer is the active layer
# now create a property:
iface.activeLayer().setCustomProperty('custom_property_name', 'custom_property_value')
# or read it from the layer/project:
iface.activeLayer().customProperty('custom_property_name')
'custom_property_value'

So before this PR, you could check the value via Python, or inspect the xml of the project, but it was not visible in the UI.

Now you can see it in the Layer-properties, in the information tab:

image

rduivenvoorde avatar Feb 03 '24 17:02 rduivenvoorde