QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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
20
21#include <memory>
22
24
29
30QList<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
82QList<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}
Base class for all map layer types.
Definition qgsmaplayer.h:76
A registry / canonical manager of GUI parts of data providers.
virtual QList< QgsProviderSourceWidgetProvider * > sourceWidgetProviders(const QString &providerKey)
Returns all source widget providers registered in provider with providerKey.
QStringList providerList() const
Returns list of available providers by their keys.
QList< QgsProviderSourceWidgetProvider * > providers()
Gets list of available providers.
QgsProviderSourceWidgetProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
QgsProviderSourceWidget * createWidget(QgsMapLayer *layer, QWidget *parent=nullptr)
Creates a new widget to configure the source of the specified layer.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QList< QgsProviderSourceWidgetProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
bool removeProvider(QgsProviderSourceWidgetProvider *provider)
Remove provider implementation from the list (provider object is deleted)
void addProvider(QgsProviderSourceWidgetProvider *provider)
Add a provider implementation. Takes ownership of the object.
An interface for providers of widgets designed to configure a data provider's source.
Base class for widgets which allow customization of a provider's source URI.