Skip to content
Permalink
Browse files

[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.
  • Loading branch information
nyalldawson committed Feb 19, 2018
1 parent 0e3af9c commit 89259e85f7fdaebbbee7bf92564db0d5fada7be8
Showing with 7 additions and 12 deletions.
  1. +7 −0 src/app/layout/qgslayoutapputils.cpp
  2. +0 −12 src/core/layout/qgslayoutitemmap.cpp
@@ -78,6 +78,13 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
{
QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
Q_ASSERT( map );

//get the color for map canvas background and set map background color accordingly
int bgRedInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), 255 );
int bgGreenInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
int bgBlueInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
map->setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );

if ( QgisApp::instance()->mapCanvas() )
{
map->zoomToExtent( QgisApp::instance()->mapCanvas()->mapSettings().visibleExtent() );
@@ -40,18 +40,6 @@ QgsLayoutItemMap::QgsLayoutItemMap( QgsLayout *layout )

assignFreeId();

if ( layout )
{
if ( QgsProject *project = layout->project() )
{
//get the color for map canvas background and set map background color accordingly
int bgRedInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), 255 );
int bgGreenInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
int bgBlueInt = project->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
}
}

connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
{
shapeChanged();

0 comments on commit 89259e8

Please sign in to comment.
You can’t perform that action at this time.