Skip to content

Commit

Permalink
[FEATURE][needs-docs] Add OGC filters to WMS
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Valsecchi committed Nov 28, 2017
1 parent d31f60b commit b8f708f
Show file tree
Hide file tree
Showing 22 changed files with 593 additions and 108 deletions.
60 changes: 60 additions & 0 deletions python/server/qgsfeaturefilter.sip
@@ -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 *
************************************************************************/
60 changes: 60 additions & 0 deletions python/server/qgsfeaturefilterprovidergroup.sip
@@ -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 *
************************************************************************/
2 changes: 2 additions & 0 deletions python/server/server_auto.sip
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeaturerequest.h
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/server/CMakeLists.txt
Expand Up @@ -44,6 +44,8 @@ SET(QGIS_SERVER_SRCS
qgsservicemodule.cpp
qgsservicenativeloader.cpp
qgsserviceregistry.cpp
qgsfeaturefilterprovidergroup.cpp
qgsfeaturefilter.cpp
)

SET (QGIS_SERVER_HDRS
Expand Down
42 changes: 42 additions & 0 deletions src/server/qgsfeaturefilter.cpp
@@ -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();
}
64 changes: 64 additions & 0 deletions src/server/qgsfeaturefilter.h
@@ -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
49 changes: 49 additions & 0 deletions src/server/qgsfeaturefilterprovidergroup.cpp
@@ -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;
}
62 changes: 62 additions & 0 deletions src/server/qgsfeaturefilterprovidergroup.h
@@ -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 b8f708f

Please sign in to comment.