QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
23 : QAbstractItemModel( parent )
30 Q_ASSERT( mConnection );
35 : QAbstractItemModel( parent )
36 , mConnection( connection )
39 Q_ASSERT( mConnection );
43 void QgsDatabaseTableModel::init()
45 Q_ASSERT( mConnection->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::Tables );
46 mTables = mConnection->tables( mSchema );
61 return mTables.count() + ( mAllowEmpty ? 1 : 0 );
73 if ( !
index.isValid() )
76 if (
index.row() == 0 && mAllowEmpty )
84 if (
index.row() - ( mAllowEmpty ? 1 : 0 ) >= mTables.count() )
105 case Qt::DecorationRole:
111 if ( role == Qt::DecorationRole )
117 if ( role == Qt::DecorationRole )
156 return static_cast< int >( table.
flags() );
171 if ( hasIndex( row, column,
parent ) )
173 return createIndex( row, column, row );
176 return QModelIndex();
181 if ( allowEmpty == mAllowEmpty )
186 beginInsertRows( QModelIndex(), 0, 0 );
192 beginRemoveRows( QModelIndex(), 0, 0 );
200 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > newTables = mConnection->tables( mSchema );
201 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > oldTables = mTables;
205 if ( !newTables.contains( oldTable ) )
207 const int r = mTables.indexOf( oldTable );
208 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
209 mTables.removeAt( r );
216 if ( !mTables.contains( newTable ) )
218 beginInsertRows( QModelIndex(), mTables.count() + ( mAllowEmpty ? 1 : 0 ), mTables.count() + ( mAllowEmpty ? 1 : 0 ) );
219 mTables.append( newTable );
QgsDatabaseTableModel(const QString &provider, const QString &connection, const QString &schema=QString(), QObject *parent=nullptr)
Constructor for QgsDatabaseTableModel, for the specified provider and connection name.
static QIcon iconTable()
Returns an icon representing non-spatial layers (tables).
@ RoleEmpty
Entry is an empty entry.
static QIcon iconPolygon()
Returns an icon representing polygon geometries.
@ RoleSchema
Table schema.
@ RoleComment
Comment role.
@ RoleTableFlags
Table flags role.
static QIcon iconLine()
Returns an icon representing line geometries.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
@ RoleWkbType
WKB type for primary (first) geometry column in table.
The TableProperty class represents a database table or view.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QVariantMap info() const
Returns additional information about the table.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > geometryColumnTypes() const
Returns the list of geometry column types and CRSs.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
static QIcon iconPoint()
Returns an icon representing point geometries.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
static QIcon iconGeometryCollection()
Returns an icon representing geometry collections.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
QString comment() const
Returns the table comment.
QString tableName() const
Returns the table name.
QModelIndex parent(const QModelIndex &child) const override
void refresh()
Refreshes the table list by querying the underlying connection.
@ RoleCrs
CRS for primary (first) geometry column in table.
void setAllowEmptyTable(bool allowEmpty)
Sets whether an optional empty table ("not set") option is present in the model.
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...
@ RoleCustomInfo
Custom info variant map role.
TableFlags flags() const
Returns the table flags.
@ RoleTableName
Table name.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
QString schema() const
Returns the schema or an empty string for backends that do not support a schema.