QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
32{
33
34}
35
37{
38 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconDbSchema.svg" ) );
39}
40
42{
43 const QString dataProviderKey { QgsApplication::dataItemProviderRegistry()->dataProviderKey( providerKey() ) };
45 if ( ! md )
46 {
47 return nullptr;
48 }
49 const QString connectionName { parent()->name() };
50 try
51 {
52 return static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( connectionName ) );
53 }
55 {
56 // This is expected and it is not an error in case the provider does not implement
57 // the connections API
58 }
59 return nullptr;
60}
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...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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).
Definition: qgsdataitem.h:345
QgsDataItem * parent() const
Gets item parent.
Definition: qgsdataitem.h:330
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...
static QIcon iconDataCollection()
Returns the standard browser data collection icon.
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:101
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.