Skip to content
Permalink
Browse files

Fix attribute table always fetches geometries for features

On behalf of Faunalia, sponsored by ENEL

(cherry-picked from 8a050de)
  • Loading branch information
nyalldawson committed Mar 7, 2017
1 parent c55ffd5 commit 93656733bf7252978e6ef52a0857dc961b12bd4a
@@ -131,6 +131,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mEditorContext.setVectorLayerTools( QgisApp::instance()->vectorLayerTools() );

QgsFeatureRequest r;
bool needsGeom = false;
if ( mLayer->geometryType() != QGis::NoGeometry &&
settings.value( "/qgis/attributeTableBehaviour", QgsAttributeTableFilterModel::ShowAll ).toInt() == QgsAttributeTableFilterModel::ShowVisible )
{
@@ -144,7 +145,10 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
delete g;

mActionShowAllFilter->setText( tr( "Show All Features In Initial Canvas Extent" ) );
needsGeom = true;
}
if ( !needsGeom )
r.setFlags( QgsFeatureRequest::NoGeometry );

// Initialize dual view
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, mEditorContext );
@@ -235,6 +235,16 @@ QgsDualView::ViewMode QgsDualView::view() const

void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filterMode )
{
bool needsGeometry = filterMode == QgsAttributeTableFilterModel::ShowVisible;

QgsFeatureRequest r = mMasterModel->request();
if ( !needsGeometry )
r.setFlags( r.flags() | QgsFeatureRequest::NoGeometry );
else
r.setFlags( r.flags() & ~( QgsFeatureRequest::NoGeometry ) );
mMasterModel->setRequest( r );
whileBlocking( mLayerCache )->setCacheGeometry( needsGeometry );

mFilterModel->setFilterMode( filterMode );
emit filterChanged();
}
@@ -179,21 +179,32 @@ void TestQgsAttributeTable::testFieldCalculationArea()
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" ) ) );
QScopedPointer< 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() ) );
QSettings().setValue( QString( "/qgis/attributeTableBehaviour" ), QgsAttributeTableFilterModel::ShowAll );
QScopedPointer< QgsAttributeTableDialog > dlg( new QgsAttributeTableDialog( tempLayer.data() ) );

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() ) );
QSettings().setValue( QString( "/qgis/attributeTableBehaviour" ), QgsAttributeTableFilterModel::ShowVisible );
dlg.reset( new QgsAttributeTableDialog( tempLayer.data() ) );
QVERIFY( dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
QVERIFY( !( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry ) );

// try changing existing dialog to no geometry mode
dlg->filterShowAll();
QVERIFY( !dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
QVERIFY( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry );

// and back to a geometry mode
dlg->filterVisible();
QVERIFY( dlg->mMainView->masterModel()->layerCache()->cacheGeometry() );
QVERIFY( !( dlg->mMainView->masterModel()->request().flags() & QgsFeatureRequest::NoGeometry ) );

}

QTEST_MAIN( TestQgsAttributeTable )

0 comments on commit 9365673

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