Skip to content

Commit

Permalink
Use TRANSFER_BACK annotation instead of FACTORY for QgsProviderRegist…
Browse files Browse the repository at this point in the history
…ry::createProvider

Paraphrasing Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:

"
/Factory/ is used when the instance returned is guaranteed to be new to Python.
In this case it isn't because it has already been seen when being returned by by the python function
creating the provider subclass.

(However for a different sub-class implemented in C++ then it would be the first time it was seen
by Python so the /Factory/ on create() would be correct.)

You might try using /TransferBack/ on createProvider() instead - that might be the best compromise.
  • Loading branch information
nyalldawson committed Feb 8, 2021
1 parent cd2df66 commit 4984de7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion python/core/auto_generated/qgsproviderregistry.sip.in
Expand Up @@ -77,10 +77,11 @@ Returns the library directory where plugins are found.
Sets library directory where to search for plugins
%End


QgsDataProvider *createProvider( const QString &providerKey,
const QString &dataSource,
const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions(),
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) /Factory/;
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) /TransferBack/;
%Docstring
Creates a new instance of a provider.

Expand Down
19 changes: 18 additions & 1 deletion src/core/qgsproviderregistry.h
Expand Up @@ -111,6 +111,23 @@ class CORE_EXPORT QgsProviderRegistry
//! Sets library directory where to search for plugins
void setLibraryDirectory( const QDir &path );

/*
* IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
* the case.
* Paraphrasing Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
*
* "
* /Factory/ is used when the instance returned is guaranteed to be new to Python.
* In this case it isn't because it has already been seen when being returned by by the python function
* creating the provider subclass.
*
* (However for a different sub-class implemented in C++ then it would be the first time it was seen
* by Python so the /Factory/ on create() would be correct.)
*
* You might try using /TransferBack/ on createProvider() instead - that might be the best compromise.
* "
*/

/**
* Creates a new instance of a provider.
* \param providerKey identifier of the provider
Expand All @@ -124,7 +141,7 @@ class CORE_EXPORT QgsProviderRegistry
QgsDataProvider *createProvider( const QString &providerKey,
const QString &dataSource,
const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions(),
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_TRANSFERBACK;

/**
* Returns the provider capabilities
Expand Down

0 comments on commit 4984de7

Please sign in to comment.