Skip to content

Commit

Permalink
Add a WMS request class
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 9, 2021
1 parent 28a3138 commit 5ba7cfb
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 6 deletions.
8 changes: 5 additions & 3 deletions python/server/auto_generated/qgsserverrequest.sip.in
Expand Up @@ -58,6 +58,8 @@ Constructor
:param headers:
%End

QgsServerRequest( const QgsServerRequest &other );

virtual ~QgsServerRequest();

static QString methodToString( const Method &method );
Expand Down Expand Up @@ -94,7 +96,7 @@ to uppercase
Returns parameters
%End

void setParameter( const QString &key, const QString &value );
virtual void setParameter( const QString &key, const QString &value );
%Docstring
Set a parameter
%End
Expand All @@ -104,7 +106,7 @@ Set a parameter
Gets a parameter value
%End

void removeParameter( const QString &key );
virtual void removeParameter( const QString &key );
%Docstring
Remove a parameter
%End
Expand Down Expand Up @@ -147,7 +149,7 @@ Check for QByteArray.isNull() to check if data
is available.
%End

void setUrl( const QUrl &url );
virtual void setUrl( const QUrl &url );
%Docstring
Set the request url
%End
Expand Down
9 changes: 9 additions & 0 deletions src/server/qgsserverrequest.cpp
Expand Up @@ -34,6 +34,15 @@ QgsServerRequest::QgsServerRequest( const QUrl &url, Method method, const Header
mParams.load( QUrlQuery( url ) );
}

QgsServerRequest::QgsServerRequest( const QgsServerRequest &other )
: mUrl( other.mUrl )
, mOriginalUrl( other.mOriginalUrl )
, mMethod( other.mMethod )
, mHeaders( other.mHeaders )
, mParams( other.mParams )
{
}

QString QgsServerRequest::methodToString( const QgsServerRequest::Method &method )
{
static QMetaEnum metaEnum = QMetaEnum::fromType<QgsServerRequest::Method>();
Expand Down
8 changes: 5 additions & 3 deletions src/server/qgsserverrequest.h
Expand Up @@ -82,6 +82,8 @@ class SERVER_EXPORT QgsServerRequest
*/
QgsServerRequest( const QUrl &url, QgsServerRequest::Method method = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers() );

QgsServerRequest( const QgsServerRequest &other );

//! destructor
virtual ~QgsServerRequest() = default;

Expand Down Expand Up @@ -119,7 +121,7 @@ class SERVER_EXPORT QgsServerRequest
/**
* Set a parameter
*/
void setParameter( const QString &key, const QString &value );
virtual void setParameter( const QString &key, const QString &value );

/**
* Gets a parameter value
Expand All @@ -129,7 +131,7 @@ class SERVER_EXPORT QgsServerRequest
/**
* Remove a parameter
*/
void removeParameter( const QString &key );
virtual void removeParameter( const QString &key );

/**
* Returns the header value
Expand Down Expand Up @@ -167,7 +169,7 @@ class SERVER_EXPORT QgsServerRequest
/**
* Set the request url
*/
void setUrl( const QUrl &url );
virtual void setUrl( const QUrl &url );

/**
* Returns the request url as seen by the web server,
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/CMakeLists.txt
Expand Up @@ -21,6 +21,7 @@ set (WMS_SRCS
qgswmsparameters.cpp
qgswmsrestorer.cpp
qgswmsrendercontext.cpp
qgswmsrequest.cpp
)

set (WMS_HDRS
Expand Down
57 changes: 57 additions & 0 deletions src/server/services/wms/qgswmsrequest.cpp
@@ -0,0 +1,57 @@
/***************************************************************************
qgswmsrequest.cpp
Define request class for getting request contents for WMS service
-------------------
begin : 2021-02-10
copyright : (C) 2021 by Paul Blottiere
email : blottiere.paul@gmail.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 "qgswmsrequest.h"

namespace QgsWms
{
QgsWmsRequest::QgsWmsRequest( const QgsServerRequest &other )
: QgsServerRequest( other )
{
init();
}

const QgsWmsParameters &QgsWmsRequest::wmsParameters() const
{
return mWmsParams;
}

void QgsWmsRequest::setParameter( const QString &key, const QString &value )
{
QgsServerRequest::setParameter( key, value );
init();
}

void QgsWmsRequest::removeParameter( const QString &key )
{
QgsServerRequest::removeParameter( key );
init();
}

void QgsWmsRequest::setUrl( const QUrl &url )
{
QgsServerRequest::setUrl( url );
init();
}

void QgsWmsRequest::init()
{
mWmsParams = QgsWmsParameters( QUrlQuery( url() ) );
}
}
68 changes: 68 additions & 0 deletions src/server/services/wms/qgswmsrequest.h
@@ -0,0 +1,68 @@
/***************************************************************************
qgswmsrequest.h
Define request class for getting request contents for WMS service
-------------------
begin : 2021-02-10
copyright : (C) 2021 by Paul Blottiere
email : blottiere.paul@gmail.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 QGSWMSREQUEST_H
#define QGSWMSREQUEST_H

#include "qgsserverrequest.h"
#include "qgswmsparameters.h"

namespace QgsWms
{

/**
* \ingroup server
* QgsWmsServerRequest
* Class defining request interface passed to WMS service
* QgsService::executeRequest() method.
*
* \since QGIS 3.20
*/

class QgsWmsRequest : public QgsServerRequest
{
Q_GADGET

public:

/**
* Copy onstructor
*/
QgsWmsRequest( const QgsServerRequest &other );

/**
* Destructor.
*/
~QgsWmsRequest() override = default;

const QgsWmsParameters &wmsParameters() const;

void setParameter( const QString &key, const QString &value ) override;

void removeParameter( const QString &key ) override;

void setUrl( const QUrl &url ) override;

private:
void init();

QgsWmsParameters mWmsParams;
};
}

#endif

0 comments on commit 5ba7cfb

Please sign in to comment.