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