QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
35  buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
36  connect( mEditName, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
37  connect( mEditUrl, &QLineEdit::textChanged, this, &QgsVectorTileConnectionDialog::updateOkButtonState );
38 }
39 
40 void QgsVectorTileConnectionDialog::setConnection( const QString &name, const QString &uri )
41 {
42  mEditName->setText( name );
43 
44  QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( uri );
45  mEditUrl->setText( conn.url );
46  mCheckBoxZMin->setChecked( conn.zMin != -1 );
47  mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
48  mCheckBoxZMax->setChecked( conn.zMax != -1 );
49  mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
50 }
51 
52 QString QgsVectorTileConnectionDialog::connectionUri() const
53 {
54  QgsVectorTileProviderConnection::Data conn;
55  conn.url = mEditUrl->text();
56  if ( mCheckBoxZMin->isChecked() )
57  conn.zMin = mSpinZMin->value();
58  if ( mCheckBoxZMax->isChecked() )
59  conn.zMax = mSpinZMax->value();
60  return QgsVectorTileProviderConnection::encodedUri( conn );
61 }
62 
63 QString QgsVectorTileConnectionDialog::connectionName() const
64 {
65  return mEditName->text();
66 }
67 
68 void QgsVectorTileConnectionDialog::updateOkButtonState()
69 {
70  bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
71  buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
72 }
73 
74 void QgsVectorTileConnectionDialog::accept()
75 {
76  if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
77  {
78  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() ) );
79  return;
80  }
81  QDialog::accept();
82 }
83 
qgsgui.h
qgsvectortileconnectiondialog.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:133
qgsvectortileconnection.h