QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
20 #include <QMessageBox>
21 #include <QPushButton>
22 
24 
25 QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
26  : QDialog( parent )
27 {
28  setupUi( this );
30 
31  // Behavior for min and max zoom checkbox
32  connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
33  connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
34  mSpinZMax->setClearValue( 14 );
35 
36  buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
37  connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
38  connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
39 }
40 
41 void QgsVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
42 {
43  mEditName->setText( name );
44 
45  QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
46  mEditUrl->setText( conn.url );
47  mCheckBoxZMin->setChecked( conn.zMin != -1 );
48  mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
49  mCheckBoxZMax->setChecked( conn.zMax != -1 );
50  mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
51 
52  mAuthSettings->setUsername( conn.username );
53  mAuthSettings->setPassword( conn.password );
54  mEditReferer->setText( conn.referer );
55  mAuthSettings->setConfigId( conn.authCfg );
56 
57  mEditStyleUrl->setText( conn.styleUrl );
58 }
59 
60 QString QgsVectorTileConnectionDialog::connectionUri() const
61 {
62  QgsVectorTileProviderConnection::Data conn;
63  conn.url = mEditUrl->text();
64  if ( mCheckBoxZMin->isChecked() )
65  conn.zMin = mSpinZMin->value();
66  if ( mCheckBoxZMax->isChecked() )
67  conn.zMax = mSpinZMax->value();
68  conn.username = mAuthSettings->username();
69  conn.password = mAuthSettings->password();
70  conn.referer = mEditReferer->text();
71  conn.authCfg = mAuthSettings->configId( );
72  conn.styleUrl = mEditStyleUrl->text();
73  return QgsVectorTileProviderConnection::encodedUri( conn );
74 }
75 
76 QString QgsVectorTileConnectionDialog::connectionName() const
77 {
78  return mEditName->text();
79 }
80 
81 void QgsVectorTileConnectionDialog::updateOkButtonState()
82 {
83  bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
84  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
85 }
86 
87 void QgsVectorTileConnectionDialog::accept()
88 {
89  if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
90  {
91  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() ) );
92  return;
93  }
94  QDialog::accept();
95 }
96 
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:156