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 );
89 QMap<QString, QString> filterMap;
90 foreach ( QByteArray format, QImageWriter::supportedImageFormats() )
93 if ( format ==
"svg" )
96 filterMap.insert(
createFileFilter_( format +
" 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;
116 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
117 outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, lastUsedDir, QStringList( filterMap.keys() ).join(
";;" ), &selectedFilter );
119 if ( !outputFileName.isNull() )
121 ext = filterMap.value( selectedFilter, QString::null );
123 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
124 settings.setValue(
"/UI/lastSaveAsImageDir", QFileInfo( outputFileName ).absolutePath() );
128 std::auto_ptr<QFileDialog> fileDialog(
new QFileDialog( theParent, theMessage, lastUsedDir, QStringList( filterMap.keys() ).join(
";;" ) ) );
131 fileDialog->setFileMode( QFileDialog::AnyFile );
132 fileDialog->setAcceptMode( QFileDialog::AcceptSave );
133 fileDialog->setConfirmOverwrite(
true );
135 if ( !lastUsedFilter.isEmpty() )
137 fileDialog->selectFilter( lastUsedFilter );
141 if ( fileDialog->exec() == QDialog::Accepted )
143 outputFileName = fileDialog->selectedFiles().first();
146 selectedFilter = fileDialog->selectedFilter();
147 QgsDebugMsg(
"Selected filter: " + selectedFilter );
148 ext = filterMap.value( selectedFilter, QString::null );
151 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
153 settings.setValue(
"/UI/lastSaveAsImageDir", fileDialog->directory().absolutePath() );
157 if ( !ext.isNull() && !outputFileName.endsWith(
"." + ext ) )
159 outputFileName +=
"." + ext;
162 return qMakePair<QString, QString>( outputFileName, ext );
167 return longName +
" (" + glob.toLower() +
" " + glob.toUpper() +
")";