26 : QSortFilterProxyModel( parent )
30 setSourceModel( mModel );
31 setDynamicSortFilter(
true );
32 setSortLocaleAware(
true );
33 setFilterCaseSensitivity( Qt::CaseInsensitive );
46 if ( mLayerWhitelist == layers )
49 mLayerWhitelist = layers;
55 if ( mExceptList == exceptList )
58 mExceptList = exceptList;
66 Q_FOREACH (
const QString &
id, ids )
87 mExcludedProviders = providers;
93 mFilterString = filter;
99 if ( mFilters.testFlag(
All ) && mExceptList.isEmpty() && mLayerWhitelist.isEmpty() && mExcludedProviders.isEmpty() && mFilterString.isEmpty() )
102 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
112 if ( !mLayerWhitelist.isEmpty() && !mLayerWhitelist.contains( layer ) )
115 if ( mExceptList.contains( layer ) )
124 if ( !layer->
name().contains( mFilterString, Qt::CaseInsensitive ) )
134 bool detectGeometry = mFilters.testFlag(
NoGeometry ) ||
141 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
143 if ( mFilters.testFlag(
HasGeometry ) && vl->isSpatial() )
171 if ( leftAdditional && !rightAdditional )
173 else if ( rightAdditional && !leftAdditional )
177 QString leftStr = sourceModel()->data( left ).toString();
178 QString rightStr = sourceModel()->data( right ).toString();
179 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.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider.
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 readOnly() const
Returns if this layer is read only.
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...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QStringList exceptedLayerIds() const
Returns the blacklist of layer IDs which are excluded from the model.
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.
QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
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.
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...
const Filters & filters() const
Returns the filter flags which affect how layers are filtered within the model.
True if index corresponds to the empty (not set) value.