Skip to content
Permalink
Browse files
Add default file name parameter for getSaveAsImageName dialog
  • Loading branch information
nyalldawson committed Dec 15, 2013
1 parent 08a10b8 commit 377c13b96bf3f3f030816e9a6e29b2f7c9f794f7
Showing with 16 additions and 4 deletions.
  1. +15 −3 src/gui/qgisgui.cpp
  2. +1 −1 src/gui/qgisgui.h
@@ -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;
@@ -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() )
{
@@ -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 );
@@ -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 );

/**

0 comments on commit 377c13b

Please sign in to comment.