31 if ( QgsVectorTileLayerItem *layerItem = qobject_cast< QgsVectorTileLayerItem * >( item ) )
33 QAction *actionEdit =
new QAction( tr(
"Edit Connection…" ), menu );
34 connect( actionEdit, &QAction::triggered,
this, [layerItem] { editConnection( layerItem ); } );
35 menu->addAction( actionEdit );
37 QAction *actionDelete =
new QAction( tr(
"Remove Connection" ), menu );
38 connect( actionDelete, &QAction::triggered,
this, [layerItem] { deleteConnection( layerItem ); } );
39 menu->addAction( actionDelete );
42 if ( QgsVectorTileRootItem *rootItem = qobject_cast< QgsVectorTileRootItem * >( item ) )
44 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ), menu );
45 connect( actionNew, &QAction::triggered,
this, [rootItem] { newConnection( rootItem ); } );
46 menu->addAction( actionNew );
48 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ), menu );
49 connect( actionNewArcGISConnection, &QAction::triggered,
this, [rootItem] { newArcGISConnection( rootItem ); } );
50 menu->addAction( actionNewArcGISConnection );
54 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ), menu );
55 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
56 menu->addAction( actionSaveXyzTilesServers );
58 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ), menu );
59 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
60 menu->addAction( actionLoadXyzTilesServers );
64void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
66 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( item->
name() );
67 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
69 switch ( connection.serviceType )
71 case QgsVectorTileProviderConnection::Generic:
73 QgsVectorTileConnectionDialog dlg;
75 dlg.setConnection( item->
name(), uri );
79 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
80 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
81 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
85 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
87 QgsArcgisVectorTileConnectionDialog dlg;
89 dlg.setConnection( item->
name(), uri );
93 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
94 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
95 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
103void QgsVectorTileDataItemGuiProvider::deleteConnection(
QgsDataItem *item )
105 if ( QMessageBox::question(
nullptr, tr(
"Remove Connection" ), tr(
"Are you sure you want to remove the connection “%1”?" ).arg( item->
name() ),
106 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
109 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
114void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
116 QgsVectorTileConnectionDialog dlg;
120 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
121 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
126void QgsVectorTileDataItemGuiProvider::newArcGISConnection(
QgsDataItem *item )
128 QgsArcgisVectorTileConnectionDialog dlg;
132 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
133 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
138void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
144void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
146 const QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(),
147 tr(
"XML files (*.xml *.XML)" ) );
148 if ( fileName.isEmpty() )
154 if ( dlg.exec() == QDialog::Accepted )
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
Base class for all items in the model.
QString name() const
Returns the name of the item (the displayed text for the item).
virtual void refreshConnections(const QString &providerKey=QString())
Causes a data item provider to refresh all registered connections.
QgsDataItem * parent() const
Gets item parent.