/
qgswmtsparameters.h
328 lines (280 loc) · 8.71 KB
/
qgswmtsparameters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/***************************************************************************
qgswmtsparameters.h
-------------------
begin : Aug 10, 2018
copyright : (C) 2018 by René-Luc Dhont
email : rldhont at 3liz dot 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 QGSWMTSPARAMETERS_H
#define QGSWMTSPARAMETERS_H
#include <QMap>
#include <QObject>
#include <QMetaEnum>
#include "qgswmtsserviceexception.h"
#include "qgsserverrequest.h"
#include "qgsprojectversion.h"
#include "qgsserverparameters.h"
namespace QgsWmts
{
/**
* \ingroup server
* \class QgsWmts::QgsWmsParameterForWmts
* \brief WMS parameter used by WMTS service.
* \since QGIS 3.4
*/
class QgsWmsParameterForWmts : public QgsServerParameterDefinition
{
Q_GADGET
public:
//! Available parameters for translating WMTS requests to WMS requests
enum Name
{
UNKNOWN,
LAYERS,
STYLES,
CRS,
BBOX,
WIDTH,
HEIGHT,
FORMAT,
TRANSPARENT,
DPI,
QUERY_LAYERS,
I,
J,
INFO_FORMAT
};
Q_ENUM( Name )
/**
* Converts a parameter's name into its string representation.
*/
static QString name( const QgsWmsParameterForWmts::Name );
/**
* Converts a string into a parameter's name (UNKNOWN in case of an
* invalid string).
*/
static QgsWmsParameterForWmts::Name name( const QString &name );
};
/**
* \ingroup server
* \class QgsWmts::QgsWmtsParameter
* \brief WMTS parameter received from the client.
* \since QGIS 3.4
*/
class QgsWmtsParameter : public QgsServerParameterDefinition
{
Q_GADGET
public:
//! Available parameters for WMTS requests
enum Name
{
UNKNOWN,
LAYER,
FORMAT,
TILEMATRIXSET,
TILEMATRIX,
TILEROW,
TILECOL,
INFOFORMAT,
I,
J
};
Q_ENUM( Name )
/**
* Constructor for QgsWmtsParameter.
* \param name Name of the WMS parameter
* \param type Type of the parameter
* \param defaultValue Default value of the parameter
*/
QgsWmtsParameter( const QgsWmtsParameter::Name name = QgsWmtsParameter::UNKNOWN,
const QVariant::Type type = QVariant::String,
const QVariant defaultValue = QVariant( "" ) );
/**
* Default destructor for QgsWmtsParameter.
*/
virtual ~QgsWmtsParameter() = default;
/**
* Converts the parameter into an integer.
* \returns An integer
* \throws QgsBadRequestException Invalid parameter exception
*/
int toInt() const;
/**
* Raises an error in case of an invalid conversion.
* \throws QgsBadRequestException Invalid parameter exception
*/
void raiseError() const;
/**
* Converts a parameter's name into its string representation.
*/
static QString name( const QgsWmtsParameter::Name );
/**
* Converts a string into a parameter's name (UNKNOWN in case of an
* invalid string).
*/
static QgsWmtsParameter::Name name( const QString &name );
QgsWmtsParameter::Name mName;
};
/**
* \ingroup server
* \class QgsWmts::QgsWmtsParameters
* \brief Provides an interface to retrieve and manipulate WMTS parameters received from the client.
* \since QGIS 3.4
*/
class QgsWmtsParameters : public QgsServerParameters
{
Q_GADGET
public:
//! Output format for the response
enum Format
{
NONE,
JPG,
PNG,
TEXT,
XML,
HTML,
GML
};
/**
* Constructor for WMTS parameters with specific values.
* \param parameters Map of parameters where keys are parameters' names.
*/
QgsWmtsParameters( const QgsServerParameters ¶meters );
/**
* Constructor for WMTS parameters with default values only.
*/
QgsWmtsParameters();
/**
* Default destructor for QgsWmtsParameters.
*/
virtual ~QgsWmtsParameters() = default;
/**
* Dumps parameters.
*/
void dump() const;
/**
* Returns VERSION parameter if defined or its default value.
* \returns version
*/
QgsProjectVersion versionAsNumber() const;
/**
* Returns LAYER parameter as a string.
* \returns layer parameter as string
*/
QString layer() const;
/**
* Returns FORMAT parameter as a string.
* \returns Format parameter as string
*/
QString formatAsString() const;
/**
* Returns format. If the FORMAT parameter is not used, then the
* default value is NONE.
* \returns format
*/
Format format() const;
/**
* Returns TILEMATRIXSET parameter as a string.
* \returns tileMatrixSet parameter as string
*/
QString tileMatrixSet() const;
/**
* Returns TILEMATRIX parameter as a string.
* \returns tileMatrix parameter as string
*/
QString tileMatrix() const;
/**
* Returns TILEMATRIX parameter as an int or its default value if not
* defined. An exception is raised if TILEMATRIX is defined and cannot be
* converted.
* \returns tileMatrix parameter
* \throws QgsBadRequestException
*/
int tileMatrixAsInt() const;
/**
* Returns TILEROW parameter as a string.
* \returns tileRow parameter as string
*/
QString tileRow() const;
/**
* Returns TILEROW parameter as an int or its default value if not
* defined. An exception is raised if TILEROW is defined and cannot be
* converted.
* \returns tileRow parameter
* \throws QgsBadRequestException
*/
int tileRowAsInt() const;
/**
* Returns TILECOL parameter as a string.
* \returns tileCol parameter as string
*/
QString tileCol() const;
/**
* Returns TILECOL parameter as an int or its default value if not
* defined. An exception is raised if TILECOL is defined and cannot be
* converted.
* \returns tileCol parameter
* \throws QgsBadRequestException
*/
int tileColAsInt() const;
/**
* Returns INFO_FORMAT parameter as a string.
* \returns INFO_FORMAT parameter as string
*/
QString infoFormatAsString() const;
/**
* Returns infoFormat. If the INFO_FORMAT parameter is not used, then the
* default value is text/plain.
* \returns infoFormat
*/
Format infoFormat() const;
/**
* Returns the infoFormat version for GML. If the INFO_FORMAT is not GML,
* then the default value is -1.
* \returns infoFormat version
*/
int infoFormatVersion() const;
/**
* Returns I parameter or an empty string if not defined.
* \returns i parameter
*/
QString i() const;
/**
* Returns I parameter as an int or its default value if not
* defined. An exception is raised if I is defined and cannot be
* converted.
* \returns i parameter
* \throws QgsBadRequestException
*/
int iAsInt() const;
/**
* Returns J parameter or an empty string if not defined.
* \returns j parameter
*/
QString j() const;
/**
* Returns J parameter as an int or its default value if not
* defined. An exception is raised if J is defined and cannot be
* converted.
* \returns j parameter
* \throws QgsBadRequestException
*/
int jAsInt() const;
private:
bool loadParameter( const QString &name, const QString &key ) override;
void save( const QgsWmtsParameter ¶meter );
void log( const QString &msg ) const;
QList<QgsProjectVersion> mVersions;
QMap<QgsWmtsParameter::Name, QgsWmtsParameter> mWmtsParameters;
};
}
#endif