QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsprovidersublayermodel.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprovidersublayermodel.cpp
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
19
20#include "qgsapplication.h"
21#include "qgsiconutils.h"
23
24#include <QLocale>
25
26#include "moc_qgsprovidersublayermodel.cpp"
27
28//
29// QgsProviderSublayerModelNode
30//
31
33QgsProviderSublayerModelNode::~QgsProviderSublayerModelNode() = default;
34
35void QgsProviderSublayerModelGroup::populateFromSublayers( const QList<QgsProviderSublayerDetails> &sublayers )
36{
37 for ( const QgsProviderSublayerDetails &sublayer : sublayers )
38 {
39 if ( !sublayer.path().isEmpty() )
40 {
41 QStringList currentPath;
42 QStringList remainingPaths = sublayer.path();
43 QgsProviderSublayerModelGroup *groupNode = this;
44
45 while ( !remainingPaths.empty() )
46 {
47 currentPath << remainingPaths.takeAt( 0 );
48
49 QgsProviderSublayerModelGroup *nextChild = groupNode->findGroup( currentPath.constLast() );
50 if ( !nextChild )
51 {
52 auto newNode = std::make_unique< QgsProviderSublayerModelGroup >( currentPath.constLast() );
53 groupNode = qgis::down_cast< QgsProviderSublayerModelGroup * >( groupNode->addChild( std::move( newNode ) ) );
54 }
55 else
56 {
57 groupNode = nextChild;
58 }
59 }
60
61 groupNode->addChild( std::make_unique< QgsProviderSublayerModelSublayerNode >( sublayer ) );
62 }
63 else
64 {
65 addChild( std::make_unique< QgsProviderSublayerModelSublayerNode >( sublayer ) );
66 }
67 }
68}
69
70QgsProviderSublayerModelGroup::QgsProviderSublayerModelGroup( const QString &title )
71 : mGroupTitle( title )
72{
73
74}
75
76QgsProviderSublayerModelNode *QgsProviderSublayerModelGroup::addChild( std::unique_ptr<QgsProviderSublayerModelNode> child )
77{
78 if ( !child )
79 return nullptr;
80
81 Q_ASSERT( !child->mParent );
82 child->mParent = this;
83
84 QgsProviderSublayerModelNode *res = child.get();
85 mChildren.emplace_back( std::move( child ) );
86 // cppcheck-suppress returnDanglingLifetime
87 return res;
88}
89
90int QgsProviderSublayerModelGroup::indexOf( QgsProviderSublayerModelNode *child ) const
91{
92 Q_ASSERT( child->mParent == this );
93 auto it = std::find_if( mChildren.begin(), mChildren.end(), [&]( const std::unique_ptr<QgsProviderSublayerModelNode> &p )
94 {
95 return p.get() == child;
96 } );
97 if ( it != mChildren.end() )
98 return std::distance( mChildren.begin(), it );
99 return -1;
100}
101
102QgsProviderSublayerModelNode *QgsProviderSublayerModelGroup::childAt( int index )
103{
104 if ( static_cast< std::size_t >( index ) < mChildren.size() )
105 return mChildren[ index ].get();
106
107 return nullptr;
108}
109
110void QgsProviderSublayerModelGroup::removeChildAt( int index )
111{
112 mChildren.erase( mChildren.begin() + index );
113}
114
115QgsProviderSublayerModelGroup *QgsProviderSublayerModelGroup::findGroup( const QString &name ) const
116{
117 for ( const auto &node : mChildren )
118 {
119 if ( QgsProviderSublayerModelGroup *group = dynamic_cast< QgsProviderSublayerModelGroup * >( node.get() ) )
120 {
121 if ( group->name() == name )
122 return group;
123 }
124 }
125 return nullptr;
126}
127
128QgsProviderSublayerModelGroup *QgsProviderSublayerModelGroup::findGroupForPath( const QStringList &path ) const
129{
130 const QgsProviderSublayerModelGroup *currentGroup = this;
131 for ( const QString &part : path )
132 {
133 currentGroup = currentGroup->findGroup( part );
134 }
135 return const_cast< QgsProviderSublayerModelGroup * >( currentGroup );
136}
137
138QgsProviderSublayerModelSublayerNode *QgsProviderSublayerModelGroup::findSublayer( const QgsProviderSublayerDetails &sublayer )
139{
140 for ( const auto &node : mChildren )
141 {
142 if ( QgsProviderSublayerModelGroup *group = dynamic_cast< QgsProviderSublayerModelGroup * >( node.get() ) )
143 {
144 if ( QgsProviderSublayerModelSublayerNode *node = group->findSublayer( sublayer ) )
145 return node;
146 }
147 else if ( QgsProviderSublayerModelSublayerNode *sublayerNode = dynamic_cast< QgsProviderSublayerModelSublayerNode * >( node.get() ) )
148 {
149 if ( sublayerNode->sublayer() == sublayer )
150 return sublayerNode;
151 }
152 }
153 return nullptr;
154}
155
156QVariant QgsProviderSublayerModelGroup::data( int role, int column ) const
157{
158 switch ( role )
159 {
160 case Qt::DisplayRole:
161 case Qt::ToolTipRole:
162 case Qt::EditRole:
163 {
164 switch ( static_cast< QgsProviderSublayerModel::Column >( column ) )
165 {
167 return mGroupTitle;
168
170 return QVariant();
171 }
172 return QVariant();
173 }
174
175 case Qt::DecorationRole:
176 {
177 if ( column == 0 )
178 return QgsApplication::getThemeIcon( QStringLiteral( "/mIconDbSchema.svg" ) );
179 else
180 return QVariant();
181 }
182
183 default:
184 return QVariant();
185 }
186}
187
188QgsProviderSublayerModelSublayerNode::QgsProviderSublayerModelSublayerNode( const QgsProviderSublayerDetails &sublayer )
189 : mSublayer( sublayer )
190{
191}
192
193QVariant QgsProviderSublayerModelSublayerNode::data( int role, int column ) const
194{
195 switch ( role )
196 {
197 case Qt::DisplayRole:
198 case Qt::ToolTipRole:
199 case Qt::EditRole:
200 {
201 switch ( static_cast< QgsProviderSublayerModel::Column >( column ) )
202 {
204 return mSublayer.name();
206 {
207 switch ( mSublayer.type() )
208 {
210 {
211 QString count;
212 if ( mSublayer.featureCount() == static_cast< long long >( Qgis::FeatureCountState::Uncounted )
213 || mSublayer.featureCount() == static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) )
214 count = QObject::tr( "Uncounted" );
215 else
216 count = QLocale().toString( mSublayer.featureCount() );
217
218 if ( !mSublayer.description().isEmpty() )
219 return QStringLiteral( "%1 - %2 (%3)" ).arg( mSublayer.description(),
220 QgsWkbTypes::displayString( mSublayer.wkbType() ),
221 count );
222 else
223 return QStringLiteral( "%2 (%3)" ).arg(
224 QgsWkbTypes::displayString( mSublayer.wkbType() ),
225 count );
226 }
227
236 return mSublayer.description();
237 }
238 break;
239
240 }
241 }
242 return mSublayer.name();
243
244 }
245
246 case Qt::DecorationRole:
247 {
248 if ( column == 0 )
249 return mSublayer.type() == Qgis::LayerType::Vector
250 ? ( mSublayer.wkbType() != Qgis::WkbType::Unknown ? QgsIconUtils::iconForWkbType( mSublayer.wkbType() ) : QVariant() )
251 : QgsIconUtils::iconForLayerType( mSublayer.type() );
252 else
253 return QVariant();
254 }
255
256 case static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ):
257 return false;
258
259 case static_cast< int >( QgsProviderSublayerModel::Role::ProviderKey ):
260 return mSublayer.providerKey();
261
262 case static_cast< int >( QgsProviderSublayerModel::Role::LayerType ):
263 return static_cast< int >( mSublayer.type() );
264
265 case static_cast< int >( QgsProviderSublayerModel::Role::Uri ):
266 return mSublayer.uri();
267
268 case static_cast< int >( QgsProviderSublayerModel::Role::Name ):
269 return mSublayer.name();
270
271 case static_cast< int >( QgsProviderSublayerModel::Role::Description ):
272 return mSublayer.description();
273
274 case static_cast< int >( QgsProviderSublayerModel::Role::Path ):
275 return mSublayer.path();
276
277 case static_cast< int >( QgsProviderSublayerModel::Role::FeatureCount ):
278 return mSublayer.featureCount();
279
280 case static_cast< int >( QgsProviderSublayerModel::Role::WkbType ):
281 return static_cast< quint32>( mSublayer.wkbType() );
282
284 return mSublayer.geometryColumnName();
285
286 case static_cast< int >( QgsProviderSublayerModel::Role::LayerNumber ):
287 return mSublayer.layerNumber();
288
289 case static_cast< int >( QgsProviderSublayerModel::Role::Flags ):
290 return static_cast< int >( mSublayer.flags() );
291
292 default:
293 return QVariant();
294 }
295}
296
297QgsProviderSublayerModelNonLayerItemNode::QgsProviderSublayerModelNonLayerItemNode( const QgsProviderSublayerModel::NonLayerItem &item )
298 : mItem( item )
299{
300}
301
302QVariant QgsProviderSublayerModelNonLayerItemNode::data( int role, int column ) const
303{
304 switch ( role )
305 {
306 case Qt::DisplayRole:
307 case Qt::ToolTipRole:
308 case Qt::EditRole:
309 {
310 switch ( static_cast< QgsProviderSublayerModel::Column >( column ) )
311 {
313 return mItem.name();
315 return mItem.description();
316 }
317 return QVariant();
318 }
319
320 case Qt::DecorationRole:
321 {
322 if ( column == 0 )
323 return mItem.icon();
324 else
325 return QVariant();
326 }
327
328 case static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ):
329 return true;
330
331 case static_cast< int >( QgsProviderSublayerModel::Role::Uri ):
332 return mItem.uri();
333
334 case static_cast< int >( QgsProviderSublayerModel::Role::Name ):
335 return mItem.name();
336
337 case static_cast< int >( QgsProviderSublayerModel::Role::Description ):
338 return mItem.description();
339
340 case static_cast< int >( QgsProviderSublayerModel::Role::NonLayerItemType ):
341 return mItem.type();
342
343 default:
344 return QVariant();
345 }
346}
347
349
350//
351// QgsProviderSublayerModel
352//
353
355 : QAbstractItemModel( parent )
356 , mRootNode( std::make_unique< QgsProviderSublayerModelGroup >( QString() ) )
357{
358
359}
360
361void QgsProviderSublayerModel::setSublayerDetails( const QList<QgsProviderSublayerDetails> &details )
362{
363 if ( mSublayers.isEmpty() )
364 {
365 // initial population, just keep things simple and reset the model
366 beginResetModel();
367 mRootNode->populateFromSublayers( details );
368 mSublayers = details;
369 endResetModel();
370 }
371 else
372 {
373 // gracefully go item by item...
374
375 // remove layers which don't exist in new list
376 for ( int i = mSublayers.count() - 1; i >= 0; --i )
377 {
378 if ( !details.contains( mSublayers.at( i ) ) )
379 {
380 QgsProviderSublayerModelSublayerNode *sublayerNode = mRootNode->findSublayer( mSublayers.at( i ) );
381 Q_ASSERT( sublayerNode );
382 Q_ASSERT( sublayerNode->parent() );
383 const int row = sublayerNode->parent()->indexOf( sublayerNode );
384
385 beginRemoveRows( node2index( sublayerNode->parent() ), row, row );
386 sublayerNode->parent()->removeChildAt( row );
387 mSublayers.removeAt( i );
388 endRemoveRows();
389 }
390 }
391
392 // and add new layers which exist only in new list
393 for ( const QgsProviderSublayerDetails &sublayer : details )
394 {
395 if ( !mSublayers.contains( sublayer ) )
396 {
397 // need to add new layer
398 QgsProviderSublayerModelGroup *group = mRootNode->findGroupForPath( sublayer.path() );
399 beginInsertRows( node2index( group ), group->childCount(), group->childCount() );
400 group->addChild( std::make_unique< QgsProviderSublayerModelSublayerNode >( sublayer ) );
401 mSublayers.append( sublayer );
402 endInsertRows();
403 }
404 }
405 }
406}
407
408QList<QgsProviderSublayerDetails> QgsProviderSublayerModel::sublayerDetails() const
409{
410 return mSublayers;
411}
412
414{
415 if ( QgsProviderSublayerModelSublayerNode *n = dynamic_cast< QgsProviderSublayerModelSublayerNode *>( index2node( index ) ) )
416 return n->sublayer();
417 else
419}
420
422{
423 if ( QgsProviderSublayerModelNonLayerItemNode *n = dynamic_cast< QgsProviderSublayerModelNonLayerItemNode *>( index2node( index ) ) )
424 return n->item();
425 else
427}
428
430{
431 beginInsertRows( QModelIndex(), mRootNode->childCount(), mRootNode->childCount() );
432 mRootNode->addChild( std::make_unique< QgsProviderSublayerModelNonLayerItemNode >( item ) );
433 endInsertRows();
434}
435
436QModelIndex QgsProviderSublayerModel::index( int row, int column, const QModelIndex &parent ) const
437{
438 if ( column < 0 || column >= columnCount()
439 || row < 0 || row >= rowCount( parent ) )
440 {
441 // out of bounds
442 return QModelIndex();
443 }
444
445 QgsProviderSublayerModelGroup *n = dynamic_cast< QgsProviderSublayerModelGroup *>( index2node( parent ) );
446 if ( !n )
447 return QModelIndex(); // have no children
448
449 return createIndex( row, column, n->childAt( row ) );
450}
451
452QModelIndex QgsProviderSublayerModel::parent( const QModelIndex &child ) const
453{
454 if ( !child.isValid() )
455 return QModelIndex();
456
457 if ( QgsProviderSublayerModelNode *n = index2node( child ) )
458 {
459 return indexOfParentNode( n->parent() ); // must not be null
460 }
461 else
462 {
463 Q_ASSERT( false );
464 return QModelIndex();
465 }
466}
467
468int QgsProviderSublayerModel::columnCount( const QModelIndex &parent ) const
469{
470 Q_UNUSED( parent )
471 return static_cast< int >( Column::Description ) + 1;
472}
473
474int QgsProviderSublayerModel::rowCount( const QModelIndex &parent ) const
475{
476 QgsProviderSublayerModelNode *n = index2node( parent );
477 if ( !n )
478 return 0;
479
480 return n->childCount();
481}
482
483Qt::ItemFlags QgsProviderSublayerModel::flags( const QModelIndex &index ) const
484{
485 if ( !index.isValid() )
486 {
487 Qt::ItemFlags rootFlags = Qt::ItemFlags();
488 return rootFlags;
489 }
490
491 Qt::ItemFlags f = Qt::ItemIsEnabled;
492
493 // if index is a group, it is not selectable ...
494 if ( !dynamic_cast< QgsProviderSublayerModelGroup * >( index2node( index ) ) )
495 {
496 f |= Qt::ItemIsSelectable;
497 }
498 return f;
499}
500
501QVariant QgsProviderSublayerModel::data( const QModelIndex &index, int role ) const
502{
503 if ( !index.isValid() )
504 return QVariant();
505
506
507 QgsProviderSublayerModelNode *node = index2node( index );
508 if ( !node )
509 return QVariant();
510
511 return node->data( role, index.column() );
512}
513
514QVariant QgsProviderSublayerModel::headerData( int section, Qt::Orientation orientation, int role ) const
515{
516 switch ( orientation )
517 {
518 case Qt::Vertical:
519 break;
520 case Qt::Horizontal:
521 {
522 switch ( role )
523 {
524 case Qt::DisplayRole:
525 case Qt::ToolTipRole:
526 {
527 switch ( static_cast< Column>( section ) )
528 {
530 return tr( "Item" );
532 return tr( "Description" );
533 }
534 break;
535 }
536 }
537 break;
538 }
539 }
540 return QVariant();
541}
542
544QgsProviderSublayerModelNode *QgsProviderSublayerModel::index2node( const QModelIndex &index ) const
545{
546 if ( !index.isValid() )
547 return mRootNode.get();
548
549 return reinterpret_cast<QgsProviderSublayerModelNode *>( index.internalPointer() );
550}
551
552QModelIndex QgsProviderSublayerModel::indexOfParentNode( QgsProviderSublayerModelNode *parentNode ) const
553{
554 Q_ASSERT( parentNode );
555
556 QgsProviderSublayerModelGroup *grandParentNode = parentNode->parent();
557 if ( !grandParentNode )
558 return QModelIndex(); // root node -> invalid index
559
560 int row = grandParentNode->indexOf( parentNode );
561 Q_ASSERT( row >= 0 );
562
563 return createIndex( row, 0, parentNode );
564}
565
566QModelIndex QgsProviderSublayerModel::node2index( QgsProviderSublayerModelNode *node ) const
567{
568 if ( !node || !node->parent() )
569 return QModelIndex(); // this is the only root item -> invalid index
570
571 QModelIndex parentIndex = node2index( node->parent() );
572
573 int row = node->parent()->indexOf( node );
574 Q_ASSERT( row >= 0 );
575 return index( row, 0, parentIndex );
576}
578
579//
580// QgsProviderSublayerModel::NonLayerItem
581//
582
584{
585 return mType;
586}
587
589{
590 mType = type;
591}
592
594{
595 return mName;
596}
597
599{
600 mName = name;
601}
602
604{
605 return mDescription;
606}
607
609{
610 mDescription = description;
611}
612
614{
615 return mUri;
616}
617
619{
620 mUri = uri;
621}
622
624{
625 return mIcon;
626}
627
629{
630 mIcon = icon;
631}
632
634{
635 return mType == other.mType
636 && mName == other.mName
637 && mDescription == other.mDescription
638 && mUri == other.mUri;
639}
640
642{
643 return !( *this == other );
644}
645
646//
647// QgsProviderSublayerProxyModel
648//
649
651 : QSortFilterProxyModel( parent )
652{
653 setRecursiveFilteringEnabled( true );
654 setDynamicSortFilter( true );
655 sort( 0 );
656}
657
658bool QgsProviderSublayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
659{
660 const QModelIndex sourceIndex = sourceModel()->index( source_row, 0, source_parent );
661
662 if ( !mIncludeSystemTables && static_cast< Qgis::SublayerFlags >( sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::Flags ) ).toInt() ) & Qgis::SublayerFlag::SystemTable )
663 return false;
664
665 if ( !mIncludeEmptyLayers && sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::FeatureCount ) ) == 0 )
666 return false;
667
668 if ( mFilterString.trimmed().isEmpty() )
669 return true;
670
671 if ( sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::Name ) ).toString().contains( mFilterString, Qt::CaseInsensitive ) )
672 return true;
673
674 // check against the Description column's display role as it might be different from QgsProviderSublayerModel::Role::Description
675 const QModelIndex descriptionColumnIndex = sourceModel()->index( source_row, 1, source_parent );
676 if ( sourceModel()->data( descriptionColumnIndex, static_cast< int >( Qt::DisplayRole ) ).toString().contains( mFilterString, Qt::CaseInsensitive ) )
677 return true;
678
679 const QVariant wkbTypeVariant = sourceModel()->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::WkbType ) );
680 if ( wkbTypeVariant.isValid() )
681 {
682 const Qgis::WkbType wkbType = static_cast< Qgis::WkbType >( wkbTypeVariant.toUInt() );
683 if ( QgsWkbTypes::displayString( wkbType ).contains( mFilterString, Qt::CaseInsensitive ) )
684 return true;
685 }
686
687 return false;
688}
689
690bool QgsProviderSublayerProxyModel::lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const
691{
692 const bool leftIsNonLayer = sourceModel()->data( source_left, static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ) ).toBool();
693 const bool rightIsNonLayer = sourceModel()->data( source_right, static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ) ).toBool();
694
695 if ( leftIsNonLayer && !rightIsNonLayer )
696 return true;
697 else if ( rightIsNonLayer && !leftIsNonLayer )
698 return false;
699
700 const QString leftName = sourceModel()->data( source_left, static_cast< int >( QgsProviderSublayerModel::Role::Name ) ).toString();
701 const QString rightName = sourceModel()->data( source_right, static_cast< int >( QgsProviderSublayerModel::Role::Name ) ).toString();
702
703 return QString::localeAwareCompare( leftName, rightName ) < 0;
704}
705
707{
708 return mIncludeSystemTables;
709}
710
712{
713 mIncludeSystemTables = include;
714 invalidateFilter();
715}
716
718{
719 return mIncludeEmptyLayers;
720}
721
723{
724 mIncludeEmptyLayers = include;
725 invalidateFilter();
726}
727
729{
730 return mFilterString;
731}
732
734{
735 mFilterString = filter;
736 invalidateFilter();
737}
@ SystemTable
Sublayer is a system or internal table, which should be hidden by default.
Definition qgis.h:1410
QFlags< SublayerFlag > SublayerFlags
Sublayer flags.
Definition qgis.h:1413
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:198
@ Plugin
Plugin based layer.
Definition qgis.h:193
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:199
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:196
@ Vector
Vector layer.
Definition qgis.h:191
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:195
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:194
@ Raster
Raster layer.
Definition qgis.h:192
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:197
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Unknown
Unknown.
Definition qgis.h:278
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Contains utility functions for working with icons.
static QIcon iconForWkbType(Qgis::WkbType type)
Returns the icon for a vector layer whose geometry type is provided.
Contains details about a sub layer available from a dataset.
QStringList path() const
Returns the path to the sublayer.
Contains details for a non-sublayer item to include in a QgsProviderSublayerModel.
void setName(const QString &name)
Sets the item's name.
void setDescription(const QString &description)
Sets the item's description.
void setType(const QString &type)
Sets the item's type.
QString type() const
Returns the item's type.
QString uri() const
Returns the item's URI.
QString name() const
Returns the item's name.
QIcon icon() const
Returns the item's icon.
bool operator!=(const QgsProviderSublayerModel::NonLayerItem &other) const
void setUri(const QString &uri)
Set the item's uri.
bool operator==(const QgsProviderSublayerModel::NonLayerItem &other) const
QString description() const
Returns the item's description.
void setIcon(const QIcon &icon)
Sets the item's icon.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QList< QgsProviderSublayerDetails > mSublayers
Sublayer list.
QList< QgsProviderSublayerDetails > sublayerDetails() const
Returns the sublayer details shown in the model.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
QgsProviderSublayerModel(QObject *parent=nullptr)
Constructor for QgsProviderSublayerModel, with the specified parent object.
QgsProviderSublayerDetails indexToSublayer(const QModelIndex &index) const
Returns the sublayer corresponding to the given index.
std::unique_ptr< QgsProviderSublayerModelGroup > mRootNode
@ NonLayerItemType
Item type (for non-sublayer items).
@ IsNonLayerItem
true if item is a non-sublayer item (e.g. an embedded project)
@ FeatureCount
Feature count (for vector sublayers).
@ GeometryColumnName
Geometry column name (for vector sublayers).
@ WkbType
WKB geometry type (for vector sublayers).
QgsProviderSublayerModel::NonLayerItem indexToNonLayerItem(const QModelIndex &index) const
Returns the non layer item corresponding to the given index.
void addNonLayerItem(const QgsProviderSublayerModel::NonLayerItem &item)
Adds a non-layer item (e.g.
void setSublayerDetails(const QList< QgsProviderSublayerDetails > &details)
Sets the sublayer details to show in the model.
QModelIndex parent(const QModelIndex &index) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
int rowCount(const QModelIndex &parent) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override
bool includeSystemTables() const
Returns true if system and internal tables will be shown in the model.
void setIncludeSystemTables(bool include)
Sets whether system and internal tables will be shown in the model.
QgsProviderSublayerProxyModel(QObject *parent=nullptr)
Constructor for QgsProviderSublayerProxyModel, with the specified parent object.
QString filterString() const
Returns the filter string used for filtering items in the model.
bool includeEmptyLayers() const
Returns true if empty tables will be shown in the model.
void setFilterString(const QString &filter)
Sets the filter string used for filtering items in the model.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
void setIncludeEmptyLayers(bool include)
Sets whether empty tables will be shown in the model.
static Q_INVOKABLE QString displayString(Qgis::WkbType type)
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
@ Uncounted
Feature count not yet computed.
Definition qgis.h:546
@ UnknownCount
Provider returned an unknown feature count.
Definition qgis.h:547