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