QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsvectortileconnectiondialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortileconnectiondialog.cpp
3 ---------------------
4 begin : March 2020
5 copyright : (C) 2020 by Martin Dobias
6 email : wonder dot sk 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"
22
23#include <QMessageBox>
24#include <QPushButton>
25
26#include "moc_qgsvectortileconnectiondialog.cpp"
27
29
30
31QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
32 : QDialog( parent )
33{
34 setupUi( this );
36
37 mEditUrl->setPlaceholderText( tr( "URL(s) can be determined from the style." ) );
38
39 // Behavior for min and max zoom checkbox
40 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
41 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
42 mSpinZMax->setClearValue( 14 );
43
44 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
45 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
46 QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
47 } );
48 connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
49 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
50 connect( mEditStyleUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
51}
52
53void QgsVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
54{
55 mEditName->setText( name );
56
57 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
58 mEditUrl->setText( conn.url );
59 mCheckBoxZMin->setChecked( conn.zMin != -1 );
60 mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
61 mCheckBoxZMax->setChecked( conn.zMax != -1 );
62 mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
63
64 mAuthSettings->setUsername( conn.username );
65 mAuthSettings->setPassword( conn.password );
66 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
67 mAuthSettings->setConfigId( conn.authCfg );
68
69 mEditStyleUrl->setText( conn.styleUrl );
70}
71
72QString QgsVectorTileConnectionDialog::connectionUri() const
73{
74 QgsVectorTileProviderConnection::Data conn;
75 conn.url = mEditUrl->text();
76 if ( mCheckBoxZMin->isChecked() )
77 conn.zMin = mSpinZMin->value();
78 if ( mCheckBoxZMax->isChecked() )
79 conn.zMax = mSpinZMax->value();
80 conn.username = mAuthSettings->username();
81 conn.password = mAuthSettings->password();
82 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
83 conn.authCfg = mAuthSettings->configId();
84 conn.styleUrl = mEditStyleUrl->text();
85 return QgsVectorTileProviderConnection::encodedUri( conn );
86}
87
88QString QgsVectorTileConnectionDialog::connectionName() const
89{
90 return mEditName->text();
91}
92
93void QgsVectorTileConnectionDialog::updateOkButtonState()
94{
95 const bool enabled = !mEditName->text().isEmpty() && ( !mEditUrl->text().isEmpty() || !mEditStyleUrl->text().isEmpty() );
96 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
97}
98
99
100void QgsVectorTileConnectionDialog::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
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.