21 : QAbstractItemModel( parent )
27 Q_ASSERT( mConnection );
32 : QAbstractItemModel( parent )
33 , mConnection( connection )
35 Q_ASSERT( mConnection );
39void QgsDatabaseSchemaModel::init()
42 mSchemas = mConnection->schemas();
57 return mSchemas.count() + ( mAllowEmpty ? 1 : 0 );
69 if ( !
index.isValid() )
72 if (
index.row() == 0 && mAllowEmpty )
80 const QString schemaName = mSchemas.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
99 if ( hasIndex( row, column,
parent ) )
101 return createIndex( row, column, row );
104 return QModelIndex();
109 if ( allowEmpty == mAllowEmpty )
114 beginInsertRows( QModelIndex(), 0, 0 );
120 beginRemoveRows( QModelIndex(), 0, 0 );
128 const QStringList newSchemas = mConnection->schemas();
129 const QStringList oldSchemas = mSchemas;
131 for (
const QString &oldSchema : oldSchemas )
133 if ( !newSchemas.contains( oldSchema ) )
135 const int r = mSchemas.indexOf( oldSchema ) ;
136 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
137 mSchemas.removeAt( r );
142 for (
const QString &newSchema : newSchemas )
144 if ( !mSchemas.contains( newSchema ) )
146 beginInsertRows( QModelIndex(), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ) );
147 mSchemas.append( newSchema );
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
@ Schemas
Can list schemas (if not set, the connection does not support schemas)
void setAllowEmptySchema(bool allowEmpty)
Sets whether an optional empty schema ("not set") option is present in the model.
QModelIndex parent(const QModelIndex &child) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
@ Empty
Entry is an empty entry.
QgsDatabaseSchemaModel(const QString &provider, const QString &connection, QObject *parent=nullptr)
Constructor for QgsDatabaseSchemaModel, for the specified provider and connection name.
void refresh()
Refreshes the schema list by querying the underlying connection.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
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.