24 #include <QFileDialog>
25 #include <QMessageBox>
31 if ( QgsVectorTileLayerItem *layerItem = qobject_cast< QgsVectorTileLayerItem * >( item ) )
33 QAction *actionEdit =
new QAction( tr(
"Edit…" ),
this );
34 connect( actionEdit, &QAction::triggered,
this, [layerItem] { editConnection( layerItem ); } );
35 menu->addAction( actionEdit );
37 QAction *actionDelete =
new QAction( tr(
"Delete" ),
this );
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…" ),
this );
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…" ),
this );
49 connect( actionNewArcGISConnection, &QAction::triggered,
this, [rootItem] { newArcGISConnection( rootItem ); } );
50 menu->addAction( actionNewArcGISConnection );
54 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ),
this );
55 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
56 menu->addAction( actionSaveXyzTilesServers );
58 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ),
this );
59 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
60 menu->addAction( actionLoadXyzTilesServers );
64 void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
66 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( item->
name() );
67 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 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 QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
95 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
103 void QgsVectorTileDataItemGuiProvider::deleteConnection(
QgsDataItem *item )
105 if ( QMessageBox::question(
nullptr, tr(
"Delete Connection" ), tr(
"Are you sure you want to delete the connection “%1”?" ).arg( item->
name() ),
106 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
109 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
114 void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
116 QgsVectorTileConnectionDialog dlg;
120 QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
121 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
126 void QgsVectorTileDataItemGuiProvider::newArcGISConnection(
QgsDataItem *item )
128 QgsArcgisVectorTileConnectionDialog dlg;
132 QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
133 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
138 void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
144 void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
146 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 )