Skip to content
Permalink
Browse files

Allow changing the authentication setup for existing AFS/AMS layers

  • Loading branch information
nyalldawson committed Jan 12, 2021
1 parent 2e9c778 commit b44e94de040d2d0916f0ce26544ccf5bb087ba85
@@ -52,6 +52,7 @@ if (WITH_GUI)
qgsarcgisrestdataitemguiprovider.cpp
qgsarcgisrestprovidergui.cpp
qgsarcgisrestsourceselect.cpp
qgsarcgisrestsourcewidget.cpp
qgsnewarcgisrestconnection.cpp
)
endif()
@@ -20,7 +20,8 @@
#include "qgsarcgisrestdataitemguiprovider.h"
#include "qgsafsprovider.h"
#include "qgsarcgisrestsourceselect.h"

#include "qgsarcgisrestsourcewidget.h"
#include "qgsprovidersourcewidgetprovider.h"

//! Provider for AFS layers source select
class QgsArcGisRestSourceSelectProvider : public QgsSourceSelectProvider
@@ -37,6 +38,29 @@ class QgsArcGisRestSourceSelectProvider : public QgsSourceSelectProvider
}
};

class QgsArcGisRestSourceWidgetProvider : public QgsProviderSourceWidgetProvider
{
public:
QgsArcGisRestSourceWidgetProvider() : QgsProviderSourceWidgetProvider() {}
QString providerKey() const override
{
return QgsAfsProvider::AFS_PROVIDER_KEY;
}
bool canHandleLayer( QgsMapLayer *layer ) const override
{
if ( layer->providerType() != QgsAfsProvider::AFS_PROVIDER_KEY && layer->providerType() != QLatin1String( "arcgismapserver" ) )
return false;

return true;
}
QgsProviderSourceWidget *createWidget( QgsMapLayer *layer, QWidget *parent = nullptr ) override
{
if ( layer->providerType() != QgsAfsProvider::AFS_PROVIDER_KEY && layer->providerType() != QLatin1String( "arcgismapserver" ) )
return nullptr;

return new QgsArcGisRestSourceWidget( layer->providerType(), parent );
}
};

class QgsArcGisRestProviderGuiMetadata: public QgsProviderGuiMetadata
{
@@ -59,6 +83,13 @@ class QgsArcGisRestProviderGuiMetadata: public QgsProviderGuiMetadata
providers << new QgsArcGisRestSourceSelectProvider;
return providers;
}

QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders() override
{
QList<QgsProviderSourceWidgetProvider *> providers;
providers << new QgsArcGisRestSourceWidgetProvider();
return providers;
}
};


@@ -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>

0 comments on commit b44e94d

Please sign in to comment.
You can’t perform that action at this time.