[QGIS-Developer] pyqgis - layer.saveDefaultStyle() for PostGIS layers

kimaidou kimaidou at gmail.com
Mon Sep 25 06:23:08 PDT 2017


Hi,

@ Tom : I really would like to trust QGIS method instead of managing
manually different providers.

@ Luigi
No error message, even worse : i got a message telling everything went well
;)

layer.saveDefaultStyle()
(u'The style dbname=\'qgis\' host=localhost port=5432 user=\'mdouchin\'
sslmode=disable key=\'ogc_fid\' estimatedmetadata=true srid=2154
type=MultiPolygon table="sup"."geo_commune" (geom) sql= was updated in the
database.', True)

But the line is not created in the layer_styles table.

Michaƫl


2017-09-25 14:48 GMT+02:00 Luigi Pirelli <luipir at gmail.com>:

> from the code:
>
> mLayer->saveStyleToDatabase and mLayer->saveDefaultStyle
>
> and in
> QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
> {
>   return saveNamedStyle( styleURI(), theResultFlag );
> }
>
> => seems you are doing correct.
>
> any log message?
>
> ******************************************
>
>
> void QgsVectorLayerProperties::saveDefaultStyle_clicked()
> {
>   apply();
>   QString errorMsg;
>   if ( mLayer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
>   {
>     QMessageBox askToUser;
>     askToUser.setText( tr( "Save default style to: " ) );
>     askToUser.setIcon( QMessageBox::Question );
>     askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole );
>     askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole );
>     askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole
> );
>
>     switch ( askToUser.exec() )
>     {
>       case 0:
>         return;
>       case 2:
>         mLayer->saveStyleToDatabase( "", "", true, "", errorMsg );
>         if ( errorMsg.isNull() )
>         {
>           return;
>         }
>         break;
>       default:
>         break;
>     }
>   }
>
>   bool defaultSavedFlag = false;
>   errorMsg = mLayer->saveDefaultStyle( defaultSavedFlag );
>   if ( !defaultSavedFlag )
>   {
>     QMessageBox::warning( this, tr( "Default Style" ), errorMsg );
>   }
> }
> Luigi Pirelli
>
> ************************************************************
> **************************************
> * Boundless QGIS Support/Development: lpirelli AT boundlessgeo DOT com
> * LinkedIn: https://www.linkedin.com/in/luigipirelli
> * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli
> * GitHub: https://github.com/luipir
> * Mastering QGIS 2nd Edition:
> * https://www.packtpub.com/big-data-and-business-
> intelligence/mastering-qgis-second-edition
> ************************************************************
> **************************************
>
>
> On 25 September 2017 at 13:44, Tom Chadwin <tom.chadwin at nnpa.org.uk>
> wrote:
> > Perhaps you have to do it manually via a PostGIS query matching
> > f_table_catalog, f_table_schema, and f_table_name, and updating styleqml
> and
> > stylesld?
> >
> > Tom
> >
> >
> >
> > -----
> > Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon
> > --
> > Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-
> f4099106.html
> > _______________________________________________
> > QGIS-Developer mailing list
> > QGIS-Developer at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170925/87d28176/attachment-0001.html>


More information about the QGIS-Developer mailing list