QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 {
40 return first->ordering() < second->ordering();
41 } );
42
43 emit providerAdded( provider->name() );
44}
45
47{
48 const QString name = provider ? provider->name() : QString();
49 const int index = mProviders.indexOf( provider );
50 if ( index >= 0 )
51 {
52 delete mProviders.takeAt( index );
53 emit providerRemoved( name );
54 return true;
55 }
56 return false;
57}
58
59
61{
62 if ( !providerGuiRegistry )
63 return;
64
65 const QStringList providersList = providerGuiRegistry->providerList();
66 for ( const QString &key : providersList )
67 {
68 const QList<QgsSourceSelectProvider *> providerList = providerGuiRegistry->sourceSelectProviders( key );
69 // the function is a factory - we keep ownership of the returned providers
70 for ( auto provider : providerList )
71 {
72 addProvider( provider );
73 }
74 }
75}
76
78{
79 const QList<QgsSourceSelectProvider *> providerList = providers();
80 for ( const auto provider : providerList )
81 {
82 if ( provider->name() == name )
83 {
84 return provider;
85 }
86 }
87 return nullptr;
88}
89
90QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey )
91{
92 QList<QgsSourceSelectProvider *> result;
93 const QList<QgsSourceSelectProvider *> providerList = providers();
94 for ( const auto provider : providerList )
95 {
96 if ( provider->providerKey() == providerKey )
97 {
98 result << provider;
99 }
100 }
101 return result;
102}
103
105 const QString &name,
106 QWidget *parent,
107 Qt::WindowFlags fl,
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...