Skip to content
Permalink
Browse files

Merge pull request #5561 from pvalsecc/wms_ogc_filters

[FEATURE][needs-docs] Add OGC filters to WMS
  • Loading branch information
rldhont committed Dec 15, 2017
2 parents ac6d251 + b8f708f commit 3692fcdb96911ee42a4efe18a8609b45645ecafb
@@ -0,0 +1,60 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsfeaturefilter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsFeatureFilter : QgsFeatureFilterProvider
{
%Docstring
A feature filter provider allowing to set filter expressions on a per-layer basis.
.. versionadded:: 3.0
*
%End

%TypeHeaderCode
#include "qgsfeaturefilter.h"
%End
public:
QgsFeatureFilter();
%Docstring
Constructor
%End

void filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const;
%Docstring
Filter the features of the layer
\param layer the layer to control
\param filterFeatures the request to fill
%End

QgsFeatureFilterProvider *clone() const /Factory/;
%Docstring
Return a clone of the object
:return: A clone
:rtype: QgsFeatureFilterProvider
%End

void setFilter( const QgsVectorLayer *layer, const QgsExpression &expression );
%Docstring
Set a filter for the given layer.
\param layer the layer to filter
\param expression the filter expression
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsfeaturefilter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -0,0 +1,60 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsfeaturefilterprovidergroup.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsFeatureFilterProviderGroup : QgsFeatureFilterProvider
{
%Docstring
A filter filter provider grouping several filter providers.
.. versionadded:: 3.0
*
%End

%TypeHeaderCode
#include "qgsfeaturefilterprovidergroup.h"
%End
public:
QgsFeatureFilterProviderGroup();
%Docstring
Constructor
%End

void filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const;
%Docstring
Filter the features of the layer
\param layer the layer to control
\param filterFeatures the request to fill
%End

QgsFeatureFilterProvider *clone() const /Factory/;
%Docstring
Return a clone of the object
:return: A clone
:rtype: QgsFeatureFilterProvider
%End

QgsFeatureFilterProviderGroup &addProvider( const QgsFeatureFilterProvider *provider );
%Docstring
Add another filter provider to the group
\param provider The provider to add
:return: itself
:rtype: QgsFeatureFilterProviderGroup
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsfeaturefilterprovidergroup.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -17,6 +17,8 @@
%Include qgsservice.sip
%Include qgsservicemodule.sip
%Include qgsserviceregistry.sip
%Include qgsfeaturefilterprovidergroup.sip
%Include qgsfeaturefilter.sip
%If ( HAVE_SERVER_PYTHON_PLUGINS )
%Include qgsserverfilter.sip
%End
@@ -428,7 +428,7 @@ class CORE_EXPORT QgsFeatureRequest
*
* \since QGIS 2.12
*/
QgsFeatureRequest &disableFilter() { mFilter = FilterNone; return *this; }
QgsFeatureRequest &disableFilter() { mFilter = FilterNone; mFilterExpression.reset(); return *this; }

/**
* Adds a new OrderByClause, appending it as the least important one.
@@ -44,6 +44,8 @@ SET(QGIS_SERVER_SRCS
qgsservicemodule.cpp
qgsservicenativeloader.cpp
qgsserviceregistry.cpp
qgsfeaturefilterprovidergroup.cpp
qgsfeaturefilter.cpp
)

SET (QGIS_SERVER_HDRS
@@ -0,0 +1,42 @@
/***************************************************************************
qgsfeaturefilter.cpp
--------------------
begin : 26-10-2017
copyright : (C) 2017 by Patrick Valsecchi
email : patrick dot valsecchi at camptocamp dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsfeaturefilter.h"
#include "qgsfeaturerequest.h"
#include "qgsvectorlayer.h"
#include "qgsexpression.h"

void QgsFeatureFilter::filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const
{
const QString expr = mFilters[layer->id()];
if ( !expr.isEmpty() )
{
filterFeatures.setFilterExpression( expr );
}
}

QgsFeatureFilterProvider *QgsFeatureFilter::clone() const
{
auto result = new QgsFeatureFilter();
result->mFilters = mFilters;
return result;
}

void QgsFeatureFilter::setFilter( const QgsVectorLayer *layer, const QgsExpression &filter )
{
mFilters[layer->id()] = filter.dump();
}
@@ -0,0 +1,64 @@
/***************************************************************************
qgsfeaturefilter.h
------------------
begin : 26-10-2017
copyright : (C) 2017 by Patrick Valsecchi
email : patrick dot valsecchi at camptocamp dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSFEATUREFILTER_H
#define QGSFEATUREFILTER_H

#include "qgsfeaturefilterprovider.h"
#include "qgis_server.h"

#include <QMap>

class QgsExpression;

/**
* \ingroup server
* \class QgsFeatureFilter
* \brief A feature filter provider allowing to set filter expressions on a per-layer basis.
* \since QGIS 3.0
**/
class SERVER_EXPORT QgsFeatureFilter : public QgsFeatureFilterProvider
{
public:
//! Constructor
QgsFeatureFilter() {}

/**
* Filter the features of the layer
* \param layer the layer to control
* \param filterFeatures the request to fill
*/
void filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const;

/**
* Return a clone of the object
* \returns A clone
*/
QgsFeatureFilterProvider *clone() const SIP_FACTORY;

/**
* Set a filter for the given layer.
* \param layer the layer to filter
* \param expression the filter expression
*/
void setFilter( const QgsVectorLayer *layer, const QgsExpression &expression );

private:
QMap<QString, QString> mFilters;
};

#endif
@@ -0,0 +1,49 @@
/***************************************************************************
qgsfeaturefilterprovidergroup.cpp
--------------------------------
begin : 26-10-2017
copyright : (C) 2017 by Patrick Valsecchi
email : patrick dot valsecchi at camptocamp dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsfeaturefilterprovidergroup.h"
#include "qgsfeaturerequest.h"

void QgsFeatureFilterProviderGroup::filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const
{
filterFeatures.disableFilter();
for ( const QgsFeatureFilterProvider *provider : mProviders )
{
QgsFeatureRequest temp;
provider->filterFeatures( layer, temp );
if ( temp.filterExpression() )
{
filterFeatures.combineFilterExpression( temp.filterExpression()->dump() );
}
}
}

QgsFeatureFilterProvider *QgsFeatureFilterProviderGroup::clone() const
{
auto result = new QgsFeatureFilterProviderGroup();
result->mProviders = mProviders;
return result;
}

QgsFeatureFilterProviderGroup &QgsFeatureFilterProviderGroup::addProvider( const QgsFeatureFilterProvider *provider )
{
if ( provider )
{
mProviders.append( provider );
}
return *this;
}
@@ -0,0 +1,62 @@
/***************************************************************************
qgsfeaturefilterprovidergroup.h
-------------------------------
begin : 26-10-2017
copyright : (C) 2017 by Patrick Valsecchi
email : patrick dot valsecchi at camptocamp dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSFEATUREFILTERPROVIDERGROUP_H
#define QGSFEATUREFILTERPROVIDERGROUP_H

#include "qgsfeaturefilterprovider.h"
#include "qgis_server.h"

#include <QList>

/**
* \ingroup server
* \class QgsFeatureFilterProviderGroup
* \brief A filter filter provider grouping several filter providers.
* \since QGIS 3.0
**/
class SERVER_EXPORT QgsFeatureFilterProviderGroup : public QgsFeatureFilterProvider
{
public:
//! Constructor
QgsFeatureFilterProviderGroup() {}

/**
* Filter the features of the layer
* \param layer the layer to control
* \param filterFeatures the request to fill
*/
void filterFeatures( const QgsVectorLayer *layer, QgsFeatureRequest &filterFeatures ) const;

/**
* Return a clone of the object
* \returns A clone
*/
QgsFeatureFilterProvider *clone() const SIP_FACTORY;

/**
* Add another filter provider to the group
* \param provider The provider to add
* \return itself
*/
QgsFeatureFilterProviderGroup &addProvider( const QgsFeatureFilterProvider *provider );

private:
QList<const QgsFeatureFilterProvider *> mProviders;
};

#endif

0 comments on commit 3692fcd

Please sign in to comment.
You can’t perform that action at this time.