Skip to content

Commit bae59b9

Browse files
committedMar 7, 2017
Add (failing) test to ensure that attribute table doesn't fetch
geometry by default (because performance) On behalf of Faunalia, sponsored by ENEL (cherry-picked from acaf97c)
1 parent 9bb0c84 commit bae59b9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎tests/src/app/testqgsattributetable.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TestQgsAttributeTable : public QObject
4040
void cleanup() {} // will be called after every testfunction.
4141
void testFieldCalculation();
4242
void testFieldCalculationArea();
43+
void testNoGeom();
4344

4445
private:
4546
QgisApp * mQgisApp;
@@ -59,6 +60,13 @@ void TestQgsAttributeTable::initTestCase()
5960
QgsApplication::init();
6061
QgsApplication::initQgis();
6162
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 );
6270
}
6371

6472
//runs after all tests
@@ -168,5 +176,25 @@ void TestQgsAttributeTable::testFieldCalculationArea()
168176
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
169177
}
170178

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+
171199
QTEST_MAIN( TestQgsAttributeTable )
172200
#include "testqgsattributetable.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.