Skip to content

Commit

Permalink
add type and default values identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Mar 30, 2017
1 parent 15e4903 commit 9846b34
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsfeature.sip
Expand Up @@ -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
Expand Down Expand Up @@ -437,6 +437,7 @@ typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;

typedef QMap<qint64, QgsGeometry> QgsGeometryMap;


typedef QSet<qint64> QgsFeatureIds;

typedef QList<QgsFeature> QgsFeatureList;
Expand Down
2 changes: 2 additions & 0 deletions scripts/sipify.pl
Expand Up @@ -287,6 +287,8 @@
$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/;
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgis.h
Expand Up @@ -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)
7 changes: 2 additions & 5 deletions src/core/qgsfeature.h
Expand Up @@ -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
Expand Down Expand Up @@ -518,6 +514,7 @@ typedef QMap<QgsFeatureId, QgsGeometry> QgsGeometryMap;
typedef QMap<qint64, QgsGeometry> QgsGeometryMap;
#endif


#ifndef SIP_RUN
typedef QSet<QgsFeatureId> QgsFeatureIds;
#else
Expand Down
14 changes: 14 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -12,6 +12,11 @@

typedef qint64 QgsFeatureId;

typedef QSet<qint64 > QgsFeatureIds;
typedef QMap<qint64 , QMap<int, QVariant>> QgsChangedAttributesMap;
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
typedef QMap<qint64, QMap<int, QVariant>> QgsChangedAttributesMap;

typedef QVector<QVariant> QgsSuperClass;

%MappedType QgsSuperClass
Expand Down Expand Up @@ -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<qint64> &list );

void complexDefaultValueAndType( QList<QPair<qint64 , QMap<int, QString>>> list = QList<QPair<qint64, QMap<int, QString>>> );
%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/;
Expand Down
12 changes: 12 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -40,6 +40,11 @@ typedef qint64 QgsFeatureId;
typedef WhatEver ShouldNotBeDisplayed;
#endif

typedef QSet<QgsFeatureId SIP_PYTYPE( qint64 )> QgsFeatureIds;
typedef QMap<QgsFeatureId SIP_PYTYPE( qint64 ), QgsAttributeMap SIP_PYTYPE( 'QMap<int, QVariant>' )> QgsChangedAttributesMap;
typedef QMap<QgsFeatureId, QgsAttributeMap> SIP_PYTYPE( 'QMap<qint64, QMap<int, QVariant> >' ) QgsChangedAttributesMap;
typedef QMap<QgsFeatureId, QPair<QMap<Something, Complex> >> SIP_PYTYPE( 'QMap<qint64, QMap<int, QVariant>>' ) QgsChangedAttributesMap;

/** \ingroup core
* A super QGIS class
*/
Expand Down Expand Up @@ -118,6 +123,13 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, 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<QgsFeatureId> SIP_PYTYPE( QList<qint64> ) &list );

//! complex default value and type (i.e. containing commas) should be given as a string with single quotes
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>>>()' ) );

inline inlineKeyWordShouldNotAppear();

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

0 comments on commit 9846b34

Please sign in to comment.