Skip to content

Commit

Permalink
[sipify] operators, remove argument
Browse files Browse the repository at this point in the history
 * skip some operators
 * allow to remove an argument with SIP_PYARGREMOVE
  • Loading branch information
3nids committed Apr 26, 2017
1 parent 0f9ddc2 commit 4cc4a27
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 36 deletions.
4 changes: 2 additions & 2 deletions cmake_templates/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,8 @@ EXPAND_AS_DEFINED = "SIP_TRANSFER" \
"SIP_KEEPREFERENCE" \
"SIP_PYNAME" \
"SIP_SKIP" \
"SIP_PYDEFAULTVALUE" \
"SIP_PYTYPE" \
"SIP_PYARGDEFAULT" \
"SIP_PYARGTYPE" \
"SIP_CONVERT_TO_SUBCLASS_CODE" \
"SIP_FEATURE" \
"SIP_IF_FEATURE" \
Expand Down
2 changes: 1 addition & 1 deletion python/core/geometry/qgsrectangle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Copy constructor
:rtype: bool
%End

// QgsRectangle &operator=( const QgsRectangle &r1 );

void unionRect( const QgsRectangle &rect );
%Docstring
Updates the rectangle to include another rectangle.
Expand Down
2 changes: 1 addition & 1 deletion python/core/processing/qgsprocessingalgorithm.sip
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QgsProcessingAlgorithm

virtual ~QgsProcessingAlgorithm();

// QgsProcessingAlgorithm &operator=( const QgsProcessingAlgorithm &other ) = delete;

virtual QString name() const = 0;
%Docstring
Returns the algorithm name, used for identifying the algorithm. This string
Expand Down
2 changes: 1 addition & 1 deletion python/core/processing/qgsprocessingcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class QgsProcessingContext
Constructor for QgsProcessingContext.
%End

// QgsProcessingContext &operator=( const QgsProcessingContext &other ) = delete;

QgsProcessingContext::Flags flags() const;
%Docstring
Returns any flags set in the context.
Expand Down
2 changes: 1 addition & 1 deletion python/core/processing/qgsprocessingprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class QgsProcessingProvider : QObject

virtual ~QgsProcessingProvider();

// QgsProcessingProvider &operator=( const QgsProcessingProvider &other ) = delete;

virtual QIcon icon() const;
%Docstring
Returns an icon for the provider.
Expand Down
2 changes: 1 addition & 1 deletion python/core/processing/qgsprocessingregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QgsProcessingRegistry : QObject

~QgsProcessingRegistry();

// QgsProcessingRegistry &operator=( const QgsProcessingRegistry &other ) = delete;

QList<QgsProcessingProvider *> providers() const;
%Docstring
Get list of available providers.
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsconditionalstyle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class QgsConditionalStyle
QgsConditionalStyle( const QgsConditionalStyle &other );
QgsConditionalStyle( const QString &rule );

// QgsConditionalStyle &operator=( const QgsConditionalStyle &other );

bool matches( const QVariant &value, QgsExpressionContext &context ) const;
%Docstring
Check if the rule matches using the given value and feature
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgscoordinatereferencesystem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Constructs an invalid CRS object
Copy constructor
%End

// QgsCoordinateReferenceSystem &operator=( const QgsCoordinateReferenceSystem &srs );

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from QgsCoordinateReferenceSystem.
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgscoordinatetransform.sip
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Default constructor, creates an invalid QgsCoordinateTransform.
Copy constructor
%End

// QgsCoordinateTransform &operator=( const QgsCoordinateTransform &o );

~QgsCoordinateTransform();
%Docstring
Assignment operator
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgscrscache.sip
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ overhead of initialization for each redraw*
:rtype: QgsCoordinateTransformCache
%End

// QgsCoordinateTransformCache &operator=( const QgsCoordinateTransformCache &rh ) = delete;

QgsCoordinateTransform transform( const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );
%Docstring
Returns coordinate transformation. Cache keeps ownership
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class QgsMapLayer : QObject

virtual ~QgsMapLayer();

// QgsMapLayer &operator=( QgsMapLayer const & ) = delete;

QgsMapLayer::LayerType type() const;
%Docstring
Returns the type of the layer.
Expand Down
10 changes: 5 additions & 5 deletions python/core/qgspropertytransformer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class QgsCurveTransform
Copy constructor
%End

// QgsCurveTransform &operator=( const QgsCurveTransform &other );

QList< QgsPoint > controlPoints() const;
%Docstring
Returns a list of the control points for the transform.
Expand Down Expand Up @@ -187,7 +187,7 @@ class QgsPropertyTransformer
%Docstring
Copy constructor.
%End
// QgsPropertyTransformer &operator=( const QgsPropertyTransformer &other );

virtual ~QgsPropertyTransformer();

virtual Type transformerType() const = 0;
Expand Down Expand Up @@ -343,7 +343,7 @@ class QgsGenericNumericTransformer : QgsPropertyTransformer
%Docstring
Copy constructor.
%End
// QgsGenericNumericTransformer &operator=( const QgsGenericNumericTransformer &other );

virtual Type transformerType() const;
virtual QgsGenericNumericTransformer *clone();
virtual QVariant toVariant() const;
Expand Down Expand Up @@ -479,7 +479,7 @@ class QgsSizeScaleTransformer : QgsPropertyTransformer
%Docstring
Copy constructor.
%End
// QgsSizeScaleTransformer &operator=( const QgsSizeScaleTransformer &other );

virtual Type transformerType() const;
virtual QgsSizeScaleTransformer *clone() /Factory/;
virtual QVariant toVariant() const;
Expand Down Expand Up @@ -619,7 +619,7 @@ class QgsColorRampTransformer : QgsPropertyTransformer
Copy constructor
%End

// QgsColorRampTransformer &operator=( const QgsColorRampTransformer &other );

virtual Type transformerType() const;
virtual QgsColorRampTransformer *clone() /Factory/;
virtual QVariant toVariant() const;
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator, QgsFeatureSin

virtual ~QgsVectorLayer();

// QgsVectorLayer &operator=( QgsVectorLayer const &rhs ) = delete;

QString storageType() const;
%Docstring
Returns the permanent storage type for this layer as a friendly name.
Expand Down
28 changes: 23 additions & 5 deletions scripts/sipify.pl
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ sub processDoxygenLine
$comment = '';
next;
}
# Skip assignment operator
if ( $line =~ m/operator=\s*\(/ ){
push @output, "// $line";
# Skip operators
if ( $line =~ m/operator(=|<<|>>)\s*\(/ ){
next;
}

Expand Down Expand Up @@ -515,8 +514,27 @@ sub processDoxygenLine
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//;

$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;
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYARGTYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;

# remove argument
if ($line =~ m/SIP_PYARGREMOVE/){
if ( $MULTILINE_DEFINITION == 1 ){
my $prev_line = pop(@output) =~ s/\n$//r;
# update multi line status
my $parenthesis_balance = 0;
$parenthesis_balance += $prev_line =~ tr/\(//;
$parenthesis_balance -= $prev_line =~ tr/\)//;
if ($parenthesis_balance == 1){
$MULTILINE_DEFINITION = 0;
}
# concat with above line to bring previous commas
$line =~ s/^\s+//;
$line = "$prev_line $line\n";
}
# see https://regex101.com/r/5iNptO/4
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)? [\w&*]+ SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
}

$line =~ s/SIP_FORCE//;

Expand Down
14 changes: 10 additions & 4 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,20 @@ typedef unsigned long long qgssize;
#define SIP_FORCE

/*
* specify an alternative type for SIP methods
* specify an alternative type for SIP argument
*/
#define SIP_PYTYPE(type)
#define SIP_PYARGTYPE(type)

/*
* specify an alternative default value for SIP methods
* specify an alternative default value for SIP argument
*/
#define SIP_PYDEFAULTVALUE(value)
#define SIP_PYARGDEFAULT(value)

/*
* remove argument in SIP method
*/
#define SIP_PYARGREMOVE


/*
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#function-annotation-ReleaseGIL
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class CORE_EXPORT QgsFeature
* \since QGIS 2.9
* \see fields
*/
void setFields( const QgsFields &fields, bool initAttributes = false SIP_PYDEFAULTVALUE( true ) );
void setFields( const QgsFields &fields, bool initAttributes = false SIP_PYARGDEFAULT( true ) );

/** Returns the field map associated with the feature.
* \see setFields
Expand Down
15 changes: 14 additions & 1 deletion tests/scripts/sipifyheader.expected.sip
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ A constructor with some special character types
Default constructor
%End

// QgsSipifyHeader &operator=( const QgsSipifyHeader other );

bool operator==( const QgsSipifyHeader other );
%Docstring
Comparison operator should be kept
Expand Down Expand Up @@ -281,6 +281,19 @@ Mulitline body
VertexType type;
}

void simple( );
%Docstring
remove argument
%End
void method( );
void test( );
void avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers );

void position( );
void position( bool keep );
void position( bool keep, bool keep );
void position( bool keep );

void ZshouldBeShown();


Expand Down
25 changes: 18 additions & 7 deletions tests/scripts/sipifyheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ 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;
typedef QSet<QgsFeatureId SIP_PYARGTYPE( qint64 )> QgsFeatureIds;
typedef QMap<QgsFeatureId SIP_PYARGTYPE( qint64 ), QgsAttributeMap SIP_PYARGTYPE( 'QMap<int, QVariant>' )> QgsChangedAttributesMap;
typedef QMap<QgsFeatureId, QgsAttributeMap> SIP_PYARGTYPE( 'QMap<qint64, QMap<int, QVariant> >' ) QgsChangedAttributesMap;
typedef QMap<QgsFeatureId, QPair<QMap<Something, Complex> >> SIP_PYARGTYPE( 'QMap<qint64, QMap<int, QVariant>>' ) QgsChangedAttributesMap;

/** \ingroup core
* A super QGIS class
Expand Down Expand Up @@ -202,12 +202,12 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas

void setDiagramRenderer( QgsDiagramRenderer *r SIP_TRANSFER );

void differentDefaultValue( bool defaultValue = true SIP_PYDEFAULTVALUE( false ), QWidget *parent = nullptr, QString msg = QString() SIP_PYDEFAULTVALUE( "hello" ) );
void differentDefaultValue( bool defaultValue = true SIP_PYARGDEFAULT( false ), QWidget *parent = nullptr, QString msg = QString() SIP_PYARGDEFAULT( "hello" ) );

void differentType( QList<QgsFeatureId> SIP_PYTYPE( QList<qint64> ) & list );
void differentType( QList<QgsFeatureId> SIP_PYARGTYPE( 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>>>()' ) );
void complexDefaultValueAndType( QList<QPair<QgsFeatureId SIP_PYARGTYPE( qint64 ), QMap<int, QString>>> list = QList<QPair<QgsFeatureId, QMap<int, QString>>>() SIP_PYARGDEFAULT( 'QList<QPair<qint64, QMap<int, QString>>>()' ) );

inline int inlineKeyWordShouldNotAppear();

Expand Down Expand Up @@ -305,6 +305,17 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
VertexType type;
}

//! remove argument
void simple( bool test SIP_PYARGREMOVE );
void method( bool myArg SIP_PYARGREMOVE = test );
void test( QgsMapLayer *vl SIP_PYARGREMOVE = nullptr );
void avoidIntersections( const QList<QgsVectorLayer *> &avoidIntersectionsLayers,
const QHash<QgsVectorLayer *, QSet<QgsFeatureId> > &ignoreFeatures SIP_PYARGREMOVE = ( QHash<QgsVectorLayer *, QSet<QgsFeatureId> >() ) );
void position( bool single_remove SIP_PYARGREMOVE );
void position( bool first_remove SIP_PYARGREMOVE, bool keep );
void position( bool keep, bool middle_remove SIP_PYARGREMOVE, bool keep );
void position( bool keep, bool last_remove SIP_PYARGREMOVE );

#if 0
#if Whatever
void X();
Expand Down

0 comments on commit 4cc4a27

Please sign in to comment.