24 #include <QImageWriter>
25 #include <QFontDialog>
26 #include <QApplication>
33 QString
const &filters, QStringList &selectedFiles, QString &enc, QString &title,
39 QString lastUsedFilter = settings.
value(
"/UI/" + filterName,
"" ).toString();
40 QString lastUsedDir = settings.
value(
"/UI/" + filterName +
"Dir", QDir::homePath() ).toString();
42 QgsDebugMsg(
"Opening file dialog with filters: " + filters );
45 selectedFiles = QFileDialog::getOpenFileNames(
nullptr, title, lastUsedDir, filters, &lastUsedFilter );
52 openFileDialog->setFileMode( QFileDialog::ExistingFiles );
54 if ( !lastUsedFilter.isEmpty() )
56 openFileDialog->selectNameFilter( lastUsedFilter );
59 if ( openFileDialog->exec() == QDialog::Accepted )
61 selectedFiles = openFileDialog->selectedFiles();
73 if ( !selectedFiles.isEmpty() )
78 QString firstFileName = selectedFiles.first();
79 QFileInfo fi( firstFileName );
80 QString path = fi.path();
84 settings.
setValue(
"/UI/" + filterName, lastUsedFilter );
85 settings.
setValue(
"/UI/" + filterName +
"Dir", path );
90 QPair<QString, QString> GUI_EXPORT
getSaveAsImageName( QWidget *parent,
const QString &message,
const QString &defaultFilename )
93 QMap<QString, QString> filterMap;
94 const auto supportedImageFormats { QImageWriter::supportedImageFormats() };
95 for (
const QByteArray &format : supportedImageFormats )
98 if ( format ==
"svg" )
106 for ( QMap<QString, QString>::iterator it = filterMap.begin(); it != filterMap.end(); ++it )
113 QString lastUsedDir = settings.
value( QStringLiteral(
"UI/lastSaveAsImageDir" ), QDir::homePath() ).toString();
116 QString pngExtension = QStringLiteral(
"png" );
118 QString selectedFilter = settings.
value( QStringLiteral(
"UI/lastSaveAsImageFilter" ), pngFilter ).toString();
121 if ( defaultFilename.isNull() )
124 initialPath = lastUsedDir;
129 initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
132 QString outputFileName;
134 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
135 outputFileName = QFileDialog::getSaveFileName( parent, message, initialPath, QStringList( filterMap.keys() ).join( QLatin1String(
";;" ) ), &selectedFilter );
137 if ( !outputFileName.isNull() )
139 ext = filterMap.value( selectedFilter, QString() );
141 settings.
setValue( QStringLiteral(
"UI/lastSaveAsImageFilter" ), selectedFilter );
142 settings.
setValue( QStringLiteral(
"UI/lastSaveAsImageDir" ), QFileInfo( outputFileName ).absolutePath() );
147 std::unique_ptr<QFileDialog> fileDialog(
new QFileDialog( parent, message, initialPath, QStringList( filterMap.keys() ).join(
";;" ) ) );
150 fileDialog->setFileMode( QFileDialog::AnyFile );
151 fileDialog->setAcceptMode( QFileDialog::AcceptSave );
152 fileDialog->setOption( QFileDialog::DontConfirmOverwrite,
false );
154 if ( !selectedFilter.isEmpty() )
156 fileDialog->selectNameFilter( selectedFilter );
160 if ( fileDialog->exec() == QDialog::Accepted )
162 outputFileName = fileDialog->selectedFiles().first();
165 selectedFilter = fileDialog->selectedNameFilter();
166 QgsDebugMsg(
"Selected filter: " + selectedFilter );
167 ext = filterMap.value( selectedFilter, QString() );
170 settings.
setValue(
"/UI/lastSaveAsImageFilter", selectedFilter );
172 settings.
setValue(
"/UI/lastSaveAsImageDir", fileDialog->directory().absolutePath() );
176 if ( !ext.isNull() && !outputFileName.endsWith(
'.' + ext.toLower(), Qt::CaseInsensitive ) )
178 outputFileName +=
'.' + ext;
181 return qMakePair<QString, QString>( outputFileName, ext );
186 return QStringLiteral(
"%1 (%2 %3)" ).arg( longName, glob.toLower(), glob.toUpper() );
191 QString longName = format.toUpper() +
" format";
192 QString glob =
"*." + format;
196 QFont
getFont(
bool &ok,
const QFont &initial,
const QString &title )
201 #if defined(Q_OS_MAC)
216 settings.
setValue( key, widget->saveGeometry() );
223 return widget->restoreGeometry( settings.
value( key ).toByteArray() );
229 if ( !keyName.isEmpty() )
233 else if ( widget->objectName().isEmpty() )
235 subKey = QString( widget->metaObject()->className() );
239 subKey = widget->objectName();
241 QString key = QStringLiteral(
"Windows/%1/geometry" ).arg( subKey );
253 int w = s.
value( QStringLiteral(
"/qgis/iconSize" ), 32 ).toInt();
256 if ( dockableToolbar )
266 int adjustedSize = 16;
267 if ( size.width() > 32 )
269 adjustedSize = size.width() - 16;
271 else if ( size.width() == 32 )
275 return QSize( adjustedSize, adjustedSize );
282 return QLocale().toString( value,
'f',
precision );
287 switch ( rasterDataType )
289 case Qgis::DataType::Int16:
290 case Qgis::DataType::UInt16:
291 case Qgis::DataType::Int32:
292 case Qgis::DataType::UInt32:
293 case Qgis::DataType::Byte:
294 case Qgis::DataType::CInt16:
295 case Qgis::DataType::CInt32:
296 case Qgis::DataType::ARGB32:
297 case Qgis::DataType::ARGB32_Premultiplied:
301 case Qgis::DataType::Float32:
302 case Qgis::DataType::CFloat32:
304 return std::numeric_limits<float>::digits10 + 1;
306 case Qgis::DataType::Float64:
307 case Qgis::DataType::CFloat64:
309 return std::numeric_limits<double>::digits10 + 1;
311 case Qgis::DataType::UnknownDataType:
313 return std::numeric_limits<double>::digits10 + 1;
326 QApplication::setOverrideCursor( cursor );
332 QApplication::restoreOverrideCursor();
340 mHasOverride =
false;
341 QApplication::restoreOverrideCursor();
351 while ( QApplication::overrideCursor() )
353 mCursors.emplace_back( QCursor( *QApplication::overrideCursor() ) );
354 QApplication::restoreOverrideCursor();
365 for (
auto it = mCursors.rbegin(); it != mCursors.rend(); ++it )
367 QApplication::setOverrideCursor( *it );