QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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"
20 
21 #include <QMessageBox>
22 #include <QPushButton>
23 
25 
26 QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
27  : QDialog( parent )
28 {
29  setupUi( this );
31 
32  // Behavior for min and max zoom checkbox
33  connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
34  connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
35  mSpinZMax->setClearValue( 14 );
36 
37  buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
38  connect( buttonBox, &QDialogButtonBox::helpRequested, this, [ = ]
39  {
40  QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#using-vector-tiles-services" ) );
41  } );
42  connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
43  connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
44 }
45 
46 void QgsVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
47 {
48  mEditName->setText( name );
49 
50  const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
51  mEditUrl->setText( conn.url );
52  mCheckBoxZMin->setChecked( conn.zMin != -1 );
53  mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
54  mCheckBoxZMax->setChecked( conn.zMax != -1 );
55  mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
56 
57  mAuthSettings->setUsername( conn.username );
58  mAuthSettings->setPassword( conn.password );
59  mEditReferer->setText( conn.referer );
60  mAuthSettings->setConfigId( conn.authCfg );
61 
62  mEditStyleUrl->setText( conn.styleUrl );
63 }
64 
65 QString QgsVectorTileConnectionDialog::connectionUri() const
66 {
67  QgsVectorTileProviderConnection::Data conn;
68  conn.url = mEditUrl->text();
69  if ( mCheckBoxZMin->isChecked() )
70  conn.zMin = mSpinZMin->value();
71  if ( mCheckBoxZMax->isChecked() )
72  conn.zMax = mSpinZMax->value();
73  conn.username = mAuthSettings->username();
74  conn.password = mAuthSettings->password();
75  conn.referer = mEditReferer->text();
76  conn.authCfg = mAuthSettings->configId( );
77  conn.styleUrl = mEditStyleUrl->text();
78  return QgsVectorTileProviderConnection::encodedUri( conn );
79 }
80 
81 QString QgsVectorTileConnectionDialog::connectionName() const
82 {
83  return mEditName->text();
84 }
85 
86 void QgsVectorTileConnectionDialog::updateOkButtonState()
87 {
88  const bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
89  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
90 }
91 
92 void QgsVectorTileConnectionDialog::accept()
93 {
94  if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
95  {
96  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() ) );
97  return;
98  }
99  QDialog::accept();
100 }
101 
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:168
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36