Skip to content

Commit 2d78ef8

Browse files
committedJun 2, 2017
handle PyName for enums
1 parent 98f653e commit 2d78ef8

File tree

8 files changed

+97
-100
lines changed

8 files changed

+97
-100
lines changed
 

‎python/core/raster/qgsrasterminmaxorigin.sip

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@ class QgsRasterMinMaxOrigin
4040

4141
enum Limits
4242
{
43-
//! User
44-
None
45-
//! Real
43+
None /PyName=None_/,
4644
MinMax,
47-
//! Range
4845
StdDev,
49-
//! Range
5046
CumulativeCut
5147
};
5248

@@ -79,22 +75,22 @@ class QgsRasterMinMaxOrigin
7975
%End
8076

8177

82-
Limits limits() const;
78+
QgsRasterMinMaxOrigin::Limits limits() const;
8379
%Docstring
8480
Return limits.
85-
:rtype: Limits
81+
:rtype: QgsRasterMinMaxOrigin.Limits
8682
%End
8783

88-
Extent extent() const;
84+
QgsRasterMinMaxOrigin::Extent extent() const;
8985
%Docstring
9086
Return extent.
91-
:rtype: Extent
87+
:rtype: QgsRasterMinMaxOrigin.Extent
9288
%End
9389

94-
StatAccuracy statAccuracy() const;
90+
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const;
9591
%Docstring
9692
Return statistic accuracy.
97-
:rtype: StatAccuracy
93+
:rtype: QgsRasterMinMaxOrigin.StatAccuracy
9894
%End
9995

10096
double cumulativeCutLower() const;
@@ -116,17 +112,17 @@ class QgsRasterMinMaxOrigin
116112
%End
117113

118114

119-
void setLimits( Limits limits );
115+
void setLimits( QgsRasterMinMaxOrigin::Limits limits );
120116
%Docstring
121117
Set limits.
122118
%End
123119

124-
void setExtent( Extent extent );
120+
void setExtent( QgsRasterMinMaxOrigin::Extent extent );
125121
%Docstring
126122
Set extent.
127123
%End
128124

129-
void setStatAccuracy( StatAccuracy accuracy );
125+
void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy );
130126
%Docstring
131127
Set statistics accuracy.
132128
%End
@@ -170,28 +166,28 @@ class QgsRasterMinMaxOrigin
170166
:rtype: Limits
171167
%End
172168

173-
static QString extentString( Extent extent );
169+
static QString extentString( QgsRasterMinMaxOrigin::Extent extent );
174170
%Docstring
175171
Return a string to serialize Extent
176172
:rtype: str
177173
%End
178174

179-
static Extent extentFromString( const QString &extent );
175+
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent );
180176
%Docstring
181177
Deserialize Extent
182-
:rtype: Extent
178+
:rtype: QgsRasterMinMaxOrigin.Extent
183179
%End
184180

185-
static QString statAccuracyString( StatAccuracy accuracy );
181+
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy );
186182
%Docstring
187183
Return a string to serialize StatAccuracy
188184
:rtype: str
189185
%End
190186

191-
static StatAccuracy statAccuracyFromString( const QString &accuracy );
187+
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy );
192188
%Docstring
193189
Deserialize StatAccuracy
194-
:rtype: StatAccuracy
190+
:rtype: QgsRasterMinMaxOrigin.StatAccuracy
195191
%End
196192

197193
};

‎python/core/raster/qgsrasternuller.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class QgsRasterNuller : QgsRasterInterface
3737
virtual Qgis::DataType dataType( int bandNo ) const;
3838

3939

40-
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = 0 );
40+
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = 0 ) /Factory/;
4141

4242

4343
void setNoData( int bandNo, const QgsRasterRangeList &noData );

‎scripts/sipify.pl

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -161,58 +161,60 @@ sub remove_following_body_or_initializerlist {
161161
};
162162
}
163163

164-
sub fix_annotations(){
165-
# printed annotations
166-
$LINE =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
167-
$LINE =~ s/\bSIP_ALLOWNONE\b/\/AllowNone\//;
168-
$LINE =~ s/\bSIP_ARRAY\b/\/Array\//g;
169-
$LINE =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//g;
170-
$LINE =~ s/\bSIP_DEPRECATED\b/\/Deprecated\//g;
171-
$LINE =~ s/\bSIP_CONSTRAINED\b/\/Constrained\//g;
172-
$LINE =~ s/\bSIP_EXTERNAL\b/\/External\//g;
173-
$LINE =~ s/\bSIP_FACTORY\b/\/Factory\//;
174-
$LINE =~ s/\bSIP_IN\b/\/In\//g;
175-
$LINE =~ s/\bSIP_INOUT\b/\/In,Out\//g;
176-
$LINE =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
177-
$LINE =~ s/\bSIP_NODEFAULTCTORS\b/\/NoDefaultCtors\//;
178-
$LINE =~ s/\bSIP_OUT\b/\/Out\//g;
179-
$LINE =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
180-
$LINE =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
181-
$LINE =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
182-
$LINE =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
183-
184-
$LINE =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
185-
186-
# combine multiple annotations
187-
# https://regex101.com/r/uvCt4M/3
188-
do {no warnings 'uninitialized';
189-
$LINE =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
190-
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
191-
};
192-
193-
# unprinted annotations
194-
$LINE =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYALTERNATIVETYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
195-
$LINE =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
196-
# remove argument
197-
if ($LINE =~ m/SIP_PYARGREMOVE/){
198-
dbg_info("remove arg");
199-
if ( $MULTILINE_DEFINITION == 1 ){
200-
my $prev_line = pop(@OUTPUT) =~ s/\n$//r;
201-
# update multi line status
202-
my $parenthesis_balance = 0;
203-
$parenthesis_balance += $prev_line =~ tr/\(//;
204-
$parenthesis_balance -= $prev_line =~ tr/\)//;
205-
if ($parenthesis_balance == 1){
206-
$MULTILINE_DEFINITION = 0;
207-
}
208-
# concat with above line to bring previous commas
209-
$LINE =~ s/^\s+//;
210-
$LINE = "$prev_line $LINE\n";
211-
}
212-
# see https://regex101.com/r/5iNptO/4
213-
$LINE =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)?\s+[\w&*]+\s+SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
214-
}
215-
$LINE =~ s/SIP_FORCE//;
164+
sub fix_annotations {
165+
my $line = $_[0];
166+
# printed annotations
167+
$line =~ s/\bSIP_ABSTRACT\b/\/Abstract\//;
168+
$line =~ s/\bSIP_ALLOWNONE\b/\/AllowNone\//;
169+
$line =~ s/\bSIP_ARRAY\b/\/Array\//g;
170+
$line =~ s/\bSIP_ARRAYSIZE\b/\/ArraySize\//g;
171+
$line =~ s/\bSIP_DEPRECATED\b/\/Deprecated\//g;
172+
$line =~ s/\bSIP_CONSTRAINED\b/\/Constrained\//g;
173+
$line =~ s/\bSIP_EXTERNAL\b/\/External\//g;
174+
$line =~ s/\bSIP_FACTORY\b/\/Factory\//;
175+
$line =~ s/\bSIP_IN\b/\/In\//g;
176+
$line =~ s/\bSIP_INOUT\b/\/In,Out\//g;
177+
$line =~ s/\bSIP_KEEPREFERENCE\b/\/KeepReference\//;
178+
$line =~ s/\bSIP_NODEFAULTCTORS\b/\/NoDefaultCtors\//;
179+
$line =~ s/\bSIP_OUT\b/\/Out\//g;
180+
$line =~ s/\bSIP_RELEASEGIL\b/\/ReleaseGIL\//;
181+
$line =~ s/\bSIP_TRANSFER\b/\/Transfer\//g;
182+
$line =~ s/\bSIP_TRANSFERBACK\b/\/TransferBack\//;
183+
$line =~ s/\bSIP_TRANSFERTHIS\b/\/TransferThis\//;
184+
185+
$line =~ s/SIP_PYNAME\(\s*(\w+)\s*\)/\/PyName=$1\//;
186+
187+
# combine multiple annotations
188+
# https://regex101.com/r/uvCt4M/3
189+
do {no warnings 'uninitialized';
190+
$line =~ s/\/(\w+(=\w+)?)\/\s*\/(\w+(=\w+)?)\//\/$1,$3\//;
191+
(! $3) or dbg_info("combine multiple annotations -- works only for 2");
192+
};
193+
194+
# unprinted annotations
195+
$line =~ s/(\w+)(\<(?>[^<>]|(?2))*\>)?\s+SIP_PYALTERNATIVETYPE\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/$3/g;
196+
$line =~ s/=\s+[^=]*?\s+SIP_PYARGDEFAULT\(\s*\'?([^()']+)(\(\s*(?:[^()]++|(?2))*\s*\))?\'?\s*\)/= $1/g;
197+
# remove argument
198+
if ($line =~ m/SIP_PYARGREMOVE/){
199+
dbg_info("remove arg");
200+
if ( $MULTILINE_DEFINITION == 1 ){
201+
my $prev_line = pop(@OUTPUT) =~ s/\n$//r;
202+
# update multi line status
203+
my $parenthesis_balance = 0;
204+
$parenthesis_balance += $prev_line =~ tr/\(//;
205+
$parenthesis_balance -= $prev_line =~ tr/\)//;
206+
if ($parenthesis_balance == 1){
207+
$MULTILINE_DEFINITION = 0;
208+
}
209+
# concat with above line to bring previous commas
210+
$line =~ s/^\s+//;
211+
$line = "$prev_line $line\n";
212+
}
213+
# see https://regex101.com/r/5iNptO/4
214+
$line =~ s/(?<coma>, +)?(const )?(\w+)(\<(?>[^<>]|(?4))*\>)?\s+[\w&*]+\s+SIP_PYARGREMOVE( = [^()]*(\(\s*(?:[^()]++|(?6))*\s*\))?)?(?(<coma>)|,?)//g;
215+
}
216+
$line =~ s/SIP_FORCE//;
217+
return $line;
216218
}
217219

218220
# detect a comment block, return 1 if found
@@ -464,7 +466,7 @@ sub detect_comment_block{
464466
if (defined $+{annot})
465467
{
466468
$LINE .= "$+{annot}";
467-
fix_annotations();
469+
$LINE = fix_annotations($LINE);
468470
}
469471

470472
$LINE .= "\n{\n";
@@ -606,8 +608,11 @@ sub detect_comment_block{
606608
if ($LINE =~ m/\};/){
607609
last;
608610
}
609-
my $enum_val = $LINE =~ s/(\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$3/r;
610-
write_output("ENU3", "$enum_val\n");
611+
do {no warnings 'uninitialized';
612+
my $enum_decl = $LINE =~ s/(\s*\w+)(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*[\w\s\d<|]+.*?)?(,?).*$/$1$2$3/r;
613+
$enum_decl = fix_annotations($enum_decl);
614+
write_output("ENU3", "$enum_decl\n");
615+
};
611616
detect_comment_block(strict_mode => UNSTRICT);
612617
}
613618
write_output("ENU4", "$LINE\n");
@@ -739,7 +744,7 @@ sub detect_comment_block{
739744
# remove export macro from struct definition
740745
$LINE =~ s/^(\s*struct )\w+_EXPORT (.+)$/$1$2/;
741746

742-
fix_annotations();
747+
$LINE = fix_annotations($LINE);
743748

744749
# fix astyle placing space after % character
745750
$LINE =~ s/\s*% (MappedType|Type(Header)?Code|Module(Header)?Code|Convert(From|To)TypeCode|MethodCode|End)/%$1/;

‎src/core/raster/qgsrasterinterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class CORE_EXPORT QgsRasterInterface
319319
*/
320320
#ifndef SIP_RUN
321321
virtual bool hasHistogram( int bandNo,
322-
int binCount = 0,
322+
int binCount,
323323
double minimum = std::numeric_limits<double>::quiet_NaN(),
324324
double maximum = std::numeric_limits<double>::quiet_NaN(),
325325
const QgsRectangle &extent = QgsRectangle(),
@@ -384,7 +384,7 @@ class CORE_EXPORT QgsRasterInterface
384384
#ifndef SIP_RUN
385385
void initHistogram( QgsRasterHistogram &histogram,
386386
int bandNo,
387-
int binCount = 0,
387+
int binCount,
388388
double minimum = std::numeric_limits<double>::quiet_NaN(),
389389
double maximum = std::numeric_limits<double>::quiet_NaN(),
390390
const QgsRectangle &boundingBox = QgsRectangle(),

‎src/core/raster/qgsrasterminmaxorigin.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
4646
//! \brief This enumerator describes the limits used to compute min/max values
4747
enum Limits
4848
{
49-
//! User defined.
50-
None SIP_PYNAME( None_ ),
51-
//! Real min-max values
52-
MinMax,
53-
//! Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
54-
StdDev,
55-
//! Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
56-
CumulativeCut
49+
None SIP_PYNAME( None_ ), //!< User defined.
50+
MinMax, //!< Real min-max values
51+
StdDev, //!< Range is [ mean - stdDevFactor() * stddev, mean + stdDevFactor() * stddev ]
52+
CumulativeCut //!< Range is [ min + cumulativeCutLower() * (max - min), min + cumulativeCutUpper() * (max - min) ]
5753
};
5854

5955
//! \brief This enumerator describes the extent used to compute min/max values
@@ -85,13 +81,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
8581
//////// Getter methods /////////////////////
8682

8783
//! \brief Return limits.
88-
Limits limits() const { return mLimits; }
84+
QgsRasterMinMaxOrigin::Limits limits() const { return mLimits; }
8985

9086
//! \brief Return extent.
91-
Extent extent() const { return mExtent; }
87+
QgsRasterMinMaxOrigin::Extent extent() const { return mExtent; }
9288

9389
//! \brief Return statistic accuracy.
94-
StatAccuracy statAccuracy() const { return mAccuracy; }
90+
QgsRasterMinMaxOrigin::StatAccuracy statAccuracy() const { return mAccuracy; }
9591

9692
//! \brief Return lower bound of cumulative cut method (between 0 and 1).
9793
double cumulativeCutLower() const { return mCumulativeCutLower; }
@@ -105,13 +101,13 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
105101
//////// Setter methods /////////////////////
106102

107103
//! \brief Set limits.
108-
void setLimits( Limits limits ) { mLimits = limits; }
104+
void setLimits( QgsRasterMinMaxOrigin::Limits limits ) { mLimits = limits; }
109105

110106
//! \brief Set extent.
111-
void setExtent( Extent extent ) { mExtent = extent; }
107+
void setExtent( QgsRasterMinMaxOrigin::Extent extent ) { mExtent = extent; }
112108

113109
//! \brief Set statistics accuracy.
114-
void setStatAccuracy( StatAccuracy accuracy ) { mAccuracy = accuracy; }
110+
void setStatAccuracy( QgsRasterMinMaxOrigin::StatAccuracy accuracy ) { mAccuracy = accuracy; }
115111

116112
//! \brief Set lower bound of cumulative cut method (between 0 and 1).
117113
void setCumulativeCutLower( double val ) { mCumulativeCutLower = val; }
@@ -139,16 +135,16 @@ class CORE_EXPORT QgsRasterMinMaxOrigin
139135
static Limits limitsFromString( const QString &limits );
140136

141137
//! \brief Return a string to serialize Extent
142-
static QString extentString( Extent extent );
138+
static QString extentString( QgsRasterMinMaxOrigin::Extent extent );
143139

144140
//! \brief Deserialize Extent
145-
static Extent extentFromString( const QString &extent );
141+
static QgsRasterMinMaxOrigin::Extent extentFromString( const QString &extent );
146142

147143
//! \brief Return a string to serialize StatAccuracy
148-
static QString statAccuracyString( StatAccuracy accuracy );
144+
static QString statAccuracyString( QgsRasterMinMaxOrigin::StatAccuracy accuracy );
149145

150146
//! \brief Deserialize StatAccuracy
151-
static StatAccuracy statAccuracyFromString( const QString &accuracy );
147+
static QgsRasterMinMaxOrigin::StatAccuracy statAccuracyFromString( const QString &accuracy );
152148

153149
private:
154150

‎src/core/raster/qgsrasternuller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CORE_EXPORT QgsRasterNuller : public QgsRasterInterface
4545

4646
Qgis::DataType dataType( int bandNo ) const override;
4747

48-
QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
48+
QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
4949

5050
void setNoData( int bandNo, const QgsRasterRangeList &noData );
5151

‎tests/scripts/sipifyheader.expected.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010

11-
1211
%ModuleHeaderCode
1312
#include <qgsnetworkspeedstrategy.h>
1413
#include <qgsnetworkdistancestrategy.h>
@@ -79,6 +78,7 @@ typedef QtClass<QVariant> QtClassQVariantBase;
7978
ImaginarySuccess,
8079
RecursiveSuccess,
8180
SuccessCombination,
81+
PythonName /PyName=DifferentName/,
8282
};
8383
typedef QFlags<QgsSipifyHeader::MyEnum> Flags;
8484

‎tests/scripts/sipifyheader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ email : denis.rouzaud@gmail.com
1616
#ifndef SIPIFYHEADER_H
1717
#define SIPIFYHEADER_H
1818

19-
2019
#include "qgis_core.h"
2120
#include <QtClass>
2221

@@ -113,6 +112,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private Ui::QgsBas
113112
ImaginarySuccess = 1 << 3, //!< Edit operation resulted in an imaginary geometry
114113
RecursiveSuccess = 1 << 4, //!< Edit operation resulted in an n-dimensional wormhole
115114
SuccessCombination = Success | ImaginarySuccess, //!< Holy Graal
115+
PythonName SIP_PYNAME( DifferentName ), //!< Different python name
116116
};
117117
Q_DECLARE_FLAGS( Flags, MyEnum )
118118

0 commit comments

Comments
 (0)
Please sign in to comment.