21 : QAbstractItemModel( parent )
22 , mProvider( provider )
25 Q_ASSERT( mMetadata );
35 if ( allowEmpty == mAllowEmpty )
40 beginInsertRows( QModelIndex(), 0, 0 );
46 beginRemoveRows( QModelIndex(), 0, 0 );
52 void QgsProviderConnectionModel::removeConnection(
const QString &connection )
54 const int index = mConnections.indexOf( connection );
58 beginRemoveRows( QModelIndex(),
index + ( mAllowEmpty ? 1 : 0 ),
index + ( mAllowEmpty ? 1 : 0 ) );
59 mConnections.removeAt(
index );
63 void QgsProviderConnectionModel::addConnection(
const QString &connection )
65 beginInsertRows( QModelIndex(), mConnections.count() + ( mAllowEmpty ? 1 : 0 ), mConnections.count() + ( mAllowEmpty ? 1 : 0 ) );
66 mConnections.append( connection );
82 return mConnections.count() + ( mAllowEmpty ? 1 : 0 );
94 if ( !
index.isValid() )
97 if (
index.row() == 0 && mAllowEmpty )
105 const QString connectionName = mConnections.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
111 case Qt::DisplayRole:
115 return connectionName;
118 case Qt::DecorationRole:
121 return connection->icon();
128 case Qt::ToolTipRole:
133 return connection->uri();
145 return connection->configuration();
160 if ( hasIndex( row, column,
parent ) )
162 return createIndex( row, column, row );
165 return QModelIndex();
The QgsAbstractProviderConnection provides an interface for data provider connections.
QgsProviderConnectionModel(const QString &provider, QObject *parent=nullptr)
Constructor for QgsProviderConnectionModel, for the specified provider.
void setAllowEmptyConnection(bool allowEmpty)
Sets whether an optional empty connection ("not set") option is present in the model.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
@ RoleEmpty
Entry is an empty entry.
@ RoleConnectionName
Connection name.
@ RoleUri
Connection URI string.
@ RoleConfiguration
Connection configuration variant map.
QModelIndex parent(const QModelIndex &child) const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
A registry / canonical manager of data providers.