QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgslayermetadataproviderregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayermetadataproviderregistry.cpp - QgsLayerMetadataProviderRegistry
3
4 ---------------------
5 begin : 17.8.2022
6 copyright : (C) 2022 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17#include "moc_qgslayermetadataproviderregistry.cpp"
19#include "qgsfeedback.h"
20
22 : QObject( parent )
23{
24
25}
26
28{
29 mMetadataProviders.insert( metadataProvider->id(), metadataProvider );
30}
31
33{
34 delete mMetadataProviders.take( metadataProvider->id() );
35}
36
37QList<QgsAbstractLayerMetadataProvider *> QgsLayerMetadataProviderRegistry::layerMetadataProviders() const
38{
39 return mMetadataProviders.values();
40}
41
43{
44 return mMetadataProviders.value( type, nullptr );
45}
46
47const QgsLayerMetadataSearchResults QgsLayerMetadataProviderRegistry::search( const QgsMetadataSearchContext &searchContext, const QString &searchString, const QgsRectangle &geographicExtent, QgsFeedback *feedback )
48{
50 for ( auto it = mMetadataProviders.cbegin(); it != mMetadataProviders.cend(); ++it )
51 {
52
53 if ( feedback && feedback->isCanceled() )
54 {
55 break;
56 }
57
58 const QgsLayerMetadataSearchResults providerResults { it.value()->search( searchContext, searchString, geographicExtent ) };
59 const QList<QgsLayerMetadataProviderResult> constMetadata { providerResults.metadata() };
60 for ( const QgsLayerMetadataProviderResult &metadata : std::as_const( constMetadata ) )
61 {
62 results.addMetadata( metadata );
63 }
64 const QList<QString> constErrors { providerResults.errors() };
65 for ( const QString &error : std::as_const( constErrors ) )
66 {
67 results.addError( error );
68 }
69 }
70 return results;
71}
Layer metadata provider backend interface.
virtual QString id() const =0
Returns the id of the layer metadata provider implementation, usually the name of the data provider b...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:53
QgsLayerMetadataProviderRegistry(QObject *parent=nullptr)
Creates the layer metadata provider registry, with an optional parent.
QList< QgsAbstractLayerMetadataProvider * > layerMetadataProviders() const
Returns the list of all registered layer metadata providers.
const QgsLayerMetadataSearchResults search(const QgsMetadataSearchContext &searchContext, const QString &searchString=QString(), const QgsRectangle &geographicExtent=QgsRectangle(), QgsFeedback *feedback=nullptr)
Search for layers in all the registered layer metadata providers, optionally filtering by searchStrin...
void unregisterLayerMetadataProvider(QgsAbstractLayerMetadataProvider *metadataProvider)
Unregisters a layer metadata provider metadataProvider and destroys its instance.
void registerLayerMetadataProvider(QgsAbstractLayerMetadataProvider *metadataProvider)
Registers a layer metadata provider metadataProvider and takes ownership of it.
QgsAbstractLayerMetadataProvider * layerMetadataProviderFromId(const QString &id)
Returns metadata provider implementation if the id matches one. Returns nullptr otherwise.
Result record of layer metadata provider search.
Container of result records from a layer metadata search.
void addError(const QString &error)
Adds a error to the list of errors.
void addMetadata(const QgsLayerMetadataProviderResult &metadata)
Adds a Metadata record to the list of results.
QList< QgsLayerMetadataProviderResult > metadata() const
Returns the list of metadata results.
A rectangle specified with double values.