Skip to content

Commit

Permalink
[pal] Always iterate through labeled layers in original layer order
Browse files Browse the repository at this point in the history
Ensures that labeling solutions are deterministic
  • Loading branch information
nyalldawson committed Jan 31, 2025
1 parent c42f86f commit 27a2846
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/core/pal/pal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,16 @@ Layer *Pal::addLayer( QgsAbstractLabelProvider *provider, const QString &layerNa
{
mMutex.lock();

Q_ASSERT( mLayers.find( provider ) == mLayers.end() );
#ifdef QGISDEBUG
for ( const auto &it : mLayers )
{
Q_ASSERT( it.first != provider );
}
#endif

std::unique_ptr< Layer > layer = std::make_unique< Layer >( provider, layerName, arrangement, defaultPriority, active, toLabel, this );
Layer *res = layer.get();
mLayers.insert( std::pair<QgsAbstractLabelProvider *, std::unique_ptr< Layer >>( provider, std::move( layer ) ) );
mLayers.emplace_back( std::make_pair( provider, std::move( layer ) ) );
mMutex.unlock();

// cppcheck-suppress returnDanglingLifetime
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ namespace pal

private:

std::unordered_map< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > mLayers;
std::vector< std::pair< QgsAbstractLabelProvider *, std::unique_ptr< Layer > > > mLayers;

QList< QgsAbstractLabelingEngineRule * > mRules;

Expand Down

0 comments on commit 27a2846

Please sign in to comment.