QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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 "moc_qgsfielddomainsitem.cpp"
20#include "qgsproviderregistry.h"
21#include "qgsprovidermetadata.h"
22#include "qgsapplication.h"
23#include "qgsfielddomain.h"
24#include "qgsmessagelog.h"
25
27 const QString &path,
28 const QString &connectionUri,
29 const QString &providerKey )
30 : QgsDataItem( Qgis::BrowserItemType::Custom, parent, tr( "Field Domains" ), path, providerKey )
31 , mConnectionUri( connectionUri )
32{
34}
35
37
39{
40 QVector<QgsDataItem *> children;
41 try
42 {
44 if ( md )
45 {
46 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn { static_cast<QgsAbstractDatabaseProviderConnection *>( md->createConnection( mConnectionUri, {} ) ) };
48 {
49 QString domainError;
50 QStringList fieldDomains;
51 try
52 {
53 fieldDomains = conn->fieldDomainNames();
54 }
56 {
57 domainError = ex.what();
58 }
59
60 for ( const QString &name : std::as_const( fieldDomains ) )
61 {
62 try
63 {
64 std::unique_ptr< QgsFieldDomain > domain( conn->fieldDomain( name ) );
65 QgsFieldDomainItem *fieldDomainItem { new QgsFieldDomainItem( this, domain.release() ) };
66 children.push_back( fieldDomainItem );
67 }
69 {
71 }
72 }
73
74 if ( !domainError.isEmpty() )
75 {
76 children.push_back( new QgsErrorItem( this, domainError, path() + QStringLiteral( "/domainerror" ) ) );
77 }
78 }
79 }
80 }
81 catch ( const QgsProviderConnectionException &ex )
82 {
83 children.push_back( new QgsErrorItem( this, ex.what(), path() + QStringLiteral( "/error" ) ) );
84 }
85 return children;
86}
87
89{
90 return QgsApplication::getThemeIcon( QStringLiteral( "mSourceFields.svg" ) );
91}
92
94{
95 return mConnectionUri;
96}
97
98//
99// QgsFieldDomainItem
100//
101
103 : QgsDataItem( Qgis::BrowserItemType::Custom, parent, domain->name(), parent->path() + '/' + domain->name(), parent->providerKey() )
104 , mDomain( domain )
105{
106 // Precondition
107 Q_ASSERT( dynamic_cast<QgsFieldDomainsItem *>( parent ) );
109 setToolTip( domain->description().isEmpty() ? domain->name() : domain->description() );
110}
111
113{
114 switch ( mDomain->type() )
115 {
117 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldText.svg" ) );
119 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldInteger.svg" ) );
121 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldText.svg" ) );
122 }
124}
125
127{
128 return mDomain.get();
129}
130
132
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.
@ 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()
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:6612