diff --git a/python/core/qgsfeature.sip b/python/core/qgsfeature.sip index 39b14db2649..8350b418fc7 100644 --- a/python/core/qgsfeature.sip +++ b/python/core/qgsfeature.sip @@ -293,7 +293,7 @@ class QgsFeature @note added in QGIS 3.0 %End - void setFields( const QgsFields &fields, bool initAttributes = true ); + void setFields( const QgsFields &fields, bool initAttributes = true ); %Docstring Assign a field map with the feature to allow attribute access by attribute name. @param fields The attribute fields which this feature holds @@ -437,6 +437,7 @@ typedef QMap > QgsChangedAttributesMap; typedef QMap QgsGeometryMap; + typedef QSet QgsFeatureIds; typedef QList QgsFeatureList; diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 26e44ca98d3..b2681f64535 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -287,6 +287,8 @@ while(!eof $header){ $line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//; $line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//; + $line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g; + $line =~ s/=\s+[^=]*?\s+SIP_PYDEFAULTVALUE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g; # fix astyle placing space after % character $line =~ s/\s*% (MappedType|TypeHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/; diff --git a/src/core/qgis.h b/src/core/qgis.h index be3d9593da0..4a13a419f37 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -437,3 +437,13 @@ typedef unsigned long long qgssize; * discard line */ #define SIP_SKIP + +/** + * specify an alternative type for SIP methods + */ +#define SIP_PYTYPE(type) + +/** + * specify an alternative default value for SIP methods + */ +#define SIP_PYDEFAULTVALUE(value) diff --git a/src/core/qgsfeature.h b/src/core/qgsfeature.h index 205847ad420..5d828a6d704 100644 --- a/src/core/qgsfeature.h +++ b/src/core/qgsfeature.h @@ -352,11 +352,7 @@ class CORE_EXPORT QgsFeature * @note added in QGIS 2.9 * @see fields */ -#ifndef SIP_RUN - void setFields( const QgsFields &fields, bool initAttributes = false ); -#else - void setFields( const QgsFields &fields, bool initAttributes = true ); -#endif + void setFields( const QgsFields &fields, bool initAttributes = false SIP_PYDEFAULTVALUE( true ) ); /** Returns the field map associated with the feature. * @see setFields @@ -518,6 +514,7 @@ typedef QMap QgsGeometryMap; typedef QMap QgsGeometryMap; #endif + #ifndef SIP_RUN typedef QSet QgsFeatureIds; #else diff --git a/tests/scripts/sipifyheader.expected.sip b/tests/scripts/sipifyheader.expected.sip index 002a77de4d4..ae392b15f0d 100644 --- a/tests/scripts/sipifyheader.expected.sip +++ b/tests/scripts/sipifyheader.expected.sip @@ -12,6 +12,11 @@ typedef qint64 QgsFeatureId; +typedef QSet QgsFeatureIds; +typedef QMap> QgsChangedAttributesMap; +typedef QMap > QgsChangedAttributesMap; +typedef QMap> QgsChangedAttributesMap; + typedef QVector QgsSuperClass; %MappedType QgsSuperClass @@ -81,6 +86,15 @@ Factory annotation void setDiagramRenderer( QgsDiagramRenderer *r /Transfer/ ); + void differentDefaultValue( bool defaultValue = false , QWidget *parent = 0, QString msg = "hello" ); + + void differentType( QList &list ); + + void complexDefaultValueAndType( QList>> list = QList>> ); +%Docstring +complex default value and type (i.e. containing commas) should be given as a string with single quotes +%End + inlineKeyWordShouldNotAppear(); QString labelForRange( double lower, double upper ) const /PyName=labelForLowerUpper/; diff --git a/tests/scripts/sipifyheader.h b/tests/scripts/sipifyheader.h index d8bf232c849..d6d3e7ea08b 100644 --- a/tests/scripts/sipifyheader.h +++ b/tests/scripts/sipifyheader.h @@ -40,6 +40,11 @@ typedef qint64 QgsFeatureId; typedef WhatEver ShouldNotBeDisplayed; #endif +typedef QSet QgsFeatureIds; +typedef QMap' )> QgsChangedAttributesMap; +typedef QMap SIP_PYTYPE( 'QMap >' ) QgsChangedAttributesMap; +typedef QMap >> SIP_PYTYPE( 'QMap>' ) QgsChangedAttributesMap; + /** \ingroup core * A super QGIS class */ @@ -118,6 +123,13 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass, private QgsBaseCla void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER ); + void differentDefaultValue( bool defaultValue = true SIP_PYDEFAULTVALUE( false ), QWidget *parent = nullptr, QString msg = QString() SIP_PYDEFAULTVALUE( "hello" ) ); + + void differentType( QList SIP_PYTYPE( QList ) &list ); + + //! complex default value and type (i.e. containing commas) should be given as a string with single quotes + void complexDefaultValueAndType( QList>> list = QList>>() SIP_PYDEFAULTVALUE( 'QList>>()' ) ); + inline inlineKeyWordShouldNotAppear(); QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );