QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgssourceselectproviderregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssourceselectproviderregistry.cpp - QgsSourceSelectProviderRegistry
3
4 ---------------------
5 begin : 1.9.2017
6 copyright : (C) 2017 by Alessandro Pasotti
7 email : apasotti at boundlessgeo dot com
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 ***************************************************************************/
18#include "moc_qgssourceselectproviderregistry.cpp"
20
21#include <memory>
22
24
29
30QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providers()
31{
32 return mProviders;
33}
34
36{
37 mProviders.append( provider );
38 std::sort( mProviders.begin(), mProviders.end(), []( const QgsSourceSelectProvider *first, const QgsSourceSelectProvider *second ) -> bool {
39 return first->ordering() < second->ordering();
40 } );
41
42 emit providerAdded( provider->name() );
43}
44
46{
47 const QString name = provider ? provider->name() : QString();
48 const int index = mProviders.indexOf( provider );
49 if ( index >= 0 )
50 {
51 delete mProviders.takeAt( index );
52 emit providerRemoved( name );
53 return true;
54 }
55 return false;
56}
57
58
60{
61 if ( !providerGuiRegistry )
62 return;
63
64 const QStringList providersList = providerGuiRegistry->providerList();
65 for ( const QString &key : providersList )
66 {
67 const QList<QgsSourceSelectProvider *> providerList = providerGuiRegistry->sourceSelectProviders( key );
68 // the function is a factory - we keep ownership of the returned providers
69 for ( auto provider : providerList )
70 {
71 addProvider( provider );
72 }
73 }
74}
75
77{
78 const QList<QgsSourceSelectProvider *> providerList = providers();
79 for ( const auto provider : providerList )
80 {
81 if ( provider->name() == name )
82 {
83 return provider;
84 }
85 }
86 return nullptr;
87}
88
89QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey )
90{
91 QList<QgsSourceSelectProvider *> result;
92 const QList<QgsSourceSelectProvider *> providerList = providers();
93 for ( const auto provider : providerList )
94 {
95 if ( provider->providerKey() == providerKey )
96 {
97 result << provider;
98 }
99 }
100 return result;
101}
102
104 const QString &name,
105 QWidget *parent,
106 Qt::WindowFlags fl,
108)
109{
110 QgsSourceSelectProvider *provider = providerByName( name );
111 if ( !provider )
112 {
113 return nullptr;
114 }
115 return provider->createDataSourceWidget( parent, fl, widgetMode );
116}
Abstract base Data Source Widget to create connections and add layers This class provides common func...
A registry / canonical manager of GUI parts of data providers.
virtual QList< QgsSourceSelectProvider * > sourceSelectProviders(const QString &providerKey)
Returns all source select providers registered in provider with providerKey.
QStringList providerList() const
Returns list of available providers by their keys.
WidgetMode
Different ways a source select dialog can be used.
QgsAbstractDataSourceWidget * createSelectionWidget(const QString &name, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode)
Gets select widget from provider with name.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QList< QgsSourceSelectProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
void providerRemoved(const QString &name)
Emitted whenever a provider is removed from the registry.
void providerAdded(const QString &name)
Emitted whenever a provider is added to the registry.
QList< QgsSourceSelectProvider * > providers()
Gets list of available providers.
QgsSourceSelectProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
void addProvider(QgsSourceSelectProvider *provider)
Add a provider implementation. Takes ownership of the object.
bool removeProvider(QgsSourceSelectProvider *provider)
Remove provider implementation from the list (provider object is deleted)
This is the interface for those who want to add entries to the QgsDataSourceManagerDialog.
virtual QgsAbstractDataSourceWidget * createDataSourceWidget(QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::Embedded) const =0
Create a new instance of QgsAbstractDataSourceWidget (or nullptr).
virtual QString name() const
Source select provider name, this is useful to retrieve a particular source select in case the provid...