Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add source widget for XYZ layers, allowing users to change properties
like the min/max zoom levels and authentication settings for any XYZ layer in a project on a layer-by-layer basis
- Loading branch information
Showing
with
417 additions
and 0 deletions.
- +10 −0 python/gui/auto_generated/qgsprovidersourcewidget.sip.in
- +11 −0 src/gui/providers/gdal/qgsgdalfilesourcewidget.cpp
- +5 −0 src/gui/providers/gdal/qgsgdalfilesourcewidget.h
- +10 −0 src/gui/qgsprovidersourcewidget.h
- +6 −0 src/gui/raster/qgsrasterlayerproperties.cpp
- +1 −0 src/providers/wms/CMakeLists.txt
- +42 −0 src/providers/wms/qgswmsprovidergui.cpp
- +1 −0 src/providers/wms/qgswmsprovidergui.h
- +108 −0 src/providers/wms/qgsxyzsourcewidget.cpp
- +44 −0 src/providers/wms/qgsxyzsourcewidget.h
- +179 −0 src/ui/qgsxyzsourcewidgetbase.ui
@@ -0,0 +1,108 @@ | ||
/*************************************************************************** | ||
qgsxyzsourcewidget.cpp | ||
-------------------------------------- | ||
Date : December 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsxyzsourcewidget.h" | ||
|
||
#include "qgsproviderregistry.h" | ||
|
||
|
||
QgsXyzSourceWidget::QgsXyzSourceWidget( QWidget *parent ) | ||
: QgsProviderSourceWidget( parent ) | ||
{ | ||
setupUi( this ); | ||
|
||
// Behavior for min and max zoom checkbox | ||
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled ); | ||
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled ); | ||
mSpinZMax->setClearValue( 18 ); | ||
|
||
connect( mEditUrl, &QLineEdit::textChanged, this, &QgsXyzSourceWidget::validate ); | ||
} | ||
|
||
void QgsXyzSourceWidget::setSourceUri( const QString &uri ) | ||
{ | ||
mSourceParts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "wms" ), uri ); | ||
|
||
mEditUrl->setText( mSourceParts.value( QStringLiteral( "url" ) ).toString() ); | ||
mCheckBoxZMin->setChecked( mSourceParts.value( QStringLiteral( "zmin" ) ).isValid() ); | ||
mSpinZMin->setValue( mCheckBoxZMin->isChecked() ? mSourceParts.value( QStringLiteral( "zmin" ) ).toInt() : 0 ); | ||
mCheckBoxZMax->setChecked( mSourceParts.value( QStringLiteral( "zmax" ) ).isValid() ); | ||
mSpinZMax->setValue( mCheckBoxZMax->isChecked() ? mSourceParts.value( QStringLiteral( "zmax" ) ).toInt() : 18 ); | ||
mAuthSettings->setUsername( mSourceParts.value( QStringLiteral( "username" ) ).toString() ); | ||
mAuthSettings->setPassword( mSourceParts.value( QStringLiteral( "password" ) ).toString() ); | ||
mEditReferer->setText( mSourceParts.value( QStringLiteral( "referer" ) ).toString() ); | ||
|
||
int index = 0; // default is "unknown" | ||
if ( mSourceParts.value( QStringLiteral( "tilePixelRatio" ) ).toInt() == 2. ) | ||
index = 2; // high-res | ||
else if ( mSourceParts.value( QStringLiteral( "tilePixelRatio" ) ).toInt() == 1. ) | ||
index = 1; // normal-res | ||
mComboTileResolution->setCurrentIndex( index ); | ||
|
||
mAuthSettings->setConfigId( mSourceParts.value( QStringLiteral( "authcfg" ) ).toString() ); | ||
|
||
mIsValid = true; | ||
} | ||
|
||
QString QgsXyzSourceWidget::sourceUri() const | ||
{ | ||
QVariantMap parts = mSourceParts; | ||
|
||
parts.insert( QStringLiteral( "url" ), mEditUrl->text() ); | ||
if ( mCheckBoxZMin->isChecked() ) | ||
parts.insert( QStringLiteral( "zmin" ), mSpinZMin->value() ); | ||
else | ||
parts.remove( QStringLiteral( "zmin" ) ); | ||
if ( mCheckBoxZMax->isChecked() ) | ||
parts.insert( QStringLiteral( "zmax" ), mSpinZMax->value() ); | ||
else | ||
parts.remove( QStringLiteral( "zmax" ) ); | ||
|
||
if ( !mAuthSettings->username().isEmpty() ) | ||
parts.insert( QStringLiteral( "username" ), mAuthSettings->username() ); | ||
else | ||
parts.remove( QStringLiteral( "username" ) ); | ||
if ( !mAuthSettings->password().isEmpty() ) | ||
parts.insert( QStringLiteral( "password" ), mAuthSettings->password() ); | ||
else | ||
parts.remove( QStringLiteral( "password" ) ); | ||
|
||
if ( !mEditReferer->text().isEmpty() ) | ||
parts.insert( QStringLiteral( "referer" ), mEditReferer->text() ); | ||
else | ||
parts.remove( QStringLiteral( "referer" ) ); | ||
|
||
if ( mComboTileResolution->currentIndex() > 0 ) | ||
parts.insert( QStringLiteral( "tilePixelRatio" ), mComboTileResolution->currentIndex() ); | ||
else | ||
parts.remove( QStringLiteral( "tilePixelRatio" ) ); | ||
|
||
if ( !mAuthSettings->configId().isEmpty() ) | ||
parts.insert( QStringLiteral( "authcfg" ), mAuthSettings->configId() ); | ||
else | ||
parts.remove( QStringLiteral( "authcfg" ) ); | ||
|
||
return QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "wms" ), parts ); | ||
} | ||
|
||
void QgsXyzSourceWidget::validate() | ||
{ | ||
const bool valid = !mEditUrl->text().isEmpty(); | ||
if ( valid != mIsValid ) | ||
emit validChanged( valid ); | ||
mIsValid = valid; | ||
} |
@@ -0,0 +1,44 @@ | ||
/*************************************************************************** | ||
qgsxyzsourcewidget.h | ||
-------------------------------------- | ||
Date : December 2020 | ||
Copyright : (C) 2020 by Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGGXYZSOURCEWIDGET_H | ||
#define QGGXYZSOURCEWIDGET_H | ||
|
||
#include "qgsprovidersourcewidget.h" | ||
#include "ui_qgsxyzsourcewidgetbase.h" | ||
#include <QVariantMap> | ||
|
||
class QgsXyzSourceWidget : public QgsProviderSourceWidget, private Ui::QgsXyzSourceWidgetBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsXyzSourceWidget( QWidget *parent = nullptr ); | ||
|
||
void setSourceUri( const QString &uri ) override; | ||
QString sourceUri() const override; | ||
|
||
private slots: | ||
|
||
void validate(); | ||
|
||
private: | ||
|
||
QVariantMap mSourceParts; | ||
bool mIsValid = false; | ||
}; | ||
|
||
#endif // QGGXYZSOURCEWIDGET_H |
Oops, something went wrong.