Skip to content

Commit 286f8dd

Browse files
elpasonyalldawson
authored andcommittedNov 1, 2021
[backport] Fix raster change datasource
Fixes #44929 Cherry-picked from master 30f3a5d.
1 parent acdcd02 commit 286f8dd

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed
 

‎src/core/qgsmaplayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ void QgsMapLayer::setLegend( QgsMapLayerLegend *legend )
17921792
if ( mLegend )
17931793
{
17941794
mLegend->setParent( this );
1795-
connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged );
1795+
connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged, Qt::UniqueConnection );
17961796
}
17971797

17981798
emit legendChanged();

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ void QgsRasterLayer::init()
601601
{
602602
mRasterType = QgsRasterLayer::GrayOrUndefined;
603603

604-
setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) );
604+
whileBlocking( this )->setLegend( QgsMapLayerLegend::defaultRasterLegend( this ) );
605605

606606
setRendererForDrawingStyle( QgsRaster::UndefinedDrawingStyle );
607607

‎src/core/raster/qgsrasterpipe.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ bool QgsRasterPipe::insert( int idx, QgsRasterInterface *interface )
9696
success = true;
9797
mInterfaces.insert( idx, interface );
9898
setRole( interface, idx );
99-
QgsDebugMsgLevel( QStringLiteral( "inserted OK" ), 4 );
99+
QgsDebugMsgLevel( QStringLiteral( "Pipe %1 inserted OK" ).arg( idx ), 4 );
100+
}
101+
else
102+
{
103+
QgsDebugMsgLevel( QStringLiteral( "Error inserting pipe %1" ).arg( idx ), 4 );
100104
}
101105

102106
// Connect or reconnect (after the test) interfaces
@@ -158,6 +162,19 @@ void QgsRasterPipe::unsetRole( QgsRasterInterface *interface )
158162
Role role = interfaceRole( interface );
159163
if ( role == UnknownRole ) return;
160164
mRoleMap.remove( role );
165+
166+
// Decrease all indexes greater than the removed one
167+
const auto roleMapValues {mRoleMap.values()};
168+
if ( roleIdx < *std::max_element( roleMapValues.begin(), roleMapValues.end() ) )
169+
{
170+
for ( auto it = mRoleMap.cbegin(); it != mRoleMap.cend(); ++it )
171+
{
172+
if ( it.value() > roleIdx )
173+
{
174+
mRoleMap[it.key()] = it.value() - 1;
175+
}
176+
}
177+
}
161178
}
162179

163180
bool QgsRasterPipe::set( QgsRasterInterface *interface )
@@ -283,11 +300,16 @@ bool QgsRasterPipe::remove( int idx )
283300
unsetRole( mInterfaces.at( idx ) );
284301
delete mInterfaces.at( idx );
285302
mInterfaces.remove( idx );
286-
QgsDebugMsgLevel( QStringLiteral( "removed OK" ), 4 );
303+
QgsDebugMsgLevel( QStringLiteral( "Pipe %1 removed OK" ).arg( idx ), 4 );
304+
}
305+
else
306+
{
307+
QgsDebugMsgLevel( QStringLiteral( "Error removing pipe %1" ).arg( idx ), 4 );
287308
}
288309

289310
// Connect or reconnect (after the test) interfaces
290311
connect( mInterfaces );
312+
291313
return success;
292314
}
293315

0 commit comments

Comments
 (0)
Please sign in to comment.