QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsdataitemproviderregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdataitemproviderregistry.cpp
3  --------------------------------------
4  Date : March 2015
5  Copyright : (C) 2015 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
18 #include "qgsdataitem.h"
19 #include "qgsdataitemprovider.h"
20 #include "qgsdataprovider.h"
21 #include "qgslogger.h"
22 #include "qgsproviderregistry.h"
23 
25 {
26  QStringList providersList = QgsProviderRegistry::instance()->providerList();
27 
28  const auto constProvidersList = providersList;
29  for ( const QString &key : constProvidersList )
30  {
31  QList<QgsDataItemProvider *> providerList = QgsProviderRegistry::instance()->dataItemProviders( key );
32  mProviders << providerList;
33  for ( const auto &p : qgis::as_const( providerList ) )
34  {
35  if ( ! p->dataProviderKey().isEmpty() )
36  {
37  mDataItemProviderOrigin[ p->name() ] = p->dataProviderKey();
38  }
39  }
40  }
41 }
42 
44 {
45  qDeleteAll( mProviders );
46 }
47 
48 QList<QgsDataItemProvider *> QgsDataItemProviderRegistry::providers() const { return mProviders; }
49 
50 QgsDataItemProvider *QgsDataItemProviderRegistry::provider( const QString &providerName ) const
51 {
52  for ( const auto &p : qgis::as_const( mProviders ) )
53  {
54  if ( p->name() == providerName )
55  {
56  return p;
57  }
58  }
59  return nullptr;
60 }
61 
63 {
64  if ( ! provider->dataProviderKey().isEmpty() )
65  {
66  mDataItemProviderOrigin[ provider->name() ] = provider->dataProviderKey();
67  }
68  mProviders.append( provider );
69  emit providerAdded( provider );
70 }
71 
73 {
74  int index = mProviders.indexOf( provider );
75  if ( index >= 0 )
76  {
78  delete mProviders.takeAt( index );
79  }
80 }
81 
82 QString QgsDataItemProviderRegistry::dataProviderKey( const QString &dataItemProviderName )
83 {
84  return mDataItemProviderOrigin.value( dataItemProviderName, QString() );
85 }
QgsDataItemProviderRegistry::providerAdded
void providerAdded(QgsDataItemProvider *provider)
Emitted when a new data item provider has been added.
QgsDataItemProviderRegistry::QgsDataItemProviderRegistry
QgsDataItemProviderRegistry()
Definition: qgsdataitemproviderregistry.cpp:24
qgsdataitemproviderregistry.h
QgsProviderRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderregistry.cpp:714
qgsdataitem.h
QgsDataItemProvider::name
virtual QString name()=0
Human-readable name of the provider name.
QgsProviderRegistry::dataItemProviders
QList< QgsDataItemProvider * > dataItemProviders(const QString &providerKey) const
Returns list of data item providers of the provider.
Definition: qgsproviderregistry.cpp:495
QgsDataItemProviderRegistry::removeProvider
void removeProvider(QgsDataItemProvider *provider)
Removes a provider implementation from the registry.
Definition: qgsdataitemproviderregistry.cpp:72
QgsDataItemProviderRegistry::addProvider
void addProvider(QgsDataItemProvider *provider)
Adds a provider implementation to the registry.
Definition: qgsdataitemproviderregistry.cpp:62
qgsproviderregistry.h
QgsDataItemProviderRegistry::providers
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
Definition: qgsdataitemproviderregistry.cpp:48
QgsDataItemProvider
This is the interface for those who want to add custom data items to the browser tree.
Definition: qgsdataitemprovider.h:46
QgsDataItemProviderRegistry::~QgsDataItemProviderRegistry
~QgsDataItemProviderRegistry()
Definition: qgsdataitemproviderregistry.cpp:43
qgsdataitemprovider.h
QgsDataItemProvider::dataProviderKey
virtual QString dataProviderKey() const
Returns the data provider key (if the data item provider is associated with a data provider),...
Definition: qgsdataitemprovider.h:59
QgsDataItemProviderRegistry::providerWillBeRemoved
void providerWillBeRemoved(QgsDataItemProvider *provider)
Emitted when a data item provider is about to be removed.
QgsDataItemProviderRegistry::dataProviderKey
QString dataProviderKey(const QString &dataItemProviderName)
Returns the (possibly blank) data provider key for a given data item provider name.
Definition: qgsdataitemproviderregistry.cpp:82
qgsdataprovider.h
QgsDataItemProviderRegistry::provider
QgsDataItemProvider * provider(const QString &providerName) const
Returns the (possibly NULL) data item provider named providerName.
Definition: qgsdataitemproviderregistry.cpp:50
qgslogger.h
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:48