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 );
35 buttonBox->button( QDialogButtonBox::Ok )->setDisabled(
true );
36 connect( mEditName, &QLineEdit::textChanged,
this, &QgsVectorTileConnectionDialog::updateOkButtonState );
37 connect( mEditUrl, &QLineEdit::textChanged,
this, &QgsVectorTileConnectionDialog::updateOkButtonState );
40 void QgsVectorTileConnectionDialog::setConnection(
const QString &name,
const QString &uri )
42 mEditName->setText( name );
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 );
52 QString QgsVectorTileConnectionDialog::connectionUri()
const
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 );
63 QString QgsVectorTileConnectionDialog::connectionName()
const
65 return mEditName->text();
68 void QgsVectorTileConnectionDialog::updateOkButtonState()
70 bool enabled = !mEditName->text().isEmpty() && !mEditUrl->text().isEmpty();
71 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
74 void QgsVectorTileConnectionDialog::accept()
76 if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
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() ) );