Skip to content

Commit 89259e8

Browse files
committed
[layouts] Move responsibility for matching map colors to project
background color to app This fits better in app - the silent auto setting of background colors should not apply to scripts manually creating QgsLayoutItemMap items.
1 parent 0e3af9c commit 89259e8

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/app/layout/qgslayoutapputils.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
7878
{
7979
QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
8080
Q_ASSERT( map );
81+
82+
//get the color for map canvas background and set map background color accordingly
83+
int bgRedInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), 255 );
84+
int bgGreenInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
85+
int bgBlueInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
86+
map->setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
87+
8188
if ( QgisApp::instance()->mapCanvas() )
8289
{
8390
map->zoomToExtent( QgisApp::instance()->mapCanvas()->mapSettings().visibleExtent() );

src/core/layout/qgslayoutitemmap.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,6 @@ QgsLayoutItemMap::QgsLayoutItemMap( QgsLayout *layout )
4040

4141
assignFreeId();
4242

43-
if ( layout )
44-
{
45-
if ( QgsProject *project = layout->project() )
46-
{
47-
//get the color for map canvas background and set map background color accordingly
48-
int bgRedInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), 255 );
49-
int bgGreenInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
50-
int bgBlueInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
51-
setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
52-
}
53-
}
54-
5543
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
5644
{
5745
shapeChanged();

0 commit comments

Comments
 (0)