QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsproviderguiregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsproviderrguiegistry.cpp
3 -------------------
4 begin : June 2019
5 copyright : (C) 2019 by Peter Petrik
6 email : zilolv at google dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <QString>
21#include <QDir>
22#include <QLibrary>
23#include <QRegularExpression>
24
25#include "qgslogger.h"
26#include "qgsgdalguiprovider.h"
27#include "qgsogrguiprovider.h"
29#include "qgspointcloudproviderguimetadata.h"
31
33#include "qgsmbtilesvectortileguiprovider.h"
34#include "qgsvtpkvectortileguiprovider.h"
35
36#ifdef HAVE_EPT
37#include "qgseptproviderguimetadata.h"
38#endif
39
40#ifdef HAVE_COPC
41#include "qgscopcproviderguimetadata.h"
42#endif
43
44#ifdef HAVE_STATIC_PROVIDERS
45#include "qgswmsprovidergui.h"
46#include "qgswcsprovidergui.h"
47#include "qgsdelimitedtextprovidergui.h"
48#include "qgsarcgisrestprovidergui.h"
49#ifdef HAVE_SPATIALITE
50#include "qgsspatialiteprovidergui.h"
51#include "qgswfsprovidergui.h"
52#include "qgsvirtuallayerprovidergui.h"
53#endif
54#ifdef HAVE_POSTGRESQL
55#include "qgspostgresprovidergui.h"
56#endif
57#endif
58
67static
69 QString const &providerKey )
70{
71 const QgsProviderGuiRegistry::GuiProviders::const_iterator i = metaData.find( providerKey );
72 if ( i != metaData.end() )
73 {
74 return i->second;
75 }
76
77 return nullptr;
78} // findMetadata_
79
81{
82 loadStaticProviders();
83 loadDynamicProviders( pluginPath );
84}
85
86void QgsProviderGuiRegistry::loadStaticProviders( )
87{
88 // Register static providers
89 QgsProviderGuiMetadata *gdal = new QgsGdalGuiProviderMetadata();
90 mProviders[ gdal->key() ] = gdal;
91
92 QgsProviderGuiMetadata *ogr = new QgsOgrGuiProviderMetadata();
93 mProviders[ ogr->key() ] = ogr;
94
95 QgsProviderGuiMetadata *vt = new QgsVectorTileProviderGuiMetadata();
96 mProviders[ vt->key() ] = vt;
97
98 QgsProviderGuiMetadata *mbtilesVectorTiles = new QgsMbtilesVectorTileGuiProviderMetadata();
99 mProviders[ mbtilesVectorTiles->key() ] = mbtilesVectorTiles;
100
101 QgsProviderGuiMetadata *vtpkVectorTiles = new QgsVtpkVectorTileGuiProviderMetadata();
102 mProviders[ vtpkVectorTiles->key() ] = vtpkVectorTiles;
103
104#ifdef HAVE_EPT
105 QgsProviderGuiMetadata *ept = new QgsEptProviderGuiMetadata();
106 mProviders[ ept->key() ] = ept;
107#endif
108
109#ifdef HAVE_COPC
110 QgsProviderGuiMetadata *copc = new QgsCopcProviderGuiMetadata();
111 mProviders[ copc->key() ] = copc;
112#endif
113
114 // only show point cloud option if we have at least one point cloud provider available!
115 if ( !QgsProviderRegistry::instance()->filePointCloudFilters().isEmpty() )
116 {
117 QgsProviderGuiMetadata *pointcloud = new QgsPointCloudProviderGuiMetadata();
118 mProviders[ pointcloud->key() ] = pointcloud;
119 }
120
121 QgsProviderGuiMetadata *tiledScene = new QgsTiledSceneProviderGuiMetadata();
122 mProviders[ tiledScene ->key() ] = tiledScene ;
123
124#ifdef HAVE_STATIC_PROVIDERS
125 QgsProviderGuiMetadata *wms = new QgsWmsProviderGuiMetadata();
126 mProviders[ wms->key() ] = wms;
127 QgsProviderGuiMetadata *wcs = new QgsWcsProviderGuiMetadata();
128 mProviders[ wcs->key() ] = wcs;
129 QgsProviderGuiMetadata *delimitedtext = new QgsDelimitedTextProviderGuiMetadata();
130 mProviders[ delimitedtext->key() ] = delimitedtext;
131 QgsProviderGuiMetadata *arc = new QgsArcGisRestProviderGuiMetadata();
132 mProviders[ arc->key() ] = arc;
133#ifdef HAVE_SPATIALITE
134 QgsProviderGuiMetadata *spatialite = new QgsSpatiaLiteProviderGuiMetadata();
135 mProviders[ spatialite->key() ] = spatialite;
136 QgsProviderGuiMetadata *wfs = new QgsWfsProviderGuiMetadata();
137 mProviders[ wfs->key() ] = wfs;
138 QgsProviderGuiMetadata *virtuallayer = new QgsVirtualLayerProviderGuiMetadata();
139 mProviders[ virtuallayer->key() ] = virtuallayer;
140#endif
141#ifdef HAVE_POSTGRESQL
142 QgsProviderGuiMetadata *postgres = new QgsPostgresProviderGuiMetadata();
143 mProviders[ postgres->key() ] = postgres;
144#endif
145#endif
146}
147
148void QgsProviderGuiRegistry::loadDynamicProviders( const QString &pluginPath )
149{
150#ifdef HAVE_STATIC_PROVIDERS
151 Q_UNUSED( pluginPath )
152 QgsDebugMsgLevel( QStringLiteral( "Forced only static GUI providers" ), 2 );
153#else
154 typedef QgsProviderGuiMetadata *factory_function( );
155
156 // add dynamic providers
157 QDir mLibraryDirectory( pluginPath );
158 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
159 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
160
161#if defined(Q_OS_WIN) || defined(__CYGWIN__)
162 mLibraryDirectory.setNameFilters( QStringList( "*.dll" ) );
163#elif defined(ANDROID)
164 mLibraryDirectory.setNameFilters( QStringList( "*provider.so" ) );
165#else
166 mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( "*.so" ) ) );
167#endif
168
169 QgsDebugMsgLevel( QStringLiteral( "Checking %1 for GUI provider plugins" ).arg( mLibraryDirectory.path() ), 2 );
170
171 if ( mLibraryDirectory.count() == 0 )
172 {
173 QgsDebugError( QStringLiteral( "No dynamic QGIS GUI provider plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() ) );
174 }
175
176 // provider file regex pattern, only files matching the pattern are loaded if the variable is defined
177 const QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
178 QRegularExpression fileRegexp;
179 if ( !filePattern.isEmpty() )
180 {
181 fileRegexp.setPattern( filePattern );
182 }
183
184 const auto constEntryInfoList = mLibraryDirectory.entryInfoList();
185 for ( const QFileInfo &fi : constEntryInfoList )
186 {
187 if ( !fileRegexp.pattern().isEmpty() )
188 {
189 const QRegularExpressionMatch fileNameMatch = fileRegexp.match( fi.fileName() );
190 if ( !fileNameMatch.hasMatch() )
191 {
192 QgsDebugMsgLevel( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern, 2 );
193 continue;
194 }
195 }
196
197 QLibrary myLib( fi.filePath() );
198 if ( myLib.load() )
199 {
200 QFunctionPointer func = myLib.resolve( QStringLiteral( "providerGuiMetadataFactory" ).toLatin1().data() );
201 factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
202 if ( !function )
203 continue;
204
205 QgsProviderGuiMetadata *meta = function( );
206
207 if ( !meta )
208 continue;
209
210 const QString providerKey = meta->key();
211
212 // check if such providers is already registered
213 if ( findMetadata_( mProviders, providerKey ) )
214 continue;
215
216 mProviders[providerKey] = meta;
217 }
218 }
219#endif
220}
221
223{
224 GuiProviders::const_iterator it = mProviders.begin();
225 while ( it != mProviders.end() )
226 {
227 delete it->second;
228 ++it;
229 }
230 mProviders.clear();
231}
232
233void QgsProviderGuiRegistry::registerGuis( QMainWindow *parent )
234{
235 for ( auto it = mProviders.begin(); it != mProviders.end(); ++it )
236 {
237 it->second->registerGui( parent );
238 }
239}
240
241const QList<QgsDataItemGuiProvider *> QgsProviderGuiRegistry::dataItemGuiProviders( const QString &providerKey )
242{
243 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
244 if ( meta )
245 return meta->dataItemGuiProviders();
246 return QList<QgsDataItemGuiProvider *>();
247}
248
249QList<QgsSourceSelectProvider *> QgsProviderGuiRegistry::sourceSelectProviders( const QString &providerKey )
250{
251 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
252 if ( meta )
253 return meta->sourceSelectProviders();
254 return QList<QgsSourceSelectProvider *> ();
255}
256
257QList<QgsProjectStorageGuiProvider *> QgsProviderGuiRegistry::projectStorageGuiProviders( const QString &providerKey )
258{
259 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
260 if ( meta )
261 return meta->projectStorageGuiProviders();
262 return QList<QgsProjectStorageGuiProvider *>();
263}
264
265QList<QgsSubsetStringEditorProvider *> QgsProviderGuiRegistry::subsetStringEditorProviders( const QString &providerKey )
266{
267 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
268 if ( meta )
269 return meta->subsetStringEditorProviders();
270 return QList<QgsSubsetStringEditorProvider *>();
271}
272
273QList<QgsProviderSourceWidgetProvider *> QgsProviderGuiRegistry::sourceWidgetProviders( const QString &providerKey )
274{
275 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
276 if ( meta )
277 return meta->sourceWidgetProviders();
278 return QList<QgsProviderSourceWidgetProvider *>();
279}
280
281QList<const QgsMapLayerConfigWidgetFactory *> QgsProviderGuiRegistry::mapLayerConfigWidgetFactories( QgsMapLayer *layer )
282{
283 QList<const QgsMapLayerConfigWidgetFactory *> res;
284 for ( GuiProviders::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
285 {
286 const QList<const QgsMapLayerConfigWidgetFactory *> providerFactories = ( *it ).second->mapLayerConfigWidgetFactories();
287 for ( const QgsMapLayerConfigWidgetFactory *factory : providerFactories )
288 {
289 if ( !layer || factory->supportsLayer( layer ) )
290 res << factory;
291 }
292 }
293 return res;
294}
295
297{
298 QStringList lst;
299 for ( GuiProviders::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
300 {
301 lst.append( it->first );
302 }
303 return lst;
304}
305
306const QgsProviderGuiMetadata *QgsProviderGuiRegistry::providerMetadata( const QString &providerKey ) const
307{
308 return findMetadata_( mProviders, providerKey );
309}
Factory class for creating custom map layer property pages.
Base class for all map layer types.
Definition qgsmaplayer.h:74
Holds data for GUI part of the data providers.
virtual QList< QgsSubsetStringEditorProvider * > subsetStringEditorProviders()
Returns subset string editor providers.
virtual QList< QgsDataItemGuiProvider * > dataItemGuiProviders()
Returns data item gui providers.
virtual QList< QgsProjectStorageGuiProvider * > projectStorageGuiProviders()
Returns project storage gui providers.
QString key() const
Returns unique provider key.
virtual QList< QgsProviderSourceWidgetProvider * > sourceWidgetProviders()
Returns source widget providers.
virtual QList< QgsSourceSelectProvider * > sourceSelectProviders()
Returns source select providers.
virtual const QList< QgsDataItemGuiProvider * > dataItemGuiProviders(const QString &providerKey)
Returns all data item gui providers registered in provider with providerKey.
virtual QList< QgsSubsetStringEditorProvider * > subsetStringEditorProviders(const QString &providerKey)
Returns all subset string editor providers registered in provider with providerKey.
const QgsProviderGuiMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
virtual QList< QgsProjectStorageGuiProvider * > projectStorageGuiProviders(const QString &providerKey)
Returns all project storage gui providers registered in provider with providerKey.
virtual QList< const QgsMapLayerConfigWidgetFactory * > mapLayerConfigWidgetFactories(QgsMapLayer *layer=nullptr)
Returns all map layer config widget factories associated with the registered providers.
std::map< QString, QgsProviderGuiMetadata * > GuiProviders
Type for data provider metadata associative container.
QgsProviderGuiRegistry(const QString &pluginPath)
Creates registry and loads static provider plugins.
virtual QList< QgsSourceSelectProvider * > sourceSelectProviders(const QString &providerKey)
Returns all source select providers registered in provider with providerKey.
virtual QList< QgsProviderSourceWidgetProvider * > sourceWidgetProviders(const QString &providerKey)
Returns all source widget providers registered in provider with providerKey.
void registerGuis(QMainWindow *widget)
Called during GUI initialization - allows providers to do its internal initialization of GUI componen...
QStringList providerList() const
Returns list of available providers by their keys.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
#define cast_to_fptr(f)
Definition qgis.h:4204
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38