QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgssensorthingsguiprovider.h"
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 QgsProviderGuiMetadata *sensorThings = new QgsSensorThingsProviderGuiMetadata();
125 mProviders[ sensorThings->key() ] = sensorThings;
126
127#ifdef HAVE_STATIC_PROVIDERS
128 QgsProviderGuiMetadata *wms = new QgsWmsProviderGuiMetadata();
129 mProviders[ wms->key() ] = wms;
130 QgsProviderGuiMetadata *wcs = new QgsWcsProviderGuiMetadata();
131 mProviders[ wcs->key() ] = wcs;
132 QgsProviderGuiMetadata *delimitedtext = new QgsDelimitedTextProviderGuiMetadata();
133 mProviders[ delimitedtext->key() ] = delimitedtext;
134 QgsProviderGuiMetadata *arc = new QgsArcGisRestProviderGuiMetadata();
135 mProviders[ arc->key() ] = arc;
136#ifdef HAVE_SPATIALITE
137 QgsProviderGuiMetadata *spatialite = new QgsSpatiaLiteProviderGuiMetadata();
138 mProviders[ spatialite->key() ] = spatialite;
139 QgsProviderGuiMetadata *wfs = new QgsWfsProviderGuiMetadata();
140 mProviders[ wfs->key() ] = wfs;
141 QgsProviderGuiMetadata *virtuallayer = new QgsVirtualLayerProviderGuiMetadata();
142 mProviders[ virtuallayer->key() ] = virtuallayer;
143#endif
144#ifdef HAVE_POSTGRESQL
145 QgsProviderGuiMetadata *postgres = new QgsPostgresProviderGuiMetadata();
146 mProviders[ postgres->key() ] = postgres;
147#endif
148#endif
149}
150
151void QgsProviderGuiRegistry::loadDynamicProviders( const QString &pluginPath )
152{
153#ifdef HAVE_STATIC_PROVIDERS
154 Q_UNUSED( pluginPath )
155 QgsDebugMsgLevel( QStringLiteral( "Forced only static GUI providers" ), 2 );
156#else
157 typedef QgsProviderGuiMetadata *factory_function( );
158
159 // add dynamic providers
160 QDir mLibraryDirectory( pluginPath );
161 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
162 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
163
164#if defined(Q_OS_WIN) || defined(__CYGWIN__)
165 mLibraryDirectory.setNameFilters( QStringList( "*.dll" ) );
166#elif defined(ANDROID)
167 mLibraryDirectory.setNameFilters( QStringList( "*provider.so" ) );
168#else
169 mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( "*.so" ) ) );
170#endif
171
172 QgsDebugMsgLevel( QStringLiteral( "Checking %1 for GUI provider plugins" ).arg( mLibraryDirectory.path() ), 2 );
173
174 if ( mLibraryDirectory.count() == 0 )
175 {
176 QgsDebugError( QStringLiteral( "No dynamic QGIS GUI provider plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() ) );
177 }
178
179 // provider file regex pattern, only files matching the pattern are loaded if the variable is defined
180 const QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
181 QRegularExpression fileRegexp;
182 if ( !filePattern.isEmpty() )
183 {
184 fileRegexp.setPattern( filePattern );
185 }
186
187 const auto constEntryInfoList = mLibraryDirectory.entryInfoList();
188 for ( const QFileInfo &fi : constEntryInfoList )
189 {
190 if ( !fileRegexp.pattern().isEmpty() )
191 {
192 const QRegularExpressionMatch fileNameMatch = fileRegexp.match( fi.fileName() );
193 if ( !fileNameMatch.hasMatch() )
194 {
195 QgsDebugMsgLevel( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern, 2 );
196 continue;
197 }
198 }
199
200 QLibrary myLib( fi.filePath() );
201 if ( myLib.load() )
202 {
203 QFunctionPointer func = myLib.resolve( QStringLiteral( "providerGuiMetadataFactory" ).toLatin1().data() );
204 factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
205 if ( !function )
206 continue;
207
208 QgsProviderGuiMetadata *meta = function( );
209
210 if ( !meta )
211 continue;
212
213 const QString providerKey = meta->key();
214
215 // check if such providers is already registered
216 if ( findMetadata_( mProviders, providerKey ) )
217 continue;
218
219 mProviders[providerKey] = meta;
220 }
221 }
222#endif
223}
224
226{
227 GuiProviders::const_iterator it = mProviders.begin();
228 while ( it != mProviders.end() )
229 {
230 delete it->second;
231 ++it;
232 }
233 mProviders.clear();
234}
235
236void QgsProviderGuiRegistry::registerGuis( QMainWindow *parent )
237{
238 for ( auto it = mProviders.begin(); it != mProviders.end(); ++it )
239 {
240 it->second->registerGui( parent );
241 }
242}
243
244const QList<QgsDataItemGuiProvider *> QgsProviderGuiRegistry::dataItemGuiProviders( const QString &providerKey )
245{
246 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
247 if ( meta )
248 return meta->dataItemGuiProviders();
249 return QList<QgsDataItemGuiProvider *>();
250}
251
252QList<QgsSourceSelectProvider *> QgsProviderGuiRegistry::sourceSelectProviders( const QString &providerKey )
253{
254 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
255 if ( meta )
256 return meta->sourceSelectProviders();
257 return QList<QgsSourceSelectProvider *> ();
258}
259
260QList<QgsProjectStorageGuiProvider *> QgsProviderGuiRegistry::projectStorageGuiProviders( const QString &providerKey )
261{
262 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
263 if ( meta )
264 return meta->projectStorageGuiProviders();
265 return QList<QgsProjectStorageGuiProvider *>();
266}
267
268QList<QgsSubsetStringEditorProvider *> QgsProviderGuiRegistry::subsetStringEditorProviders( const QString &providerKey )
269{
270 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
271 if ( meta )
272 return meta->subsetStringEditorProviders();
273 return QList<QgsSubsetStringEditorProvider *>();
274}
275
276QList<QgsProviderSourceWidgetProvider *> QgsProviderGuiRegistry::sourceWidgetProviders( const QString &providerKey )
277{
278 QgsProviderGuiMetadata *meta = findMetadata_( mProviders, providerKey );
279 if ( meta )
280 return meta->sourceWidgetProviders();
281 return QList<QgsProviderSourceWidgetProvider *>();
282}
283
284QList<const QgsMapLayerConfigWidgetFactory *> QgsProviderGuiRegistry::mapLayerConfigWidgetFactories( QgsMapLayer *layer )
285{
286 QList<const QgsMapLayerConfigWidgetFactory *> res;
287 for ( GuiProviders::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
288 {
289 const QList<const QgsMapLayerConfigWidgetFactory *> providerFactories = ( *it ).second->mapLayerConfigWidgetFactories();
290 for ( const QgsMapLayerConfigWidgetFactory *factory : providerFactories )
291 {
292 if ( !layer || factory->supportsLayer( layer ) )
293 res << factory;
294 }
295 }
296 return res;
297}
298
300{
301 QStringList lst;
302 for ( GuiProviders::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
303 {
304 lst.append( it->first );
305 }
306 return lst;
307}
308
309const QgsProviderGuiMetadata *QgsProviderGuiRegistry::providerMetadata( const QString &providerKey ) const
310{
311 return findMetadata_( mProviders, providerKey );
312}
Factory class for creating custom map layer property pages.
Base class for all map layer types.
Definition qgsmaplayer.h:76
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:5769
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38