Skip to content

Commit

Permalink
Keep API compatibility and update SIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Oct 1, 2016
1 parent 4aef2db commit da67550
Show file tree
Hide file tree
Showing 39 changed files with 218 additions and 65 deletions.
1 change: 1 addition & 0 deletions python/core/qgsogcutils.sip
Expand Up @@ -62,6 +62,7 @@ class QgsOgcUtils
/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
* @note added in 2.14.8
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );

Expand Down
18 changes: 17 additions & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -733,7 +733,23 @@ class QgsVectorLayer : QgsMapLayer
*/
bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;

bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, QgsStringMap& props ) const;
/**
* Writes the symbology of the layer into the document provided in SLD 1.1 format
* @param node the node that will have the style element added to it.
* @param doc the document that will have the QDomNode added.
* @param errorMessage reference to string that will be updated with any error messages
* @param props a open ended set of properties that can drive/inform the SLD encoding
* @return true in case of success
*/
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, const QgsStringMap& props = QgsStringMap() ) const;

/**
* Read the symbology of the layer according to the information contained in
* the UserStyle element of a SLD style document
* @param node the node that have the style element in it.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success
*/
bool readSld( const QDomNode& node, QString& errorMessage );

/**
Expand Down
10 changes: 9 additions & 1 deletion python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip
Expand Up @@ -28,7 +28,12 @@ class QgsRendererCategoryV2
// debugging
QString dump() const;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
/** Creates a DOM element representing the category in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
*/
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

protected:

Expand Down Expand Up @@ -65,7 +70,10 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsCategorizedSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
Expand Down
1 change: 1 addition & 0 deletions python/core/symbology-ng/qgsellipsesymbollayerv2.sip
Expand Up @@ -18,6 +18,7 @@ class QgsEllipseSymbolLayerV2 : QgsMarkerSymbolLayerV2
virtual QgsEllipseSymbolLayerV2* clone() const /Factory/;
QgsStringMap properties() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
void writeSldMarker( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

Expand Down
5 changes: 5 additions & 0 deletions python/core/symbology-ng/qgsfillsymbollayerv2.sip
Expand Up @@ -32,6 +32,7 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2

virtual QgsSimpleFillSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -661,6 +662,7 @@ class QgsSVGFillSymbolLayer: QgsImageFillSymbolLayer

virtual QgsSVGFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

//getters and setters
Expand Down Expand Up @@ -720,6 +722,7 @@ class QgsLinePatternFillSymbolLayer: QgsImageFillSymbolLayer

virtual QgsLinePatternFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

double estimateMaxBleed() const;
Expand Down Expand Up @@ -791,6 +794,7 @@ class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer

virtual QgsPointPatternFillSymbolLayer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

double estimateMaxBleed() const;
Expand Down Expand Up @@ -879,6 +883,7 @@ class QgsCentroidFillSymbolLayerV2 : QgsFillSymbolLayerV2

virtual QgsCentroidFillSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Expand Up @@ -108,7 +108,10 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsGraduatedSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities();
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgslinesymbollayerv2.sip
Expand Up @@ -31,6 +31,7 @@ class QgsSimpleLineSymbolLayerV2 : QgsLineSymbolLayerV2

virtual QgsSimpleLineSymbolLayerV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -142,6 +143,7 @@ class QgsMarkerLineSymbolLayerV2 : QgsLineSymbolLayerV2

virtual QgsMarkerLineSymbolLayerV2* clone() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

void setColor( const QColor& color );
Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgspointdisplacementrenderer.sip
Expand Up @@ -18,7 +18,10 @@ class QgsPointDisplacementRenderer : QgsFeatureRendererV2

virtual QgsPointDisplacementRenderer* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

/** Reimplemented from QgsFeatureRendererV2*/
bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
Expand Down
5 changes: 5 additions & 0 deletions python/core/symbology-ng/qgsrendererv2.sip
Expand Up @@ -205,6 +205,9 @@ class QgsFeatureRendererV2
//! create the SLD UserStyle element following the SLD v1.1 specs with the given name
//! @note added in 2.8
virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName ) const;
//! create the SLD UserStyle element following the SLD v1.1 specs with the given name
//! @note added in 2.14.8
virtual QDomElement writeSld( QDomDocument& doc, const QString& styleName, const QgsStringMap& props ) const;

/** Create a new renderer according to the information contained in
* the UserStyle element of a SLD style document
Expand All @@ -220,6 +223,8 @@ class QgsFeatureRendererV2

//! used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

//! return a list of symbology items for the legend
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
Expand Down
12 changes: 10 additions & 2 deletions python/core/symbology-ng/qgsrulebasedrendererv2.sip
Expand Up @@ -82,7 +82,7 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
*/
QSet<QString> usedAttributes();

//! @note available in python bindings as symbol2
//! @note available in python bindings as symbol2
QgsSymbolV2List symbols( const QgsRenderContext& context = QgsRenderContext() ) /PyName=symbols2/;

//! @note not available in python bindings
Expand Down Expand Up @@ -198,7 +198,12 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
//! clone this rule, return new instance
QgsRuleBasedRendererV2::Rule* clone() const /Factory/;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props );
/** Creates a DOM element representing the rule in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
*/
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props = QgsStringMap() );
static QgsRuleBasedRendererV2::Rule* createFromSld( QDomElement& element, QGis::GeometryType geomType ) /Factory/;

QDomElement save( QDomDocument& doc, QgsSymbolV2Map& symbolMap );
Expand Down Expand Up @@ -359,7 +364,10 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

virtual QgsRuleBasedRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType ) /Factory/;

Expand Down
3 changes: 3 additions & 0 deletions python/core/symbology-ng/qgssinglesymbolrendererv2.sip
Expand Up @@ -37,7 +37,10 @@ class QgsSingleSymbolRendererV2 : QgsFeatureRendererV2

virtual QgsSingleSymbolRendererV2* clone() const /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
static QgsFeatureRendererV2* createFromSld( QDomElement& element, QGis::GeometryType geomType );

//! returns bitwise OR-ed capabilities of the renderer
Expand Down
2 changes: 2 additions & 0 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Expand Up @@ -107,6 +107,7 @@ class QgsSymbolLayerV2
*/
virtual QgsSymbolLayerV2* clone() const = 0 /Factory/;

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

virtual QString ogrFeatureStyle( double mmScaleFactor, double mapUnitScaleFactor ) const;
Expand Down Expand Up @@ -377,6 +378,7 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2
void setOffset( QPointF offset );
QPointF offset();

//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;
Expand Down
10 changes: 5 additions & 5 deletions python/core/symbology-ng/qgssymbollayerv2utils.sip
Expand Up @@ -415,31 +415,31 @@ class QgsSymbolLayerV2Utils

/** Rescales the given size based on the uomScale found in the props, if any is found, otherwise
* returns the value un-modified
* @note added in 3.0
* @note added in 2.14.8
*/
static double rescaleUom( double size, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props );

/** Rescales the given point based on the uomScale found in the props, if any is found, otherwise
* returns a copy of the original point
* @note added in 3.0
* @note added in 2.14.8
*/
static QPointF rescaleUom( const QPointF& point, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props ) /PyName=rescalePointUom/;

/** Rescales the given array based on the uomScale found in the props, if any is found, otherwise
* returns a copy of the original point
* @note added in 3.0
* @note added in 2.14.8
*/
static QVector<qreal> rescaleUom( const QVector<qreal>& array, QgsSymbolV2::OutputUnit unit, const QgsStringMap& props ) /PyName=rescaleArrayUom/;

/**
* Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into the SE Rule element
* @note added in 3.0
* @note added in 2.14.8
*/
static void applyScaleDependency( QDomDocument& doc, QDomElement& ruleElem, QgsStringMap& props );

/**
* Merges the local scale limits, if any, with the ones already in the map, if any
* @note added in 3.0
* @note added in 2.14.8
*/
static void mergeScaleDependencies( int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap& props );

Expand Down
3 changes: 2 additions & 1 deletion python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -152,7 +152,8 @@ class QgsSymbolV2

virtual QgsSymbolV2* clone() const = 0 /Factory/;

void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const;

OutputUnit outputUnit() const;
void setOutputUnit( OutputUnit u );
Expand Down
1 change: 1 addition & 0 deletions python/core/symbology-ng/qgsvectorfieldsymbollayer.sip
Expand Up @@ -44,6 +44,7 @@ class QgsVectorFieldSymbolLayer : QgsMarkerSymbolLayerV2
virtual QgsVectorFieldSymbolLayer* clone() const /Factory/;
QgsStringMap properties() const;

//! Writes the SLD element following the SLD v1.1 specs
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsogcutils.h
Expand Up @@ -162,6 +162,7 @@ class CORE_EXPORT QgsOgcUtils
/** Creates an OGC expression XML element.
* @return valid OGC expression QDomElement on success,
* otherwise null QDomElement
* @note added in 2.14.8
*/
static QDomElement expressionToOgcExpression( const QgsExpression& exp, QDomDocument& doc, QString* errorMessage = nullptr );

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -2112,7 +2112,7 @@ bool QgsVectorLayer::writeSld( QDomNode& node, QDomDocument& doc, QString& error
return writeSld( node, doc, errorMessage, QgsStringMap() );
}

bool QgsVectorLayer::writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, QgsStringMap props ) const
bool QgsVectorLayer::writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, const QgsStringMap& props ) const
{
Q_UNUSED( errorMessage );

Expand Down
17 changes: 16 additions & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -840,6 +840,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
bool writeSymbology( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const override;


/**
* Writes the symbology of the layer into the document provided in SLD 1.1 format
* @param node the node that will have the style element added to it.
* @param doc the document that will have the QDomNode added.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success
*/
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;

/**
Expand All @@ -850,8 +858,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @param props a open ended set of properties that can drive/inform the SLD encoding
* @return true in case of success
*/
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, QgsStringMap props = QgsStringMap() ) const;
bool writeSld( QDomNode& node, QDomDocument& doc, QString& errorMessage, const QgsStringMap& props ) const;

/**
* Read the symbology of the layer according to the information contained in
* the UserStyle element of a SLD style document
* @param node the node that have the style element in it.
* @param errorMessage reference to string that will be updated with any error messages
* @return true in case of success
*/
bool readSld( const QDomNode& node, QString& errorMessage ) override;

/**
Expand Down
18 changes: 12 additions & 6 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -114,7 +114,7 @@ QString QgsRendererCategoryV2::dump() const
return QString( "%1::%2::%3:%4\n" ).arg( mValue.toString(), mLabel, mSymbol->dump() ).arg( mRender );
}

void QgsRendererCategoryV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
void QgsRendererCategoryV2::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const
{
if ( !mSymbol.data() || props.value( "attribute", "" ).isEmpty() )
return;
Expand Down Expand Up @@ -531,18 +531,24 @@ QgsCategorizedSymbolRendererV2* QgsCategorizedSymbolRendererV2::clone() const
return r;
}

void QgsCategorizedSymbolRendererV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
void QgsCategorizedSymbolRendererV2::toSld( QDomDocument &doc, QDomElement &element ) const
{
props[ "attribute" ] = mAttrName;
toSld( doc, element, QgsStringMap() );
}

void QgsCategorizedSymbolRendererV2::toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap& props ) const
{
QgsStringMap locProps( props );
locProps[ "attribute" ] = mAttrName;
if ( mRotation.data() )
props[ "angle" ] = mRotation->expression();
locProps[ "angle" ] = mRotation->expression();
if ( mSizeScale.data() )
props[ "scale" ] = mSizeScale->expression();
locProps[ "scale" ] = mSizeScale->expression();

// create a Rule for each range
for ( QgsCategoryList::const_iterator it = mCategories.constBegin(); it != mCategories.constEnd(); ++it )
{
QgsStringMap catProps( props );
QgsStringMap catProps( locProps );
it->toSld( doc, element, catProps );
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -56,7 +56,12 @@ class CORE_EXPORT QgsRendererCategoryV2
// debugging
QString dump() const;

void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props ) const;
/** Creates a DOM element representing the category in SLD format.
* @param doc DOM document
* @param element destination DOM element
* @param props graduated renderer properties
*/
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;

protected:
QVariant mValue;
Expand Down Expand Up @@ -94,7 +99,10 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

virtual QgsCategorizedSymbolRendererV2* clone() const override;

virtual void toSld( QDomDocument& doc, QDomElement &element, QgsStringMap props = QgsStringMap() ) const override;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
//! Writes the SLD element following the SLD v1.1 specs
virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const override;

//! returns bitwise OR-ed capabilities of the renderer
virtual int capabilities() override { return SymbolLevels | RotationField | Filter; }
Expand Down

0 comments on commit da67550

Please sign in to comment.