QGIS icon indicating copy to clipboard operation
QGIS copied to clipboard

Add ability to filter features in layer according to current Map Theme

Open blacktesta opened this issue 2 years ago • 8 comments

Feature description

Hi, developers and community! I ran into one problem. I wanted to filter data in my layers according to current map theme in QGIS and realised there is no way to do it. Provider feature filter is not a part of style, so it can't be changed by theme. Rule-based symbology can't get current theme because there is no @theme variable. That why i want to propose adding @theme or @currrent_theme variable in QGIS

Additional context

P.s. making filter part of style would also be great

blacktesta avatar Nov 27 '23 13:11 blacktesta

Hi @blacktesta While I second the addition of a variable for map themes (#29581), I'm not sure I understand what you mean by

I wanted to filter data in my layers according to current map theme in QGIS

What do you expect? Can you elaborate a bit on your intentions, please? Thanks

DelazJ avatar Nov 27 '23 15:11 DelazJ

@DelazJ I want
I want possibility to do something like this: image Or possibility to include filter to style (like save to .qml) so it can be changed with changing map theme. So I'm talking not in context of layouts. I'm talking about main map in QGIS.

blacktesta avatar Nov 28 '23 05:11 blacktesta

@DelazJ Hi, I wanted to propose a feature like this, I think it would be possible to save a map theme with filters enabled on layers, not necessarily on all layers.
I provide a link to a topic where I found helpful content: https://gis.stackexchange.com/questions/470982/changing-layer-filter-according-to-map-theme-in-qgis

szooon1 avatar Feb 02 '24 20:02 szooon1

Hello all, I would like to add my own notice on this improvement. What he is trying to explain is about the possibility to access Preset theme in Expression builder.

A pratical exemple

Let's take project where user has define a preset (themes) for every month in a year
image

And then, let's suppose that user want to edit an attribut form that shows only some specifics fields according to when a certain Preset (theme) is ACTIVATED.

The easiest way is to open layer properties

  • Open attributes form tab
  • Change form generation setting from AUTOGENERATE to DRAG AND DROP DESIGNER
  • Create NEW TAB or GROUP
  • In the group parameters, check the checkbox CONTROL VISIBILITY BY EXPRESSION
  • then open the expression builder and start to build expression image

From there, User should have possibility to write expression that litterally says : APPEARS ONLY IF THE CURRENT PRESET (THEME) IS 'JANV23'

In the expression builder it should be : @CURRENT_PRESET = 'JANV23' or in other way @CURRENT_THEME = 'JANV23'

But there is no way to call the current preset (theme) in the expression builder

In the layout buider, after adding a map item, you can see in it's properties that there is an option that let you choose the Preset (Theme) to follow. I'm not a develloper but i guess that Presets are called here as variable or parameters. image

Can't it be the same in EXPRESSION BUILDER?

Hope this will help.

Sekou225 avatar Feb 14 '24 17:02 Sekou225

@DelazJ Hi, I wanted to propose a feature like this, I think it would be possible to save a map theme with filters enabled on layers, not necessarily on all layers. I provide a link to a topic where I found helpful content: https://gis.stackexchange.com/questions/470982/changing-layer-filter-according-to-map-theme-in-qgis

Dead link

Sekou225 avatar Feb 14 '24 17:02 Sekou225

Hi @Sekou225 . Thank you for your comment. The case you provided is not what i'm asking for, but i agree it would be great to have theme variable in expression builder . Attribute Form settings is already part of Layer Style, wich is part of Map Theme. So you can do the trick already just setting different forms in different styles in different themes. I think I created a slight misunderstanding because I could not fully formulate what I wanted at the time of opening this issue. Let say we have a layer with 200 features and one field "theme" with two possible values 'A' and 'B'. 100 of the features have value 'A' and other 100 have value 'B'. And we have two map themes 'A' and 'B'. I want to filter this layer to have only 100 features with value 'A' when current theme is 'A'. At the moment i can do it with rule-based symbology, filtering features with rules. But in this case my users will see another 100 features with value 'B' in attribute table. So I need to use data provider filter, but I can't. To sum up, I want to:

  1. (complex solution) Have @theme variable and ability to use variables in provider feature filter query builder.
  2. (less complex solution) Have ability to save provider feature filter query as part of layer style.

blacktesta avatar Feb 14 '24 18:02 blacktesta

I have changed the title to better match the problem

blacktesta avatar Feb 14 '24 18:02 blacktesta

Hi everyone, Having a map theme variable in expression builder or a filter based on the map theme would be great. In my example, there is about 30 map themes in my project which call 30 different layer styles with :

  • some symbology rules depending on a theme field value (to mask or to show features)
  • forms (which are similar in every layer style, in my case)

to make my project easier to use and to set, i'd like to have only one layer style with symbology ruled by a variable like "@map_theme". When a user chose a theme, the features with the same theme name in the field "theme" would be showed.
I know that multiple layer style or multiple symbologies rules would work but the problem is this one : When you have 30 layer styles and you realise there is an error in a form or in the symbology or a new field to add in the form, you have to repair the error 30 times so it needs work and there is a risk of forgetting some layer style. We have to do it manually because the style copy/paste does not work every time. (I don't know why)

If you have any other tips to help me i would be very grateful Thank you

FrancoisAlto avatar Apr 25 '24 20:04 FrancoisAlto