Skip to content

Commit

Permalink
[layouts] Move responsibility for matching map colors to project
Browse files Browse the repository at this point in the history
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 89259e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -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() );
Expand Down
12 changes: 0 additions & 12 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 89259e8

Please sign in to comment.