Skip to content

Commit

Permalink
Add default file name parameter for getSaveAsImageName dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2013
1 parent 08a10b8 commit 377c13b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/gui/qgisgui.cpp
Expand Up @@ -83,7 +83,7 @@ namespace QgisGui
return false;
}

QPair<QString, QString> GUI_EXPORT getSaveAsImageName( QWidget *theParent, QString theMessage )
QPair<QString, QString> GUI_EXPORT getSaveAsImageName( QWidget *theParent, QString theMessage, QString defaultFilename )
{
// get a list of supported output image types
QMap<QString, QString> filterMap;
Expand Down Expand Up @@ -113,8 +113,20 @@ namespace QgisGui
QString selectedFilter = lastUsedFilter;
QString ext;

QString initialPath;
if ( defaultFilename.isNull() )
{
//no default filename provided, just use last directory
initialPath = lastUsedDir;
}
else
{
//a default filename was provided, so use it to build the initial path
initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
}

#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, lastUsedDir, QStringList( filterMap.keys() ).join( ";;" ), &selectedFilter );
outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join( ";;" ), &selectedFilter );

if ( !outputFileName.isNull() )
{
Expand All @@ -125,7 +137,7 @@ namespace QgisGui
}
#else
//create a file dialog using the filter list generated above
std::auto_ptr<QFileDialog> fileDialog( new QFileDialog( theParent, theMessage, lastUsedDir, QStringList( filterMap.keys() ).join( ";;" ) ) );
std::auto_ptr<QFileDialog> fileDialog( new QFileDialog( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join( ";;" ) ) );

// allow for selection of more than one file
fileDialog->setFileMode( QFileDialog::AnyFile );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgisgui.h
Expand Up @@ -83,7 +83,7 @@ namespace QgisGui
* the file type
* @note added in 1.6
*/
QPair<QString, QString> GUI_EXPORT getSaveAsImageName( QWidget * theParent, QString theMessage );
QPair<QString, QString> GUI_EXPORT getSaveAsImageName( QWidget * theParent, QString theMessage, QString defaultFilename = NULL );

/**
Expand Down

0 comments on commit 377c13b

Please sign in to comment.