Skip to content
Permalink
Browse files
sipify improvements
* add demo file and start a short doc
* fix some annotations
* do not display hidden line (SIP_SKIP, delete)
* use a defined var for SIP_SKIP
* remove constructor definition in header
* fix comment after method definition in header
* add a test for sipify itself
  • Loading branch information
3nids committed Mar 30, 2017
1 parent 21be025 commit 15e4903890205ada900877bf54fe8280585a9395
@@ -8,4 +8,5 @@ ENABLE_TESTING()

ADD_TEST(qgis_indentation ${CMAKE_SOURCE_DIR}/../../../scripts/verify-indentation.sh)
ADD_TEST(qgis_spelling ${CMAKE_SOURCE_DIR}/../../../scripts/spell_check/spell_test.sh)
ADD_TEST(qgis_sip ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_auto_sipfiles.sh)
ADD_TEST(qgis_sipify ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_sipify.sh)
ADD_TEST(qgis_sip_uptodate ${CMAKE_SOURCE_DIR}/../../../tests/scripts/test_sipfiles_uptodate.sh)
@@ -1356,7 +1356,8 @@ EXPAND_AS_DEFINED = "SIP_TRANSFER" \
"SIP_TRANSFERBACK" \
"SIP_FACTORY" \
"SIP_KEEPREFERENCE" \
"SIP_PYNAME"
"SIP_PYNAME" \
"SIP_SKIP"

# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
# doxygen's preprocessor will remove all function-like macros that are alone
@@ -10,6 +10,7 @@




typedef QMap<int, QVariant> QgsAttributeMap;

typedef QMap<int, QString> QgsFieldNameMap;
@@ -10,6 +10,7 @@




typedef qint64 QgsFeatureId;


@@ -152,13 +153,7 @@ class QgsFeature
Copy constructor
%End

// QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP


// bool operator==( const QgsFeature &other ) const; // SIP_SKIP


// bool operator!=( const QgsFeature &other ) const; // SIP_SKIP


virtual ~QgsFeature();
@@ -437,10 +432,6 @@ Allows direct construction of QVariants from features.

}; // class QgsFeature

// CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ); // SIP_SKIP

// CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ); // SIP_SKIP


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

@@ -450,7 +441,5 @@ typedef QSet<qint64> QgsFeatureIds;

typedef QList<QgsFeature> QgsFeatureList;

// uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP



@@ -335,8 +335,6 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator

virtual ~QgsVectorLayer();

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

QString storageType() const;
%Docstring
@@ -384,8 +382,6 @@ Returns a comment for the data in the layer
Returns the data provider
%End

// const QgsVectorDataProvider *dataProvider() const; // SIP_SKIP


void setProviderEncoding( const QString &encoding );
%Docstring
@@ -630,8 +626,6 @@ Sets diagram rendering object (takes ownership)
Return renderer.
%End

// const QgsFeatureRenderer *renderer() const { return mRenderer; } // SIP_SKIP


void setRenderer( QgsFeatureRenderer *r /Transfer/ );
%Docstring
@@ -973,10 +967,6 @@ TODO QGIS 3.0 returns an enum instead of a magic constant
@return 0 in case of success
%End

// const QgsAbstractVectorLayerLabeling *labeling() const { return mLabeling; } // SIP_SKIP


// void setLabeling( QgsAbstractVectorLayerLabeling *labeling ); // SIP_SKIP


virtual bool isEditable() const;
@@ -1256,8 +1246,6 @@ Set annotation form for layer
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
%End

// const QgsVectorLayerEditBuffer *editBuffer() const { return mEditBuffer; } // SIP_SKIP


void beginEditCommand( const QString &text );
%Docstring
@@ -1512,8 +1500,6 @@ Returns the current transparency for the vector layer

QString metadata() const;

// inline QgsGeometryCache *cache() { return mCache; } // SIP_SKIP


void setSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod );
%Docstring
@@ -35,7 +35,6 @@
# Skip preprocessor stuff
if ($line =~ m/^\s*#/){
if ( $line =~ m/^\s*#ifdef SIP_RUN/){

$SIP_RUN = 1;
if ($PRIVATE_SECTION == 1){
print $private_section_line;
@@ -125,13 +124,11 @@

# SIP_SKIP
if ( $line =~ m/SIP_SKIP/ ){
$line =~ s/^(\s*)(\w.*)$/$1\/\/ $2\n/;
print $line;
next;
}

# Private members (exclude SIP_RUN)
if ( $line =~ m/^\s*private( slots)?:.*$/ ){
if ( $line =~ m/^\s*private( slots)?:/ ){
$PRIVATE_SECTION = 1;
$private_section_line = $line;
next;
@@ -148,18 +145,20 @@
}

# Detect comment block
if ($line =~ m/\s*\/\*\*/){
$comment = $line =~ s/\s*\/\*\*(.*)$/$1/r;
if ($line =~ m/^\s*\/\*/){
do {no warnings 'uninitialized';
$comment = $line =~ s/^\s*\/\*(\*)?(.*)$/$2/r;
};
$comment =~ s/^\s*$//;
while(!eof $header){
$line = readline $header;
$line =~ m/\s*\*?(.*?)(\/)?$/;
$comment .= "$1\n";
$comment .= $line =~ s/\s*\*?(.*?)(\/)?$/$1/r;
if ( $line =~ m/\*\/$/ ){
last;
}
}
$comment =~ s/(\n)+$//;
#print $comment;
next;
}

@@ -177,14 +176,17 @@
$line = "$1$3";
# Inheritance
if ($4){
my $m;
$m = $4;
my $m = $4;
$m =~ s/public //g;
$m =~ s/\s*private \w+,?//;
$m =~ s/,?\s*private \w+//;
$m =~ s/(\s*:)?\s*$//;
$line .= $m;
}

$line .= "\n{\n%Docstring\n$comment\n%End\n";
$line .= "\n{\n";
if ( $comment !~ m/^\s*$/ ){
$line .= "%Docstring\n$comment\n%End\n";
}
$line .= "\n%TypeHeaderCode\n#include \"" . basename($headerfile) . "\"\n";

print $line;
@@ -214,17 +216,46 @@
print $line;
}
print $line;
# enums don't have Docstring apparently
next;
}

# remove keywords
do {no warnings 'uninitialized';
$line =~ s/\s*override( SIP_FACTORY)?;/$1;/;
# remove keywords
$line =~ s/\s*override( SIP_\w+(\(.+\))?)?;/$1;/;
$line =~ s/^(\s*)?(const )?(virtual |static )?inline /$1$2$3/;
$line =~ s/\bnullptr\b/0/g;

# remove constructor definition
if ( $line =~ m/^(\s*)?(explicit )?(\w+)\(([^()]*\([^()]*\)[^()]*)*\)(?!;)$/ ){
my $newline = $line =~ s/\n/;\n/r;
my $nesting_index = 0;
while(!eof $header){
$line = readline $header;
if ( $nesting_index == 0 ){
if ( $line =~ m/^\s*(:|,)/ ){
next;
}
$line =~ m/^\s*\{/ or die 'Constructor definition misses {';
if ( $line =~ m/^\s*\{.*?\}/ ){
last;
}
$nesting_index = 1;
next;
}
else {
$nesting_index += $line =~ tr/\{//;
$nesting_index -= $line =~ tr/\}//;
if ($nesting_index eq 0){
last;
}
}
}
$line = $newline;
}

# remove function bodies
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*(\{.*\})?(?!;)$/ ){
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*(\{.*\})?(?!;)(\s*\/\/.*)?$/ ){
my $newline = "$1$2$3$4;\n";
if ($line !~ m/\{.*?\}$/){
$line = readline $header;
@@ -242,18 +273,20 @@
};

# deleted functions
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*= delete;$/ ){
$line =~ s/^/\/\//;
if ( $line =~ m/^(\s*)?(const )?(virtual |static )?((\w+(<.*?>)?\s+(\*|&)?)?(\w+|operator.)\(.*?(\(.*\))*.*\)( const)?)\s*= delete;(\s*\/\/.*)?$/ ){
$comment = '';
next;
}

$line =~ s/SIP_FACTORY/\/Factory\//;
$line =~ s/SIP_OUT/\/Out\//g;
$line =~ s/SIP_INOUT/\/In,Out\//g;
$line =~ s/SIP_TRANSFER/\/Transfer\//g;
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_OUT\b/\/Out\//g;
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;

$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
$line =~ s/SIP_KEEPREFERENCE\((\w+)\)/\/KeepReference\//;
$line =~ s/SIP_TRANSFERTHIS\((\w+)\)/\/TransferThis\//;
$line =~ s/SIP_TRANSFERBACK\((\w+)\)/\/TransferBack\//;

# fix astyle placing space after % character
$line =~ s/\s*% (MappedType|TypeHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/%$1/;
@@ -280,7 +313,7 @@
if ( $line =~ m/^\s*$/ || $line =~ m/\/\// || $line =~ m/\s*typedef / ){
$comment = '';
}
elsif ( $comment ne '' ){
elsif ( $comment !~ m/^\s*$/ ){
print "%Docstring\n$comment\n%End\n";
$comment = '';
}
@@ -416,7 +416,7 @@ typedef unsigned long long qgssize;
* and
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-Out
*/
#define SIP_IN_OUT
#define SIP_INOUT

/**
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#function-annotation-Factory
@@ -432,3 +432,8 @@ typedef unsigned long long qgssize;
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-KeepReference
*/
#define SIP_KEEPREFERENCE

/**
* discard line
*/
#define SIP_SKIP
@@ -19,6 +19,8 @@
#define QGSATTRIBUTES_H

#include "qgis_core.h"
#include "qgis.h"

#include <QMap>
#include <QString>
#include <QVariant>
@@ -113,7 +115,7 @@ class CORE_EXPORT QgsAttributes : public QVector<QVariant>
* @note added in QGIS 3.0
* @note not available in Python bindings
*/
QgsAttributeMap toMap() const; // SIP_SKIP
QgsAttributeMap toMap() const SIP_SKIP;

inline bool operator!=( const QgsAttributes &v ) const { return !( *this == v ); }
};
@@ -17,6 +17,8 @@ email : sherman at mrcc.com
#define QGSFEATURE_H

#include "qgis_core.h"
#include "qgis.h"

#include <QExplicitlySharedDataPointer>
#include <QList>
#include <QMap>
@@ -200,17 +202,17 @@ class CORE_EXPORT QgsFeature

/** Assignment operator
*/
QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP
QgsFeature &operator=( const QgsFeature &rhs ) SIP_SKIP;

/**
* Compares two features
*/
bool operator==( const QgsFeature &other ) const; // SIP_SKIP
bool operator==( const QgsFeature &other ) const SIP_SKIP;

/**
* Compares two features
*/
bool operator!=( const QgsFeature &other ) const; // SIP_SKIP
bool operator!=( const QgsFeature &other ) const SIP_SKIP;

virtual ~QgsFeature();

@@ -498,9 +500,9 @@ class CORE_EXPORT QgsFeature
}; // class QgsFeature

//! Writes the feature to stream out. QGIS version compatibility is not guaranteed.
CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ); // SIP_SKIP
CORE_EXPORT QDataStream &operator<<( QDataStream &out, const QgsFeature &feature ) SIP_SKIP;
//! Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed.
CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ); // SIP_SKIP
CORE_EXPORT QDataStream &operator>>( QDataStream &in, QgsFeature &feature ) SIP_SKIP;

// key = feature id, value = changed attributes
#ifndef SIP_RUN
@@ -524,7 +526,7 @@ typedef QSet<qint64> QgsFeatureIds;

typedef QList<QgsFeature> QgsFeatureList;

uint qHash( const QgsFeature &key, uint seed = 0 ); // SIP_SKIP
uint qHash( const QgsFeature &key, uint seed = 0 ) SIP_SKIP;

Q_DECLARE_METATYPE( QgsFeature )
Q_DECLARE_METATYPE( QgsFeatureList )

0 comments on commit 15e4903

Please sign in to comment.