Skip to content
Permalink
Browse files

Merge pull request #7002 from 3nids/sip_metoobject

[sipify] insert missing QMetaObject for gadget classes
  • Loading branch information
3nids committed May 17, 2018
2 parents 9a79fc7 + 2abcfa2 commit 1a879b18a19754bd516e761024530d19f587f638
@@ -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)
@@ -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
@@ -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__}
@@ -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)
@@ -55,6 +55,9 @@ class QgsAbstractGeometry
else
sipType = 0;
%End
public:
static const QMetaObject staticMetaObject;

public:

enum SegmentationToleranceType
@@ -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
@@ -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 )];
@@ -156,6 +156,9 @@ both flavors.
%TypeHeaderCode
#include "qgscoordinatereferencesystem.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum CrsType
@@ -16,6 +16,9 @@ class QgsDataSourceUri
%TypeHeaderCode
#include "qgsdatasourceuri.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
enum SslMode
{
@@ -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__();
@@ -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(),
@@ -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
@@ -27,6 +27,9 @@ supports Z and M values.
%TypeHeaderCode
#include "qgspointxy.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
QgsPointXY();

@@ -17,6 +17,9 @@ class QgsRelation
%TypeHeaderCode
#include "qgsrelation.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum RelationStrength
@@ -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
@@ -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
@@ -22,6 +22,9 @@ class QgsUnitTypes
%TypeHeaderCode
#include "qgsunittypes.h"
%End
public:
static const QMetaObject staticMetaObject;

public:
enum DistanceUnit
{
@@ -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
@@ -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
@@ -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;
}

@@ -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
@@ -17,6 +17,7 @@
#define QGSDEFAULTVALUE_H

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

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

0 comments on commit 1a879b1

Please sign in to comment.
You can’t perform that action at this time.