QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsprovidersublayermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprovidersublayermodel.h
3  ----------------------
4  begin : June 2021
5  copyright : (C) 2021 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPROVIDERSUBLAYERMODEL_H
19 #define QGSPROVIDERSUBLAYERMODEL_H
20 
21 #include "qgstaskmanager.h"
22 #include <QAbstractItemModel>
23 #include <QSortFilterProxyModel>
24 
26 
42 class CORE_EXPORT QgsProviderSublayerModel: public QAbstractItemModel
43 {
44  Q_OBJECT
45 
46  public:
47 
49  enum class Role : int
50  {
51  ProviderKey = Qt::UserRole + 1,
52  LayerType,
53  Uri,
54  Name,
55  Description,
56  Path,
57  FeatureCount,
58  WkbType,
59  GeometryColumnName,
60  LayerNumber,
61  IsNonLayerItem,
62  NonLayerItemType,
63  Flags,
64  };
65 
67  enum class Column : int
68  {
69  Name = 0,
70  Description = 1,
71  };
72 
80  class CORE_EXPORT NonLayerItem
81  {
82  public:
83 
88  QString type() const;
89 
94  void setType( const QString &type );
95 
100  QString name() const;
101 
106  void setName( const QString &name );
107 
112  QString description() const;
113 
118  void setDescription( const QString &description );
119 
124  QString uri() const;
125 
130  void setUri( const QString &uri );
131 
136  QIcon icon() const;
137 
142  void setIcon( const QIcon &icon );
143 
144  bool operator==( const QgsProviderSublayerModel::NonLayerItem &other ) const;
145  bool operator!=( const QgsProviderSublayerModel::NonLayerItem &other ) const;
146 
147 #ifdef SIP_RUN
148  SIP_PYOBJECT __repr__();
149  % MethodCode
150  QString str = QStringLiteral( "<QgsProviderSublayerModel.NonLayerItem: %1 - %2>" ).arg( sipCpp->type(), sipCpp->name() );
151  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
152  % End
153 #endif
154 
155  private:
156 
157  QString mType;
158  QString mName;
159  QString mDescription;
160  QString mUri;
161  QIcon mIcon;
162 
163  };
164 
168  QgsProviderSublayerModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
169 
175  void setSublayerDetails( const QList< QgsProviderSublayerDetails > &details );
176 
182  QList< QgsProviderSublayerDetails > sublayerDetails() const;
183 
187  QgsProviderSublayerDetails indexToSublayer( const QModelIndex &index ) const;
188 
192  QgsProviderSublayerModel::NonLayerItem indexToNonLayerItem( const QModelIndex &index ) const;
193 
197  void addNonLayerItem( const QgsProviderSublayerModel::NonLayerItem &item );
198 
199  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
200  QModelIndex parent( const QModelIndex &index ) const override;
201  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
202  int rowCount( const QModelIndex &parent ) const override;
203  QVariant data( const QModelIndex &index, int role ) const override;
204  QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
205 
206  protected:
207 
209  QList<QgsProviderSublayerDetails> mSublayers;
210 
212  QList<NonLayerItem> mNonLayerItems;
213 
214 };
215 
216 
224 class CORE_EXPORT QgsProviderSublayerProxyModel: public QSortFilterProxyModel
225 {
226  Q_OBJECT
227 
228  public:
229 
233  QgsProviderSublayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
234 
240  QString filterString() const;
241 
247  void setFilterString( const QString &filter );
248 
254  bool includeSystemTables() const;
255 
261  void setIncludeSystemTables( bool include );
262 
263  protected:
264  bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
265  bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
266 
267  private:
268 
269  QString mFilterString;
270  bool mIncludeSystemTables = false;
271 
272 };
273 
274 
275 #endif // QGSPROVIDERSUBLAYERMODEL_H
Contains details about a sub layer available from a dataset.
Contains details for a non-sublayer item to include in a QgsProviderSublayerModel.
A model for representing the sublayers present in a URI.
QList< QgsProviderSublayerDetails > mSublayers
Sublayer list.
QList< NonLayerItem > mNonLayerItems
Non layer item list.
A QSortFilterProxyModel for filtering and sorting a QgsProviderSublayerModel.
#define str(x)
Definition: qgis.cpp:37
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)