QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
18#include "qgsgui.h"
19#include "qgshelp.h"
21
22#include <QMessageBox>
23#include <QPushButton>
24
26
27
28QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
29 : QDialog( parent )
30{
31 setupUi( this );
33
34 mEditUrl->setPlaceholderText( tr( "URL(s) can be determined from the style." ) );
35
36 // Behavior for min and max zoom checkbox
37 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
38 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
39 mSpinZMax->setClearValue( 14 );
40
41 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
42 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [ = ]
43 {
44 QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
45 } );
46 connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
47 connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
48 connect( mEditStyleUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
49}
50
51void QgsVectorTileConnectionDialog::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 mCheckBoxZMin->setChecked( conn.zMin != -1 );
58 mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
59 mCheckBoxZMax->setChecked( conn.zMax != -1 );
60 mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
61
62 mAuthSettings->setUsername( conn.username );
63 mAuthSettings->setPassword( conn.password );
64 mEditReferer->setText( conn.httpHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
65 mAuthSettings->setConfigId( conn.authCfg );
66
67 mEditStyleUrl->setText( conn.styleUrl );
68}
69
70QString QgsVectorTileConnectionDialog::connectionUri() const
71{
72 QgsVectorTileProviderConnection::Data conn;
73 conn.url = mEditUrl->text();
74 if ( mCheckBoxZMin->isChecked() )
75 conn.zMin = mSpinZMin->value();
76 if ( mCheckBoxZMax->isChecked() )
77 conn.zMax = mSpinZMax->value();
78 conn.username = mAuthSettings->username();
79 conn.password = mAuthSettings->password();
80 conn.httpHeaders[QgsHttpHeaders::KEY_REFERER] = mEditReferer->text();
81 conn.authCfg = mAuthSettings->configId( );
82 conn.styleUrl = mEditStyleUrl->text();
83 return QgsVectorTileProviderConnection::encodedUri( conn );
84}
85
86QString QgsVectorTileConnectionDialog::connectionName() const
87{
88 return mEditName->text();
89}
90
91void QgsVectorTileConnectionDialog::updateOkButtonState()
92{
93 const bool enabled = !mEditName->text().isEmpty() && ( !mEditUrl->text().isEmpty() || !mEditStyleUrl->text().isEmpty() );
94 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
95}
96
97
98void QgsVectorTileConnectionDialog::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
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:208
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:39
static const QString KEY_REFERER
Used in settings as the referer key.