QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsfilterrestorer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsowsserver.cpp
3 -------------------
4 begin : February 27, 2012
5 copyright : (C) 2012 by René-Luc D'Hont & Marco Hugentobler
6 email : rldhont at 3liz dot com
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
18#include "qgsfilterrestorer.h"
19#include "qgsmessagelog.h"
20#include "qgsvectorlayer.h"
21
22#ifdef HAVE_SERVER_PYTHON_PLUGINS
23#include "qgsaccesscontrol.h"
24#endif
25
27#ifdef HAVE_SERVER_PYTHON_PLUGINS
28void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl *accessControl, QgsMapLayer *mapLayer, QHash<QgsMapLayer *, QString> &originalLayerFilters )
29{
30 if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
31 {
32 QString sql = accessControl->extraSubsetString( layer );
33 if ( !sql.isEmpty() )
34 {
35 if ( !originalLayerFilters.contains( layer ) )
36 {
37 originalLayerFilters.insert( layer, layer->subsetString() );
38 }
39 if ( !layer->subsetString().isEmpty() )
40 {
41 sql.prepend( ") AND (" );
42 sql.append( ")" );
43 sql.prepend( layer->subsetString() );
44 sql.prepend( "(" );
45 }
46 if ( !layer->setSubsetString( sql ) )
47 {
48 QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
49 }
50 }
51 }
52}
53
55{
56 if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
57 {
58 QString sql = accessControl->extraSubsetString( layer );
59 if ( !sql.isEmpty() )
60 {
61 if ( !layer->subsetString().isEmpty() )
62 {
63 sql.prepend( ") AND (" );
64 sql.append( ")" );
65 sql.prepend( layer->subsetString() );
66 sql.prepend( "(" );
67 }
68 if ( !layer->setSubsetString( sql ) )
69 {
70 QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
71 }
72 }
73 }
74}
75#endif
76
78void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer *, QString> &filterMap )
79{
80 QHash<QgsMapLayer *, QString>::const_iterator filterIt = filterMap.constBegin();
81 for ( ; filterIt != filterMap.constEnd(); ++filterIt )
82 {
83 QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( filterIt.key() );
84 if ( filteredLayer )
85 {
86 if ( !filteredLayer->setSubsetString( filterIt.value() ) )
87 {
88 QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
89 }
90 }
91 }
92}
A helper class that centralizes restrictions given by all the access control filter plugins.
QString extraSubsetString(const QgsVectorLayer *layer) const
Returns an additional subset string (typically SQL) filter.
Base class for all map layer types.
Definition qgsmaplayer.h:76
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
static void applyAccessControlLayerFilters(const QgsAccessControl *accessControl, QgsMapLayer *mapLayer, QHash< QgsMapLayer *, QString > &originalLayerFilters)
Apply filter from AccessControl.
void restoreLayerFilters(const QHash< QgsMapLayer *, QString > &filterMap)
Apply filter from AccessControal.
Represents a vector layer which manages a vector based data sets.
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.