Skip to content

Commit 9bb0c84

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 (cherry-picked from dadd613)
1 parent 7daeca6 commit 9bb0c84

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

python/core/qgsvectorlayercache.sip

Lines changed: 1 addition & 10 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
103103
* Enable or disable the caching of geometries
104104
*
105105
* @param cacheGeometry Enable or disable the caching of geometries
106+
* @see cacheGeometry()
106107
*/
107108
void setCacheGeometry( bool cacheGeometry );
108109

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

110117
/**
111118
* Set the subset of attributes to be cached

src/gui/attributetable/qgsdualview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void QgsDualView::init( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const Qg
8181
connect( mTableView->horizontalHeader(), SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( showViewHeaderMenu( QPoint ) ) );
8282
connect( mTableView, SIGNAL( columnResized( int, int ) ), this, SLOT( tableColumnResized( int, int ) ) );
8383

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

8787
mConditionalFormatWidget->setLayer( mLayer );

tests/src/gui/testqgsdualview.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class TestQgsDualView : public QObject
5353
void testSort();
5454

5555
void testAttributeFormSharedValueScanning();
56+
void testNoGeom();
5657

5758
private:
5859
QgsMapCanvas* mCanvas;
@@ -266,6 +267,36 @@ void TestQgsDualView::testAttributeFormSharedValueScanning()
266267
QVERIFY( mixedValueFields.isEmpty() );
267268
}
268269

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

0 commit comments

Comments
 (0)