Skip to content
Permalink
Browse files

Merge pull request #1864 from michaelkirk/feature/export-png-first-8493

[fixes #8493] "Save as Image" defaults to PNG
  • Loading branch information
NathanW2 committed Jan 27, 2015
2 parents 1cd7dc6 + d6c969c commit 6dd42cae2046d1a13e3a4069b78473a0b9d818c3
Showing with 70 additions and 7 deletions.
  1. +15 −7 src/gui/qgisgui.cpp
  2. +9 −0 src/gui/qgisgui.h
  3. +1 −0 tests/src/gui/CMakeLists.txt
  4. +45 −0 tests/src/gui/testqgsgui.cpp
@@ -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 );

@@ -176,7 +177,14 @@ namespace QgisGui

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

QString createFileFilter_( QString const &format )
{
QString longName = format.toUpper() + " format";
QString glob = "*." + format;
return createFileFilter_( longName, glob );
}

} // end of QgisGui namespace
@@ -91,6 +91,15 @@ namespace QgisGui
case versions added.
*/
QString GUI_EXPORT 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 GUI_EXPORT createFileFilter_( QString const &format );

}

#endif
@@ -117,6 +117,7 @@ ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp)

#ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)
ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
ADD_QGIS_TEST(qgsguitest testqgsgui.cpp)
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
ADD_QGIS_TEST(dualviewtest testqgsdualview.cpp )
ADD_QGIS_TEST(doublespinbox testqgsdoublespinbox.cpp)
@@ -0,0 +1,45 @@
/***************************************************************************
testqgsgui.cpp
--------------------------------------
Date : 26.1.2015
Copyright : (C) 2015 Michael Kirk
Email : michael at jackpine dot me
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QtTest/QtTest>
#include <qgisgui.h>

class TestQgsGui : public QObject
{
Q_OBJECT
private slots:
void createFileFilterForFormat();
void createFileFilter();

};

void TestQgsGui::createFileFilterForFormat()
{
QString expected = "FOO format (*.foo *.FOO)";
QString actual = QgisGui::createFileFilter_("foo");

QCOMPARE( actual, expected );
}

void TestQgsGui::createFileFilter()
{
QString expected = "My Description (my_regex MY_REGEX)";
QString actual = QgisGui::createFileFilter_("My Description", "my_regex");

QCOMPARE( actual, expected );
}

QTEST_MAIN( TestQgsGui )
#include "testqgsgui.moc"

0 comments on commit 6dd42ca

Please sign in to comment.
You can’t perform that action at this time.