19#include "moc_qgsfieldsitem.cpp"
30 const QString &connectionUri,
31 const QString &providerKey,
32 const QString &schema,
33 const QString &tableName )
34 :
QgsDataItem(
Qgis::BrowserItemType::Fields, parent, tr(
"Fields" ), path, providerKey )
36 , mTableName( tableName )
37 , mConnectionUri( connectionUri )
46 mTableProperty = std::make_unique<QgsAbstractDatabaseProviderConnection::TableProperty>( conn->table(
schema,
tableName ) );
54 QgsDebugError( QStringLiteral(
"Error creating fields item: %1" ).arg( ex.
what() ) );
76 const QgsFields constFields { conn->fields( mSchema, mTableName ) };
77 for (
const auto &f : constFields )
100 return mConnectionUri;
105 std::unique_ptr<QgsVectorLayer> vl;
124 QgsDebugError( QStringLiteral(
"Error getting connection from %1" ).arg( mConnectionUri ) );
137 return mTableProperty.get();
151 :
QgsDataItem(
Qgis::BrowserItemType::Field, parent, field.name(), parent->path() +
'/' + field.name(), parent->providerKey() )
156 Q_ASSERT( fieldsItem );
174 if ( parentFields && parentFields->tableProperty() &&
175 parentFields->tableProperty()->geometryColumn() ==
mName &&
176 !parentFields->tableProperty()->geometryColumnTypes().isEmpty() )
178 if ( mField.
typeName() == QLatin1String(
"raster" ) )
213 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.
@ 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()
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 data item representing a single field from a layer.
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.
QMetaType::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 nullptr) 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 nullptr) 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(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, 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.