QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgsproviderregistry.h"
20#include "qgsprovidermetadata.h"
21#include <QRegularExpression>
22
24 : QObject( parent )
25{
26}
27
29{
30 const QRegularExpressionMatch m = QRegularExpression( QStringLiteral( "(.*?)\\://(.*)" ) ).match( id );
31 if ( !m.hasMatch() )
32 throw QgsProviderConnectionException( QObject::tr( "Invalid connection id" ) );
33
34 const QString providerKey = m.captured( 1 );
35 const QString name = m.captured( 2 );
36
38
39 if ( !md )
40 throw QgsProviderConnectionException( QObject::tr( "Invalid provider key: %1" ).arg( providerKey ) );
41
42 return md->createConnection( name );
43}
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