Skip to content

Commit

Permalink
Rename some QgsProviderRegistry methods to clarify that they are fact…
Browse files Browse the repository at this point in the history
…ories

- provider() was renamed to createProvider()
- selectWidget() was renamed to createSelectionWidget()
- providerLibrary() was renamed to createProviderLibrary()
  • Loading branch information
nyalldawson committed May 6, 2017
1 parent 6502864 commit ba2fdf0
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 61 deletions.
8 changes: 8 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,14 @@ QgsProjectPropertyValue {#qgis_api_break_3_0_QgsProjectPropertyValue}

- The unused count() and entryList() methods were removed.

QgsProviderRegistry {#qgis_api_break_3_0_QgsProviderRegistry}
-------------------

- provider() was renamed to createProvider()
- selectWidget() was renamed to createSelectionWidget()
- providerLibrary() was renamed to createProviderLibrary()


QgsRaster {#qgis_api_break_3_0_QgsRaster}
---------

Expand Down
12 changes: 6 additions & 6 deletions python/core/qgsproviderregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Return list of provider plugins found
Set library directory where to search for plugins
%End

QgsDataProvider *provider( const QString &providerKey,
const QString &dataSource ) /Factory/;
QgsDataProvider *createProvider( const QString &providerKey,
const QString &dataSource ) /Factory/;
%Docstring
Create a new instance of a provider.
Creates a new instance of a provider.
\param providerKey identificator of the provider
\param dataSource string containing data source for the provider
:return: new instance of provider or NULL on error
Expand All @@ -87,8 +87,8 @@ Set library directory where to search for plugins
:rtype: int
%End

QWidget *selectWidget( const QString &providerKey,
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
%Docstring
Returns a new widget for selecting layers from a provider.
Either the ``parent`` widget must be set or the caller becomes
Expand All @@ -107,7 +107,7 @@ Set library directory where to search for plugins
:rtype: QFunctionPointer
%End

QLibrary *providerLibrary( const QString &providerKey ) const /Factory/;
QLibrary *createProviderLibrary( const QString &providerKey ) const /Factory/;
%Docstring
Returns a new QLibrary for the specified ``providerKey``. Ownership of the returned
object is transferred to the caller and the caller is responsible for deleting it.
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/MetaSearch/dialogs/maindialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ def add_to_ows(self):
self.settings.endGroup()

# open provider window
ows_provider = QgsProviderRegistry.instance().selectWidget(stype[2],
self)
ows_provider = QgsProviderRegistry.instance().createSelectionWidget(stype[2],
self)
service_type = stype[0]

# connect dialog signals to iface slots
Expand Down
24 changes: 12 additions & 12 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4371,7 +4371,7 @@ void QgisApp::addDatabaseLayer()
QgsDebugMsg( "about to addRasterLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "postgres" ), this ) );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "postgres" ), this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "PostgreSQL" ), tr( "Cannot get PostgreSQL select dialog from provider." ) );
Expand Down Expand Up @@ -4461,7 +4461,7 @@ void QgisApp::addDatabaseLayers( QStringList const &layerPathList, QString const
void QgisApp::addSpatiaLiteLayer()
{
// show the SpatiaLite dialog
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "spatialite" ), this ) );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "spatialite" ), this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "SpatiaLite" ), tr( "Cannot get SpatiaLite select dialog from provider." ) );
Expand All @@ -4476,7 +4476,7 @@ void QgisApp::addSpatiaLiteLayer()
void QgisApp::addDelimitedTextLayer()
{
// show the Delimited text dialog
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "delimitedtext" ), this ) );
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "delimitedtext" ), this ) );
if ( !dts )
{
QMessageBox::warning( this, tr( "Delimited Text" ), tr( "Cannot get Delimited Text select dialog from provider." ) );
Expand All @@ -4491,7 +4491,7 @@ void QgisApp::addDelimitedTextLayer()
void QgisApp::addVirtualLayer()
{
// show the Delimited text dialog
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "virtual" ), this ) );
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "virtual" ), this ) );
if ( !dts )
{
QMessageBox::warning( this, tr( "Virtual layer" ), tr( "Cannot get virtual layer select dialog from provider." ) );
Expand Down Expand Up @@ -4532,7 +4532,7 @@ void QgisApp::replaceSelectedVectorLayer( const QString &oldId, const QString &u
void QgisApp::addMssqlLayer()
{
// show the MSSQL dialog
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "mssql" ), this ) );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "mssql" ), this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "MSSQL" ), tr( "Cannot get MSSQL select dialog from provider." ) );
Expand All @@ -4548,7 +4548,7 @@ void QgisApp::addDb2Layer()
{
// show the DB2 dialog
QgsDebugMsg( "Show dialog for DB2 " );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "DB2" ), this ) );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "DB2" ), this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "DB2" ), tr( "Cannot get DB2 select dialog from provider." ) );
Expand All @@ -4564,7 +4564,7 @@ void QgisApp::addOracleLayer()
{
#ifdef HAVE_ORACLE
// show the Oracle dialog
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( "oracle", this ) );
QDialog *dbs = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( "oracle", this ) );
if ( !dbs )
{
QMessageBox::warning( this, tr( "Oracle" ), tr( "Cannot get Oracle select dialog from provider." ) );
Expand All @@ -4587,7 +4587,7 @@ void QgisApp::addWmsLayer()
QgsDebugMsg( "about to addRasterLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "wms" ), this ) );
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
if ( !wmss )
{
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
Expand All @@ -4604,7 +4604,7 @@ void QgisApp::addWcsLayer()
QgsDebugMsg( "about to addWcsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wcss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "wcs" ), this ) );
QDialog *wcss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wcs" ), this ) );
if ( !wcss )
{
QMessageBox::warning( this, tr( "WCS" ), tr( "Cannot get WCS select dialog from provider." ) );
Expand All @@ -4621,7 +4621,7 @@ void QgisApp::addWfsLayer()
QgsDebugMsg( "about to addWfsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wfss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "WFS" ), this ) );
QDialog *wfss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "WFS" ), this ) );
if ( !wfss )
{
QMessageBox::warning( this, tr( "WFS" ), tr( "Cannot get WFS select dialog from provider." ) );
Expand Down Expand Up @@ -4650,7 +4650,7 @@ void QgisApp::addAfsLayer()
QgsDebugMsg( "about to addAfsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "arcgisfeatureserver" ), this ) );
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgisfeatureserver" ), this ) );
if ( !afss )
{
QMessageBox::warning( this, tr( "ArcGIS Feature Server" ), tr( "Cannot get ArcGIS Feature Server select dialog from provider." ) );
Expand Down Expand Up @@ -4684,7 +4684,7 @@ void QgisApp::addAmsLayer()
QgsDebugMsg( "about to addAmsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QgsSourceSelectDialog *amss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->selectWidget( QStringLiteral( "arcgismapserver" ), this ) );
QgsSourceSelectDialog *amss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgismapserver" ), this ) );
if ( !amss )
{
QMessageBox::warning( this, tr( "ArcGIS Map Server" ), tr( "Cannot get ArcGIS Map Server select dialog from provider." ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ void QgsZipItem::init()
QgsDebugMsgLevel( "provider " + k, 3 );
// some providers hangs with empty uri (Postgis) etc...
// -> using libraries directly
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->providerLibrary( k ) );
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( k ) );
if ( library )
{
dataCapabilities_t *dataCapabilities = reinterpret_cast< dataCapabilities_t * >( cast_to_fptr( library->resolve( "dataCapabilities" ) ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdataitemproviderregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QgsDataItemProviderRegistry::QgsDataItemProviderRegistry()

Q_FOREACH ( const QString &key, providersList )
{
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->providerLibrary( key ) );
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
if ( !library )
continue;

Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsproviderregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ typedef QgsDataProvider *classFactoryFunction_t( const QString * );
* It seems more sensible to provide the code in one place rather than
* in qgsrasterlayer, qgsvectorlayer, serversourceselect, etc.
*/
QgsDataProvider *QgsProviderRegistry::provider( QString const &providerKey, QString const &dataSource )
QgsDataProvider *QgsProviderRegistry::createProvider( QString const &providerKey, QString const &dataSource )
{
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?
Expand Down Expand Up @@ -422,7 +422,7 @@ QgsDataProvider *QgsProviderRegistry::provider( QString const &providerKey, QStr

int QgsProviderRegistry::providerCapabilities( const QString &providerKey ) const
{
std::unique_ptr< QLibrary > library( providerLibrary( providerKey ) );
std::unique_ptr< QLibrary > library( createProviderLibrary( providerKey ) );
if ( !library )
{
return QgsDataProvider::NoDataCapabilities;
Expand All @@ -440,7 +440,7 @@ int QgsProviderRegistry::providerCapabilities( const QString &providerKey ) cons
// This should be QWidget, not QDialog
typedef QWidget *selectFactoryFunction_t( QWidget *parent, Qt::WindowFlags fl );

QWidget *QgsProviderRegistry::selectWidget( const QString &providerKey,
QWidget *QgsProviderRegistry::createSelectionWidget( const QString &providerKey,
QWidget *parent, Qt::WindowFlags fl )
{
selectFactoryFunction_t *selectFactory =
Expand Down Expand Up @@ -474,7 +474,7 @@ QFunctionPointer QgsProviderRegistry::function( QString const &providerKey,
}
}

QLibrary *QgsProviderRegistry::providerLibrary( QString const &providerKey ) const
QLibrary *QgsProviderRegistry::createProviderLibrary( QString const &providerKey ) const
{
QString lib = library( providerKey );
if ( lib.isEmpty() )
Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsproviderregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ class CORE_EXPORT QgsProviderRegistry
void setLibraryDirectory( const QDir &path );

/**
* Create a new instance of a provider.
* Creates a new instance of a provider.
* \param providerKey identificator of the provider
* \param dataSource string containing data source for the provider
* \returns new instance of provider or NULL on error
*/
QgsDataProvider *provider( const QString &providerKey,
const QString &dataSource ) SIP_FACTORY;
QgsDataProvider *createProvider( const QString &providerKey,
const QString &dataSource ) SIP_FACTORY;

/** Return the provider capabilities
\param providerKey identificator of the provider
Expand All @@ -97,8 +97,8 @@ class CORE_EXPORT QgsProviderRegistry
* Either the \a parent widget must be set or the caller becomes
* responsible for deleting the returned widget.
*/
QWidget *selectWidget( const QString &providerKey,
QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );
QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );

/**
* Get pointer to provider function
Expand All @@ -117,7 +117,7 @@ class CORE_EXPORT QgsProviderRegistry
* If the provider uses direct provider function pointers instead of a library nullptr will
* be returned.
*/
QLibrary *providerLibrary( const QString &providerKey ) const SIP_FACTORY;
QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY;

//! Return list of available providers by their keys
QStringList providerList() const;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgstransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef QgsTransaction *createTransaction_t( const QString &connString );

QgsTransaction *QgsTransaction::create( const QString &connString, const QString &providerKey )
{
std::unique_ptr< QLibrary > lib( QgsProviderRegistry::instance()->providerLibrary( providerKey ) );
std::unique_ptr< QLibrary > lib( QgsProviderRegistry::instance()->createProviderLibrary( providerKey ) );
if ( !lib )
return nullptr;

Expand Down Expand Up @@ -164,7 +164,7 @@ bool QgsTransaction::rollback( QString &errorMsg )

bool QgsTransaction::supportsTransaction( const QgsVectorLayer *layer )
{
std::unique_ptr< QLibrary > lib( QgsProviderRegistry::instance()->providerLibrary( layer->providerType() ) );
std::unique_ptr< QLibrary > lib( QgsProviderRegistry::instance()->createProviderLibrary( layer->providerType() ) );
if ( !lib )
return false;

Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
//XXX - This was a dynamic cast but that kills the Windows
// version big-time with an abnormal termination error
delete mDataProvider;
mDataProvider = ( QgsVectorDataProvider * )( QgsProviderRegistry::instance()->provider( provider, mDataSource ) );
mDataProvider = ( QgsVectorDataProvider * )( QgsProviderRegistry::instance()->createProvider( provider, mDataSource ) );
if ( !mDataProvider )
{
QgsDebugMsg( " unable to get data provider" );
Expand Down Expand Up @@ -4003,7 +4003,7 @@ QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx ) const

int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError )
{
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->providerLibrary( mProviderKey ) );
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->createProviderLibrary( mProviderKey ) );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
Expand All @@ -4022,7 +4022,7 @@ int QgsVectorLayer::listStylesInDatabase( QStringList &ids, QStringList &names,

QString QgsVectorLayer::getStyleFromDatabase( const QString &styleId, QString &msgError )
{
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->providerLibrary( mProviderKey ) );
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->createProviderLibrary( mProviderKey ) );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
Expand All @@ -4041,7 +4041,7 @@ QString QgsVectorLayer::getStyleFromDatabase( const QString &styleId, QString &m

bool QgsVectorLayer::deleteStyleFromDatabase( const QString &styleId, QString &msgError )
{
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->providerLibrary( mProviderKey ) );
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->createProviderLibrary( mProviderKey ) );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
Expand All @@ -4062,7 +4062,7 @@ void QgsVectorLayer::saveStyleToDatabase( const QString &name, const QString &de
{

QString sldStyle, qmlStyle;
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->providerLibrary( mProviderKey ) );
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->createProviderLibrary( mProviderKey ) );
if ( !myLib )
{
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
Expand Down Expand Up @@ -4107,7 +4107,7 @@ QString QgsVectorLayer::loadNamedStyle( const QString &theURI, bool &resultFlag,
QgsDataSourceUri dsUri( theURI );
if ( !loadFromLocalDB && mDataProvider && mDataProvider->isSaveAndLoadStyleToDatabaseSupported() )
{
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->providerLibrary( mProviderKey ) );
std::unique_ptr<QLibrary> myLib( QgsProviderRegistry::instance()->createProviderLibrary( mProviderKey ) );
if ( myLib )
{
loadStyle_t *loadStyleExternalMethod = reinterpret_cast< loadStyle_t * >( cast_to_fptr( myLib->resolve( "loadStyle" ) ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayerimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ QgsVectorLayerImport::QgsVectorLayerImport( const QString &uri,

QgsProviderRegistry *pReg = QgsProviderRegistry::instance();

std::unique_ptr< QLibrary > myLib( pReg->providerLibrary( providerKey ) );
std::unique_ptr< QLibrary > myLib( pReg->createProviderLibrary( providerKey ) );
if ( !myLib )
{
mError = ErrInvalidProvider;
Expand Down Expand Up @@ -111,7 +111,7 @@ QgsVectorLayerImport::QgsVectorLayerImport( const QString &uri,
uriUpdated += layerName;
}
}
QgsVectorDataProvider *vectorProvider = dynamic_cast< QgsVectorDataProvider * >( pReg->provider( providerKey, uriUpdated ) );
QgsVectorDataProvider *vectorProvider = dynamic_cast< QgsVectorDataProvider * >( pReg->createProvider( providerKey, uriUpdated ) );
if ( !vectorProvider || !vectorProvider->isValid() || ( vectorProvider->capabilities() & QgsVectorDataProvider::AddFeatures ) == 0 )
{
mError = ErrInvalidLayer;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ bool QgsRasterChecker::runTest( const QString &verifiedKey, QString verifiedUri,
mReport += QLatin1String( "\n\n" );

//QgsRasterDataProvider* verifiedProvider = QgsRasterLayer::loadProvider( verifiedKey, verifiedUri );
QgsRasterDataProvider *verifiedProvider = dynamic_cast< QgsRasterDataProvider * >( QgsProviderRegistry::instance()->provider( verifiedKey, verifiedUri ) );
QgsRasterDataProvider *verifiedProvider = dynamic_cast< QgsRasterDataProvider * >( QgsProviderRegistry::instance()->createProvider( verifiedKey, verifiedUri ) );
if ( !verifiedProvider || !verifiedProvider->isValid() )
{
error( QStringLiteral( "Cannot load provider %1 with URI: %2" ).arg( verifiedKey, verifiedUri ), mReport );
ok = false;
}

//QgsRasterDataProvider* expectedProvider = QgsRasterLayer::loadProvider( expectedKey, expectedUri );
QgsRasterDataProvider *expectedProvider = dynamic_cast< QgsRasterDataProvider * >( QgsProviderRegistry::instance()->provider( expectedKey, expectedUri ) );
QgsRasterDataProvider *expectedProvider = dynamic_cast< QgsRasterDataProvider * >( QgsProviderRegistry::instance()->createProvider( expectedKey, expectedUri ) );
if ( !expectedProvider || !expectedProvider->isValid() )
{
error( QStringLiteral( "Cannot load provider %1 with URI: %2" ).arg( expectedKey, expectedUri ), mReport );
Expand Down

0 comments on commit ba2fdf0

Please sign in to comment.