Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3665 from rouault/save_style_gpkg
 [FEATURE] [OGR provider] Load/save style in database for GPKG and Spatialite
  • Loading branch information
rouault committed Oct 26, 2016
2 parents 469f07c + 3bb7d5c commit 2d2ce00
Show file tree
Hide file tree
Showing 6 changed files with 736 additions and 64 deletions.
3 changes: 3 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1438,6 +1438,9 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.</li>
<li>Removed fieldNameIndex(), use fields().lookupField() or fields().indexFromName() instead
<li>Renamed addAttributeAlias() to setFieldAlias()
<li>Renamed remAttributeAlias() to removeFieldAlias()
<li>saveStyleToDatabase(): msgError argument is correctly declared as output argument
<li>getStyleFromDatabase(): msgError argument is correctly declared as output argument
<li>loadNamedStyle(): theResultFlag argument is correctly declared as output argument
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer
Expand Down
10 changes: 5 additions & 5 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -662,11 +662,11 @@ class QgsVectorLayer : QgsMapLayer
* @param description
* @param useAsDefault
* @param uiFileContent
* @param msgError
* @param msgError (out)
*/
virtual void saveStyleToDatabase( const QString& name, const QString& description,
bool useAsDefault, const QString& uiFileContent,
QString &msgError );
QString &msgError /Out/ );

/**
* Lists all the style in db split into related to the layer and not related to
Expand All @@ -682,21 +682,21 @@ class QgsVectorLayer : QgsMapLayer
/**
* Will return the named style corresponding to style id provided
*/
virtual QString getStyleFromDatabase( const QString& styleId, QString &msgError );
virtual QString getStyleFromDatabase( const QString& styleId, QString &msgError /Out/ );

/**
* Load a named style from file/local db/datasource db
* @param theURI the URI of the style or the URI of the layer
* @param theResultFlag will be set to true if a named style is correctly loaded
* @param loadFromLocalDb if true forces to load from local db instead of datasource one
*/
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag, bool loadFromLocalDb );
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag /Out/, bool loadFromLocalDb );

/**
* Calls loadNamedStyle( theURI, theResultFlag, false );
* Retained for backward compatibility
*/
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag /Out/ );

/** Read the symbology for the current layer from the Dom node supplied.
* @param node node that will contain the symbology definition for this layer.
Expand Down
11 changes: 9 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1947,7 +1947,14 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
mConditionalStyles->writeXml( node, doc );

// save expression fields
mExpressionFieldBuffer->writeXml( node, doc );
if ( !mExpressionFieldBuffer )
{
// can happen when saving style on a invalid layer
QgsExpressionFieldBuffer dummy;
dummy.writeXml( node, doc );
}
else
mExpressionFieldBuffer->writeXml( node, doc );

// save readonly state
node.toElement().setAttribute( QStringLiteral( "readOnly" ), mReadOnly );
Expand Down Expand Up @@ -4107,7 +4114,7 @@ QString QgsVectorLayer::loadNamedStyle( const QString &theURI, bool &theResultFl
QString QgsVectorLayer::loadNamedStyle( const QString &theURI, bool &theResultFlag, bool loadFromLocalDB )
{
QgsDataSourceUri dsUri( theURI );
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
if ( !loadFromLocalDB && mDataProvider && mDataProvider->isSaveAndLoadStyleToDBSupported() )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
Expand Down

0 comments on commit 2d2ce00

Please sign in to comment.