Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add DXF parameters in QgsWmsParameters
  • Loading branch information
pblottiere committed Mar 25, 2019
1 parent 9327834 commit 3953608
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
98 changes: 98 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -1817,4 +1817,102 @@ namespace QgsWms
{
return name.startsWith( EXTERNAL_LAYER_PREFIX );
}

QStringList QgsWmsParameters::dxfLayerAttributes() const
{
QStringList attributes;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();

if ( options.contains( DxfFormatOption::LAYERATTRIBUTES ) )
{
attributes = options[ DxfFormatOption::LAYERATTRIBUTES ].split( ',' );
}

return attributes;
}

bool QgsWmsParameters::dxfUseLayerTitleAsName() const
{
bool use = false;
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();

if ( options.contains( DxfFormatOption::USE_TITLE_AS_LAYERNAME ) )
{
use = QVariant( options[ DxfFormatOption::USE_TITLE_AS_LAYERNAME ] ).toBool();
}

return use;
}

double QgsWmsParameters::dxfScale() const
{
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();

double scale = -1;
if ( options.contains( DxfFormatOption::SCALE ) )
{
scale = options[ DxfFormatOption::SCALE ].toDouble();
}

return scale;
}

QgsDxfExport::SymbologyExport QgsWmsParameters::dxfMode() const
{
const QMap<DxfFormatOption, QString> options = dxfFormatOptions();

QgsDxfExport::SymbologyExport symbo = QgsDxfExport::NoSymbology;

if ( ! options.contains( DxfFormatOption::MODE ) )
{
return symbo;
}

const QString mode = options[ DxfFormatOption::MODE ];
if ( mode.compare( QLatin1String( "SymbolLayerSymbology" ), Qt::CaseInsensitive ) == 0 )
{
symbo = QgsDxfExport::SymbolLayerSymbology;
}
else if ( mode.compare( QLatin1String( "FeatureSymbology" ), Qt::CaseInsensitive ) == 0 )
{
symbo = QgsDxfExport::FeatureSymbology;
}

return symbo;
}

QString QgsWmsParameters::dxfCodec() const
{
QString codec = QStringLiteral( "ISO-8859-1" );

if ( dxfFormatOptions().contains( DxfFormatOption::CODEC ) )
{
codec = dxfFormatOptions()[ DxfFormatOption::CODEC ];
}

return codec;
}

QMap<QgsWmsParameters::DxfFormatOption, QString> QgsWmsParameters::dxfFormatOptions() const
{
QMap<QgsWmsParameters::DxfFormatOption, QString> options;

const QMetaEnum metaEnum( QMetaEnum::fromType<QgsWmsParameters::DxfFormatOption>() );
const QStringList opts = mWmsParameters[ QgsWmsParameter::FORMAT_OPTIONS ].toStringList( ';' );

for ( auto it = opts.constBegin(); it != opts.constEnd(); ++it )
{
const int equalIdx = it->indexOf( ':' );
if ( equalIdx > 0 && equalIdx < ( it->length() - 1 ) )
{
const QString name = it->left( equalIdx ).toUpper();
const QgsWmsParameters::DxfFormatOption option =
( QgsWmsParameters::DxfFormatOption ) metaEnum.keyToValue( name.toStdString().c_str() );
const QString value = it->right( it->length() - equalIdx - 1 );
options.insert( option, value );
}
}

return options;
}
}
27 changes: 26 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Expand Up @@ -28,6 +28,7 @@
#include "qgsprojectversion.h"
#include "qgsogcutils.h"
#include "qgsserverparameters.h"
#include "qgsdxfexport.h"

namespace QgsWms
{
Expand Down Expand Up @@ -174,7 +175,8 @@ namespace QgsWms
WITH_GEOMETRY,
WITH_MAPTIP,
WMTVER,
ATLAS_PK
ATLAS_PK,
FORMAT_OPTIONS
};
Q_ENUM( Name )

Expand Down Expand Up @@ -323,6 +325,17 @@ namespace QgsWms
};
Q_ENUM( Format )

//! Options for DXF format
enum DxfFormatOption
{
SCALE,
MODE,
LAYERATTRIBUTES,
USE_TITLE_AS_LAYERNAME,
CODEC
};
Q_ENUM( DxfFormatOption )

/**
* Constructor for WMS parameters with specific values.
* \param parameters Map of parameters where keys are parameters' names.
Expand Down Expand Up @@ -1177,6 +1190,18 @@ namespace QgsWms
*/
QStringList atlasPk() const;

QMap<DxfFormatOption, QString> dxfFormatOptions() const;

QStringList dxfLayerAttributes() const;

bool dxfUseLayerTitleAsName() const;

double dxfScale() const;

QgsDxfExport::SymbologyExport dxfMode() const;

QString dxfCodec() const;

private:
static bool isExternalLayer( const QString &name );

Expand Down

0 comments on commit 3953608

Please sign in to comment.