Skip to content

Commit 2d2ce00

Browse files
authored
Merge pull request #3665 from rouault/save_style_gpkg
[FEATURE] [OGR provider] Load/save style in database for GPKG and Spatialite
2 parents 469f07c + 3bb7d5c commit 2d2ce00

File tree

6 files changed

+736
-64
lines changed

6 files changed

+736
-64
lines changed

doc/api_break.dox

+3
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,9 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.</li>
14381438
<li>Removed fieldNameIndex(), use fields().lookupField() or fields().indexFromName() instead
14391439
<li>Renamed addAttributeAlias() to setFieldAlias()
14401440
<li>Renamed remAttributeAlias() to removeFieldAlias()
1441+
<li>saveStyleToDatabase(): msgError argument is correctly declared as output argument
1442+
<li>getStyleFromDatabase(): msgError argument is correctly declared as output argument
1443+
<li>loadNamedStyle(): theResultFlag argument is correctly declared as output argument
14411444
</ul>
14421445

14431446
\subsection qgis_api_break_3_0_QgsVectorLayerEditBuffer QgsVectorLayerEditBuffer

python/core/qgsvectorlayer.sip

+5-5
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ class QgsVectorLayer : QgsMapLayer
662662
* @param description
663663
* @param useAsDefault
664664
* @param uiFileContent
665-
* @param msgError
665+
* @param msgError (out)
666666
*/
667667
virtual void saveStyleToDatabase( const QString& name, const QString& description,
668668
bool useAsDefault, const QString& uiFileContent,
669-
QString &msgError );
669+
QString &msgError /Out/ );
670670

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

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

695695
/**
696696
* Calls loadNamedStyle( theURI, theResultFlag, false );
697697
* Retained for backward compatibility
698698
*/
699-
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
699+
virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag /Out/ );
700700

701701
/** Read the symbology for the current layer from the Dom node supplied.
702702
* @param node node that will contain the symbology definition for this layer.

src/core/qgsvectorlayer.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,14 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
19471947
mConditionalStyles->writeXml( node, doc );
19481948

19491949
// save expression fields
1950-
mExpressionFieldBuffer->writeXml( node, doc );
1950+
if ( !mExpressionFieldBuffer )
1951+
{
1952+
// can happen when saving style on a invalid layer
1953+
QgsExpressionFieldBuffer dummy;
1954+
dummy.writeXml( node, doc );
1955+
}
1956+
else
1957+
mExpressionFieldBuffer->writeXml( node, doc );
19511958

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

0 commit comments

Comments
 (0)