43 setWindowTitle( tr(
"Add Vector Tile Layer" ) );
45 mRadioSourceService->setChecked(
true );
46 mStackedWidget->setCurrentIndex( 1 );
48 connect( mRadioSourceFile, &QRadioButton::toggled,
this, [
this]
50 mStackedWidget->setCurrentIndex( 0 );
52 emit enableButtons( !mFileWidget->filePath().isEmpty() );
54 connect( mRadioSourceService, &QRadioButton::toggled,
this, [
this]
56 mStackedWidget->setCurrentIndex( 1 );
58 emit enableButtons( !cmbConnections->currentText().isEmpty() );
61 btnNew->setPopupMode( QToolButton::InstantPopup );
62 QMenu *newMenu =
new QMenu( btnNew );
64 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ),
this );
65 connect( actionNew, &QAction::triggered,
this, &QgsVectorTileSourceSelect::btnNew_clicked );
66 newMenu->addAction( actionNew );
68 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ),
this );
69 connect( actionNewArcGISConnection, &QAction::triggered,
this, &QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection );
70 newMenu->addAction( actionNewArcGISConnection );
72 btnNew->setMenu( newMenu );
74 connect( btnEdit, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnEdit_clicked );
75 connect( btnDelete, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnDelete_clicked );
76 connect( btnSave, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnSave_clicked );
77 connect( btnLoad, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnLoad_clicked );
78 connect( cmbConnections, &QComboBox::currentTextChanged,
this, &QgsVectorTileSourceSelect::cmbConnections_currentTextChanged );
79 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileSourceSelect::showHelp );
80 setupButtons( buttonBox );
82 populateConnectionList();
84 mFileWidget->setDialogTitle( tr(
"Open Vector Tile Dataset" ) );
87 mFileWidget->setOptions( QFileDialog::HideNameFilterDetails );
90 emit enableButtons( !path.isEmpty() );
94void QgsVectorTileSourceSelect::btnNew_clicked()
96 QgsVectorTileConnectionDialog nc(
this );
99 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
100 populateConnectionList();
101 QgsVectorTileProviderConnection::setSelectedConnection( nc.connectionName() );
102 setConnectionListPosition();
103 emit connectionsChanged();
107void QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection()
109 QgsArcgisVectorTileConnectionDialog nc(
this );
112 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
113 populateConnectionList();
114 emit connectionsChanged();
118void QgsVectorTileSourceSelect::btnEdit_clicked()
120 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( cmbConnections->currentText() );
121 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
123 switch ( connection.serviceType )
125 case QgsVectorTileProviderConnection::Generic:
127 QgsVectorTileConnectionDialog nc(
this );
128 nc.setConnection( cmbConnections->currentText(), uri );
131 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
132 populateConnectionList();
133 emit connectionsChanged();
138 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
140 QgsArcgisVectorTileConnectionDialog nc(
this );
142 nc.setConnection( cmbConnections->currentText(), uri );
145 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
146 populateConnectionList();
147 emit connectionsChanged();
154void QgsVectorTileSourceSelect::btnDelete_clicked()
156 const QString msg = tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
157 .arg( cmbConnections->currentText() );
158 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
161 QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );
163 populateConnectionList();
164 emit connectionsChanged();
167void QgsVectorTileSourceSelect::btnSave_clicked()
173void QgsVectorTileSourceSelect::btnLoad_clicked()
175 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Connections" ), QDir::homePath(),
176 tr(
"XML files (*.xml *.XML)" ) );
177 if ( fileName.isEmpty() )
184 populateConnectionList();
187void QgsVectorTileSourceSelect::addButtonClicked()
189 if ( mRadioSourceService->isChecked() )
191 const QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
193 emit addVectorTileLayer( uri, cmbConnections->currentText() );
197 else if ( mRadioSourceFile->isChecked() )
199 const QString filePath = mFileWidget->filePath();
206 providerKey = details.metadata()->key();
211 parts.insert( QStringLiteral(
"path" ), filePath );
221void QgsVectorTileSourceSelect::populateConnectionList()
223 cmbConnections->blockSignals(
true );
224 cmbConnections->clear();
225 cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
226 cmbConnections->blockSignals(
false );
228 btnEdit->setDisabled( cmbConnections->count() == 0 );
229 btnDelete->setDisabled( cmbConnections->count() == 0 );
230 btnSave->setDisabled( cmbConnections->count() == 0 );
231 cmbConnections->setDisabled( cmbConnections->count() == 0 );
233 setConnectionListPosition();
236void QgsVectorTileSourceSelect::setConnectionListPosition()
238 const QString toSelect = QgsVectorTileProviderConnection::selectedConnection();
240 cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );
242 if ( cmbConnections->currentIndex() < 0 )
244 if ( toSelect.isNull() )
245 cmbConnections->setCurrentIndex( 0 );
247 cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
250 emit enableButtons( !cmbConnections->currentText().isEmpty() );
253void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged(
const QString &text )
255 QgsVectorTileProviderConnection::setSelectedConnection( text );
256 emit enableButtons( !text.isEmpty() );
259void QgsVectorTileSourceSelect::showHelp()
261 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