Skip to content

Commit 5e6d540

Browse files
committed
Refactor out canvas initializing to project settings
1 parent 3210fcc commit 5e6d540

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

src/app/qgisapp.cpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,22 @@ void QgisApp::readRecentProjects()
16051605
settings.endGroup();
16061606
}
16071607

1608+
void QgisApp::applyProjectSettingsToCanvas( QgsMapCanvas *canvas )
1609+
{
1610+
int red = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), 255 );
1611+
int green = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
1612+
int blue = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
1613+
QColor myColor = QColor( red, green, blue );
1614+
canvas->setCanvasColor( myColor );
1615+
1616+
int alpha = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), 255 );
1617+
red = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), 255 );
1618+
green = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), 255 );
1619+
blue = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), 0 );
1620+
myColor = QColor( red, green, blue, alpha );
1621+
canvas->setSelectionColor( myColor );
1622+
}
1623+
16081624
void QgisApp::readSettings()
16091625
{
16101626
QgsSettings settings;
@@ -4564,27 +4580,27 @@ void QgisApp::fileNew( bool promptToSaveFlag, bool forceBlank )
45644580
//set the color for selections
45654581
//the default can be set in qgisoptions
45664582
//use project properties to override the color on a per project basis
4567-
int myRed = settings.value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
4568-
int myGreen = settings.value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
4569-
int myBlue = settings.value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
4570-
int myAlpha = settings.value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
4571-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), myRed );
4572-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), myGreen );
4573-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), myBlue );
4574-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), myAlpha );
4575-
mMapCanvas->setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
4583+
int red = settings.value( QStringLiteral( "/qgis/default_selection_color_red" ), 255 ).toInt();
4584+
int green = settings.value( QStringLiteral( "/qgis/default_selection_color_green" ), 255 ).toInt();
4585+
int blue = settings.value( QStringLiteral( "/qgis/default_selection_color_blue" ), 0 ).toInt();
4586+
int alpha = settings.value( QStringLiteral( "/qgis/default_selection_color_alpha" ), 255 ).toInt();
4587+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), red );
4588+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), green );
4589+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), blue );
4590+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), alpha );
45764591

45774592
//set the canvas to the default background color
45784593
//the default can be set in qgisoptions
45794594
//use project properties to override the color on a per project basis
4580-
myRed = settings.value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
4581-
myGreen = settings.value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
4582-
myBlue = settings.value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
4583-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), myRed );
4584-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), myGreen );
4585-
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), myBlue );
4586-
mMapCanvas->setCanvasColor( QColor( myRed, myGreen, myBlue ) );
4587-
mOverviewCanvas->setBackgroundColor( QColor( myRed, myGreen, myBlue ) );
4595+
red = settings.value( QStringLiteral( "/qgis/default_canvas_color_red" ), 255 ).toInt();
4596+
green = settings.value( QStringLiteral( "/qgis/default_canvas_color_green" ), 255 ).toInt();
4597+
blue = settings.value( QStringLiteral( "/qgis/default_canvas_color_blue" ), 255 ).toInt();
4598+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorRedPart" ), red );
4599+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), green );
4600+
prj->writeEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), blue );
4601+
4602+
mOverviewCanvas->setBackgroundColor( QColor( red, green, blue ) );
4603+
applyProjectSettingsToCanvas( mMapCanvas );
45884604

45894605
prj->setDirty( false );
45904606

@@ -5027,16 +5043,9 @@ bool QgisApp::addProject( const QString &projectFile )
50275043
int myGreenInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorGreenPart" ), 255 );
50285044
int myBlueInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/CanvasColorBluePart" ), 255 );
50295045
QColor myColor = QColor( myRedInt, myGreenInt, myBlueInt );
5030-
mMapCanvas->setCanvasColor( myColor ); //this is fill color before rendering starts
50315046
mOverviewCanvas->setBackgroundColor( myColor );
50325047

5033-
QgsDebugMsg( "Canvas background color restored..." );
5034-
int myAlphaInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorAlphaPart" ), 255 );
5035-
myRedInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorRedPart" ), 255 );
5036-
myGreenInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorGreenPart" ), 255 );
5037-
myBlueInt = QgsProject::instance()->readNumEntry( QStringLiteral( "Gui" ), QStringLiteral( "/SelectionColorBluePart" ), 0 );
5038-
myColor = QColor( myRedInt, myGreenInt, myBlueInt, myAlphaInt );
5039-
mMapCanvas->setSelectionColor( myColor ); //this is selection color before rendering starts
5048+
applyProjectSettingsToCanvas( mMapCanvas );
50405049

50415050
//load project scales
50425051
bool projectScales = QgsProject::instance()->readBoolEntry( QStringLiteral( "Scales" ), QStringLiteral( "/useProjectScales" ) );

src/app/qgisapp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15391539
//! Loads the list of recent projects from settings
15401540
void readRecentProjects();
15411541

1542+
/**
1543+
* Applies project map canvas settings to the specified canvas
1544+
*/
1545+
void applyProjectSettingsToCanvas( QgsMapCanvas *canvas );
1546+
15421547
QgisAppStyleSheet *mStyleSheetBuilder = nullptr;
15431548

15441549
// actions for menus and toolbars -----------------

0 commit comments

Comments
 (0)