@@ -83,7 +83,7 @@ namespace QgisGui
8383 return false ;
8484 }
8585
86- QPair<QString, QString> GUI_EXPORT getSaveAsImageName ( QWidget *theParent, QString theMessage )
86+ QPair<QString, QString> GUI_EXPORT getSaveAsImageName ( QWidget *theParent, QString theMessage, QString defaultFilename )
8787 {
8888 // get a list of supported output image types
8989 QMap<QString, QString> filterMap;
@@ -113,8 +113,20 @@ namespace QgisGui
113113 QString selectedFilter = lastUsedFilter;
114114 QString ext;
115115
116+ QString initialPath;
117+ if ( defaultFilename.isNull () )
118+ {
119+ // no default filename provided, just use last directory
120+ initialPath = lastUsedDir;
121+ }
122+ else
123+ {
124+ // a default filename was provided, so use it to build the initial path
125+ initialPath = QDir ( lastUsedDir ).filePath ( defaultFilename );
126+ }
127+
116128#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
117- outputFileName = QFileDialog::getSaveFileName ( theParent, theMessage, lastUsedDir , QStringList ( filterMap.keys () ).join ( " ;;" ), &selectedFilter );
129+ outputFileName = QFileDialog::getSaveFileName ( theParent, theMessage, initialPath , QStringList ( filterMap.keys () ).join ( " ;;" ), &selectedFilter );
118130
119131 if ( !outputFileName.isNull () )
120132 {
@@ -125,7 +137,7 @@ namespace QgisGui
125137 }
126138#else
127139 // create a file dialog using the filter list generated above
128- std::auto_ptr<QFileDialog> fileDialog ( new QFileDialog ( theParent, theMessage, lastUsedDir , QStringList ( filterMap.keys () ).join ( " ;;" ) ) );
140+ std::auto_ptr<QFileDialog> fileDialog ( new QFileDialog ( theParent, theMessage, initialPath , QStringList ( filterMap.keys () ).join ( " ;;" ) ) );
129141
130142 // allow for selection of more than one file
131143 fileDialog->setFileMode ( QFileDialog::AnyFile );
0 commit comments