QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsconnectionregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsconnectionregistry.cpp
3  --------------------------
4  begin : March 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail 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 
18 #include "qgsconnectionregistry.h"
19 #include "qgsproviderregistry.h"
20 #include "qgsprovidermetadata.h"
21 
23  : QObject( parent )
24 {
25 }
26 
28 {
29  QRegularExpressionMatch m = QRegularExpression( QStringLiteral( "(.*?)\\://(.*)" ) ).match( id );
30  if ( !m.hasMatch() )
31  throw QgsProviderConnectionException( QObject::tr( "Invalid connection id" ) );
32 
33  const QString providerKey = m.captured( 1 );
34  const QString name = m.captured( 2 );
35 
37 
38  if ( !md )
39  throw QgsProviderConnectionException( QObject::tr( "Invalid provider key: %1" ).arg( providerKey ) );
40 
41  return md->createConnection( name );
42 }
QgsConnectionRegistry::QgsConnectionRegistry
QgsConnectionRegistry(QObject *parent=nullptr)
Constructor for QgsConnectionRegistry.
Definition: qgsconnectionregistry.cpp:22
QgsProviderMetadata::createConnection
virtual QgsAbstractProviderConnection * createConnection(const QString &uri, const QVariantMap &configuration) SIP_THROW(QgsProviderConnectionException)
Creates a new connection from uri and configuration, the newly created connection is not automaticall...
Definition: qgsprovidermetadata.cpp:241
QgsConnectionRegistry::createConnection
QgsAbstractProviderConnection * createConnection(const QString &name) SIP_THROW(QgsProviderConnectionException)
Creates a new connection by loading the connection with the given id from the settings.
Definition: qgsconnectionregistry.cpp:27
qgsconnectionregistry.h
qgsprovidermetadata.h
qgsproviderregistry.h
QgsProviderRegistry::providerMetadata
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
Definition: qgsproviderregistry.cpp:722
QgsProviderConnectionException
Definition: qgsexception.h:100
QgsProviderMetadata
Definition: qgsprovidermetadata.h:126
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:44
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:48
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53