Skip to content

Commit

Permalink
use project title as default filename in Save and Save as dialogs
Browse files Browse the repository at this point in the history
(implements #4326)
  • Loading branch information
alexbruy committed Dec 15, 2011
1 parent 4d80762 commit 8618836
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2762,6 +2762,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 )
{
Expand Down Expand Up @@ -2807,8 +2808,6 @@ bool QgisApp::fileSave()
return true;
} // QgisApp::fileSave



void QgisApp::fileSaveAs()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
Expand All @@ -2819,29 +2818,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
{
Expand Down

0 comments on commit 8618836

Please sign in to comment.