22#include "moc_qgsvectortilesourceselect.cpp"
44 setWindowTitle( tr(
"Add Vector Tile Layer" ) );
46 mRadioSourceService->setChecked(
true );
47 mStackedWidget->setCurrentIndex( 1 );
49 connect( mRadioSourceFile, &QRadioButton::toggled,
this, [
this]
51 mStackedWidget->setCurrentIndex( 0 );
53 emit enableButtons( !mFileWidget->filePath().isEmpty() );
55 connect( mRadioSourceService, &QRadioButton::toggled,
this, [
this]
57 mStackedWidget->setCurrentIndex( 1 );
59 emit enableButtons( !cmbConnections->currentText().isEmpty() );
62 btnNew->setPopupMode( QToolButton::InstantPopup );
63 QMenu *newMenu =
new QMenu( btnNew );
65 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ),
this );
66 connect( actionNew, &QAction::triggered,
this, &QgsVectorTileSourceSelect::btnNew_clicked );
67 newMenu->addAction( actionNew );
69 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ),
this );
70 connect( actionNewArcGISConnection, &QAction::triggered,
this, &QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection );
71 newMenu->addAction( actionNewArcGISConnection );
73 btnNew->setMenu( newMenu );
75 connect( btnEdit, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnEdit_clicked );
76 connect( btnDelete, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnDelete_clicked );
77 connect( btnSave, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnSave_clicked );
78 connect( btnLoad, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnLoad_clicked );
79 connect( cmbConnections, &QComboBox::currentTextChanged,
this, &QgsVectorTileSourceSelect::cmbConnections_currentTextChanged );
80 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileSourceSelect::showHelp );
81 setupButtons( buttonBox );
83 populateConnectionList();
85 mFileWidget->setDialogTitle( tr(
"Open Vector Tile Dataset" ) );
88 mFileWidget->setOptions( QFileDialog::HideNameFilterDetails );
91 emit enableButtons( !path.isEmpty() );
95void QgsVectorTileSourceSelect::btnNew_clicked()
97 QgsVectorTileConnectionDialog nc(
this );
100 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
101 populateConnectionList();
102 QgsVectorTileProviderConnection::setSelectedConnection( nc.connectionName() );
103 setConnectionListPosition();
104 emit connectionsChanged();
108void QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection()
110 QgsArcgisVectorTileConnectionDialog nc(
this );
113 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
114 populateConnectionList();
115 emit connectionsChanged();
119void QgsVectorTileSourceSelect::btnEdit_clicked()
121 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( cmbConnections->currentText() );
122 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
124 switch ( connection.serviceType )
126 case QgsVectorTileProviderConnection::Generic:
128 QgsVectorTileConnectionDialog nc(
this );
129 nc.setConnection( cmbConnections->currentText(), uri );
132 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
133 populateConnectionList();
134 emit connectionsChanged();
139 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
141 QgsArcgisVectorTileConnectionDialog nc(
this );
143 nc.setConnection( cmbConnections->currentText(), uri );
146 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
147 populateConnectionList();
148 emit connectionsChanged();
155void QgsVectorTileSourceSelect::btnDelete_clicked()
157 const QString msg = tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
158 .arg( cmbConnections->currentText() );
159 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
162 QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );
164 populateConnectionList();
165 emit connectionsChanged();
168void QgsVectorTileSourceSelect::btnSave_clicked()
174void QgsVectorTileSourceSelect::btnLoad_clicked()
176 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Connections" ), QDir::homePath(),
177 tr(
"XML files (*.xml *.XML)" ) );
178 if ( fileName.isEmpty() )
185 populateConnectionList();
188void QgsVectorTileSourceSelect::addButtonClicked()
190 if ( mRadioSourceService->isChecked() )
192 const QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
194 emit addVectorTileLayer( uri, cmbConnections->currentText() );
198 else if ( mRadioSourceFile->isChecked() )
200 const QString filePath = mFileWidget->filePath();
207 providerKey = details.metadata()->key();
212 parts.insert( QStringLiteral(
"path" ), filePath );
222void QgsVectorTileSourceSelect::populateConnectionList()
224 cmbConnections->blockSignals(
true );
225 cmbConnections->clear();
226 cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
227 cmbConnections->blockSignals(
false );
229 btnEdit->setDisabled( cmbConnections->count() == 0 );
230 btnDelete->setDisabled( cmbConnections->count() == 0 );
231 btnSave->setDisabled( cmbConnections->count() == 0 );
232 cmbConnections->setDisabled( cmbConnections->count() == 0 );
234 setConnectionListPosition();
237void QgsVectorTileSourceSelect::setConnectionListPosition()
239 const QString toSelect = QgsVectorTileProviderConnection::selectedConnection();
241 cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );
243 if ( cmbConnections->currentIndex() < 0 )
245 if ( toSelect.isNull() )
246 cmbConnections->setCurrentIndex( 0 );
248 cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
251 emit enableButtons( !cmbConnections->currentText().isEmpty() );
254void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged(
const QString &text )
256 QgsVectorTileProviderConnection::setSelectedConnection( text );
257 emit enableButtons( !text.isEmpty() );
260void QgsVectorTileSourceSelect::showHelp()
262 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/opening_data.html#using-vector-tiles-services" ) );
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Contains information pertaining to a candidate provider.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
WidgetMode
Different ways a source select dialog can be used.
QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri(const QString &uri) const
Returns the details for the preferred provider(s) for opening the specified uri.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
static QString suggestLayerNameFromFilePath(const QString &path)
Suggests a suitable layer name given only a file path.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH