Skip to content
Permalink
Browse files

Use TRANSFER_BACK annotation instead of FACTORY for QgsProviderRegist…

…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 4984de792def0029436bb253ca2248403a8e1705
Showing with 20 additions and 2 deletions.
  1. +2 −1 python/core/auto_generated/qgsproviderregistry.sip.in
  2. +18 −1 src/core/qgsproviderregistry.h
@@ -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.

@@ -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
@@ -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

0 comments on commit 4984de7

Please sign in to comment.