Skip to content

Commit dadd613

Browse files
committed
Ensure both attribute table cache & master model request respect
geometry fetching If request needs geometry but cache isn't fetching it then cache is bypassed. This is a performance hit, so ensure that cache and request are always in sync wrt to fetching geoms. On behalf of Faunalia, sponsored by ENEL
1 parent 5b0e84a commit dadd613

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

python/core/qgsvectorlayercache.sip

+1-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,10 @@ class QgsVectorLayerCache : QObject
3333
*/
3434
int cacheSize();
3535

36-
/**
37-
* Enable or disable the caching of geometries
38-
*
39-
* @param cacheGeometry Enable or disable the caching of geometries
40-
*/
4136
void setCacheGeometry( bool cacheGeometry );
4237

38+
bool cacheGeometry() const;
4339

44-
/**
45-
* Set the subset of attributes to be cached
46-
*
47-
* @param attributes The attributes to be cached
48-
*/
4940
void setCacheSubsetOfAttributes( const QgsAttributeList& attributes );
5041

5142
/**

src/core/qgsvectorlayercache.h

+7
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
106106
* Enable or disable the caching of geometries
107107
*
108108
* @param cacheGeometry Enable or disable the caching of geometries
109+
* @see cacheGeometry()
109110
*/
110111
void setCacheGeometry( bool cacheGeometry );
111112

113+
/**
114+
* Returns true if the cache will fetch and cache feature geometries.
115+
* @note added in QGIS 3.0
116+
* @see setCacheGeometry()
117+
*/
118+
bool cacheGeometry() const { return mCacheGeometry; }
112119

113120
/**
114121
* Set the subset of attributes to be cached

src/gui/attributetable/qgsdualview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void QgsDualView::init( QgsVectorLayer *layer, QgsMapCanvas *mapCanvas, const Qg
8282
connect( mTableView->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, &QgsDualView::showViewHeaderMenu );
8383
connect( mTableView, &QgsAttributeTableView::columnResized, this, &QgsDualView::tableColumnResized );
8484

85-
initLayerCache( !request.filterRect().isNull() );
85+
initLayerCache( !( request.flags() & QgsFeatureRequest::NoGeometry ) || !request.filterRect().isNull() );
8686
initModels( mapCanvas, request );
8787

8888
mConditionalFormatWidget->setLayer( mLayer );

tests/src/gui/testqgsdualview.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TestQgsDualView : public QObject
5656
void testSort();
5757

5858
void testAttributeFormSharedValueScanning();
59+
void testNoGeom();
5960

6061
private:
6162
QgsMapCanvas *mCanvas = nullptr;
@@ -270,5 +271,35 @@ void TestQgsDualView::testAttributeFormSharedValueScanning()
270271
QVERIFY( mixedValueFields.isEmpty() );
271272
}
272273

274+
void TestQgsDualView::testNoGeom()
275+
{
276+
//test that both the master model and cache for the dual view either both request geom or both don't request geom
277+
std::unique_ptr< QgsDualView > dv( new QgsDualView() );
278+
279+
// request with geometry
280+
QgsFeatureRequest req;
281+
dv->init( mPointsLayer, mCanvas, req );
282+
// check that both master model AND cache are using geometry
283+
QgsAttributeTableModel* model = dv->masterModel();
284+
QVERIFY( model->layerCache()->cacheGeometry() );
285+
QVERIFY( !( model->request().flags() & QgsFeatureRequest::NoGeometry ) );
286+
287+
// request with NO geometry, but using filter rect (which should override and request geom)
288+
req = QgsFeatureRequest().setFilterRect( QgsRectangle( 1, 2, 3, 4 ) );
289+
dv.reset( new QgsDualView() );
290+
dv->init( mPointsLayer, mCanvas, req );
291+
model = dv->masterModel();
292+
QVERIFY( model->layerCache()->cacheGeometry() );
293+
QVERIFY( !( model->request().flags() & QgsFeatureRequest::NoGeometry ) );
294+
295+
// request with NO geometry
296+
req = QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry );
297+
dv.reset( new QgsDualView() );
298+
dv->init( mPointsLayer, mCanvas, req );
299+
model = dv->masterModel();
300+
QVERIFY( !model->layerCache()->cacheGeometry() );
301+
QVERIFY(( model->request().flags() & QgsFeatureRequest::NoGeometry ) );
302+
}
303+
273304
QGSTEST_MAIN( TestQgsDualView )
274305
#include "testqgsdualview.moc"

0 commit comments

Comments
 (0)