Skip to content

Commit

Permalink
also monkey patch the former enum type
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Mar 25, 2019
1 parent 38c2d4a commit 9a6ddbd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions python/core/auto_additions/qgsmaplayer.py
@@ -1,4 +1,5 @@
# The following has been generated automatically from src/core/qgsmaplayer.h
QgsMapLayer.LayerType = QgsMapLayerType
# monkey patching scoped based enum
QgsMapLayer.VectorLayer = QgsMapLayerType.VectorLayer
QgsMapLayer.VectorLayer.__doc__ = ""
Expand Down
9 changes: 6 additions & 3 deletions scripts/sipify.pl
Expand Up @@ -959,12 +959,15 @@ sub detect_non_method_member{
my $is_scope_based = "0";
$is_scope_based = "1" if defined $2;
my $monkeypatch = "0";
$monkeypatch = "1" if defined $is_scope_based eq "1" and $LINE =~ m/SIP_MONKEYPATCH_SCOPEENUM(_UNNEST)?(:?\(\s*(?<emkb>\w+)\s*\))?/;
$monkeypatch = "1" if defined $is_scope_based eq "1" and $LINE =~ m/SIP_MONKEYPATCH_SCOPEENUM(_UNNEST)?(:?\(\s*(?<emkb>\w+)\s*,\s*(?<emkf>\w+)\s*\))?/;
my $enum_mk_base = "";
$enum_mk_base = $+{emkb} if defined $+{emkb};
if (defined $+{emkf} and $monkeypatch eq "1"){
push @OUTPUT_PYTHON, "$enum_mk_base.$+{emkf} = $enum_qualname\n";
}
if ($LINE =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
# one line declaration
$LINE !~ m/=/ or exit_with_error("spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.");
$LINE !~ m/=/ or exit_with_error("Sipify does not handle enum one liners with value assignment. Use multiple lines instead. Or jusr write a new parser.");
next;
}
else
Expand All @@ -984,7 +987,7 @@ sub detect_non_method_member{

do {no warnings 'uninitialized';
my $enum_decl = $LINE =~ s/^(\s*(?<em>\w+))(\s+SIP_\w+(?:\([^()]+\))?)?(?:\s*=\s*(?:[\w\s\d|+-]|::|<<)+)?(,?)(:?\s*\/\/!<\s*(?<co>.*)|.*)$/$1$3$4/r;
my $enum_member = $+{em};
my $enum_member = $+{em};
my $comment = $+{co};
dbg_info("is_scope_based:$is_scope_based enum_mk_base:$enum_mk_base monkeypatch:$monkeypatch");
if ($is_scope_based eq "1") {
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgis_sip.h
Expand Up @@ -242,7 +242,7 @@
* These macros should be removed in QGIS 4
*/
#define SIP_MONKEYPATCH_SCOPEENUM
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS)
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS,FORMERNAME)


#endif // QGIS_SIP_H
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.h
Expand Up @@ -58,7 +58,7 @@ class QPainter;


//! Types of layers that can be added to a map
enum class QgsMapLayerType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsMapLayer ) : int
enum class QgsMapLayerType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsMapLayer, LayerType ) : int
{
VectorLayer,
RasterLayer,
Expand Down

0 comments on commit 9a6ddbd

Please sign in to comment.