QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgsdatabaseschemaitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatabaseschemaitem.cpp
3 -------------------
4 begin : 2011-04-01
5 copyright : (C) 2011 Radim Blazek
6 email : radim dot blazek 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 "qgsapplication.h"
21#include "qgsprovidermetadata.h"
22#include "qgsproviderregistry.h"
24
25QgsDatabaseSchemaItem::QgsDatabaseSchemaItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &providerKey )
26 : QgsDataCollectionItem( parent, name, path, providerKey )
27{
28
29}
30
35
37{
38 const QString dataProviderKey { QgsApplication::dataItemProviderRegistry()->dataProviderKey( providerKey() ) };
40 if ( ! md )
41 {
42 return nullptr;
43 }
44 const QString connectionName { parent()->name() };
45 try
46 {
47 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( connectionName ) );
48 }
50 {
51 // This is expected and it is not an error in case the provider does not implement
52 // the connections API
53 }
54 return nullptr;
55}
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
static QgsDataItemProviderRegistry * dataItemProviderRegistry()
Returns the application's data item provider registry, which keeps a list of data item providers that...
A Collection: logical collection of layers or subcollections, e.g.
QString dataProviderKey(const QString &dataItemProviderName)
Returns the (possibly blank) data provider key for a given data item provider name.
Base class for all items in the model.
Definition qgsdataitem.h:46
QString name() const
Returns the name of the item (the displayed text for the item).
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
QgsDatabaseSchemaItem(QgsDataItem *parent, const QString &name, const QString &path=QString(), const QString &providerKey=QString())
Constructor for QgsDatabaseSchemaItem, with the specified parent item.
QgsAbstractDatabaseProviderConnection * databaseConnection() const override
For data items that represent a DB connection or one of its children, this method returns a connectio...
Custom exception class for provider connection related exceptions.
Holds data provider key, description, and associated shared library file or function pointer informat...
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.