17#include "moc_qgsmaplayerproxymodel.cpp"
24 : QSortFilterProxyModel( parent )
25 , mFilters(
Qgis::LayerFilter::All )
28 setSourceModel( mModel );
29 setDynamicSortFilter(
true );
30 setSortLocaleAware(
true );
31 setFilterCaseSensitivity( Qt::CaseInsensitive );
66 if (
const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( layer ) )
91 if ( mLayerAllowlist == layers )
94 mLayerAllowlist = layers;
100 if ( mExceptList == exceptList )
103 mExceptList = exceptList;
116 const auto constIds = ids;
117 for (
const QString &
id : constIds )
130 const auto constMExceptList = mExceptList;
139 mExcludedProviders = providers;
148 if ( !mLayerAllowlist.isEmpty() && !mLayerAllowlist.contains( layer ) )
151 if ( mExceptList.contains( layer ) )
160 if ( !layer->
name().contains( mFilterString, Qt::CaseInsensitive ) )
168 mFilterString = filter;
174 if ( mFilters.testFlag(
Qgis::LayerFilter::All ) && mExceptList.isEmpty() && mLayerAllowlist.isEmpty() && mExcludedProviders.isEmpty() && mFilterString.isEmpty() )
177 const QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
198 if ( leftAdditional && !rightAdditional )
200 else if ( rightAdditional && !leftAdditional )
204 const QString leftStr = sourceModel()->data( left ).toString();
205 const QString rightStr = sourceModel()->data( right ).toString();
206 return QString::localeAwareCompare( leftStr, rightStr ) < 0;
The Qgis class provides global constants for use throughout the application.
@ PointCloudLayer
QgsPointCloudLayer.
@ VectorTileLayer
QgsVectorTileLayer.
@ AnnotationLayer
QgsAnnotationLayer.
@ TiledSceneLayer
QgsTiledSceneLayer.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< LayerFilter > LayerFilters
The QgsMapLayerModel class is a model to display layers in widgets.
void setProject(QgsProject *project)
Sets the QgsProject from which map layers are shown.
@ Additional
True if index corresponds to an additional (non map layer) item.
@ Empty
True if index corresponds to the empty (not set) value.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
static bool layerMatchesFilters(const QgsMapLayer *layer, const Qgis::LayerFilters &filters)
Returns if the layer matches the given filters.
Qgis::LayerFilters filters
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.
QgsMapLayerProxyModel * setFilters(Qgis::LayerFilters filters)
Sets filter flags which affect how layers are filtered within the 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.
void setProject(QgsProject *project)
Sets the project from which map layers are shown.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
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.