23 #include <QFileDialog>
24 #include <QMessageBox>
30 if ( QgsVectorTileLayerItem *layerItem = qobject_cast< QgsVectorTileLayerItem * >( item ) )
32 QAction *actionEdit =
new QAction( tr(
"Edit…" ),
this );
33 connect( actionEdit, &QAction::triggered,
this, [layerItem] { editConnection( layerItem ); } );
34 menu->addAction( actionEdit );
36 QAction *actionDelete =
new QAction( tr(
"Delete" ),
this );
37 connect( actionDelete, &QAction::triggered,
this, [layerItem] { deleteConnection( layerItem ); } );
38 menu->addAction( actionDelete );
41 if ( QgsVectorTileRootItem *rootItem = qobject_cast< QgsVectorTileRootItem * >( item ) )
43 QAction *actionNew =
new QAction( tr(
"New Connection…" ),
this );
44 connect( actionNew, &QAction::triggered,
this, [rootItem] { newConnection( rootItem ); } );
45 menu->addAction( actionNew );
47 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ),
this );
48 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
49 menu->addAction( actionSaveXyzTilesServers );
51 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ),
this );
52 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
53 menu->addAction( actionLoadXyzTilesServers );
57 void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
59 QgsVectorTileConnectionDialog dlg;
60 QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( item->
name() ) );
61 dlg.setConnection( item->
name(), uri );
65 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
66 QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
67 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
72 void QgsVectorTileDataItemGuiProvider::deleteConnection(
QgsDataItem *item )
74 if ( QMessageBox::question(
nullptr, tr(
"Delete Connection" ), tr(
"Are you sure you want to delete the connection “%1”?" ).arg( item->
name() ),
75 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
78 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
83 void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
85 QgsVectorTileConnectionDialog dlg;
89 QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
90 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
95 void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
101 void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
103 QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(),
104 tr(
"XML files (*.xml *.XML)" ) );
105 if ( fileName.isEmpty() )