Skip to content
Permalink
Browse files

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)
  • Loading branch information
nyalldawson committed Mar 7, 2017
1 parent 9bb0c84 commit bae59b90b0e49238e5dbde1de440ef5bedc40f4f
Showing with 28 additions and 0 deletions.
  1. +28 −0 tests/src/app/testqgsattributetable.cpp
@@ -40,6 +40,7 @@ class TestQgsAttributeTable : public QObject
void cleanup() {} // will be called after every testfunction.
void testFieldCalculation();
void testFieldCalculationArea();
void testNoGeom();

private:
QgisApp * mQgisApp;
@@ -59,6 +60,13 @@ void TestQgsAttributeTable::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();
mQgisApp = new QgisApp();

// setup the test QSettings environment
QCoreApplication::setOrganizationName( QString( "QGIS" ) );
QCoreApplication::setOrganizationDomain( QString( "qgis.org" ) );
QCoreApplication::setApplicationName( QString( "QGIS-TEST" ) );

QSettings().setValue( QString( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
}

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

void TestQgsAttributeTable::testNoGeom()
{
//test that by default the attribute table DOESN'T fetch geometries (because performance)
std::unique_ptr< QgsVectorLayer> tempLayer( new QgsVectorLayer( QString( "LineString?crs=epsg:3111&field=pk:int&field=col1:double" ), QString( "vl" ), QString( "memory" ) ) );
QVERIFY( tempLayer->isValid() );

QSettings().setValue( QString( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
std::unique_ptr< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.get() ) );

QVERIFY( !dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
QVERIFY( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry );

// but if we are requesting only visible features, then geometry must be fetched...

QSettings().setValue( QString( "/qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowVisible );
dlg.reset( new QgsAttributeTableDialog( tempLayer.get() ) );
QVERIFY( dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
QVERIFY( !( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry ) );
}

QTEST_MAIN( TestQgsAttributeTable )
#include "testqgsattributetable.moc"

0 comments on commit bae59b9

Please sign in to comment.
You can’t perform that action at this time.