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 ) );
45 if ( conn->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::RenameField )
52 QgsDebugMsg( QStringLiteral(
"Error creating fields item: %1" ).arg( ex.
what() ) );
74 const QgsFields constFields { conn->fields( mSchema, mTableName ) };
75 for (
const auto &f : constFields )
98 return mConnectionUri;
103 std::unique_ptr<QgsVectorLayer> vl;
122 QgsDebugMsg( QStringLiteral(
"Error getting connection from %1" ).arg( mConnectionUri ) );
135 return mTableProperty.get();
149 :
QgsDataItem(
Qgis::BrowserItemType::Field, parent,
field.name(), parent->path() +
'/' +
field.name(), parent->providerKey() )
154 Q_ASSERT( fieldsItem );
161 QStringList constraintsText;
162 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintNotNull ) )
164 constraintsText.push_back( tr(
"NOT NULL" ) );
166 if ( constraints.testFlag( QgsFieldConstraints::Constraint::ConstraintUnique ) )
168 constraintsText.push_back( tr(
"UNIQUE" ) );
170 if ( ! constraintsText.isEmpty() )
172 setToolTip( QStringLiteral(
"<ul><li>%1</li></ul>" ).arg( constraintsText.join( QLatin1String(
"</li><li>" ) ) ) );
184 if ( parentFields && parentFields->tableProperty() &&
185 parentFields->tableProperty()->geometryColumn() ==
mName &&
186 !parentFields->tableProperty()->geometryColumnTypes().isEmpty() )
188 if ( mField.
typeName() == QLatin1String(
"raster" ) )
195 case QgsWkbTypes::GeometryType::LineGeometry:
197 case QgsWkbTypes::GeometryType::PointGeometry:
199 case QgsWkbTypes::GeometryType::PolygonGeometry:
201 case QgsWkbTypes::GeometryType::UnknownGeometry:
203 case QgsWkbTypes::GeometryType::NullGeometry:
223 const QgsFieldItem *o = qobject_cast<const QgsFieldItem *>( other );
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,...
@ RefreshChildrenWhenItemIsRefreshed
When the item is refreshed, all its populated children will also be refreshed in turn (since QGIS 3....
@ Rename
Item can be renamed.
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
Qgis::BrowserItemCapabilities mCapabilities
Qgis::BrowserItemType type() 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.
Q_GADGET Constraints constraints
A layer field item, information about the connection URI, the schema and the table as well as the lay...
bool equal(const QgsDataItem *other) override
Returns true if this item is equal to another item (by testing item type and path).
QgsFieldItem(QgsDataItem *parent, const QgsField &field)
Constructor for QgsFieldItem, with the specified parent item and field.
QgsField field() const
Returns the field definition.
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.
bool canRenameFields() const
Returns true if the connection supports renaming fields.
~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/... types.
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.