QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsproviderconnectionmodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproviderconnectionmodel.h
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 #ifndef QGSPROVIDERCONNECTIONMODEL_H
17 #define QGSPROVIDERCONNECTIONMODEL_H
18 
19 #include <QAbstractItemModel>
20 #include <QSortFilterProxyModel>
21 #include <QStringList>
22 
23 #include "qgis_core.h"
24 #include "qgis_sip.h"
25 
27 
38 class CORE_EXPORT QgsProviderConnectionModel : public QAbstractItemModel
39 {
40  Q_OBJECT
41 
42  public:
43 
45  enum Role
46  {
47  RoleConnectionName = Qt::UserRole,
51  };
52  Q_ENUM( Role )
53 
54 
60  explicit QgsProviderConnectionModel( const QString &provider, QObject *parent SIP_TRANSFERTHIS = nullptr );
61 
66  void setAllowEmptyConnection( bool allowEmpty );
67 
72  bool allowEmptyConnection() const { return mAllowEmpty; }
73 
74  // QAbstractItemModel interface
75  QModelIndex parent( const QModelIndex &child ) const override;
76  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
77  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
78  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
79  QModelIndex index( int row, int column, const QModelIndex &parent ) const override;
80  private slots:
81  void removeConnection( const QString &connection );
82  void addConnection( const QString &connection );
83 
84  private:
85  QString mProvider;
86  QgsProviderMetadata *mMetadata = nullptr;
87  QStringList mConnections;
88  bool mAllowEmpty = false;
89 };
90 
91 #endif // QGSPROVIDERCONNECTIONMODEL_H
A model containing registered connection names for a specific data provider.
bool allowEmptyConnection() const
Returns true if the model allows the empty connection ("not set") choice.
@ RoleEmpty
Entry is an empty entry.
@ RoleConfiguration
Connection configuration variant map.
Holds data provider key, description, and associated shared library file or function pointer informat...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53