QGIS API Documentation 3.39.0-Master (47f7b3a4989)
Loading...
Searching...
No Matches
qgstiledscenedataitemguiprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledscenedataitemguiprovider.cpp
3 --------------------------------------
4 begin : June 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
22
23#include <QMessageBox>
24#include <QFileDialog>
25
27
28void QgsTiledSceneDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &selection, QgsDataItemGuiContext context )
29{
30 if ( QgsTiledSceneLayerItem *layerItem = qobject_cast< QgsTiledSceneLayerItem * >( item ) )
31 {
32 QAction *actionEdit = new QAction( tr( "Edit Connection…" ), menu );
33 connect( actionEdit, &QAction::triggered, this, [layerItem] { editConnection( layerItem ); } );
34 menu->addAction( actionEdit );
35
36 const QList< QgsTiledSceneLayerItem * > sceneConnectionItems = QgsDataItem::filteredItems<QgsTiledSceneLayerItem>( selection );
37 QAction *actionDelete = new QAction( sceneConnectionItems.size() > 1 ? tr( "Remove Connections…" ) : tr( "Remove Connection…" ), menu );
38 connect( actionDelete, &QAction::triggered, this, [sceneConnectionItems, context]
39 {
40 QgsDataItemGuiProviderUtils::deleteConnections( sceneConnectionItems, []( const QString & connectionName )
41 {
42 QgsTiledSceneProviderConnection( QString() ).remove( connectionName );
43 }, context );
44 } );
45 menu->addAction( actionDelete );
46 }
47
48 if ( QgsTiledSceneRootItem *rootItem = qobject_cast< QgsTiledSceneRootItem * >( item ) )
49 {
50 QAction *actionNewCesium = new QAction( tr( "New Cesium 3D Tiles Connection…" ), menu );
51 connect( actionNewCesium, &QAction::triggered, this, [rootItem] { newCesium3dTilesConnection( rootItem ); } );
52 menu->addAction( actionNewCesium );
53
54 menu->addSeparator();
55
56 QAction *actionSave = new QAction( tr( "Save Connections…" ), menu );
57 connect( actionSave, &QAction::triggered, this, [] { saveConnections(); } );
58 menu->addAction( actionSave );
59
60 QAction *actionLoadXyzTilesServers = new QAction( tr( "Load Connections…" ), menu );
61 connect( actionLoadXyzTilesServers, &QAction::triggered, this, [rootItem] { loadConnections( rootItem ); } );
62 menu->addAction( actionLoadXyzTilesServers );
63 }
64}
65
66void QgsTiledSceneDataItemGuiProvider::editConnection( QgsDataItem *item )
67{
69 const QString uri = QgsTiledSceneProviderConnection::encodedUri( connection );
70
71 QgsTiledSceneConnectionDialog dlg;
72
73 dlg.setConnection( item->name(), uri );
74 if ( !dlg.exec() )
75 return;
76
77 QgsTiledSceneProviderConnection( QString() ).remove( item->name() );
78
80 newConnection.provider = connection.provider;
81
82 QgsTiledSceneProviderConnection::addConnection( dlg.connectionName(), newConnection );
83
84 item->parent()->refreshConnections();
85}
86
87void QgsTiledSceneDataItemGuiProvider::newCesium3dTilesConnection( QgsDataItem *item )
88{
89 QgsTiledSceneConnectionDialog dlg;
90 if ( !dlg.exec() )
91 return;
92
94 conn.provider = QStringLiteral( "cesiumtiles" );
95
96 QgsTiledSceneProviderConnection::addConnection( dlg.connectionName(), conn );
97
98 item->refreshConnections();
99}
100
101void QgsTiledSceneDataItemGuiProvider::saveConnections()
102{
104 dlg.exec();
105}
106
107void QgsTiledSceneDataItemGuiProvider::loadConnections( QgsDataItem *item )
108{
109 const QString fileName = QFileDialog::getOpenFileName( nullptr, tr( "Load Connections" ), QDir::homePath(),
110 tr( "XML files (*.xml *.XML)" ) );
111 if ( fileName.isEmpty() )
112 {
113 return;
114 }
115
117 if ( dlg.exec() == QDialog::Accepted )
118 item->refreshConnections();
119}
120
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
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.
Definition qgsdataitem.h:46
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 (since QGIS 3.34)
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.