Skip to content
Permalink
Browse files
[backport] Fix raster change datasource
Fixes #44929

Cherry-picked from master 30f3a5d.
  • Loading branch information
elpaso authored and nyalldawson committed Nov 1, 2021
1 parent acdcd02 commit 286f8ddd7617e7f5eb940afa7952b67b66dc7f0d
Showing with 26 additions and 4 deletions.
  1. +1 −1 src/core/qgsmaplayer.cpp
  2. +1 −1 src/core/raster/qgsrasterlayer.cpp
  3. +24 −2 src/core/raster/qgsrasterpipe.cpp
@@ -1792,7 +1792,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();
@@ -601,7 +601,7 @@ void QgsRasterLayer::init()
{
mRasterType = QgsRasterLayer::GrayOrUndefined;

setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) );
whileBlocking( this )->setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) );

setRendererForDrawingStyle( QgsRaster::UndefinedDrawingStyle );

@@ -96,7 +96,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
@@ -158,6 +162,19 @@ void QgsRasterPipe::unsetRole( QgsRasterInterface *interface )
Role role = interfaceRole( interface );
if ( role == UnknownRole ) return;
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 )
@@ -283,11 +300,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;
}

0 comments on commit 286f8dd

Please sign in to comment.