QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsserverapicontext.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsserverapicontext.cpp - QgsServerApiContext
3
4 ---------------------
5 begin : 13.5.2019
6 copyright : (C) 2019 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#include "qgsserverapicontext.h"
17
18#include "qgsserverrequest.h"
19#include "qgsserverresponse.h"
20#include "qgsproject.h"
21#include "qgsserverinterface.h"
22
23QgsServerApiContext::QgsServerApiContext( const QString &apiRootPath, const QgsServerRequest *request, QgsServerResponse *response, const QgsProject *project, QgsServerInterface *serverInterface )
24 : mApiRootPath( apiRootPath ), mRequest( request ), mResponse( response ), mProject( project ), mServerInterface( serverInterface )
25{
26}
27
29{
30 return mRequest;
31}
32
33
35{
36 return mResponse;
37}
38
39
41{
42 return mProject;
43}
44
46{
47 mProject = project;
48}
49
51{
52 return mServerInterface;
53}
54
56{
57 QString path { mRequest->url().path() };
58 const auto idx { path.indexOf( mApiRootPath ) };
59 if ( idx != -1 )
60 {
61 path.truncate( idx + mApiRootPath.length() );
62 return path;
63 }
64 else
65 {
66 return QString();
67 }
68}
69
71{
72 return mApiRootPath;
73}
74
76{
77 mRequest = request;
78}
79
81{
82 const QUrl url { request()->url() };
83 const QString urlBasePath { matchedPath() };
84 if ( !urlBasePath.isEmpty() )
85 {
86 return url.path().mid( urlBasePath.length() );
87 }
88 else
89 {
90 return url.path();
91 }
92}
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
const QgsProject * project() const
Returns the (possibly NULL) project.
QgsServerResponse * response() const
Returns the server response object.
QString handlerPath() const
Returns the handler component of the URL path, i.e.
const QgsServerRequest * request() const
Returns the server request object.
void setProject(const QgsProject *project)
Sets the project to project.
void setRequest(const QgsServerRequest *request)
Sets context request to request.
QgsServerInterface * serverInterface() const
Returns the server interface.
QString apiRootPath() const
Returns the API root path.
QgsServerApiContext(const QString &apiRootPath, const QgsServerRequest *request, QgsServerResponse *response, const QgsProject *project, QgsServerInterface *serverInterface)
QgsServerApiContext constructor.
const QString matchedPath() const
Returns the initial part of the incoming request URL path that matches the API root path.
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...