39 changes: 34 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mMapCanvas = new QgsMapCanvas( this, "theMapCanvas" );
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
"layers are displayed when added to the map" ) );
// set canvas color right away
int myRed = settings.value( "/qgis/default_canvas_color_red", 255 ).toInt();
int myGreen = settings.value( "/qgis/default_canvas_color_green", 255 ).toInt();
int myBlue = settings.value( "/qgis/default_canvas_color_blue", 255 ).toInt();
mMapCanvas->setCanvasColor( QColor( myRed, myGreen, myBlue ) );
setCentralWidget( mMapCanvas );
//set the focus to the map canvas
mMapCanvas->setFocus();
Expand Down Expand Up @@ -542,7 +547,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
// set graphical credential requester
new QgsCredentialDialog( this );

fileNew(); // prepare empty project
qApp->processEvents();

// load providers
Expand Down Expand Up @@ -664,6 +668,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
// update windows
qApp->processEvents();

fileNew(); // prepare empty project

} // QgisApp ctor


Expand Down Expand Up @@ -813,6 +819,7 @@ void QgisApp::createActions()
// File Menu Items

connect( mActionNewProject, SIGNAL( triggered() ), this, SLOT( fileNew() ) );
connect( mActionNewBlankProject, SIGNAL( triggered() ), this, SLOT( fileNewBlank() ) );
connect( mActionOpenProject, SIGNAL( triggered() ), this, SLOT( fileOpen() ) );
connect( mActionSaveProject, SIGNAL( triggered() ), this, SLOT( fileSave() ) );
connect( mActionSaveProjectAs, SIGNAL( triggered() ), this, SLOT( fileSaveAs() ) );
Expand Down Expand Up @@ -2875,15 +2882,20 @@ void QgisApp::fileExit()
}



void QgisApp::fileNew()
{
fileNew( true ); // prompts whether to save project
} // fileNew()


void QgisApp::fileNewBlank()
{
fileNew( true, true );
}


//as file new but accepts flags to indicate whether we should prompt to save
void QgisApp::fileNew( bool thePromptToSaveFlag )
void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
Expand All @@ -2898,6 +2910,24 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
}
}

// load template instead of loading defaults - or should this be done *after* loading defaults?
QSettings settings;
if ( ! forceBlank )
{
QString projectTemplate = QgsApplication::qgisSettingsDirPath() + QString( "default.qgs" );
if ( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() &&
! projectTemplate.isEmpty() )
{
QgsDebugMsg( QString( "loading template: %1 - %2" ).arg( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() ).arg( projectTemplate ) );
if ( addProject( projectTemplate ) )
{
// set null filename so we don't override the template
QgsProject::instance()->setFileName( QString() );
return;
}
}
}

deletePrintComposers();
removeAnnotationItems();

Expand All @@ -2910,8 +2940,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
prj->setFileName( QString::null );
prj->clearProperties(); // why carry over properties from previous projects?

QSettings settings;

//set the color for selections
//the default can be set in qgisoptions
//use project properties to override the color on a per project basis
Expand Down Expand Up @@ -2976,6 +3004,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
mMapCanvas->setMapTool( mMapTools.mTouch );
mNonEditMapTool = mMapTools.mTouch; // signals are not yet setup to catch this
#endif

} // QgisApp::fileNew(bool thePromptToSaveFlag)


Expand Down
6 changes: 4 additions & 2 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void fileOpen();
//! Create a new project
void fileNew();
//! As above but allows forcing without prompt
void fileNew( bool thePromptToSaveFlag );
//! Create a new blank project (no template)
void fileNewBlank();
//! As above but allows forcing without prompt and forcing blank project
void fileNew( bool thePromptToSaveFlag, bool forceBlank = false );
//! Calculate new rasters from existing ones
void showRasterCalculator();
void embedLayers();
Expand Down
62 changes: 62 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"

#include <QFileDialog>
#include <QSettings>
Expand All @@ -31,6 +32,7 @@
#include <QToolBar>
#include <QSize>
#include <QStyleFactory>
#include <QMessageBox>

#if QT_VERSION >= 0x40500
#include <QNetworkDiskCache>
Expand All @@ -57,6 +59,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
QDialog( parent, fl )
{
setupUi( this );

connect( cmbTheme, SIGNAL( activated( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );
connect( cmbTheme, SIGNAL( highlighted( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );
connect( cmbTheme, SIGNAL( textChanged( const QString& ) ), this, SLOT( themeChanged( const QString& ) ) );
Expand Down Expand Up @@ -408,6 +411,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

chbAskToSaveProjectChanges->setChecked( settings.value( "qgis/askToSaveProjectChanges", QVariant( true ) ).toBool() );
chbWarnOldProjectVersion->setChecked( settings.value( "/qgis/warnOldProjectVersion", QVariant( true ) ).toBool() );
cbxNewProjectTemplate->setChecked( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() );

cmbWheelAction->setCurrentIndex( settings.value( "/qgis/wheel_action", 2 ).toInt() );
spinZoomFactor->setValue( settings.value( "/qgis/zoom_factor", 2 ).toDouble() );
Expand Down Expand Up @@ -557,6 +561,63 @@ QgsOptions::~QgsOptions()
settings.setValue( "/Windows/Options/row", tabWidget->currentIndex() );
}

#if 0
void QgsOptions::on_pbtnNewProjectTemplate_pressed( )
{
QString lastUsedDir = QFileInfo( leNewProjectTemplate->text() ).canonicalFilePath();
if ( lastUsedDir == "" )
{
QSettings settings;
lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
}

QString fullPath = QFileDialog::getOpenFileName( this,
tr( "Choose a QGIS project file to open" ),
lastUsedDir,
tr( "QGis files" ) + " (*.qgs *.QGS)" );
if ( ! fullPath.isNull() )
{
leNewProjectTemplate->setText( fullPath );
}
}
#endif

void QgsOptions::on_cbxNewProjectTemplate_toggled( bool checked )
{
if ( checked )
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "default.qgs" );
if ( ! QFile::exists( fileName ) )
{
QMessageBox::information( 0, tr( "Save default project" ), tr( "You must set a default project" ) );
cbxNewProjectTemplate->setChecked( false );
}
}
}

void QgsOptions::on_pbnSetCurrentProjectDefault_clicked( )
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "default.qgs" );
if ( QgsProject::instance()->write( QFileInfo( fileName ) ) )
{
QMessageBox::information( 0, tr( "Save default project" ), tr( "Current project saved as default" ) );
}
else
{
QMessageBox::critical( 0, tr( "Save default project" ), tr( "Error saving current project as default" ) );
}
}

void QgsOptions::on_pbnResetCurrentProjectDefault_clicked( )
{
QString fileName = QgsApplication::qgisSettingsDirPath() + QString( "default.qgs" );
if ( QFile::exists( fileName ) )
{
QFile::remove( fileName );
}
cbxNewProjectTemplate->setChecked( false );
}

void QgsOptions::on_pbnSelectionColor_clicked()
{
#if QT_VERSION >= 0x040500
Expand Down Expand Up @@ -721,6 +782,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
settings.setValue( "/qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
settings.setValue( "/qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
settings.setValue( "/qgis/newProjectTemplate", cbxNewProjectTemplate->isChecked() );
settings.setValue( "/qgis/nullValue", leNullValue->text() );
settings.setValue( "/qgis/style", cmbStyle->currentText() );

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
QString theme();

public slots:
void on_cbxNewProjectTemplate_toggled( bool checked );
void on_pbnSetCurrentProjectDefault_clicked();
void on_pbnResetCurrentProjectDefault_clicked();
//! Slot called when user chooses to change the project wide projection.
void on_pbnSelectProjection_clicked();
//! Slot called when user chooses to change the default 'on the fly' projection.
Expand Down
Loading