QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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#include "moc_qgsdataitemproviderregistry.cpp"
18
19#include "qgsdataitem.h"
20#include "qgsdataitemprovider.h"
21#include "qgsdataprovider.h"
22#include "qgslogger.h"
23#include "qgsproviderregistry.h"
25
27{
28 mProviders << new QgsFileBasedDataItemProvider();
29
30 QStringList providersList = QgsProviderRegistry::instance()->providerList();
31
32 const auto constProvidersList = providersList;
33 for ( const QString &key : constProvidersList )
34 {
35 QList<QgsDataItemProvider *> providerList = QgsProviderRegistry::instance()->dataItemProviders( key );
36 mProviders << providerList;
37 for ( const auto &p : std::as_const( providerList ) )
38 {
39 if ( ! p->dataProviderKey().isEmpty() )
40 {
41 mDataItemProviderOrigin[ p->name() ] = p->dataProviderKey();
42 }
43 }
44 }
45}
46
48{
49 qDeleteAll( mProviders );
50}
51
52QList<QgsDataItemProvider *> QgsDataItemProviderRegistry::providers() const { return mProviders; }
53
55{
56 for ( const auto &p : std::as_const( mProviders ) )
57 {
58 if ( p->name() == providerName )
59 {
60 return p;
61 }
62 }
63 return nullptr;
64}
65
67{
68 if ( ! provider->dataProviderKey().isEmpty() )
69 {
70 mDataItemProviderOrigin[ provider->name() ] = provider->dataProviderKey();
71 }
72 mProviders.append( provider );
73 emit providerAdded( provider );
74}
75
77{
78 int index = mProviders.indexOf( provider );
79 if ( index >= 0 )
80 {
82 delete mProviders.takeAt( index );
83 }
84}
85
86QString QgsDataItemProviderRegistry::dataProviderKey( const QString &dataItemProviderName )
87{
88 return mDataItemProviderOrigin.value( dataItemProviderName, QString() );
89}
QList< QgsDataItemProvider * > providers() const
Returns the list of available providers.
QString dataProviderKey(const QString &dataItemProviderName)
Returns the (possibly blank) data provider key for a given data item provider name.
void providerWillBeRemoved(QgsDataItemProvider *provider)
Emitted when a data item provider is about to be removed.
void removeProvider(QgsDataItemProvider *provider)
Removes a provider implementation from the registry.
void providerAdded(QgsDataItemProvider *provider)
Emitted when a new data item provider has been added.
void addProvider(QgsDataItemProvider *provider)
Adds a provider implementation to the registry.
QgsDataItemProvider * provider(const QString &providerName) const
Returns the (possibly nullptr) data item provider named providerName.
This is the interface for those who want to add custom data items to the browser tree.
virtual QString dataProviderKey() const
Returns the data provider key (if the data item provider is associated with a data provider),...
virtual QString name()=0
Human-readable name of the provider name.
A data item provider for file based data sources.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QList< QgsDataItemProvider * > dataItemProviders(const QString &providerKey) const
Returns list of data item providers of the provider.
QStringList providerList() const
Returns list of available providers by their keys.