23 #include <QImageWriter>    24 #include <QFontDialog>    25 #include <QApplication>    32       QString 
const &filters, QStringList &selectedFiles, QString &enc, QString &title,
    38     QString lastUsedFilter = settings.
value( 
"/UI/" + filterName, 
"" ).toString();
    39     QString lastUsedDir = settings.
value( 
"/UI/" + filterName + 
"Dir", QDir::homePath() ).toString();
    41     QgsDebugMsg( 
"Opening file dialog with filters: " + filters );
    44       selectedFiles = QFileDialog::getOpenFileNames( 
nullptr, title, lastUsedDir, filters, &lastUsedFilter );
    51       openFileDialog->setFileMode( QFileDialog::ExistingFiles );
    53       if ( !lastUsedFilter.isEmpty() )
    55         openFileDialog->selectNameFilter( lastUsedFilter );
    58       if ( openFileDialog->exec() == QDialog::Accepted )
    60         selectedFiles = openFileDialog->selectedFiles();
    72     if ( !selectedFiles.isEmpty() )
    77       QString firstFileName = selectedFiles.first();
    78       QFileInfo fi( firstFileName );
    79       QString path = fi.path();
    83       settings.
setValue( 
"/UI/" + filterName, lastUsedFilter );
    84       settings.
setValue( 
"/UI/" + filterName + 
"Dir", path );
    89   QPair<QString, QString> GUI_EXPORT 
getSaveAsImageName( QWidget *parent, 
const QString &message, 
const QString &defaultFilename )
    92     QMap<QString, QString> filterMap;
    93     const auto supportedImageFormats { QImageWriter::supportedImageFormats() };
    94     for ( 
const QByteArray &format : supportedImageFormats )
    97       if ( format == 
"svg" )
   104     QgsDebugMsg( QStringLiteral( 
"Available Filters Map: " ) );
   105     for ( QMap<QString, QString>::iterator it = filterMap.begin(); it != filterMap.end(); ++it )
   112     QString lastUsedDir = settings.
value( QStringLiteral( 
"UI/lastSaveAsImageDir" ), QDir::homePath() ).toString();
   115     QString pngExtension = QStringLiteral( 
"png" );
   117     QString selectedFilter = settings.value( QStringLiteral( 
"UI/lastSaveAsImageFilter" ), pngFilter ).toString();
   120     if ( defaultFilename.isNull() )
   123       initialPath = lastUsedDir;
   128       initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
   131     QString outputFileName;
   133 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)   134     outputFileName = QFileDialog::getSaveFileName( parent, message, initialPath, QStringList( filterMap.keys() ).join( QStringLiteral( 
";;" ) ), &selectedFilter );
   136     if ( !outputFileName.isNull() )
   138       ext = filterMap.value( selectedFilter, QString() );
   140         settings.setValue( QStringLiteral( 
"UI/lastSaveAsImageFilter" ), selectedFilter );
   141       settings.setValue( QStringLiteral( 
"UI/lastSaveAsImageDir" ), QFileInfo( outputFileName ).absolutePath() );
   146     std::unique_ptr<QFileDialog> fileDialog( 
new QFileDialog( parent, message, initialPath, QStringList( filterMap.keys() ).join( 
";;" ) ) );
   149     fileDialog->setFileMode( QFileDialog::AnyFile );
   150     fileDialog->setAcceptMode( QFileDialog::AcceptSave );
   151     fileDialog->setOption( QFileDialog::DontConfirmOverwrite, 
false );
   153     if ( !selectedFilter.isEmpty() )     
   155       fileDialog->selectNameFilter( selectedFilter );
   159     if ( fileDialog->exec() == QDialog::Accepted )
   161       outputFileName = fileDialog->selectedFiles().first();
   164     selectedFilter = fileDialog->selectedNameFilter();
   165     QgsDebugMsg( 
"Selected filter: " + selectedFilter );
   166     ext = filterMap.value( selectedFilter, QString() );
   169       settings.setValue( 
"/UI/lastSaveAsImageFilter", selectedFilter );
   171     settings.setValue( 
"/UI/lastSaveAsImageDir", fileDialog->directory().absolutePath() );
   175     if ( !ext.isNull() && !outputFileName.endsWith( 
'.' + ext.toLower(), Qt::CaseInsensitive ) )
   177       outputFileName += 
'.' + ext;
   180     return qMakePair<QString, QString>( outputFileName, ext );
   185     return QStringLiteral( 
"%1 (%2 %3)" ).arg( longName, glob.toLower(), glob.toUpper() );
   190     QString longName = format.toUpper() + 
" format";
   191     QString glob = 
"*." + format;
   195   QFont 
getFont( 
bool &ok, 
const QFont &initial, 
const QString &title )
   200 #if defined(Q_OS_MAC)   215     settings.
setValue( key, widget->saveGeometry() );
   222     return widget->restoreGeometry( settings.
value( key ).toByteArray() );
   228     if ( !keyName.isEmpty() )
   232     else if ( widget->objectName().isEmpty() )
   234       subKey = QString( widget->metaObject()->className() );
   238       subKey = widget->objectName();
   240     QString key = QStringLiteral( 
"Windows/%1/geometry" ).arg( subKey );
   246     QFontMetrics fm( ( QFont() ) );
   247     const double scale = 1.1 * standardSize / 24;
   248     return static_cast< int >( std::floor( std::max( 
Qgis::UI_SCALE_FACTOR * fm.height() * scale, 
static_cast< double >( standardSize ) ) ) );
   254     int w = s.
value( QStringLiteral( 
"/qgis/iconSize" ), 32 ).toInt();
   257     if ( dockableToolbar )
   267     int adjustedSize = 16;
   268     if ( size.width() > 32 )
   270       adjustedSize = size.width() - 16;
   272     else if ( size.width() == 32 )
   276     return QSize( adjustedSize, adjustedSize );
   286   QApplication::setOverrideCursor( cursor );
   292     QApplication::restoreOverrideCursor();
   300   mHasOverride = 
false;
   301   QApplication::restoreOverrideCursor();
   311   while ( QApplication::overrideCursor() )
   313     mCursors.emplace_back( QCursor( *QApplication::overrideCursor() ) );
   314     QApplication::restoreOverrideCursor();
   325   for ( 
auto it = mCursors.rbegin(); it != mCursors.rend(); ++it )
   327     QApplication::setOverrideCursor( *it );
 A file dialog which lets the user select the preferred encoding type for a data provider. 
 
QgsTemporaryCursorRestoreOverride()
Constructor for QgsTemporaryCursorRestoreOverride. 
 
QString createFileFilter_(QString const &longName, QString const &glob)
Convenience function for readily creating file filters. 
 
static const double UI_SCALE_FACTOR
UI scaling factor. 
 
This class is a composition of two QSettings instances: 
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key. 
 
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
 
~QgsTemporaryCursorRestoreOverride()
 
~QgsTemporaryCursorOverride()
 
QPair< QString, QString > GUI_EXPORT getSaveAsImageName(QWidget *parent, const QString &message, const QString &defaultFilename)
A helper function to get an image name from the user. 
 
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings. 
 
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings. 
 
QSize panelIconSize(QSize size)
Returns dockable panel toolbar icon width based on the provided window toolbar width. 
 
The QgsGuiUtils namespace contains constants and helper functions used throughout the QGIS GUI...
 
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons. 
 
void addCancelAll()
Adds a 'Cancel All' button for the user to click. 
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value. 
 
void restore()
Restores the cursor override early (i.e. 
 
void release()
Releases the cursor override early (i.e. 
 
bool cancelAll()
Returns true if the user clicked 'Cancel All'. 
 
QString createWidgetKey(QWidget *widget, const QString &keyName)
Creates a key for the given widget that can be used to store related data in settings. 
 
QgsTemporaryCursorOverride(const QCursor &cursor)
Constructor for QgsTemporaryCursorOverride. 
 
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...
 
QFont getFont(bool &ok, const QFont &initial, const QString &title)
Show font selection dialog.