This expression [%@project_path%] prints the path of the qgis project.
How the Map Theme used in the layout can also be printed automatically ?
According to QGIS documentation, a Map Theme is a snapshot of the current map legend that records.
How to reproduce the issue
The Map Theme is set according to these steps :
- View tab > Panels > Layers
- Click on the Manage Map Themes icon > Add Theme
- Give the new Map Theme a name
- Open a new Print Layout > click on Adds a new Label to the Layout > create one
Issue
Does a variable or an expression exist to automatically print the name of the Map Theme in the Print Composer?
Answer 1 (not entirely satisfactory)
- create manually a Map Theme
- open Python console > iface.mapCanvas().setTheme('your theme')
- open Print Composer > add a new map to the layout > Item propriety tab > Item ID > write what you want
add a new Label to the Layout > item propriety > click insert an expression button > function editor tab > click '+' button > insert the code below :
from qgis.core import * from qgis.gui import * from qgis.utils import iface
@qgsfunction(args='auto', group='Custom') def print_theme(value1, feature, parent): return iface.mapCanvas().theme()
Expression tab > print_theme('_your_map_id_')
iface.mapCanvas().theme()
but it seems to only work if the theme is set programmatically (e.g. through the Python console) withiface.mapCanvas().setTheme('My theme')
. See gis.stackexchange.com/questions/293507/…