Skip to content

Commit

Permalink
Ensure all canvases are refreshed when project properties are applied
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent d619980 commit 5c873f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
8 changes: 1 addition & 7 deletions src/app/qgisapp.cpp
Expand Up @@ -3129,7 +3129,6 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )

mapCanvas->setLayers( mMapCanvas->layers() );
mapCanvas->setExtent( mMapCanvas->extent() );
mapCanvas->setCachingEnabled( true );

mapCanvas->setDestinationCrs( QgsProject::instance()->crs() );

Expand Down Expand Up @@ -10609,11 +10608,6 @@ void QgisApp::projectProperties()
&QgsStatusBarScaleWidget::updateScales );
QApplication::restoreOverrideCursor();

//pass any refresh signals off to canvases
// Line below was commented out by wonder three years ago (r4949).
// It is needed to refresh scale bar after changing display units.
connect( pp, SIGNAL( refresh() ), mMapCanvas, SLOT( refresh() ) );

// Display the modal dialog box.
pp->exec();

Expand All @@ -10626,7 +10620,7 @@ void QgisApp::projectProperties()

// delete the property sheet object
delete pp;
} // QgisApp::projectProperties
}


QgsClipboard *QgisApp::clipboard()
Expand Down
37 changes: 23 additions & 14 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -812,21 +812,25 @@ void QgsProjectProperties::apply()
}

//set the color for selections
QColor myColor = pbnSelectionColor->color();
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), myColor.red() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), myColor.green() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), myColor.blue() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), myColor.alpha() );
mMapCanvas->setSelectionColor( myColor );
QColor selectionColor = pbnSelectionColor->color();
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), selectionColor.red() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), selectionColor.green() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), selectionColor.blue() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), selectionColor.alpha() );


//set the color for canvas
myColor = pbnCanvasColor->color();
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), myColor.red() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), myColor.green() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), myColor.blue() );
mMapCanvas->setCanvasColor( myColor );
QgisApp::instance()->mapOverviewCanvas()->setBackgroundColor( myColor );
QgisApp::instance()->mapOverviewCanvas()->refresh();
QColor canvasColor = pbnCanvasColor->color();
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), canvasColor.red() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), canvasColor.green() );
QgsProject::instance()->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), canvasColor.blue() );

Q_FOREACH ( QgsMapCanvas *canvas, QgisApp::instance()->mapCanvases() )
{
canvas->setCanvasColor( canvasColor );
canvas->setSelectionColor( selectionColor );
}
QgisApp::instance()->mapOverviewCanvas()->setBackgroundColor( canvasColor );

//save project scales
QStringList myScales;
Expand Down Expand Up @@ -1140,7 +1144,12 @@ void QgsProjectProperties::apply()
//save variables
QgsProject::instance()->setCustomVariables( mVariableEditor->variablesInActiveScope() );

emit refresh();
//refresh canvases to reflect new properties, eg background color and scale bar after changing display units.
Q_FOREACH ( QgsMapCanvas *canvas, QgisApp::instance()->mapCanvases() )
{
canvas->refresh();
}
QgisApp::instance()->mapOverviewCanvas()->refresh();
}

void QgsProjectProperties::showProjectionsTab()
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgsprojectproperties.h
Expand Up @@ -162,9 +162,6 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
//! Signal used to inform listeners that project scale list may have changed
void scalesChanged( const QStringList &scales = QStringList() );

//! let listening canvases know to refresh
void refresh();

private:

//! Formats for displaying coordinates
Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1544,7 +1544,6 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool *tool )
}
}

//! Write property of QColor bgColor.
void QgsMapCanvas::setCanvasColor( const QColor &color )
{
// background of map's pixmap
Expand All @@ -1561,7 +1560,7 @@ void QgsMapCanvas::setCanvasColor( const QColor &color )

// background of QGraphicsScene
mScene->setBackgroundBrush( bgBrush );
} // setBackgroundColor
}

QColor QgsMapCanvas::canvasColor() const
{
Expand Down

0 comments on commit 5c873f6

Please sign in to comment.