Skip to content
Permalink
Browse files

add optional default project file which is loaded when fileNew() is c…

…alled
  • Loading branch information
etiennesky committed Jul 17, 2012
1 parent 3a1772f commit f3e0cf5ab77150426817ad5a24e38157715cbad3
Showing with 104 additions and 21 deletions.
  1. +23 −3 src/app/qgisapp.cpp
  2. +30 −0 src/app/qgsoptions.cpp
  3. +2 −0 src/app/qgsoptions.h
  4. +49 −18 src/ui/qgsoptionsbase.ui
@@ -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();
@@ -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
@@ -664,6 +668,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
// update windows
qApp->processEvents();

fileNew(); // prepare empty project

} // QgisApp ctor


@@ -2898,6 +2904,21 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
}
}

// load template instead of loading defaults - or should this be done *after* loading defaults?
QSettings settings;
QString projectTemplate = settings.value( "/qgis/newProjectTemplateFile", "" ).toString();
if ( settings.value( "/qgis/newProjectTemplate", QVariant( false ) ).toBool() &&
! projectTemplate.isEmpty() )
{
QgsDebugMsg( QString( "tryingload 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();

@@ -2910,8 +2931,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
@@ -2976,6 +2995,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)


@@ -57,6 +57,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& ) ) );
@@ -408,6 +409,8 @@ 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() );
@@ -557,6 +560,31 @@ QgsOptions::~QgsOptions()
settings.setValue( "/Windows/Options/row", tabWidget->currentIndex() );
}

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

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 );
}
}

void QgsOptions::on_pbnSelectionColor_clicked()
{
#if QT_VERSION >= 0x040500
@@ -721,6 +749,8 @@ 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/newProjectTemplateFile", leNewProjectTemplate->text().trimmed() );
settings.setValue( "/qgis/nullValue", leNullValue->text() );
settings.setValue( "/qgis/style", cmbStyle->currentText() );

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

public slots:
void on_cbxNewProjectTemplate_toggled( bool );
void on_pbtnNewProjectTemplate_pressed();
//! 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,9 +65,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>823</height>
<y>-22</y>
<width>760</width>
<height>1005</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -91,6 +91,37 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QCheckBox" name="cbxNewProjectTemplate">
<property name="text">
<string>New project template</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leNewProjectTemplate">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbtnNewProjectTemplate">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@@ -806,9 +837,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-174</y>
<width>762</width>
<height>658</height>
<y>0</y>
<width>760</width>
<height>625</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
@@ -1054,8 +1085,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>539</width>
<height>502</height>
<width>760</width>
<height>506</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
@@ -1340,8 +1371,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>270</width>
<height>93</height>
<width>778</width>
<height>436</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
@@ -1421,8 +1452,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>571</width>
<height>620</height>
<width>760</width>
<height>627</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
@@ -1797,8 +1828,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>417</height>
<width>778</width>
<height>436</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
@@ -1971,8 +2002,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>584</height>
<width>760</width>
<height>551</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
@@ -2068,8 +2099,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>355</width>
<height>572</height>
<width>760</width>
<height>554</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">

0 comments on commit f3e0cf5

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