QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsprovidersourcewidgetproviderregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprovidersourcewidgetproviderregistry.cpp
3  ----------------------------------------
4  Date : December 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7 ****************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
19 #include "qgsproviderguiregistry.h"
20 
21 #include <memory>
22 
24 
26 {
27  qDeleteAll( mProviders );
28 }
29 
30 QList<QgsProviderSourceWidgetProvider *> QgsProviderSourceWidgetProviderRegistry::providers()
31 {
32  return mProviders;
33 }
34 
36 {
37  mProviders.append( provider );
38 }
39 
41 {
42  const int index = mProviders.indexOf( provider );
43  if ( index >= 0 )
44  {
45  delete mProviders.takeAt( index );
46  return true;
47  }
48  return false;
49 }
50 
51 
53 {
54  if ( !providerGuiRegistry )
55  return;
56 
57  const QStringList providersList = providerGuiRegistry->providerList();
58  for ( const QString &key : providersList )
59  {
60  const QList<QgsProviderSourceWidgetProvider *> providerList = providerGuiRegistry->sourceWidgetProviders( key );
61  // the function is a factory - we keep ownership of the returned providers
62  for ( QgsProviderSourceWidgetProvider *provider : providerList )
63  {
64  addProvider( provider );
65  }
66  }
67 }
68 
70 {
71  const QList<QgsProviderSourceWidgetProvider *> providerList = providers();
72  for ( QgsProviderSourceWidgetProvider *provider : providerList )
73  {
74  if ( provider->name() == name )
75  {
76  return provider;
77  }
78  }
79  return nullptr;
80 }
81 
82 QList<QgsProviderSourceWidgetProvider *> QgsProviderSourceWidgetProviderRegistry::providersByKey( const QString &providerKey )
83 {
84  QList<QgsProviderSourceWidgetProvider *> result;
85  const QList<QgsProviderSourceWidgetProvider *> providerList = providers();
86  for ( QgsProviderSourceWidgetProvider *provider : providerList )
87  {
88  if ( provider->providerKey() == providerKey )
89  {
90  result << provider;
91  }
92  }
93  return result;
94 }
95 
97 {
98  const QList<QgsProviderSourceWidgetProvider *> providerList = providers();
99  // Loop over providers to find one that can handle the layer.
100  for ( QgsProviderSourceWidgetProvider *provider : providerList )
101  {
102  if ( provider->canHandleLayer( layer ) )
103  {
104  return provider->createWidget( layer, parent );
105  }
106  }
107 
108  return nullptr;
109 }
QgsProviderSourceWidgetProviderRegistry::providersByKey
QList< QgsProviderSourceWidgetProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:82
QgsProviderSourceWidgetProviderRegistry::initializeFromProviderGuiRegistry
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:52
QgsProviderSourceWidgetProviderRegistry::addProvider
void addProvider(QgsProviderSourceWidgetProvider *provider)
Add a provider implementation. Takes ownership of the object.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:35
QgsProviderSourceWidgetProviderRegistry::providers
QList< QgsProviderSourceWidgetProvider * > providers()
Gets list of available providers.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:30
QgsProviderSourceWidgetProviderRegistry::removeProvider
bool removeProvider(QgsProviderSourceWidgetProvider *provider)
Remove provider implementation from the list (provider object is deleted)
Definition: qgsprovidersourcewidgetproviderregistry.cpp:40
QgsProviderSourceWidgetProviderRegistry::~QgsProviderSourceWidgetProviderRegistry
~QgsProviderSourceWidgetProviderRegistry()
Definition: qgsprovidersourcewidgetproviderregistry.cpp:25
qgsproviderguiregistry.h
QgsProviderSourceWidgetProvider
An interface for providers of widgets designed to configure a data provider's source.
Definition: qgsprovidersourcewidgetprovider.h:37
qgsprovidersourcewidgetprovider.h
QgsProviderSourceWidget
Base class for widgets which allow customization of a provider's source URI.
Definition: qgsprovidersourcewidget.h:32
qgsprovidersourcewidgetproviderregistry.h
QgsProviderGuiRegistry
A registry / canonical manager of GUI parts of data providers.
Definition: qgsproviderguiregistry.h:53
QgsProviderSourceWidgetProviderRegistry::QgsProviderSourceWidgetProviderRegistry
QgsProviderSourceWidgetProviderRegistry()
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsProviderGuiRegistry::sourceWidgetProviders
virtual QList< QgsProviderSourceWidgetProvider * > sourceWidgetProviders(const QString &providerKey)
Returns all source widget providers registered in provider with providerKey.
Definition: qgsproviderguiregistry.cpp:262
QgsProviderSourceWidgetProviderRegistry::createWidget
QgsProviderSourceWidget * createWidget(QgsMapLayer *layer, QWidget *parent=nullptr)
Creates a new widget to configure the source of the specified layer.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:96
QgsProviderGuiRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderguiregistry.cpp:285
QgsProviderSourceWidgetProviderRegistry::providerByName
QgsProviderSourceWidgetProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
Definition: qgsprovidersourcewidgetproviderregistry.cpp:69