19 #include <QImageWriter>
29 QString
const &filters, QStringList & selectedFiles, QString& enc, QString &title,
35 QString lastUsedFilter = settings.value(
"/UI/" + filterName,
"" ).toString();
36 QString lastUsedDir = settings.value(
"/UI/" + filterName +
"Dir",
"." ).toString();
38 QgsDebugMsg(
"Opening file dialog with filters: " + filters );
41 selectedFiles = QFileDialog::getOpenFileNames( 0, title, lastUsedDir, filters, &lastUsedFilter );
48 openFileDialog->setFileMode( QFileDialog::ExistingFiles );
50 if ( !lastUsedFilter.isEmpty() )
52 openFileDialog->selectFilter( lastUsedFilter );
55 if ( openFileDialog->exec() == QDialog::Accepted )
57 selectedFiles = openFileDialog->selectedFiles();
69 if ( !selectedFiles.isEmpty() )
74 QString firstFileName = selectedFiles.first();
75 QFileInfo fi( firstFileName );
76 QString path = fi.path();
80 settings.setValue(
"/UI/" + filterName, lastUsedFilter );
81 settings.setValue(
"/UI/" + filterName +
"Dir", path );
86 QPair<QString, QString> GUI_EXPORT
getSaveAsImageName( QWidget *theParent, QString theMessage, QString defaultFilename )
89 QMap<QString, QString> filterMap;
90 foreach ( QByteArray format, QImageWriter::supportedImageFormats() )
93 if ( format ==
"svg" )
96 filterMap.insert(
createFileFilter_( format.toUpper() +
" format",
"*." + format ), format );
101 for ( QMap<QString, QString>::iterator it = filterMap.begin(); it != filterMap.end(); ++it )
109 QString lastUsedFilter = settings.value(
"/UI/lastSaveAsImageFilter" ).toString();
110 QString lastUsedDir = settings.value(
"/UI/lastSaveAsImageDir",
"." ).toString();
112 QString outputFileName;
113 QString selectedFilter = lastUsedFilter;
117 if ( defaultFilename.isNull() )
120 initialPath = lastUsedDir;
125 initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
128 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
129 outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join(
";;" ), &selectedFilter );
131 if ( !outputFileName.isNull() )
133 ext = filterMap.value( selectedFilter, QString::null );
135 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
136 settings.setValue(
"/UI/lastSaveAsImageDir", QFileInfo( outputFileName ).absolutePath() );
140 std::auto_ptr<QFileDialog> fileDialog(
new QFileDialog( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join(
";;" ) ) );
143 fileDialog->setFileMode( QFileDialog::AnyFile );
144 fileDialog->setAcceptMode( QFileDialog::AcceptSave );
145 fileDialog->setConfirmOverwrite(
true );
147 if ( !lastUsedFilter.isEmpty() )
149 fileDialog->selectFilter( lastUsedFilter );
153 if ( fileDialog->exec() == QDialog::Accepted )
155 outputFileName = fileDialog->selectedFiles().first();
158 selectedFilter = fileDialog->selectedFilter();
159 QgsDebugMsg(
"Selected filter: " + selectedFilter );
160 ext = filterMap.value( selectedFilter, QString::null );
163 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
165 settings.setValue(
"/UI/lastSaveAsImageDir", fileDialog->directory().absolutePath() );
169 if ( !ext.isNull() && !outputFileName.toLower().endsWith(
"." + ext.toLower() ) )
171 outputFileName +=
"." + ext;
174 return qMakePair<QString, QString>( outputFileName, ext );
179 return longName +
" (" + glob.toLower() +
" " + glob.toUpper() +
")";