QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 ***************************************************************************/
18#include "qgsfeedback.h"
19
21 : QObject( parent )
22{
23
24}
25
27{
28 mMetadataProviders.insert( metadataProvider->id(), metadataProvider );
29}
30
32{
33 delete mMetadataProviders.take( metadataProvider->id() );
34}
35
36QList<QgsAbstractLayerMetadataProvider *> QgsLayerMetadataProviderRegistry::layerMetadataProviders() const
37{
38 return mMetadataProviders.values();
39}
40
42{
43 return mMetadataProviders.value( type, nullptr );
44}
45
46const QgsLayerMetadataSearchResults QgsLayerMetadataProviderRegistry::search( const QgsMetadataSearchContext &searchContext, const QString &searchString, const QgsRectangle &geographicExtent, QgsFeedback *feedback )
47{
49 for ( auto it = mMetadataProviders.cbegin(); it != mMetadataProviders.cend(); ++it )
50 {
51
52 if ( feedback && feedback->isCanceled() )
53 {
54 break;
55 }
56
57 const QgsLayerMetadataSearchResults providerResults { it.value()->search( searchContext, searchString, geographicExtent ) };
58 const QList<QgsLayerMetadataProviderResult> constMetadata { providerResults.metadata() };
59 for ( const QgsLayerMetadataProviderResult &metadata : std::as_const( constMetadata ) )
60 {
61 results.addMetadata( metadata );
62 }
63 const QList<QString> constErrors { providerResults.errors() };
64 for ( const QString &error : std::as_const( constErrors ) )
65 {
66 results.addError( error );
67 }
68 }
69 return results;
70}
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:45
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:54
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.
Definition: qgsrectangle.h:42