17#include "moc_qgsvectortiledataitemguiprovider.cpp"
31void QgsVectorTileDataItemGuiProvider::populateContextMenu(
QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selection,
QgsDataItemGuiContext context )
33 if ( QgsVectorTileLayerItem *layerItem = qobject_cast<QgsVectorTileLayerItem *>( item ) )
35 QAction *actionEdit =
new QAction( tr(
"Edit Connection…" ), menu );
36 connect( actionEdit, &QAction::triggered,
this, [layerItem] { editConnection( layerItem ); } );
37 menu->addAction( actionEdit );
39 QAction *actionDuplicate =
new QAction( tr(
"Duplicate Connection" ), menu );
40 connect( actionDuplicate, &QAction::triggered,
this, [layerItem] { duplicateConnection( layerItem ); } );
41 menu->addAction( actionDuplicate );
43 const QList<QgsVectorTileLayerItem *> vtConnectionItems = QgsDataItem::filteredItems<QgsVectorTileLayerItem>( selection );
44 QAction *actionDelete =
new QAction( vtConnectionItems.size() > 1 ? tr(
"Remove Connections…" ) : tr(
"Remove Connection…" ), menu );
45 connect( actionDelete, &QAction::triggered,
this, [vtConnectionItems, context] {
48 menu->addAction( actionDelete );
51 if ( QgsVectorTileRootItem *rootItem = qobject_cast<QgsVectorTileRootItem *>( item ) )
53 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ), menu );
54 connect( actionNew, &QAction::triggered,
this, [rootItem] { newConnection( rootItem ); } );
55 menu->addAction( actionNew );
57 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ), menu );
58 connect( actionNewArcGISConnection, &QAction::triggered,
this, [rootItem] { newArcGISConnection( rootItem ); } );
59 menu->addAction( actionNewArcGISConnection );
63 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ), menu );
64 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
65 menu->addAction( actionSaveXyzTilesServers );
67 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ), menu );
68 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
69 menu->addAction( actionLoadXyzTilesServers );
73void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
75 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( item->
name() );
76 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
78 switch ( connection.serviceType )
80 case QgsVectorTileProviderConnection::Generic:
82 QgsVectorTileConnectionDialog dlg;
84 dlg.setConnection( item->
name(), uri );
88 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
89 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
90 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
94 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
96 QgsArcgisVectorTileConnectionDialog dlg;
98 dlg.setConnection( item->
name(), uri );
102 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
103 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
104 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
112void QgsVectorTileDataItemGuiProvider::duplicateConnection(
QgsDataItem *item )
114 const QString connectionName = item->
name();
115 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( connectionName );
116 const QStringList connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
120 QgsVectorTileProviderConnection::addConnection( newConnectionName, connection );
124void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
126 QgsVectorTileConnectionDialog dlg;
130 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
131 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
136void QgsVectorTileDataItemGuiProvider::newArcGISConnection(
QgsDataItem *item )
138 QgsArcgisVectorTileConnectionDialog dlg;
142 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
143 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
148void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
154void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
156 const QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
157 if ( fileName.isEmpty() )
163 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.