Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Allow changing the authentication setup for existing AFS/AMS layers
- Loading branch information
Showing
with
278 additions
and 1 deletion.
@@ -0,0 +1,106 @@ | ||
/*************************************************************************** | ||
qgsarcgisrestsourcewidget.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 "qgsarcgisrestsourcewidget.h" | ||
|
||
#include "qgsproviderregistry.h" | ||
|
||
|
||
QgsArcGisRestSourceWidget::QgsArcGisRestSourceWidget( const QString &providerKey, QWidget *parent ) | ||
: QgsProviderSourceWidget( parent ) | ||
, mProviderKey( providerKey ) | ||
{ | ||
setupUi( this ); | ||
} | ||
|
||
void QgsArcGisRestSourceWidget::setSourceUri( const QString &uri ) | ||
{ | ||
mSourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, uri ); | ||
|
||
mAuthSettings->setUsername( mSourceParts.value( QStringLiteral( "username" ) ).toString() ); | ||
mAuthSettings->setPassword( mSourceParts.value( QStringLiteral( "password" ) ).toString() ); | ||
mEditReferer->setText( mSourceParts.value( QStringLiteral( "referer" ) ).toString() ); | ||
|
||
mAuthSettings->setConfigId( mSourceParts.value( QStringLiteral( "authcfg" ) ).toString() ); | ||
} | ||
|
||
QString QgsArcGisRestSourceWidget::sourceUri() const | ||
{ | ||
QVariantMap parts = mSourceParts; | ||
|
||
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 ( !mAuthSettings->configId().isEmpty() ) | ||
parts.insert( QStringLiteral( "authcfg" ), mAuthSettings->configId() ); | ||
else | ||
parts.remove( QStringLiteral( "authcfg" ) ); | ||
|
||
return QgsProviderRegistry::instance()->encodeUri( mProviderKey, parts ); | ||
} | ||
|
||
void QgsArcGisRestSourceWidget::setUsername( const QString &username ) | ||
{ | ||
mAuthSettings->setUsername( username ); | ||
} | ||
|
||
void QgsArcGisRestSourceWidget::setPassword( const QString &password ) | ||
{ | ||
mAuthSettings->setPassword( password ); | ||
} | ||
|
||
void QgsArcGisRestSourceWidget::setAuthCfg( const QString &id ) | ||
{ | ||
mAuthSettings->setConfigId( id ); | ||
} | ||
|
||
QString QgsArcGisRestSourceWidget::username() const | ||
{ | ||
return mAuthSettings->username(); | ||
} | ||
|
||
QString QgsArcGisRestSourceWidget::password() const | ||
{ | ||
return mAuthSettings->password(); | ||
} | ||
|
||
QString QgsArcGisRestSourceWidget::authcfg() const | ||
{ | ||
return mAuthSettings->configId(); | ||
} | ||
|
||
void QgsArcGisRestSourceWidget::setReferer( const QString &referer ) | ||
{ | ||
mEditReferer->setText( referer ); | ||
} | ||
|
||
QString QgsArcGisRestSourceWidget::referer() const | ||
{ | ||
return mEditReferer->text(); | ||
} | ||
|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
qgsarcgisrestsourcewidget.h | ||
-------------------------------------- | ||
Date : January 2021 | ||
Copyright : (C) 2021 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 QGSARCGISRESTSOURCEWIDGET_H | ||
#define QGSARCGISRESTSOURCEWIDGET_H | ||
|
||
#include "qgsprovidersourcewidget.h" | ||
#include "ui_qgsarcgisrestsourcewidgetbase.h" | ||
#include <QVariantMap> | ||
|
||
class QgsArcGisRestSourceWidget : public QgsProviderSourceWidget, private Ui::QgsArcGisRestSourceWidgetBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsArcGisRestSourceWidget( const QString &providerKey, QWidget *parent = nullptr ); | ||
|
||
void setSourceUri( const QString &uri ) override; | ||
QString sourceUri() const override; | ||
|
||
void setUsername( const QString &username ); | ||
void setPassword( const QString &password ); | ||
void setAuthCfg( const QString &id ); | ||
|
||
QString username() const; | ||
QString password() const; | ||
QString authcfg() const; | ||
|
||
void setReferer( const QString &referer ); | ||
QString referer() const; | ||
|
||
private: | ||
|
||
const QString mProviderKey; | ||
QVariantMap mSourceParts; | ||
}; | ||
|
||
#endif // QGSARCGISRESTSOURCEWIDGET_H |
@@ -0,0 +1,88 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>QgsArcGisRestSourceWidgetBase</class> | ||
<widget class="QgsProviderSourceWidget" name="QgsArcGisRestSourceWidgetBase"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>362</width> | ||
<height>96</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>ArcGIS REST Connection</string> | ||
</property> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<property name="leftMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>0</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>0</number> | ||
</property> | ||
<item row="0" column="0" colspan="2"> | ||
<widget class="QGroupBox" name="mAuthGroupBox"> | ||
<property name="title"> | ||
<string>Authentication</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout_3"> | ||
<property name="leftMargin"> | ||
<number>6</number> | ||
</property> | ||
<property name="topMargin"> | ||
<number>6</number> | ||
</property> | ||
<property name="rightMargin"> | ||
<number>6</number> | ||
</property> | ||
<property name="bottomMargin"> | ||
<number>6</number> | ||
</property> | ||
<item> | ||
<widget class="QgsAuthSettingsWidget" name="mAuthSettings" native="true"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="lblReferer"> | ||
<property name="text"> | ||
<string>Referer</string> | ||
</property> | ||
<property name="buddy"> | ||
<cstring>mEditReferer</cstring> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QLineEdit" name="mEditReferer"> | ||
<property name="toolTip"> | ||
<string>Optional custom referer</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<customwidgets> | ||
<customwidget> | ||
<class>QgsAuthSettingsWidget</class> | ||
<extends>QWidget</extends> | ||
<header>auth/qgsauthsettingswidget.h</header> | ||
<container>1</container> | ||
</customwidget> | ||
<customwidget> | ||
<class>QgsProviderSourceWidget</class> | ||
<extends>QWidget</extends> | ||
<header>qgsprovidersourcewidget.h</header> | ||
<container>1</container> | ||
</customwidget> | ||
</customwidgets> | ||
<resources/> | ||
<connections/> | ||
</ui> |