-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QgsSourceSelectProviderRegistry with tests
- Loading branch information
Showing
8 changed files
with
337 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgssourceselectproviderregistry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsSourceSelectProviderRegistry | ||
{ | ||
%Docstring | ||
This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog | ||
When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...) | ||
|
||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgssourceselectproviderregistry.h" | ||
%End | ||
public: | ||
QgsSourceSelectProviderRegistry(); | ||
|
||
~QgsSourceSelectProviderRegistry(); | ||
|
||
|
||
QList< QgsSourceSelectProvider*> providers() const; | ||
%Docstring | ||
Get list of available providers | ||
:rtype: list of QgsSourceSelectProvider | ||
%End | ||
|
||
void addProvider( QgsSourceSelectProvider *provider /Transfer/ ); | ||
%Docstring | ||
Add a provider implementation. Takes ownership of the object. | ||
%End | ||
|
||
void removeProvider( QgsSourceSelectProvider *provider ); | ||
%Docstring | ||
Remove provider implementation from the list (provider object is deleted) | ||
%End | ||
|
||
QgsSourceSelectProvider *providerByName( const QString &name ) const; | ||
%Docstring | ||
Return a provider by name or None if not found | ||
:rtype: QgsSourceSelectProvider | ||
%End | ||
|
||
QList<QgsSourceSelectProvider *> providersByKey( const QString &providerKey ) const; | ||
%Docstring | ||
Return a (possibly empty) list of providers by data provider's key | ||
:rtype: list of QgsSourceSelectProvider | ||
%End | ||
|
||
|
||
private: | ||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh ); | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/qgssourceselectproviderregistry.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
qgssourceselectproviderregistry.cpp - QgsSourceSelectProviderRegistry | ||
--------------------- | ||
begin : 1.9.2017 | ||
copyright : (C) 2017 by Alessandro Pasotti | ||
email : apasotti at boundlessgeo dot com | ||
*************************************************************************** | ||
* * | ||
* 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 "qgssourceselectprovider.h" | ||
#include "qgssourceselectproviderregistry.h" | ||
#include "qgsproviderregistry.h" | ||
|
||
#include <memory> | ||
|
||
typedef QList<QgsSourceSelectProvider *> *sourceSelectProviders_t(); | ||
|
||
|
||
QgsSourceSelectProviderRegistry::QgsSourceSelectProviderRegistry() | ||
{ | ||
QStringList providersList = QgsProviderRegistry::instance()->providerList(); | ||
|
||
Q_FOREACH ( const QString &key, providersList ) | ||
{ | ||
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) ); | ||
if ( !library ) | ||
continue; | ||
|
||
sourceSelectProviders_t *sourceSelectProvidersFn = reinterpret_cast< sourceSelectProviders_t * >( cast_to_fptr( library->resolve( "sourceSelectProviders" ) ) ); | ||
if ( sourceSelectProvidersFn ) | ||
{ | ||
QList<QgsSourceSelectProvider *> *providerList = sourceSelectProvidersFn(); | ||
// the function is a factory - we keep ownership of the returned providers | ||
for ( auto provider : qgsAsConst( *providerList ) ) | ||
{ | ||
addProvider( provider ); | ||
} | ||
delete providerList; | ||
} | ||
} | ||
} | ||
|
||
QgsSourceSelectProviderRegistry::~QgsSourceSelectProviderRegistry() | ||
{ | ||
qDeleteAll( mProviders ); | ||
} | ||
|
||
void QgsSourceSelectProviderRegistry::addProvider( QgsSourceSelectProvider *provider ) | ||
{ | ||
mProviders.append( provider ); | ||
std::sort( mProviders.begin(), mProviders.end(), [ ]( const QgsSourceSelectProvider * first, const QgsSourceSelectProvider * second ) -> bool | ||
{ | ||
return first->ordering() < second->ordering(); | ||
} ); | ||
} | ||
|
||
void QgsSourceSelectProviderRegistry::removeProvider( QgsSourceSelectProvider *provider ) | ||
{ | ||
int index = mProviders.indexOf( provider ); | ||
if ( index >= 0 ) | ||
delete mProviders.takeAt( index ); | ||
} | ||
|
||
QgsSourceSelectProvider *QgsSourceSelectProviderRegistry::providerByName( const QString &name ) const | ||
{ | ||
for ( const auto provider : qgsAsConst( mProviders ) ) | ||
{ | ||
if ( provider->name() == name ) | ||
{ | ||
return provider; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey ) const | ||
{ | ||
QList<QgsSourceSelectProvider *> providerList; | ||
for ( const auto provider : qgsAsConst( mProviders ) ) | ||
{ | ||
if ( provider->providerKey() == providerKey ) | ||
{ | ||
providerList << provider; | ||
} | ||
} | ||
return providerList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*************************************************************************** | ||
qgssourceselectproviderregistry.h - QgsSourceSelectProviderRegistry | ||
--------------------- | ||
begin : 1.9.2017 | ||
copyright : (C) 2017 by Alessandro Pasotti | ||
email : apasotti at boundlessgeo dot com | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSSOURCESELECTPROVIDERREGISTRY_H | ||
#define QGSSOURCESELECTPROVIDERREGISTRY_H | ||
|
||
#include "qgis_gui.h" | ||
#include "qgis.h" | ||
|
||
class QgsSourceSelectProvider; | ||
|
||
/** \ingroup gui | ||
* This class keeps a list of source select providers that may add items to the QgsDataSourceManagerDialog | ||
* When created, it automatically adds providers from data provider plugins (e.g. PostGIS, WMS, ...) | ||
* | ||
* \since QGIS 3.0 | ||
*/ | ||
class GUI_EXPORT QgsSourceSelectProviderRegistry | ||
{ | ||
public: | ||
QgsSourceSelectProviderRegistry(); | ||
|
||
~QgsSourceSelectProviderRegistry(); | ||
|
||
//! QgsDataItemProviderRegistry cannot be copied. | ||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh ) = delete; | ||
//! QgsDataItemProviderRegistry cannot be copied. | ||
QgsSourceSelectProviderRegistry &operator=( const QgsSourceSelectProviderRegistry &rh ) = delete; | ||
|
||
//! Get list of available providers | ||
QList< QgsSourceSelectProvider *> providers() const { return mProviders; } | ||
|
||
//! Add a provider implementation. Takes ownership of the object. | ||
void addProvider( QgsSourceSelectProvider *provider SIP_TRANSFER ); | ||
|
||
//! Remove provider implementation from the list (provider object is deleted) | ||
void removeProvider( QgsSourceSelectProvider *provider ); | ||
|
||
//! Return a provider by name or nullptr if not found | ||
QgsSourceSelectProvider *providerByName( const QString &name ) const; | ||
|
||
//! Return a (possibly empty) list of providers by data provider's key | ||
QList<QgsSourceSelectProvider *> providersByKey( const QString &providerKey ) const; | ||
|
||
|
||
private: | ||
#ifdef SIP_RUN | ||
QgsSourceSelectProviderRegistry( const QgsSourceSelectProviderRegistry &rh ); | ||
#endif | ||
|
||
//! available providers. this class owns the pointers | ||
QList<QgsSourceSelectProvider *> mProviders; | ||
|
||
}; | ||
|
||
#endif // QGSSOURCESELECTPROVIDERREGISTRY_H |
Oops, something went wrong.