QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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
29  QHash<QgsMapLayer *, QString> &originalLayerFilters )
30 {
31  if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
32  {
33  QString sql = accessControl->extraSubsetString( layer );
34  if ( !sql.isEmpty() )
35  {
36  if ( !originalLayerFilters.contains( layer ) )
37  {
38  originalLayerFilters.insert( layer, layer->subsetString() );
39  }
40  if ( !layer->subsetString().isEmpty() )
41  {
42  sql.prepend( ") AND (" );
43  sql.append( ")" );
44  sql.prepend( layer->subsetString() );
45  sql.prepend( "(" );
46  }
47  if ( !layer->setSubsetString( sql ) )
48  {
49  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
50  }
51  }
52  }
53 }
54 
56 {
57  if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
58  {
59  QString sql = accessControl->extraSubsetString( layer );
60  if ( !sql.isEmpty() )
61  {
62  if ( !layer->subsetString().isEmpty() )
63  {
64  sql.prepend( ") AND (" );
65  sql.append( ")" );
66  sql.prepend( layer->subsetString() );
67  sql.prepend( "(" );
68  }
69  if ( !layer->setSubsetString( sql ) )
70  {
71  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
72  }
73  }
74  }
75 }
76 #endif
77 
79 void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer *, QString> &filterMap )
80 {
81  QHash<QgsMapLayer *, QString>::const_iterator filterIt = filterMap.constBegin();
82  for ( ; filterIt != filterMap.constEnd(); ++filterIt )
83  {
84  QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( filterIt.key() );
85  if ( filteredLayer )
86  {
87  if ( !filteredLayer->setSubsetString( filterIt.value() ) )
88  {
89  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
90  }
91  }
92  }
93 }
Base class for all map layer types.
Definition: qgsmaplayer.h:78
QString extraSubsetString(const QgsVectorLayer *layer) const
Returns an additional subset string (typically SQL) filter.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
virtual bool setSubsetString(const QString &subset)
Sets the string (typically sql) used to define a subset of the layer.
A helper class that centralizes restrictions given by all the access control filter plugins...
Represents a vector layer which manages a vector based data sets.