diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index 2d2fd17af213..11e0058c8ef1 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -1970,7 +1970,7 @@ void QgsMapLayer::setLegend( QgsMapLayerLegend *legend ) if ( mLegend ) { mLegend->setParent( this ); - connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged ); + connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged, Qt::UniqueConnection ); } emit legendChanged(); diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index e114c2d6984d..a99fa8de2420 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -585,7 +585,7 @@ void QgsRasterLayer::init() { mRasterType = QgsRasterLayer::GrayOrUndefined; - setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) ); + whileBlocking( this )->setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) ); setRendererForDrawingStyle( QgsRaster::UndefinedDrawingStyle ); diff --git a/src/core/raster/qgsrasterpipe.cpp b/src/core/raster/qgsrasterpipe.cpp index 3a91f11a46ae..4a742431c4a7 100644 --- a/src/core/raster/qgsrasterpipe.cpp +++ b/src/core/raster/qgsrasterpipe.cpp @@ -99,7 +99,11 @@ bool QgsRasterPipe::insert( int idx, QgsRasterInterface *interface ) success = true; mInterfaces.insert( idx, interface ); setRole( interface, idx ); - QgsDebugMsgLevel( QStringLiteral( "inserted OK" ), 4 ); + QgsDebugMsgLevel( QStringLiteral( "Pipe %1 inserted OK" ).arg( idx ), 4 ); + } + else + { + QgsDebugMsgLevel( QStringLiteral( "Error inserting pipe %1" ).arg( idx ), 4 ); } // Connect or reconnect (after the test) interfaces @@ -152,7 +156,7 @@ Qgis::RasterPipeInterfaceRole QgsRasterPipe::interfaceRole( QgsRasterInterface * else if ( dynamic_cast( interface ) ) role = Qgis::RasterPipeInterfaceRole::Nuller; - QgsDebugMsgLevel( QStringLiteral( "%1 role = %2" ).arg( typeid( *interface ).name() ).arg( qgsEnumValueToKey( role ) ), 4 ); + QgsDebugMsgLevel( QStringLiteral( "%1 role = %2" ).arg( typeid( *interface ).name(), qgsEnumValueToKey( role ) ), 4 ); return role; } @@ -171,7 +175,21 @@ void QgsRasterPipe::unsetRole( QgsRasterInterface *interface ) if ( role == Qgis::RasterPipeInterfaceRole::Unknown ) return; + const int roleIdx{ mRoleMap[role] }; mRoleMap.remove( role ); + + // Decrease all indexes greater than the removed one + const auto roleMapValues {mRoleMap.values()}; + if ( roleIdx < *std::max_element( roleMapValues.begin(), roleMapValues.end() ) ) + { + for ( auto it = mRoleMap.cbegin(); it != mRoleMap.cend(); ++it ) + { + if ( it.value() > roleIdx ) + { + mRoleMap[it.key()] = it.value() - 1; + } + } + } } bool QgsRasterPipe::set( QgsRasterInterface *interface ) @@ -300,11 +318,16 @@ bool QgsRasterPipe::remove( int idx ) unsetRole( mInterfaces.at( idx ) ); delete mInterfaces.at( idx ); mInterfaces.remove( idx ); - QgsDebugMsgLevel( QStringLiteral( "removed OK" ), 4 ); + QgsDebugMsgLevel( QStringLiteral( "Pipe %1 removed OK" ).arg( idx ), 4 ); + } + else + { + QgsDebugMsgLevel( QStringLiteral( "Error removing pipe %1" ).arg( idx ), 4 ); } // Connect or reconnect (after the test) interfaces connect( mInterfaces ); + return success; }