diff --git a/python/core/qgsvectorlayercache.sip b/python/core/qgsvectorlayercache.sip index 6ece7982510..d025c8c88ec 100644 --- a/python/core/qgsvectorlayercache.sip +++ b/python/core/qgsvectorlayercache.sip @@ -33,19 +33,10 @@ class QgsVectorLayerCache : QObject */ int cacheSize(); - /** - * Enable or disable the caching of geometries - * - * @param cacheGeometry Enable or disable the caching of geometries - */ void setCacheGeometry( bool cacheGeometry ); + bool cacheGeometry() const; - /** - * Set the subset of attributes to be cached - * - * @param attributes The attributes to be cached - */ void setCacheSubsetOfAttributes( const QgsAttributeList& attributes ); /** diff --git a/src/core/qgsvectorlayercache.h b/src/core/qgsvectorlayercache.h index df25ea50e99..345d9e5945e 100644 --- a/src/core/qgsvectorlayercache.h +++ b/src/core/qgsvectorlayercache.h @@ -106,9 +106,16 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject * Enable or disable the caching of geometries * * @param cacheGeometry Enable or disable the caching of geometries + * @see cacheGeometry() */ void setCacheGeometry( bool cacheGeometry ); + /** + * Returns true if the cache will fetch and cache feature geometries. + * @note added in QGIS 3.0 + * @see setCacheGeometry() + */ + bool cacheGeometry() const { return mCacheGeometry; } /** * Set the subset of attributes to be cached diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index aa5747eabaf..60d47fb3c24 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -82,7 +82,7 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg connect( mTableView->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &QgsDualView::showViewHeaderMenu ); connect( mTableView, &QgsAttributeTableView::columnResized, this, &QgsDualView::tableColumnResized ); - initLayerCache( !request.filterRect().isNull() ); + initLayerCache( !( request.flags() & QgsFeatureRequest::NoGeometry ) || !request.filterRect().isNull() ); initModels( mapCanvas, request ); mConditionalFormatWidget->setLayer( mLayer ); diff --git a/tests/src/gui/testqgsdualview.cpp b/tests/src/gui/testqgsdualview.cpp index 76df6685016..d87c34f4c58 100644 --- a/tests/src/gui/testqgsdualview.cpp +++ b/tests/src/gui/testqgsdualview.cpp @@ -56,6 +56,7 @@ class TestQgsDualView : public QObject void testSort(); void testAttributeFormSharedValueScanning(); + void testNoGeom(); private: QgsMapCanvas *mCanvas = nullptr; @@ -270,5 +271,35 @@ void TestQgsDualView::testAttributeFormSharedValueScanning() QVERIFY( mixedValueFields.isEmpty() ); } +void TestQgsDualView::testNoGeom() +{ + //test that both the master model and cache for the dual view either both request geom or both don't request geom + std::unique_ptr< QgsDualView > dv( new QgsDualView() ); + + // request with geometry + QgsFeatureRequest req; + dv->init( mPointsLayer, mCanvas, req ); + // check that both master model AND cache are using geometry + QgsAttributeTableModel* model = dv->masterModel(); + QVERIFY( model->layerCache()->cacheGeometry() ); + QVERIFY( !( model->request().flags() & QgsFeatureRequest::NoGeometry ) ); + + // request with NO geometry, but using filter rect (which should override and request geom) + req = QgsFeatureRequest().setFilterRect( QgsRectangle( 1, 2, 3, 4 ) ); + dv.reset( new QgsDualView() ); + dv->init( mPointsLayer, mCanvas, req ); + model = dv->masterModel(); + QVERIFY( model->layerCache()->cacheGeometry() ); + QVERIFY( !( model->request().flags() & QgsFeatureRequest::NoGeometry ) ); + + // request with NO geometry + req = QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ); + dv.reset( new QgsDualView() ); + dv->init( mPointsLayer, mCanvas, req ); + model = dv->masterModel(); + QVERIFY( !model->layerCache()->cacheGeometry() ); + QVERIFY(( model->request().flags() & QgsFeatureRequest::NoGeometry ) ); +} + QGSTEST_MAIN( TestQgsDualView ) #include "testqgsdualview.moc"