QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 "qgsproviderguiregistry.h"
19 
20 #include <memory>
21 
23 
25 {
26  qDeleteAll( mProviders );
27 }
28 
29 QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providers()
30 {
31  return mProviders;
32 }
33 
35 {
36  mProviders.append( provider );
37  std::sort( mProviders.begin(), mProviders.end(), [ ]( const QgsSourceSelectProvider * first, const QgsSourceSelectProvider * second ) -> bool
38  {
39  return first->ordering() < second->ordering();
40  } );
41 }
42 
44 {
45  int index = mProviders.indexOf( provider );
46  if ( index >= 0 )
47  {
48  delete mProviders.takeAt( index );
49  return true;
50  }
51  return false;
52 }
53 
54 
56 {
57  if ( !providerGuiRegistry )
58  return;
59 
60  const QStringList providersList = providerGuiRegistry->providerList();
61  for ( const QString &key : providersList )
62  {
63  const QList<QgsSourceSelectProvider *> providerList = providerGuiRegistry->sourceSelectProviders( key );
64  // the function is a factory - we keep ownership of the returned providers
65  for ( auto provider : providerList )
66  {
67  addProvider( provider );
68  }
69  }
70 }
71 
73 {
74  const QList<QgsSourceSelectProvider *> providerList = providers();
75  for ( const auto provider : providerList )
76  {
77  if ( provider->name() == name )
78  {
79  return provider;
80  }
81  }
82  return nullptr;
83 }
84 
85 QList<QgsSourceSelectProvider *> QgsSourceSelectProviderRegistry::providersByKey( const QString &providerKey )
86 {
87  QList<QgsSourceSelectProvider *> result;
88  const QList<QgsSourceSelectProvider *> providerList = providers();
89  for ( const auto provider : providerList )
90  {
91  if ( provider->providerKey() == providerKey )
92  {
93  result << provider;
94  }
95  }
96  return result;
97 }
98 
100  const QString &name,
101  QWidget *parent,
102  Qt::WindowFlags fl,
104 {
105  QgsSourceSelectProvider *provider = providerByName( name );
106  if ( !provider )
107  {
108  return nullptr;
109  }
110  return provider->createDataSourceWidget( parent, fl, widgetMode );
111 }
qgssourceselectprovider.h
QgsAbstractDataSourceWidget
Abstract base Data Source Widget to create connections and add layers This class provides common func...
Definition: qgsabstractdatasourcewidget.h:42
QgsSourceSelectProviderRegistry::createSelectionWidget
QgsAbstractDataSourceWidget * createSelectionWidget(const QString &name, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode)
Gets select widget from provider with name.
Definition: qgssourceselectproviderregistry.cpp:99
QgsSourceSelectProviderRegistry::QgsSourceSelectProviderRegistry
QgsSourceSelectProviderRegistry()
QgsSourceSelectProvider
Definition: qgssourceselectprovider.h:35
QgsSourceSelectProviderRegistry::removeProvider
bool removeProvider(QgsSourceSelectProvider *provider)
Remove provider implementation from the list (provider object is deleted)
Definition: qgssourceselectproviderregistry.cpp:43
qgsproviderguiregistry.h
QgsSourceSelectProvider::createDataSourceWidget
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).
qgssourceselectproviderregistry.h
QgsProviderRegistry::WidgetMode
WidgetMode
Different ways a source select dialog can be used.
Definition: qgsproviderregistry.h:63
QgsProviderGuiRegistry
Definition: qgsproviderguiregistry.h:49
QgsSourceSelectProviderRegistry::providersByKey
QList< QgsSourceSelectProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
Definition: qgssourceselectproviderregistry.cpp:85
QgsProviderGuiRegistry::sourceSelectProviders
virtual QList< QgsSourceSelectProvider * > sourceSelectProviders(const QString &providerKey)
Returns all source select providers registered in provider with providerKey.
Definition: qgsproviderguiregistry.cpp:183
QgsSourceSelectProviderRegistry::initializeFromProviderGuiRegistry
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
Definition: qgssourceselectproviderregistry.cpp:55
QgsSourceSelectProviderRegistry::providers
QList< QgsSourceSelectProvider * > providers()
Gets list of available providers.
Definition: qgssourceselectproviderregistry.cpp:29
QgsSourceSelectProviderRegistry::providerByName
QgsSourceSelectProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
Definition: qgssourceselectproviderregistry.cpp:72
QgsProviderGuiRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderguiregistry.cpp:199
QgsSourceSelectProviderRegistry::addProvider
void addProvider(QgsSourceSelectProvider *provider)
Add a provider implementation. Takes ownership of the object.
Definition: qgssourceselectproviderregistry.cpp:34
QgsSourceSelectProviderRegistry::~QgsSourceSelectProviderRegistry
~QgsSourceSelectProviderRegistry()
Definition: qgssourceselectproviderregistry.cpp:24