Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Speed up loading of complex projects with many symbols
  • Loading branch information
nyalldawson committed Aug 19, 2021
1 parent 1706e7b commit 9cfdf3d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/symbology/qgssymbollayerreference.cpp
Expand Up @@ -40,10 +40,12 @@ QString symbolLayerReferenceListToString( const QgsSymbolLayerReferenceList &lst
QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList( const QString &str )
{
QgsSymbolLayerReferenceList lst;
if ( str.isEmpty() )
return lst;

// when saving we used ; as a concatenator... but that was silly, cos maybe the symbol keys contain this string!
// try to handle this gracefully via regex...
const QRegularExpression partsRx( QStringLiteral( "((?:.*?),(?:.*?),(?:(?:\\d+,)+)?(?:\\d+);)" ) );
const thread_local QRegularExpression partsRx( QStringLiteral( "((?:.*?),(?:.*?),(?:(?:\\d+,)+)?(?:\\d+);)" ) );
QRegularExpressionMatchIterator partsIt = partsRx.globalMatch( str + ';' );

while ( partsIt.hasNext() )
Expand All @@ -54,7 +56,7 @@ QgsSymbolLayerReferenceList stringToSymbolLayerReferenceList( const QString &str
// We should have "layer_id,symbol_key,symbol_layer_index0,symbol_layer_index1,..."
// EXCEPT that the symbol_key CAN have commas, so this whole logic is extremely broken.
// Let's see if a messy regex can save the day!
const QRegularExpression rx( QStringLiteral( "(.*?),(.*?),((?:\\d+,)+)?(\\d+)" ) );
const thread_local QRegularExpression rx( QStringLiteral( "(.*?),(.*?),((?:\\d+,)+)?(\\d+)" ) );

const QRegularExpressionMatch match = rx.match( tuple );
if ( !match.hasMatch() )
Expand Down

0 comments on commit 9cfdf3d

Please sign in to comment.