Skip to content

Commit 377c13b

Browse files
committed
Add default file name parameter for getSaveAsImageName dialog
1 parent 08a10b8 commit 377c13b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/gui/qgisgui.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -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 );

src/gui/qgisgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace QgisGui
8383
* the file type
8484
* @note added in 1.6
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 = NULL );
8787

8888
/**
8989

0 commit comments

Comments
 (0)