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