1 /*************************************************************************** 2 qgsprojectstorageregistry.cpp 3 -------------------------------------- 4 Date : March 2018 5 Copyright : (C) 2018 by Martin Dobias 6 Email : wonder dot sk at gmail dot com 7 *************************************************************************** 8 * * 9 * This program is free software; you can redistribute it and/or modify * 10 * it under the terms of the GNU General Public License as published by * 11 * the Free Software Foundation; either version 2 of the License, or * 12 * (at your option) any later version. * 13 * * 14 ***************************************************************************/ 15 16 #include "qgsprojectstorageregistry.h" 17 18 #include "qgsprojectstorage.h" 19 20 ~QgsProjectStorageRegistry()21QgsProjectStorageRegistry::~QgsProjectStorageRegistry() 22 { 23 qDeleteAll( mBackends ); 24 } 25 projectStorageFromType(const QString & type)26QgsProjectStorage *QgsProjectStorageRegistry::projectStorageFromType( const QString &type ) 27 { 28 return mBackends.value( type, nullptr ); 29 } 30 projectStorageFromUri(const QString & uri)31QgsProjectStorage *QgsProjectStorageRegistry::projectStorageFromUri( const QString &uri ) 32 { 33 for ( auto it = mBackends.constBegin(); it != mBackends.constEnd(); ++it ) 34 { 35 QgsProjectStorage *storage = it.value(); 36 const QString scheme = storage->type() + ':'; 37 if ( uri.startsWith( scheme ) ) 38 return storage; 39 } 40 41 // second chance -- use isSupportedUri to determine if a uri is supported by a backend 42 for ( auto it = mBackends.constBegin(); it != mBackends.constEnd(); ++it ) 43 { 44 QgsProjectStorage *storage = it.value(); 45 if ( storage->isSupportedUri( uri ) ) 46 return storage; 47 } 48 return nullptr; 49 } 50 projectStorages() const51QList<QgsProjectStorage *> QgsProjectStorageRegistry::projectStorages() const 52 { 53 return mBackends.values(); 54 } 55 registerProjectStorage(QgsProjectStorage * storage)56void QgsProjectStorageRegistry::registerProjectStorage( QgsProjectStorage *storage ) 57 { 58 mBackends.insert( storage->type(), storage ); 59 } 60 unregisterProjectStorage(QgsProjectStorage * storage)61void QgsProjectStorageRegistry::unregisterProjectStorage( QgsProjectStorage *storage ) 62 { 63 delete mBackends.take( storage->type() ); 64 } 65