QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
18#include "qgsgui.h"
19#include "qgshelp.h"
20
21#include <QMessageBox>
22#include <QPushButton>
23
25
26QgsArcgisVectorTileConnectionDialog::QgsArcgisVectorTileConnectionDialog( QWidget *parent )
27 : QDialog( parent )
28{
29 setupUi( this );
31
32 // Behavior for min and max zoom checkbox
33 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
34 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
35 mSpinZMax->setClearValue( 14 );
36
37 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
38 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [ = ]
39 {
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:194
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.