QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
24 
26 {
27  mProviders << new QgsFileBasedDataItemProvider();
28 
29  QStringList providersList = QgsProviderRegistry::instance()->providerList();
30 
31  const auto constProvidersList = providersList;
32  for ( const QString &key : constProvidersList )
33  {
34  QList<QgsDataItemProvider *> providerList = QgsProviderRegistry::instance()->dataItemProviders( key );
35  mProviders << providerList;
36  for ( const auto &p : std::as_const( providerList ) )
37  {
38  if ( ! p->dataProviderKey().isEmpty() )
39  {
40  mDataItemProviderOrigin[ p->name() ] = p->dataProviderKey();
41  }
42  }
43  }
44 }
45 
47 {
48  qDeleteAll( mProviders );
49 }
50 
51 QList<QgsDataItemProvider *> QgsDataItemProviderRegistry::providers() const { return mProviders; }
52 
53 QgsDataItemProvider *QgsDataItemProviderRegistry::provider( const QString &providerName ) const
54 {
55  for ( const auto &p : std::as_const( mProviders ) )
56  {
57  if ( p->name() == providerName )
58  {
59  return p;
60  }
61  }
62  return nullptr;
63 }
64 
66 {
67  if ( ! provider->dataProviderKey().isEmpty() )
68  {
69  mDataItemProviderOrigin[ provider->name() ] = provider->dataProviderKey();
70  }
71  mProviders.append( provider );
72  emit providerAdded( provider );
73 }
74 
76 {
77  int index = mProviders.indexOf( provider );
78  if ( index >= 0 )
79  {
81  delete mProviders.takeAt( index );
82  }
83 }
84 
85 QString QgsDataItemProviderRegistry::dataProviderKey( const QString &dataItemProviderName )
86 {
87  return mDataItemProviderOrigin.value( dataItemProviderName, QString() );
88 }
QgsDataItemProviderRegistry::providerAdded
void providerAdded(QgsDataItemProvider *provider)
Emitted when a new data item provider has been added.
QgsDataItemProviderRegistry::QgsDataItemProviderRegistry
QgsDataItemProviderRegistry()
Definition: qgsdataitemproviderregistry.cpp:25
qgsdataitemproviderregistry.h
QgsProviderRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderregistry.cpp:863
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:613
QgsDataItemProviderRegistry::removeProvider
void removeProvider(QgsDataItemProvider *provider)
Removes a provider implementation from the registry.
Definition: qgsdataitemproviderregistry.cpp:75
QgsDataItemProviderRegistry::addProvider
void addProvider(QgsDataItemProvider *provider)
Adds a provider implementation to the registry.
Definition: qgsdataitemproviderregistry.cpp:65
qgsproviderregistry.h
QgsDataItemProviderRegistry::providers
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
Definition: qgsdataitemproviderregistry.cpp:51
QgsDataItemProvider
This is the interface for those who want to add custom data items to the browser tree.
Definition: qgsdataitemprovider.h:44
QgsDataItemProviderRegistry::~QgsDataItemProviderRegistry
~QgsDataItemProviderRegistry()
Definition: qgsdataitemproviderregistry.cpp:46
QgsFileBasedDataItemProvider
A data item provider for file based data sources.
Definition: qgsfilebaseddataitemprovider.h:113
qgsfilebaseddataitemprovider.h
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:58
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:85
qgsdataprovider.h
QgsDataItemProviderRegistry::provider
QgsDataItemProvider * provider(const QString &providerName) const
Returns the (possibly NULL) data item provider named providerName.
Definition: qgsdataitemproviderregistry.cpp:53
qgslogger.h
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73