28 : QSortFilterProxyModel( parent )
32 setSourceModel( mModel );
33 setDynamicSortFilter(
true );
34 setSortLocaleAware(
true );
35 setFilterCaseSensitivity( Qt::CaseInsensitive );
48 if ( mLayerWhitelist == layers )
51 mLayerWhitelist = layers;
57 if ( mExceptList == exceptList )
60 mExceptList = exceptList;
68 const auto constIds = ids;
69 for (
const QString &
id : constIds )
82 const auto constMExceptList = mExceptList;
91 mExcludedProviders = providers;
100 if ( !mLayerWhitelist.isEmpty() && !mLayerWhitelist.contains( layer ) )
103 if ( mExceptList.contains( layer ) )
112 if ( !layer->
name().contains( mFilterString, Qt::CaseInsensitive ) )
123 bool detectGeometry = mFilters.testFlag(
NoGeometry ) ||
130 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
132 if ( mFilters.testFlag(
HasGeometry ) && vl->isSpatial() )
150 mFilterString = filter;
156 if ( mFilters.testFlag(
All ) && mExceptList.isEmpty() && mLayerWhitelist.isEmpty() && mExcludedProviders.isEmpty() && mFilterString.isEmpty() )
159 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
165 return acceptsLayer( static_cast<QgsMapLayer *>( index.internalPointer() ) );
180 if ( leftAdditional && !rightAdditional )
182 else if ( rightAdditional && !leftAdditional )
186 QString leftStr = sourceModel()->data( left ).toString();
187 QString rightStr = sourceModel()->data( right ).toString();
188 return QString::localeAwareCompare( leftStr, rightStr ) < 0;
QgsMapLayerProxyModel(QObject *parent=nullptr)
QgsMapLayerProxModel creates a proxy model with a QgsMapLayerModel as source model.
Base class for all map layer types.
QgsMapLayerType type() const
Returns the type of the layer.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
QStringList exceptedLayerIds() const
Returns the blacklist of layer IDs which are excluded from the model.
void setExceptedLayerIds(const QStringList &ids)
Sets a blacklist of layers (by layer ID) to exclude from the model.
virtual QString name() const =0
Returns a provider name.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
True if index corresponds to an additional (non map layer) item.
bool acceptsLayer(QgsMapLayer *layer) const
Returns true if the proxy model accepts the specified map layer.
void setExceptedLayerList(const QList< QgsMapLayer *> &exceptList)
Sets a blacklist of layers to exclude from the model.
The QgsMapLayerModel class is a model to display layers in widgets.
The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widget...
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
void setLayerWhitelist(const QList< QgsMapLayer *> &layers)
Sets a whitelist of layers to include within the model.
void setExcludedProviders(const QStringList &providers)
Sets a blacklist of data providers which should be excluded from the model.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsMapLayerProxyModel * setFilters(QgsMapLayerProxyModel::Filters filters)
Sets filter flags which affect how layers are filtered within the model.
const Filters & filters() const
Returns the filter flags which affect how layers are filtered within the model.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
bool readOnly() const
Returns if this layer is read only.
Represents a vector layer which manages a vector based data sets.
void setFilterString(const QString &filter)
Sets a filter string, such that only layers with names matching the specified string will be shown...
True if index corresponds to the empty (not set) value.