22#include "moc_qgsproviderconnectionmodel.cpp"
25 : QAbstractItemModel(
parent )
26 , mProvider( provider )
29 Q_ASSERT( mMetadata );
34 mConnections = mMetadata->connections().keys();
39 if ( allowEmpty == mAllowEmpty )
44 beginInsertRows( QModelIndex(), 0, 0 );
50 beginRemoveRows( QModelIndex(), 0, 0 );
56void QgsProviderConnectionModel::removeConnection(
const QString &connection )
58 const int index = mConnections.indexOf( connection );
62 beginRemoveRows( QModelIndex(),
index + ( mAllowEmpty ? 1 : 0 ),
index + ( mAllowEmpty ? 1 : 0 ) );
63 mConnections.removeAt(
index );
67void QgsProviderConnectionModel::addConnection(
const QString &connection )
69 beginInsertRows( QModelIndex(), mConnections.count() + ( mAllowEmpty ? 1 : 0 ), mConnections.count() + ( mAllowEmpty ? 1 : 0 ) );
70 mConnections.append( connection );
86 return mConnections.count() + ( mAllowEmpty ? 1 : 0 );
98 if ( !
index.isValid() )
101 if (
index.row() == 0 && mAllowEmpty )
109 const QString connectionName = mConnections.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
115 case Qt::DisplayRole:
119 return connectionName;
122 case Qt::DecorationRole:
125 return connection->icon();
132 case Qt::ToolTipRole:
137 return connection->uri();
149 return connection->configuration();
166 if ( hasIndex( row, column,
parent ) )
168 return createIndex( row, column, row );
171 return QModelIndex();
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
@ Configuration
Connection configuration variant map.
@ ConnectionName
Connection name.
@ Uri
Connection URI string.
@ Empty
Entry is an empty entry.
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.