QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsarcgisvectortileconnectiondialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsarcgisvectortileconnectiondialog.cpp
3  ---------------------
4  begin : September 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson 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 QgsArcgisVectorTileConnectionDialog::QgsArcgisVectorTileConnectionDialog( 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, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
38  connect( mEditUrl, &QLineEdit::textChanged, this, &QgsArcgisVectorTileConnectionDialog::updateOkButtonState );
39 }
40 
41 void QgsArcgisVectorTileConnectionDialog::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 
48  mCheckBoxZMin->setChecked( conn.zMin != -1 );
49  mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
50  mCheckBoxZMax->setChecked( conn.zMax != -1 );
51  mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
52 
53  mAuthSettings->setUsername( conn.username );
54  mAuthSettings->setPassword( conn.password );
55  mEditReferer->setText( conn.referer );
56  mAuthSettings->setConfigId( conn.authCfg );
57 
58  mEditStyleUrl->setText( conn.styleUrl );
59 }
60 
61 QString QgsArcgisVectorTileConnectionDialog::connectionUri() const
62 {
63  QgsVectorTileProviderConnection::Data conn;
64  conn.url = mEditUrl->text();
65  if ( conn.url.endsWith( '/' ) )
66  conn.url = conn.url.left( conn.url.length() - 1 );
67 
68  conn.serviceType = QgsVectorTileProviderConnection::ArcgisVectorTileService;
69 
70  if ( mCheckBoxZMin->isChecked() )
71  conn.zMin = mSpinZMin->value();
72  if ( mCheckBoxZMax->isChecked() )
73  conn.zMax = mSpinZMax->value();
74 
75  conn.username = mAuthSettings->username();
76  conn.password = mAuthSettings->password();
77  conn.referer = mEditReferer->text();
78  conn.authCfg = mAuthSettings->configId( );
79 
80  conn.styleUrl = mEditStyleUrl->text();
81 
82  return QgsVectorTileProviderConnection::encodedUri( conn );
83 }
84 
85 QString QgsArcgisVectorTileConnectionDialog::connectionName() const
86 {
87  return mEditName->text();
88 }
89 
90 void QgsArcgisVectorTileConnectionDialog::accept()
91 {
92  if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
93  {
94  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() ) );
95  return;
96  }
97  QDialog::accept();
98 }
99 
100 void QgsArcgisVectorTileConnectionDialog::updateOkButtonState()
101 {
102  bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
103  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
104 }
105 
qgsgui.h
QgsGui::enableAutoGeometryRestore
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:139
qgsvectortileconnection.h
qgsarcgisvectortileconnectiondialog.h