29 const QString &connectionUri,
30 const QString &providerKey,
31 const QString &schema,
32 const QString &tableName )
33 :
QgsDataItem(
Qgis::BrowserItemType::Fields, parent, tr(
"Fields" ), path, providerKey )
35 , mTableName( tableName )
36 , mConnectionUri( connectionUri )
45 mTableProperty = std::make_unique<QgsAbstractDatabaseProviderConnection::TableProperty>( conn->table(
schema,
tableName ) );
53 QgsDebugError( QStringLiteral(
"Error creating fields item: %1" ).arg( ex.
what() ) );
75 const QgsFields constFields { conn->fields( mSchema, mTableName ) };
76 for (
const auto &f : constFields )
99 return mConnectionUri;
104 std::unique_ptr<QgsVectorLayer> vl;
123 QgsDebugError( QStringLiteral(
"Error getting connection from %1" ).arg( mConnectionUri ) );
136 return mTableProperty.get();
150 :
QgsDataItem(
Qgis::BrowserItemType::Field, parent, field.name(), parent->path() +
'/' + field.name(), parent->providerKey() )
155 Q_ASSERT( fieldsItem );
173 if ( parentFields && parentFields->tableProperty() &&
174 parentFields->tableProperty()->geometryColumn() ==
mName &&
175 !parentFields->tableProperty()->geometryColumnTypes().isEmpty() )
177 if ( mField.
typeName() == QLatin1String(
"raster" ) )
212 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.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
@ RenameField
Can rename existing fields via renameField() (since QGIS 3.28)
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.
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.
static QString fieldToolTip(const QgsField &field)
Returns a HTML formatted tooltip string for a field, containing details like the field name,...
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.
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, const QString &typeString=QString())
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 Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
#define QgsDebugError(str)
The TableProperty class represents a database table or view.