QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
18#include "qgsgui.h"
19#include "qgshelp.h"
21
22#include <QMessageBox>
23#include <QPushButton>
24
25#include "moc_qgsarcgisvectortileconnectiondialog.cpp"
26
28
29QgsArcgisVectorTileConnectionDialog::QgsArcgisVectorTileConnectionDialog( QWidget *parent )
30 : QDialog( parent )
31{
32 setupUi( this );
34
35 // Behavior for min and max zoom checkbox
36 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
37 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
38 mSpinZMax->setClearValue( 14 );
39
40 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
41 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
42 QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
43 } );
44 connect( mEditName, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
45 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
46}
47
48void QgsArcgisVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
49{
50 mEditName->setText( name );
51
52 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
53 mEditUrl->setText( conn.url );
54
55 mCheckBoxZMin->setChecked( conn.zMin != -1 );
56 mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
57 mCheckBoxZMax->setChecked( conn.zMax != -1 );
58 mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
59
60 mAuthSettings->setUsername( conn.username );
61 mAuthSettings->setPassword( conn.password );
62 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
63 mAuthSettings->setConfigId( conn.authCfg );
64
65 mEditStyleUrl->setText( conn.styleUrl );
66}
67
68QString QgsArcgisVectorTileConnectionDialog::connectionUri() const
69{
70 QgsVectorTileProviderConnection::Data conn;
71 conn.url = mEditUrl->text();
72 if ( conn.url.endsWith( '/' ) )
73 conn.url = conn.url.left( conn.url.length() - 1 );
74
75 conn.serviceType = QgsVectorTileProviderConnection::ArcgisVectorTileService;
76
77 if ( mCheckBoxZMin->isChecked() )
78 conn.zMin = mSpinZMin->value();
79 if ( mCheckBoxZMax->isChecked() )
80 conn.zMax = mSpinZMax->value();
81
82 conn.username = mAuthSettings->username();
83 conn.password = mAuthSettings->password();
84 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
85 conn.authCfg = mAuthSettings->configId();
86
87 conn.styleUrl = mEditStyleUrl->text();
88
89 return QgsVectorTileProviderConnection::encodedUri( conn );
90}
91
92QString QgsArcgisVectorTileConnectionDialog::connectionName() const
93{
94 return mEditName->text();
95}
96
97void QgsArcgisVectorTileConnectionDialog::accept()
98{
99 if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
100 {
101 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() ) );
102 return;
103 }
104 QDialog::accept();
105}
106
107void QgsArcgisVectorTileConnectionDialog::updateOkButtonState()
108{
109 const bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
110 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
111}
112
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:221
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
static const QString KEY_REFERER
Used in settings as the referer key.