QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
19#include "moc_qgsconnectionregistry.cpp"
20#include "qgsproviderregistry.h"
21#include "qgsprovidermetadata.h"
22#include <QRegularExpression>
23
25 : QObject( parent )
26{
27}
28
30{
31 const QRegularExpressionMatch m = QRegularExpression( QStringLiteral( "(.*?)\\://(.*)" ) ).match( id );
32 if ( !m.hasMatch() )
33 throw QgsProviderConnectionException( QObject::tr( "Invalid connection id" ) );
34
35 const QString providerKey = m.captured( 1 );
36 const QString name = m.captured( 2 );
37
39
40 if ( !md )
41 throw QgsProviderConnectionException( QObject::tr( "Invalid provider key: %1" ).arg( providerKey ) );
42
43 return md->createConnection( name );
44}
The QgsAbstractProviderConnection provides an interface for data provider connections.
QgsAbstractProviderConnection * createConnection(const QString &name)
Creates a new connection by loading the connection with the given id from the settings.
QgsConnectionRegistry(QObject *parent=nullptr)
Constructor for QgsConnectionRegistry.
Custom exception class for provider connection related exceptions.
Holds data provider key, description, and associated shared library file or function pointer informat...
virtual QgsAbstractProviderConnection * createConnection(const QString &uri, const QVariantMap &configuration)
Creates a new connection from uri and configuration, the newly created connection is not automaticall...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53