QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
41 } );
42 connect( mEditName, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
43 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
44}
45
46void QgsArcgisVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
47{
48 mEditName->setText( name );
49
50 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
51 mEditUrl->setText( conn.url );
52
53 mCheckBoxZMin->setChecked( conn.zMin != -1 );
54 mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
55 mCheckBoxZMax->setChecked( conn.zMax != -1 );
56 mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
57
58 mAuthSettings->setUsername( conn.username );
59 mAuthSettings->setPassword( conn.password );
60 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
61 mAuthSettings->setConfigId( conn.authCfg );
62
63 mEditStyleUrl->setText( conn.styleUrl );
64}
65
66QString QgsArcgisVectorTileConnectionDialog::connectionUri() const
67{
68 QgsVectorTileProviderConnection::Data conn;
69 conn.url = mEditUrl->text();
70 if ( conn.url.endsWith( '/' ) )
71 conn.url = conn.url.left( conn.url.length() - 1 );
72
73 conn.serviceType = QgsVectorTileProviderConnection::ArcgisVectorTileService;
74
75 if ( mCheckBoxZMin->isChecked() )
76 conn.zMin = mSpinZMin->value();
77 if ( mCheckBoxZMax->isChecked() )
78 conn.zMax = mSpinZMax->value();
79
80 conn.username = mAuthSettings->username();
81 conn.password = mAuthSettings->password();
82 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
83 conn.authCfg = mAuthSettings->configId();
84
85 conn.styleUrl = mEditStyleUrl->text();
86
87 return QgsVectorTileProviderConnection::encodedUri( conn );
88}
89
90QString QgsArcgisVectorTileConnectionDialog::connectionName() const
91{
92 return mEditName->text();
93}
94
95void QgsArcgisVectorTileConnectionDialog::accept()
96{
97 if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
98 {
99 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() ) );
100 return;
101 }
102 QDialog::accept();
103}
104
105void QgsArcgisVectorTileConnectionDialog::updateOkButtonState()
106{
107 const bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
108 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
109}
110
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:210
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.