Skip to content
Permalink
Browse files

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
  • Loading branch information
wonder-sk committed May 13, 2017
1 parent 23a7bd0 commit 5bdae75156075f313c33ce13d00a5e633ad81339
@@ -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<QString> 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}
----------
@@ -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();

@@ -304,16 +304,16 @@ 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

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()
@@ -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
@@ -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 );

@@ -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 );
@@ -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
@@ -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 );

@@ -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;

0 comments on commit 5bdae75

Please sign in to comment.