18 #include <QImageWriter>
22 #include <QFontDialog>
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->selectNameFilter( 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" )
101 for ( QMap<QString, QString>::iterator it = filterMap.begin(); it != filterMap.end(); ++it )
108 QString lastUsedDir = settings.value(
"/UI/lastSaveAsImageDir",
"." ).toString();
111 QString pngExtension =
"png";
113 QString selectedFilter = settings.value(
"/UI/lastSaveAsImageFilter", pngFilter ).toString();
116 if ( defaultFilename.isNull() )
119 initialPath = lastUsedDir;
124 initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
127 QString outputFileName;
129 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
130 outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join(
";;" ), &selectedFilter );
132 if ( !outputFileName.isNull() )
134 ext = filterMap.value( selectedFilter, QString::null );
136 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
137 settings.setValue(
"/UI/lastSaveAsImageDir", QFileInfo( outputFileName ).absolutePath() );
142 QScopedPointer<QFileDialog> fileDialog(
new QFileDialog( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join(
";;" ) ) );
145 fileDialog->setFileMode( QFileDialog::AnyFile );
146 fileDialog->setAcceptMode( QFileDialog::AcceptSave );
147 fileDialog->setConfirmOverwrite(
true );
149 if ( !selectedFilter.isEmpty() )
151 fileDialog->selectNameFilter( selectedFilter );
155 if ( fileDialog->exec() == QDialog::Accepted )
157 outputFileName = fileDialog->selectedFiles().first();
160 selectedFilter = fileDialog->selectedFilter();
161 QgsDebugMsg(
"Selected filter: " + selectedFilter );
162 ext = filterMap.value( selectedFilter, QString::null );
165 settings.setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
167 settings.setValue(
"/UI/lastSaveAsImageDir", fileDialog->directory().absolutePath() );
171 if ( !ext.isNull() && !outputFileName.toLower().endsWith(
"." + ext.toLower() ) )
173 outputFileName +=
"." + ext;
176 return qMakePair<QString, QString>( outputFileName, ext );
181 return QString(
"%1 (%2 %3)" ).arg( longName ).arg( glob.toLower() ).arg( glob.toUpper() );
186 QString longName = format.toUpper() +
" format";
187 QString glob =
"*." + format;
191 QFont
getFont(
bool &ok,
const QFont &initial,
const QString &title )
196 #if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA)