Skip to content

Commit

Permalink
Saving map defaults to PNG instead of BMP
Browse files Browse the repository at this point in the history
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 1e936df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/gui/qgisgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() )
Expand All @@ -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 );

Expand Down Expand Up @@ -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
14 changes: 6 additions & 8 deletions src/gui/qgisgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.