Skip to content

Commit

Permalink
Fix overview canvas background color not set (fix #11157)
Browse files Browse the repository at this point in the history
(cherry-picked from f60ca59)
  • Loading branch information
nyalldawson committed Nov 19, 2015
1 parent c576281 commit 4d7cb24
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -864,6 +864,7 @@ QgisApp::QgisApp()
, mToolPopupOverviews( 0 )
, mToolPopupDisplay( 0 )
, mMapCanvas( 0 )
, mOverviewCanvas( 0 )
, mLayerTreeView( 0 )
, mLayerTreeCanvasBridge( 0 )
, mMapLayerOrder( 0 )
Expand Down Expand Up @@ -2282,25 +2283,33 @@ void QgisApp::createCanvasTools()
void QgisApp::createOverview()
{
// overview canvas
QgsMapOverviewCanvas* overviewCanvas = new QgsMapOverviewCanvas( NULL, mMapCanvas );
overviewCanvas->setWhatsThis( tr( "Map overview canvas. This canvas can be used to display a locator map that shows the current extent of the map canvas. The current extent is shown as a red rectangle. Any layer on the map can be added to the overview canvas." ) );
mOverviewCanvas = new QgsMapOverviewCanvas( NULL, mMapCanvas );

//set canvas color to default
QSettings settings;
int red = settings.value( "/qgis/default_canvas_color_red", 255 ).toInt();
int green = settings.value( "/qgis/default_canvas_color_green", 255 ).toInt();
int blue = settings.value( "/qgis/default_canvas_color_blue", 255 ).toInt();
mOverviewCanvas->setBackgroundColor( QColor( red, green, blue ) );

mOverviewCanvas->setWhatsThis( tr( "Map overview canvas. This canvas can be used to display a locator map that shows the current extent of the map canvas. The current extent is shown as a red rectangle. Any layer on the map can be added to the overview canvas." ) );

QBitmap overviewPanBmp = QBitmap::fromData( QSize( 16, 16 ), pan_bits );
QBitmap overviewPanBmpMask = QBitmap::fromData( QSize( 16, 16 ), pan_mask_bits );
mOverviewMapCursor = new QCursor( overviewPanBmp, overviewPanBmpMask, 0, 0 ); //set upper left corner as hot spot - this is better when extent marker is small; hand won't cover the marker
overviewCanvas->setCursor( *mOverviewMapCursor );
mOverviewCanvas->setCursor( *mOverviewMapCursor );
// QVBoxLayout *myOverviewLayout = new QVBoxLayout;
// myOverviewLayout->addWidget(overviewCanvas);
// overviewFrame->setLayout(myOverviewLayout);
mOverviewDock = new QDockWidget( tr( "Overview" ), this );
mOverviewDock->setObjectName( "Overview" );
mOverviewDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
mOverviewDock->setWidget( overviewCanvas );
mOverviewDock->setWidget( mOverviewCanvas );
addDockWidget( Qt::LeftDockWidgetArea, mOverviewDock );
// add to the Panel submenu
mPanelMenu->addAction( mOverviewDock->toggleViewAction() );

mMapCanvas->enableOverviewMode( overviewCanvas );
mMapCanvas->enableOverviewMode( mOverviewCanvas );

// moved here to set anti aliasing to both map canvas and overview
QSettings mySettings;
Expand Down Expand Up @@ -3631,6 +3640,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
prj->writeEntry( "Gui", "/CanvasColorGreenPart", myGreen );
prj->writeEntry( "Gui", "/CanvasColorBluePart", myBlue );
mMapCanvas->setCanvasColor( QColor( myRed, myGreen, myBlue ) );
mOverviewCanvas->setBackgroundColor( QColor( myRed, myGreen, myBlue ) );

prj->dirty( false );

Expand Down Expand Up @@ -4008,6 +4018,8 @@ bool QgisApp::addProject( QString projectFile )
int myBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt );
mMapCanvas->setCanvasColor( myColor ); //this is fill color before rendering starts
mOverviewCanvas->setBackgroundColor( myColor );

QgsDebugMsg( "Canvas background color restored..." );
myRedInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
myGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -55,6 +55,7 @@ class QgsMapLayer;
class QgsMapTip;
class QgsMapTool;
class QgsMapToolAdvancedDigitizing;
class QgsMapOverviewCanvas;
class QgsPoint;
class QgsProviderRegistry;
class QgsPythonUtils;
Expand Down Expand Up @@ -432,6 +433,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! return CAD dock widget
QgsAdvancedDigitizingDockWidget *cadDockWidget() { return mAdvancedDigitizingDockWidget; }

//! Returns map overview canvas
QgsMapOverviewCanvas* mapOverviewCanvas() { return mOverviewCanvas; }

//! show layer properties
void showLayerProperties( QgsMapLayer *ml );

Expand Down Expand Up @@ -1534,6 +1538,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QMenu *mToolPopupDisplay;
//! Map canvas
QgsMapCanvas *mMapCanvas;
//! Overview map canvas
QgsMapOverviewCanvas *mOverviewCanvas;
//! Table of contents (legend) for the map
QgsLayerTreeView *mLayerTreeView;
//! Helper class that connects layer tree with map canvas
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -49,6 +49,7 @@
#include "qgscolorschemeregistry.h"
#include "qgssymbollayerv2utils.h"
#include "qgscolordialog.h"
#include "qgsmapoverviewcanvas.h"

//qt includes
#include <QInputDialog>
Expand Down Expand Up @@ -678,6 +679,8 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorGreenPart", myColor.green() );
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorBluePart", myColor.blue() );
mMapCanvas->setCanvasColor( myColor );
QgisApp::instance()->mapOverviewCanvas()->setBackgroundColor( myColor );
QgisApp::instance()->mapOverviewCanvas()->refresh();

//save project scales
QStringList myScales;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmapoverviewcanvas.cpp
Expand Up @@ -74,6 +74,7 @@ QgsMapOverviewCanvas::QgsMapOverviewCanvas( QWidget * parent, QgsMapCanvas* mapC
, mMapCanvas( mapCanvas )
, mJob( 0 )
{
setAutoFillBackground( true );
setObjectName( "theOverviewCanvas" );
mPanningWidget = new QgsPanningWidget( this );

Expand Down

0 comments on commit 4d7cb24

Please sign in to comment.