25 #include <QFileDialog>
26 #include <QMessageBox>
35 setWindowTitle( tr(
"Add Vector Tile Layer" ) );
36 mConnectionsGroupBox->setTitle( tr(
"Vector Tile Connections" ) );
40 connect( btnNew, &QPushButton::clicked,
this, &QgsVectorTileSourceSelect::btnNew_clicked );
41 connect( btnEdit, &QPushButton::clicked,
this, &QgsVectorTileSourceSelect::btnEdit_clicked );
42 connect( btnDelete, &QPushButton::clicked,
this, &QgsVectorTileSourceSelect::btnDelete_clicked );
43 connect( btnSave, &QPushButton::clicked,
this, &QgsVectorTileSourceSelect::btnSave_clicked );
44 connect( btnLoad, &QPushButton::clicked,
this, &QgsVectorTileSourceSelect::btnLoad_clicked );
45 connect( cmbConnections, &QComboBox::currentTextChanged,
this, &QgsVectorTileSourceSelect::cmbConnections_currentTextChanged );
46 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileSourceSelect::showHelp );
47 setupButtons( buttonBox );
50 buttonBox->button( QDialogButtonBox::Help )->setEnabled(
false );
52 populateConnectionList();
55 void QgsVectorTileSourceSelect::btnNew_clicked()
57 QgsVectorTileConnectionDialog nc(
this );
60 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
61 populateConnectionList();
62 emit connectionsChanged();
66 void QgsVectorTileSourceSelect::btnEdit_clicked()
68 QgsVectorTileConnectionDialog nc(
this );
69 QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
70 nc.setConnection( cmbConnections->currentText(), uri );
73 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
74 populateConnectionList();
75 emit connectionsChanged();
79 void QgsVectorTileSourceSelect::btnDelete_clicked()
81 QString msg = tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
82 .arg( cmbConnections->currentText() );
83 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
86 QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );
88 populateConnectionList();
89 emit connectionsChanged();
92 void QgsVectorTileSourceSelect::btnSave_clicked()
98 void QgsVectorTileSourceSelect::btnLoad_clicked()
100 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Connections" ), QDir::homePath(),
101 tr(
"XML files (*.xml *.XML)" ) );
102 if ( fileName.isEmpty() )
109 populateConnectionList();
112 void QgsVectorTileSourceSelect::addButtonClicked()
114 QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
115 emit addVectorTileLayer( uri, cmbConnections->currentText() );
118 void QgsVectorTileSourceSelect::populateConnectionList()
120 cmbConnections->blockSignals(
true );
121 cmbConnections->clear();
122 cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
123 cmbConnections->blockSignals(
false );
125 btnEdit->setDisabled( cmbConnections->count() == 0 );
126 btnDelete->setDisabled( cmbConnections->count() == 0 );
127 btnSave->setDisabled( cmbConnections->count() == 0 );
128 cmbConnections->setDisabled( cmbConnections->count() == 0 );
130 setConnectionListPosition();
133 void QgsVectorTileSourceSelect::setConnectionListPosition()
135 QString toSelect = QgsVectorTileProviderConnection::selectedConnection();
137 cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );
139 if ( cmbConnections->currentIndex() < 0 )
141 if ( toSelect.isNull() )
142 cmbConnections->setCurrentIndex( 0 );
144 cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
147 emit enableButtons( !cmbConnections->currentText().isEmpty() );
150 void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged(
const QString &text )
152 QgsVectorTileProviderConnection::setSelectedConnection( text );
153 emit enableButtons( !text.isEmpty() );
156 void QgsVectorTileSourceSelect::showHelp()