Skip to content

Commit

Permalink
First test with Qvariant QgsGeometry*
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Nov 14, 2012
1 parent 4ca2160 commit 2b31660
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -757,6 +757,37 @@ static QVariant fcnYat( const QVariantList& values, QgsFeature* f, QgsExpression
else
return QVariant();
}
static QVariant fcnGeometry( const QVariantList& , QgsFeature* f, QgsExpression* )
{
QgsGeometry* geom = f->geometry();
if ( geom )
return QVariant::fromValue( geom );
else
return QVariant();
}
static QVariant fcnGeomFromWKT( const QVariantList& values, QgsFeature*, QgsExpression* parent )
{
QString wkt = getStringValue( values.at( 0 ), parent );
QgsGeometry* geom = QgsGeometry::fromWkt( wkt );
if ( geom )
return QVariant::fromValue( geom );
else
return QVariant();
}
static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExpression* parent )
{
QDomDocument doc;
QString errorMsg;
QString gml = getStringValue( values.at( 0 ), parent );
if ( !doc.setContent( gml, true, &errorMsg ) )
return QVariant();

QgsGeometry* geom = QgsGeometry::fromGML2( doc.documentElement() );
if ( geom )
return QVariant::fromValue( geom );
else
return QVariant();
}

static QVariant fcnGeomArea( const QVariantList& , QgsFeature* f, QgsExpression* parent )
{
Expand Down Expand Up @@ -932,6 +963,9 @@ const QList<QgsExpression::Function*> &QgsExpression::Functions()
<< new StaticFunction( "$perimeter", 0, fcnGeomPerimeter, QObject::tr( "Geometry" ), "", true )
<< new StaticFunction( "$x", 0, fcnX, QObject::tr( "Geometry" ), "", true )
<< new StaticFunction( "$y", 0, fcnY, QObject::tr( "Geometry" ), "" , true )
<< new StaticFunction( "$geometry", 0, fcnGeometry, QObject::tr( "Geometry" ), "" , true )
<< new StaticFunction( "GeomFromWKT", 1, fcnGeomFromWKT, QObject::tr( "Geometry" ) )
<< new StaticFunction( "GeomFromGML2", 1, fcnGeomFromGML2, QObject::tr( "Geometry" ) )
<< new StaticFunction( "$rownum", 0, fcnRowNumber, QObject::tr( "Record" ) )
<< new StaticFunction( "$id", 0, fcnFeatureId, QObject::tr( "Record" ) )
<< new StaticFunction( "$scale", 0, fcnScale, QObject::tr( "Record" ) )
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsexpression.h
Expand Up @@ -434,7 +434,7 @@ class CORE_EXPORT QgsExpression
{
public:
NodeSpatialOperator( SpatialOperator op, QgsGeometry* opGeom ) : mOp( op ), mOpGeometry( 0 ) { if ( opGeom ) mOpGeometry = opGeom; }
~NodeSpatialOperator() { delete mOpGeometry; }
~NodeSpatialOperator() { }

virtual bool prepare( QgsExpression* parent, const QgsFieldMap& fields );
virtual QVariant eval( QgsExpression* parent, QgsFeature* f );
Expand Down Expand Up @@ -630,6 +630,7 @@ class CORE_EXPORT QgsExpression
QgsDistanceArea* mCalc;
};

Q_DECLARE_METATYPE( QgsExpression::Interval )
Q_DECLARE_METATYPE( QgsExpression::Interval );
Q_DECLARE_METATYPE( QgsGeometry * );

#endif // QGSEXPRESSION_H

0 comments on commit 2b31660

Please sign in to comment.