Skip to content

Commit f31b739

Browse files
committed
Allow to pass on position and cloud user information scops when creating features using FeatureUtils.createFeature() function
1 parent 5b67281 commit f31b739

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/core/utils/featureutils.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* *
1515
***************************************************************************/
1616

17+
#include "expressioncontextutils.h"
1718
#include "featureutils.h"
1819
#include "qgsquickmapsettings.h"
1920

@@ -35,11 +36,19 @@ QgsFeature FeatureUtils::createBlankFeature( const QgsFields &fields, const QgsG
3536
return feature;
3637
}
3738

38-
QgsFeature FeatureUtils::createFeature( QgsVectorLayer *layer, const QgsGeometry &geometry )
39+
QgsFeature FeatureUtils::createFeature( QgsVectorLayer *layer, const QgsGeometry &geometry, const GnssPositionInformation &positionInformation, const CloudUserInformation &cloudUserInformation )
3940
{
4041
QgsFeature feature;
4142
QgsAttributeMap attributes;
4243
QgsExpressionContext context = layer->createExpressionContext();
44+
if ( positionInformation.isValid() )
45+
{
46+
context << ExpressionContextUtils::positionScope( positionInformation, false );
47+
}
48+
if ( !cloudUserInformation.isEmpty() )
49+
{
50+
context << ExpressionContextUtils::cloudUserScope( cloudUserInformation );
51+
}
4352
feature = QgsVectorLayerUtils::createFeature( layer, geometry, attributes, &context );
4453
return feature;
4554
}

src/core/utils/featureutils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#ifndef FEATUREUTILS_H
1717
#define FEATUREUTILS_H
1818

19+
#include "gnsspositioninformation.h"
1920
#include "qfield_core_export.h"
21+
#include "qfieldcloudutils.h"
2022

2123
#include <QObject>
2224
#include <qgsfeature.h>
@@ -42,7 +44,7 @@ class QFIELD_CORE_EXPORT FeatureUtils : public QObject
4244
/**
4345
* Returns a new feature with its fields set to default values.
4446
*/
45-
static Q_INVOKABLE QgsFeature createFeature( QgsVectorLayer *layer, const QgsGeometry &geometry = QgsGeometry() );
47+
static Q_INVOKABLE QgsFeature createFeature( QgsVectorLayer *layer, const QgsGeometry &geometry = QgsGeometry(), const GnssPositionInformation &positionInformation = GnssPositionInformation(), const CloudUserInformation &cloudUserInformation = CloudUserInformation() );
4648

4749
/**
4850
* Returns the display name of a given feature.

src/qml/qgismobileapp.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,7 @@ ApplicationWindow {
39023902

39033903
ProjectInfo {
39043904
id: projectInfo
3905+
objectName: "projectInfo"
39053906

39063907
mapSettings: mapCanvas.mapSettings
39073908
layerTree: dashBoard.layerTree

0 commit comments

Comments
 (0)