30void QgsVectorTileDataItemGuiProvider::populateContextMenu(
QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selection,
QgsDataItemGuiContext context )
32 if ( QgsVectorTileLayerItem *layerItem = qobject_cast< QgsVectorTileLayerItem * >( item ) )
34 QAction *actionEdit =
new QAction( tr(
"Edit Connection…" ), menu );
35 connect( actionEdit, &QAction::triggered,
this, [layerItem] { editConnection( layerItem ); } );
36 menu->addAction( actionEdit );
38 QAction *actionDuplicate =
new QAction( tr(
"Duplicate Connection" ), menu );
39 connect( actionDuplicate, &QAction::triggered,
this, [layerItem] { duplicateConnection( layerItem ); } );
40 menu->addAction( actionDuplicate );
42 const QList< QgsVectorTileLayerItem * > vtConnectionItems = QgsDataItem::filteredItems<QgsVectorTileLayerItem>( selection );
43 QAction *actionDelete =
new QAction( vtConnectionItems.size() > 1 ? tr(
"Remove Connections…" ) : tr(
"Remove Connection…" ), menu );
44 connect( actionDelete, &QAction::triggered,
this, [vtConnectionItems, context]
48 QgsVectorTileProviderConnection::deleteConnection( connectionName );
51 menu->addAction( actionDelete );
54 if ( QgsVectorTileRootItem *rootItem = qobject_cast< QgsVectorTileRootItem * >( item ) )
56 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ), menu );
57 connect( actionNew, &QAction::triggered,
this, [rootItem] { newConnection( rootItem ); } );
58 menu->addAction( actionNew );
60 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ), menu );
61 connect( actionNewArcGISConnection, &QAction::triggered,
this, [rootItem] { newArcGISConnection( rootItem ); } );
62 menu->addAction( actionNewArcGISConnection );
66 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ), menu );
67 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
68 menu->addAction( actionSaveXyzTilesServers );
70 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ), menu );
71 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
72 menu->addAction( actionLoadXyzTilesServers );
76void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
78 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( item->
name() );
79 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
81 switch ( connection.serviceType )
83 case QgsVectorTileProviderConnection::Generic:
85 QgsVectorTileConnectionDialog dlg;
87 dlg.setConnection( item->
name(), uri );
91 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
92 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
93 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
97 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
99 QgsArcgisVectorTileConnectionDialog dlg;
101 dlg.setConnection( item->
name(), uri );
105 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
106 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
107 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
115void QgsVectorTileDataItemGuiProvider::duplicateConnection(
QgsDataItem *item )
117 const QString connectionName = item->
name();
118 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( connectionName );
119 const QStringList connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
123 QgsVectorTileProviderConnection::addConnection( newConnectionName, connection );
127void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
129 QgsVectorTileConnectionDialog dlg;
133 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
134 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
139void QgsVectorTileDataItemGuiProvider::newArcGISConnection(
QgsDataItem *item )
141 QgsArcgisVectorTileConnectionDialog dlg;
145 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
146 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
151void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
157void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
159 const QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(),
160 tr(
"XML files (*.xml *.XML)" ) );
161 if ( fileName.isEmpty() )
167 if ( dlg.exec() == QDialog::Accepted )
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
static const QString uniqueName(const QString &name, const QStringList &connectionNames)
Check if connection with name exists in connectionNames list and then try to append a number to it to...
static void deleteConnections(const QList< T * > &items, const std::function< void(const QString &) > &deleteConnection, QgsDataItemGuiContext context)
Handles deletion of a list of connection items.
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.