57 QgsProviderRegistry::QgsProviderRegistry(
const QString& pluginPath )
65 char **argv = qApp->argv();
67 int bin = appDir.
findRev(
"/bin", -1,
false );
69 QString mLibraryDirectory = baseDir +
"/lib";
71 mLibraryDirectory = pluginPath;
76 void QgsProviderRegistry::init()
78 mLibraryDirectory.
setSorting( QDir::Name | QDir::IgnoreCase );
79 mLibraryDirectory.
setFilter( QDir::Files | QDir::NoSymLinks );
81 #if defined(Q_OS_WIN) || defined(__CYGWIN__) 83 #elif defined(ANDROID) 91 if ( mLibraryDirectory.
count() == 0 )
94 msg +=
QObject::tr(
"No vector layers can be loaded. Check your QGIS installation" );
104 QString filePattern = getenv(
"QGIS_PROVIDER_FILE" );
117 QgsDebugMsg(
"provider " + fi.
fileName() +
" skipped because doesn't match pattern " + filePattern );
125 QgsDebugMsg(
QString(
"Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName(), myLib.errorString() ) );
134 QgsDebugMsg(
QString(
"Checking %1: ...invalid (has type method)" ).arg( myLib.fileName() ) );
142 QgsDebugMsg(
QString(
"Checking %1: ...invalid (no isProvider method)" ).arg( myLib.fileName() ) );
149 QgsDebugMsg(
QString(
"Checking %1: ...invalid (not a provider)" ).arg( myLib.fileName() ) );
157 QgsDebugMsg(
QString(
"Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
164 QgsDebugMsg(
QString(
"Checking %1: ...invalid (no providerKey method)" ).arg( myLib.fileName() ) );
173 if ( pDatabaseDrivers )
175 mDatabaseDrivers = pDatabaseDrivers();
180 if ( pDirectoryDrivers )
182 mDirectoryDrivers = pDirectoryDrivers();
187 if ( pProtocolDrivers )
189 mProtocolDrivers = pProtocolDrivers();
194 if ( pFileVectorFilters )
198 if ( !fileVectorFilters.
isEmpty() )
199 mVectorFileFilters += fileVectorFilters;
201 QgsDebugMsg(
QString(
"Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileVectorFilters.
split(
";;" ).
count() ) );
211 pBuild( fileRasterFilters );
213 QgsDebugMsg(
"raster filters: " + fileRasterFilters );
214 if ( !fileRasterFilters.
isEmpty() )
215 mRasterFileFilters += fileRasterFilters;
217 QgsDebugMsg(
QString(
"Checking %1: ...loaded ok (%2 file filters)" ).arg( myLib.fileName() ).arg( fileRasterFilters.
split(
";;" ).
count() ) );
226 void QgsProviderRegistry::clean()
230 Providers::const_iterator it = mProviders.begin();
232 while ( it != mProviders.end() )
235 QString lib = it->second->library();
237 if ( myLib.isLoaded() )
265 QgsProviderRegistry::Providers::const_iterator i =
266 metaData.find( providerKey );
268 if ( i != metaData.end() )
293 Providers::const_iterator it = mProviders.begin();
295 if ( mProviders.empty() )
296 return QObject::tr(
"No data provider plugins are available. No vector layers can be loaded" );
303 while ( it != mProviders.end() )
308 list += it->second->description();
326 mLibraryDirectory = path;
333 return mLibraryDirectory;
357 #ifdef TESTPROVIDERLIB 358 const char *cLib = lib.
toUtf8();
362 void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
412 if ( !dataCapabilities )
417 return dataCapabilities();
429 if ( !selectFactory )
432 return selectFactory( parent, fl );
435 #if QT_VERSION >= 0x050000 491 typedef void registerGui_function(
QWidget * parent );
495 registerGui_function *registerGui =
reinterpret_cast< registerGui_function *
>(
cast_to_fptr(
function( provider,
"registerGui" ) ) );
500 registerGui( parent );
506 return mVectorFileFilters;
511 return mRasterFileFilters;
516 return mDatabaseDrivers;
521 return mDirectoryDrivers;
526 return mProtocolDrivers;
532 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
QgsDataProvider * classFactoryFunction_t(const QString *)
QString databaseDrivers_t()
void cleanupProviderFunction_t()
static QgsProviderMetadata * findMetadata_(QgsProviderRegistry::Providers const &metaData, QString const &providerKey)
Convenience function for finding any existing data providers that match "providerKey".
void setNameFilters(const QStringList &nameFilters)
int findRev(QChar c, int i, bool cs) const
const QDir & libraryDirectory() const
Return library directory where plugins are found.
virtual void setTitle(const QString &title)=0
set title for the messages
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static void warning(const QString &msg)
Goes to qWarning.
virtual QString protocolDrivers() const
Return a string containing the available protocol drivers.
QLibrary * providerLibrary(const QString &providerKey) const
QString library(const QString &providerKey) const
Return path for the library of the provider.
void registerGuis(QWidget *widget)
virtual QString databaseDrivers() const
Return a string containing the available database drivers.
QString directoryDrivers_t()
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
Abstract base class for spatial data provider implementations.
void removeAllMapLayers()
Removes all registered layers.
virtual ~QgsProviderRegistry()
Virtual dectructor.
void setSorting(QFlags< QDir::SortFlag > sort)
QString tr(const char *sourceText, const char *disambiguation, int n)
QWidget * selectFactoryFunction_t(QWidget *parent, Qt::WindowFlags fl)
virtual QString name() const =0
Return a provider name.
virtual QString fileVectorFilters() const
Return vector file filter string.
void setPattern(const QString &pattern)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void setFilter(QFlags< QDir::Filter > filters)
int count(const T &value) const
void append(const T &value)
QgsDataProvider * provider(const QString &providerKey, const QString &dataSource)
Create an instance of the provider.
QWidget * selectWidget(const QString &providerKey, QWidget *parent=nullptr, const Qt::WindowFlags &fl=Qt::WindowFlags())
Returns a widget for selecting layers from a provider.
QFileInfoList entryInfoList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
virtual void setMessage(const QString &message, MessageType msgType)=0
set message, it won't be displayed until
void setLibraryDirectory(const QDir &path)
Set library directory where to search for plugins.
const QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Return metadata of the provider or NULL if not found.
QString pluginList(bool asHtml=false) const
Return list of provider plugins found.
void buildsupportedrasterfilefilter_t(QString &theFileFiltersString)
QString fileVectorFilters_t()
std::map< QString, QgsProviderMetadata * > Providers
Open the given vector data source.
A registry / canonical manager of data providers.
int providerCapabilities(const QString &providerKey) const
Return the provider capabilities.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void * resolve(const char *symbol)
virtual QString directoryDrivers() const
Return a string containing the available directory drivers.
virtual QString fileRasterFilters() const
Return raster file filter string.
QString left(int n) const
void * function(const QString &providerKey, const QString &functionName)
Get pointer to provider function.
void(*)() cast_to_fptr(void *p)
QString protocolDrivers_t()
QStringList providerList() const
Return list of available providers by their keys.
Interface for showing messages from QGIS in GUI independent way.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QByteArray toAscii() const
QString errorString() const
QByteArray toUtf8() const