Skip to content
Permalink
Browse files

replace QgsRasterLayer::buildSupportedRasterFileFilter() with QgsProv…

…iderRegistry::instance()->fileRasterFilters()
  • Loading branch information
etiennesky committed Jun 14, 2013
1 parent 3efe9e3 commit 7cceaaf73b641149acad26edef3c91d63de0fac1
@@ -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
*/
@@ -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,
@@ -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
@@ -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() );
@@ -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() )
{
@@ -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 );
@@ -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();
@@ -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

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

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

QString QgsProviderRegistry::databaseDrivers() const
{
return mDatabaseDrivers;
@@ -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
*/
@@ -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:
@@ -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")
@@ -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
@@ -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
@@ -48,6 +48,7 @@
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "../../app/qgsrasterlayerproperties.h"
#include "qgsproviderregistry.h"

#include "qgsgeorefdatapoint.h"
#include "qgsgeoreftooladdpoint.h"
@@ -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 );
@@ -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 );
@@ -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
@@ -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 );

0 comments on commit 7cceaaf

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