Skip to content
Permalink
Browse files
Saving map defaults to PNG instead of BMP
This only affects a user the first time they save a map as an image.
Afterwards their preference is saved.

FIXES: #8493
  • Loading branch information
michaelkirk committed Jan 26, 2015
1 parent 098aa68 commit 1e936df8d4a6bf9ba0f553ded48601c7d6a91685
Showing with 15 additions and 16 deletions.
  1. +9 −8 src/gui/qgisgui.cpp
  2. +6 −8 src/gui/qgisgui.h
@@ -93,7 +93,7 @@ namespace QgisGui
if ( format == "svg" )
continue;

filterMap.insert( createFileFilter_( format.toUpper() + " format", "*." + format ), format );
filterMap.insert( createFileFilter_( format ), format );
}

#ifdef QGISDEBUG
@@ -104,14 +104,13 @@ namespace QgisGui
}
#endif

//find out the last used filter
QSettings settings; // where we keep last used filter in persistent state
QString lastUsedFilter = settings.value( "/UI/lastSaveAsImageFilter" ).toString();
QString lastUsedDir = settings.value( "/UI/lastSaveAsImageDir", "." ).toString();

QString outputFileName;
QString selectedFilter = lastUsedFilter;
QString ext;
// Prefer "png" format unless the user previously chose a different format
QString pngExtension = "png";
QString pngFilter = createFileFilter_( pngExtension );
QString selectedFilter = settings.value( "/UI/lastSaveAsImageFilter", pngFilter ).toString();

QString initialPath;
if ( defaultFilename.isNull() )
@@ -125,6 +124,8 @@ namespace QgisGui
initialPath = QDir( lastUsedDir ).filePath( defaultFilename );
}

QString outputFileName;
QString ext;
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_LINUX)
outputFileName = QFileDialog::getSaveFileName( theParent, theMessage, initialPath, QStringList( filterMap.keys() ).join( ";;" ), &selectedFilter );

@@ -174,9 +175,9 @@ namespace QgisGui
return qMakePair<QString, QString>( outputFileName, ext );
}

QString createFileFilter_( QString const &longName, QString const &glob )
QString createFileFilter_( QString const &format )
{
return longName + " (" + glob.toLower() + " " + glob.toUpper() + ")";
return QString( "%1 format (*.%2 *.%1)" ).arg( format.toUpper() ).arg( format.toLower() );
}

} // end of QgisGui namespace
@@ -83,14 +83,12 @@ namespace QgisGui
QPair<QString, QString> GUI_EXPORT getSaveAsImageName( QWidget * theParent, QString theMessage, QString defaultFilename = QString::null );

/**
Convenience function for readily creating file filters.
Given a long name for a file filter and a regular expression, return
a file filter string suitable for use in a QFileDialog::OpenFiles()
call. The regular express, glob, will have both all lower and upper
case versions added.
*/
QString createFileFilter_( QString const &longName, QString const &glob );
* Create file filters suitable for use with QFileDialog
*
* @param format extension e.g. "png"
* @return QString e.g. "PNG format (*.png, *.PNG)"
*/
QString createFileFilter_( QString const &format );
}

#endif

0 comments on commit 1e936df

Please sign in to comment.