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]
49 QgsVectorTileProviderConnection::deleteConnection( connectionName );
52 menu->addAction( actionDelete );
55 if ( QgsVectorTileRootItem *rootItem = qobject_cast< QgsVectorTileRootItem * >( item ) )
57 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ), menu );
58 connect( actionNew, &QAction::triggered,
this, [rootItem] { newConnection( rootItem ); } );
59 menu->addAction( actionNew );
61 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ), menu );
62 connect( actionNewArcGISConnection, &QAction::triggered,
this, [rootItem] { newArcGISConnection( rootItem ); } );
63 menu->addAction( actionNewArcGISConnection );
67 QAction *actionSaveXyzTilesServers =
new QAction( tr(
"Save Connections…" ), menu );
68 connect( actionSaveXyzTilesServers, &QAction::triggered,
this, [] { saveXyzTilesServers(); } );
69 menu->addAction( actionSaveXyzTilesServers );
71 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ), menu );
72 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadXyzTilesServers( rootItem ); } );
73 menu->addAction( actionLoadXyzTilesServers );
77void QgsVectorTileDataItemGuiProvider::editConnection(
QgsDataItem *item )
79 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( item->
name() );
80 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
82 switch ( connection.serviceType )
84 case QgsVectorTileProviderConnection::Generic:
86 QgsVectorTileConnectionDialog dlg;
88 dlg.setConnection( item->
name(), uri );
92 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
93 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
94 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
98 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
100 QgsArcgisVectorTileConnectionDialog dlg;
102 dlg.setConnection( item->
name(), uri );
106 QgsVectorTileProviderConnection::deleteConnection( item->
name() );
107 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
108 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
116void QgsVectorTileDataItemGuiProvider::duplicateConnection(
QgsDataItem *item )
118 const QString connectionName = item->
name();
119 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( connectionName );
120 const QStringList connections = QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
124 QgsVectorTileProviderConnection::addConnection( newConnectionName, connection );
128void QgsVectorTileDataItemGuiProvider::newConnection(
QgsDataItem *item )
130 QgsVectorTileConnectionDialog dlg;
134 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
135 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
140void QgsVectorTileDataItemGuiProvider::newArcGISConnection(
QgsDataItem *item )
142 QgsArcgisVectorTileConnectionDialog dlg;
146 const QgsVectorTileProviderConnection::Data conn = QgsVectorTileProviderConnection::decodedUri( dlg.connectionUri() );
147 QgsVectorTileProviderConnection::addConnection( dlg.connectionName(), conn );
152void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
158void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers(
QgsDataItem *item )
160 const QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(),
161 tr(
"XML files (*.xml *.XML)" ) );
162 if ( fileName.isEmpty() )
168 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.