QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 }
WidgetMode
Different ways a source select dialog can be used.
Abstract base Data Source Widget to create connections and add layers This class provides common func...
QList< QgsSourceSelectProvider * > providers()
Gets list of available providers.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QgsAbstractDataSourceWidget * createSelectionWidget(const QString &name, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode)
Gets select widget from provider with name.
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 QList< QgsSourceSelectProvider * > sourceSelectProviders(const QString &providerKey)
Returns all source select providers registered in provider with providerKey.
QgsSourceSelectProvider * providerByName(const QString &name)
Returns a provider by name or nullptr if not found.
This is the interface for those who want to add entries to the QgsDataSourceManagerDialog.
bool removeProvider(QgsSourceSelectProvider *provider)
Remove provider implementation from the list (provider object is deleted)
void addProvider(QgsSourceSelectProvider *provider)
Add a provider implementation. Takes ownership of the object.
QStringList providerList() const
Returns list of available providers by their keys.
QList< QgsSourceSelectProvider * > providersByKey(const QString &providerKey)
Returns a (possibly empty) list of providers by data providerkey.
virtual int ordering() const
Ordering: the source select provider registry will be able to sort the source selects (ascending) usi...
A registry / canonical manager of GUI parts of data providers.