Skip to content

Commit 8618836

Browse files
committed
use project title as default filename in Save and Save as dialogs
(implements #4326)
1 parent 4d80762 commit 8618836

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/app/qgisapp.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,7 @@ bool QgisApp::fileSave()
27622762
saveFileDialog->setFileMode( QFileDialog::AnyFile );
27632763
saveFileDialog->setAcceptMode( QFileDialog::AcceptSave );
27642764
saveFileDialog->setConfirmOverwrite( true );
2765+
saveFileDialog->selectFile( QgsProject::instance()->title() );
27652766

27662767
if ( saveFileDialog->exec() == QDialog::Accepted )
27672768
{
@@ -2807,8 +2808,6 @@ bool QgisApp::fileSave()
28072808
return true;
28082809
} // QgisApp::fileSave
28092810

2810-
2811-
28122811
void QgisApp::fileSaveAs()
28132812
{
28142813
if ( mMapCanvas && mMapCanvas->isDrawing() )
@@ -2819,29 +2818,44 @@ void QgisApp::fileSaveAs()
28192818
// Retrieve last used project dir from persistent settings
28202819
QSettings settings;
28212820
QString lastUsedDir = settings.value( "/UI/lastProjectDir", "." ).toString();
2822-
QString saveFilePath = QFileDialog::getSaveFileName( this, tr( "Choose a file name to save the QGIS project file as" ), lastUsedDir, tr( "QGis files (*.qgs)" ) );
2823-
if ( saveFilePath.isNull() ) //canceled
2821+
2822+
std::auto_ptr<QFileDialog> saveFileDialog( new QFileDialog( this,
2823+
tr( "Choose a file name to save the QGIS project file as" ),
2824+
lastUsedDir, tr( "QGis files (*.qgs)" ) ) );
2825+
saveFileDialog->setFileMode( QFileDialog::AnyFile );
2826+
saveFileDialog->setAcceptMode( QFileDialog::AcceptSave );
2827+
saveFileDialog->setConfirmOverwrite( true );
2828+
saveFileDialog->selectFile( QgsProject::instance()->title() );
2829+
2830+
QFileInfo fullPath;
2831+
if ( saveFileDialog->exec() == QDialog::Accepted )
2832+
{
2833+
//saveFilePath = saveFileDialog->selectedFiles().first();
2834+
fullPath.setFile( saveFileDialog->selectedFiles().first() );
2835+
}
2836+
else
28242837
{
28252838
return;
28262839
}
2827-
QFileInfo myFI( saveFilePath );
2828-
QString myPath = myFI.path();
2840+
2841+
QString myPath = fullPath.path();
28292842
settings.setValue( "/UI/lastProjectDir", myPath );
28302843

28312844
// make sure the .qgs extension is included in the path name. if not, add it...
2832-
if ( "qgs" != myFI.suffix() )
2845+
if ( "qgs" != fullPath.suffix() )
28332846
{
2834-
saveFilePath = myFI.filePath() + ".qgs";
2847+
myPath = fullPath.filePath() + ".qgs";
2848+
fullPath.setFile( myPath );
28352849
}
28362850

2837-
QgsProject::instance()->setFileName( saveFilePath );
2851+
QgsProject::instance()->setFileName( fullPath.filePath() );
28382852

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

0 commit comments

Comments
 (0)