QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsprojectstorageguiregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprojectstorageguiregistry.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 
20 #include "qgsproviderguiregistry.h"
21 
23 
25 {
26  qDeleteAll( mBackends );
27 }
28 
30 {
31  return mBackends.value( type, nullptr );
32 }
33 
35 {
36  for ( auto it = mBackends.constBegin(); it != mBackends.constEnd(); ++it )
37  {
38  QgsProjectStorageGuiProvider *storage = it.value();
39  const QString scheme = storage->type() + ':';
40  if ( uri.startsWith( scheme ) )
41  return storage;
42  }
43  return nullptr;
44 }
45 
46 QList<QgsProjectStorageGuiProvider *> QgsProjectStorageGuiRegistry::projectStorages() const
47 {
48  return mBackends.values();
49 }
50 
52 {
53  mBackends.insert( storage->type(), storage );
54 }
55 
57 {
58  delete mBackends.take( storage->type() );
59 }
60 
62 {
63  if ( !providerGuiRegistry )
64  return;
65 
66  const QStringList providersList = providerGuiRegistry->providerList();
67  for ( const QString &key : providersList )
68  {
69  const QList<QgsProjectStorageGuiProvider *> providerList = providerGuiRegistry->projectStorageGuiProviders( key );
70  // the function is a factory - we keep ownership of the returned providers
71  for ( QgsProjectStorageGuiProvider *provider : providerList )
72  {
73  mBackends[key] = provider;
74  }
75  }
76 }
Abstract interface for project storage GUI - to be implemented by various backends and registered in ...
virtual QString type()=0
Unique identifier of the project storage type.
QgsProjectStorageGuiProvider * projectStorageFromType(const QString &type)
Returns storage implementation if the storage type matches one. Returns nullptr otherwise (it is a no...
void unregisterProjectStorage(QgsProjectStorageGuiProvider *storage)
Unregisters a storage backend and destroys its instance.
QList< QgsProjectStorageGuiProvider * > projectStorages() const
Returns a list of registered project storage implementations.
void registerProjectStorage(QgsProjectStorageGuiProvider *storage)
Registers a storage backend and takes ownership of it.
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
QgsProjectStorageGuiProvider * projectStorageFromUri(const QString &uri)
Returns storage implementation if the URI matches one. Returns nullptr otherwise (it is a normal file...
A registry / canonical manager of GUI parts of data providers.
virtual QList< QgsProjectStorageGuiProvider * > projectStorageGuiProviders(const QString &providerKey)
Returns all project storage gui providers registered in provider with providerKey.
QStringList providerList() const
Returns list of available providers by their keys.