Skip to content

Commit e4b9dfc

Browse files
committed
add New Blank Project action that creates a blank project, regardless of template settings
1 parent f3e0cf5 commit e4b9dfc

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/app/qgisapp.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ void QgisApp::createActions()
819819
// File Menu Items
820820

821821
connect( mActionNewProject, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
822+
connect( mActionNewBlankProject, SIGNAL( triggered() ), this, SLOT( fileNewBlank() ) );
822823
connect( mActionOpenProject, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
823824
connect( mActionSaveProject, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
824825
connect( mActionSaveProjectAs, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
@@ -2881,15 +2882,20 @@ void QgisApp::fileExit()
28812882
}
28822883

28832884

2884-
28852885
void QgisApp::fileNew()
28862886
{
28872887
fileNew( true ); // prompts whether to save project
28882888
} // fileNew()
28892889

28902890

2891+
void QgisApp::fileNewBlank()
2892+
{
2893+
fileNew( true, true );
2894+
}
2895+
2896+
28912897
//as file new but accepts flags to indicate whether we should prompt to save
2892-
void QgisApp::fileNew( bool thePromptToSaveFlag )
2898+
void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
28932899
{
28942900
if ( mMapCanvas && mMapCanvas->isDrawing() )
28952901
{
@@ -2906,16 +2912,19 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
29062912

29072913
// load template instead of loading defaults - or should this be done *after* loading defaults?
29082914
QSettings settings;
2909-
QString projectTemplate = settings.value( "/qgis/newProjectTemplateFile", "" ).toString();
2910-
if ( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() &&
2911-
! projectTemplate.isEmpty() )
2915+
if ( ! forceBlank )
29122916
{
2913-
QgsDebugMsg( QString( "tryingload template: %1 - %2" ).arg( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() ).arg( projectTemplate ) );
2914-
if ( addProject( projectTemplate ) )
2917+
QString projectTemplate = settings.value( "/qgis/newProjectTemplateFile", "" ).toString();
2918+
if ( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() &&
2919+
! projectTemplate.isEmpty() )
29152920
{
2916-
// set null filename so we don't override the template
2917-
QgsProject::instance()->setFileName( QString() );
2918-
return;
2921+
QgsDebugMsg( QString( "loading template: %1 - %2" ).arg( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() ).arg( projectTemplate ) );
2922+
if ( addProject( projectTemplate ) )
2923+
{
2924+
// set null filename so we don't override the template
2925+
QgsProject::instance()->setFileName( QString() );
2926+
return;
2927+
}
29192928
}
29202929
}
29212930

src/app/qgisapp.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
617617
void fileOpen();
618618
//! Create a new project
619619
void fileNew();
620-
//! As above but allows forcing without prompt
621-
void fileNew( bool thePromptToSaveFlag );
620+
//! Create a new blank project (no template)
621+
void fileNewBlank();
622+
//! As above but allows forcing without prompt and forcing blank project
623+
void fileNew( bool thePromptToSaveFlag, bool forceBlank = false );
622624
//! Calculate new rasters from existing ones
623625
void showRasterCalculator();
624626
void embedLayers();

src/ui/qgisapp.ui

+13
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
</widget>
6565
<addaction name="mActionNewProject"/>
6666
<addaction name="mActionOpenProject"/>
67+
<addaction name="mActionNewBlankProject"/>
6768
<addaction name="separator"/>
6869
<addaction name="mRecentProjectsMenu"/>
6970
<addaction name="mActionSaveProject"/>
@@ -1697,6 +1698,18 @@
16971698
<string>Creates a scale bar that is displayed on the map canvas</string>
16981699
</property>
16991700
</action>
1701+
<action name="mActionNewBlankProject">
1702+
<property name="icon">
1703+
<iconset resource="../../images/images.qrc">
1704+
<normaloff>:/images/themes/default/mActionFileNew.png</normaloff>:/images/themes/default/mActionFileNew.png</iconset>
1705+
</property>
1706+
<property name="text">
1707+
<string>New Blank Project</string>
1708+
</property>
1709+
<property name="toolTip">
1710+
<string>New Blank Project</string>
1711+
</property>
1712+
</action>
17001713
</widget>
17011714
<resources>
17021715
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)