QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 "qgis_core.h"
22#include "qgis_sip.h"
24
25#include <QAbstractItemModel>
26#include <QSortFilterProxyModel>
27#include <QIcon>
28#include <memory>
29#include <deque>
30
32class QgsProviderSublayerModelNode;
33class QgsProviderSublayerModelGroup;
34class QgsProviderSublayerModelSublayerNode;
36
37
38
54class CORE_EXPORT QgsProviderSublayerModel: public QAbstractItemModel
55{
56 Q_OBJECT
57
58 public:
59
61 enum class Role : int
62 {
63 ProviderKey = Qt::UserRole + 1,
64 LayerType,
65 Uri,
66 Name,
67 Description,
68 Path,
69 FeatureCount,
70 WkbType,
71 GeometryColumnName,
72 LayerNumber,
73 IsNonLayerItem,
74 NonLayerItemType,
75 Flags,
76 };
77
79 enum class Column : int
80 {
81 Name = 0,
82 Description = 1,
83 };
84
92 class CORE_EXPORT NonLayerItem
93 {
94 public:
95
100 QString type() const;
101
106 void setType( const QString &type );
107
112 QString name() const;
113
118 void setName( const QString &name );
119
124 QString description() const;
125
130 void setDescription( const QString &description );
131
136 QString uri() const;
137
142 void setUri( const QString &uri );
143
148 QIcon icon() const;
149
154 void setIcon( const QIcon &icon );
155
156 bool operator==( const QgsProviderSublayerModel::NonLayerItem &other ) const;
157 bool operator!=( const QgsProviderSublayerModel::NonLayerItem &other ) const;
158
159#ifdef SIP_RUN
160 SIP_PYOBJECT __repr__();
161 % MethodCode
162 QString str = QStringLiteral( "<QgsProviderSublayerModel.NonLayerItem: %1 - %2>" ).arg( sipCpp->type(), sipCpp->name() );
163 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
164 % End
165#endif
166
167 private:
168
169 QString mType;
170 QString mName;
171 QString mDescription;
172 QString mUri;
173 QIcon mIcon;
174
175 };
176
180 QgsProviderSublayerModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
181
187 void setSublayerDetails( const QList< QgsProviderSublayerDetails > &details );
188
194 QList< QgsProviderSublayerDetails > sublayerDetails() const;
195
199 QgsProviderSublayerDetails indexToSublayer( const QModelIndex &index ) const;
200
204 QgsProviderSublayerModel::NonLayerItem indexToNonLayerItem( const QModelIndex &index ) const;
205
209 void addNonLayerItem( const QgsProviderSublayerModel::NonLayerItem &item );
210
211 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
212 QModelIndex parent( const QModelIndex &index ) const override;
213 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
214 int rowCount( const QModelIndex &parent ) const override;
215 Qt::ItemFlags flags( const QModelIndex &index ) const override;
216 QVariant data( const QModelIndex &index, int role ) const override;
217 QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
218
220
225 QgsProviderSublayerModelNode *index2node( const QModelIndex &index ) const SIP_SKIP;
227
228 protected:
229
231 QList<QgsProviderSublayerDetails> mSublayers;
232
233 std::unique_ptr< QgsProviderSublayerModelGroup > mRootNode;
234
235 private:
236 QModelIndex indexOfParentNode( QgsProviderSublayerModelNode *parentNode ) const;
237
238 QModelIndex node2index( QgsProviderSublayerModelNode *node ) const;
239};
240
241
242#ifndef SIP_RUN
244
245class CORE_EXPORT QgsProviderSublayerModelNode
246{
247 public:
248
249 virtual ~QgsProviderSublayerModelNode();
250
256 QgsProviderSublayerModelGroup *parent() { return mParent; }
257
261 virtual QVariant data( int role = Qt::DisplayRole, int column = 0 ) const = 0;
262
266 virtual int childCount() const = 0;
267
268 protected:
269
270 QgsProviderSublayerModelGroup *mParent = nullptr;
271
272 friend class QgsProviderSublayerModelGroup;
273};
274
275class CORE_EXPORT QgsProviderSublayerModelGroup : public QgsProviderSublayerModelNode
276{
277 public:
278
282 QgsProviderSublayerModelGroup( const QString &title );
283
284 QgsProviderSublayerModelGroup( QgsProviderSublayerModelGroup &&other ) = default;
285 QgsProviderSublayerModelGroup &operator=( QgsProviderSublayerModelGroup && ) = default;
286
290 QString name() const { return mGroupTitle; }
291
295 QgsProviderSublayerModelNode *addChild( std::unique_ptr< QgsProviderSublayerModelNode > child );
296
302 int indexOf( QgsProviderSublayerModelNode *child ) const;
303
307 QgsProviderSublayerModelNode *childAt( int index );
308
312 void removeChildAt( int index );
313
317 QgsProviderSublayerModelGroup *findGroup( const QString &name ) const;
318
322 QgsProviderSublayerModelGroup *findGroupForPath( const QStringList &path ) const;
323
324 QgsProviderSublayerModelSublayerNode *findSublayer( const QgsProviderSublayerDetails &sublayer );
325
326 int childCount() const override final { return mChildren.size(); }
327 QVariant data( int role = Qt::DisplayRole, int column = 0 ) const override;
328
329 void populateFromSublayers( const QList<QgsProviderSublayerDetails> &sublayers );
330
331 protected:
332
333
334 std::deque< std::unique_ptr< QgsProviderSublayerModelNode > > mChildren;
335
336 QString mGroupTitle;
337
338};
339
340class CORE_EXPORT QgsProviderSublayerModelSublayerNode : public QgsProviderSublayerModelNode
341{
342 public:
343
344 QgsProviderSublayerModelSublayerNode( const QgsProviderSublayerDetails &sublayer );
345 int childCount() const override final { return 0; }
346 QVariant data( int role = Qt::DisplayRole, int column = 0 ) const override;
347 QgsProviderSublayerDetails sublayer() const { return mSublayer; }
348
349 private:
351
352};
353
354class CORE_EXPORT QgsProviderSublayerModelNonLayerItemNode : public QgsProviderSublayerModelNode
355{
356 public:
357
358 QgsProviderSublayerModelNonLayerItemNode( const QgsProviderSublayerModel::NonLayerItem &item );
359 int childCount() const override final { return 0; }
360 QVariant data( int role = Qt::DisplayRole, int column = 0 ) const override;
361
362 QgsProviderSublayerModel::NonLayerItem item() const { return mItem; }
363
364 private:
366
367};
368
370#endif
371
379class CORE_EXPORT QgsProviderSublayerProxyModel: public QSortFilterProxyModel
380{
381 Q_OBJECT
382
383 public:
384
388 QgsProviderSublayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
389
395 QString filterString() const;
396
402 void setFilterString( const QString &filter );
403
409 bool includeSystemTables() const;
410
416 void setIncludeSystemTables( bool include );
417
424 bool includeEmptyLayers() const;
425
432 void setIncludeEmptyLayers( bool include );
433
434 protected:
435 bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
436 bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
437
438 private:
439
440 QString mFilterString;
441 bool mIncludeSystemTables = false;
442 bool mIncludeEmptyLayers = true;
443
444};
445
446
447#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.
std::unique_ptr< QgsProviderSublayerModelGroup > mRootNode
A QSortFilterProxyModel for filtering and sorting a QgsProviderSublayerModel.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)