Bug report #14884

Default layer style from PostGIS 'layer_style' table not applied at login

Added by Bruce Steedman almost 8 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Unknown
Affected QGIS version:2.14.2 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:22837

Description

I have saved a layer style into my PostgreSQL datasource and selected the 'Use as default style for this layer' checkbox. I save my project and close QGIS. I then change some aspect of the style directly in the database XML- 'layer_styles' table, 'styleqml' field (I edited the 'outline_width' value for a simple renderer as a test). I then save the database record and restart QGIS. The amended style is not loaded from PostGIS and instead the last 'local' copy is loaded - i.e. before the changes I made. The behaviour I expected was that the layer style would be loaded from PostGIS (I verified that the 'useasdefault' field value was 'TRUE').

I have described the issue here: https://gis.stackexchange.com/questions/194607/qgis-not-loading-default-layer-style-from-postgresql-database-on-startup and can confirm that it is still an issue with QGIS 2.14.2. I'd be happy to provide the data that I am using so it can be tested on your systems.

Many thanks

Bruce Steedman

History

#1 Updated by Bruce Steedman over 7 years ago

This is still an issue as of 2.14.3, can someone please take a look at it please? I have also found an article confirming the expected behaviour (not the behaviour I observe) in the section entitled "Change layer Style"
https://publicwiki.deltares.nl/display/OET/Workshop+PostgreSQL,+PostGIS+and+QGIS

Many thanks

#2 Updated by Giovanni Manghi almost 7 years ago

  • Regression? set to No
  • Easy fix? set to No

#3 Updated by Jürgen Fischer over 6 years ago

  • Category set to Unknown

#4 Updated by Regis Haubourg over 6 years ago

  • Description updated (diff)

Looking into various style loading issues here. Do you expect QGIS to override the style saved in your project by the one stored in the database?

IMHO, the default style is only supposed to be applied when adding a raw table from the PG connection dialog or the browser dock. Overriding a project file is not something we usually expect. Please correct me if I misunderstood your description.

#5 Updated by Giovanni Manghi over 6 years ago

  • Status changed from Open to Feedback

#6 Updated by Bruce Steedman over 6 years ago

Thanks for looking at this Giovanni

Yes. The docs (link below) say: "When loading a layer from the database, if a style already exists for this layer, QGIS will load the layer and its style". It is indeed loaded. However, if the 'useasdefault' flag is set in the layer_style table, the style is not applied on load (though it can be selected manually). With this flag set I would expect the renderer in the database (XML) to be applied at startup/load - otherwise what is the purpose of recording whether or not a style is the default in the database?!

This is not what I observe (confirmed in 2.18).

http://docs.qgis.org/2.8/en/docs/user_manual/working_with_vector/vector_properties.html?highlight=style

#7 Updated by Harrissou Santanna over 6 years ago

Bruce Steedman wrote:

Thanks for looking at this Giovanni

Yes. The docs (link below) say: "When loading a layer from the database, if a style already exists for this layer, QGIS will load the layer and its style".

otherwise what is the purpose of recording whether or not a style is the default in the database?!

Here, unless I misunderstood, you are not loading the layer; you are opening a project tha loads the layer. A project in which you had already setup the style to use for that layer.
Afaik, the default style is applied when you add a new layer to the project and only at that moment. Otherwise, that would mean that once you have defined a default style in PG, it will be impossible to use another one on the layer because each time you open your project, QGIS will fetch that saved style from PG and overwrite the one used in the project.

#8 Updated by Bruce Steedman over 6 years ago

So perhaps I am misunderstanding the significance of the 'useasdefault' flag. How does setting this flag in the layer_style table modify the behaviour you describe? My current understanding is that a layer's default style should be applied when a project is opened, is that wrong?

If I am wrong & the behaviour I observe is correct, I will look at doing this in Python - which would answer this question: https://gis.stackexchange.com/questions/64600/how-to-load-the-default-layer-style-from-postgresql-with-python

Many thanks.

#9 Updated by Harrissou Santanna over 6 years ago

My current understanding is that a layer's default style should be applied when a project is opened, is that wrong?

I think it's wrong. NOT when a project is opened. A layer's default style should be applied when the layer is added to QGIS (when you use the browser, the db manager, the add a vector, a python command....or anything else to import your data in your project). At that time, QGIS checks if the datasource has a default style (in PG in this case) and applies it to the layer.

But if you already have the layer available in a saved project and you open that project, QGIS will show the layer with its style when you closed the project ( ie, the one you set in the project and saved within). To apply the default style (graphically), you'd need to go to layer properties and use "Restore Default" command from the style drop-down. Should be possible programmatically, also.

#10 Updated by Bruce Steedman over 6 years ago

OK, will look at writing a macro to do this. Many thanks for clarifying this Harrissou, please close this ticket.

#11 Updated by Giovanni Manghi over 6 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

Also available in: Atom PDF