QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
qgstaskmanager.h
QgsProviderSublayerModel::mNonLayerItems
QList< NonLayerItem > mNonLayerItems
Non layer item list.
Definition: qgsprovidersublayermodel.h:212
QgsProviderSublayerModel
A model for representing the sublayers present in a URI.
Definition: qgsprovidersublayermodel.h:42
QgsProviderSublayerModel::mSublayers
QList< QgsProviderSublayerDetails > mSublayers
Sublayer list.
Definition: qgsprovidersublayermodel.h:209
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:430
QgsProviderSublayerModel::Column
Column
Model columns.
Definition: qgsprovidersublayermodel.h:67
QgsProviderSublayerDetails
Contains details about a sub layer available from a dataset.
Definition: qgsprovidersublayerdetails.h:44
QgsProviderSublayerModel::NonLayerItem
Contains details for a non-sublayer item to include in a QgsProviderSublayerModel.
Definition: qgsprovidersublayermodel.h:80
str
#define str(x)
Definition: qgis.cpp:37
QgsProviderSublayerModel::Role
Role
Custom model roles.
Definition: qgsprovidersublayermodel.h:49
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsProviderSublayerProxyModel
A QSortFilterProxyModel for filtering and sorting a QgsProviderSublayerModel.
Definition: qgsprovidersublayermodel.h:224