Skip to content

Commit 5bdae75

Browse files
committed
API break update + read/write context in labeling and text renderer
This enables correct loading/saving of relative paths of SVG files for background of labels
1 parent 23a7bd0 commit 5bdae75

16 files changed

+109
-65
lines changed

doc/api_break.dox

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,16 @@ all these item added events.
762762
- addComposerMap no longer takes a setDefaultPreviewStyle argument.
763763
- the mapsToRestore parameter has been removed from addItemsFromXml
764764

765+
QgsConditionalLayerStyle {#qgis_api_break_3_0_QgsConditionalLayerStyle}
766+
------------------------
767+
768+
- readXml() and writeXml() require a new argument: a reference to QgsReadWriteContext
769+
770+
QgsConditionalStyle {#qgis_api_break_3_0_QgsConditionalStyle}
771+
-------------------
772+
773+
- readXml() and writeXml() require a new argument: a reference to QgsReadWriteContext
774+
765775
QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}
766776
----------------------------
767777

@@ -921,6 +931,8 @@ QgsDiagramRenderer {#qgis_api_break_3_0_QgsDiagramRenderer}
921931
- referencedFields() no longer takes a QgsFields argument.
922932
- renderDiagram() now takes an optional data defined overrides collection argument.
923933
- readXml(), _readXml(), writeXml(), _writeXml() do not take QgsVectorLayer as an argument anymore.
934+
- readXml(), _readXml(), writeXml(), _writeXml() require a new argument: a reference to QgsReadWriteContext
935+
924936

925937

926938
QgsDiagramLayerSettings {#qgis_api_break_3_0_QgsDiagramLayerSettings}
@@ -1098,6 +1110,8 @@ QgsFeatureRendererV2 {#qgis_api_break_3_0_QgsFeatureRendererV2}
10981110
- originalSymbolsForFeature( QgsFeature& feat ) has been removed. The originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) method should be used instead (previously available as originalSymbolsForFeature2 in PyQGIS bindings).
10991111
- copyPaintEffect() was removed. copyRendererData() should be used instead.
11001112
- usedAttributes() now requires a QgsRenderContext argument.
1113+
- save() expects QgsReadWriteContext reference as the last argument
1114+
- static create() method in subclasses expects QgsReadWriteContext reference as the last argument
11011115

11021116

11031117
QgsFeatureRequest {#qgis_api_break_3_0_QgsFeatureRequest}
@@ -1417,6 +1431,9 @@ screenUpdateRequested() were removed. These members have had no effect for a num
14171431
- asLayerDefinition(), fromLayerDefinition(), fromLayerDefinitionFile() were moved to QgsLayerDefinition class and renamed to exportLayerDefinitionLayers() resp. loadLayerDefinitionLayers()
14181432
- loadNamedStyleFromDb() was renamed to loadNamedStyleFromDatabase()
14191433
- readLayerXml() and writeLayerXml() expect QgsReadWriteContext reference as the last argument
1434+
- readSymbology() and writeSymbology() expect QgsReadWriteContext reference as the last argument
1435+
- readStyle() and writeStyle() expect QgsReadWriteContext reference as the last argument
1436+
- readXml() and writeXml() expect QgsReadWriteContext reference as the last argument
14201437
- the invalidTransformInput() slot was removed - calling this slot had no effect
14211438
- metadata() was renamed to htmlMetadata()
14221439

@@ -1627,6 +1644,7 @@ dataDefinedValue(), dataDefinedEvaluate(), dataDefinedIsActive(),
16271644
dataDefinedUseExpression(), dataDefinedProperties() and dataDefinedNames()
16281645
members were removed. Use the QgsProperty framework through dataDefinedProperties()
16291646
and setDataDefinedProperties() instead.
1647+
- readXml() and writeXml() now expect a reference to QgsReadWriteContext.
16301648

16311649

16321650
QgsPanelWidgetStack {#qgis_api_break_3_0_QgsPanelWidgetStack}
@@ -1944,11 +1962,26 @@ QgsSvgCache {#qgis_api_break_3_0_QgsSvgCache}
19441962
- This class is no longer a singleton and instance() has been removed. Instead use QgsApplication::svgCache() to access an application-wide cache.
19451963
- containsParamsV2() was removed. Use containsParamsV3() instead.
19461964
- The rasterScaleFactor parameter was removed from all methods
1965+
- svgAsImage(), svgAsPicture(), svgViewboxSize(), svgContent(), insertSvg(), cacheEntry() only accept absolute path to SVG file (relative paths will not be resolved).
19471966

19481967
QgsSvgCacheEntry {#qgis_api_break_3_0_QgsSvgCacheEntry}
19491968
----------------
19501969

19511970
- The rasterScaleFactor member was removed.
1971+
- The lookupKey member was removed.
1972+
- The "file" member has been renamed to "path".
1973+
- Constructor does not take lookup key as an optional last argument
1974+
1975+
1976+
QgsSVGFillSymbolLayer {#qgis_api_break_3_0_QgsSVGFillSymbolLayer}
1977+
---------------------
1978+
1979+
- The first argument of the constructor (svgFilePath) does not have default value anymore.
1980+
1981+
QgsSvgMarkerSymbolLayer {#qgis_api_break_3_0_QgsSvgMarkerSymbolLayer}
1982+
-----------------------
1983+
1984+
- The first argument of the constructor (path) does not have a default value anymore.
19521985

19531986
QgsStyle (renamed from QgsStyleV2) {#qgis_api_break_3_0_QgsStyle}
19541987
----------------------------------
@@ -2025,6 +2058,8 @@ QgsSymbolLayerUtils (renamed from QgsSymbolLayerUtilsV2) {#qgis_api_break
20252058
- pixelSizeScaleFactor() was removed. Use QgsRenderContext::convertToPainterUnits() instead.
20262059
- mapUnitScaleFactor() was removed. Use QgsRenderContext::convertToMapUnits() instead.
20272060
- estimateMaxSymbolBleed() now requires a QgsRenderContext argument (since the bleed depends on render context for non-pixel units)
2061+
- loadSymbol(), saveSymbol(), loadSymbols(), saveSymbols(), loadSymbolLayer() now require a reference to QgsReadWriteContext
2062+
- symbolNameToPath() and symbolPathToName() have been renamed to svgSymbolNameToPath() and svgSymbolPathToName() and they require reference to QgsPathResolver
20282063

20292064

20302065
QgsSymbolSelectorWidget {#qgis_api_break_3_0_QgsSymbolSelectorWidget}
@@ -2254,6 +2289,11 @@ optional property map passing down layer level properties to the SLD encoders. I
22542289
- setScaleMethodToSymbol was removed. This is now handled using data defined scaling at a symbol layer level
22552290
- usedAttributes is now a const method and returns QSet<QString> instead of QStringList
22562291

2292+
QgsRendererAbstractMetadata {#qgis_api_break_3_0_QgsRendererAbstractMetadata}
2293+
---------------------------
2294+
2295+
- createRenderer() now expects a reference to QgsReadWriteContext as the second argument
2296+
22572297

22582298
Processing {#qgis_api_break_3_0_Processing}
22592299
----------

python/core/qgspallabeling.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,12 @@ class QgsPalLayerSettings
426426
/** Read settings from a DOM element
427427
* @note added in 2.12
428428
*/
429-
void readXml( QDomElement &elem );
429+
void readXml( QDomElement& elem, const QgsReadWriteContext &context );
430430

431431
/** Write settings into a DOM element
432432
* @note added in 2.12
433433
*/
434-
QDomElement writeXml( QDomDocument &doc );
434+
QDomElement writeXml( QDomDocument& doc, const QgsReadWriteContext &context );
435435

436436
QgsPropertyCollection &dataDefinedProperties();
437437

python/core/qgstextrenderer.sip

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,16 @@ class QgsTextBackgroundSettings
304304

305305
QString svgFile() const;
306306
%Docstring
307-
Returns the path to the background SVG file, if set.
307+
Returns the absolute path to the background SVG file, if set.
308308
.. seealso:: setSvgFile()
309309
:rtype: str
310310
%End
311311

312312
void setSvgFile( const QString &file );
313313
%Docstring
314314
Sets the path to the background SVG file. This is only used if type() is set to
315-
QgsTextBackgroundSettings.ShapeSVG.
316-
\param file SVG file path
315+
QgsTextBackgroundSettings.ShapeSVG. The path must be absolute.
316+
\param file Absolute SVG file path
317317
.. seealso:: svgFile()
318318
%End
319319

@@ -688,13 +688,13 @@ class QgsTextBackgroundSettings
688688
.. seealso:: readFromLayer()
689689
%End
690690

691-
void readXml( const QDomElement &elem );
691+
void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
692692
%Docstring
693693
Read settings from a DOM element.
694694
.. seealso:: writeXml()
695695
%End
696696

697-
QDomElement writeXml( QDomDocument &doc ) const;
697+
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
698698
%Docstring
699699
Write settings into a DOM element.
700700
.. seealso:: readXml()
@@ -1251,13 +1251,13 @@ class QgsTextFormat
12511251
.. seealso:: readFromLayer()
12521252
%End
12531253

1254-
void readXml( const QDomElement &elem );
1254+
void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
12551255
%Docstring
12561256
Read settings from a DOM element.
12571257
.. seealso:: writeXml()
12581258
%End
12591259

1260-
QDomElement writeXml( QDomDocument &doc ) const;
1260+
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
12611261
%Docstring
12621262
Write settings into a DOM element.
12631263
.. seealso:: readXml()

src/app/qgslabelingwidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "qgslabelengineconfigdialog.h"
2222
#include "qgslabelinggui.h"
23+
#include "qgsreadwritecontext.h"
2324
#include "qgsrulebasedlabelingwidget.h"
2425
#include "qgsvectorlayer.h"
2526
#include "qgsvectorlayerlabeling.h"
@@ -75,8 +76,8 @@ void QgsLabelingWidget::setLayer( QgsMapLayer *mapLayer )
7576
if ( mLayer->labeling() )
7677
{
7778
QDomDocument doc;
78-
QDomElement oldSettings = mLayer->labeling()->save( doc );
79-
mOldSettings.reset( QgsAbstractVectorLayerLabeling::create( oldSettings ) );
79+
QDomElement oldSettings = mLayer->labeling()->save( doc, QgsReadWriteContext() );
80+
mOldSettings.reset( QgsAbstractVectorLayerLabeling::create( oldSettings, QgsReadWriteContext() ) );
8081
mOldPalSettings.readFromLayer( mLayer );
8182
}
8283
else

src/app/qgsrulebasedlabelingwidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgslabelinggui.h"
2121
#include "qgsmapcanvas.h"
2222
#include "qgsproject.h"
23+
#include "qgsreadwritecontext.h"
2324
#include "qgsrulebasedlabeling.h"
2425
#include "qgsvectorlayer.h"
2526
#include "qgsvectorlayerlabeling.h"
@@ -479,7 +480,7 @@ QMimeData *QgsRuleBasedLabelingModel::mimeData( const QModelIndexList &indexes )
479480

480481
QDomElement rootElem = doc.createElement( QStringLiteral( "rule_mime" ) );
481482
rootElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "labeling" ) ); // for determining whether rules are from renderer or labeling
482-
QDomElement rulesElem = rule->save( doc );
483+
QDomElement rulesElem = rule->save( doc, QgsReadWriteContext() );
483484
rootElem.appendChild( rulesElem );
484485
doc.appendChild( rootElem );
485486

@@ -529,7 +530,7 @@ bool QgsRuleBasedLabelingModel::dropMimeData( const QMimeData *data, Qt::DropAct
529530
QDomElement ruleElem = rootElem.firstChildElement( QStringLiteral( "rule" ) );
530531
if ( rootElem.attribute( QStringLiteral( "type" ) ) == QLatin1String( "renderer" ) )
531532
_renderer2labelingRules( ruleElem ); // do some modifications so that we load the rules more nicely
532-
QgsRuleBasedLabeling::Rule *rule = QgsRuleBasedLabeling::Rule::create( ruleElem );
533+
QgsRuleBasedLabeling::Rule *rule = QgsRuleBasedLabeling::Rule::create( ruleElem, QgsReadWriteContext() );
533534

534535
insertRule( parent, row + rows, rule );
535536

src/core/qgspallabeling.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer *layer )
768768
layer->emitStyleChanged();
769769
}
770770

771-
void QgsPalLayerSettings::readXml( QDomElement &elem )
771+
void QgsPalLayerSettings::readXml( QDomElement &elem, const QgsReadWriteContext &context )
772772
{
773773
enabled = true;
774774
drawLabels = true;
@@ -778,7 +778,7 @@ void QgsPalLayerSettings::readXml( QDomElement &elem )
778778
fieldName = textStyleElem.attribute( QStringLiteral( "fieldName" ) );
779779
isExpression = textStyleElem.attribute( QStringLiteral( "isExpression" ) ).toInt();
780780

781-
mFormat.readXml( elem );
781+
mFormat.readXml( elem, context );
782782
previewBkgrdColor = QColor( textStyleElem.attribute( QStringLiteral( "previewBkgrdColor" ), QStringLiteral( "#ffffff" ) ) );
783783
substitutions.readXml( textStyleElem.firstChildElement( QStringLiteral( "substitutions" ) ) );
784784
useSubstitutions = textStyleElem.attribute( QStringLiteral( "useSubstitutions" ) ).toInt();
@@ -889,11 +889,11 @@ void QgsPalLayerSettings::readXml( QDomElement &elem )
889889

890890

891891

892-
QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc )
892+
QDomElement QgsPalLayerSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context )
893893
{
894894
// we assume (enabled == true && drawLabels == true) so those are not saved
895895

896-
QDomElement textStyleElem = mFormat.writeXml( doc );
896+
QDomElement textStyleElem = mFormat.writeXml( doc, context );
897897

898898
// text style
899899
textStyleElem.setAttribute( QStringLiteral( "fieldName" ), fieldName );

src/core/qgspallabeling.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,12 +531,12 @@ class CORE_EXPORT QgsPalLayerSettings
531531
/** Read settings from a DOM element
532532
* \since QGIS 2.12
533533
*/
534-
void readXml( QDomElement &elem );
534+
void readXml( QDomElement &elem, const QgsReadWriteContext &context );
535535

536536
/** Write settings into a DOM element
537537
* \since QGIS 2.12
538538
*/
539-
QDomElement writeXml( QDomDocument &doc );
539+
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context );
540540

541541
/** Returns a reference to the label's property collection, used for data defined overrides.
542542
* \since QGIS 3.0

src/core/qgsrulebasedlabeling.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::clone() const
193193
return newrule;
194194
}
195195

196-
QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElement &ruleElem )
196+
QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElement &ruleElem, const QgsReadWriteContext &context )
197197
{
198198
QgsPalLayerSettings *settings = nullptr;
199199
QDomElement settingsElem = ruleElem.firstChildElement( QStringLiteral( "settings" ) );
200200
if ( !settingsElem.isNull() )
201201
{
202202
settings = new QgsPalLayerSettings;
203-
settings->readXml( settingsElem );
203+
settings->readXml( settingsElem, context );
204204
}
205205

206206
QString filterExp = ruleElem.attribute( QStringLiteral( "filter" ) );
@@ -218,7 +218,7 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElemen
218218
QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral( "rule" ) );
219219
while ( !childRuleElem.isNull() )
220220
{
221-
Rule *childRule = create( childRuleElem );
221+
Rule *childRule = create( childRuleElem, context );
222222
if ( childRule )
223223
{
224224
rule->appendChild( childRule );
@@ -233,13 +233,13 @@ QgsRuleBasedLabeling::Rule *QgsRuleBasedLabeling::Rule::create( const QDomElemen
233233
return rule;
234234
}
235235

236-
QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc ) const
236+
QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
237237
{
238238
QDomElement ruleElem = doc.createElement( QStringLiteral( "rule" ) );
239239

240240
if ( mSettings )
241241
{
242-
ruleElem.appendChild( mSettings->writeXml( doc ) );
242+
ruleElem.appendChild( mSettings->writeXml( doc, context ) );
243243
}
244244
if ( !mFilterExp.isEmpty() )
245245
ruleElem.setAttribute( QStringLiteral( "filter" ), mFilterExp );
@@ -256,7 +256,7 @@ QDomElement QgsRuleBasedLabeling::Rule::save( QDomDocument &doc ) const
256256
for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it )
257257
{
258258
Rule *rule = *it;
259-
ruleElem.appendChild( rule->save( doc ) );
259+
ruleElem.appendChild( rule->save( doc, context ) );
260260
}
261261
return ruleElem;
262262
}
@@ -401,11 +401,11 @@ QgsRuleBasedLabeling::~QgsRuleBasedLabeling()
401401
}
402402

403403

404-
QgsRuleBasedLabeling *QgsRuleBasedLabeling::create( const QDomElement &element )
404+
QgsRuleBasedLabeling *QgsRuleBasedLabeling::create( const QDomElement &element, const QgsReadWriteContext &context )
405405
{
406406
QDomElement rulesElem = element.firstChildElement( QStringLiteral( "rules" ) );
407407

408-
Rule *root = Rule::create( rulesElem );
408+
Rule *root = Rule::create( rulesElem, context );
409409
if ( !root )
410410
return nullptr;
411411

@@ -418,12 +418,12 @@ QString QgsRuleBasedLabeling::type() const
418418
return QStringLiteral( "rule-based" );
419419
}
420420

421-
QDomElement QgsRuleBasedLabeling::save( QDomDocument &doc ) const
421+
QDomElement QgsRuleBasedLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
422422
{
423423
QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) );
424424
elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "rule-based" ) );
425425

426-
QDomElement rulesElem = mRootRule->save( doc );
426+
QDomElement rulesElem = mRootRule->save( doc, context );
427427
rulesElem.setTagName( QStringLiteral( "rules" ) ); // instead of just "rule"
428428
elem.appendChild( rulesElem );
429429

src/core/qgsrulebasedlabeling.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
241241
* \param ruleElem The XML rule element
242242
* \returns A new rule
243243
*/
244-
static Rule *create( const QDomElement &ruleElem );
244+
static Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context );
245245

246246
//! store labeling info to XML element
247-
QDomElement save( QDomDocument &doc ) const;
247+
QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
248248

249249
// evaluation
250250

@@ -323,12 +323,12 @@ class CORE_EXPORT QgsRuleBasedLabeling : public QgsAbstractVectorLayerLabeling
323323
const Rule *rootRule() const { return mRootRule; }
324324

325325
//! Create the instance from a DOM element with saved configuration
326-
static QgsRuleBasedLabeling *create( const QDomElement &element );
326+
static QgsRuleBasedLabeling *create( const QDomElement &element, const QgsReadWriteContext &context );
327327

328328
// implementation of parent interface
329329

330330
virtual QString type() const override;
331-
virtual QDomElement save( QDomDocument &doc ) const override;
331+
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const override;
332332
virtual QgsVectorLayerLabelProvider *provider( QgsVectorLayer *layer ) const override;
333333
virtual QStringList subProviders() const override;
334334
virtual QgsPalLayerSettings settings( QgsVectorLayer *layer, const QString &providerId = QString() ) const override;

0 commit comments

Comments
 (0)