22 : QAbstractItemModel( parent )
29 Q_ASSERT( mConnection );
34 : QAbstractItemModel( parent )
35 , mConnection( connection )
38 Q_ASSERT( mConnection );
42 void QgsDatabaseTableModel::init()
44 Q_ASSERT( mConnection->capabilities() & QgsAbstractDatabaseProviderConnection::Capability::Tables );
45 mTables = mConnection->tables( mSchema );
60 return mTables.count() + ( mAllowEmpty ? 1 : 0 );
72 if ( !
index.isValid() )
75 if (
index.row() == 0 && mAllowEmpty )
83 if (
index.row() - ( mAllowEmpty ? 1 : 0 ) >= mTables.count() )
104 case Qt::DecorationRole:
110 if ( role == Qt::DecorationRole )
116 if ( role == Qt::DecorationRole )
151 return static_cast< int >( table.
flags() );
166 if ( hasIndex( row, column,
parent ) )
168 return createIndex( row, column, row );
171 return QModelIndex();
176 if ( allowEmpty == mAllowEmpty )
181 beginInsertRows( QModelIndex(), 0, 0 );
187 beginRemoveRows( QModelIndex(), 0, 0 );
195 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > newTables = mConnection->tables( mSchema );
196 const QList< QgsAbstractDatabaseProviderConnection::TableProperty > oldTables = mTables;
200 if ( !newTables.contains( oldTable ) )
202 int r = mTables.indexOf( oldTable );
203 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
204 mTables.removeAt( r );
211 if ( !mTables.contains( newTable ) )
213 beginInsertRows( QModelIndex(), mTables.count() + ( mAllowEmpty ? 1 : 0 ), mTables.count() + ( mAllowEmpty ? 1 : 0 ) );
214 mTables.append( newTable );
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
QgsDatabaseTableModel(const QString &provider, const QString &connection, const QString &schema=QString(), QObject *parent=nullptr)
Constructor for QgsDatabaseTableModel, for the specified provider and connection name.
QModelIndex parent(const QModelIndex &child) const override
void refresh()
Refreshes the table list by querying the underlying connection.
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void setAllowEmptyTable(bool allowEmpty)
Sets whether an optional empty table ("not set") option is present in the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
@ RoleWkbType
WKB type for primary (first) geometry column in table.
@ RoleEmpty
Entry is an empty entry.
@ RoleCrs
CRS for primary (first) geometry column in table.
@ RoleCustomInfo
Custom info variant map role.
@ RoleTableName
Table name.
@ RoleTableFlags
Table flags role.
@ RoleComment
Comment role.
@ RoleSchema
Table schema.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
static QIcon iconPolygon()
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.
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.
QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > geometryColumnTypes() const
Returns the list of geometry column types and CRSs.
QString tableName() const
Returns the table name.
QVariantMap info() const
Returns additional information about the table.
QString comment() const
Returns the table comment.
QString schema() const
Returns the schema or an empty string for backends that do not support a schema.
TableFlags flags() const
Returns the table flags.