From e8cf8c2f1c4265e4f16bd9555e1d496a84defe77 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Tue, 15 May 2018 17:37:18 -0400 Subject: [PATCH 1/4] [sipify] insert missing QMetaObject for gadget classes --- .../geometry/qgsabstractgeometry.sip.in | 3 +++ .../core/auto_generated/geometry/qgsgeometry.sip.in | 3 +++ python/core/auto_generated/geometry/qgspoint.sip.in | 3 +++ .../qgscoordinatereferencesystem.sip.in | 3 +++ python/core/auto_generated/qgsdatasourceuri.sip.in | 3 +++ python/core/auto_generated/qgsdefaultvalue.sip.in | 3 +++ python/core/auto_generated/qgsfeature.sip.in | 3 +++ python/core/auto_generated/qgsfield.sip.in | 3 +++ .../core/auto_generated/qgsfieldconstraints.sip.in | 3 +++ python/core/auto_generated/qgspointxy.sip.in | 3 +++ python/core/auto_generated/qgsrelation.sip.in | 3 +++ python/core/auto_generated/qgssnappingconfig.sip.in | 3 +++ python/core/auto_generated/qgstolerance.sip.in | 3 +++ python/core/auto_generated/qgsunittypes.sip.in | 3 +++ .../auto_generated/qgsvectorsimplifymethod.sip.in | 3 +++ .../auto_generated/raster/qgsrasterprojector.sip.in | 3 +++ scripts/sipify.pl | 12 ++++++++++-- 17 files changed, 58 insertions(+), 2 deletions(-) diff --git a/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in b/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in index dead46488dd..63347c975dc 100644 --- a/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in +++ b/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in @@ -25,6 +25,9 @@ class QgsAbstractGeometry %TypeHeaderCode #include "qgsabstractgeometry.h" %End + public: + static const QMetaObject staticMetaObject; + %ConvertToSubClassCode if ( qgsgeometry_cast( sipCpp ) != nullptr ) sipType = sipType_QgsPoint; diff --git a/python/core/auto_generated/geometry/qgsgeometry.sip.in b/python/core/auto_generated/geometry/qgsgeometry.sip.in index 0d1efa21678..b12fdc995f5 100644 --- a/python/core/auto_generated/geometry/qgsgeometry.sip.in +++ b/python/core/auto_generated/geometry/qgsgeometry.sip.in @@ -43,6 +43,9 @@ can be accessed via the geometry() method or set using the setGeometry() method. %TypeHeaderCode #include "qgsgeometry.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum OperationResult diff --git a/python/core/auto_generated/geometry/qgspoint.sip.in b/python/core/auto_generated/geometry/qgspoint.sip.in index 72901ba30d4..75459607a22 100644 --- a/python/core/auto_generated/geometry/qgspoint.sip.in +++ b/python/core/auto_generated/geometry/qgspoint.sip.in @@ -21,6 +21,9 @@ class QgsPoint: QgsAbstractGeometry %TypeHeaderCode #include "qgspoint.h" %End + public: + static const QMetaObject staticMetaObject; + public: QgsPoint( double x = 0.0, double y = 0.0, SIP_PYOBJECT z = Py_None, SIP_PYOBJECT m = Py_None, QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown ) [( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0, QgsWkbTypes::Type wkbType = QgsWkbTypes::Unknown )]; diff --git a/python/core/auto_generated/qgscoordinatereferencesystem.sip.in b/python/core/auto_generated/qgscoordinatereferencesystem.sip.in index e4c8251ba5e..60ea5572155 100644 --- a/python/core/auto_generated/qgscoordinatereferencesystem.sip.in +++ b/python/core/auto_generated/qgscoordinatereferencesystem.sip.in @@ -156,6 +156,9 @@ both flavors. %TypeHeaderCode #include "qgscoordinatereferencesystem.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum CrsType diff --git a/python/core/auto_generated/qgsdatasourceuri.sip.in b/python/core/auto_generated/qgsdatasourceuri.sip.in index e8575e0cff1..b58cd54176e 100644 --- a/python/core/auto_generated/qgsdatasourceuri.sip.in +++ b/python/core/auto_generated/qgsdatasourceuri.sip.in @@ -16,6 +16,9 @@ class QgsDataSourceUri %TypeHeaderCode #include "qgsdatasourceuri.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum SslMode { diff --git a/python/core/auto_generated/qgsdefaultvalue.sip.in b/python/core/auto_generated/qgsdefaultvalue.sip.in index 9ca357c323b..bec96336300 100644 --- a/python/core/auto_generated/qgsdefaultvalue.sip.in +++ b/python/core/auto_generated/qgsdefaultvalue.sip.in @@ -36,6 +36,9 @@ not set, the default value will only be used when a feature is created. %TypeHeaderCode #include "qgsdefaultvalue.h" %End + public: + static const QMetaObject staticMetaObject; + public: explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false ); diff --git a/python/core/auto_generated/qgsfeature.sip.in b/python/core/auto_generated/qgsfeature.sip.in index ea0adc2d081..25ebe8ee71f 100644 --- a/python/core/auto_generated/qgsfeature.sip.in +++ b/python/core/auto_generated/qgsfeature.sip.in @@ -33,6 +33,9 @@ geometry and a list of field/values attributes. #define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant)) #endif %End + public: + static const QMetaObject staticMetaObject; + public: SIP_PYOBJECT __iter__(); diff --git a/python/core/auto_generated/qgsfield.sip.in b/python/core/auto_generated/qgsfield.sip.in index 05204c58112..f4e02f3a8d3 100644 --- a/python/core/auto_generated/qgsfield.sip.in +++ b/python/core/auto_generated/qgsfield.sip.in @@ -27,6 +27,9 @@ length, and if applicable, precision. %TypeHeaderCode #include "qgsfield.h" %End + public: + static const QMetaObject staticMetaObject; + public: QgsField( const QString &name = QString(), diff --git a/python/core/auto_generated/qgsfieldconstraints.sip.in b/python/core/auto_generated/qgsfieldconstraints.sip.in index 3f2e5ee360f..56e2f18e4ae 100644 --- a/python/core/auto_generated/qgsfieldconstraints.sip.in +++ b/python/core/auto_generated/qgsfieldconstraints.sip.in @@ -21,6 +21,9 @@ Stores information about constraints which may be present on a field. %TypeHeaderCode #include "qgsfieldconstraints.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum Constraint diff --git a/python/core/auto_generated/qgspointxy.sip.in b/python/core/auto_generated/qgspointxy.sip.in index 486c34f1c6b..eada839f46f 100644 --- a/python/core/auto_generated/qgspointxy.sip.in +++ b/python/core/auto_generated/qgspointxy.sip.in @@ -27,6 +27,9 @@ supports Z and M values. %TypeHeaderCode #include "qgspointxy.h" %End + public: + static const QMetaObject staticMetaObject; + public: QgsPointXY(); diff --git a/python/core/auto_generated/qgsrelation.sip.in b/python/core/auto_generated/qgsrelation.sip.in index 61676e4c95e..ae33fd7dcf3 100644 --- a/python/core/auto_generated/qgsrelation.sip.in +++ b/python/core/auto_generated/qgsrelation.sip.in @@ -17,6 +17,9 @@ class QgsRelation %TypeHeaderCode #include "qgsrelation.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum RelationStrength diff --git a/python/core/auto_generated/qgssnappingconfig.sip.in b/python/core/auto_generated/qgssnappingconfig.sip.in index eeedd57d7c2..26a7b279c18 100644 --- a/python/core/auto_generated/qgssnappingconfig.sip.in +++ b/python/core/auto_generated/qgssnappingconfig.sip.in @@ -21,6 +21,9 @@ This is a container for configuration of the snapping of the project %TypeHeaderCode #include "qgssnappingconfig.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum SnappingMode diff --git a/python/core/auto_generated/qgstolerance.sip.in b/python/core/auto_generated/qgstolerance.sip.in index c02c3d123b3..bbcc49e5f67 100644 --- a/python/core/auto_generated/qgstolerance.sip.in +++ b/python/core/auto_generated/qgstolerance.sip.in @@ -19,6 +19,9 @@ This is the class is providing tolerance value in map unit values. %TypeHeaderCode #include "qgstolerance.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum UnitType diff --git a/python/core/auto_generated/qgsunittypes.sip.in b/python/core/auto_generated/qgsunittypes.sip.in index e300becc402..81b7d120d59 100644 --- a/python/core/auto_generated/qgsunittypes.sip.in +++ b/python/core/auto_generated/qgsunittypes.sip.in @@ -22,6 +22,9 @@ class QgsUnitTypes %TypeHeaderCode #include "qgsunittypes.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum DistanceUnit { diff --git a/python/core/auto_generated/qgsvectorsimplifymethod.sip.in b/python/core/auto_generated/qgsvectorsimplifymethod.sip.in index 1bbe467d1a0..f2528d1d61f 100644 --- a/python/core/auto_generated/qgsvectorsimplifymethod.sip.in +++ b/python/core/auto_generated/qgsvectorsimplifymethod.sip.in @@ -20,6 +20,9 @@ This class contains information how to simplify geometries fetched from a vector %TypeHeaderCode #include "qgsvectorsimplifymethod.h" %End + public: + static const QMetaObject staticMetaObject; + public: QgsVectorSimplifyMethod(); %Docstring diff --git a/python/core/auto_generated/raster/qgsrasterprojector.sip.in b/python/core/auto_generated/raster/qgsrasterprojector.sip.in index 9fc855528c0..6259939fe23 100644 --- a/python/core/auto_generated/raster/qgsrasterprojector.sip.in +++ b/python/core/auto_generated/raster/qgsrasterprojector.sip.in @@ -24,6 +24,9 @@ which are used to calculate affine transformation matrices. %TypeHeaderCode #include "qgsrasterprojector.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum Precision diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 02eeacd6c53..5e95df8ccba 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -599,8 +599,16 @@ while ($LINE_IDX < $LINE_COUNT){ if ( $LINE =~ m/^\s*friend class \w+/ ){ next; } - # Skip Q_OBJECT, Q_PROPERTY, Q_ENUM, Q_GADGET etc. - if ($LINE =~ m/^\s*Q_(OBJECT|ENUMS|ENUM|FLAG|PROPERTY|GADGET|DECLARE_METATYPE|DECLARE_TYPEINFO|NOWARN_DEPRECATED_(PUSH|POP))\b.*?$/){ + + # insert metaoject for Q_GADGET + if ($LINE =~ m/^\s*Q_GADGET\b.*?$/){ + write_output("HCE", " public:\n"); + write_output("HCE", " static const QMetaObject staticMetaObject;\n\n"); + next; + } + + # Skip Q_OBJECT, Q_PROPERTY, Q_ENUM etc. + if ($LINE =~ m/^\s*Q_(OBJECT|ENUMS|ENUM|FLAG|PROPERTY|DECLARE_METATYPE|DECLARE_TYPEINFO|NOWARN_DEPRECATED_(PUSH|POP))\b.*?$/){ next; } From 5790bbcad601e29adc75a62d521fdc291417a320 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Wed, 16 May 2018 07:31:22 -0400 Subject: [PATCH 2/4] fix QgsAbstractGeometry Q_GADGET position --- .../core/auto_generated/geometry/qgsabstractgeometry.sip.in | 6 +++--- src/core/geometry/qgsabstractgeometry.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in b/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in index 63347c975dc..c5e0be153de 100644 --- a/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in +++ b/python/core/auto_generated/geometry/qgsabstractgeometry.sip.in @@ -25,9 +25,6 @@ class QgsAbstractGeometry %TypeHeaderCode #include "qgsabstractgeometry.h" %End - public: - static const QMetaObject staticMetaObject; - %ConvertToSubClassCode if ( qgsgeometry_cast( sipCpp ) != nullptr ) sipType = sipType_QgsPoint; @@ -58,6 +55,9 @@ class QgsAbstractGeometry else sipType = 0; %End + public: + static const QMetaObject staticMetaObject; + public: enum SegmentationToleranceType diff --git a/src/core/geometry/qgsabstractgeometry.h b/src/core/geometry/qgsabstractgeometry.h index 9bc4ed415bd..4a637d4ea8f 100644 --- a/src/core/geometry/qgsabstractgeometry.h +++ b/src/core/geometry/qgsabstractgeometry.h @@ -52,7 +52,6 @@ typedef QVector< QVector< QVector< QgsPoint > > > QgsCoordinateSequence; */ class CORE_EXPORT QgsAbstractGeometry { - Q_GADGET #ifdef SIP_RUN SIP_CONVERT_TO_SUBCLASS_CODE @@ -86,6 +85,9 @@ class CORE_EXPORT QgsAbstractGeometry sipType = 0; SIP_END #endif + + Q_GADGET + public: //! Segmentation tolerance as maximum angle or maximum difference between approximation and circle From 95ecea897a85f7aebe7db8f9e1563536ac0866df Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Wed, 16 May 2018 11:29:28 -0400 Subject: [PATCH 3/4] move additions from top __init__ to core.__init__ --- python/__init__.py | 22 ---------------------- python/core/__init__.py | 24 ++++++++++++++---------- python/core/additions/qgsfeature.py | 7 +++++++ python/core/additions/qgsgeometry.py | 7 +++++++ 4 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 python/core/additions/qgsfeature.py diff --git a/python/__init__.py b/python/__init__.py index 0cedfe0ca71..b0efd4a6288 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -69,25 +69,3 @@ if os.name == 'nt': from qgis.PyQt import QtCore -from qgis.core import QgsFeature, QgsGeometry - - -def mapping_feature(feature): - geom = feature.geometry() - properties = {} - fields = [field.name() for field in feature.fields()] - properties = dict(list(zip(fields, feature.attributes()))) - return {'type': 'Feature', - 'properties': properties, - 'geometry': geom.__geo_interface__} - - -def mapping_geometry(geometry): - geo = geometry.asJson() - # We have to use eval because exportToGeoJSON() gives us - # back a string that looks like a dictionary. - return eval(geo) - - -QgsFeature.__geo_interface__ = property(mapping_feature) -QgsGeometry.__geo_interface__ = property(mapping_geometry) diff --git a/python/core/__init__.py b/python/core/__init__.py index 765bb9d68c6..1474e3b9570 100644 --- a/python/core/__init__.py +++ b/python/core/__init__.py @@ -26,22 +26,26 @@ __revision__ = '$Format:%H$' from qgis.PyQt.QtCore import NULL from qgis._core import * -from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory -from .additions.projectdirtyblocker import ProjectDirtyBlocker -from .additions.qgstaskwrapper import QgsTaskWrapper -from .additions.qgsfunction import register_function, qgsfunction from .additions.edit import edit, QgsEditError from .additions.fromfunction import fromFunction from .additions.processing import processing_output_layer_repr, processing_source_repr -from .additions.qgsgeometry import _geometryNonZero +from .additions.projectdirtyblocker import ProjectDirtyBlocker from .additions.qgsdefaultvalue import _isValid +from .additions.qgsfeature import mapping_feature +from .additions.qgsfunction import register_function, qgsfunction +from .additions.qgsgeometry import _geometryNonZero, mapping_geometry +from .additions.qgstaskwrapper import QgsTaskWrapper +from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory # Injections into classes -QgsGeometry.__nonzero__ = _geometryNonZero -QgsGeometry.__bool__ = _geometryNonZero QgsDefaultValue.__bool__ = _isValid -QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory -QgsProject.blockDirtying = ProjectDirtyBlocker -QgsTask.fromFunction = fromFunction +QgsFeature.__geo_interface__ = property(mapping_feature) +QgsGeometry.__bool__ = _geometryNonZero +QgsGeometry.__geo_interface__ = property(mapping_geometry) +QgsGeometry.__nonzero__ = _geometryNonZero QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr +QgsProject.blockDirtying = ProjectDirtyBlocker +QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory +QgsTask.fromFunction = fromFunction +QgsTolerance.UnitType.parentClass = QgsTolerance diff --git a/python/core/additions/qgsfeature.py b/python/core/additions/qgsfeature.py new file mode 100644 index 00000000000..49f15e1cc49 --- /dev/null +++ b/python/core/additions/qgsfeature.py @@ -0,0 +1,7 @@ +def mapping_feature(feature): + geom = feature.geometry() + fields = [field.name() for field in feature.fields()] + properties = dict(list(zip(fields, feature.attributes()))) + return {'type': 'Feature', + 'properties': properties, + 'geometry': geom.__geo_interface__} diff --git a/python/core/additions/qgsgeometry.py b/python/core/additions/qgsgeometry.py index cc25a0fffd5..59f3dd1ea06 100644 --- a/python/core/additions/qgsgeometry.py +++ b/python/core/additions/qgsgeometry.py @@ -20,3 +20,10 @@ def _geometryNonZero(self): return not self.isEmpty() + + +def mapping_geometry(geometry): + geo = geometry.asJson() + # We have to use eval because exportToGeoJSON() gives us + # back a string that looks like a dictionary. + return eval(geo) From 2abcfa23b8b0948bacd9ba427bb8df76aad1d7f6 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Wed, 16 May 2018 14:25:01 -0400 Subject: [PATCH 4/4] do not add static QMetaObject to QgsDefaultValue it has no Q_ENUM so no need for now I do not understand while it doesn't compile though --- python/core/__init__.py | 1 - python/core/auto_generated/qgsdefaultvalue.sip.in | 3 --- scripts/sipify.pl | 6 ++++-- src/core/qgsdefaultvalue.h | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/python/core/__init__.py b/python/core/__init__.py index 1474e3b9570..759b5410ec2 100644 --- a/python/core/__init__.py +++ b/python/core/__init__.py @@ -48,4 +48,3 @@ QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr QgsProject.blockDirtying = ProjectDirtyBlocker QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory QgsTask.fromFunction = fromFunction -QgsTolerance.UnitType.parentClass = QgsTolerance diff --git a/python/core/auto_generated/qgsdefaultvalue.sip.in b/python/core/auto_generated/qgsdefaultvalue.sip.in index bec96336300..9ca357c323b 100644 --- a/python/core/auto_generated/qgsdefaultvalue.sip.in +++ b/python/core/auto_generated/qgsdefaultvalue.sip.in @@ -36,9 +36,6 @@ not set, the default value will only be used when a feature is created. %TypeHeaderCode #include "qgsdefaultvalue.h" %End - public: - static const QMetaObject staticMetaObject; - public: explicit QgsDefaultValue( const QString &expression = QString(), bool applyOnUpdate = false ); diff --git a/scripts/sipify.pl b/scripts/sipify.pl index 5e95df8ccba..5bd928b06f2 100755 --- a/scripts/sipify.pl +++ b/scripts/sipify.pl @@ -602,8 +602,10 @@ while ($LINE_IDX < $LINE_COUNT){ # insert metaoject for Q_GADGET if ($LINE =~ m/^\s*Q_GADGET\b.*?$/){ - write_output("HCE", " public:\n"); - write_output("HCE", " static const QMetaObject staticMetaObject;\n\n"); + if ($LINE !~ m/SIP_SKIP/){ + write_output("HCE", " public:\n"); + write_output("HCE", " static const QMetaObject staticMetaObject;\n\n"); + } next; } diff --git a/src/core/qgsdefaultvalue.h b/src/core/qgsdefaultvalue.h index c7000426e27..5889e930caa 100644 --- a/src/core/qgsdefaultvalue.h +++ b/src/core/qgsdefaultvalue.h @@ -17,6 +17,7 @@ #define QGSDEFAULTVALUE_H #include "qgis_core.h" +#include "qgis_sip.h" #include #include @@ -46,7 +47,7 @@ */ class CORE_EXPORT QgsDefaultValue { - Q_GADGET + Q_GADGET SIP_SKIP Q_PROPERTY( QString expression READ expression WRITE setExpression ) Q_PROPERTY( bool applyOnUpdate READ applyOnUpdate WRITE setApplyOnUpdate )