Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nameloCmaS
Copy link
Contributor

Resolves the issue from #1155

Ensures true and false are capitalised properly for Javascript.

@andreaordonselli
Copy link
Collaborator

Thank you very much @nameloCmaS
Are you sure this change won’t disrupt other functionalities of qgis2web based on true/false?
Sometimes, there might be a need for the value True with an uppercase T?
With your code, we are always converting the value to true in all lowercase.

@nameloCmaS
Copy link
Contributor Author

Hi @andreaordonselli

As far as I can tell, the code uses the tokenised version of the expression and this tokenising is done by QGIS.

The node parameter of handle_literal is a QgsExpressionNodeLiteral class and the attribute value is checked if it is type bool. If it is an instance of str where say 'True' was needed with the capital T, it will pick this up in the next if.

You can see the types in the extract from the debugger below:

Screenshot 2025-06-11 at 08 05 23

I note line 196 may be (part?) of the issue in #1157.

@andreaordonselli
Copy link
Collaborator

Have you tested if this change (row 193) resolves the user's issue in #1155 with their specific project, exporting with OpenLayers and Leaflet?
I'm not sure if this file exp2js.py is used by qgis2web; it could solve many things that we now handle manually, like this and many others throughout the code.

olStyleScripts.py
categoryStr = "case '%s':" % value_str.replace("'", "\\'")

@andreaordonselli
Copy link
Collaborator

Good morning,
I am waiting for a response to proceed with this pull.

@nameloCmaS
Copy link
Contributor Author

@andreaordonselli It doesn't fix that issue.

There seems to be a bug in QGIS possibly related to the following issue qgis/QGIS#60324

For me I do not see the coloured areas in the test project file, just the orange dots (in both QGIS and qgis2web).

This is on QGIS 3.40.5

The category values should be whatever auto categorise sets them as (from memory True and ELSE), but this didn't fix it for me either in QGIS.

Using the PyQGIS interface, I sometimes got True and sometimes true (the values do not go through my PR's code).

It might be we need to add a condition for handling boolean fields explicitly.

I will try and do a bit more investigating and report as an issue to QGIS if needed.

This PR's code is more for rule based renderer or anything that processes expressions, and fixed the issue I had for me.

@nameloCmaS
Copy link
Contributor Author

Sorry the second item you reference - exp2js is used in qgis2web but only for converting QGIS expressions to JavaScript; used quite well in the rule based renderer, but not elsewhere.

The manual JavaScript escaping throughout could be replaced with a utility function which would help in maintaining the codebase.

@andreaordonselli
Copy link
Collaborator

Every time I make an update, I must:

  • Simplify the code
  • Make it future-proof and efficient
  • Retain all existing functionalities
  • Solve real user problems

Sometimes, to adhere to this list, more "manual" programming is better than "automated" solutions.
We solve one problem at a time.

Issue #1155 occurs because qgis2web exports "true" and "false" in the layer style but then reads the values as "True" and "False". I suggested to the user not to use a boolean field (where True and False are unmodifiable) but instead to use a text field and define "true" and "false" so that both the style and its reading work correctly.

Let me know your idea for solving this without losing any other functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants