mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
create Python __repr__ methods for QgsPoint and QgsPointXY
This commit is contained in:
parent
97726d6fbc
commit
ac4f508c13
python/core
scripts
src/core
2
python/core/auto_additions/qgspoint.py
Normal file
2
python/core/auto_additions/qgspoint.py
Normal file
@ -0,0 +1,2 @@
|
||||
# The following has been generated automatically from src/core/geometry/qgspoint.h
|
||||
QgsPoint.__repr__ = lambda self: '<QgsPoint {}>'.format(self.asWkt())
|
2
python/core/auto_additions/qgspointxy.py
Normal file
2
python/core/auto_additions/qgspointxy.py
Normal file
@ -0,0 +1,2 @@
|
||||
# The following has been generated automatically from src/core/qgspointxy.h
|
||||
QgsPointXY.__repr__ = lambda self: '<QgsPointXY {}>'.format(self.toString())
|
@ -426,6 +426,7 @@ Angle undefined. Always returns 0.0
|
||||
virtual QgsPoint *createEmptyWithSameType() const /Factory/;
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual int childCount() const;
|
||||
|
@ -122,6 +122,7 @@ Returns a string representation of the point (x, y) with a preset ``precision``.
|
||||
If ``precision`` is -1, then a default precision will be used.
|
||||
%End
|
||||
|
||||
|
||||
QString asWkt() const;
|
||||
%Docstring
|
||||
Returns the well known text representation for the point (e.g. "POINT(x y)").
|
||||
|
@ -694,7 +694,7 @@ while ($LINE_IDX < $LINE_COUNT){
|
||||
}
|
||||
|
||||
# SIP_SKIP
|
||||
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_OPERATOR_/ ){
|
||||
if ( $LINE =~ m/SIP_SKIP|SIP_PYTHON_SPECIAL_/ ){
|
||||
dbg_info('SIP SKIP!');
|
||||
# if multiline definition, remove previous lines
|
||||
if ( $MULTILINE_DEFINITION != MULTILINE_NO){
|
||||
@ -711,9 +711,18 @@ while ($LINE_IDX < $LINE_COUNT){
|
||||
detect_and_remove_following_body_or_initializerlist();
|
||||
# line skipped, go to next iteration
|
||||
|
||||
if ($LINE =~ m/SIP_PYTHON_OPERATOR_(\w+)\(\s*(\w+)\s*\)/ ){
|
||||
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: self.$2()";
|
||||
dbg_info("PYTHON OPERATOR $pyop");
|
||||
if ($LINE =~ m/SIP_PYTHON_SPECIAL_(\w+)\(\s*(".*"|\w+)\s*\)/ ){
|
||||
my $method_or_code = $2;
|
||||
dbg_info("PYTHON SPECIAL method or code: $method_or_code");
|
||||
my $pyop = "${ACTUAL_CLASS}.__" . lc($1) . "__ = lambda self: ";
|
||||
if ( $method_or_code =~ m/^"(.*)"$/ ){
|
||||
$pyop .= $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pyop .= "self.${method_or_code}()";
|
||||
}
|
||||
dbg_info("PYTHON SPECIAL $pyop");
|
||||
if ($python_output ne ''){
|
||||
push @OUTPUT_PYTHON, "$pyop\n";
|
||||
}
|
||||
|
@ -495,6 +495,8 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry
|
||||
|
||||
QgsPoint *createEmptyWithSameType() const override SIP_FACTORY;
|
||||
|
||||
SIP_PYTHON_SPECIAL_REPR( "'<QgsPoint {}>'.format(self.asWkt())" )
|
||||
|
||||
protected:
|
||||
|
||||
int childCount() const override;
|
||||
|
@ -198,9 +198,19 @@
|
||||
#define SIP_DOC_TEMPLATE
|
||||
|
||||
/*
|
||||
* Define the __bool__ operator using the given method
|
||||
* sipify.pl will take care of creating the injection in qgis/{module}/__init__.py
|
||||
* Define Python special method (bool, repr, etc.) using the given method or code
|
||||
* sipify.pl will create a dedicated python file named according to the class
|
||||
* and located in python/{module}/auto_additions/{classname}.py
|
||||
* a simple method name can be provided (e.g. isValid) and sipify will create the proper code
|
||||
* or some Python code can be provided:
|
||||
*
|
||||
* SIP_PYTHON_SPECIAL_BOOL( isValid )
|
||||
* => sipify => MyClass.__bool__ = lambda self: self.isValid()
|
||||
*
|
||||
* SIP_PYTHON_SPECIAL_REPR( "'<MyClass {}>'format(self.toString())'" )
|
||||
* => sipify => MyClass.__repr__ = lambda self: '<MyClass {}>'format(self.toString())'
|
||||
*/
|
||||
#define SIP_PYTHON_OPERATOR_BOOL(method)
|
||||
#define SIP_PYTHON_SPECIAL_BOOL(method_or_code)
|
||||
#define SIP_PYTHON_SPECIAL_REPR(method_or_code)
|
||||
|
||||
#endif // QGIS_SIP_H
|
||||
|
@ -95,7 +95,7 @@ class CORE_EXPORT QgsDefaultValue
|
||||
* Checks if a default value is set. Alias for isValid().
|
||||
* \returns false if the expression is a null string.
|
||||
*/
|
||||
operator bool() const SIP_PYTHON_OPERATOR_BOOL( isValid );
|
||||
operator bool() const SIP_PYTHON_SPECIAL_BOOL( isValid );
|
||||
|
||||
private:
|
||||
QString mExpression;
|
||||
|
@ -156,6 +156,8 @@ class CORE_EXPORT QgsPointXY
|
||||
*/
|
||||
QString toString( int precision = -1 ) const;
|
||||
|
||||
SIP_PYTHON_SPECIAL_REPR( "'<QgsPointXY {}>'.format(self.toString())" )
|
||||
|
||||
/**
|
||||
* Returns the well known text representation for the point (e.g. "POINT(x y)").
|
||||
* The wkt is created without an SRID.
|
||||
|
Loading…
x
Reference in New Issue
Block a user