Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Define an enum for predefined WMS Dimension names
  • Loading branch information
rldhont committed Sep 16, 2019
1 parent b18cbc7 commit 4823054
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
16 changes: 9 additions & 7 deletions python/core/auto_generated/qgsvectorlayerserverproperties.sip.in
Expand Up @@ -23,6 +23,15 @@ Manages QGIS Server properties for a vector layer
#include "qgsvectorlayerserverproperties.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum PredefinedWmsDimensionName
{
TIME,
ELEVATION
};

struct WmsDimensionInfo
{
Expand Down Expand Up @@ -59,13 +68,6 @@ Constructor for WmsDimensionInfo.
Constructor - Creates a Vector Layer QGIS Server Properties

:param layer: The vector layer
%End

static QStringList predefinedWmsDimensionNames();
%Docstring
Returns predefined/restricted WMS Dimension names

.. versionadded:: 3.10
%End

static QMap<int, QString> wmsDimensionDefaultDisplayLabels();
Expand Down
25 changes: 14 additions & 11 deletions src/app/qgswmsdimensiondialog.cpp
Expand Up @@ -46,11 +46,13 @@ QgsWmsDimensionDialog::QgsWmsDimensionDialog( QgsVectorLayer *layer, QStringList
connect( mDefaultDisplayComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsWmsDimensionDialog::defaultDisplayChanged );

// Set available names
for ( const QString &name : QgsVectorLayerServerProperties::predefinedWmsDimensionNames() )
const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsVectorLayerServerProperties::PredefinedWmsDimensionName>() );
for ( int i = 0; i < pnMetaEnum.keyCount(); i++ )
{
if ( !alreadyDefinedDimensions.contains( name ) )
QString name( pnMetaEnum.key( i ) );
if ( !alreadyDefinedDimensions.contains( name.toLower() ) )
{
mNameComboBox->addItem( QStringLiteral( "%1%2" ).arg( name.left( 1 ).toUpper(), name.mid( 1 ) ), QVariant( name ) );
mNameComboBox->addItem( QStringLiteral( "%1%2" ).arg( name.left( 1 ), name.mid( 1 ).toLower() ), QVariant( pnMetaEnum.value( i ) ) );
}
}

Expand All @@ -70,14 +72,15 @@ QgsWmsDimensionDialog::QgsWmsDimensionDialog( QgsVectorLayer *layer, QStringList

void QgsWmsDimensionDialog::setInfo( const QgsVectorLayerServerProperties::WmsDimensionInfo &info )
{
int nameDataIndex = mNameComboBox->findData( QVariant( info.name ) );
if ( nameDataIndex == -1 )
const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsVectorLayerServerProperties::PredefinedWmsDimensionName>() );
int predefinedNameValue = pnMetaEnum.keyToValue( info.name.toUpper().toStdString().c_str() );
if ( predefinedNameValue == -1 )
{
mNameComboBox->setEditText( info.name );
}
else
{
mNameComboBox->setCurrentIndex( nameDataIndex );
mNameComboBox->setCurrentIndex( mNameComboBox->findData( QVariant( predefinedNameValue ) ) );
}
mNameComboBox->setEnabled( false );

Expand Down Expand Up @@ -112,13 +115,13 @@ QgsVectorLayerServerProperties::WmsDimensionInfo QgsWmsDimensionDialog::info() c
QString name = mNameComboBox->currentText();
if ( mNameComboBox->findText( name ) != -1 )
{
name = mNameComboBox->currentData().toString();
name = name.toLower();
}

// Gets the reference value
QString refText = mReferenceValueComboBox->currentText();
QVariant refValue;
if ( mNameComboBox->findText( name ) != -1 )
if ( mReferenceValueComboBox->findText( refText ) != -1 )
{
refValue = mReferenceValueComboBox->currentData();
}
Expand All @@ -141,8 +144,8 @@ void QgsWmsDimensionDialog::nameChanged( const QString &name )
// Is the name a predefined value?
if ( mNameComboBox->findText( name ) != -1 )
{
QString data = mNameComboBox->currentData().toString();
if ( data.compare( QLatin1String( "time" ) ) == 0 ) // Time
int data = mNameComboBox->currentData().toInt();
if ( data == QgsVectorLayerServerProperties::TIME )
{
mFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::DateTime );
mEndFieldComboBox->setFilters( QgsFieldProxyModel::String | QgsFieldProxyModel::DateTime );
Expand All @@ -152,7 +155,7 @@ void QgsWmsDimensionDialog::nameChanged( const QString &name )
mUnitSymbolLabel->setEnabled( false );
mUnitSymbolLineEdit->setEnabled( false );
}
else if ( data.compare( QLatin1String( "elevation" ) ) == 0 ) // Elevation
else if ( data == QgsVectorLayerServerProperties::ELEVATION )
{
mFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
mEndFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
Expand Down
18 changes: 12 additions & 6 deletions src/core/qgsvectorlayerserverproperties.h
Expand Up @@ -37,9 +37,21 @@ class QDomDocument;
*/
class CORE_EXPORT QgsVectorLayerServerProperties
{
Q_GADGET

public:

/**
* Predefined/Restricted WMS Dimension name
* \since QGIS 3.10
*/
enum PredefinedWmsDimensionName
{
TIME,
ELEVATION
};
Q_ENUM( PredefinedWmsDimensionName )

/**
* Setting to define QGIS Server WMS Dimension.
* \since QGIS 3.10
Expand Down Expand Up @@ -93,12 +105,6 @@ class CORE_EXPORT QgsVectorLayerServerProperties
*/
QgsVectorLayerServerProperties( QgsVectorLayer *layer = nullptr );

/**
* Returns predefined/restricted WMS Dimension names
* \since QGIS 3.10
*/
static QStringList predefinedWmsDimensionNames() { return { "time", "elevation" }; }

/**
* Returns WMS Dimension default display labels
* \since QGIS 3.10
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -2016,15 +2016,15 @@ namespace QgsWms
QMap<QString, QString> QgsWmsParameters::dimensionValues() const
{
QMap<QString, QString> dimValues;
const QStringList reservedNames = QgsVectorLayerServerProperties::predefinedWmsDimensionNames();
const QMetaEnum pnMetaEnum( QMetaEnum::fromType<QgsVectorLayerServerProperties::PredefinedWmsDimensionName>() );
const QStringList unmanagedNames = mUnmanagedParameters.keys();
for ( const QString &key : unmanagedNames )
{
if ( key.startsWith( QStringLiteral( "DIM_" ) ) )
{
dimValues[key.mid( 4 )] = mUnmanagedParameters[key];
}
else if ( reservedNames.contains( key.toLower() ) )
else if ( pnMetaEnum.keyToValue( key.toUpper().toStdString().c_str() ) != -1 )
{
dimValues[key] = mUnmanagedParameters[key];
}
Expand Down

0 comments on commit 4823054

Please sign in to comment.