22 #include <QRegularExpression> 34 return QStringLiteral(
"1.3.0" );
48 static QSet<QString> sFilter
50 QStringLiteral(
"REQUEST" ),
51 QStringLiteral(
"VERSION" ),
52 QStringLiteral(
"SERVICE" ),
53 QStringLiteral(
"LAYERS" ),
54 QStringLiteral(
"STYLES" ),
55 QStringLiteral(
"SLD_VERSION" ),
56 QStringLiteral(
"_DC" )
62 for (
auto param : q.queryItems() )
64 if ( sFilter.contains( param.first.toUpper() ) )
65 q.removeAllQueryItems( param.first );
77 if ( format.compare( QLatin1String(
"png" ), Qt::CaseInsensitive ) == 0 ||
78 format.compare( QLatin1String(
"image/png" ), Qt::CaseInsensitive ) == 0 )
82 else if ( format.compare( QLatin1String(
"jpg " ), Qt::CaseInsensitive ) == 0 ||
83 format.compare( QLatin1String(
"image/jpeg" ), Qt::CaseInsensitive ) == 0 )
90 QRegularExpression modeExpr = QRegularExpression( QStringLiteral(
"image/png\\s*;\\s*mode=([^;]+)" ),
91 QRegularExpression::CaseInsensitiveOption );
93 QRegularExpressionMatch match = modeExpr.match( format );
94 QString mode = match.captured( 1 );
95 if ( mode.compare( QLatin1String(
"16bit" ), Qt::CaseInsensitive ) == 0 )
97 if ( mode.compare( QLatin1String(
"8bit" ), Qt::CaseInsensitive ) == 0 )
99 if ( mode.compare( QLatin1String(
"1bit" ), Qt::CaseInsensitive ) == 0 )
109 layersList = parameters.value( QStringLiteral(
"LAYER" ) ).split(
',', QString::SkipEmptyParts );
110 layersList = layersList + parameters.value( QStringLiteral(
"LAYERS" ) ).split(
',', QString::SkipEmptyParts );
111 stylesList = parameters.value( QStringLiteral(
"STYLE" ) ).split(
',', QString::SkipEmptyParts );
112 stylesList = stylesList + parameters.value( QStringLiteral(
"STYLES" ) ).split(
',', QString::SkipEmptyParts );
124 switch ( outputFormat )
128 contentType =
"image/png";
133 QVector<QRgb> colorTable;
135 result = img.convertToFormat( QImage::Format_Indexed8, colorTable,
136 Qt::ColorOnly | Qt::ThresholdDither |
137 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
139 contentType =
"image/png";
143 result = img.convertToFormat( QImage::Format_ARGB4444_Premultiplied );
144 contentType =
"image/png";
148 result = img.convertToFormat( QImage::Format_Mono,
149 Qt::MonoOnly | Qt::ThresholdDither |
150 Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
151 contentType =
"image/png";
156 contentType =
"image/jpeg";
165 if ( outputFormat !=
UNKN )
167 response.
setHeader(
"Content-Type", contentType );
168 if ( saveFormat ==
"JPEG" )
170 result.save( response.
io(), qPrintable( saveFormat ), imageQuality );
174 result.save( response.
io(), qPrintable( saveFormat ) );
180 QString(
"Output format '%1' is not supported in the GetMap request" ).arg( formatStr ) );
186 QStringList lst = bboxStr.split(
',' );
187 if ( lst.count() != 4 )
192 for (
int i = 0; i < 4; i++ )
194 lst[i].replace(
' ',
'+' );
195 d[i] = lst[i].toDouble( &ok );
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
A rectangle specified with double values.
SERVER_EXPORT QString wmsServiceUrl(const QgsProject &project)
Returns the WMS service url defined in a QGIS project.
QUrl originalUrl() const
Returns the request url as seen by the web server, by default this is equal to the url seen by QGIS s...
Exception class for WMS service exceptions.
void writeImage(QgsServerResponse &response, QImage &img, const QString &formatStr, int imageQuality)
Write image response.
QgsRectangle parseBbox(const QString &bboxStr)
Parse bbox parameter.
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).
QString ImplementationVersion()
Returns the highest version supported by this implementation.
Reads and writes project states.
void readLayersAndStyles(const QgsServerRequest::Parameters ¶meters, QStringList &layersList, QStringList &stylesList)
Reads the layers and style lists from the parameters LAYERS and STYLES.
Median cut implementation.
void medianCut(QVector< QRgb > &colorTable, int nColors, const QImage &inputImage)
Median cut implementation used when reducing RGB colors to palletized colors.
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
virtual QIODevice * io()=0
Returns the underlying QIODevice.
QUrl serviceUrl(const QgsServerRequest &request, const QgsProject *project)
Returns WMS service URL.
ImageOutputFormat
Supported image output format.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
ImageOutputFormat parseImageFormat(const QString &format)
Parse image format parameter.
QMap< QString, QString > Parameters