Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[sipify] improvements
 * add In annotation
 * remove struct forward declarations
 * fix members initialization list in header
 * merge removal code for function bodies and constructor definition
  • Loading branch information
3nids committed Apr 26, 2017
1 parent 946f0fa commit 45266cd
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 40 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsaction.sip
Expand Up @@ -33,6 +33,7 @@ class QgsAction
%Docstring
Default constructor
%End

QgsAction( ActionType type, const QString &description, const QString &command, bool capture = false );
%Docstring
Create a new QgsAction
Expand All @@ -42,6 +43,7 @@ class QgsAction
\param command The action text. Its interpretation depends on the type
\param capture If this is set to true, the output will be captured when an action is run
%End

QgsAction( ActionType type, const QString &description, const QString &action, const QString &icon, bool capture, const QString &shortTitle = QString(), const QSet<QString> &actionScopes = QSet<QString>() );
%Docstring
Create a new QgsAction
Expand All @@ -54,6 +56,7 @@ class QgsAction
\param shortTitle A short string used to label user interface elements like buttons
\param actionScopes A set of scopes in which this action will be available
%End

QString name() const;
%Docstring
The name of the action. This may be a longer description.
Expand Down
1 change: 1 addition & 0 deletions python/core/qgsactionmanager.sip
Expand Up @@ -29,6 +29,7 @@ class QgsActionManager
%Docstring
Constructor
%End

QUuid addAction( QgsAction::ActionType type, const QString &name, const QString &command, bool capture = false );
%Docstring
Add an action with the given name and action details.
Expand Down
5 changes: 5 additions & 0 deletions python/core/qgsattributeeditorelement.sip
Expand Up @@ -59,6 +59,7 @@ class QgsAttributeEditorElement /Abstract/
\param name
\param parent
%End

virtual ~QgsAttributeEditorElement();

QString name() const;
Expand Down Expand Up @@ -143,6 +144,7 @@ class QgsAttributeEditorContainer : QgsAttributeEditorElement
\param parent The parent. May be another container.
%End


virtual ~QgsAttributeEditorContainer();

virtual void addChildElement( QgsAttributeEditorElement *element );
Expand Down Expand Up @@ -254,6 +256,7 @@ class QgsAttributeEditorField : QgsAttributeEditorElement
\param idx The index of the field which should be embedded
\param parent The parent of this widget (used as container)
%End

int idx() const;
%Docstring
Return the index of the field
Expand Down Expand Up @@ -284,6 +287,7 @@ class QgsAttributeEditorRelation : QgsAttributeEditorElement
\param relationId The id of the relation to embed
\param parent The parent (used as container)
%End

QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent );
%Docstring
Creates a new element which embeds a relation.
Expand All @@ -292,6 +296,7 @@ class QgsAttributeEditorRelation : QgsAttributeEditorElement
\param relation The relation to embed
\param parent The parent (used as container)
%End

const QgsRelation &relation() const;
%Docstring
Get the id of the relation which shall be embedded
Expand Down
1 change: 1 addition & 0 deletions python/core/qgsattributetableconfig.sip
Expand Up @@ -36,6 +36,7 @@ class QgsAttributeTableConfig
Constructor for ColumnConfig
%End


QgsAttributeTableConfig::Type type; //!< The type of this column.
QString name; //!< The name of the attribute if this column represents a field
bool hidden; //!< Flag that controls if the column is hidden
Expand Down
3 changes: 2 additions & 1 deletion python/core/qgscolorramp.sip
Expand Up @@ -102,6 +102,7 @@ class QgsGradientStop
\param offset positional offset for stop, between 0 and 1.0
\param color color for stop
%End

double offset;
%Docstring
Relative positional offset, between 0 and 1
Expand Down Expand Up @@ -685,7 +686,7 @@ lazy loading - have to call loadPalette() explicitly
%End
void setVariantName( const QString &variantName );
void setVariantList( const QStringList &variantList );
void setName( const QString &schemeName, const QString &variantName = "", const QStringList &variantList = QStringList() );
void setName( const QString &schemeName, const QString &variantName = QString(), const QStringList &variantList = QStringList() );

void loadPalette();
bool hasMultiStops() const;
Expand Down
1 change: 1 addition & 0 deletions python/core/qgsfeedback.sip
Expand Up @@ -39,6 +39,7 @@ class QgsFeedback : QObject
%Docstring
Construct a feedback object
%End

void cancel();
%Docstring
Tells the internal routines that the current operation should be canceled. This should be run by the main thread
Expand Down
1 change: 0 additions & 1 deletion python/core/qgsofflineediting.sip
Expand Up @@ -9,7 +9,6 @@



struct sqlite3;

class QgsOfflineEditing : QObject
{
Expand Down
1 change: 1 addition & 0 deletions python/core/scalebar/qgsscalebarsettings.sip
Expand Up @@ -38,6 +38,7 @@ class QgsScaleBarSettings
%Docstring
Constructor for QgsScaleBarSettings.
%End

int numberOfSegments() const;
%Docstring
Returns the number of segments included in the scalebar.
Expand Down
3 changes: 3 additions & 0 deletions python/gui/qgsidentifymenu.sip
Expand Up @@ -32,8 +32,11 @@ class QgsIdentifyMenu : QMenu
struct ActionData
{
ActionData();

ActionData( QgsMapLayer *layer, QgsMapLayerAction *mapLayerAction = 0 );

ActionData( QgsMapLayer *layer, QgsFeatureId fid, QgsMapLayerAction *mapLayerAction = 0 );

bool mIsValid;
bool mAllResults;
bool mIsExternalAction;
Expand Down
3 changes: 3 additions & 0 deletions python/gui/qgsoptionswidgetfactory.sip
Expand Up @@ -24,6 +24,7 @@ class QgsOptionsPageWidget : QWidget
%Docstring
Constructor for QgsOptionsPageWidget.
%End

public slots:

virtual void apply() = 0;
Expand All @@ -49,10 +50,12 @@ QGIS crashing when a plugin crashes/exits without deregistering a factory
%Docstring
Constructor
%End

QgsOptionsWidgetFactory( const QString &title, const QIcon &icon );
%Docstring
Constructor
%End

virtual QIcon icon() const;
%Docstring
The icon that will be shown in the UI for the panel.
Expand Down
44 changes: 10 additions & 34 deletions scripts/sipify.pl
Expand Up @@ -201,7 +201,7 @@ sub processDoxygenLine
}

# Skip forward declarations
if ($line =~ m/^\s*class \w+;$/){
if ($line =~ m/^\s*(class|struct) \w+;$/){
next;
}
# Skip Q_OBJECT, Q_PROPERTY, Q_ENUM, Q_GADGET
Expand Down Expand Up @@ -440,43 +440,18 @@ sub processDoxygenLine
$line =~ s/\bnullptr\b/0/g;
$line =~ s/\s*=\s*default\b//g;

# remove constructor definition
if ( $line =~ m/^(\s*)?(explicit )?(\w+)\([\w\=\(\)\s\,\&\*\<\>]*\)(?!;)$/ ){
my $newline = $line =~ s/\n/;\n/r;
my $nesting_index = 0;
while ($line_idx < $line_count){
$line = $lines[$line_idx];
$line_idx++;
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 ( $SIP_RUN != 1 && $line =~ m/^(\s*)?(virtual )?(static |const )*(([\w:]+(<.*?>)?\s+(\*|&)?)?(\w+|operator.{1,2})\(.*?(\(.*\))*.*\)( (?:const|SIP_[A-Z_]*?))*)\s*(\{.*\})?(?!;)(\s*\/\/.*)?$/ ){
my $newline = "$1$2$3$4;";
# remove constructor definition, function bodies, member initializing list
if ( $SIP_RUN != 1 && $line =~ m/^(\s*)?(explicit )?(virtual )?(static |const )*(([\w:]+(<.*?>)?\s+(\*|&)?)?(\w+|operator.{1,2})\([\w=()\/ ,&*<>:]*\)( (?:const|SIP_[A-Z_]*?))*)\s*(\{.*\})?(?!;)(\s*\/\/.*)?$/ ){
my $newline = "$1$2$3$4$5;";
if ($line !~ m/\{.*?\}$/){
$line = $lines[$line_idx];
$line_idx++;
while ( $line =~ m/^\s*[:,] \w+\(.*?\)/){
$line = $lines[$line_idx];
$line_idx++;
}
my $nesting_index = 1;
if ( $line =~ m/^\s*\{\s*$/ ){
if ( $line =~ m/^\s*\{$/ ){
while ($line_idx < $line_count){
$line = $lines[$line_idx];
$line_idx++;
Expand Down Expand Up @@ -532,6 +507,7 @@ sub processDoxygenLine

$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
$line =~ s/\bSIP_OUT\b/\/Out\//g;
$line =~ s/\bSIP_IN\b/\/In\//g;
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgis.h
Expand Up @@ -413,6 +413,11 @@ typedef unsigned long long qgssize;
*/
#define SIP_OUT

/*
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-In
*/
#define SIP_IN

/*
* Combination of
* http://pyqt.sourceforge.net/Docs/sip4/annotations.html?highlight=keepreference#argument-annotation-In
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscolorramp.h
Expand Up @@ -604,7 +604,7 @@ class CORE_EXPORT QgsCptCityColorRamp : public QgsGradientColorRamp
void setSchemeName( const QString &schemeName ) { mSchemeName = schemeName; mFileLoaded = false; }
void setVariantName( const QString &variantName ) { mVariantName = variantName; mFileLoaded = false; }
void setVariantList( const QStringList &variantList ) { mVariantList = variantList; }
void setName( const QString &schemeName, const QString &variantName = "", const QStringList &variantList = QStringList() )
void setName( const QString &schemeName, const QString &variantName = QString(), const QStringList &variantList = QStringList() )
{ mSchemeName = schemeName; mVariantName = variantName; mVariantList = variantList; mFileLoaded = false; }

void loadPalette() { loadFile(); }
Expand Down
13 changes: 11 additions & 2 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -97,7 +97,6 @@ A constructor with no empty `()`
%Docstring
A constructor with some special character types
%End
{}

QgsSipifyHeader();
%Docstring
Expand Down Expand Up @@ -261,7 +260,17 @@ Mulitline body

struct PublicStruct
{
int var;
explicit PublicStruct( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex );

bool isValid( const QgsAbstractGeometry *geom ) const;
%Docstring
:rtype: bool
%End

int part;
int ring;
int vertex;
VertexType type;
}

void ZshouldBeShown();
Expand Down
19 changes: 18 additions & 1 deletion tests/scripts/sipifyheader.h
Expand Up @@ -276,7 +276,24 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas

struct CORE_EXPORT PublicStruct
{
int var;
explicit PublicStruct( int _part = -1, int _ring = -1, int _vertex = -1, VertexType _type = SegmentVertex )
: part( _part )
, ring( _ring )
, vertex( _vertex )
, type( _type )
{}

bool isValid( const QgsAbstractGeometry *geom ) const
{
return ( part >= 0 && part < geom->partCount() ) &&
( ring < geom->ringCount( part ) ) &&
( vertex < 0 || vertex < geom->vertexCount( part, ring ) );
}

int part;
int ring;
int vertex;
VertexType type;
}

#if 0
Expand Down

0 comments on commit 45266cd

Please sign in to comment.