QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  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 }
QgsProjectStorageGuiRegistry::~QgsProjectStorageGuiRegistry
~QgsProjectStorageGuiRegistry()
Definition: qgsprojectstorageguiregistry.cpp:24
QgsProjectStorageGuiRegistry::registerProjectStorage
void registerProjectStorage(QgsProjectStorageGuiProvider *storage)
Registers a storage backend and takes ownership of it.
Definition: qgsprojectstorageguiregistry.cpp:51
qgsprojectstorageguiprovider.h
QgsProjectStorageGuiProvider::type
virtual QString type()=0
Unique identifier of the project storage type.
QgsProjectStorageGuiRegistry::QgsProjectStorageGuiRegistry
QgsProjectStorageGuiRegistry()
qgsproviderguiregistry.h
QgsProjectStorageGuiRegistry::projectStorageFromType
QgsProjectStorageGuiProvider * projectStorageFromType(const QString &type)
Returns storage implementation if the storage type matches one. Returns nullptr otherwise (it is a no...
Definition: qgsprojectstorageguiregistry.cpp:29
QgsProjectStorageGuiRegistry::projectStorages
QList< QgsProjectStorageGuiProvider * > projectStorages() const
Returns a list of registered project storage implementations.
Definition: qgsprojectstorageguiregistry.cpp:46
QgsProjectStorageGuiRegistry::projectStorageFromUri
QgsProjectStorageGuiProvider * projectStorageFromUri(const QString &uri)
Returns storage implementation if the URI matches one. Returns nullptr otherwise (it is a normal file...
Definition: qgsprojectstorageguiregistry.cpp:34
QgsProviderGuiRegistry
A registry / canonical manager of GUI parts of data providers.
Definition: qgsproviderguiregistry.h:50
QgsProviderGuiRegistry::projectStorageGuiProviders
virtual QList< QgsProjectStorageGuiProvider * > projectStorageGuiProviders(const QString &providerKey)
Returns all project storage gui providers registered in provider with providerKey.
Definition: qgsproviderguiregistry.cpp:191
qgsprojectstorageguiregistry.h
QgsProjectStorageGuiProvider
Abstract interface for project storage GUI - to be implemented by various backends and registered in ...
Definition: qgsprojectstorageguiprovider.h:32
QgsProjectStorageGuiRegistry::unregisterProjectStorage
void unregisterProjectStorage(QgsProjectStorageGuiProvider *storage)
Unregisters a storage backend and destroys its instance.
Definition: qgsprojectstorageguiregistry.cpp:56
QgsProviderGuiRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderguiregistry.cpp:199
QgsProjectStorageGuiRegistry::initializeFromProviderGuiRegistry
void initializeFromProviderGuiRegistry(QgsProviderGuiRegistry *providerGuiRegistry)
Initializes the registry.
Definition: qgsprojectstorageguiregistry.cpp:61