QGIS API Documentation 3.99.0-Master (f78f5286a64)
qgsgroupedfeaturefilterprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgroupedfeaturefilterprovider.cpp
3 --------------------------------
4 begin : 2025-07-26
5 copyright : (C) 2025 by Mathieu Pellerin
6 email : mathieu at opengis dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsfeaturerequest.h"
20#include "qgsvectorlayer.h"
21
23{
24 for ( const QgsFeatureFilterProvider *provider : mProviders )
25 {
27 if ( !provider->isFilterThreadSafe() )
28 {
29 return false;
30 }
32 }
33 return true;
34}
35
37{
38 for ( const QgsFeatureFilterProvider *provider : mProviders )
39 {
42 if ( provider->isFilterThreadSafe() )
43 {
44 provider->filterFeatures( layer->id(), temp );
45 }
46 else
47 {
48 provider->filterFeatures( layer, temp );
49 }
51 if ( auto *lFilterExpression = temp.filterExpression() )
52 {
53 filterFeatures.combineFilterExpression( lFilterExpression->dump() );
54 }
55 }
56}
57
58void QgsGroupedFeatureFilterProvider::filterFeatures( const QString &layerId, QgsFeatureRequest &filterFeatures ) const
59{
60 for ( const QgsFeatureFilterProvider *provider : mProviders )
61 {
63 provider->filterFeatures( layerId, temp );
64 if ( auto *lFilterExpression = temp.filterExpression() )
65 {
66 filterFeatures.combineFilterExpression( lFilterExpression->dump() );
67 }
68 }
69}
70
71QStringList QgsGroupedFeatureFilterProvider::layerAttributes( const QgsVectorLayer *layer, const QStringList &attributes ) const
72{
73 QStringList allowedAttributes { attributes };
74 for ( const QgsFeatureFilterProvider *provider : mProviders )
75 {
76 const QgsFeatureRequest temp;
77 allowedAttributes = provider->layerAttributes( layer, allowedAttributes );
78 }
79 return allowedAttributes;
80}
81
83{
85 filter->mProviders = mProviders;
86 return filter;
87}
88
90{
91 if ( provider )
92 {
93 mProviders.append( provider );
94 }
95 return *this;
96}
Abstract interface for use by classes that filter the features or attributes of a layer.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
QgsExpression * filterExpression() const
Returns the filter expression (if set).
A filter filter provider grouping several filter providers.
Q_DECL_DEPRECATED bool isFilterThreadSafe() const override
Returns true if the filterFeature function is thread safe, which will lead to reliance on layer ID in...
QgsGroupedFeatureFilterProvider()=default
Constructor.
QgsGroupedFeatureFilterProvider * clone() const override
Create a clone of the feature filter provider.
Q_DECL_DEPRECATED void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures) const override
Add additional filters to the feature request to further restrict the features returned by the reques...
QgsGroupedFeatureFilterProvider & addProvider(const QgsFeatureFilterProvider *provider)
Add another filter provider to the group.
QStringList layerAttributes(const QgsVectorLayer *layer, const QStringList &attributes) const override
Returns the list of visible attribute names from a list of attributes names for the given layer.
QString id
Definition qgsmaplayer.h:81
Represents a vector layer which manages a vector based dataset.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6945
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6944