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 Q_FOREACH (
const QString &
id, ids )
89 mExcludedProviders = providers;
95 mFilterString = filter;
101 if ( mFilters.testFlag(
All ) && mExceptList.isEmpty() && mLayerWhitelist.isEmpty() && mExcludedProviders.isEmpty() && mFilterString.isEmpty() )
104 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
114 if ( !mLayerWhitelist.isEmpty() && !mLayerWhitelist.contains( layer ) )
117 if ( mExceptList.contains( layer ) )
126 if ( !layer->
name().contains( mFilterString, Qt::CaseInsensitive ) )
137 bool detectGeometry = mFilters.testFlag(
NoGeometry ) ||
144 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
146 if ( mFilters.testFlag(
HasGeometry ) && vl->isSpatial() )
174 if ( leftAdditional && !rightAdditional )
176 else if ( rightAdditional && !leftAdditional )
180 QString leftStr = sourceModel()->data( left ).toString();
181 QString rightStr = sourceModel()->data( right ).toString();
182 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.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be null.
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.
QgsMapLayer::LayerType type() const
Returns the type of the layer.
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.
void setExceptedLayerList(const QList< QgsMapLayer *> &exceptList)
Sets a blacklist of layers to exclude from the model.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
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.