QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgsdataitemguiproviderregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdataitemguiproviderregistry.cpp
3  --------------------------------------
4  Date : October 2018
5  Copyright : (C) 2018 by Nyall Dawson
6  Email : nyall dot dawson 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 "qgsdataitemguiprovider.h"
18 #include "qgsproviderregistry.h"
19 
20 typedef QList<QgsDataItemGuiProvider *> *dataItemGuiProviders_t();
21 
23 {
24  const QStringList providersList = QgsProviderRegistry::instance()->providerList();
25 
26  for ( const QString &key : providersList )
27  {
28  std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
29  if ( !library )
30  continue;
31 
32  if ( dataItemGuiProviders_t *dataItemGuiProvidersFn = reinterpret_cast< dataItemGuiProviders_t * >( cast_to_fptr( library->resolve( "dataItemGuiProviders" ) ) ) )
33  {
34  const QList<QgsDataItemGuiProvider *> *providerList = dataItemGuiProvidersFn();
35  // the function is a factory - we keep ownership of the returned providers
36  mProviders << *providerList;
37  delete providerList;
38  }
39  }
40 }
41 
43 {
44  qDeleteAll( mProviders );
45 }
46 
48 {
49  mProviders.append( provider );
50 }
51 
53 {
54  int index = mProviders.indexOf( provider );
55  if ( index >= 0 )
56  delete mProviders.takeAt( index );
57 }
QList< QgsDataItemGuiProvider * > * dataItemGuiProviders_t()
void removeProvider(QgsDataItemGuiProvider *provider)
Removes a provider implementation from the registry.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Abstract base class for providers which affect how QgsDataItem items behave within the application GU...
#define cast_to_fptr(f)
Definition: qgis.h:158
QStringList providerList() const
Returns list of available providers by their keys.
void addProvider(QgsDataItemGuiProvider *provider)
Adds a provider implementation to the registry.