[Server] Refactoring, removing qgs*parser files

This commit is contained in:
rldhont 2017-09-06 13:48:30 +02:00
parent d8cf02e083
commit 8774e69328
19 changed files with 0 additions and 7366 deletions

View File

@ -34,17 +34,6 @@ class QgsConfigCache : QObject
:rtype: QgsConfigCache
%End
QgsServerProjectParser *serverConfiguration( const QString &filePath );
%Docstring
:rtype: QgsServerProjectParser
%End
QgsWmsConfigParser *wmsConfiguration( const QString &filePath,
const QgsAccessControl *accessControl,
const QMap<QString, QString> &parameterMap = QMap< QString, QString >() );
%Docstring
:rtype: QgsWmsConfigParser
%End
void removeEntry( const QString &path );
const QgsProject *project( const QString &path );

View File

@ -1,235 +0,0 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsserverprojectparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsServerProjectParser
{
%Docstring
*************************************************************************
*
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. *
*
**************************************************************************
%End
%TypeHeaderCode
#include "qgsserverprojectparser.h"
%End
public:
QgsServerProjectParser( QDomDocument *xmlDoc, const QString &filePath );
QString projectPath() const;
%Docstring
:rtype: str
%End
const QDomDocument *xmlDocument() const;
%Docstring
:rtype: QDomDocument
%End
void projectLayerMap( QMap<QString, QgsMapLayer *> &layerMap ) const;
%Docstring
Returns project layers by id
%End
QString convertToAbsolutePath( const QString &file ) const;
%Docstring
Converts a (possibly relative) path to absolute
:rtype: str
%End
QgsMapLayer *createLayerFromElement( const QDomElement &elem, bool useCache = true ) const;
%Docstring
Creates a maplayer object from <maplayer> element. The layer cash owns the maplayer, so don't delete it
:return: the maplayer or 0 in case of error*
:rtype: QgsMapLayer
%End
QgsMapLayer *mapLayerFromLayerId( const QString &lId, bool useCache = true ) const;
%Docstring
:rtype: QgsMapLayer
%End
QString layerIdFromLegendLayer( const QDomElement &legendLayer ) const;
%Docstring
Returns the layer id under a <legendlayer> tag in the QGIS projectfile
:rtype: str
%End
void combineExtentAndCrsOfGroupChildren( QDomElement &groupElement, QDomDocument &doc, bool considerMapExtent = false ) const;
%Docstring
\param considerMapExtent Take user-defined map extent instead of data-calculated extent if present in project file
%End
void addLayerProjectSettings( QDomElement &layerElem, QDomDocument &doc, QgsMapLayer *currentLayer ) const;
QgsRectangle layerBoundingBoxInProjectCrs( const QDomElement &layerElem, const QDomDocument &doc ) const;
%Docstring
:rtype: QgsRectangle
%End
bool crsSetForLayer( const QDomElement &layerElement, QSet<QString> &crsSet ) const;
%Docstring
:rtype: bool
%End
QgsCoordinateReferenceSystem projectCrs() const;
%Docstring
:rtype: QgsCoordinateReferenceSystem
%End
QgsRectangle mapRectangle() const;
%Docstring
:rtype: QgsRectangle
%End
QStringList supportedOutputCrsList() const;
%Docstring
:rtype: list of str
%End
QList<QDomElement> projectLayerElements() const;
%Docstring
:rtype: list of QDomElement
%End
QList<QDomElement> legendGroupElements() const;
%Docstring
:rtype: list of QDomElement
%End
QString projectTitle() const;
%Docstring
:rtype: str
%End
QDomElement legendElem() const;
%Docstring
:rtype: QDomElement
%End
QDomElement propertiesElem() const;
%Docstring
:rtype: QDomElement
%End
QSet<QString> restrictedLayers() const;
%Docstring
:rtype: set of str
%End
bool useLayerIds() const;
%Docstring
:rtype: bool
%End
QHash< QString, QDomElement > projectLayerElementsByName() const;
%Docstring
:rtype: QHash< str, QDomElement >
%End
QHash< QString, QDomElement > projectLayerElementsById() const;
%Docstring
:rtype: QHash< str, QDomElement >
%End
QStringList wfsLayerNames() const;
%Docstring
:rtype: list of str
%End
QStringList wcsLayerNames() const;
%Docstring
:rtype: list of str
%End
QStringList layersNames() const;
%Docstring
Gets a list containing names of layers. If a layer has a short name,
then it's used instead of it's name.
:return: A list of layers' names or short name if defined
.. versionadded:: 3.0
:rtype: list of str
%End
QDomElement firstComposerLegendElement() const;
%Docstring
:rtype: QDomElement
%End
QList<QDomElement> publishedComposerElements() const;
%Docstring
:rtype: list of QDomElement
%End
QStringList wfsLayers() const;
%Docstring
:rtype: list of str
%End
QStringList wcsLayers() const;
%Docstring
:rtype: list of str
%End
void addJoinLayersForElement( const QDomElement &layerElem ) const;
%Docstring
Add layers for vector joins
%End
void addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const;
void addGetFeatureLayers( const QDomElement &layerElem ) const;
%Docstring
Add layers which are necessary for the evaluation of the expression function 'getFeature( layer, attributeField, value)'
%End
QString layerId( const QDomElement &layerElem ) const;
%Docstring
Returns the text of the <id> element for a layer element
:return: id or a null string in case of error*
:rtype: str
%End
QgsRectangle projectExtent() const;
%Docstring
:rtype: QgsRectangle
%End
int numberOfLayers() const;
%Docstring
:rtype: int
%End
bool updateLegendDrawingOrder() const;
%Docstring
:rtype: bool
%End
void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &service, bool sia2045 = false ) const;
QStringList customLayerOrder() const;
%Docstring
:rtype: list of str
%End
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgsserverprojectparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -1,243 +0,0 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgswmsconfigparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsWmsConfigParser
{
%Docstring
*************************************************************************
*
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. *
*
**************************************************************************
%End
%TypeHeaderCode
#include "qgswmsconfigparser.h"
%End
public:
virtual void layersAndStylesCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &version, const QString &serviceUrl, bool fullProjectSettings = false ) const = 0;
%Docstring
Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
\param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*
%End
virtual QList<QgsMapLayer *> mapLayerFromStyle( const QString &lName, const QString &styleName, bool useCache = true ) const = 0;
%Docstring
Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned
:rtype: list of QgsMapLayer
%End
virtual int layersAndStyles( QStringList &layers, QStringList &styles ) const = 0;
%Docstring
Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success
:rtype: int
%End
virtual QDomDocument getStyle( const QString &styleName, const QString &layerName ) const = 0;
%Docstring
Returns the xml fragment of a style
:rtype: QDomDocument
%End
virtual QDomDocument getStyles( QStringList &layerList ) const = 0;
%Docstring
Returns the xml fragment of layers styles
:rtype: QDomDocument
%End
virtual QDomDocument describeLayer( QStringList &layerList, const QString &wfsHrefString, const QString &wcsHrefString ) const = 0;
%Docstring
Returns the xml fragment of layers styles description
:rtype: QDomDocument
%End
virtual QgsUnitTypes::RenderUnit outputUnits() const = 0;
%Docstring
Returns if output are MM or PIXEL
:rtype: QgsUnitTypes.RenderUnit
%End
virtual QStringList identifyDisabledLayers() const = 0;
%Docstring
Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file
:rtype: list of str
%End
virtual bool featureInfoWithWktGeometry() const = 0;
%Docstring
True if the feature info response should contain the wkt geometry for vector features
:rtype: bool
%End
virtual bool segmentizeFeatureInfoWktGeometry() const = 0;
%Docstring
True if the feature info wkt geometry is delivered with segmentized curve types
:rtype: bool
%End
virtual QHash<QString, QString> featureInfoLayerAliasMap() const = 0;
%Docstring
Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias
:rtype: QHash<str, QString>
%End
virtual QString featureInfoDocumentElement( const QString &defaultValue ) const = 0;
%Docstring
:rtype: str
%End
virtual QString featureInfoDocumentElementNS() const = 0;
%Docstring
:rtype: str
%End
virtual QString featureInfoSchema() const = 0;
%Docstring
:rtype: str
%End
virtual bool featureInfoFormatSIA2045() const = 0;
%Docstring
Return feature info in format SIA2045?
:rtype: bool
%End
virtual void drawOverlays( QPainter *p, int dpi, int width, int height ) const = 0;
%Docstring
Draw text annotation items from the QGIS projectfile
%End
virtual void loadLabelSettings() const = 0;
%Docstring
Load PAL engine settings into global project instance
%End
virtual QStringList wfsLayerNames() const = 0;
%Docstring
:rtype: list of str
%End
virtual void owsGeneralAndResourceList( QDomElement &parentElement, QDomDocument &doc, const QString &strHref ) const = 0;
virtual double legendBoxSpace() const = 0;
%Docstring
:rtype: float
%End
virtual double legendLayerSpace() const = 0;
%Docstring
:rtype: float
%End
virtual double legendLayerTitleSpace() const = 0;
%Docstring
:rtype: float
%End
virtual double legendSymbolSpace() const = 0;
%Docstring
:rtype: float
%End
virtual double legendIconLabelSpace() const = 0;
%Docstring
:rtype: float
%End
virtual double legendSymbolWidth() const = 0;
%Docstring
:rtype: float
%End
virtual double legendSymbolHeight() const = 0;
%Docstring
:rtype: float
%End
virtual QFont legendLayerFont() const = 0;
%Docstring
:rtype: QFont
%End
virtual QFont legendItemFont() const = 0;
%Docstring
:rtype: QFont
%End
virtual double imageQuality() const = 0;
%Docstring
:rtype: float
%End
virtual int wmsPrecision() const = 0;
%Docstring
:rtype: int
%End
virtual bool wmsInspireActivated() const = 0;
%Docstring
:rtype: bool
%End
virtual void inspireCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
%Docstring
Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element
%End
QgsComposition *createPrintComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, const QMap< QString, QString > &parameterMap, QStringList &highlightLayers ) const;
%Docstring
:rtype: QgsComposition
%End
virtual void printCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
%Docstring
Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element
%End
virtual void setScaleDenominator( double denom ) = 0;
virtual void addExternalGMLData( const QString &layerName, QDomDocument *gmlDoc ) = 0;
virtual int nLayers() const = 0;
%Docstring
:rtype: int
%End
virtual void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
virtual bool useLayerIds() const = 0;
%Docstring
:rtype: bool
%End
virtual bool allowRequestDefinedDatasources() const;
%Docstring
:rtype: bool
%End
static QStringList addHighlightLayers( const QMap<QString, QString> &parameterMap, QStringList &layerSet, const QString &parameterPrefix = QString() );
%Docstring
Adds highlight layers to the layer registry and to the layer set. Returns the ids of the newly created layers (for later removal)
:rtype: list of str
%End
static void removeHighlightLayers( const QStringList &layerIds );
private:
QgsWmsConfigParser();
virtual ~QgsWmsConfigParser();
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgswmsconfigparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -1,190 +0,0 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgswmsprojectparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsWmsProjectParser : QgsWmsConfigParser
{
%Docstring
*************************************************************************
*
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. *
*
**************************************************************************
%End
%TypeHeaderCode
#include "qgswmsprojectparser.h"
%End
public:
QgsWmsProjectParser( const QString &filePath, const QgsAccessControl *accessControl );
virtual ~QgsWmsProjectParser();
virtual void layersAndStylesCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &version, const QString &serviceUrl, bool fullProjectSettings = false ) const;
%Docstring
Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
\param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*
%End
virtual QList<QgsMapLayer *> mapLayerFromStyle( const QString &lName, const QString &styleName, bool useCache = true ) const;
virtual QStringList wfsLayerNames() const;
virtual void owsGeneralAndResourceList( QDomElement &parentElement, QDomDocument &doc, const QString &strHref ) const;
virtual double legendBoxSpace() const;
virtual double legendLayerSpace() const;
virtual double legendLayerTitleSpace() const;
virtual double legendSymbolSpace() const;
virtual double legendIconLabelSpace() const;
virtual double legendSymbolWidth() const;
virtual double legendSymbolHeight() const;
virtual QFont legendLayerFont() const;
virtual QFont legendItemFont() const;
virtual double imageQuality() const;
virtual int wmsPrecision() const;
virtual bool wmsInspireActivated() const;
virtual void inspireCapabilities( QDomElement &parentElement, QDomDocument &doc ) const;
virtual void printCapabilities( QDomElement &parentElement, QDomDocument &doc ) const;
virtual void setScaleDenominator( double );
virtual void addExternalGMLData( const QString &, QDomDocument * );
virtual int layersAndStyles( QStringList &layers, QStringList &styles ) const;
%Docstring
Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success
:rtype: int
%End
virtual QDomDocument getStyle( const QString &styleName, const QString &layerName ) const;
%Docstring
Returns the xml fragment of a style
:rtype: QDomDocument
%End
virtual QDomDocument getStyles( QStringList &layerList ) const;
%Docstring
Returns the xml fragment of layers styles
:rtype: QDomDocument
%End
virtual QDomDocument describeLayer( QStringList &layerList, const QString &wfsHrefString, const QString &wcsHrefString ) const;
%Docstring
Returns the xml fragment of layers styles description
:rtype: QDomDocument
%End
virtual QgsUnitTypes::RenderUnit outputUnits() const;
%Docstring
Returns if output are MM or PIXEL
:rtype: QgsUnitTypes.RenderUnit
%End
virtual bool featureInfoWithWktGeometry() const;
%Docstring
True if the feature info response should contain the wkt geometry for vector features
:rtype: bool
%End
virtual bool segmentizeFeatureInfoWktGeometry() const;
%Docstring
True if the feature info wkt geometry is delivered with segmentized curve types
:rtype: bool
%End
virtual QHash<QString, QString> featureInfoLayerAliasMap() const;
%Docstring
Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias
:rtype: QHash<str, QString>
%End
virtual QString featureInfoDocumentElement( const QString &defaultValue ) const;
virtual QString featureInfoDocumentElementNS() const;
virtual QString featureInfoSchema() const;
virtual bool featureInfoFormatSIA2045() const;
%Docstring
Return feature info in format SIA2045?
:rtype: bool
%End
virtual void drawOverlays( QPainter *p, int dpi, int width, int height ) const;
%Docstring
Draw text annotation items from the QGIS projectfile
%End
virtual void loadLabelSettings() const;
%Docstring
Load PAL engine settings into global project instance
%End
virtual int nLayers() const;
virtual void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc ) const;
virtual bool useLayerIds() const;
virtual bool allowRequestDefinedDatasources() const;
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/server/qgswmsprojectparser.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -11,15 +11,12 @@
%If ( HAVE_SERVER_PYTHON_PLUGINS )
%Include qgsserverinterface.sip
%End
%Include qgsserverprojectparser.sip
%Include qgsserverprojectutils.sip
%Include qgsserverrequest.sip
%Include qgsserverresponse.sip
%Include qgsservice.sip
%Include qgsservicemodule.sip
%Include qgsserviceregistry.sip
%Include qgswmsconfigparser.sip
%Include qgswmsprojectparser.sip
%If ( HAVE_SERVER_PYTHON_PLUGINS )
%Include qgsserverfilter.sip
%End

View File

@ -43,7 +43,6 @@ SET(QGIS_SERVER_SRCS
qgsserverinterface.cpp
qgsserverinterfaceimpl.cpp
qgsserverlogger.cpp
qgsserverprojectparser.cpp
qgsserverprojectutils.cpp
qgsserverrequest.cpp
qgsserverresponse.cpp
@ -52,9 +51,6 @@ SET(QGIS_SERVER_SRCS
qgsservicemodule.cpp
qgsservicenativeloader.cpp
qgsserviceregistry.cpp
qgssldconfigparser.cpp
qgswmsconfigparser.cpp
qgswmsprojectparser.cpp
)
SET (QGIS_SERVER_HDRS

View File

@ -18,8 +18,6 @@
#include "qgsconfigcache.h"
#include "qgsmessagelog.h"
#include "qgsmslayercache.h"
#include "qgswmsprojectparser.h"
#include "qgssldconfigparser.h"
#include "qgsaccesscontrol.h"
#include "qgsproject.h"
@ -54,79 +52,6 @@ const QgsProject *QgsConfigCache::project( const QString &path )
return mProjectCache[ path ];
}
QgsServerProjectParser *QgsConfigCache::serverConfiguration( const QString &filePath )
{
QgsMessageLog::logMessage(
QStringLiteral( "Open the project file '%1'." )
.arg( filePath ),
QStringLiteral( "Server" ), QgsMessageLog::INFO
);
QDomDocument *doc = xmlDocument( filePath );
if ( !doc )
{
return nullptr;
}
QgsProjectVersion fileVersion = getVersion( *doc );
QgsProjectVersion thisVersion( Qgis::QGIS_VERSION );
if ( thisVersion != fileVersion )
{
QgsMessageLog::logMessage(
QString(
"\n========================================================================"
"\n= WARNING: This project file was saved by a different version of QGIS. ="
"\n========================================================================"
), QStringLiteral( "Server" ), QgsMessageLog::WARNING
);
}
QgsMessageLog::logMessage(
QStringLiteral( "QGIS server version %1, project version %2" )
.arg( thisVersion.text(), fileVersion.text() ),
QStringLiteral( "Server" ), QgsMessageLog::INFO
);
return new QgsServerProjectParser( doc, filePath );
}
QgsWmsConfigParser *QgsConfigCache::wmsConfiguration(
const QString &filePath
, const QgsAccessControl *accessControl
, const QMap<QString, QString> &parameterMap
)
{
QgsWmsConfigParser *p = mWMSConfigCache.object( filePath );
if ( !p )
{
QDomDocument *doc = xmlDocument( filePath );
if ( !doc )
{
return nullptr;
}
//sld or QGIS project file?
//is it an sld document or a qgis project file?
QDomElement documentElem = doc->documentElement();
if ( documentElem.tagName() == QLatin1String( "StyledLayerDescriptor" ) )
{
p = new QgsSLDConfigParser( doc, parameterMap );
}
else
{
p = new QgsWmsProjectParser(
filePath
, accessControl
);
}
mWMSConfigCache.insert( filePath, p );
p = mWMSConfigCache.object( filePath );
Q_ASSERT( p );
}
QgsMSLayerCache::instance()->setProjectMaxLayers( p->nLayers() );
return p;
}
QDomDocument *QgsConfigCache::xmlDocument( const QString &filePath )
{
//first open file
@ -168,8 +93,6 @@ QDomDocument *QgsConfigCache::xmlDocument( const QString &filePath )
void QgsConfigCache::removeChangedEntry( const QString &path )
{
mWMSConfigCache.remove( path );
//xml document must be removed last, as other config cache destructors may require it
mXmlDocumentCache.remove( path );

View File

@ -28,10 +28,8 @@
#include "qgis_server.h"
#include "qgis_sip.h"
#include "qgswmsconfigparser.h"
#include "qgsproject.h"
class QgsServerProjectParser;
class QgsAccessControl;
class SERVER_EXPORT QgsConfigCache : public QObject
@ -40,11 +38,6 @@ class SERVER_EXPORT QgsConfigCache : public QObject
public:
static QgsConfigCache *instance();
QgsServerProjectParser *serverConfiguration( const QString &filePath );
QgsWmsConfigParser *wmsConfiguration( const QString &filePath,
const QgsAccessControl *accessControl,
const QMap<QString, QString> &parameterMap = QMap< QString, QString >() );
void removeEntry( const QString &path );
/** If the project is not cached yet, then the project is read thank to the
@ -65,7 +58,6 @@ class SERVER_EXPORT QgsConfigCache : public QObject
QDomDocument *xmlDocument( const QString &filePath );
QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsWmsConfigParser> mWMSConfigCache;
QCache<QString, QgsProject> mProjectCache;
private slots:

File diff suppressed because it is too large Load Diff

View File

@ -1,175 +0,0 @@
/***************************************************************************
qgsserverprojectparser.h
------------------------
begin : March 25, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 QGSSERVERPROJECTPARSER_H
#define QGSSERVERPROJECTPARSER_H
#include "qgsconfig.h"
#include "qgsvectorlayer.h"
#include "qgsdatumtransformstore.h"
#include <QDomElement>
#include <QHash>
#include <QMap>
#include <QString>
#include "qgis_server.h"
class QgsCoordinateReferenceSystem;
class QgsMapLayer;
class QgsRectangle;
class QDomDocument;
class QgsLayerTreeGroup;
class SERVER_EXPORT QgsServerProjectParser
{
public:
QgsServerProjectParser( QDomDocument *xmlDoc, const QString &filePath );
QString projectPath() const { return mProjectPath; }
const QDomDocument *xmlDocument() const { return mXMLDoc; }
//! Returns project layers by id
void projectLayerMap( QMap<QString, QgsMapLayer *> &layerMap ) const;
//! Converts a (possibly relative) path to absolute
QString convertToAbsolutePath( const QString &file ) const;
/** Creates a maplayer object from <maplayer> element. The layer cash owns the maplayer, so don't delete it
\returns the maplayer or 0 in case of error*/
QgsMapLayer *createLayerFromElement( const QDomElement &elem, bool useCache = true ) const;
QgsMapLayer *mapLayerFromLayerId( const QString &lId, bool useCache = true ) const;
//! Returns the layer id under a <legendlayer> tag in the QGIS projectfile
QString layerIdFromLegendLayer( const QDomElement &legendLayer ) const;
//! \param considerMapExtent Take user-defined map extent instead of data-calculated extent if present in project file
void combineExtentAndCrsOfGroupChildren( QDomElement &groupElement, QDomDocument &doc, bool considerMapExtent = false ) const;
void addLayerProjectSettings( QDomElement &layerElem, QDomDocument &doc, QgsMapLayer *currentLayer ) const;
QgsRectangle layerBoundingBoxInProjectCrs( const QDomElement &layerElem, const QDomDocument &doc ) const;
bool crsSetForLayer( const QDomElement &layerElement, QSet<QString> &crsSet ) const;
QgsCoordinateReferenceSystem projectCrs() const;
QgsRectangle mapRectangle() const;
QStringList supportedOutputCrsList() const;
QList<QDomElement> projectLayerElements() const { return mProjectLayerElements; }
QList<QDomElement> legendGroupElements() const { return mLegendGroupElements; }
QString projectTitle() const;
QDomElement legendElem() const;
QDomElement propertiesElem() const;
QSet<QString> restrictedLayers() const { return mRestrictedLayers; }
bool useLayerIds() const;
QHash< QString, QDomElement > projectLayerElementsByName() const { return mProjectLayerElementsByName; }
QHash< QString, QDomElement > projectLayerElementsById() const { return mProjectLayerElementsById; }
void layerFromLegendLayer( const QDomElement &legendLayerElem, QMap< int, QgsMapLayer *> &layers, bool useCache = true ) const SIP_SKIP;
QStringList wfsLayerNames() const;
QStringList wcsLayerNames() const;
/** Gets a list containing names of layers. If a layer has a short name,
* then it's used instead of it's name.
* \returns A list of layers' names or short name if defined
* \since QGIS 3.0
*/
QStringList layersNames() const;
QDomElement firstComposerLegendElement() const;
QList<QDomElement> publishedComposerElements() const;
QList< QPair< QString, QgsDatumTransformStore::Entry > > layerCoordinateTransforms() const SIP_SKIP;
QStringList wfsLayers() const;
QStringList wcsLayers() const;
//! Add layers for vector joins
void addJoinLayersForElement( const QDomElement &layerElem ) const;
void addValueRelationLayersForLayer( const QgsVectorLayer *vl ) const;
//! Add layers which are necessary for the evaluation of the expression function 'getFeature( layer, attributeField, value)'
void addGetFeatureLayers( const QDomElement &layerElem ) const;
/** Returns the text of the <id> element for a layer element
\returns id or a null string in case of error*/
QString layerId( const QDomElement &layerElem ) const;
QgsRectangle projectExtent() const;
int numberOfLayers() const;
bool updateLegendDrawingOrder() const;
void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &service, bool sia2045 = false ) const;
QStringList customLayerOrder() const { return mCustomLayerOrder; }
private:
//! Content of project file
QDomDocument *mXMLDoc = nullptr;
//! Project
const QgsProject *mProject = nullptr;
//! Absolute project file path (including file name)
QString mProjectPath;
//! List of project layer (ordered same as in the project file)
QList<QDomElement> mProjectLayerElements;
//! Project layer elements, accessible by layer id
QHash< QString, QDomElement > mProjectLayerElementsById;
//! Project layer elements, accessible by layer name
QHash< QString, QDomElement > mProjectLayerElementsByName;
//! List of all legend group elements
QList<QDomElement> mLegendGroupElements;
//! Names of layers and groups which should not be published
QSet<QString> mRestrictedLayers;
QgsServerProjectParser(); //forbidden
//! Returns a complete string set with all the restricted layer names (layers/groups that are not to be published)
QSet<QString> findRestrictedLayers() const;
QStringList mCustomLayerOrder;
QList<QDomElement> findLegendGroupElements() const;
QList<QDomElement> setLegendGroupElementsWithLayerTree( QgsLayerTreeGroup *layerTreeGroup, const QDomElement &legendElement ) const;
//! Adds sublayers of an embedded group to layer set
static void sublayersOfEmbeddedGroup( const QString &projectFilePath, const QString &groupName, QSet<QString> &layerSet );
};
#endif // QGSSERVERPROJECTPARSER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,209 +0,0 @@
/***************************************************************************
qgssldconfigparser.h
--------------------
begin : March 28, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 QGSSLDCONFIGPARSER_H
#define QGSSLDCONFIGPARSER_H
#define SIP_NO_FILE
#include "qgswmsconfigparser.h"
#include <QFont>
class QgsFeatureRenderer;
class QgsVectorLayer;
class QgsRasterLayer;
class QTemporaryFile;
class SERVER_EXPORT QgsSLDConfigParser : public QgsWmsConfigParser
{
public:
/** Constructor takes a dom document as argument. The class takes ownership of the document and deletes it in the destructor
\param doc SLD document
\param parameterMap map containing the wms request parameters*/
QgsSLDConfigParser( QDomDocument *doc, const QMap<QString, QString> &parameters );
virtual ~QgsSLDConfigParser();
void setFallbackParser( QgsWmsConfigParser *p ) { mFallbackParser = p; }
/** Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
\param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
void layersAndStylesCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &version, const QString &serviceUrl, bool fullProjectSettings = false ) const override;
//! Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned
QList<QgsMapLayer *> mapLayerFromStyle( const QString &lName, const QString &styleName, bool useCache = true ) const override;
//! Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success
int layersAndStyles( QStringList &layers, QStringList &styles ) const override;
//! Returns the xml fragment of a style
QDomDocument getStyle( const QString &styleName, const QString &layerName ) const override;
//! Returns the xml fragment of layers styles
QDomDocument getStyles( QStringList &layerList ) const override;
//! Returns the xml fragment of layers styles description
QDomDocument describeLayer( QStringList &layerList, const QString &wfsHrefString, const QString &wcsHrefString ) const override;
//! Returns if output are MM or PIXEL
QgsUnitTypes::RenderUnit outputUnits() const override;
//! Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file
QStringList identifyDisabledLayers() const override;
//! True if the feature info response should contain the wkt geometry for vector features
bool featureInfoWithWktGeometry() const override;
//! True if the feature info wkt geometry is delivered with segmentized curve types
bool segmentizeFeatureInfoWktGeometry() const override;
//! Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias
QHash<QString, QString> featureInfoLayerAliasMap() const override;
QString featureInfoDocumentElement( const QString &defaultValue ) const override;
QString featureInfoDocumentElementNS() const override;
QString featureInfoSchema() const override;
//! Return feature info in format SIA2045?
bool featureInfoFormatSIA2045() const override;
//! Draw text annotation items from the QGIS projectfile
void drawOverlays( QPainter *p, int dpi, int width, int height ) const override;
//! Load PAL engine settings into global project instance
void loadLabelSettings() const override;
QStringList wfsLayerNames() const override;
void owsGeneralAndResourceList( QDomElement &parentElement, QDomDocument &doc, const QString &strHref ) const override;
//legend
double legendBoxSpace() const override;
double legendLayerSpace() const override;
double legendLayerTitleSpace() const override;
double legendSymbolSpace() const override;
double legendIconLabelSpace() const override;
double legendSymbolWidth() const override;
double legendSymbolHeight() const override;
QFont legendLayerFont() const override;
QFont legendItemFont() const override;
double imageQuality() const override;
int wmsPrecision() const override;
// WMS inspire capabilities
bool wmsInspireActivated() const override;
//! Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element
void inspireCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
//printing
//! Creates a print composition, usually for a GetPrint request. Replaces map and label parameters
QgsComposition *createPrintComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, const QMap< QString, QString > &parameterMap, QStringList &highlightLayers ) const;
//! Creates a composition from the project file (probably delegated to the fallback parser)
QgsComposition *initComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, QList< QgsComposerMap *> &mapList, QList< QgsComposerLegend * > &legendList, QList< QgsComposerLabel * > &labelList, QList<const QgsComposerHtml *> &htmlFrameList ) const override;
//! Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element
void printCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
void setScaleDenominator( double denom ) override;
void addExternalGMLData( const QString &layerName, QDomDocument *gmlDoc ) override;
QList< QPair< QString, QgsDatumTransformStore::Entry > > layerCoordinateTransforms() const override;
int nLayers() const override;
void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
bool allowRequestDefinedDatasources() const override;
private:
//! SLD as dom document
QDomDocument *mXMLDoc = nullptr;
//! Map containing the WMS parameters of the request
QMap<QString, QString> mParameterMap;
QString mSLDNamespace;
//! Output units (pixel or mm)
QgsUnitTypes::RenderUnit mOutputUnits;
QgsWmsConfigParser *mFallbackParser = nullptr;
QFont mLegendLayerFont;
QFont mLegendItemFont;
//! Stores pointers to layers that have to be removed after the request
mutable QList<QgsMapLayer *> mLayersToRemove;
//! Stores the temporary file objects. The class takes ownership of the objects and deletes them in the destructor
mutable QList<QTemporaryFile *> mFilesToRemove;
/** Stores paths of files that need to be removed after each request (necessary because of contours shapefiles that
cannot be handles with QTemporaryFile*/
mutable QList<QString> mFilePathsToRemove;
//default constructor forbidden
QgsSLDConfigParser();
//! Returns a list of all <NamedLayer> element that match the layer name. Returns an empty list if no such layer
QList<QDomElement> findNamedLayerElements( const QString &layerName ) const;
//! Returns the <UserStyle> node of a given <UserLayer> or a null node in case of failure
QDomElement findUserStyleElement( const QDomElement &userLayerElement, const QString &styleName ) const;
//! Returns the <NamedStyle> node of a given <NamedLayer> or a null node in case of failure
QDomElement findNamedStyleElement( const QDomElement &layerElement, const QString &styleName ) const;
//! Creates a Renderer from a UserStyle SLD node. Returns 0 in case of error
QgsFeatureRenderer *rendererFromUserStyle( const QDomElement &userStyleElement, QgsVectorLayer *vec ) const;
/** Searches for a <TextSymbolizer> element and applies the settings to the vector layer
\returns true if settings have been applied, false in case of <TextSymbolizer> element not present or error*/
bool labelSettingsFromUserStyle( const QDomElement &userStyleElement, QgsVectorLayer *vec ) const;
/** Searches for a <RasterSymbolizer> element and applies the settings to the raster layer
\returns true if settings have been applied, false in case of error*/
bool rasterSymbologyFromUserStyle( const QDomElement &userStyleElement, QgsRasterLayer *r ) const;
/** Creates a line layer (including renderer) from contour symboliser
\returns the layer or 0 if no layer could be created*/
QgsVectorLayer *contourLayerFromRaster( const QDomElement &userStyleElem, QgsRasterLayer *rasterLayer ) const;
//! Returns the <UserLayer> dom node or a null node in case of failure
QDomElement findUserLayerElement( const QString &layerName ) const;
/** Creates a vector layer from a <UserLayer> tag.
\param layerName the WMS layer name. This is only necessary for the fallback SLD parser
\returns 0 in case of error.
Delegates the work to specific methods for <SendedVDS>, <HostedVDS> or <RemoteOWS>*/
QgsMapLayer *mapLayerFromUserLayer( const QDomElement &userLayerElem, const QString &layerName, bool allowCaching = true ) const;
//! Reads attributes "epsg" or "proj" from layer element and sets specified CRS if present
void setCrsForLayer( const QDomElement &layerElem, QgsMapLayer *ml ) const;
bool useLayerIds() const override { return false; }
};
#endif // QGSSLDCONFIGPARSER_H

View File

@ -1,598 +0,0 @@
/***************************************************************************
qgswmsconfigparser.cpp
----------------------
begin : March 25, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 "qgis_server.h"
#include "qgswmsconfigparser.h"
#include "qgsmaplayer.h"
#include "qgspallabeling.h"
#include "qgsproject.h"
#include "qgsmapserviceexception.h"
#include "qgscomposerlabel.h"
#include "qgscomposerlegend.h"
#include "qgscomposermap.h"
#include "qgscomposermapgrid.h"
#include "qgscomposerhtml.h"
#include "qgscomposerframe.h"
#include "qgscomposition.h"
#include "qgsmapsettings.h"
#include "qgslayertreegroup.h"
#include "qgslayertreelayer.h"
#include "qgslayertree.h"
#include "qgsrenderer.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerlabeling.h"
QgsWmsConfigParser::QgsWmsConfigParser()
{
}
QgsComposition *QgsWmsConfigParser::createPrintComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, const QMap< QString, QString > &parameterMap, QStringList &highlightLayers ) const
{
QList<QgsComposerMap *> composerMaps;
QList<QgsComposerLegend *> composerLegends;
QList<QgsComposerLabel *> composerLabels;
QList<const QgsComposerHtml *> composerHtmls;
QgsComposition *c = initComposition( composerTemplate, mapSettings, composerMaps, composerLegends, composerLabels, composerHtmls );
if ( !c )
{
return nullptr;
}
QString dpi = parameterMap.value( QStringLiteral( "DPI" ) );
if ( !dpi.isEmpty() )
{
c->setPrintResolution( dpi.toInt() );
}
//replace composer map parameters
Q_FOREACH ( QgsComposerMap *currentMap, composerMaps )
{
if ( !currentMap )
{
continue;
}
QString mapId = "MAP" + QString::number( currentMap->id() );
QString extent = parameterMap.value( mapId + ":EXTENT" );
if ( extent.isEmpty() ) //map extent is mandatory
{
//remove map from composition if not referenced by the request
c->removeItem( currentMap );
delete currentMap;
continue;
}
// Change CRS of map set to "project CRS" to match requested CRS
// (if map has a valid preset crs then we keep this crs and don't use the
// requested crs for this map item)
if ( mapSettings.destinationCrs().isValid() && !currentMap->presetCrs().isValid() )
currentMap->setCrs( mapSettings.destinationCrs() );
QStringList coordList = extent.split( QStringLiteral( "," ) );
if ( coordList.size() < 4 )
{
c->removeItem( currentMap );
delete currentMap;
continue; //need at least four coordinates
}
bool xMinOk, yMinOk, xMaxOk, yMaxOk;
double xmin = coordList.at( 0 ).toDouble( &xMinOk );
double ymin = coordList.at( 1 ).toDouble( &yMinOk );
double xmax = coordList.at( 2 ).toDouble( &xMaxOk );
double ymax = coordList.at( 3 ).toDouble( &yMaxOk );
if ( !xMinOk || !yMinOk || !xMaxOk || !yMaxOk )
{
c->removeItem( currentMap );
delete currentMap;
continue;
}
QgsRectangle r( xmin, ymin, xmax, ymax );
//Change x- and y- of extent for WMS 1.3.0 if axis inverted
QString version = parameterMap.value( QStringLiteral( "VERSION" ) );
if ( version == QLatin1String( "1.3.0" ) && mapSettings.destinationCrs().hasAxisInverted() )
{
r.invert();
}
currentMap->setNewExtent( r );
//scale
QString scaleString = parameterMap.value( mapId + ":SCALE" );
if ( !scaleString.isEmpty() )
{
bool scaleOk;
double scale = scaleString.toDouble( &scaleOk );
if ( scaleOk )
{
currentMap->setNewScale( scale );
}
}
//rotation
QString rotationString = parameterMap.value( mapId + ":ROTATION" );
if ( !rotationString.isEmpty() )
{
bool rotationOk;
double rotation = rotationString.toDouble( &rotationOk );
if ( rotationOk )
{
currentMap->setMapRotation( rotation );
}
}
//layers / styles
QStringList layerSet;
if ( currentMap->keepLayerSet() )
{
Q_FOREACH ( QgsMapLayer *layer, currentMap->layers() )
layerSet << layer->id();
}
else
{
QString layers = parameterMap.value( mapId + ":LAYERS" );
QString styles = parameterMap.value( mapId + ":STYLES" );
if ( layers.isEmpty() )
{
layers = parameterMap.value( QStringLiteral( "LAYERS" ) );
styles = parameterMap.value( QStringLiteral( "STYLES" ) );
}
QStringList wmsLayerList = layers.split( QStringLiteral( "," ) );
QStringList wmsStyleList;
if ( !styles.isEmpty() )
{
wmsStyleList = styles.split( QStringLiteral( "," ) );
}
for ( int i = 0; i < wmsLayerList.size(); ++i )
{
QString styleName;
if ( wmsStyleList.size() > i )
{
styleName = wmsStyleList.at( i );
}
foreach ( QgsMapLayer *layer, mapLayerFromStyle( wmsLayerList.at( i ), styleName ) )
{
if ( layer )
{
layerSet.prepend( layer->id() );
}
}
}
}
//save layer list prior to adding highlight layers
QStringList bkLayerSet = layerSet;
//add highlight layers
highlightLayers.append( addHighlightLayers( parameterMap, layerSet, mapId + ":" ) );
QList<QgsMapLayer *> layers;
Q_FOREACH ( const QString &layerId, layerSet )
{
if ( QgsMapLayer *layer = QgsProject::instance()->mapLayer( layerId ) )
layers << layer;
}
currentMap->setLayers( layers );
currentMap->setKeepLayerSet( true );
//remove highlight layers from the composer legends
QList< QgsComposerLegend * >::iterator legendIt = composerLegends.begin();
for ( ; legendIt != composerLegends.end(); ++legendIt )
{
if ( ( *legendIt )->autoUpdateModel() )
{
setLayerIdsToLegendModel( ( *legendIt )->model(), bkLayerSet, currentMap->scale() );
}
}
//grid space x / y
currentMap->grid()->setIntervalX( parameterMap.value( mapId + ":GRID_INTERVAL_X" ).toDouble() );
currentMap->grid()->setIntervalY( parameterMap.value( mapId + ":GRID_INTERVAL_Y" ).toDouble() );
}
//update legend
// if it has an auto-update model
Q_FOREACH ( QgsComposerLegend *currentLegend, composerLegends )
{
if ( !currentLegend )
{
continue;
}
if ( currentLegend->autoUpdateModel() || currentLegend->legendFilterByMapEnabled() )
{
// the legend has an auto-update model or
// has to be filter by map
// we will update it with map's layers
const QgsComposerMap *map = currentLegend->composerMap();
if ( !map )
{
continue;
}
// get model and layer tree root of the legend
QgsLegendModel *model = currentLegend->model();
QStringList layerSet;
Q_FOREACH ( QgsMapLayer *layer, map->layers() )
layerSet << layer->id();
setLayerIdsToLegendModel( model, layerSet, map->scale() );
}
}
//replace label text
Q_FOREACH ( QgsComposerLabel *currentLabel, composerLabels )
{
QString title = parameterMap.value( currentLabel->id().toUpper() );
if ( title.isEmpty() )
{
//remove exported labels referenced in the request
//but with empty string
if ( parameterMap.contains( currentLabel->id().toUpper() ) )
{
c->removeItem( currentLabel );
delete currentLabel;
}
continue;
}
currentLabel->setText( title );
}
//replace html url
Q_FOREACH ( const QgsComposerHtml *currentHtml, composerHtmls )
{
QgsComposerHtml *html = const_cast<QgsComposerHtml *>( currentHtml );
QgsComposerFrame *htmlFrame = html->frame( 0 );
QString htmlId = htmlFrame->id();
QString url = parameterMap.value( htmlId.toUpper() );
if ( url.isEmpty() )
{
//remove exported Htmls referenced in the request
//but with empty string
if ( parameterMap.contains( htmlId.toUpper() ) )
{
c->removeMultiFrame( html );
delete currentHtml;
}
else
{
html->update();
}
continue;
}
QUrl newUrl( url );
html->setUrl( newUrl );
html->update();
}
return c;
}
QStringList QgsWmsConfigParser::addHighlightLayers( const QMap<QString, QString> &parameterMap, QStringList &layerSet, const QString &parameterPrefix )
{
QStringList highlightLayers, geomSplit, symbolSplit, labelSplit, labelFontSplit, labelSizeSplit,
labelWeightSplit, labelColorSplit, labelBufferColorSplit, labelBufferSizeSplit;
highlightParameters( parameterMap, parameterPrefix, geomSplit, symbolSplit, labelSplit, labelFontSplit, labelSizeSplit, labelWeightSplit,
labelColorSplit, labelBufferColorSplit, labelBufferSizeSplit );
if ( geomSplit.isEmpty() || symbolSplit.isEmpty() )
{
return highlightLayers;
}
QString crsString = parameterMap.contains( QStringLiteral( "CRS" ) ) ? parameterMap.value( QStringLiteral( "CRS" ) ) : parameterMap.value( QStringLiteral( "SRS" ) );
int nHighlights = std::min( geomSplit.size(), symbolSplit.size() );
for ( int i = 0; i < nHighlights; ++i )
{
//create geometry
QgsGeometry geom( QgsGeometry::fromWkt( geomSplit.at( i ) ) );
if ( !geom )
{
continue;
}
//create renderer from sld
QDomDocument sldDoc;
if ( !sldDoc.setContent( symbolSplit[i], true ) )
{
continue;
}
QString errorMsg;
std::unique_ptr<QgsFeatureRenderer> renderer( QgsFeatureRenderer::loadSld( sldDoc.documentElement(), geom.type(), errorMsg ) );
if ( !renderer )
{
continue;
}
//add label settings
QString labelString;
if ( i < labelSplit.size() )
{
labelString = labelSplit.at( i );
}
std::unique_ptr<QgsVectorLayer> layer( createHighlightLayer( i, crsString, geom, labelString, labelSizeSplit, labelColorSplit, labelWeightSplit, labelFontSplit,
labelBufferSizeSplit, labelBufferColorSplit ) );
if ( !layer )
{
continue;
}
layer->setRenderer( renderer.release() );
layerSet.prepend( layer->id() );
highlightLayers.append( layer->id() );
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << layer.release() );
}
return highlightLayers;
}
QgsVectorLayer *QgsWmsConfigParser::createHighlightLayer( int i, const QString &crsString, const QgsGeometry &geom, const QString &labelString, const QStringList &labelSizeSplit, const QStringList &labelColorSplit,
const QStringList &labelWeightSplit, const QStringList &labelFontSplit, const QStringList &labelBufferSizeSplit,
const QStringList &labelBufferColorSplit )
{
if ( !geom )
{
return 0;
}
QgsWkbTypes::GeometryType geomType = geom.type();
QString typeName = QString( QgsWkbTypes::displayString( geom.wkbType() ) ).replace( QLatin1String( "WKB" ), QLatin1String( "" ) );
QString url = typeName + "?crs=" + crsString;
if ( !labelString.isEmpty() )
{
url += QLatin1String( "&field=label:string" );
if ( geomType == QgsWkbTypes::PolygonGeometry )
{
url += QLatin1String( "&field=x:double&field=y:double&field=hali:string&field=vali:string" );
}
}
QgsVectorLayer *layer = new QgsVectorLayer( url, "highlight_" + QString::number( i ), QStringLiteral( "memory" ) );
if ( !layer->isValid() )
{
delete layer;
return 0;
}
QgsPalLayerSettings settings;
settings.fieldName = "label";
//give highest priority to highlight layers and make sure the labels are always drawn
settings.priority = 10;
settings.displayAll = true;
QgsTextFormat textFormat;
QgsTextBufferSettings bufferSettings;
QString fontFamily;
int fontSize = 12;
int fontWeight = -1;
QgsPropertyCollection &ddp = settings.dataDefinedProperties();
QgsFeature fet( layer->pendingFields() );
if ( !labelString.isEmpty() )
{
fet.setAttribute( 0, labelString );
if ( geomType == QgsWkbTypes::PolygonGeometry )
{
QgsGeometry point = geom.pointOnSurface();
if ( point )
{
QgsPointXY pt = point.asPoint();
fet.setAttribute( 1, pt.x() );
fet.setAttribute( 2, pt.y() );
fet.setAttribute( 3, "Center" );
fet.setAttribute( 4, "Half" );
}
}
//fontsize?
if ( i < labelSizeSplit.size() )
{
fontSize = labelSizeSplit.at( i ).toInt();
}
//font color
if ( i < labelColorSplit.size() )
{
QColor c( labelColorSplit.at( i ) );
textFormat.setColor( c );
}
//font weight
if ( i < labelWeightSplit.size() )
{
fontWeight = labelWeightSplit.at( i ).toInt();
}
//font family list
if ( i < labelFontSplit.size() )
{
fontFamily = labelFontSplit.at( i );
}
//buffer
if ( i < labelBufferSizeSplit.size() )
{
bufferSettings.setSize( labelBufferSizeSplit.at( i ).toInt() );
}
//buffer color
if ( i < labelBufferColorSplit.size() )
{
QColor c( labelBufferColorSplit.at( i ) );
bufferSettings.setColor( c );
}
//placement
switch ( geomType )
{
case QgsWkbTypes::PointGeometry:
settings.placement = QgsPalLayerSettings::AroundPoint;
settings.dist = 2;
settings.placementFlags = 0;
break;
case QgsWkbTypes::PolygonGeometry:
settings.placement = QgsPalLayerSettings::AroundPoint;
ddp.setProperty( QgsPalLayerSettings::PositionX, QgsProperty::fromField( "x" ) );
ddp.setProperty( QgsPalLayerSettings::PositionY, QgsProperty::fromField( "y" ) );
ddp.setProperty( QgsPalLayerSettings::Hali, QgsProperty::fromField( "hali" ) );
ddp.setProperty( QgsPalLayerSettings::Vali, QgsProperty::fromValue( "vali" ) );
break;
default:
settings.placement = QgsPalLayerSettings::Line; //parallel placement for line
settings.dist = 2;
settings.placementFlags = 10;
}
}
textFormat.setFont( QFont( fontFamily, fontSize, fontWeight ) );
textFormat.setSize( fontSize );
textFormat.setBuffer( bufferSettings );
settings.setFormat( textFormat );
layer->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) );
fet.setGeometry( geom );
layer->dataProvider()->addFeatures( QgsFeatureList() << fet );
return layer;
}
void QgsWmsConfigParser::highlightParameters( const QMap<QString, QString> &parameterMap, const QString &parameterPrefix, QStringList &geom, QStringList &symbol,
QStringList &label, QStringList &labelFont, QStringList &labelSize, QStringList &labelWeight, QStringList &labelColor,
QStringList &labelBufferColor, QStringList &labelBufferSize )
{
QString geomParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_GEOM" );
QString symbolParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_SYMBOL" );
if ( geomParam.isEmpty() || symbolParam.isEmpty() )
{
return;
}
QString labelParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELSTRING" );
QString labelFontParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELFONT" );
QString labelSizeParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELSIZE" );
QString labelWeightParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELWEIGHT" );
QString labelColorParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELCOLOR" );
QString labelBufferColorParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELBUFFERCOLOR" );
QString labelBufferSizeParam = parameterMap.value( parameterPrefix + "HIGHLIGHT_LABELBUFFERSIZE" );
geom = geomParam.split( QStringLiteral( ";" ) );
symbol = symbolParam.split( QStringLiteral( ";" ) );
label.clear();
labelFont.clear();
labelSize.clear();
labelWeight.clear();
labelColor.clear();
labelBufferColor.clear();
labelBufferSize.clear();
if ( !labelParam.isEmpty() )
{
label = labelParam.split( QStringLiteral( ";" ) );
}
if ( !labelFontParam.isEmpty() )
{
labelFont = labelFontParam.split( QStringLiteral( ";" ) );
}
if ( !labelSizeParam.isEmpty() )
{
labelSize = labelSizeParam.split( QStringLiteral( ";" ) );
}
if ( !labelWeightParam.isEmpty() )
{
labelWeight = labelWeightParam.split( QStringLiteral( ";" ) );
}
if ( !labelColorParam.isEmpty() )
{
labelColor = labelColorParam.split( QStringLiteral( ";" ) );
}
if ( !labelBufferColorParam.isEmpty() )
{
labelBufferColor = labelBufferColorParam.split( QStringLiteral( ";" ) );
}
if ( !labelBufferSizeParam.isEmpty() )
{
labelBufferSize = labelBufferSizeParam.split( QStringLiteral( ";" ) );
}
}
void QgsWmsConfigParser::removeHighlightLayers( const QStringList &layerIds )
{
QStringList::const_iterator idIt = layerIds.constBegin();
for ( ; idIt != layerIds.constEnd(); ++idIt )
{
QgsProject::instance()->removeMapLayers( QStringList() << *idIt );
}
}
void QgsWmsConfigParser::setLayerIdsToLegendModel( QgsLegendModel *model, const QStringList &layerSet, double scale )
{
if ( !model )
{
return;
}
// get model and layer tree root of the legend
QgsLayerTree *root = model->rootGroup();
// get layerIds find in the layer tree root
QStringList layerIds = root->findLayerIds();
// Q_FOREACH layer find in the layer tree
// remove it if the layer id is not in map layerIds
Q_FOREACH ( const QString &layerId, layerIds )
{
QgsLayerTreeLayer *nodeLayer = root->findLayer( layerId );
if ( !nodeLayer )
{
continue;
}
if ( !layerSet.contains( layerId ) )
{
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
else
{
QgsMapLayer *layer = nodeLayer->layer();
if ( !layer->isInScaleRange( scale ) )
{
qobject_cast<QgsLayerTreeGroup *>( nodeLayer->parent() )->removeChildNode( nodeLayer );
}
}
}
root->removeChildrenGroupWithoutLayers();
}

View File

@ -1,169 +0,0 @@
/***************************************************************************
qgswmsconfigparser.h
--------------------
begin : March 25, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 QGSWMSCONFIGPARSER_H
#define QGSWMSCONFIGPARSER_H
#include "qgsunittypes.h"
#include "qgsdatumtransformstore.h"
#include "qgis_server.h"
#include "qgis_sip.h"
class QPainter;
class QDomDocument;
class QgsComposerHtml;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerMap;
class QgsComposition;
class QgsGeometry;
class QgsMapLayer;
class QgsLegendModel;
class QgsMapSettings;
class QgsVectorLayer;
class SERVER_EXPORT QgsWmsConfigParser
{
public:
QgsWmsConfigParser() SIP_SKIP;
virtual ~QgsWmsConfigParser() = default SIP_SKIP;
/** Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
\param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
virtual void layersAndStylesCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &version, const QString &serviceUrl, bool fullProjectSettings = false ) const = 0;
//! Returns one or possibly several maplayers for a given layer name and style. If no layers/style are found, an empty list is returned
virtual QList<QgsMapLayer *> mapLayerFromStyle( const QString &lName, const QString &styleName, bool useCache = true ) const = 0;
//! Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success
virtual int layersAndStyles( QStringList &layers, QStringList &styles ) const = 0;
//! Returns the xml fragment of a style
virtual QDomDocument getStyle( const QString &styleName, const QString &layerName ) const = 0;
//! Returns the xml fragment of layers styles
virtual QDomDocument getStyles( QStringList &layerList ) const = 0;
//! Returns the xml fragment of layers styles description
virtual QDomDocument describeLayer( QStringList &layerList, const QString &wfsHrefString, const QString &wcsHrefString ) const = 0;
//! Returns if output are MM or PIXEL
virtual QgsUnitTypes::RenderUnit outputUnits() const = 0;
//! Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file
virtual QStringList identifyDisabledLayers() const = 0;
//! True if the feature info response should contain the wkt geometry for vector features
virtual bool featureInfoWithWktGeometry() const = 0;
//! True if the feature info wkt geometry is delivered with segmentized curve types
virtual bool segmentizeFeatureInfoWktGeometry() const = 0;
//! Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias
virtual QHash<QString, QString> featureInfoLayerAliasMap() const = 0;
virtual QString featureInfoDocumentElement( const QString &defaultValue ) const = 0;
virtual QString featureInfoDocumentElementNS() const = 0;
virtual QString featureInfoSchema() const = 0;
//! Return feature info in format SIA2045?
virtual bool featureInfoFormatSIA2045() const = 0;
//! Draw text annotation items from the QGIS projectfile
virtual void drawOverlays( QPainter *p, int dpi, int width, int height ) const = 0;
//! Load PAL engine settings into global project instance
virtual void loadLabelSettings() const = 0;
virtual QStringList wfsLayerNames() const = 0;
virtual void owsGeneralAndResourceList( QDomElement &parentElement, QDomDocument &doc, const QString &strHref ) const = 0;
//legend
virtual double legendBoxSpace() const = 0;
virtual double legendLayerSpace() const = 0;
virtual double legendLayerTitleSpace() const = 0;
virtual double legendSymbolSpace() const = 0;
virtual double legendIconLabelSpace() const = 0;
virtual double legendSymbolWidth() const = 0;
virtual double legendSymbolHeight() const = 0;
virtual QFont legendLayerFont() const = 0;
virtual QFont legendItemFont() const = 0;
virtual double imageQuality() const = 0;
// WMS GetFeatureInfo precision (decimal places)
virtual int wmsPrecision() const = 0;
// WMS inspire capabilities
virtual bool wmsInspireActivated() const = 0;
//! Adds inspire capabilities to xml document. ParentElem usually is the <Capabilities> element
virtual void inspireCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
//printing
QgsComposition *createPrintComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, const QMap< QString, QString > &parameterMap, QStringList &highlightLayers ) const;
//! Creates a composition from the project file (probably delegated to the fallback parser)
virtual QgsComposition *initComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, QList< QgsComposerMap *> &mapList, QList< QgsComposerLegend * > &legendList, QList< QgsComposerLabel * > &labelList, QList<const QgsComposerHtml *> &htmlFrameList ) const = 0 SIP_SKIP;
//! Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element
virtual void printCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
virtual void setScaleDenominator( double denom ) = 0;
virtual void addExternalGMLData( const QString &layerName, QDomDocument *gmlDoc ) = 0;
virtual QList< QPair< QString, QgsDatumTransformStore::Entry > > layerCoordinateTransforms() const = 0 SIP_SKIP;
virtual int nLayers() const = 0;
virtual void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc ) const = 0;
virtual bool useLayerIds() const = 0;
virtual bool allowRequestDefinedDatasources() const { return false; }
//! Adds highlight layers to the layer registry and to the layer set. Returns the ids of the newly created layers (for later removal)
static QStringList addHighlightLayers( const QMap<QString, QString> &parameterMap, QStringList &layerSet, const QString &parameterPrefix = QString() );
static void removeHighlightLayers( const QStringList &layerIds );
#if 0
//! List of GML datasets passed outside SLD (e.g. in a SOAP request). Key of the map is the layer name
QMap<QString, QDomDocument *> mExternalGMLDatasets;
#endif //0
private:
#ifdef SIP_RUN
QgsWmsConfigParser();
virtual ~QgsWmsConfigParser();
#endif
//helper methods for 'addHighlightLayers'
static void highlightParameters( const QMap<QString, QString> &parameterMap, const QString &parameterPrefix, QStringList &geom, QStringList &symbol, QStringList &label,
QStringList &labelFont, QStringList &labelSize, QStringList &labelWeight, QStringList &labelColor,
QStringList &labelBufferColor, QStringList &labelBufferSize );
static QgsVectorLayer *createHighlightLayer( int i, const QString &crsString, const QgsGeometry &geom, const QString &labelString, const QStringList &labelSizeSplit, const QStringList &labelColorSplit,
const QStringList &labelWeightSplit, const QStringList &labelFontSplit, const QStringList &labelBufferSizeSplit,
const QStringList &labelBufferColorSplit );
static void setLayerIdsToLegendModel( QgsLegendModel *model, const QStringList &layerIds, double scale );
};
#endif // QGSWMSCONFIGPARSER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,180 +0,0 @@
/***************************************************************************
qgswmsprojectparser.h
---------------------
begin : March 25, 2014
copyright : (C) 2014 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 QGSWMSPROJECTPARSER_H
#define QGSWMSPROJECTPARSER_H
#include "qgswmsconfigparser.h"
#include "qgsserverprojectparser.h"
#include "qgis_server.h"
class QgsAccessControl;
class QTextDocument;
class QSvgRenderer;
class QgsMapSettings;
class QgsLayerTree;
class SERVER_EXPORT QgsWmsProjectParser : public QgsWmsConfigParser
{
public:
QgsWmsProjectParser( const QString &filePath, const QgsAccessControl *accessControl );
virtual ~QgsWmsProjectParser();
/** Adds layer and style specific capabilities elements to the parent node. This includes the individual layers and styles, their description, native CRS, bounding boxes, etc.
\param fullProjectInformation If true: add extended project information (does not validate against WMS schema)*/
void layersAndStylesCapabilities( QDomElement &parentElement, QDomDocument &doc, const QString &version, const QString &serviceUrl, bool fullProjectSettings = false ) const override;
QList<QgsMapLayer *> mapLayerFromStyle( const QString &lName, const QString &styleName, bool useCache = true ) const override;
QStringList wfsLayerNames() const override;
void owsGeneralAndResourceList( QDomElement &parentElement, QDomDocument &doc, const QString &strHref ) const override;
//legend
double legendBoxSpace() const override;
double legendLayerSpace() const override;
double legendLayerTitleSpace() const override;
double legendSymbolSpace() const override;
double legendIconLabelSpace() const override;
double legendSymbolWidth() const override;
double legendSymbolHeight() const override;
QFont legendLayerFont() const override;
QFont legendItemFont() const override;
double imageQuality() const override;
int wmsPrecision() const override;
// WMS inspire capabilities
bool wmsInspireActivated() const override;
void inspireCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
//printing
QgsComposition *initComposition( const QString &composerTemplate, const QgsMapSettings &mapSettings, QList< QgsComposerMap * > &mapList, QList< QgsComposerLegend * > &legendList, QList< QgsComposerLabel * > &labelList, QList<const QgsComposerHtml *> &htmlFrameList ) const override SIP_SKIP;
void printCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
//todo: fixme
void setScaleDenominator( double ) override {}
void addExternalGMLData( const QString &, QDomDocument * ) override {}
QList< QPair< QString, QgsDatumTransformStore::Entry > > layerCoordinateTransforms() const override SIP_SKIP;
//! Fills a layer and a style list. The two list have the same number of entries and the style and the layer at a position belong together (similar to the HTTP parameters 'Layers' and 'Styles'. Returns 0 in case of success
int layersAndStyles( QStringList &layers, QStringList &styles ) const override;
//! Returns the xml fragment of a style
QDomDocument getStyle( const QString &styleName, const QString &layerName ) const override;
//! Returns the xml fragment of layers styles
QDomDocument getStyles( QStringList &layerList ) const override;
//! Returns the xml fragment of layers styles description
QDomDocument describeLayer( QStringList &layerList, const QString &wfsHrefString, const QString &wcsHrefString ) const override;
//! Returns if output are MM or PIXEL
QgsUnitTypes::RenderUnit outputUnits() const override;
//! True if the feature info response should contain the wkt geometry for vector features
bool featureInfoWithWktGeometry() const override;
//! True if the feature info wkt geometry is delivered with segmentized curve types
bool segmentizeFeatureInfoWktGeometry() const override;
//! Returns map with layer aliases for GetFeatureInfo (or 0 pointer if not supported). Key: layer name, Value: layer alias
QHash<QString, QString> featureInfoLayerAliasMap() const override;
QString featureInfoDocumentElement( const QString &defaultValue ) const override;
QString featureInfoDocumentElementNS() const override;
QString featureInfoSchema() const override;
//! Return feature info in format SIA2045?
bool featureInfoFormatSIA2045() const override;
//! Draw text annotation items from the QGIS projectfile
void drawOverlays( QPainter *p, int dpi, int width, int height ) const override;
//! Load PAL engine settings into global project instance
void loadLabelSettings() const override;
int nLayers() const override;
void serviceCapabilities( QDomElement &parentElement, QDomDocument &doc ) const override;
bool useLayerIds() const override { return mProjectParser->useLayerIds(); }
bool allowRequestDefinedDatasources() const override;
private:
QgsServerProjectParser *mProjectParser = nullptr;
const QgsAccessControl *mAccessControl = nullptr;
mutable QFont mLegendLayerFont;
mutable QFont mLegendItemFont;
//! Watermark text items
QList< QPair< QTextDocument *, QDomElement > > mTextAnnotationItems;
//! Watermark items (content cached in QgsSVGCache)
QList< QPair< QSvgRenderer *, QDomElement > > mSvgAnnotationElems;
//! Returns an ID-list of layers which are not queryable (comes from <properties> -> <Identify> -> <disabledLayers in the project file
virtual QStringList identifyDisabledLayers() const override;
//! Reads layer drawing order from the legend section of the project file and appends it to the parent elemen (usually the <Capability> element)
void addDrawingOrder( QDomElement &parentElem, QDomDocument &doc, const QHash<QString, QString> &idNameMap, const QStringList &layerIDList ) const;
void addLayerStyles( QgsMapLayer *currentLayer, QDomDocument &doc, QDomElement &layerElem, const QString &version, const QString &serviceUrl ) const;
void addLayers( QDomDocument &doc,
QDomElement &parentLayer,
const QDomElement &legendElem,
QgsLayerTreeGroup *layerTreeGroup,
const QMap<QString, QgsMapLayer *> &layerMap,
const QStringList &nonIdentifiableLayers,
const QString &version, //1.1.1 or 1.3.0
const QString &serviceUrl,
bool fullProjectSettings,
QHash<QString, QString> &idNameMap,
QStringList &layerIDList ) const;
void addOWSLayerStyles( QgsMapLayer *currentLayer, QDomDocument &doc, QDomElement &layerElem ) const;
void addOWSLayers( QDomDocument &doc, QDomElement &parentElem, const QDomElement &legendElem,
const QMap<QString, QgsMapLayer *> &layerMap, const QStringList &nonIdentifiableLayers,
const QString &strHref, QgsRectangle &combinedBBox, const QString &strGroup ) const;
//! Adds layers from a legend group to list (could be embedded or a normal group)
void addLayersFromGroup( const QDomElement &legendGroupElem, QMap< int, QgsMapLayer *> &layers, bool useCache = true ) const;
QDomElement composerByName( const QString &composerName ) const;
QgsLayerTree *projectLayerTreeGroup() const;
static bool annotationPosition( const QDomElement &elem, double scaleFactor, double &xPos, double &yPos );
static void drawAnnotationRectangle( QPainter *p, const QDomElement &elem, double scaleFactor, double xPos, double yPos, int itemWidth, int itemHeight );
void createTextAnnotationItems();
void createSvgAnnotationItems();
void cleanupSvgAnnotationItems();
void cleanupTextAnnotationItems();
QString getCapaServiceUrl( QDomDocument &doc ) const;
void readLabelSettings( int &searchMethod, int &nCandPoint, int &nCandLine, int &nCandPoly, bool &showingCandidates, bool &drawRectOnly, bool &showingShadowRects, bool &showingAllLabels, bool &showingPartialsLabels, bool &drawOutlineLabels ) const;
};
#endif // QGSWMSPROJECTPARSER_H

View File

@ -46,7 +46,6 @@
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgssldconfigparser.h"
#include "qgssymbol.h"
#include "qgsrenderer.h"
#include "qgspaintenginehack.h"

View File

@ -20,7 +20,6 @@
#ifndef QGSWMSRENDERER_H
#define QGSWMSRENDERER_H
#include "qgswmsconfigparser.h"
#include "qgsserversettings.h"
#include "qgswmsparameters.h"
#include <QDomDocument>

View File

@ -24,7 +24,6 @@
#define QGSWMSUTILS_H
#include "qgsmodule.h"
#include "qgswmsconfigparser.h"
#include "qgswmsserviceexception.h"
class QgsRectangle;