Skip to content

Commit 250c626

Browse files
authoredMar 25, 2019
Merge pull request #9560 from pblottiere/server_dxf_params
[server] Move parsing of DXF parameters in QgsWmsParameters...
2 parents 9327834 + 5704f70 commit 250c626

File tree

10 files changed

+370
-86
lines changed

10 files changed

+370
-86
lines changed
 

‎src/server/qgsserverinterfaceimpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* \brief Interfaces exposed by QGIS Server and made available to plugins.
3333
* \since QGIS 2.8
3434
*/
35-
class QgsServerInterfaceImpl : public QgsServerInterface
35+
class SERVER_EXPORT QgsServerInterfaceImpl : public QgsServerInterface
3636
{
3737
public:
3838

‎src/server/services/wms/qgsdxfwriter.cpp

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,18 @@ email : david dot marteau at 3liz dot com
2121

2222
namespace QgsWms
2323
{
24-
25-
namespace
26-
{
27-
28-
QMap<QString, QString> parseFormatOptions( const QString &optionString )
29-
{
30-
QMap<QString, QString> options;
31-
32-
QStringList optionsList = optionString.split( ';' );
33-
for ( auto optionsIt = optionsList.constBegin(); optionsIt != optionsList.constEnd(); ++optionsIt )
34-
{
35-
int equalIdx = optionsIt->indexOf( ':' );
36-
if ( equalIdx > 0 && equalIdx < ( optionsIt->length() - 1 ) )
37-
{
38-
options.insert( optionsIt->left( equalIdx ).toUpper(),
39-
optionsIt->right( optionsIt->length() - equalIdx - 1 ).toUpper() );
40-
}
41-
}
42-
return options;
43-
}
44-
45-
}
46-
4724
void writeAsDxf( QgsServerInterface *serverIface, const QgsProject *project,
4825
const QString &version, const QgsServerRequest &request,
4926
QgsServerResponse &response )
5027
{
5128
Q_UNUSED( version );
5229

53-
QgsServerRequest::Parameters params = request.parameters();
54-
5530
QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
5631
QgsRenderer renderer( serverIface, project, wmsParameters );
5732

58-
QMap<QString, QString> formatOptionsMap = parseFormatOptions( params.value( QStringLiteral( "FORMAT_OPTIONS" ) ) );
59-
60-
QgsDxfExport dxf = renderer.getDxf( formatOptionsMap );
61-
62-
QString codec = QStringLiteral( "ISO-8859-1" );
63-
QMap<QString, QString>::const_iterator codecIt = formatOptionsMap.find( QStringLiteral( "CODEC" ) );
64-
if ( codecIt != formatOptionsMap.constEnd() )
65-
{
66-
codec = formatOptionsMap.value( QStringLiteral( "CODEC" ) );
67-
}
68-
6933
// Write output
34+
QgsDxfExport dxf = renderer.getDxf();
7035
response.setHeader( "Content-Type", "application/dxf" );
71-
dxf.writeToFile( response.io(), codec );
36+
dxf.writeToFile( response.io(), wmsParameters.dxfCodec() );
7237
}
73-
74-
7538
} // namespace QgsWms

‎src/server/services/wms/qgswmsparameters.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ namespace QgsWms
504504
const QgsWmsParameter pAtlasPk( QgsWmsParameter::ATLAS_PK,
505505
QVariant::StringList );
506506
save( pAtlasPk );
507+
508+
const QgsWmsParameter pFormatOpts( QgsWmsParameter::FORMAT_OPTIONS,
509+
QVariant::String );
510+
save( pFormatOpts );
507511
}
508512

509513
QgsWmsParameters::QgsWmsParameters( const QgsServerParameters &parameters )
@@ -1817,4 +1821,102 @@ namespace QgsWms
18171821
{
18181822
return name.startsWith( EXTERNAL_LAYER_PREFIX );
18191823
}
1824+
1825+
QStringList QgsWmsParameters::dxfLayerAttributes() const
1826+
{
1827+
QStringList attributes;
1828+
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
1829+
1830+
if ( options.contains( DxfFormatOption::LAYERATTRIBUTES ) )
1831+
{
1832+
attributes = options[ DxfFormatOption::LAYERATTRIBUTES ].split( ',' );
1833+
}
1834+
1835+
return attributes;
1836+
}
1837+
1838+
bool QgsWmsParameters::dxfUseLayerTitleAsName() const
1839+
{
1840+
bool use = false;
1841+
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
1842+
1843+
if ( options.contains( DxfFormatOption::USE_TITLE_AS_LAYERNAME ) )
1844+
{
1845+
use = QVariant( options[ DxfFormatOption::USE_TITLE_AS_LAYERNAME ] ).toBool();
1846+
}
1847+
1848+
return use;
1849+
}
1850+
1851+
double QgsWmsParameters::dxfScale() const
1852+
{
1853+
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
1854+
1855+
double scale = -1;
1856+
if ( options.contains( DxfFormatOption::SCALE ) )
1857+
{
1858+
scale = options[ DxfFormatOption::SCALE ].toDouble();
1859+
}
1860+
1861+
return scale;
1862+
}
1863+
1864+
QgsDxfExport::SymbologyExport QgsWmsParameters::dxfMode() const
1865+
{
1866+
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();
1867+
1868+
QgsDxfExport::SymbologyExport symbol = QgsDxfExport::NoSymbology;
1869+
1870+
if ( ! options.contains( DxfFormatOption::MODE ) )
1871+
{
1872+
return symbol;
1873+
}
1874+
1875+
const QString mode = options[ DxfFormatOption::MODE ];
1876+
if ( mode.compare( QLatin1String( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
1877+
{
1878+
symbol = QgsDxfExport::SymbolLayerSymbology;
1879+
}
1880+
else if ( mode.compare( QLatin1String( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
1881+
{
1882+
symbol = QgsDxfExport::FeatureSymbology;
1883+
}
1884+
1885+
return symbol;
1886+
}
1887+
1888+
QString QgsWmsParameters::dxfCodec() const
1889+
{
1890+
QString codec = QStringLiteral( "ISO-8859-1" );
1891+
1892+
if ( dxfFormatOptions().contains( DxfFormatOption::CODEC ) )
1893+
{
1894+
codec = dxfFormatOptions()[ DxfFormatOption::CODEC ];
1895+
}
1896+
1897+
return codec;
1898+
}
1899+
1900+
QMap<QgsWmsParameters::DxfFormatOption, QString> QgsWmsParameters::dxfFormatOptions() const
1901+
{
1902+
QMap<QgsWmsParameters::DxfFormatOption, QString> options;
1903+
1904+
const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameters::DxfFormatOption>() );
1905+
const QStringList opts = mWmsParameters[ QgsWmsParameter::FORMAT_OPTIONS ].toStringList( ';' );
1906+
1907+
for ( auto it = opts.constBegin(); it != opts.constEnd(); ++it )
1908+
{
1909+
const int equalIdx = it->indexOf( ':' );
1910+
if ( equalIdx > 0 && equalIdx < ( it->length() - 1 ) )
1911+
{
1912+
const QString name = it->left( equalIdx ).toUpper();
1913+
const QgsWmsParameters::DxfFormatOption option =
1914+
( QgsWmsParameters::DxfFormatOption ) metaEnum.keyToValue( name.toStdString().c_str() );
1915+
const QString value = it->right( it->length() - equalIdx - 1 );
1916+
options.insert( option, value );
1917+
}
1918+
}
1919+
1920+
return options;
1921+
}
18201922
}

‎src/server/services/wms/qgswmsparameters.h

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsprojectversion.h"
2929
#include "qgsogcutils.h"
3030
#include "qgsserverparameters.h"
31+
#include "qgsdxfexport.h"
3132

3233
namespace QgsWms
3334
{
@@ -174,7 +175,8 @@ namespace QgsWms
174175
WITH_GEOMETRY,
175176
WITH_MAPTIP,
176177
WMTVER,
177-
ATLAS_PK
178+
ATLAS_PK,
179+
FORMAT_OPTIONS
178180
};
179181
Q_ENUM( Name )
180182

@@ -323,6 +325,17 @@ namespace QgsWms
323325
};
324326
Q_ENUM( Format )
325327

328+
//! Options for DXF format
329+
enum DxfFormatOption
330+
{
331+
SCALE,
332+
MODE,
333+
LAYERATTRIBUTES,
334+
USE_TITLE_AS_LAYERNAME,
335+
CODEC
336+
};
337+
Q_ENUM( DxfFormatOption )
338+
326339
/**
327340
* Constructor for WMS parameters with specific values.
328341
* \param parameters Map of parameters where keys are parameters' names.
@@ -1177,6 +1190,42 @@ namespace QgsWms
11771190
*/
11781191
QStringList atlasPk() const;
11791192

1193+
/**
1194+
* Returns a map of DXF options defined within FORMAT_OPTIONS parameter.
1195+
* \since QGIS 3.8
1196+
*/
1197+
QMap<DxfFormatOption, QString> dxfFormatOptions() const;
1198+
1199+
/**
1200+
* Returns the DXF LAYERATTRIBUTES parameter.
1201+
* \since QGIS 3.8
1202+
*/
1203+
QStringList dxfLayerAttributes() const;
1204+
1205+
/**
1206+
* Returns the DXF USE_TITLE_AS_LAYERNAME parameter.
1207+
* \since QGIS 3.8
1208+
*/
1209+
bool dxfUseLayerTitleAsName() const;
1210+
1211+
/**
1212+
* Returns the DXF SCALE parameter.
1213+
* \since QGIS 3.8
1214+
*/
1215+
double dxfScale() const;
1216+
1217+
/**
1218+
* Returns the DXF MODE parameter.
1219+
* \since QGIS 3.8
1220+
*/
1221+
QgsDxfExport::SymbologyExport dxfMode() const;
1222+
1223+
/**
1224+
* Returns the DXF CODEC parameter.
1225+
* \since QGIS 3.8
1226+
*/
1227+
QString dxfCodec() const;
1228+
11801229
private:
11811230
static bool isExternalLayer( const QString &name );
11821231

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ namespace QgsWms
892892
return image.release();
893893
}
894894

895-
QgsDxfExport QgsRenderer::getDxf( const QMap<QString, QString> &options )
895+
QgsDxfExport QgsRenderer::getDxf()
896896
{
897897
QgsDxfExport dxf;
898898

@@ -919,18 +919,11 @@ namespace QgsWms
919919
layers = stylizedLayers( params );
920920
}
921921

922-
// layer attributes options
923-
QStringList layerAttributes;
924-
QMap<QString, QString>::const_iterator layerAttributesIt = options.find( QStringLiteral( "LAYERATTRIBUTES" ) );
925-
if ( layerAttributesIt != options.constEnd() )
926-
{
927-
layerAttributes = options.value( QStringLiteral( "LAYERATTRIBUTES" ) ).split( ',' );
928-
}
929-
930922
// only wfs layers are allowed to be published
931923
QStringList wfsLayerIds = QgsServerProjectUtils::wfsLayerIds( *mProject );
932924

933925
// get dxf layers
926+
const QStringList attributes = mWmsParameters.dxfLayerAttributes();
934927
QList< QgsDxfExport::DxfLayer > dxfLayers;
935928
int layerIdx = -1;
936929
for ( QgsMapLayer *layer : layers )
@@ -962,49 +955,21 @@ namespace QgsWms
962955

963956
// get the layer attribute used in dxf
964957
int layerAttribute = -1;
965-
if ( layerAttributes.size() > layerIdx )
958+
if ( attributes.size() > layerIdx )
966959
{
967-
layerAttribute = vlayer->fields().indexFromName( layerAttributes.at( layerIdx ) );
960+
layerAttribute = vlayer->fields().indexFromName( attributes[ layerIdx ] );
968961
}
969962

970963
dxfLayers.append( QgsDxfExport::DxfLayer( vlayer, layerAttribute ) );
971964
}
972965

973966
// add layers to dxf
974967
dxf.addLayers( dxfLayers );
975-
976-
dxf.setLayerTitleAsName( options.contains( QStringLiteral( "USE_TITLE_AS_LAYERNAME" ) ) );
977-
978-
//MODE
979-
QMap<QString, QString>::const_iterator modeIt = options.find( QStringLiteral( "MODE" ) );
980-
981-
QgsDxfExport::SymbologyExport se;
982-
if ( modeIt == options.constEnd() )
983-
{
984-
se = QgsDxfExport::NoSymbology;
985-
}
986-
else
987-
{
988-
if ( modeIt->compare( QStringLiteral( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
989-
{
990-
se = QgsDxfExport::SymbolLayerSymbology;
991-
}
992-
else if ( modeIt->compare( QStringLiteral( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
993-
{
994-
se = QgsDxfExport::FeatureSymbology;
995-
}
996-
else
997-
{
998-
se = QgsDxfExport::NoSymbology;
999-
}
1000-
}
1001-
dxf.setSymbologyExport( se );
1002-
1003-
//SCALE
1004-
QMap<QString, QString>::const_iterator scaleIt = options.find( QStringLiteral( "SCALE" ) );
1005-
if ( scaleIt != options.constEnd() )
968+
dxf.setLayerTitleAsName( mWmsParameters.dxfUseLayerTitleAsName() );
969+
dxf.setSymbologyExport( mWmsParameters.dxfMode() );
970+
if ( mWmsParameters.dxfFormatOptions().contains( QgsWmsParameters::DxfFormatOption::SCALE ) )
1006971
{
1007-
dxf.setSymbologyScale( scaleIt->toDouble() );
972+
dxf.setSymbologyScale( mWmsParameters.dxfScale() );
1008973
}
1009974

1010975
return dxf;

‎src/server/services/wms/qgswmsrenderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class QgsAccessControl;
4242
class QgsDxfExport;
4343
class QgsLayerTreeModel;
4444
class QgsLayerTree;
45+
class QgsServerInterface;
4546

4647
class QImage;
4748
class QPaintDevice;
@@ -91,11 +92,10 @@ namespace QgsWms
9192

9293
/**
9394
* Returns the map as DXF data
94-
* \param options extracted from the FORMAT_OPTIONS parameter
9595
* \returns the map as DXF data
9696
* \since QGIS 3.0
9797
*/
98-
QgsDxfExport getDxf( const QMap<QString, QString> &options );
98+
QgsDxfExport getDxf();
9999

100100
/**
101101
* Returns printed page as binary

‎tests/src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ IF (ENABLE_TESTS)
5050
IF (WITH_QUICK)
5151
ADD_SUBDIRECTORY(quickgui)
5252
ENDIF (WITH_QUICK)
53+
IF (WITH_SERVER)
54+
ADD_SUBDIRECTORY(server)
55+
ENDIF (WITH_SERVER)
5356
ENDIF (ENABLE_TESTS)

‎tests/src/server/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ADD_SUBDIRECTORY(wms)

‎tests/src/server/wms/CMakeLists.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#####################################################
2+
# Don't forget to include output directory, otherwise
3+
# the UI file won't be wrapped!
4+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
5+
${CMAKE_CURRENT_BINARY_DIR}
6+
${CMAKE_SOURCE_DIR}/src/core
7+
${CMAKE_SOURCE_DIR}/src/core/geometry
8+
${CMAKE_SOURCE_DIR}/src/core/expression
9+
${CMAKE_SOURCE_DIR}/src/core/dxf
10+
${CMAKE_SOURCE_DIR}/src/core/symbology
11+
${CMAKE_SOURCE_DIR}/src/core/metadata
12+
${CMAKE_SOURCE_DIR}/src/core/layertree
13+
${CMAKE_SOURCE_DIR}/src/core/raster
14+
${CMAKE_SOURCE_DIR}/src/core/annotations
15+
${CMAKE_SOURCE_DIR}/src/core/layout
16+
${CMAKE_BINARY_DIR}/src/core
17+
${CMAKE_SOURCE_DIR}/src/test
18+
${CMAKE_SOURCE_DIR}/src/server
19+
${CMAKE_BINARY_DIR}/src/server
20+
${CMAKE_SOURCE_DIR}/src/server/services
21+
${CMAKE_SOURCE_DIR}/src/server/services/wms
22+
)
23+
24+
#note for tests we should not include the moc of our
25+
#qtests in the executable file list as the moc is
26+
#directly included in the sources
27+
#and should not be compiled twice. Trying to include
28+
#them in will cause an error at build time
29+
30+
#No relinking and full RPATH for the install tree
31+
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree
32+
SET(MODULE_WMS_SRCS
33+
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsrenderer.cpp
34+
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgslayerrestorer.cpp
35+
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgsmaprendererjobproxy.cpp
36+
${CMAKE_SOURCE_DIR}/src/server/services/wms/qgswmsparameters.cpp
37+
)
38+
39+
MACRO (ADD_QGIS_TEST TESTSRC)
40+
SET (TESTNAME ${TESTSRC})
41+
STRING(REPLACE "test" "" TESTNAME ${TESTNAME})
42+
STRING(REPLACE "qgs" "" TESTNAME ${TESTNAME})
43+
STRING(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
44+
SET (TESTNAME "qgis_${TESTNAME}test")
45+
ADD_EXECUTABLE(${TESTNAME} ${TESTSRC} ${MODULE_WMS_SRCS})
46+
SET_TARGET_PROPERTIES(${TESTNAME} PROPERTIES AUTOMOC TRUE)
47+
TARGET_LINK_LIBRARIES(${TESTNAME}
48+
${Qt5Core_LIBRARIES}
49+
${Qt5Xml_LIBRARIES}
50+
${Qt5Svg_LIBRARIES}
51+
${Qt5Test_LIBRARIES}
52+
${PROJ_LIBRARY}
53+
${GEOS_LIBRARY}
54+
${GDAL_LIBRARY}
55+
qgis_core
56+
qgis_server
57+
)
58+
ADD_TEST(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
59+
ENDMACRO (ADD_QGIS_TEST)
60+
61+
#############################################################
62+
# Tests:
63+
64+
SET(TESTS
65+
test_qgsserver_wms_dxf.cpp
66+
)
67+
68+
FOREACH(TESTSRC ${TESTS})
69+
ADD_QGIS_TEST(${TESTSRC})
70+
ENDFOREACH(TESTSRC)
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/***************************************************************************
2+
testqgswmsparameters.cpp
3+
--------------------------------------
4+
Date : 20 Mar 2019
5+
Copyright : (C) 2019 by Paul Blottiere
6+
Email : paul dot blottiere @ oslandia.com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgstest.h"
17+
#include "qgsproject.h"
18+
#include "qgsvectorlayer.h"
19+
#include "qgsserverinterfaceimpl.h"
20+
#include "qgswmsparameters.h"
21+
#include "qgswmsrenderer.h"
22+
23+
/**
24+
* \ingroup UnitTests
25+
* This is a unit test for the WMS parameters parsing
26+
*/
27+
class TestQgsServerWmsDxf : public QObject
28+
{
29+
Q_OBJECT
30+
31+
private slots:
32+
void initTestCase();
33+
void cleanupTestCase();
34+
35+
void use_title_as_layername_true();
36+
void use_title_as_layername_false();
37+
};
38+
39+
void TestQgsServerWmsDxf::initTestCase()
40+
{
41+
QgsApplication::init();
42+
QgsApplication::initQgis();
43+
}
44+
45+
void TestQgsServerWmsDxf::cleanupTestCase()
46+
{
47+
QgsApplication::exitQgis();
48+
}
49+
50+
void TestQgsServerWmsDxf::use_title_as_layername_true()
51+
{
52+
const QString key = "FORMAT_OPTIONS";
53+
const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:FALSE;LAYERATTRIBUTES:name;CODEC:my_codec_name";
54+
55+
QUrlQuery query;
56+
query.addQueryItem( key, value );
57+
query.addQueryItem( "LAYERS", "testlayer èé" );
58+
59+
QgsWms::QgsWmsParameters parameters( query );
60+
61+
QCOMPARE( int( parameters.dxfScale() ), 250 );
62+
QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) );
63+
QCOMPARE( parameters.dxfUseLayerTitleAsName(), false );
64+
QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology );
65+
QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 1 );
66+
QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "name" ) );
67+
68+
const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR );
69+
QgsProject project;
70+
project.read( filename );
71+
72+
QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0];
73+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
74+
75+
QgsCapabilitiesCache cache;
76+
QgsServiceRegistry registry;
77+
QgsServerSettings settings;
78+
QgsServerInterfaceImpl interface( &cache, &registry, &settings );
79+
QgsWms::QgsRenderer renderer( &interface, &project, parameters );
80+
81+
QgsDxfExport exporter = renderer.getDxf();
82+
const QString name = exporter.layerName( vl );
83+
QCOMPARE( exporter.layerName( vl ), QString( "testlayer \u00E8\u00E9" ) );
84+
85+
const QgsFeature ft = vl->getFeature( 1 );
86+
QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "two" ) );
87+
}
88+
89+
void TestQgsServerWmsDxf::use_title_as_layername_false()
90+
{
91+
const QString key = "FORMAT_OPTIONS";
92+
const QString value = "MODE:SYMBOLLAYERSYMBOLOGY;SCALE:250;USE_TITLE_AS_LAYERNAME:TRUE;LAYERATTRIBUTES:pif,paf,pouf;CODEC:my_codec_name";
93+
94+
QUrlQuery query;
95+
query.addQueryItem( key, value );
96+
query.addQueryItem( "LAYERS", "testlayer èé" );
97+
98+
QgsWms::QgsWmsParameters parameters( query );
99+
100+
QCOMPARE( int( parameters.dxfScale() ), 250 );
101+
QCOMPARE( parameters.dxfCodec(), QString( "my_codec_name" ) );
102+
QCOMPARE( parameters.dxfUseLayerTitleAsName(), true );
103+
QCOMPARE( parameters.dxfMode(), QgsDxfExport::SymbolLayerSymbology );
104+
QCOMPARE( int( parameters.dxfLayerAttributes().size() ), 3 );
105+
QCOMPARE( parameters.dxfLayerAttributes()[0], QString( "pif" ) );
106+
QCOMPARE( parameters.dxfLayerAttributes()[1], QString( "paf" ) );
107+
QCOMPARE( parameters.dxfLayerAttributes()[2], QString( "pouf" ) );
108+
109+
const QString filename = QString( "%1/qgis_server/test_project.qgs" ).arg( TEST_DATA_DIR );
110+
QgsProject project;
111+
project.read( filename );
112+
113+
QgsMapLayer *layer = project.layerStore()->mapLayersByName( "testlayer èé" )[0];
114+
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
115+
116+
QgsCapabilitiesCache cache;
117+
QgsServiceRegistry registry;
118+
QgsServerSettings settings;
119+
QgsServerInterfaceImpl interface( &cache, &registry, &settings );
120+
QgsWms::QgsRenderer renderer( &interface, &project, parameters );
121+
122+
QgsDxfExport exporter = renderer.getDxf();
123+
const QString name = exporter.layerName( vl );
124+
QCOMPARE( exporter.layerName( vl ), QString( "A test vector layer" ) );
125+
126+
const QgsFeature ft = vl->getFeature( 1 );
127+
QCOMPARE( exporter.layerName( vl->id(), ft ), QString( "A test vector layer" ) );
128+
}
129+
130+
QGSTEST_MAIN( TestQgsServerWmsDxf )
131+
#include "test_qgsserver_wms_dxf.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.