forked from opengisch/QField
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_featuremodel.cpp
More file actions
61 lines (50 loc) · 3.41 KB
/
test_featuremodel.cpp
File metadata and controls
61 lines (50 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***************************************************************************
test_featuremodel.h
--------------------
begin : Oct 2022
copyright : (C) 2022 by Mathieu Pellerin
email : mathieu@opengis.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "appexpressioncontextscopesgenerator.h"
#include "catch2.h"
#include "featuremodel.h"
#include "gnsspositioninformation.h"
#include <QAbstractItemModelTester>
#include <qgsvectorlayer.h>
TEST_CASE( "FeatureModel" )
{
std::unique_ptr<QgsVectorLayer> layer = std::make_unique<QgsVectorLayer>( QStringLiteral( "Point?crs=EPSG:4326&field=name:text&field=horizontal_accuracy:double(12,6)&field=vertical_accuracy:double(12,6)" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) );
layer->setDefaultValueDefinition( 1, QgsDefaultValue( QStringLiteral( "@position_horizontal_accuracy" ), true ) );
layer->setDefaultValueDefinition( 2, QgsDefaultValue( QStringLiteral( "@position_vertical_accuracy" ), true ) );
std::unique_ptr<FeatureModel> featureModel = std::make_unique<FeatureModel>();
std::unique_ptr<AppExpressionContextScopesGenerator> appExpressionContextScopesGenerator = std::make_unique<AppExpressionContextScopesGenerator>();
featureModel->setAppExpressionContextScopesGenerator( appExpressionContextScopesGenerator.get() );
GnssPositionInformation position( 1.1, 2.2, 50.0, 50.0, 0.0, QList<QgsSatelliteInfo>(), 0, 0, 0, 5.5, 10.5, QDateTime(), QChar(), 0, 100 );
featureModel->setCurrentLayer( layer.get() );
featureModel->appExpressionContextScopesGenerator()->setPositionInformation( position );
featureModel->appExpressionContextScopesGenerator()->setPositionLocked( true );
featureModel->resetFeature();
featureModel->resetAttributes();
featureModel->setData( featureModel->index( 0, 0 ), QStringLiteral( "created" ), FeatureModel::AttributeValue );
featureModel->create();
QgsFeature feature = featureModel->feature();
REQUIRE( feature.attribute( 0 ).toString() == QStringLiteral( "created" ) );
REQUIRE( feature.attribute( 1 ).toDouble() == 5.5 );
REQUIRE( feature.attribute( 2 ).toDouble() == 10.5 );
featureModel->setData( featureModel->index( 0, 0 ), QStringLiteral( "updated" ), FeatureModel::AttributeValue );
featureModel->save();
feature = featureModel->feature();
REQUIRE( feature.attribute( 0 ).toString() == QStringLiteral( "updated" ) );
REQUIRE( feature.attribute( 1 ).toDouble() == 5.5 );
REQUIRE( feature.attribute( 2 ).toDouble() == 10.5 );
std::unique_ptr<FeatureModel> modelTest = std::make_unique<FeatureModel>();
std::unique_ptr<QAbstractItemModelTester> modelTester = std::make_unique<QAbstractItemModelTester>( modelTest.get(), QAbstractItemModelTester::FailureReportingMode::Fatal );
}