Skip to content

Commit 9846b34

Browse files
committedMar 30, 2017
add type and default values identifiers
1 parent 15e4903 commit 9846b34

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed
 

‎python/core/qgsfeature.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class QgsFeature
293293
@note added in QGIS 3.0
294294
%End
295295

296-
void setFields( const QgsFields &fields, bool initAttributes = true );
296+
void setFields( const QgsFields &fields, bool initAttributes = true );
297297
%Docstring
298298
Assign a field map with the feature to allow attribute access by attribute name.
299299
@param fields The attribute fields which this feature holds
@@ -437,6 +437,7 @@ typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
437437

438438
typedef QMap<qint64, QgsGeometry> QgsGeometryMap;
439439

440+
440441
typedef QSet<qint64> QgsFeatureIds;
441442

442443
typedef QList<QgsFeature> QgsFeatureList;

‎scripts/sipify.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@
287287
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
288288

289289
$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
290+
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
291+
$line =~ s/=\s+[^=]*?\s+SIP_PYDEFAULTVALUE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
290292

291293
# fix astyle placing space after % character
292294
$line =~ s/\s*% (MappedType|TypeHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/;

‎src/core/qgis.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,13 @@ typedef unsigned long long qgssize;
437437
* discard line
438438
*/
439439
#define SIP_SKIP
440+
441+
/**
442+
* specify an alternative type for SIP methods
443+
*/
444+
#define SIP_PYTYPE(type)
445+
446+
/**
447+
* specify an alternative default value for SIP methods
448+
*/
449+
#define SIP_PYDEFAULTVALUE(value)

‎src/core/qgsfeature.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,7 @@ class CORE_EXPORT QgsFeature
352352
* @note added in QGIS 2.9
353353
* @see fields
354354
*/
355-
#ifndef SIP_RUN
356-
void setFields( const QgsFields &fields, bool initAttributes = false );
357-
#else
358-
void setFields( const QgsFields &fields, bool initAttributes = true );
359-
#endif
355+
void setFields( const QgsFields &fields, bool initAttributes = false SIP_PYDEFAULTVALUE( true ) );
360356

361357
/** Returns the field map associated with the feature.
362358
* @see setFields
@@ -518,6 +514,7 @@ typedef QMap<QgsFeatureId, QgsGeometry> QgsGeometryMap;
518514
typedef QMap<qint64, QgsGeometry> QgsGeometryMap;
519515
#endif
520516

517+
521518
#ifndef SIP_RUN
522519
typedef QSet<QgsFeatureId> QgsFeatureIds;
523520
#else

‎tests/scripts/sipifyheader.expected.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
typedef qint64 QgsFeatureId;
1414

15+
typedef QSet<qint64 > QgsFeatureIds;
16+
typedef QMap<qint64 , QMap<int, QVariant>> QgsChangedAttributesMap;
17+
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
18+
typedef QMap<qint64, QMap<int, QVariant>> QgsChangedAttributesMap;
19+
1520
typedef QVector<QVariant> QgsSuperClass;
1621

1722
%MappedType QgsSuperClass
@@ -81,6 +86,15 @@ Factory annotation
8186

8287
void setDiagramRenderer( QgsDiagramRenderer *r /Transfer/ );
8388

89+
void differentDefaultValue( bool defaultValue = false , QWidget *parent = 0, QString msg = "hello" );
90+
91+
void differentType( QList<qint64> &list );
92+
93+
void complexDefaultValueAndType( QList<QPair<qint64 , QMap<int, QString>>> list = QList<QPair<qint64, QMap<int, QString>>> );
94+
%Docstring
95+
complex default value and type (i.e. containing commas) should be given as a string with single quotes
96+
%End
97+
8498
inlineKeyWordShouldNotAppear();
8599

86100
QString labelForRange( double lower, double upper ) const /PyName=labelForLowerUpper/;

‎tests/scripts/sipifyheader.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ typedef qint64 QgsFeatureId;
4040
typedef WhatEver ShouldNotBeDisplayed;
4141
#endif
4242

43+
typedef QSet<QgsFeatureId SIP_PYTYPE( qint64 )> QgsFeatureIds;
44+
typedef QMap<QgsFeatureId SIP_PYTYPE( qint64 ), QgsAttributeMap SIP_PYTYPE( 'QMap<int, QVariant>' )> QgsChangedAttributesMap;
45+
typedef QMap<QgsFeatureId, QgsAttributeMap> SIP_PYTYPE( 'QMap<qint64, QMap<int, QVariant> >' ) QgsChangedAttributesMap;
46+
typedef QMap<QgsFeatureId, QPair<QMap<Something, Complex> >> SIP_PYTYPE( 'QMap<qint64, QMap<int, QVariant>>' ) QgsChangedAttributesMap;
47+
4348
/** \ingroup core
4449
* A super QGIS class
4550
*/
@@ -118,6 +123,13 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private QgsBaseCla
118123

119124
void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );
120125

126+
void differentDefaultValue( bool defaultValue = true SIP_PYDEFAULTVALUE( false ), QWidget *parent = nullptr, QString msg = QString() SIP_PYDEFAULTVALUE( "hello" ) );
127+
128+
void differentType( QList<QgsFeatureId> SIP_PYTYPE( QList<qint64> ) &list );
129+
130+
//! complex default value and type (i.e. containing commas) should be given as a string with single quotes
131+
void complexDefaultValueAndType( QList<QPair<QgsFeatureId SIP_PYTYPE( qint64 ), QMap<int, QString>>> list = QList<QPair<QgsFeatureId, QMap<int, QString>>>() SIP_PYDEFAULTVALUE( 'QList<QPair<qint64, QMap<int, QString>>>()' ) );
132+
121133
inline inlineKeyWordShouldNotAppear();
122134

123135
QString labelForRange( double lower, double upper ) const SIP_PYNAME( labelForLowerUpper );

0 commit comments

Comments
 (0)
Please sign in to comment.