Feature request #10523
Postgis provider: a styles in layer_style with useasdefault set to false are used as default style
Status: | Open | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Data Provider/PostGIS | ||
Pull Request or Patch supplied: | Yes | Resolution: | |
Easy fix?: | No | Copied to github as #: | 18933 |
Description
I have a postgis layer with several styles saved in table public.layer_styles.
All styles have useasdefault set to false (these styles only makes sense within some projects, should not be used as default styles).
Obtained results¶
When I open the layer without any project, one of the styles is applied, in particular the one with update_time more recent.
Expected results¶
When I open the layer without any project, no style is applied
Discussion¶
The exact query that finds the default style is in ~qgis/src/providers/postgres/qgspostgresprovider.cpp, line 3464
QString selectQmlQuery = QString( "SELECT styleQML" " FROM layer_styles" " WHERE f_table_catalog=%1" " AND f_table_schema=%2" " AND f_table_name=%3" " AND f_geometry_column=%4" " ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END" ",update_time DESC LIMIT 1" )
In my opinion rows with useasdefault set to false should be completely filtered out by the query.
If all styles have useasdefault set to false, current query retrieves the most recent style while I think that no rows should be retrieved in this case and a "random color" style be applied.
Thus I propose to change the query to:
QString selectQmlQuery = QString( "SELECT styleQML" " FROM layer_styles" " WHERE f_table_catalog=%1" " AND f_table_schema=%2" " AND f_table_name=%3" " AND f_geometry_column=%4" " WHERE useAsDefault" " ORDER BY update_time DESC LIMIT 1" )
History
#1 Updated by Gabriele Monfardini over 10 years ago
- File 10523.patch added
#2 Updated by Giovanni Manghi over 10 years ago
better propose a patch as a pul request on qgis github repository, here it will probably not seen/reviewed by devs.
#3 Updated by Jürgen Fischer over 10 years ago
- Category set to Data Provider/PostGIS
#4 Updated by Jürgen Fischer over 10 years ago
- Tracker changed from Bug report to Feature request
There are two order criteria - first useDefault, second update_time. So the style with default comes first and the reset is ordered by update_time - that means if there is no style with useDefault the most current non-default style is taken. IMHO that's no bug - although the other behavior also makes sense.
#5 Updated by Giovanni Manghi over 7 years ago
- Easy fix? set to No