Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 918d21f

Browse files
nyalldawsongithub-actions[bot]
authored andcommittedMar 8, 2023
Optimise legend filter by map test by finishing early when we have
determined that all available legend symbols for a layer are visible in the map Avoids a LOT of wasted time calculating visible symbols, especially for layers with a single symbol renderer.
1 parent d52b461 commit 918d21f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
 

‎src/core/qgsmaphittest.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
162162
usedSymbols.clear();
163163
usedSymbolsRuleKey.clear();
164164

165+
QSet< QString > remainingKeysToFind = r->legendKeys();
166+
165167
QgsFeature f;
166168
while ( fi.nextFeature( f ) )
167169
{
@@ -178,16 +180,17 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
178180

179181
//make sure we store string representation of symbol, not pointer
180182
//otherwise layer style override changes will delete original symbols and leave hanging pointers
181-
const auto constLegendKeysForFeature = r->legendKeysForFeature( f, context );
182-
for ( const QString &legendKey : constLegendKeysForFeature )
183+
const QSet< QString > legendKeysForFeature = r->legendKeysForFeature( f, context );
184+
for ( const QString &legendKey : legendKeysForFeature )
183185
{
184186
usedSymbolsRuleKey.insert( legendKey );
187+
remainingKeysToFind.remove( legendKey );
185188
}
186189

187190
if ( moreSymbolsPerFeature )
188191
{
189-
const auto constOriginalSymbolsForFeature = r->originalSymbolsForFeature( f, context );
190-
for ( QgsSymbol *s : constOriginalSymbolsForFeature )
192+
const QgsSymbolList originalSymbolsForFeature = r->originalSymbolsForFeature( f, context );
193+
for ( QgsSymbol *s : originalSymbolsForFeature )
191194
{
192195
if ( s )
193196
usedSymbols.insert( QgsSymbolLayerUtils::symbolProperties( s ) );
@@ -199,6 +202,12 @@ void QgsMapHitTest::runHitTestLayer( QgsVectorLayer *vl, SymbolSet &usedSymbols,
199202
if ( s )
200203
usedSymbols.insert( QgsSymbolLayerUtils::symbolProperties( s ) );
201204
}
205+
206+
if ( remainingKeysToFind.empty() )
207+
{
208+
// already found features for all legend items, no need to keep searching
209+
break;
210+
}
202211
}
203212
r->stopRender( context );
204213
}

0 commit comments

Comments
 (0)
Please sign in to comment.