17#include "moc_qgstiledscenedataitemguiprovider.cpp"
30void QgsTiledSceneDataItemGuiProvider::populateContextMenu(
QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selection,
QgsDataItemGuiContext context )
32 if ( QgsTiledSceneLayerItem *layerItem = qobject_cast<QgsTiledSceneLayerItem *>( 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<QgsTiledSceneLayerItem *> sceneConnectionItems = QgsDataItem::filteredItems<QgsTiledSceneLayerItem>( selection );
43 QAction *actionDelete =
new QAction( sceneConnectionItems.size() > 1 ? tr(
"Remove Connections…" ) : tr(
"Remove Connection…" ), menu );
44 connect( actionDelete, &QAction::triggered,
this, [sceneConnectionItems, context] {
47 menu->addAction( actionDelete );
50 if ( QgsTiledSceneRootItem *rootItem = qobject_cast<QgsTiledSceneRootItem *>( item ) )
52 QAction *actionNewCesium =
new QAction( tr(
"New Cesium 3D Tiles Connection…" ), menu );
53 connect( actionNewCesium, &QAction::triggered,
this, [rootItem] { newConnection( rootItem,
"cesiumtiles" ); } );
54 menu->addAction( actionNewCesium );
56 QAction *actionNewQM =
new QAction( tr(
"New Quantized Mesh Connection…" ), menu );
57 connect( actionNewQM, &QAction::triggered,
this, [rootItem] { newConnection( rootItem,
"quantizedmesh" ); } );
58 menu->addAction( actionNewQM );
62 QAction *actionSave =
new QAction( tr(
"Save Connections…" ), menu );
63 connect( actionSave, &QAction::triggered,
this, [] { saveConnections(); } );
64 menu->addAction( actionSave );
66 QAction *actionLoadXyzTilesServers =
new QAction( tr(
"Load Connections…" ), menu );
67 connect( actionLoadXyzTilesServers, &QAction::triggered,
this, [rootItem] { loadConnections( rootItem ); } );
68 menu->addAction( actionLoadXyzTilesServers );
72void QgsTiledSceneDataItemGuiProvider::editConnection(
QgsDataItem *item )
77 QgsTiledSceneConnectionDialog dlg;
79 dlg.setConnection( item->
name(), uri );
93void QgsTiledSceneDataItemGuiProvider::duplicateConnection(
QgsDataItem *item )
95 const QString connectionName = item->
name();
97 const QStringList connections = QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
105void QgsTiledSceneDataItemGuiProvider::newConnection(
QgsDataItem *item, QString provider )
107 QgsTiledSceneConnectionDialog dlg;
119void QgsTiledSceneDataItemGuiProvider::saveConnections()
125void QgsTiledSceneDataItemGuiProvider::loadConnections(
QgsDataItem *item )
127 const QString fileName = QFileDialog::getOpenFileName(
nullptr, tr(
"Load Connections" ), QDir::homePath(), tr(
"XML files (*.xml *.XML)" ) );
128 if ( fileName.isEmpty() )
134 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.
@ TiledScene
Tiled scene connection.
Represents connections to tiled scene data sources.
virtual void remove(const QString &name) const override
Deletes the connection from the settings.
static Data decodedUri(const QString &uri)
Returns a connection uri decoded to a data structure.
static Data connection(const QString &name)
Returns connection details for the stored connection with the specified name.
static void addConnection(const QString &name, const Data &connection)
Stores a new connection, under the specified connection name.
static QString encodedUri(const Data &data)
Returns connection data encoded as a string.
Represents decoded data of a tiled scene connection.
QString provider
Provider key.