Navigation Menu

Skip to content

Commit

Permalink
replace QgsRasterLayer::buildSupportedRasterFileFilter() with QgsProv…
Browse files Browse the repository at this point in the history
…iderRegistry::instance()->fileRasterFilters()
  • Loading branch information
etiennesky committed Jun 14, 2013
1 parent 3efe9e3 commit 7cceaaf
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 45 deletions.
9 changes: 9 additions & 0 deletions python/core/qgsproviderregistry.sip
Expand Up @@ -69,6 +69,15 @@ class QgsProviderRegistry
It'd be nice to eventually be raster/vector neutral.
*/
virtual QString fileVectorFilters() const;
/** return raster file filter string

Returns a string suitable for a QFileDialog of raster file formats
supported by all data providers.

@note this method was added in QGIS 2.0
@note This replaces QgsRasterLayer::buildSupportedRasterFileFilter()
*/
virtual QString fileRasterFilters() const;
/** return a string containing the available database drivers
* @note this method was added in QGIS 1.1
*/
Expand Down
2 changes: 0 additions & 2 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -77,8 +77,6 @@ class QgsRasterLayer : QgsMapLayer
//
// Static methods:
//
static void buildSupportedRasterFileFilter( QString & fileFilters );
static QString buildSupportedRasterFileFilter2(); /* for sip api v2 */

/** This helper checks to see whether the file name appears to be a valid
* raster file name. If the file name looks like it could be valid,
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/GdalTools/tools/GdalTools_utils.py
Expand Up @@ -428,7 +428,7 @@ def setFilter(self, typeName, aFilter):
@classmethod
def allRastersFilter(self):
if self.rastersFilter == '':
self.rastersFilter = QgsRasterLayer.buildSupportedRasterFileFilter2()
self.rastersFilter = QgsProviderRegistry.instance().fileRasterFilters()

# workaround for QGis < 1.5 (see #2376)
# removed as this is a core plugin QGis >= 1.9
Expand Down
10 changes: 4 additions & 6 deletions src/app/qgisapp.cpp
Expand Up @@ -638,11 +638,10 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

mSplash->showMessage( tr( "Initializing file filters" ), Qt::AlignHCenter | Qt::AlignBottom );
qApp->processEvents();
// now build vector file filter
mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();

// now build raster file filter
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
// now build vector and raster file filters
mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
mRasterFileFilter = QgsProviderRegistry::instance()->fileRasterFilters();

// set handler for missing layers (will be owned by QgsProject)
QgsProject::instance()->setBadLayerHandler( new QgsHandleBadLayersHandler() );
Expand Down Expand Up @@ -6596,8 +6595,7 @@ void QgisApp::options()
//do we need this? TS
mMapCanvas->refresh();

mRasterFileFilter.clear();
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
mRasterFileFilter = QgsProviderRegistry::instance()->fileRasterFilters();

if ( oldScales != mySettings.value( "Map/scales", PROJECT_SCALES ).toString() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgshandlebadlayers.cpp
Expand Up @@ -63,7 +63,7 @@ QgsHandleBadLayers::QgsHandleBadLayers( const QList<QDomNode> &layers, const QDo
setupUi( this );

mVectorFileFilter = QgsProviderRegistry::instance()->fileVectorFilters();
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
mRasterFileFilter = QgsProviderRegistry::instance()->fileRasterFilters();

mBrowseButton = new QPushButton( tr( "Browse" ) );
buttonBox->addButton( mBrowseButton, QDialogButtonBox::ActionRole );
Expand Down
22 changes: 22 additions & 0 deletions src/core/qgsproviderregistry.cpp
Expand Up @@ -36,6 +36,7 @@ typedef QString providerkey_t();
typedef QString description_t();
typedef bool isprovider_t();
typedef QString fileVectorFilters_t();
typedef void buildsupportedrasterfilefilter_t( QString & theFileFiltersString );
typedef QString databaseDrivers_t();
typedef QString directoryDrivers_t();
typedef QString protocolDrivers_t();
Expand Down Expand Up @@ -183,6 +184,22 @@ QgsProviderRegistry::QgsProviderRegistry( QString pluginPath )

QgsDebugMsg( QString( "Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileVectorFilters.split( ";;" ).count() ) );
}

// now get raster file filters, if any
// this replaces deprecated QgsRasterLayer::buildSupportedRasterFileFilter
buildsupportedrasterfilefilter_t *pBuild =
( buildsupportedrasterfilefilter_t * ) cast_to_fptr( myLib.resolve( "buildSupportedRasterFileFilter" ) );
if ( pBuild )
{
QString fileRasterFilters;
pBuild( fileRasterFilters );

QgsDebugMsg( "raster filters: "+fileRasterFilters);
if ( !fileRasterFilters.isEmpty() )
mRasterFileFilters += fileRasterFilters;

QgsDebugMsg( QString( "Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileRasterFilters.split( ";;" ).count() ) );
}
}
} // QgsProviderRegistry ctor

Expand Down Expand Up @@ -411,6 +428,11 @@ QString QgsProviderRegistry::fileVectorFilters() const
return mVectorFileFilters;
}

QString QgsProviderRegistry::fileRasterFilters() const
{
return mRasterFileFilters;
}

QString QgsProviderRegistry::databaseDrivers() const
{
return mDatabaseDrivers;
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsproviderregistry.h
Expand Up @@ -100,6 +100,18 @@ class CORE_EXPORT QgsProviderRegistry
It'd be nice to eventually be raster/vector neutral.
*/
virtual QString fileVectorFilters() const;
/** return raster file filter string
Returns a string suitable for a QFileDialog of raster file formats
supported by all data providers.
This walks through all data providers appending calls to their
buildSupportedRasterFileFilter to a string, which is then returned.
@note this method was added in QGIS 2.0
@note This replaces QgsRasterLayer::buildSupportedRasterFileFilter()
*/
virtual QString fileRasterFilters() const;
/** return a string containing the available database drivers
* @note this method was added in QGIS 1.1
*/
Expand Down Expand Up @@ -165,6 +177,9 @@ class CORE_EXPORT QgsProviderRegistry
one time.
*/
QString mVectorFileFilters;
/** file filter string for raster files
*/
QString mRasterFileFilters;
/** Available database drivers string for vector databases
This is a string of form:
Expand Down
28 changes: 0 additions & 28 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -68,7 +68,6 @@ email : tim at linfiniti.com
#include <QTime>

// typedefs for provider plugin functions of interest
typedef void buildsupportedrasterfilefilter_t( QString & theFileFiltersString );
typedef bool isvalidrasterfilename_t( QString const & theFileNameQString, QString & retErrMsg );

#define ERR(message) QGS_ERROR_MESSAGE(message,"Raster layer")
Expand Down Expand Up @@ -162,33 +161,6 @@ QgsRasterLayer::~QgsRasterLayer()
// Static Methods and members
//
/////////////////////////////////////////////////////////
/**
Builds the list of file filter strings to later be used by
QgisApp::addRasterLayer()
We query GDAL for a list of supported raster formats; we then build
a list of file filter strings from that list. We return a string
that contains this list that is suitable for use in a
QFileDialog::getOpenFileNames() call.
*/
void QgsRasterLayer::buildSupportedRasterFileFilter( QString & theFileFiltersString )
{
QgsDebugMsg( "Entered" );
buildsupportedrasterfilefilter_t *pBuild = ( buildsupportedrasterfilefilter_t * ) cast_to_fptr( QgsProviderRegistry::instance()->function( "gdal", "buildSupportedRasterFileFilter" ) );
if ( ! pBuild )
{
QgsDebugMsg( "Could not get buildSupportedRasterFileFilter in gdal provider library" );
return;
}

pBuild( theFileFiltersString );
}

QString QgsRasterLayer::buildSupportedRasterFileFilter2( )
{
QString theFileFiltersString;
buildSupportedRasterFileFilter( theFileFiltersString );
return theFileFiltersString;
}

/**
* This helper checks to see whether the file name appears to be a valid raster file name
Expand Down
3 changes: 0 additions & 3 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -228,9 +228,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
ColorLayer
};

static void buildSupportedRasterFileFilter( QString & fileFilters );
static QString buildSupportedRasterFileFilter2(); /* for sip api v2 */

/** This helper checks to see whether the file name appears to be a valid
* raster file name. If the file name looks like it could be valid,
* but some sort of error occurs in processing the file, the error is
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -48,6 +48,7 @@
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "../../app/qgsrasterlayerproperties.h"
#include "qgsproviderregistry.h"

#include "qgsgeorefdatapoint.h"
#include "qgsgeoreftooladdpoint.h"
Expand Down Expand Up @@ -211,8 +212,7 @@ void QgsGeorefPluginGui::openRaster()
QString otherFiles = tr( "All other files (*)" );
QString lastUsedFilter = s.value( "/Plugin-GeoReferencer/lastusedfilter", otherFiles ).toString();

QString filters;
QgsRasterLayer::buildSupportedRasterFileFilter( filters );
QString filters = QgsProviderRegistry::instance()->fileRasterFilters();
filters.prepend( otherFiles + ";;" );
filters.chop( otherFiles.size() + 2 );
mRasterFileName = QFileDialog::getOpenFileName( this, tr( "Open raster" ), dir, filters, &lastUsedFilter );
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/georeferencer/qgsopenrasterdialog.cpp
Expand Up @@ -64,8 +64,7 @@ void QgsOpenRasterDialog::on_tbnSelectRaster_clicked()

QString lastUsedFilter = settings.value( "/Plugin-GeoReferencer/lastusedfilter" ).toString();

QString filters;
QgsRasterLayer::buildSupportedRasterFileFilter( filters );
QString filters = QgsProviderRegistry::instance()->fileRasterFilters();
filters.prepend( "(*.*);;" );
QString rasterFileName = QFileDialog::getOpenFileName( this, tr( "Choose a name of the raster" ), dir,
filters, &lastUsedFilter );
Expand Down
4 changes: 4 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -1818,6 +1818,8 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString

GDALDriverH jp2Driver = NULL; // first JPEG2000 driver found

QgsGdalProviderBase::registerGdalDrivers();

// Grind through all the drivers and their respective metadata.
// We'll add a file filter for those drivers that have a file
// extension defined for them; the others, well, even though
Expand All @@ -1832,6 +1834,8 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
// start with the default case
theFileFiltersString = QObject::tr( "[GDAL] All files (*)" );

QgsDebugMsg( QString( "GDAL driver count: %1" ).arg( GDALGetDriverCount() ) );

for ( int i = 0; i < GDALGetDriverCount(); ++i )
{
myGdalDriver = GDALGetDriver( i );
Expand Down

0 comments on commit 7cceaaf

Please sign in to comment.