28 const QString &connectionUri,
29 const QString &providerKey,
30 const QString &schema,
31 const QString &tableName )
32 :
QgsDataItem(
Qgis::BrowserItemType::Fields, parent, tr(
"Fields" ), path, providerKey )
34 , mTableName( tableName )
35 , mConnectionUri( connectionUri )
44 mTableProperty = std::make_unique<QgsAbstractDatabaseProviderConnection::TableProperty>( conn->table(
schema,
tableName ) );
48 QgsDebugMsg( QStringLiteral(
"Error creating fields item: %1" ).arg( ex.
what() ) );
70 const QgsFields constFields { conn->fields( mSchema, mTableName ) };
71 for (
const auto &f : constFields )
94 return mConnectionUri;
99 std::unique_ptr<QgsVectorLayer> vl;
118 QgsDebugMsg( QStringLiteral(
"Error getting connection from %1" ).arg( mConnectionUri ) );
131 return mTableProperty.get();
145 :
QgsDataItem(
Qgis::BrowserItemType::Field, parent,
field.name(), parent->path() +
'/' +
field.name(), parent->providerKey() )
152 QStringList constraintsText;
153 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintNotNull ) )
155 constraintsText.push_back( tr(
"NOT NULL" ) );
157 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintUnique ) )
159 constraintsText.push_back( tr(
"UNIQUE" ) );
161 if ( ! constraintsText.isEmpty() )
163 setToolTip( QStringLiteral(
"<ul><li>%1</li></ul>" ).arg( constraintsText.join( QLatin1String(
"</li><li>" ) ) ) );
175 if ( parentFields && parentFields->tableProperty() &&
176 parentFields->tableProperty()->geometryColumn() ==
mName &&
177 parentFields->tableProperty()->geometryColumnTypes().count() )
179 if ( mField.
typeName() == QLatin1String(
"raster" ) )
186 case QgsWkbTypes::GeometryType::LineGeometry:
188 case QgsWkbTypes::GeometryType::PointGeometry:
190 case QgsWkbTypes::GeometryType::PolygonGeometry:
192 case QgsWkbTypes::GeometryType::UnknownGeometry:
194 case QgsWkbTypes::GeometryType::NullGeometry:
The Qgis class provides global constants for use throughout the application.
@ 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,...
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
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.
void setSortKey(const QVariant &key)
Sets a custom sorting key for the item.
void setToolTip(const QString &msg)
QVector< QgsDataItem * > children() const
QgsDataItem * parent() const
Gets item parent.
Qgis::BrowserItemCapabilities mCapabilities
virtual void setState(Qgis::BrowserItemState state)
Set item state.
QString providerKey() const
Returns the provider key that created this item (e.g.
Data item that can be used to report problems (e.g.
Q_GADGET Constraints constraints
A layer field item, information about the connection URI, the schema and the table as well as the lay...
QgsFieldItem(QgsDataItem *parent, const QgsField &field)
Constructor for QgsFieldItem, with the specified parent item and field.
Encapsulate a field in an attribute table or data source.
QString typeName() const
Gets the field type.
QVariant::Type subType() const
If the field is a collection, gets its element's type.
QgsFieldConstraints constraints
A collection of field items with some internal logic to retrieve the fields and a the vector layer in...
QString tableName() const
Returns the table name.
QgsFieldsItem(QgsDataItem *parent, const QString &path, const QString &connectionUri, const QString &providerKey, const QString &schema, const QString &tableName)
Constructor for QgsFieldsItem, with the specified parent item.
QgsAbstractDatabaseProviderConnection::TableProperty * tableProperty() const
Returns the (possibly NULL) properties of the table this fields belong to.
QString connectionUri() const
Returns the connection URI.
QVector< QgsDataItem * > createChildren() override
Create children.
QgsVectorLayer * layer()
Creates and returns a (possibly NULL) layer from the connection URI and schema/table information.
~QgsFieldsItem() override
QString schema() const
Returns the schema name.
Container of fields for a vector layer.
static QIcon iconForFieldType(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns an icon corresponding to a field type.
static QIcon iconLine()
Returns an icon representing line geometries.
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
static QIcon iconGeometryCollection()
Returns an icon representing geometry collections.
static QIcon iconDefaultLayer()
Returns a default icon for layers, which aren't the standard raster/vector/...
static QIcon iconPoint()
Returns an icon representing point geometries.
static QIcon iconRaster()
Returns an icon representing raster layers.
Custom exception class for provider connection related exceptions.
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.
Represents a vector layer which manages a vector based data sets.
static GeometryType geometryType(Type type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
The TableProperty class represents a database table or view.