QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsarcgisvectortileconnectiondialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsarcgisvectortileconnectiondialog.cpp
3 ---------------------
4 begin : September 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsarcgisvectortileconnectiondialog.cpp"
19#include "qgsgui.h"
20#include "qgshelp.h"
21
22#include <QMessageBox>
23#include <QPushButton>
24
26
27QgsArcgisVectorTileConnectionDialog::QgsArcgisVectorTileConnectionDialog( QWidget *parent )
28 : QDialog( parent )
29{
30 setupUi( this );
32
33 // Behavior for min and max zoom checkbox
34 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
35 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
36 mSpinZMax->setClearValue( 14 );
37
38 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
39 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [ = ]
40 {
41 QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
42 } );
43 connect( mEditName, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
44 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
45}
46
47void QgsArcgisVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
48{
49 mEditName->setText( name );
50
51 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
52 mEditUrl->setText( conn.url );
53
54 mCheckBoxZMin->setChecked( conn.zMin != -1 );
55 mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
56 mCheckBoxZMax->setChecked( conn.zMax != -1 );
57 mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
58
59 mAuthSettings->setUsername( conn.username );
60 mAuthSettings->setPassword( conn.password );
61 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
62 mAuthSettings->setConfigId( conn.authCfg );
63
64 mEditStyleUrl->setText( conn.styleUrl );
65}
66
67QString QgsArcgisVectorTileConnectionDialog::connectionUri() const
68{
69 QgsVectorTileProviderConnection::Data conn;
70 conn.url = mEditUrl->text();
71 if ( conn.url.endsWith( '/' ) )
72 conn.url = conn.url.left( conn.url.length() - 1 );
73
74 conn.serviceType = QgsVectorTileProviderConnection::ArcgisVectorTileService;
75
76 if ( mCheckBoxZMin->isChecked() )
77 conn.zMin = mSpinZMin->value();
78 if ( mCheckBoxZMax->isChecked() )
79 conn.zMax = mSpinZMax->value();
80
81 conn.username = mAuthSettings->username();
82 conn.password = mAuthSettings->password();
83 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
84 conn.authCfg = mAuthSettings->configId( );
85
86 conn.styleUrl = mEditStyleUrl->text();
87
88 return QgsVectorTileProviderConnection::encodedUri( conn );
89}
90
91QString QgsArcgisVectorTileConnectionDialog::connectionName() const
92{
93 return mEditName->text();
94}
95
96void QgsArcgisVectorTileConnectionDialog::accept()
97{
98 if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
99 {
100 QMessageBox::warning( this, tr( "Connection Properties" ), tr( "The maximum zoom level (%1) cannot be lower than the minimum zoom level (%2)." ).arg( mSpinZMax->value() ).arg( mSpinZMin->value() ) );
101 return;
102 }
103 QDialog::accept();
104}
105
106void QgsArcgisVectorTileConnectionDialog::updateOkButtonState()
107{
108 const bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
109 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
110}
111
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:209
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
static const QString KEY_REFERER
Used in settings as the referer key.