QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #include "qgsvectordataprovider.h"
22 
23 #ifdef HAVE_SERVER_PYTHON_PLUGINS
24 #include "qgsaccesscontrol.h"
25 #endif
26 
28 #ifdef HAVE_SERVER_PYTHON_PLUGINS
30  QHash<QgsMapLayer *, QString> &originalLayerFilters )
31 {
32  if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
33  {
34  QString sql = accessControl->extraSubsetString( layer );
35  if ( !sql.isEmpty() )
36  {
37  if ( !originalLayerFilters.contains( layer ) )
38  {
39  originalLayerFilters.insert( layer, layer->subsetString() );
40  }
41  if ( !layer->subsetString().isEmpty() )
42  {
43  sql.prepend( ") AND (" );
44  sql.append( ")" );
45  sql.prepend( layer->subsetString() );
46  sql.prepend( "(" );
47  }
48  if ( !layer->setSubsetString( sql ) )
49  {
50  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
51  }
52  }
53  }
54 }
55 
57 {
58  if ( QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( mapLayer ) )
59  {
60  QString sql = accessControl->extraSubsetString( layer );
61  if ( !sql.isEmpty() )
62  {
63  if ( !layer->subsetString().isEmpty() )
64  {
65  sql.prepend( ") AND (" );
66  sql.append( ")" );
67  sql.prepend( layer->subsetString() );
68  sql.prepend( "(" );
69  }
70  if ( !layer->setSubsetString( sql ) )
71  {
72  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
73  }
74  }
75  }
76 }
77 #endif
78 
80 void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer *, QString> &filterMap )
81 {
82  QHash<QgsMapLayer *, QString>::const_iterator filterIt = filterMap.constBegin();
83  for ( ; filterIt != filterMap.constEnd(); ++filterIt )
84  {
85  QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( filterIt.key() );
86  if ( filteredLayer )
87  {
88  if ( !filteredLayer->setSubsetString( filterIt.value() ) )
89  {
90  QgsMessageLog::logMessage( QStringLiteral( "Layer does not support Subset String" ) );
91  }
92  }
93  }
94 }
Base class for all map layer types.
Definition: qgsmaplayer.h:63
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)
Set 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.