Skip to content
Permalink
Browse files
use project title as default filename in Save and Save as dialogs
(implements #4326)
  • Loading branch information
alexbruy committed Dec 15, 2011
1 parent 5b6ed1e commit de92cacf51295dff2023f6deea0c1a2148e8453a
Showing with 24 additions and 10 deletions.
  1. +24 −10 src/app/qgisapp.cpp
@@ -2795,6 +2795,7 @@ bool QgisApp::fileSave()
saveFileDialog->setFileMode( QFileDialog::AnyFile );
saveFileDialog->setAcceptMode( QFileDialog::AcceptSave );
saveFileDialog->setConfirmOverwrite( true );
saveFileDialog->selectFile( QgsProject::instance()->title() );

if ( saveFileDialog->exec() == QDialog::Accepted )
{
@@ -2840,8 +2841,6 @@ bool QgisApp::fileSave()
return true;
} // QgisApp::fileSave



void QgisApp::fileSaveAs()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
@@ -2852,29 +2851,44 @@ void QgisApp::fileSaveAs()
// Retrieve last used project dir from persistent settings
QSettings settings;
QString lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
QString saveFilePath = QFileDialog::getSaveFileName( this, tr( "Choose a file name to save the QGIS project file as" ), lastUsedDir, tr( "QGis files (*.qgs)" ) );
if ( saveFilePath.isNull() ) //canceled

std::auto_ptr<QFileDialog> saveFileDialog( new QFileDialog( this,
tr( "Choose a file name to save the QGIS project file as" ),
lastUsedDir, tr( "QGis files (*.qgs)" ) ) );
saveFileDialog->setFileMode( QFileDialog::AnyFile );
saveFileDialog->setAcceptMode( QFileDialog::AcceptSave );
saveFileDialog->setConfirmOverwrite( true );
saveFileDialog->selectFile( QgsProject::instance()->title() );

QFileInfo fullPath;
if ( saveFileDialog->exec() == QDialog::Accepted )
{
//saveFilePath = saveFileDialog->selectedFiles().first();
fullPath.setFile( saveFileDialog->selectedFiles().first() );
}
else
{
return;
}
QFileInfo myFI( saveFilePath );
QString myPath = myFI.path();

QString myPath = fullPath.path();
settings.setValue( "/UI/lastProjectDir", myPath );

// make sure the .qgs extension is included in the path name. if not, add it...
if ( "qgs" != myFI.suffix() )
if ( "qgs" != fullPath.suffix() )
{
saveFilePath = myFI.filePath() + ".qgs";
myPath = fullPath.filePath() + ".qgs";
fullPath.setFile( myPath );
}

QgsProject::instance()->setFileName( saveFilePath );
QgsProject::instance()->setFileName( fullPath.filePath() );

if ( QgsProject::instance()->write() )
{
setTitleBarText_( *this ); // update title bar
statusBar()->showMessage( tr( "Saved project to: %1" ).arg( QgsProject::instance()->fileName() ) );
// add this to the list of recently used project files
saveRecentProjectPath( saveFilePath, settings );
saveRecentProjectPath( fullPath.filePath(), settings );
}
else
{

0 comments on commit de92cac

Please sign in to comment.