Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #45074 from elpaso/bugfix-gh44929-raster-datasourc…
…e-change-issue

Fix raster change datasource
  • Loading branch information
elpaso committed Sep 16, 2021
2 parents 2b9bc26 + 30f3a5d commit b60400c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -585,7 +585,7 @@ void QgsRasterLayer::init()
{
mRasterType = QgsRasterLayer::GrayOrUndefined;

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

setRendererForDrawingStyle( QgsRaster::UndefinedDrawingStyle );

Expand Down
29 changes: 26 additions & 3 deletions src/core/raster/qgsrasterpipe.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -152,7 +156,7 @@ Qgis::RasterPipeInterfaceRole QgsRasterPipe::interfaceRole( QgsRasterInterface *
else if ( dynamic_cast<QgsRasterNuller *>( 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;
}

Expand All @@ -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 )
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b60400c

Please sign in to comment.