QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
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
51QList<QgsDataItemProvider *> QgsDataItemProviderRegistry::providers() const { return mProviders; }
52
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
85QString QgsDataItemProviderRegistry::dataProviderKey( const QString &dataItemProviderName )
86{
87 return mDataItemProviderOrigin.value( dataItemProviderName, QString() );
88}
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.