18 #include <QImageWriter> 22 #include <QFontDialog> 38 QgsDebugMsg(
"Opening file dialog with filters: " + filters );
48 openFileDialog->
setFileMode( QFileDialog::ExistingFiles );
50 if ( !lastUsedFilter.
isEmpty() )
55 if ( openFileDialog->
exec() == QDialog::Accepted )
80 settings.
setValue(
"/UI/" + filterName, lastUsedFilter );
81 settings.
setValue(
"/UI/" + filterName +
"Dir", path );
93 if ( format ==
"svg" )
113 QString selectedFilter = settings.value(
"/UI/lastSaveAsImageFilter", pngFilter ).toString();
116 if ( defaultFilename.
isNull() )
119 initialPath = lastUsedDir;
124 initialPath =
QDir( lastUsedDir ).
filePath( defaultFilename );
129 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX) 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() );
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() );
173 outputFileName +=
'.' + ext;
176 return qMakePair<QString, QString>( outputFileName, ext );
196 #if defined(Q_OS_MAC) && defined(QT_MAC_USE_COCOA) bool GUI_EXPORT openFilesRememberingFilter(QString const &filterName, QString const &filters, QStringList &selectedFiles, QString &enc, QString &title, bool cancelAll)
Open files, preferring to have the default file selector be the last one used, if any; also...
A file dialog which lets the user select the preferred encoding type for a data provider.
/namespace QgisGui The QgisGui namespace contains constants and helper functions used throughout the ...
QFont getFont(bool &ok, const QFont &initial, const QString &title)
Show font selection dialog.
QString filePath(const QString &fileName) const
QString createFileFilter_(QString const &longName, QString const &glob)
Convenience function for readily creating file filters.
QList< Key > keys() const
void setValue(const QString &key, const QVariant &value)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
void addCancelAll()
Adds a 'Cancel All' button for the user to click.
QVariant value(const QString &key, const QVariant &defaultValue) const
void setFileMode(FileMode mode)
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
QPair< QString, QString > GUI_EXPORT getSaveAsImageName(QWidget *theParent, const QString &theMessage, const QString &defaultFilename)
A helper function to get an image name from the user.
iterator insert(const Key &key, const T &value)
QStringList selectedFiles() const
void selectNameFilter(const QString &filter)
bool cancelAll()
Returns true if the user clicked 'Cancel All'.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QStringList getOpenFileNames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
QFont getFont(bool *ok, const QFont &initial, QWidget *parent, const QString &title, QFlags< QFontDialog::FontDialogOption > options)
const T value(const Key &key) const