QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 ***************************************************************************/
17
18#include <memory>
19
22
23#include "moc_qgssourceselectproviderregistry.cpp"
24
26
31
32QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providers()
33{
34 return mProviders;
35}
36
38{
39 mProviders.append( provider );
40 std::sort( mProviders.begin(), mProviders.end(), []( const QgsSourceSelectProvider *first, const QgsSourceSelectProvider *second ) -> bool {
41 return first->ordering() < second->ordering();
42 } );
43
44 emit providerAdded( provider->name() );
45}
46
48{
49 const QString name = provider ? provider->name() : QString();
50 const int index = mProviders.indexOf( provider );
51 if ( index >= 0 )
52 {
53 delete mProviders.takeAt( index );
54 emit providerRemoved( name );
55 return true;
56 }
57 return false;
58}
59
60
62{
63 if ( !providerGuiRegistry )
64 return;
65
66 const QStringList providersList = providerGuiRegistry->providerList();
67 for ( const QString &key : providersList )
68 {
69 const QList<QgsSourceSelectProvider *> providerList = providerGuiRegistry->sourceSelectProviders( key );
70 // the function is a factory - we keep ownership of the returned providers
71 for ( auto provider : providerList )
72 {
73 addProvider( provider );
74 }
75 }
76}
77
79{
80 const QList<QgsSourceSelectProvider *> providerList = providers();
81 for ( const auto provider : providerList )
82 {
83 if ( provider->name() == name )
84 {
85 return provider;
86 }
87 }
88 return nullptr;
89}
90
91QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey )
92{
93 QList<QgsSourceSelectProvider *> result;
94 const QList<QgsSourceSelectProvider *> providerList = providers();
95 for ( const auto provider : providerList )
96 {
97 if ( provider->providerKey() == providerKey )
98 {
99 result << provider;
100 }
101 }
102 return result;
103}
104
106 const QString &name,
107 QWidget *parent,
108 Qt::WindowFlags fl,
110)
111{
112 QgsSourceSelectProvider *provider = providerByName( name );
113 if ( !provider )
114 {
115 return nullptr;
116 }
117 return provider->createDataSourceWidget( parent, fl, widgetMode );
118}
Abstract base class for Data Source widgets to create connections and add layers.
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).
An interface for pages shown in a 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...