@@ -40,6 +40,7 @@ class TestQgsAttributeTable : public QObject
40
40
void cleanup () {} // will be called after every testfunction.
41
41
void testFieldCalculation ();
42
42
void testFieldCalculationArea ();
43
+ void testNoGeom ();
43
44
44
45
private:
45
46
QgisApp * mQgisApp ;
@@ -59,6 +60,13 @@ void TestQgsAttributeTable::initTestCase()
59
60
QgsApplication::init ();
60
61
QgsApplication::initQgis ();
61
62
mQgisApp = new QgisApp ();
63
+
64
+ // setup the test QSettings environment
65
+ QCoreApplication::setOrganizationName ( QString ( " QGIS" ) );
66
+ QCoreApplication::setOrganizationDomain ( QString ( " qgis.org" ) );
67
+ QCoreApplication::setApplicationName ( QString ( " QGIS-TEST" ) );
68
+
69
+ QSettings ().setValue ( QString ( " /qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
62
70
}
63
71
64
72
// runs after all tests
@@ -168,5 +176,25 @@ void TestQgsAttributeTable::testFieldCalculationArea()
168
176
QVERIFY ( qgsDoubleNear ( f.attribute ( " col1" ).toDouble (), expected, 0.001 ) );
169
177
}
170
178
179
+ void TestQgsAttributeTable::testNoGeom ()
180
+ {
181
+ // test that by default the attribute table DOESN'T fetch geometries (because performance)
182
+ std::unique_ptr< QgsVectorLayer> tempLayer ( new QgsVectorLayer ( QString ( " LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QString ( " vl" ), QString ( " memory" ) ) );
183
+ QVERIFY ( tempLayer->isValid () );
184
+
185
+ QSettings ().setValue ( QString ( " /qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
186
+ std::unique_ptr< QgsAttributeTableDialog > dlg ( new QgsAttributeTableDialog ( tempLayer.get () ) );
187
+
188
+ QVERIFY ( !dlg->mMainView ->masterModel ()->layerCache ()->cacheGeometry () );
189
+ QVERIFY ( dlg->mMainView ->masterModel ()->request ().flags () & QgsFeatureRequest::NoGeometry );
190
+
191
+ // but if we are requesting only visible features, then geometry must be fetched...
192
+
193
+ QSettings ().setValue ( QString ( " /qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowVisible );
194
+ dlg.reset ( new QgsAttributeTableDialog ( tempLayer.get () ) );
195
+ QVERIFY ( dlg->mMainView ->masterModel ()->layerCache ()->cacheGeometry () );
196
+ QVERIFY ( !( dlg->mMainView ->masterModel ()->request ().flags () & QgsFeatureRequest::NoGeometry ) );
197
+ }
198
+
171
199
QTEST_MAIN ( TestQgsAttributeTable )
172
200
#include " testqgsattributetable.moc"
0 commit comments