Skip to content

Commit

Permalink
Handle Q_DECLARE_FLAGS and Q_DECLARE_OPERATORS_FOR_FLAGS in sipify
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 5542444 commit 7db1913
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scripts/sipify.pl
Expand Up @@ -42,6 +42,8 @@ sub processDoxygenLine
my $nesting_index = 0;
my $private_section_line = '';
my $line;
my $classname = '';
my %qflag_hash;

print "/************************************************************************\n";
print " * This file has been generated automatically from *\n";
Expand Down Expand Up @@ -220,12 +222,12 @@ sub processDoxygenLine
}

# class declaration started
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?(\s+\w+)(\s*\:.*)?$/ ){
if ( $line =~ m/^(\s*class)\s*([A-Z]+_EXPORT)?\s+(\w+)(\s*\:.*)?$/ ){
do {no warnings 'uninitialized';
my $classname = $3;
$classname = $3;
$line =~ m/\b[A-Z]+_EXPORT\b/ or die "Class$classname in $headerfile should be exported with appropriate [LIB]_EXPORT macro. If this should not be available in python, wrap it in a `#ifndef SIP_RUN` block.";
};
$line = "$1$3";
$line = "$1 $3";
# Inheritance
if ($4){
my $m = $4;
Expand Down Expand Up @@ -272,6 +274,17 @@ sub processDoxygenLine
next;
}

# catch Q_DECLARE_FLAGS
if ( $line =~ m/^(\s*)Q_DECLARE_FLAGS\(\s*(.*?)\s*,\s*(.*?)\s*\)\s*$/ ){
$line = "$1typedef QFlags<$classname::$3> $2;\n";
$qflag_hash{"$classname::$2"} = "$classname::$3";
}
# catch Q_DECLARE_OPERATORS_FOR_FLAGS
if ( $line =~ m/^(\s*)Q_DECLARE_OPERATORS_FOR_FLAGS\(\s*(.*?)\s*\)\s*$/ ){
my $flag = $qflag_hash{$2};
$line = "$1QFlags<$flag> operator|($flag f1, QFlags<$flag> f2);\n";
}

do {no warnings 'uninitialized';
# remove keywords
$line =~ s/\s*override( SIP_\w+(\(.+\))?)?;/$1;/;
Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/sipifyheader.expected.sip
Expand Up @@ -62,6 +62,7 @@ class QgsSipifyHeader : QtClass<QVariant>
Success,
NoSuccess,
};
typedef QFlags<QgsSipifyHeader::MyEnum> Flags;

explicit QgsSipifyHeader();
%Docstring
Expand Down Expand Up @@ -177,6 +178,8 @@ A constructor with definition in header on several lines

}

QFlags<QgsSipifyHeader::MyEnum> operator|(QgsSipifyHeader::MyEnum f1, QFlags<QgsSipifyHeader::MyEnum> f2);


/************************************************************************
* This file has been generated automatically from *
Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/sipifyheader.h
Expand Up @@ -99,6 +99,7 @@ class CORE_EXPORT QgsSipifyHeader : public QtClass<QVariant>, private QgsBaseCla
Success = 0, //!< Edit operation was successful
NoSuccess = 1, //!< Edit operation resulted in an empty geometry
};
Q_DECLARE_FLAGS( Flags, MyEnum )

//! A constructor with definition in header
explicit QgsSipifyHeader()
Expand Down Expand Up @@ -219,5 +220,7 @@ class CORE_EXPORT ClassWithPrivateInheritanceOnly : private QgsBaseClass

}

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsSipifyHeader::Flags )


#endif

0 comments on commit 7db1913

Please sign in to comment.