20 #include <QMessageBox>
21 #include <QPushButton>
25 QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
32 connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
33 connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
34 mSpinZMax->setClearValue( 14 );
36 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
37 connect( mEditName, &QLineEdit::textChanged,
this, &QgsVectorTileConnectionDialog::updateOkButtonState );
38 connect( mEditUrl, &QLineEdit::textChanged,
this, &QgsVectorTileConnectionDialog::updateOkButtonState );
41 void QgsVectorTileConnectionDialog::setConnection(
const QString &name,
const QString &uri )
43 mEditName->setText( name );
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 );
52 mAuthSettings->setUsername( conn.username );
53 mAuthSettings->setPassword( conn.password );
54 mEditReferer->setText( conn.referer );
55 mAuthSettings->setConfigId( conn.authCfg );
57 mEditStyleUrl->setText( conn.styleUrl );
60 QString QgsVectorTileConnectionDialog::connectionUri()
const
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 );
76 QString QgsVectorTileConnectionDialog::connectionName()
const
78 return mEditName->text();
81 void QgsVectorTileConnectionDialog::updateOkButtonState()
83 bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
84 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
87 void QgsVectorTileConnectionDialog::accept()
89 if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
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() ) );