28 : QSortFilterProxyModel( parent )
32 setSourceModel( mModel );
33 setDynamicSortFilter(
true );
34 setSortLocaleAware(
true );
35 setFilterCaseSensitivity( Qt::CaseInsensitive );
68 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
93 if ( mLayerAllowlist == layers )
96 mLayerAllowlist = layers;
102 if ( mExceptList == exceptList )
105 mExceptList = exceptList;
113 const auto constIds = ids;
114 for (
const QString &
id : constIds )
127 const auto constMExceptList = mExceptList;
136 mExcludedProviders = providers;
145 if ( !mLayerAllowlist.isEmpty() && !mLayerAllowlist.contains( layer ) )
148 if ( mExceptList.contains( layer ) )
157 if ( !layer->
name().contains( mFilterString, Qt::CaseInsensitive ) )
165 mFilterString = filter;
171 if ( mFilters.testFlag(
All ) && mExceptList.isEmpty() && mLayerAllowlist.isEmpty() && mExcludedProviders.isEmpty() && mFilterString.isEmpty() )
174 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
195 if ( leftAdditional && !rightAdditional )
197 else if ( rightAdditional && !leftAdditional )
201 QString leftStr = sourceModel()->data( left ).toString();
202 QString rightStr = sourceModel()->data( right ).toString();
203 return QString::localeAwareCompare( leftStr, rightStr ) < 0;
The QgsMapLayerModel class is a model to display layers in widgets.
@ EmptyRole
True if index corresponds to the empty (not set) value.
@ AdditionalRole
True if index corresponds to an additional (non map layer) item.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
QgsMapLayerProxyModel::Filters filters
static bool layerMatchesFilters(const QgsMapLayer *layer, const Filters &filters)
Returns if the layer matches the given filters.
QgsMapLayerProxyModel * setFilters(QgsMapLayerProxyModel::Filters filters)
Sets filter flags which affect how layers are filtered within the model.
void setExceptedLayerIds(const QStringList &ids)
Sets a blocklist of layers (by layer ID) to exclude from the model.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
void setFilterString(const QString &filter)
Sets a filter string, such that only layers with names matching the specified string will be shown.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
QgsMapLayerProxyModel(QObject *parent=nullptr)
QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model.
bool acceptsLayer(QgsMapLayer *layer) const
Returns true if the proxy model accepts the specified map layer.
QStringList exceptedLayerIds
void setExcludedProviders(const QStringList &providers)
Sets a blocklist of data providers which should be excluded from the model.
void setLayerAllowlist(const QList< QgsMapLayer * > &layers)
Sets an allowlist of layers to include within the model.
@ VectorTileLayer
QgsVectorTileLayer.
@ PointCloudLayer
QgsPointCloudLayer.
Q_DECL_DEPRECATED void setLayerWhitelist(const QList< QgsMapLayer * > &layers)
Sets an allowlist of layers to include within the model.
void setExceptedLayerList(const QList< QgsMapLayer * > &exceptList)
Sets a blocklist of layers to exclude from the model.
Base class for all map layer types.
QString providerType() const
Returns the provider type (provider key) for this layer.
bool readOnly() const
Returns if this layer is read only.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Represents a vector layer which manages a vector based data sets.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.