-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
639f63e
commit e32c5cd
Showing
11 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.