16#include "moc_qgsdatabaseschemamodel.cpp"
22 : QAbstractItemModel( parent )
28 Q_ASSERT( mConnection );
33 : QAbstractItemModel( parent )
34 , mConnection( connection )
36 Q_ASSERT( mConnection );
40void QgsDatabaseSchemaModel::init()
43 mSchemas = mConnection->schemas();
58 return mSchemas.count() + ( mAllowEmpty ? 1 : 0 );
70 if ( !
index.isValid() )
73 if (
index.row() == 0 && mAllowEmpty )
81 const QString schemaName = mSchemas.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
100 if ( hasIndex( row, column,
parent ) )
102 return createIndex( row, column, row );
105 return QModelIndex();
110 if ( allowEmpty == mAllowEmpty )
115 beginInsertRows( QModelIndex(), 0, 0 );
121 beginRemoveRows( QModelIndex(), 0, 0 );
129 const QStringList newSchemas = mConnection->schemas();
130 const QStringList oldSchemas = mSchemas;
132 for (
const QString &oldSchema : oldSchemas )
134 if ( !newSchemas.contains( oldSchema ) )
136 const int r = mSchemas.indexOf( oldSchema ) ;
137 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
138 mSchemas.removeAt( r );
143 for (
const QString &newSchema : newSchemas )
145 if ( !mSchemas.contains( newSchema ) )
147 beginInsertRows( QModelIndex(), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ) );
148 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.