diff --git a/python/gui/auto_generated/qgsdataitemguiproviderregistry.sip.in b/python/gui/auto_generated/qgsdataitemguiproviderregistry.sip.in index d66aef0d49d..62e1038d019 100644 --- a/python/gui/auto_generated/qgsdataitemguiproviderregistry.sip.in +++ b/python/gui/auto_generated/qgsdataitemguiproviderregistry.sip.in @@ -25,10 +25,7 @@ QgsGui.instance()->dataItemGuiProviderRegistry(). #include "qgsdataitemguiproviderregistry.h" %End public: - QgsDataItemGuiProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); -%Docstring -Initializes the registry. Do not create new instances in client code - use QgsGui.dataItemGuiProviderRegistry() instead -%End + QgsDataItemGuiProviderRegistry(); ~QgsDataItemGuiProviderRegistry(); @@ -47,6 +44,14 @@ is transferred to the registry. %Docstring Removes a ``provider`` implementation from the registry. The provider object is automatically deleted. +%End + + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); +%Docstring +Initializes the registry. The registry needs to be passed explicitly +(instead of using singleton) because this gets called from QgsGui constructor. + +.. versionadded:: 3.10 %End private: diff --git a/python/gui/auto_generated/qgsprojectstorageguiregistry.sip.in b/python/gui/auto_generated/qgsprojectstorageguiregistry.sip.in index cfb0e097ec7..fb4d4a66fb8 100644 --- a/python/gui/auto_generated/qgsprojectstorageguiregistry.sip.in +++ b/python/gui/auto_generated/qgsprojectstorageguiregistry.sip.in @@ -29,10 +29,7 @@ QgsProjectStorageGuiRegistry is not usually directly created, but rather accesse #include "qgsprojectstorageguiregistry.h" %End public: - QgsProjectStorageGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); -%Docstring -Initializes the registry. Do not create new instances in client code - use QgsGui.projectStorageGuiRegistry() instead -%End + QgsProjectStorageGuiRegistry(); ~QgsProjectStorageGuiRegistry(); @@ -59,6 +56,12 @@ Registers a storage backend and takes ownership of it void unregisterProjectStorage( QgsProjectStorageGuiProvider *storage ); %Docstring Unregisters a storage backend and destroys its instance +%End + + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); +%Docstring +Initializes the registry. The registry needs to be passed explicitly +(instead of using singleton) because this gets called from QgsGui constructor. %End private: diff --git a/python/gui/auto_generated/qgssourceselectproviderregistry.sip.in b/python/gui/auto_generated/qgssourceselectproviderregistry.sip.in index 6c1e45b03f3..b87e6f35973 100644 --- a/python/gui/auto_generated/qgssourceselectproviderregistry.sip.in +++ b/python/gui/auto_generated/qgssourceselectproviderregistry.sip.in @@ -27,11 +27,7 @@ QgsSourceSelectProviderRegistry is not usually directly created, but rather acce %End public: - QgsSourceSelectProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); -%Docstring -Constructor for QgsSourceSelectProviderRegistry. -%End - + QgsSourceSelectProviderRegistry(); ~QgsSourceSelectProviderRegistry(); @@ -50,6 +46,14 @@ Add a ``provider`` implementation. Takes ownership of the object. Remove ``provider`` implementation from the list (``provider`` object is deleted) :return: ``True`` if the provider was actually removed and deleted +%End + + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); +%Docstring +Initializes the registry. The registry needs to be passed explicitly +(instead of using singleton) because this gets called from QgsGui constructor. + +.. versionadded:: 3.10 %End QgsSourceSelectProvider *providerByName( const QString &name ); diff --git a/src/gui/qgsdataitemguiproviderregistry.cpp b/src/gui/qgsdataitemguiproviderregistry.cpp index a32f916b00a..2c82c66ec64 100644 --- a/src/gui/qgsdataitemguiproviderregistry.cpp +++ b/src/gui/qgsdataitemguiproviderregistry.cpp @@ -19,20 +19,7 @@ #include "qgsdataitemguiprovider.h" #include "qgsproviderguiregistry.h" -QgsDataItemGuiProviderRegistry::QgsDataItemGuiProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) -{ - if ( !providerGuiRegistry ) - return; - - const QStringList providersList = providerGuiRegistry->providerList(); - - for ( const QString &key : providersList ) - { - const QList providerList = providerGuiRegistry->dataItemGuiProviders( key ); - // the function is a factory - we keep ownership of the returned providers - mProviders << providerList; - } -} +QgsDataItemGuiProviderRegistry::QgsDataItemGuiProviderRegistry() = default; QgsDataItemGuiProviderRegistry::~QgsDataItemGuiProviderRegistry() { @@ -50,3 +37,18 @@ void QgsDataItemGuiProviderRegistry::removeProvider( QgsDataItemGuiProvider *pro if ( index >= 0 ) delete mProviders.takeAt( index ); } + +void QgsDataItemGuiProviderRegistry::initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) +{ + if ( !providerGuiRegistry ) + return; + + const QStringList providersList = providerGuiRegistry->providerList(); + + for ( const QString &key : providersList ) + { + const QList providerList = providerGuiRegistry->dataItemGuiProviders( key ); + // the function is a factory - we keep ownership of the returned providers + mProviders << providerList; + } +} diff --git a/src/gui/qgsdataitemguiproviderregistry.h b/src/gui/qgsdataitemguiproviderregistry.h index cd15c87155d..e7f97b19aa1 100644 --- a/src/gui/qgsdataitemguiproviderregistry.h +++ b/src/gui/qgsdataitemguiproviderregistry.h @@ -37,8 +37,7 @@ class QgsProviderGuiRegistry; class GUI_EXPORT QgsDataItemGuiProviderRegistry { public: - //! Initializes the registry. Do not create new instances in client code - use QgsGui::dataItemGuiProviderRegistry() instead - QgsDataItemGuiProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); + QgsDataItemGuiProviderRegistry(); ~QgsDataItemGuiProviderRegistry(); //! QgsDataItemGuiProviderRegistry cannot be copied. @@ -63,6 +62,13 @@ class GUI_EXPORT QgsDataItemGuiProviderRegistry */ void removeProvider( QgsDataItemGuiProvider *provider ); + /** + * Initializes the registry. The registry needs to be passed explicitly + * (instead of using singleton) because this gets called from QgsGui constructor. + * \since QGIS 3.10 + */ + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); + private: #ifdef SIP_RUN QgsDataItemGuiProviderRegistry( const QgsDataItemGuiProviderRegistry &rh ); diff --git a/src/gui/qgsgui.cpp b/src/gui/qgsgui.cpp index a25805504d0..89ee095aac0 100644 --- a/src/gui/qgsgui.cpp +++ b/src/gui/qgsgui.cpp @@ -184,9 +184,13 @@ QgsGui::QgsGui() // provider gui registry initialize QgsProviderRegistry too mProviderGuiRegistry = new QgsProviderGuiRegistry( QgsApplication::pluginPath() ); - mProjectStorageGuiRegistry = new QgsProjectStorageGuiRegistry( mProviderGuiRegistry ); - mDataItemGuiProviderRegistry = new QgsDataItemGuiProviderRegistry( mProviderGuiRegistry ); - mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry( mProviderGuiRegistry ); + mProjectStorageGuiRegistry = new QgsProjectStorageGuiRegistry(); + mDataItemGuiProviderRegistry = new QgsDataItemGuiProviderRegistry(); + mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry(); + + mProjectStorageGuiRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry ); + mDataItemGuiProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry ); + mSourceSelectProviderRegistry->initializeFromProviderGuiRegistry( mProviderGuiRegistry ); mEditorWidgetRegistry = new QgsEditorWidgetRegistry(); mShortcutsManager = new QgsShortcutsManager(); diff --git a/src/gui/qgsprojectstorageguiregistry.cpp b/src/gui/qgsprojectstorageguiregistry.cpp index 3800a580a3b..f8c8ddc424f 100644 --- a/src/gui/qgsprojectstorageguiregistry.cpp +++ b/src/gui/qgsprojectstorageguiregistry.cpp @@ -19,23 +19,7 @@ #include "qgsprojectstorageguiprovider.h" #include "qgsproviderguiregistry.h" -QgsProjectStorageGuiRegistry::QgsProjectStorageGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) -{ - if ( !providerGuiRegistry ) - return; - - const QStringList providersList = providerGuiRegistry->providerList(); - - for ( const QString &key : providersList ) - { - const QList providerList = providerGuiRegistry->projectStorageGuiProviders( key ); - // the function is a factory - we keep ownership of the returned providers - for ( QgsProjectStorageGuiProvider *provider : providerList ) - { - mBackends[key] = provider; - } - } -} +QgsProjectStorageGuiRegistry::QgsProjectStorageGuiRegistry() = default; QgsProjectStorageGuiRegistry::~QgsProjectStorageGuiRegistry() { @@ -73,3 +57,20 @@ void QgsProjectStorageGuiRegistry::unregisterProjectStorage( QgsProjectStorageGu { delete mBackends.take( storage->type() ); } + +void QgsProjectStorageGuiRegistry::initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) +{ + if ( !providerGuiRegistry ) + return; + + const QStringList providersList = providerGuiRegistry->providerList(); + for ( const QString &key : providersList ) + { + const QList providerList = providerGuiRegistry->projectStorageGuiProviders( key ); + // the function is a factory - we keep ownership of the returned providers + for ( QgsProjectStorageGuiProvider *provider : providerList ) + { + mBackends[key] = provider; + } + } +} diff --git a/src/gui/qgsprojectstorageguiregistry.h b/src/gui/qgsprojectstorageguiregistry.h index 50b97578e57..91ccfa9bf58 100644 --- a/src/gui/qgsprojectstorageguiregistry.h +++ b/src/gui/qgsprojectstorageguiregistry.h @@ -44,8 +44,7 @@ class QgsProviderGuiRegistry; class GUI_EXPORT QgsProjectStorageGuiRegistry { public: - //! Initializes the registry. Do not create new instances in client code - use QgsGui::projectStorageGuiRegistry() instead - QgsProjectStorageGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); + QgsProjectStorageGuiRegistry(); ~QgsProjectStorageGuiRegistry(); //! QgsProjectStorageGuiRegistry cannot be copied. @@ -68,6 +67,12 @@ class GUI_EXPORT QgsProjectStorageGuiRegistry //! Unregisters a storage backend and destroys its instance void unregisterProjectStorage( QgsProjectStorageGuiProvider *storage ); + /** + * Initializes the registry. The registry needs to be passed explicitly + * (instead of using singleton) because this gets called from QgsGui constructor. + */ + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); + private: #ifdef SIP_RUN QgsProjectStorageGuiRegistry( const QgsProjectStorageGuiRegistry &rh ); diff --git a/src/gui/qgssourceselectproviderregistry.cpp b/src/gui/qgssourceselectproviderregistry.cpp index d2f843bf174..2e7426bbd7a 100644 --- a/src/gui/qgssourceselectproviderregistry.cpp +++ b/src/gui/qgssourceselectproviderregistry.cpp @@ -19,19 +19,7 @@ #include -QgsSourceSelectProviderRegistry::QgsSourceSelectProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) -{ - const QStringList providersList = providerGuiRegistry->providerList(); - for ( const QString &key : providersList ) - { - const QList providerList = providerGuiRegistry->sourceSelectProviders( key ); - // the function is a factory - we keep ownership of the returned providers - for ( auto provider : providerList ) - { - addProvider( provider ); - } - } -} +QgsSourceSelectProviderRegistry::QgsSourceSelectProviderRegistry() = default; QgsSourceSelectProviderRegistry::~QgsSourceSelectProviderRegistry() { @@ -63,6 +51,24 @@ bool QgsSourceSelectProviderRegistry::removeProvider( QgsSourceSelectProvider *p return false; } + +void QgsSourceSelectProviderRegistry::initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ) +{ + if ( !providerGuiRegistry ) + return; + + const QStringList providersList = providerGuiRegistry->providerList(); + for ( const QString &key : providersList ) + { + const QList providerList = providerGuiRegistry->sourceSelectProviders( key ); + // the function is a factory - we keep ownership of the returned providers + for ( auto provider : providerList ) + { + addProvider( provider ); + } + } +} + QgsSourceSelectProvider *QgsSourceSelectProviderRegistry::providerByName( const QString &name ) { const QList providerList = providers(); diff --git a/src/gui/qgssourceselectproviderregistry.h b/src/gui/qgssourceselectproviderregistry.h index 17a7baa5d56..28a7205b494 100644 --- a/src/gui/qgssourceselectproviderregistry.h +++ b/src/gui/qgssourceselectproviderregistry.h @@ -42,11 +42,7 @@ class GUI_EXPORT QgsSourceSelectProviderRegistry { public: - /** - * Constructor for QgsSourceSelectProviderRegistry. - */ - QgsSourceSelectProviderRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); - + QgsSourceSelectProviderRegistry(); ~QgsSourceSelectProviderRegistry(); //! QgsDataItemProviderRegistry cannot be copied. @@ -66,6 +62,13 @@ class GUI_EXPORT QgsSourceSelectProviderRegistry */ bool removeProvider( QgsSourceSelectProvider *provider SIP_TRANSFER ); + /** + * Initializes the registry. The registry needs to be passed explicitly + * (instead of using singleton) because this gets called from QgsGui constructor. + * \since QGIS 3.10 + */ + void initializeFromProviderGuiRegistry( QgsProviderGuiRegistry *providerGuiRegistry ); + //! Returns a provider by \a name or NULLPTR if not found QgsSourceSelectProvider *providerByName( const QString &name );