qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.49k stars 2.99k forks source link

map_to_html_table expression function doesn't seem to respect keys order #56127

Open DelazJ opened 8 months ago

DelazJ commented 8 months ago

What is the bug or the crash?

Let's use this expression in the expression builder and watch the output

map_to_html_table(
  map(
    'qgis','rocks',
    'gdal', 'rocks also')
)

I would expect "qgis" as first column in the output table and not "gdal".

Steps to reproduce the issue

image

Versions

Also affects 3.34

QGIS version | 3.35.0-Master | QGIS code revision | 4fbc42fd2b -- | -- | -- | -- Qt version | 5.15.3 Python version | 3.9.18 Compiled against GDAL/OGR | 3.9.0dev-527b897e63 | Running against GDAL/OGR | 3.9.0dev-da8d8118a9 PROJ version | 9.3.1 EPSG Registry database version | v10.098 (2023-11-24) GEOS version | 3.12.1-CAPI-1.18.1 SQLite version | 3.41.1 PDAL version | 2.6.0 PostgreSQL client version | 15.2 SpatiaLite version | 5.1.0 QWT version | 6.1.6 QScintilla2 version | 2.13.4 OS version | Windows 10 Version 2009   |   |   |   This copy of QGIS writes debugging output.   |   |   |   Active Python plugins bdtopo_importer | 0.2 cadastre | 1.18.0 lizmap | 4.1.1 MapsPrinter | 0.9 plugin_reloader | 0.9.3 db_manager | 0.1.20 grassprovider | 2.12.99 MetaSearch | 0.3.6 processing | 2.12.99 ### Supported QGIS version - [ ] I'm running a supported QGIS version according to [the roadmap](https://www.qgis.org/en/site/getinvolved/development/roadmap.html#release-schedule). ### New profile - [ ] I tried with a new [QGIS profile](https://docs.qgis.org/latest/en/docs/user_manual/introduction/qgis_configuration.html#working-with-user-profiles) ### Additional context _No response_
DelazJ commented 8 months ago

Well, further testing... It seems that it is the map function that displays an output with keys alphabetically ordered map('qgis','rocks', 'arcgis', 'doesn''t rock', 'gdal', 'rocks also') outputs { 'arcgis': 'doesn't rock', 'gdal': 'rocks also', 'qgis': 'rocks' }

ps: I don't know if this is an issue (or to what extent it would be fixable, as if I'm not wrong, maps do not have order concepts), but I wonder how one could control the map_to_html_table output order (e.g. for display in a maptip)

NathanW2 commented 8 months ago

@DelazJ Yeah you're right the issue here is going to be the map as it ordered by key.

You could make a Python expression function to do your tooltip logic although not as portable as a built in function.

Might be handy to have a to_html function that can take a element type and data and convert it into different elements possibly. So you could do to_html('ul', data) that makes a list from given data.