Skip to content

Commit

Permalink
Merge pull request #7002 from 3nids/sip_metoobject
Browse files Browse the repository at this point in the history
[sipify] insert missing QMetaObject for gadget classes
  • Loading branch information
3nids committed May 17, 2018
2 parents 9a79fc7 + 2abcfa2 commit 1a879b1
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 36 deletions.
22 changes: 0 additions & 22 deletions python/__init__.py
Expand Up @@ -69,25 +69,3 @@ def setupenv():


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)
23 changes: 13 additions & 10 deletions python/core/__init__.py
Expand Up @@ -26,22 +26,25 @@
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
7 changes: 7 additions & 0 deletions 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__}
7 changes: 7 additions & 0 deletions python/core/additions/qgsgeometry.py
Expand Up @@ -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)
Expand Up @@ -55,6 +55,9 @@ class QgsAbstractGeometry
else
sipType = 0;
%End
public:
static const QMetaObject staticMetaObject;

public:

enum SegmentationToleranceType
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/geometry/qgspoint.sip.in
Expand Up @@ -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 )];
Expand Down
Expand Up @@ -156,6 +156,9 @@ both flavors.
%TypeHeaderCode
#include "qgscoordinatereferencesystem.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum CrsType
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsdatasourceuri.sip.in
Expand Up @@ -16,6 +16,9 @@ class QgsDataSourceUri
%TypeHeaderCode
#include "qgsdatasourceuri.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
enum SslMode
{
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsfeature.sip.in
Expand Up @@ -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__();
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsfield.sip.in
Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsfieldconstraints.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgspointxy.sip.in
Expand Up @@ -27,6 +27,9 @@ supports Z and M values.
%TypeHeaderCode
#include "qgspointxy.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
QgsPointXY();

Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsrelation.sip.in
Expand Up @@ -17,6 +17,9 @@ class QgsRelation
%TypeHeaderCode
#include "qgsrelation.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum RelationStrength
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgssnappingconfig.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgstolerance.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsunittypes.sip.in
Expand Up @@ -22,6 +22,9 @@ class QgsUnitTypes
%TypeHeaderCode
#include "qgsunittypes.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
enum DistanceUnit
{
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/qgsvectorsimplifymethod.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/auto_generated/raster/qgsrasterprojector.sip.in
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions scripts/sipify.pl
Expand Up @@ -599,8 +599,18 @@ sub detect_non_method_member{
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.*?$/){
if ($LINE !~ m/SIP_SKIP/){
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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/geometry/qgsabstractgeometry.h
Expand Up @@ -52,7 +52,6 @@ typedef QVector< QVector< QVector< QgsPoint > > > QgsCoordinateSequence;
*/
class CORE_EXPORT QgsAbstractGeometry
{
Q_GADGET

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsdefaultvalue.h
Expand Up @@ -17,6 +17,7 @@
#define QGSDEFAULTVALUE_H

#include "qgis_core.h"
#include "qgis_sip.h"

#include <QString>
#include <QObject>
Expand Down Expand Up @@ -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 )
Expand Down

0 comments on commit 1a879b1

Please sign in to comment.