Skip to content

Commit

Permalink
change WMS encoding scheme to "interpretation"
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec authored and nyalldawson committed Jan 8, 2022
1 parent f3224fb commit 0fbc7cc
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 235 deletions.
6 changes: 3 additions & 3 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -55,9 +55,9 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
mAuth.mReferer = uri.param( QStringLiteral( "referer" ) );
mXyz = false; // assume WMS / WMTS

if ( uri.hasParam( QStringLiteral( "encodingScheme" ) ) )
if ( uri.hasParam( QStringLiteral( "interpretation" ) ) )
{
mEncodingScheme = uri.param( QStringLiteral( "encodingScheme" ) );
mInterpretation = uri.param( QStringLiteral( "interpretation" ) );
}

if ( uri.param( QStringLiteral( "type" ) ) == QLatin1String( "xyz" ) ||
Expand All @@ -74,7 +74,7 @@ bool QgsWmsSettings::parseUri( const QString &uriString )
mBaseUrl = mHttpUri;
mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;
mSmoothPixmapTransform = mEncodingScheme.isEmpty();
mSmoothPixmapTransform = mInterpretation.isEmpty();
mDpiMode = DpiNone; // does not matter what we set here
mActiveSubLayers = QStringList( QStringLiteral( "xyz" ) ); // just a placeholder to have one sub-layer
mActiveSubStyles = QStringList( QStringLiteral( "xyz" ) ); // just a placeholder to have one sub-style
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmscapabilities.h
Expand Up @@ -858,7 +858,7 @@ class QgsWmsSettings

bool mEnableContextualLegend;

QString mEncodingScheme;
QString mInterpretation;

friend class QgsWmsProvider;
};
Expand Down
16 changes: 8 additions & 8 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -222,7 +222,7 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri, const ProviderOptions &optio
// 3) http://xxx.xxx.xx/yyy/yyy?zzz=www


mConverter = QgsWmsConverter::createConverter( mSettings.mEncodingScheme );
mConverter = QgsWmsInterpretationConverter::createConverter( mSettings.mInterpretation );

mValid = true;
QgsDebugMsgLevel( QStringLiteral( "exiting constructor." ), 4 );
Expand Down Expand Up @@ -4844,20 +4844,20 @@ QGISEXTERN QgsProviderMetadata *providerMetadataFactory()
}
#endif

Qgis::DataType QgsWmsConverter::dataType() const
Qgis::DataType QgsWmsInterpretationConverter::dataType() const
{
return Qgis::DataType::Float32;
}

std::unique_ptr<QgsWmsConverter> QgsWmsConverter::createConverter( const QString &key )
std::unique_ptr<QgsWmsInterpretationConverter> QgsWmsInterpretationConverter::createConverter( const QString &key )
{
if ( key == QgsWmsConverterMapTilerTerrainRGB::encodingSchemeKey() )
return std::make_unique<QgsWmsConverterMapTilerTerrainRGB>();
if ( key == QgsWmsInterpretationConverterMapTilerTerrainRGB::interpretationKey() )
return std::make_unique<QgsWmsInterpretationConverterMapTilerTerrainRGB>();

return nullptr;
}

void QgsWmsConverterMapTilerTerrainRGB::convert( const QRgb &color, float *converted ) const
void QgsWmsInterpretationConverterMapTilerTerrainRGB::convert( const QRgb &color, float *converted ) const
{
int R = qRed( color );
int G = qGreen( color );
Expand All @@ -4866,7 +4866,7 @@ void QgsWmsConverterMapTilerTerrainRGB::convert( const QRgb &color, float *conve
*converted = -10000 + ( ( R * 256 * 256 + G * 256 + B ) ) * 0.1;
}

QgsRasterBandStats QgsWmsConverterMapTilerTerrainRGB::statistics( int, int, const QgsRectangle &, int, QgsRasterBlockFeedback * ) const
QgsRasterBandStats QgsWmsInterpretationConverterMapTilerTerrainRGB::statistics( int, int, const QgsRectangle &, int, QgsRasterBlockFeedback * ) const
{
QgsRasterBandStats stat;
stat.minimumValue = 0;
Expand All @@ -4875,7 +4875,7 @@ QgsRasterBandStats QgsWmsConverterMapTilerTerrainRGB::statistics( int, int, cons
return stat;
}

QgsRasterHistogram QgsWmsConverterMapTilerTerrainRGB::histogram( int, int, double, double, const QgsRectangle &, int, bool, QgsRasterBlockFeedback * ) const
QgsRasterHistogram QgsWmsInterpretationConverterMapTilerTerrainRGB::histogram( int, int, double, double, const QgsRectangle &, int, bool, QgsRasterBlockFeedback * ) const
{
return QgsRasterHistogram();
}
16 changes: 8 additions & 8 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -99,11 +99,11 @@ class QgsCachedImageFetcher: public QgsImageFetcher
}
};

//! Abstract class to convert color to float value following encoding scheme
class QgsWmsConverter
//! Abstract class to convert color to float value following an interpretation
class QgsWmsInterpretationConverter
{
public:
virtual ~QgsWmsConverter() = default;
virtual ~QgsWmsInterpretationConverter() = default;

//! Convert the \a color to a value pointed by float
virtual void convert( const QRgb &color, float *converted ) const = 0;
Expand All @@ -128,12 +128,12 @@ class QgsWmsConverter
QgsRasterBlockFeedback *feedback = nullptr ) const = 0;

//! Creates a converter instance corresponding to the \a key
static std::unique_ptr<QgsWmsConverter> createConverter( const QString &key );
static std::unique_ptr<QgsWmsInterpretationConverter> createConverter( const QString &key );
};


//! Class to convert color to float value following the mapTiler terrain RGB encoding scheme
class QgsWmsConverterMapTilerTerrainRGB : public QgsWmsConverter
//! Class to convert color to float value following the mapTiler terrain RGB interpretation
class QgsWmsInterpretationConverterMapTilerTerrainRGB : public QgsWmsInterpretationConverter
{
public:
void convert( const QRgb &color, float *converted ) const override;
Expand All @@ -153,7 +153,7 @@ class QgsWmsConverterMapTilerTerrainRGB : public QgsWmsConverter
QgsRasterBlockFeedback *feedback = nullptr ) const override;

static QString displayName() {return QObject::tr( "MapTiler Terrain RGB" );}
static QString encodingSchemeKey() {return QStringLiteral( "maptilerterrain" );}
static QString interpretationKey() {return QStringLiteral( "maptilerterrain" );}
};

/**
Expand Down Expand Up @@ -563,7 +563,7 @@ class QgsWmsProvider final: public QgsRasterDataProvider

QList< double > mNativeResolutions;

std::unique_ptr<QgsWmsConverter> mConverter;
std::unique_ptr<QgsWmsInterpretationConverter> mConverter;

friend class TestQgsWmsProvider;

Expand Down
61 changes: 17 additions & 44 deletions src/providers/wms/qgswmssourceselect.cpp
Expand Up @@ -143,8 +143,9 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
tabLayers->layout()->removeWidget( gbCRS );
}

mEncodingSchemeWidget = new QgsWmsEncodingSchemeWidget( this );
mEncodingSchemeLayout->addWidget( mEncodingSchemeWidget );

mInterpretationCombo = new QgsWmsInterpretationComboBox( this );
mInterpretationLayout->addWidget( mInterpretationCombo );

clear();

Expand Down Expand Up @@ -288,7 +289,7 @@ void QgsWMSSourceSelect::clear()

mFeatureCount->setEnabled( false );

mEncodingSchemeWidget->setEncodingScheme( QString() );
mInterpretationCombo->setInterpretation( QString() );
}

bool QgsWMSSourceSelect::populateLayerList( const QgsWmsCapabilities &capabilities )
Expand Down Expand Up @@ -604,8 +605,8 @@ void QgsWMSSourceSelect::addButtonClicked()
uri.setParam( QStringLiteral( "featureCount" ), mFeatureCount->text() );
}

if ( tabTilesets->isEnabled() && !mEncodingSchemeWidget->encodingScheme().isEmpty() )
uri.setParam( QStringLiteral( "encodingScheme" ), mEncodingSchemeWidget->encodingScheme() );
if ( tabTilesets->isEnabled() && !mInterpretationCombo->interpretation().isEmpty() )
uri.setParam( QStringLiteral( "interpretation" ), mInterpretationCombo->interpretation() );

uri.setParam( QStringLiteral( "contextualWMSLegend" ), mContextualLegendCheckbox->isChecked() ? "1" : "0" );

Expand Down Expand Up @@ -1317,53 +1318,25 @@ void QgsWMSSourceSelect::showHelp()
QgsHelp::openHelp( QStringLiteral( "working_with_ogc/ogc_client_support.html" ) );
}

QgsWmsEncodingSchemeWidget::QgsWmsEncodingSchemeWidget( QWidget *parent ): QWidget( parent )
QgsWmsInterpretationComboBox::QgsWmsInterpretationComboBox( QWidget *parent ): QComboBox( parent )
{
QHBoxLayout *lay = new QHBoxLayout( this );
lay->setContentsMargins( 0, 0, 0, 0 );
setLayout( lay );
mCheckBox = new QCheckBox( this );
mCheckBox->setText( tr( "Convert to single band raster" ) );
mCheckBox->setChecked( false );
layout()->addWidget( mCheckBox );

mCombo = new QComboBox( this );
mCombo->setEnabled( false );
layout()->addWidget( mCombo );

connect( mCheckBox, &QAbstractButton::toggled, mCombo, &QComboBox::setEnabled );

populateEncodingScheme();
addItem( tr( "default" ), QString() );
addItem( QgsWmsInterpretationConverterMapTilerTerrainRGB::displayName(), QgsWmsInterpretationConverterMapTilerTerrainRGB::interpretationKey() );
}

void QgsWmsEncodingSchemeWidget::populateEncodingScheme()
void QgsWmsInterpretationComboBox::setInterpretation( const QString &interpretationKey )
{
mCombo->addItem( QgsWmsConverterMapTilerTerrainRGB::displayName(), QgsWmsConverterMapTilerTerrainRGB::encodingSchemeKey() );
}

void QgsWmsEncodingSchemeWidget::setEncodingScheme( const QString &encodingSchemeKey )
{
bool checked = false;
if ( ! encodingSchemeKey.isEmpty() )
if ( ! interpretationKey.isEmpty() )
{
int index = mCombo->findData( encodingSchemeKey );
if ( index != -1 )
{
checked = true;
mCombo->setCurrentIndex( index );
}
int index = findData( interpretationKey );
if ( index == -1 )
setCurrentIndex( 0 );
else
checked = false;
setCurrentIndex( index );
}

mCheckBox->setChecked( checked );
mCombo->setEnabled( checked );
}

QString QgsWmsEncodingSchemeWidget::encodingScheme() const
QString QgsWmsInterpretationComboBox::interpretation() const
{
if ( mCheckBox->isChecked() )
return mCombo->currentData().toString();

return QString();
return currentData().toString();
}
25 changes: 9 additions & 16 deletions src/providers/wms/qgswmssourceselect.h
Expand Up @@ -33,7 +33,7 @@ class QgsTreeWidgetItem;
class QDomDocument;
class QDomElement;
class QgsWmsCapabilities;
class QgsWmsEncodingSchemeWidget;
class QgsWmsInterpretationComboBox;

/*!
* \brief Dialog to create connections and add layers from WMS, etc.
Expand Down Expand Up @@ -193,7 +193,7 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM
// save the current status of the layer true
QMap<QTreeWidgetItem *, bool> mTreeInitialExpand = QMap<QTreeWidgetItem *, bool>();

QgsWmsEncodingSchemeWidget *mEncodingSchemeWidget = nullptr;
QgsWmsInterpretationComboBox *mInterpretationCombo = nullptr;

private slots:
void lstTilesets_itemClicked( QTableWidgetItem *item );
Expand All @@ -204,28 +204,21 @@ class QgsWMSSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsWM
};

/*!
* \brief Widget that embeds a checkbox and a combobox to select an encoding scheme to convert image to a single band raster
* \brief ComboBox to select interpretation to convert image to a single band raster
*/
class QgsWmsEncodingSchemeWidget : public QWidget
class QgsWmsInterpretationComboBox : public QComboBox
{
public:
//! Constructor
QgsWmsEncodingSchemeWidget( QWidget *parent = nullptr );
QgsWmsInterpretationComboBox( QWidget *parent = nullptr );

/**
* Sets the current encoding scheme from its key \a encodingSchemeKey,
* leading to checked the checkbox if the encoding scheme exists or unchecked if the key is empty or the scheme does not exist
* Sets the interpretation from its key \a interpretationKey, default if interpretationKey is empty
*/
void setEncodingScheme( const QString &encodingSchemeKey );
void setInterpretation( const QString &interpretationKey );

//! Returns the key of the current selected scheme, returns empty string if the checkbox is unchecked
QString encodingScheme() const;

private:
QCheckBox *mCheckBox = nullptr;
QComboBox *mCombo = nullptr;

void populateEncodingScheme();
//! Returns the key of the current selected interpretation, returns empty string if the current is default
QString interpretation() const;
};

#endif // QGSWMSSOURCESELECT_H
8 changes: 4 additions & 4 deletions src/providers/wms/qgsxyzconnection.cpp
Expand Up @@ -38,8 +38,8 @@ QString QgsXyzConnection::encodedUri() const
uri.setParam( QStringLiteral( "referer" ), referer );
if ( tilePixelRatio != 0 )
uri.setParam( QStringLiteral( "tilePixelRatio" ), QString::number( tilePixelRatio ) );
if ( !encodingScheme.isEmpty() )
uri.setParam( QStringLiteral( "encodingScheme" ), encodingScheme );
if ( !interpretation.isEmpty() )
uri.setParam( QStringLiteral( "interpretation" ), interpretation );
return uri.encodedUri();
}

Expand Down Expand Up @@ -96,7 +96,7 @@ QgsXyzConnection QgsXyzConnectionUtils::connection( const QString &name )
conn.referer = settings.value( QStringLiteral( "referer" ) ).toString();
conn.tilePixelRatio = settings.value( QStringLiteral( "tilePixelRatio" ), 0 ).toDouble();
conn.hidden = settings.value( QStringLiteral( "hidden" ) ).toBool();
conn.encodingScheme = settings.value( QStringLiteral( "encodingScheme" ), conn.encodingScheme ).toString();
conn.interpretation = settings.value( QStringLiteral( "interpretation" ), QString() ).toString();
return conn;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ void QgsXyzConnectionUtils::addConnection( const QgsXyzConnection &conn )
settings.setValue( QStringLiteral( "password" ), conn.password );
settings.setValue( QStringLiteral( "referer" ), conn.referer );
settings.setValue( QStringLiteral( "tilePixelRatio" ), conn.tilePixelRatio );
settings.setValue( QStringLiteral( "encodingScheme" ), conn.encodingScheme );
settings.setValue( QStringLiteral( "interpretation" ), conn.interpretation );
if ( addHiddenProperty )
{
settings.setValue( QStringLiteral( "hidden" ), false );
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wms/qgsxyzconnection.h
Expand Up @@ -36,8 +36,8 @@ struct QgsXyzConnection
double tilePixelRatio = 0;
bool hidden = false;

// Encoding scheme key related to the converter from color to value, empty if none
QString encodingScheme;
// Interpretation key related to the converter from color to value, empty if none
QString interpretation;

QString encodedUri() const;
};
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wms/qgsxyzconnectiondialog.cpp
Expand Up @@ -52,7 +52,7 @@ void QgsXyzConnectionDialog::setConnection( const QgsXyzConnection &conn )
mSourceWidget->setReferer( conn.referer );
mSourceWidget->setTilePixelRatio( conn.tilePixelRatio );
mSourceWidget->setAuthCfg( conn.authCfg );
mSourceWidget->setEncodingScheme( conn.encodingScheme );
mSourceWidget->setInterpretation( conn.interpretation );
}

QgsXyzConnection QgsXyzConnectionDialog::connection() const
Expand All @@ -67,7 +67,7 @@ QgsXyzConnection QgsXyzConnectionDialog::connection() const
conn.referer = mSourceWidget->referer();
conn.tilePixelRatio = mSourceWidget->tilePixelRatio();
conn.authCfg = mSourceWidget->authcfg( );
conn.encodingScheme = mSourceWidget->encodingScheme();
conn.interpretation = mSourceWidget->interpretation();
return conn;
}

Expand Down
20 changes: 10 additions & 10 deletions src/providers/wms/qgsxyzsourcewidget.cpp
Expand Up @@ -32,8 +32,8 @@ QgsXyzSourceWidget::QgsXyzSourceWidget( QWidget *parent )
mSpinZMax->setClearValue( 18 );

connect( mEditUrl, &QLineEdit::textChanged, this, &QgsXyzSourceWidget::validate );
mEncodingSchemeWidget = new QgsWmsEncodingSchemeWidget( this );
mEncodingSchemeLayout->addWidget( mEncodingSchemeWidget );
mInterpretationCombo = new QgsWmsInterpretationComboBox( this );
mInterpretationLayout->addWidget( mInterpretationCombo );
}

void QgsXyzSourceWidget::setSourceUri( const QString &uri )
Expand All @@ -58,7 +58,7 @@ void QgsXyzSourceWidget::setSourceUri( const QString &uri )

mAuthSettings->setConfigId( mSourceParts.value( QStringLiteral( "authcfg" ) ).toString() );

setEncodingScheme( mSourceParts.value( QStringLiteral( "encodingScheme" ) ).toString() );
setInterpretation( mSourceParts.value( QStringLiteral( "interpretation" ) ).toString() );

mIsValid = true;
}
Expand Down Expand Up @@ -101,10 +101,10 @@ QString QgsXyzSourceWidget::sourceUri() const
else
parts.remove( QStringLiteral( "authcfg" ) );

if ( !mEncodingSchemeWidget->encodingScheme().isEmpty() )
parts.insert( QStringLiteral( "encodingScheme" ), mEncodingSchemeWidget->encodingScheme() );
if ( !mInterpretationCombo->interpretation().isEmpty() )
parts.insert( QStringLiteral( "interpretation" ), mInterpretationCombo->interpretation() );
else
parts.remove( QStringLiteral( "encodingScheme" ) );
parts.remove( QStringLiteral( "interpretation" ) );

return QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "wms" ), parts );
}
Expand Down Expand Up @@ -201,14 +201,14 @@ int QgsXyzSourceWidget::tilePixelRatio() const
return 0; // unknown
}

void QgsXyzSourceWidget::setEncodingScheme( const QString &encodingSchemeKey )
void QgsXyzSourceWidget::setInterpretation( const QString &interpretation )
{
mEncodingSchemeWidget->setEncodingScheme( encodingSchemeKey );
mInterpretationCombo->setInterpretation( interpretation );
}

QString QgsXyzSourceWidget::encodingScheme() const
QString QgsXyzSourceWidget::interpretation() const
{
return mEncodingSchemeWidget->encodingScheme();
return mInterpretationCombo->interpretation();
}

void QgsXyzSourceWidget::validate()
Expand Down

0 comments on commit 0fbc7cc

Please sign in to comment.