Skip to content
Permalink
Browse files

save default template to <home>/.qgis/default.qgs

  • Loading branch information
etiennesky committed Jul 17, 2012
1 parent e4b9dfc commit 298632e0ba3fd39dd7c417da69d04d0070d5165e
Showing with 74 additions and 21 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +40 −8 src/app/qgsoptions.cpp
  3. +3 −2 src/app/qgsoptions.h
  4. +30 −10 src/ui/qgsoptionsbase.ui
@@ -2914,7 +2914,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
QSettings settings;
if ( ! forceBlank )
{
QString projectTemplate = settings.value( "/qgis/newProjectTemplateFile", "" ).toString();
QString projectTemplate = QgsApplication::qgisSettingsDirPath() + QString( "default.qgs" );
if ( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() &&
! projectTemplate.isEmpty() )
{
@@ -23,6 +23,7 @@
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"

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

#if QT_VERSION >= 0x40500
#include <QNetworkDiskCache>
@@ -410,7 +412,6 @@ 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() );
leNewProjectTemplate->setText( settings.value( "/qgis/newProjectTemplateFile", "" ).toString() );

cmbWheelAction->setCurrentIndex( settings.value( "/qgis/wheel_action", 2 ).toInt() );
spinZoomFactor->setValue( settings.value( "/qgis/zoom_factor", 2 ).toDouble() );
@@ -560,12 +561,7 @@ QgsOptions::~QgsOptions()
settings.setValue( "/Windows/Options/row", tabWidget->currentIndex() );
}

void QgsOptions::on_cbxNewProjectTemplate_toggled( bool checked )
{
pbtnNewProjectTemplate->setEnabled( checked );
leNewProjectTemplate->setEnabled( checked );
}

#if 0
void QgsOptions::on_pbtnNewProjectTemplate_pressed( )
{
QString lastUsedDir = QFileInfo( leNewProjectTemplate->text() ).canonicalFilePath();
@@ -584,6 +580,43 @@ void QgsOptions::on_pbtnNewProjectTemplate_pressed( )
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()
{
@@ -750,7 +783,6 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
settings.setValue( "/qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
settings.setValue( "/qgis/newProjectTemplate", cbxNewProjectTemplate->isChecked() );
settings.setValue( "/qgis/newProjectTemplateFile", leNewProjectTemplate->text().trimmed() );
settings.setValue( "/qgis/nullValue", leNullValue->text() );
settings.setValue( "/qgis/style", cmbStyle->currentText() );

@@ -50,8 +50,9 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
QString theme();

public slots:
void on_cbxNewProjectTemplate_toggled( bool );
void on_pbtnNewProjectTemplate_pressed();
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.
@@ -65,7 +65,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-22</y>
<y>0</y>
<width>760</width>
<height>1005</height>
</rect>
@@ -96,27 +96,47 @@
<item>
<widget class="QCheckBox" name="cbxNewProjectTemplate">
<property name="text">
<string>New project template</string>
<string>Create new project from default project</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leNewProjectTemplate">
<property name="enabled">
<bool>false</bool>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbnSetCurrentProjectDefault">
<property name="text">
<string/>
<string>Set current project as default</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbtnNewProjectTemplate">
<property name="enabled">
<bool>false</bool>
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pbnResetCurrentProjectDefault">
<property name="text">
<string>Browse</string>
<string>Reset default</string>
</property>
</widget>
</item>

0 comments on commit 298632e

Please sign in to comment.
You can’t perform that action at this time.