Skip to content
Permalink
Browse files
Handle Q_DECLARE_FLAGS and Q_DECLARE_OPERATORS_FOR_FLAGS in sipify
  • Loading branch information
nyalldawson committed Apr 3, 2017
1 parent 5542444 commit 7db1913c077435c40d6806db4d95b71311fcaa6d
Showing with 22 additions and 3 deletions.
  1. +16 −3 scripts/sipify.pl
  2. +3 −0 tests/scripts/sipifyheader.expected.sip
  3. +3 −0 tests/scripts/sipifyheader.h
@@ -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";
@@ -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;
@@ -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;/;
@@ -62,6 +62,7 @@ class QgsSipifyHeader : QtClass<QVariant>
Success,
NoSuccess,
};
typedef QFlags<QgsSipifyHeader::MyEnum> Flags;

explicit QgsSipifyHeader();
%Docstring
@@ -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 *
@@ -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()
@@ -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.