diff --git a/doc/api_break.dox b/doc/api_break.dox index 6678597bcf1..25d3f6dac3f 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -762,6 +762,16 @@ all these item added events. - addComposerMap no longer takes a setDefaultPreviewStyle argument. - the mapsToRestore parameter has been removed from addItemsFromXml +QgsConditionalLayerStyle {#qgis_api_break_3_0_QgsConditionalLayerStyle} +------------------------ + +- readXml() and writeXml() require a new argument: a reference to QgsReadWriteContext + +QgsConditionalStyle {#qgis_api_break_3_0_QgsConditionalStyle} +------------------- + +- readXml() and writeXml() require a new argument: a reference to QgsReadWriteContext + QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem} ---------------------------- @@ -921,6 +931,8 @@ QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer} - referencedFields() no longer takes a QgsFields argument. - renderDiagram() now takes an optional data defined overrides collection argument. - readXml(), _readXml(), writeXml(), _writeXml() do not take QgsVectorLayer as an argument anymore. +- readXml(), _readXml(), writeXml(), _writeXml() require a new argument: a reference to QgsReadWriteContext + QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings} @@ -1098,6 +1110,8 @@ QgsFeatureRendererV2 {#qgis_api_break_3_0_QgsFeatureRendererV2} - originalSymbolsForFeature( QgsFeature& feat ) has been removed. The originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) method should be used instead (previously available as originalSymbolsForFeature2 in PyQGIS bindings). - copyPaintEffect() was removed. copyRendererData() should be used instead. - usedAttributes() now requires a QgsRenderContext argument. +- save() expects QgsReadWriteContext reference as the last argument +- static create() method in subclasses expects QgsReadWriteContext reference as the last argument QgsFeatureRequest {#qgis_api_break_3_0_QgsFeatureRequest} @@ -1417,6 +1431,9 @@ screenUpdateRequested() were removed. These members have had no effect for a num - asLayerDefinition(), fromLayerDefinition(), fromLayerDefinitionFile() were moved to QgsLayerDefinition class and renamed to exportLayerDefinitionLayers() resp. loadLayerDefinitionLayers() - loadNamedStyleFromDb() was renamed to loadNamedStyleFromDatabase() - readLayerXml() and writeLayerXml() expect QgsReadWriteContext reference as the last argument +- readSymbology() and writeSymbology() expect QgsReadWriteContext reference as the last argument +- readStyle() and writeStyle() expect QgsReadWriteContext reference as the last argument +- readXml() and writeXml() expect QgsReadWriteContext reference as the last argument - the invalidTransformInput() slot was removed - calling this slot had no effect - metadata() was renamed to htmlMetadata() @@ -1627,6 +1644,7 @@ dataDefinedValue(), dataDefinedEvaluate(), dataDefinedIsActive(), dataDefinedUseExpression(), dataDefinedProperties() and dataDefinedNames() members were removed. Use the QgsProperty framework through dataDefinedProperties() and setDataDefinedProperties() instead. +- readXml() and writeXml() now expect a reference to QgsReadWriteContext. QgsPanelWidgetStack {#qgis_api_break_3_0_QgsPanelWidgetStack} @@ -1944,11 +1962,26 @@ QgsSvgCache {#qgis_api_break_3_0_QgsSvgCache} - This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::svgCache() to access an application-wide cache. - containsParamsV2() was removed. Use containsParamsV3() instead. - The rasterScaleFactor parameter was removed from all methods +- svgAsImage(), svgAsPicture(), svgViewboxSize(), svgContent(), insertSvg(), cacheEntry() only accept absolute path to SVG file (relative paths will not be resolved). QgsSvgCacheEntry {#qgis_api_break_3_0_QgsSvgCacheEntry} ---------------- - The rasterScaleFactor member was removed. +- The lookupKey member was removed. +- The "file" member has been renamed to "path". +- Constructor does not take lookup key as an optional last argument + + +QgsSVGFillSymbolLayer {#qgis_api_break_3_0_QgsSVGFillSymbolLayer} +--------------------- + +- The first argument of the constructor (svgFilePath) does not have default value anymore. + +QgsSvgMarkerSymbolLayer {#qgis_api_break_3_0_QgsSvgMarkerSymbolLayer} +----------------------- + +- The first argument of the constructor (path) does not have a default value anymore. QgsStyle (renamed from QgsStyleV2) {#qgis_api_break_3_0_QgsStyle} ---------------------------------- @@ -2025,6 +2058,8 @@ QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break - pixelSizeScaleFactor() was removed. Use QgsRenderContext::convertToPainterUnits() instead. - mapUnitScaleFactor() was removed. Use QgsRenderContext::convertToMapUnits() instead. - estimateMaxSymbolBleed() now requires a QgsRenderContext argument (since the bleed depends on render context for non-pixel units) +- loadSymbol(), saveSymbol(), loadSymbols(), saveSymbols(), loadSymbolLayer() now require a reference to QgsReadWriteContext +- symbolNameToPath() and symbolPathToName() have been renamed to svgSymbolNameToPath() and svgSymbolPathToName() and they require reference to QgsPathResolver QgsSymbolSelectorWidget {#qgis_api_break_3_0_QgsSymbolSelectorWidget} @@ -2254,6 +2289,11 @@ optional property map passing down layer level properties to the SLD encoders. I - setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level - usedAttributes is now a const method and returns QSet instead of QStringList +QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata} +--------------------------- + +- createRenderer() now expects a reference to QgsReadWriteContext as the second argument + Processing {#qgis_api_break_3_0_Processing} ---------- diff --git a/python/core/qgspallabeling.sip b/python/core/qgspallabeling.sip index 4f284792ea3..aaa29c85d03 100644 --- a/python/core/qgspallabeling.sip +++ b/python/core/qgspallabeling.sip @@ -426,12 +426,12 @@ class QgsPalLayerSettings /** Read settings from a DOM element * @note added in 2.12 */ - void readXml( QDomElement &elem ); + void readXml( QDomElement& elem, const QgsReadWriteContext &context ); /** Write settings into a DOM element * @note added in 2.12 */ - QDomElement writeXml( QDomDocument &doc ); + QDomElement writeXml( QDomDocument& doc, const QgsReadWriteContext &context ); QgsPropertyCollection &dataDefinedProperties(); diff --git a/python/core/qgstextrenderer.sip b/python/core/qgstextrenderer.sip index c55f01d0b06..bf6fa66e063 100644 --- a/python/core/qgstextrenderer.sip +++ b/python/core/qgstextrenderer.sip @@ -304,7 +304,7 @@ class QgsTextBackgroundSettings QString svgFile() const; %Docstring - Returns the path to the background SVG file, if set. + Returns the absolute path to the background SVG file, if set. .. seealso:: setSvgFile() :rtype: str %End @@ -312,8 +312,8 @@ class QgsTextBackgroundSettings void setSvgFile( const QString &file ); %Docstring Sets the path to the background SVG file. This is only used if type() is set to - QgsTextBackgroundSettings.ShapeSVG. - \param file SVG file path + QgsTextBackgroundSettings.ShapeSVG. The path must be absolute. + \param file Absolute SVG file path .. seealso:: svgFile() %End @@ -688,13 +688,13 @@ class QgsTextBackgroundSettings .. seealso:: readFromLayer() %End - void readXml( const QDomElement &elem ); + void readXml( const QDomElement &elem, const QgsReadWriteContext &context ); %Docstring Read settings from a DOM element. .. seealso:: writeXml() %End - QDomElement writeXml( QDomDocument &doc ) const; + QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const; %Docstring Write settings into a DOM element. .. seealso:: readXml() @@ -1251,13 +1251,13 @@ class QgsTextFormat .. seealso:: readFromLayer() %End - void readXml( const QDomElement &elem ); + void readXml( const QDomElement &elem, const QgsReadWriteContext &context ); %Docstring Read settings from a DOM element. .. seealso:: writeXml() %End - QDomElement writeXml( QDomDocument &doc ) const; + QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const; %Docstring Write settings into a DOM element. .. seealso:: readXml() diff --git a/src/app/qgslabelingwidget.cpp b/src/app/qgslabelingwidget.cpp index 670e71cd398..94741f829c3 100644 --- a/src/app/qgslabelingwidget.cpp +++ b/src/app/qgslabelingwidget.cpp @@ -20,6 +20,7 @@ #include "qgslabelengineconfigdialog.h" #include "qgslabelinggui.h" +#include "qgsreadwritecontext.h" #include "qgsrulebasedlabelingwidget.h" #include "qgsvectorlayer.h" #include "qgsvectorlayerlabeling.h" @@ -75,8 +76,8 @@ void QgsLabelingWidget::setLayer( QgsMapLayer *mapLayer ) if ( mLayer->labeling() ) { QDomDocument doc; - QDomElement oldSettings = mLayer->labeling()->save( doc ); - mOldSettings.reset( QgsAbstractVectorLayerLabeling::create( oldSettings ) ); + QDomElement oldSettings = mLayer->labeling()->save( doc, QgsReadWriteContext() ); + mOldSettings.reset( QgsAbstractVectorLayerLabeling::create( oldSettings, QgsReadWriteContext() ) ); mOldPalSettings.readFromLayer( mLayer ); } else diff --git a/src/app/qgsrulebasedlabelingwidget.cpp b/src/app/qgsrulebasedlabelingwidget.cpp index c962e9b7c2e..3dcfc5bdbe9 100644 --- a/src/app/qgsrulebasedlabelingwidget.cpp +++ b/src/app/qgsrulebasedlabelingwidget.cpp @@ -20,6 +20,7 @@ #include "qgslabelinggui.h" #include "qgsmapcanvas.h" #include "qgsproject.h" +#include "qgsreadwritecontext.h" #include "qgsrulebasedlabeling.h" #include "qgsvectorlayer.h" #include "qgsvectorlayerlabeling.h" @@ -479,7 +480,7 @@ QMimeData *QgsRuleBasedLabelingModel::mimeData( const QModelIndexList &indexes ) QDomElement rootElem = doc.createElement( QStringLiteral( "rule_mime" ) ); rootElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "labeling" ) ); // for determining whether rules are from renderer or labeling - QDomElement rulesElem = rule->save( doc ); + QDomElement rulesElem = rule->save( doc, QgsReadWriteContext() ); rootElem.appendChild( rulesElem ); doc.appendChild( rootElem ); @@ -529,7 +530,7 @@ bool QgsRuleBasedLabelingModel::dropMimeData( const QMimeData *data, Qt::DropAct QDomElement ruleElem = rootElem.firstChildElement( QStringLiteral( "rule" ) ); if ( rootElem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "renderer" ) ) _renderer2labelingRules( ruleElem ); // do some modifications so that we load the rules more nicely - QgsRuleBasedLabeling::Rule *rule = QgsRuleBasedLabeling::Rule::create( ruleElem ); + QgsRuleBasedLabeling::Rule *rule = QgsRuleBasedLabeling::Rule::create( ruleElem, QgsReadWriteContext() ); insertRule( parent, row + rows, rule ); diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index 6772ade7b9b..6ab87a51373 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -768,7 +768,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer *layer ) layer->emitStyleChanged(); } -void QgsPalLayerSettings::readXml( QDomElement &elem ) +void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext &context ) { enabled = true; drawLabels = true; @@ -778,7 +778,7 @@ void QgsPalLayerSettings::readXml( QDomElement &elem ) fieldName = textStyleElem.attribute( QStringLiteral( "fieldName" ) ); isExpression = textStyleElem.attribute( QStringLiteral( "isExpression" ) ).toInt(); - mFormat.readXml( elem ); + mFormat.readXml( elem, context ); previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral( "previewBkgrdColor" ), QStringLiteral( "#ffffff" ) ) ); substitutions.readXml( textStyleElem.firstChildElement( QStringLiteral( "substitutions" ) ) ); useSubstitutions = textStyleElem.attribute( QStringLiteral( "useSubstitutions" ) ).toInt(); @@ -889,11 +889,11 @@ void QgsPalLayerSettings::readXml( QDomElement &elem ) -QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc ) +QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) { // we assume (enabled == true && drawLabels == true) so those are not saved - QDomElement textStyleElem = mFormat.writeXml( doc ); + QDomElement textStyleElem = mFormat.writeXml( doc, context ); // text style textStyleElem.setAttribute( QStringLiteral( "fieldName" ), fieldName ); diff --git a/src/core/qgspallabeling.h b/src/core/qgspallabeling.h index c5f030a0943..fcec086145e 100644 --- a/src/core/qgspallabeling.h +++ b/src/core/qgspallabeling.h @@ -531,12 +531,12 @@ class CORE_EXPORT QgsPalLayerSettings /** Read settings from a DOM element * \since QGIS 2.12 */ - void readXml( QDomElement &elem ); + void readXml( QDomElement &elem, const QgsReadWriteContext &context ); /** Write settings into a DOM element * \since QGIS 2.12 */ - QDomElement writeXml( QDomDocument &doc ); + QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ); /** Returns a reference to the label's property collection, used for data defined overrides. * \since QGIS 3.0 diff --git a/src/core/qgsrulebasedlabeling.cpp b/src/core/qgsrulebasedlabeling.cpp index ca92647044b..ffc991aa370 100644 --- a/src/core/qgsrulebasedlabeling.cpp +++ b/src/core/qgsrulebasedlabeling.cpp @@ -193,14 +193,14 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::clone() const return newrule; } -QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElement &ruleElem ) +QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) { QgsPalLayerSettings *settings = nullptr; QDomElement settingsElem = ruleElem.firstChildElement( QStringLiteral( "settings" ) ); if ( !settingsElem.isNull() ) { settings = new QgsPalLayerSettings; - settings->readXml( settingsElem ); + settings->readXml( settingsElem, context ); } QString filterExp = ruleElem.attribute( QStringLiteral( "filter" ) ); @@ -218,7 +218,7 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElemen QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral( "rule" ) ); while ( !childRuleElem.isNull() ) { - Rule *childRule = create( childRuleElem ); + Rule *childRule = create( childRuleElem, context ); if ( childRule ) { rule->appendChild( childRule ); @@ -233,13 +233,13 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElemen return rule; } -QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc ) const +QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc, const QgsReadWriteContext &context ) const { QDomElement ruleElem = doc.createElement( QStringLiteral( "rule" ) ); if ( mSettings ) { - ruleElem.appendChild( mSettings->writeXml( doc ) ); + ruleElem.appendChild( mSettings->writeXml( doc, context ) ); } if ( !mFilterExp.isEmpty() ) ruleElem.setAttribute( QStringLiteral( "filter" ), mFilterExp ); @@ -256,7 +256,7 @@ QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc ) const for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it ) { Rule *rule = *it; - ruleElem.appendChild( rule->save( doc ) ); + ruleElem.appendChild( rule->save( doc, context ) ); } return ruleElem; } @@ -401,11 +401,11 @@ QgsRuleBasedLabeling::~QgsRuleBasedLabeling() } -QgsRuleBasedLabeling *QgsRuleBasedLabeling::create( const QDomElement &element ) +QgsRuleBasedLabeling *QgsRuleBasedLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) { QDomElement rulesElem = element.firstChildElement( QStringLiteral( "rules" ) ); - Rule *root = Rule::create( rulesElem ); + Rule *root = Rule::create( rulesElem, context ); if ( !root ) return nullptr; @@ -418,12 +418,12 @@ QString QgsRuleBasedLabeling::type() const return QStringLiteral( "rule-based" ); } -QDomElement QgsRuleBasedLabeling::save( QDomDocument &doc ) const +QDomElement QgsRuleBasedLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const { QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) ); elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "rule-based" ) ); - QDomElement rulesElem = mRootRule->save( doc ); + QDomElement rulesElem = mRootRule->save( doc, context ); rulesElem.setTagName( QStringLiteral( "rules" ) ); // instead of just "rule" elem.appendChild( rulesElem ); diff --git a/src/core/qgsrulebasedlabeling.h b/src/core/qgsrulebasedlabeling.h index 43410607023..66b326c7dca 100644 --- a/src/core/qgsrulebasedlabeling.h +++ b/src/core/qgsrulebasedlabeling.h @@ -241,10 +241,10 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling * \param ruleElem The XML rule element * \returns A new rule */ - static Rule *create( const QDomElement &ruleElem ); + static Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ); //! store labeling info to XML element - QDomElement save( QDomDocument &doc ) const; + QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const; // evaluation @@ -323,12 +323,12 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling const Rule *rootRule() const { return mRootRule; } //! Create the instance from a DOM element with saved configuration - static QgsRuleBasedLabeling *create( const QDomElement &element ); + static QgsRuleBasedLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ); // implementation of parent interface virtual QString type() const override; - virtual QDomElement save( QDomDocument &doc ) const override; + virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override; virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override; virtual QStringList subProviders() const override; virtual QgsPalLayerSettings settings( QgsVectorLayer *layer, const QString &providerId = QString() ) const override; diff --git a/src/core/qgstextrenderer.cpp b/src/core/qgstextrenderer.cpp index 5c2e98734b8..1db803b25df 100644 --- a/src/core/qgstextrenderer.cpp +++ b/src/core/qgstextrenderer.cpp @@ -18,6 +18,8 @@ #include "qgis.h" #include "qgstextrenderer_p.h" #include "qgsfontutils.h" +#include "qgspathresolver.h" +#include "qgsreadwritecontext.h" #include "qgsvectorlayer.h" #include "qgssymbollayerutils.h" #include "qgspainting.h" @@ -805,14 +807,12 @@ void QgsTextBackgroundSettings::writeToLayer( QgsVectorLayer *layer ) const } } -void QgsTextBackgroundSettings::readXml( const QDomElement &elem ) +void QgsTextBackgroundSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { - // TODO: convert relative path to absolute - QDomElement backgroundElem = elem.firstChildElement( QStringLiteral( "background" ) ); d->enabled = backgroundElem.attribute( QStringLiteral( "shapeDraw" ), QStringLiteral( "0" ) ).toInt(); d->type = static_cast< ShapeType >( backgroundElem.attribute( QStringLiteral( "shapeType" ), QString::number( ShapeRectangle ) ).toUInt() ); - d->svgFile = backgroundElem.attribute( QStringLiteral( "shapeSVGFile" ) ); + d->svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( backgroundElem.attribute( QStringLiteral( "shapeSVGFile" ) ), context.pathResolver() ); d->sizeType = static_cast< SizeType >( backgroundElem.attribute( QStringLiteral( "shapeSizeType" ), QString::number( SizeBuffer ) ).toUInt() ); d->size = QSizeF( backgroundElem.attribute( QStringLiteral( "shapeSizeX" ), QStringLiteral( "0" ) ).toDouble(), backgroundElem.attribute( QStringLiteral( "shapeSizeY" ), QStringLiteral( "0" ) ).toDouble() ); @@ -924,14 +924,12 @@ void QgsTextBackgroundSettings::readXml( const QDomElement &elem ) setPaintEffect( nullptr ); } -QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc ) const +QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const { - // TODO: convert absolute path to relative - QDomElement backgroundElem = doc.createElement( QStringLiteral( "background" ) ); backgroundElem.setAttribute( QStringLiteral( "shapeDraw" ), d->enabled ); backgroundElem.setAttribute( QStringLiteral( "shapeType" ), static_cast< unsigned int >( d->type ) ); - backgroundElem.setAttribute( QStringLiteral( "shapeSVGFile" ), d->svgFile ); + backgroundElem.setAttribute( QStringLiteral( "shapeSVGFile" ), QgsSymbolLayerUtils::svgSymbolPathToName( d->svgFile, context.pathResolver() ) ); backgroundElem.setAttribute( QStringLiteral( "shapeSizeType" ), static_cast< unsigned int >( d->sizeType ) ); backgroundElem.setAttribute( QStringLiteral( "shapeSizeX" ), d->size.width() ); backgroundElem.setAttribute( QStringLiteral( "shapeSizeY" ), d->size.height() ); @@ -1549,7 +1547,7 @@ void QgsTextFormat::writeToLayer( QgsVectorLayer *layer ) const mBackgroundSettings.writeToLayer( layer ); } -void QgsTextFormat::readXml( const QDomElement &elem ) +void QgsTextFormat::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { QDomElement textStyleElem = elem.firstChildElement( QStringLiteral( "text-style" ) ); QFont appFont = QApplication::font(); @@ -1651,15 +1649,15 @@ void QgsTextFormat::readXml( const QDomElement &elem ) } if ( textStyleElem.firstChildElement( QStringLiteral( "background" ) ).isNull() ) { - mBackgroundSettings.readXml( elem ); + mBackgroundSettings.readXml( elem, context ); } else { - mBackgroundSettings.readXml( textStyleElem ); + mBackgroundSettings.readXml( textStyleElem, context ); } } -QDomElement QgsTextFormat::writeXml( QDomDocument &doc ) const +QDomElement QgsTextFormat::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const { // text style QDomElement textStyleElem = doc.createElement( QStringLiteral( "text-style" ) ); @@ -1681,7 +1679,7 @@ QDomElement QgsTextFormat::writeXml( QDomDocument &doc ) const textStyleElem.setAttribute( QStringLiteral( "multilineHeight" ), d->multilineHeight ); textStyleElem.appendChild( mBufferSettings.writeXml( doc ) ); - textStyleElem.appendChild( mBackgroundSettings.writeXml( doc ) ); + textStyleElem.appendChild( mBackgroundSettings.writeXml( doc, context ) ); textStyleElem.appendChild( mShadowSettings.writeXml( doc ) ); return textStyleElem; } diff --git a/src/core/qgstextrenderer.h b/src/core/qgstextrenderer.h index 34fef349ee6..378f9cb8041 100644 --- a/src/core/qgstextrenderer.h +++ b/src/core/qgstextrenderer.h @@ -27,6 +27,7 @@ #include #include +class QgsReadWriteContext; class QgsTextBufferSettingsPrivate; class QgsTextBackgroundSettingsPrivate; class QgsTextShadowSettingsPrivate; @@ -284,14 +285,14 @@ class CORE_EXPORT QgsTextBackgroundSettings */ void setType( ShapeType type ); - /** Returns the path to the background SVG file, if set. + /** Returns the absolute path to the background SVG file, if set. * \see setSvgFile() */ QString svgFile() const; /** Sets the path to the background SVG file. This is only used if type() is set to - * QgsTextBackgroundSettings::ShapeSVG. - * \param file SVG file path + * QgsTextBackgroundSettings::ShapeSVG. The path must be absolute. + * \param file Absolute SVG file path * \see svgFile() */ void setSvgFile( const QString &file ); @@ -605,12 +606,12 @@ class CORE_EXPORT QgsTextBackgroundSettings /** Read settings from a DOM element. * \see writeXml() */ - void readXml( const QDomElement &elem ); + void readXml( const QDomElement &elem, const QgsReadWriteContext &context ); /** Write settings into a DOM element. * \see readXml() */ - QDomElement writeXml( QDomDocument &doc ) const; + QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const; private: @@ -1087,12 +1088,12 @@ class CORE_EXPORT QgsTextFormat /** Read settings from a DOM element. * \see writeXml() */ - void readXml( const QDomElement &elem ); + void readXml( const QDomElement &elem, const QgsReadWriteContext &context ); /** Write settings into a DOM element. * \see readXml() */ - QDomElement writeXml( QDomDocument &doc ) const; + QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const; /** Returns true if any component of the font format requires advanced effects * such as blend modes, which require output in raster formats to be fully respected. diff --git a/src/core/qgstextrenderer_p.h b/src/core/qgstextrenderer_p.h index ff2db4fe532..01865b27f3c 100644 --- a/src/core/qgstextrenderer_p.h +++ b/src/core/qgstextrenderer_p.h @@ -151,7 +151,7 @@ class CORE_EXPORT QgsTextBackgroundSettingsPrivate : public QSharedData bool enabled; QgsTextBackgroundSettings::ShapeType type; - QString svgFile; + QString svgFile; //!< Absolute path to SVG file QgsTextBackgroundSettings::SizeType sizeType; QSizeF size; QgsUnitTypes::RenderUnit sizeUnits; diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 853fb34faa6..741f6af2b94 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -1782,7 +1782,7 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con QDomElement labelingElement = node.firstChildElement( QStringLiteral( "labeling" ) ); if ( !labelingElement.isNull() ) { - QgsAbstractVectorLayerLabeling *l = QgsAbstractVectorLayerLabeling::create( labelingElement ); + QgsAbstractVectorLayerLabeling *l = QgsAbstractVectorLayerLabeling::create( labelingElement, context ); setLabeling( l ? l : new QgsVectorLayerSimpleLabeling ); } @@ -2011,7 +2011,7 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err if ( mLabeling ) { - QDomElement labelingElement = mLabeling->save( doc ); + QDomElement labelingElement = mLabeling->save( doc, context ); node.appendChild( labelingElement ); } diff --git a/src/core/qgsvectorlayerlabeling.cpp b/src/core/qgsvectorlayerlabeling.cpp index a13ba1103b9..2dbd5fb1561 100644 --- a/src/core/qgsvectorlayerlabeling.cpp +++ b/src/core/qgsvectorlayerlabeling.cpp @@ -19,11 +19,11 @@ #include "qgsvectorlayer.h" -QgsAbstractVectorLayerLabeling *QgsAbstractVectorLayerLabeling::create( const QDomElement &element ) +QgsAbstractVectorLayerLabeling *QgsAbstractVectorLayerLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) { if ( element.attribute( QStringLiteral( "type" ) ) == QLatin1String( "rule-based" ) ) { - return QgsRuleBasedLabeling::create( element ); + return QgsRuleBasedLabeling::create( element, context ); } else { @@ -45,8 +45,9 @@ QString QgsVectorLayerSimpleLabeling::type() const return QStringLiteral( "simple" ); } -QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc ) const +QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const { + Q_UNUSED( context ); // all configuration is kept in layer custom properties (for compatibility) QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) ); elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "simple" ) ); diff --git a/src/core/qgsvectorlayerlabeling.h b/src/core/qgsvectorlayerlabeling.h index 702c0aa7a02..714edfdaf93 100644 --- a/src/core/qgsvectorlayerlabeling.h +++ b/src/core/qgsvectorlayerlabeling.h @@ -24,6 +24,7 @@ class QDomDocument; class QDomElement; class QgsPalLayerSettings; +class QgsReadWriteContext; class QgsVectorLayer; class QgsVectorLayerLabelProvider; @@ -47,7 +48,7 @@ class CORE_EXPORT QgsAbstractVectorLayerLabeling virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const = 0; //! Return labeling configuration as XML element - virtual QDomElement save( QDomDocument &doc ) const = 0; + virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const = 0; //! Get list of sub-providers within the layer's labeling. virtual QStringList subProviders() const { return QStringList( QString() ); } @@ -67,7 +68,7 @@ class CORE_EXPORT QgsAbstractVectorLayerLabeling // static stuff //! Try to create instance of an implementation based on the XML data - static QgsAbstractVectorLayerLabeling *create( const QDomElement &element ); + static QgsAbstractVectorLayerLabeling *create( const QDomElement &element, const QgsReadWriteContext &context ); }; /** \ingroup core @@ -85,7 +86,7 @@ class CORE_EXPORT QgsVectorLayerSimpleLabeling : public QgsAbstractVectorLayerLa virtual QString type() const override; virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override; - virtual QDomElement save( QDomDocument &doc ) const override; + virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override; virtual QgsPalLayerSettings settings( QgsVectorLayer *layer, const QString &providerId = QString() ) const override; bool requiresAdvancedEffects( QgsVectorLayer *layer ) const override; }; diff --git a/tests/src/core/testqgslabelingengine.cpp b/tests/src/core/testqgslabelingengine.cpp index 4e6f083e949..efacf3800a7 100644 --- a/tests/src/core/testqgslabelingengine.cpp +++ b/tests/src/core/testqgslabelingengine.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -254,15 +255,15 @@ void TestQgsLabelingEngine::testRuleBased() // test read/write rules QDomDocument doc, doc2, doc3; - QDomElement e = vl->labeling()->save( doc ); + QDomElement e = vl->labeling()->save( doc, QgsReadWriteContext() ); doc.appendChild( e ); // read saved rules doc2.setContent( doc.toString() ); QDomElement e2 = doc2.documentElement(); - QgsRuleBasedLabeling *rl2 = QgsRuleBasedLabeling::create( e2 ); + QgsRuleBasedLabeling *rl2 = QgsRuleBasedLabeling::create( e2, QgsReadWriteContext() ); QVERIFY( rl2 ); // check that another save will keep the data the same - QDomElement e3 = rl2->save( doc3 ); + QDomElement e3 = rl2->save( doc3, QgsReadWriteContext() ); doc3.appendChild( e3 ); QCOMPARE( doc.toString(), doc3.toString() );