Feature request #10523
Postgis provider: a styles in layer_style with useasdefault set to false are used as default style
|Pull Request or Patch supplied:||Yes||Resolution:|
|Easy fix?:||No||Copied to github as #:||18933|
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).
When I open the layer without any project, one of the styles is applied, in particular the one with update_time more recent.
When I open the layer without any project, no style is applied
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" )
#1 Updated by Gabriele Monfardini almost 9 years ago
- File 10523.patch added
#2 Updated by Giovanni Manghi almost 9 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 almost 9 years ago
- Category set to Data Provider/PostGIS
#4 Updated by Jürgen Fischer almost 9 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 about 6 years ago
- Easy fix? set to No