20 : QAbstractItemModel( parent )
21 , mProvider( provider )
24 Q_ASSERT( mMetadata );
34 if ( allowEmpty == mAllowEmpty )
39 beginInsertRows( QModelIndex(), 0, 0 );
45 beginRemoveRows( QModelIndex(), 0, 0 );
51 void QgsProviderConnectionModel::removeConnection(
const QString &connection )
53 int index = mConnections.indexOf( connection );
57 beginRemoveRows( QModelIndex(),
index + ( mAllowEmpty ? 1 : 0 ),
index + ( mAllowEmpty ? 1 : 0 ) );
58 mConnections.removeAt(
index );
62 void QgsProviderConnectionModel::addConnection(
const QString &connection )
64 beginInsertRows( QModelIndex(), mConnections.count() + ( mAllowEmpty ? 1 : 0 ), mConnections.count() + ( mAllowEmpty ? 1 : 0 ) );
65 mConnections.append( connection );
81 return mConnections.count() + ( mAllowEmpty ? 1 : 0 );
93 if ( !
index.isValid() )
96 if (
index.row() == 0 && mAllowEmpty )
104 const QString connectionName = mConnections.value(
index.row() - ( mAllowEmpty ? 1 : 0 ) );
110 case Qt::DisplayRole:
114 return connectionName;
117 case Qt::DecorationRole:
120 return connection->icon();
127 case Qt::ToolTipRole:
132 return connection->uri();
144 return connection->configuration();
159 if ( hasIndex( row, column,
parent ) )
161 return createIndex( row, column, row );
164 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.