21#include "moc_qgsdatabaseschemamodel.cpp"
24 : QAbstractItemModel(
parent )
30 Q_ASSERT( mConnection );
35 : QAbstractItemModel(
parent )
36 , mConnection( connection )
38 Q_ASSERT( mConnection );
42void QgsDatabaseSchemaModel::init()
45 mSchemas = mConnection->schemas();
60 return mSchemas.count() + ( mAllowEmpty ? 1 : 0 );
72 if ( !
index.isValid() )
75 if (
index.row() == 0 && mAllowEmpty )
83 const QString schemaName = mSchemas.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
102 if ( hasIndex( row, column,
parent ) )
104 return createIndex( row, column, row );
107 return QModelIndex();
112 if ( allowEmpty == mAllowEmpty )
117 beginInsertRows( QModelIndex(), 0, 0 );
123 beginRemoveRows( QModelIndex(), 0, 0 );
131 const QStringList newSchemas = mConnection->schemas();
132 const QStringList oldSchemas = mSchemas;
134 for (
const QString &oldSchema : oldSchemas )
136 if ( !newSchemas.contains( oldSchema ) )
138 const int r = mSchemas.indexOf( oldSchema ) ;
139 beginRemoveRows( QModelIndex(), r + ( mAllowEmpty ? 1 : 0 ), r + ( mAllowEmpty ? 1 : 0 ) );
140 mSchemas.removeAt( r );
145 for (
const QString &newSchema : newSchemas )
147 if ( !mSchemas.contains( newSchema ) )
149 beginInsertRows( QModelIndex(), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ), mSchemas.count() + ( mAllowEmpty ? 1 : 0 ) );
150 mSchemas.append( newSchema );
Provides common functionality for database based connections.
@ 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.