2

I need to insert project variable into map composer file (.qpt) for showing specific legend item. The item is a layer constructed from a URL query that I need to dynamically change based on a project variable.

When I open another project, the layer URL query in the legend has a fixed value and the legend does not display the symbol, only the layer title, because in that project the layer has a URL query with a dynamic variable and the legend does not "find" the corresponding layer in the project.

...<layer-tree-layer name="Some Name" id="query_where_obec_3D598259_text__objectIds__time__geometry__geometryType_...">
    <customproperties>
     <Option type="Map">
      <Option name="cached_name" type="QString" value="Území obce"/>
     </Option>
    </customproperties>
   </layer-tree-layer>
   <custom-order enabled="0"/>
  </layer-tree-group>...

In the "ID" option i need to insert the QGIS variable.

Is this possible or is there another solution for this problem?

EDIT: I must have auto update turned off for custom legend item settings.

REPRODUCIBLE EXAMPLE: Create a label in map composer, save as template (.qpt) and insert a qgis variable in the .qpt file somehow and after opening the template in a new map composer it should appear in the label.

0

1 Answer 1

2

The correct syntax is labelText="[% @myvar %]":

<layer-tree-layer name="Some Name" id="[% @myvar %]">
4
  • Yes, that works! Thank you so much!
    – TomyPoty
    Commented Oct 11, 2022 at 9:51
  • Ad: Can this solution be applied to the layer source? I mean if I replace part of the source with a variable.
    – TomyPoty
    Commented Oct 11, 2022 at 17:46
  • I guess. What happens if you try?
    – MrXsquared
    Commented Oct 11, 2022 at 18:04
  • The layer in the legend is not displayed, only the label. And the layer source does not display the value of the variable, but the entire variable entry.
    – TomyPoty
    Commented Oct 12, 2022 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.