[QGIS-Developer] is_layer_active expression
Nyall Dawson
nyall.dawson at gmail.com
Tue Sep 25 00:03:42 PDT 2018
On Tue, 25 Sep 2018 at 16:43, Otto Dassau <dassau at gbd-consult.de> wrote:
>
> thanks for the info Nyall!
Ok, PR opened. https://github.com/qgis/QGIS/pull/8016
But for reference -- I think what's going to be more useful for layout
use is the 3.4 @map_layers variable. As noted in the earlier reply,
some functions are context dependent, and is_layer_visible is one of
these. So in 3.4 it will work *within* a layout item map, it won't
allow you to e.g. have a label item outside the map change its content
based on is_layer_visible.
On the other hand, you *can* retrieve expression variables (not
functions!) from another layout item, using the item_variables
function! So you can build the expression:
map_get( item_variables( 'Your_Map_ID' ), 'map_layers' )
To retrieve a list of map layers within the Your_Map_Id map item, and
this expression will work anywhere inside the layout! (i.e. labels,
data defined expressions, etc).
One intended use case for this is to allow labels with expressions like:
array_to_string( array_foreach(map_get( item_variables(
'Your_Map_ID' ), 'map_layers' ), layer_property(@element, 'name')),
',' )
To get a nice comma separated list of all layers included in the map
item. (Admittedly, that expression is quite complex, but if you pick
it apart piece by piece you should be able to decipher it!).
Nyall
>
> Regards,
> Otto
>
> Am Tue, 25 Sep 2018 16:37:38 +1000
> schrieb Nyall Dawson <nyall.dawson at gmail.com>:
>
> > On Mon, 24 Sep 2018 at 19:20, Otto Dassau <dassau at gbd-consult.de> wrote:
> > >
> > > Dear Devs,
> > >
> > > in QGIS 3 I found the expression "is_layer_active" within the copyright
> > > decoration very useful. I would like to use this expression also within
> > > the print composer, but it seems to be not available there.
> >
> > Confirmed -- fix incoming!
> >
> > > Is this correct, are expressions not available all over QGIS within the
> > > expression builder?
> >
> > Some expression functions/variables are "context dependent". E.g.
> > is_layer_visible doesn't make any sense in expressions which aren't
> > directly associated with a map. So the function won't be available as
> > for expressions used as a field default value, or for a layout text
> > label (since the layout may have multiple maps, each with a different
> > layer set, and a label isn't linked to any map item in particular!).
> >
> > > And how can I get this expression working for the print composer as
> > > well?
> >
> > Wait for 3.4 ;)
> >
> > Nyall
>
More information about the QGIS-Developer
mailing list