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