QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsfielddomainsitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsfielddomainsitem.h
3 -------------------
4 begin : 2022-01-27
5 copyright : (C) 2022 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 "qgsfielddomainsitem.h"
19#include "qgsproviderregistry.h"
20#include "qgsprovidermetadata.h"
21#include "qgsapplication.h"
22#include "qgsfielddomain.h"
23#include "qgsmessagelog.h"
24
26 const QString &path,
27 const QString &connectionUri,
28 const QString &providerKey )
29 : QgsDataItem( Qgis::BrowserItemType::Custom, parent, tr( "Field Domains" ), path, providerKey )
30 , mConnectionUri( connectionUri )
31{
33}
34
36
38{
39 QVector<QgsDataItem *> children;
40 try
41 {
43 if ( md )
44 {
45 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn { static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( mConnectionUri, {} ) ) };
47 {
48 QString domainError;
49 QStringList fieldDomains;
50 try
51 {
52 fieldDomains = conn->fieldDomainNames();
53 }
55 {
56 domainError = ex.what();
57 }
58
59 for ( const QString &name : std::as_const( fieldDomains ) )
60 {
61 try
62 {
63 std::unique_ptr< QgsFieldDomain > domain( conn->fieldDomain( name ) );
64 QgsFieldDomainItem *fieldDomainItem { new QgsFieldDomainItem( this, domain.release() ) };
65 children.push_back( fieldDomainItem );
66 }
68 {
70 }
71 }
72
73 if ( !domainError.isEmpty() )
74 {
75 children.push_back( new QgsErrorItem( this, domainError, path() + QStringLiteral( "/domainerror" ) ) );
76 }
77 }
78 }
79 }
80 catch ( const QgsProviderConnectionException &ex )
81 {
82 children.push_back( new QgsErrorItem( this, ex.what(), path() + QStringLiteral( "/error" ) ) );
83 }
84 return children;
85}
86
88{
89 return QgsApplication::getThemeIcon( QStringLiteral( "mSourceFields.svg" ) );
90}
91
93{
94 return mConnectionUri;
95}
96
97//
98// QgsFieldDomainItem
99//
100
102 : QgsDataItem( Qgis::BrowserItemType::Custom, parent, domain->name(), parent->path() + '/' + domain->name(), parent->providerKey() )
103 , mDomain( domain )
104{
105 // Precondition
106 Q_ASSERT( dynamic_cast<QgsFieldDomainsItem *>( parent ) );
108 setToolTip( domain->description().isEmpty() ? domain->name() : domain->description() );
109}
110
112{
113 switch ( mDomain->type() )
114 {
116 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldText.svg" ) );
118 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldInteger.svg" ) );
120 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldText.svg" ) );
121 }
123}
124
126{
127 return mDomain.get();
128}
129
131
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
@ Populated
Children created.
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
@ Fertile
Can create children. Even items without this capability may have children, but cannot create them,...
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn (since QGIS 3....
@ Coded
Coded field domain.
@ Range
Numeric range field domain (min/max)
@ Glob
Glob string pattern field domain.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
@ RetrieveFieldDomain
Can retrieve field domain details from provider via fieldDomain() (since QGIS 3.26)
virtual QStringList fieldDomainNames() const
Returns a list of field domain names present on the provider.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Base class for all items in the model.
Definition qgsdataitem.h:46
void setToolTip(const QString &msg)
QVector< QgsDataItem * > children() const
Qgis::BrowserItemCapabilities mCapabilities
QString name() const
Returns the name of the item (the displayed text for the item).
QString path() const
virtual void setState(Qgis::BrowserItemState state)
Set item state.
QgsDataItem * parent() const
Gets item parent.
QString providerKey() const
Returns the provider key that created this item (e.g.
Data item that can be used to report problems (e.g.
QString what() const
A browser item representing a field domain.
const QgsFieldDomain * fieldDomain()
Returns the associated field domain.
~QgsFieldDomainItem() override
QgsFieldDomainItem(QgsDataItem *parent, QgsFieldDomain *domain)
Constructor for QgsFieldDomainItem, with the specified parent item and domain.
Base class for field domains.
QString name() const
Returns the name of the field domain.
QString description() const
Returns the description of the field domain.
Contains a collection of field domain items.
QgsFieldDomainsItem(QgsDataItem *parent, const QString &path, const QString &connectionUri, const QString &providerKey)
Constructor for QgsFieldDomainsItem, with the specified parent item.
QVector< QgsDataItem * > createChildren() override
Create children.
~QgsFieldDomainsItem() override
QString connectionUri() const
Returns the connection URI.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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.
#define BUILTIN_UNREACHABLE
Definition qgis.h:5790