QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
21
22#include <QMessageBox>
23#include <QFileDialog>
24
26
27void QgsTiledSceneDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
28{
29 if ( QgsTiledSceneLayerItem *layerItem = qobject_cast< QgsTiledSceneLayerItem * >( item ) )
30 {
31 QAction *actionEdit = new QAction( tr( "Edit Connection…" ), menu );
32 connect( actionEdit, &QAction::triggered, this, [layerItem] { editConnection( layerItem ); } );
33 menu->addAction( actionEdit );
34
35 QAction *actionDelete = new QAction( tr( "Remove Connection" ), menu );
36 connect( actionDelete, &QAction::triggered, this, [layerItem] { deleteConnection( layerItem ); } );
37 menu->addAction( actionDelete );
38 }
39
40 if ( QgsTiledSceneRootItem *rootItem = qobject_cast< QgsTiledSceneRootItem * >( item ) )
41 {
42 QAction *actionNewCesium = new QAction( tr( "New Cesium 3D Tiles Connection…" ), menu );
43 connect( actionNewCesium, &QAction::triggered, this, [rootItem] { newCesium3dTilesConnection( rootItem ); } );
44 menu->addAction( actionNewCesium );
45
46 menu->addSeparator();
47
48 QAction *actionSave = new QAction( tr( "Save Connections…" ), menu );
49 connect( actionSave, &QAction::triggered, this, [] { saveConnections(); } );
50 menu->addAction( actionSave );
51
52 QAction *actionLoadXyzTilesServers = new QAction( tr( "Load Connections…" ), menu );
53 connect( actionLoadXyzTilesServers, &QAction::triggered, this, [rootItem] { loadConnections( rootItem ); } );
54 menu->addAction( actionLoadXyzTilesServers );
55 }
56}
57
58void QgsTiledSceneDataItemGuiProvider::editConnection( QgsDataItem *item )
59{
61 const QString uri = QgsTiledSceneProviderConnection::encodedUri( connection );
62
63 QgsTiledSceneConnectionDialog dlg;
64
65 dlg.setConnection( item->name(), uri );
66 if ( !dlg.exec() )
67 return;
68
69 QgsTiledSceneProviderConnection( QString() ).remove( item->name() );
70
72 newConnection.provider = connection.provider;
73
74 QgsTiledSceneProviderConnection::addConnection( dlg.connectionName(), newConnection );
75
76 item->parent()->refreshConnections();
77}
78
79void QgsTiledSceneDataItemGuiProvider::deleteConnection( QgsDataItem *item )
80{
81 if ( QMessageBox::question( nullptr, tr( "Remove Connection" ), tr( "Are you sure you want to remove the connection “%1”?" ).arg( item->name() ),
82 QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
83 return;
84
85 QgsTiledSceneProviderConnection( QString() ).remove( item->name() );
86
87 item->parent()->refreshConnections();
88}
89
90void QgsTiledSceneDataItemGuiProvider::newCesium3dTilesConnection( QgsDataItem *item )
91{
92 QgsTiledSceneConnectionDialog dlg;
93 if ( !dlg.exec() )
94 return;
95
97 conn.provider = QStringLiteral( "cesiumtiles" );
98
99 QgsTiledSceneProviderConnection::addConnection( dlg.connectionName(), conn );
100
101 item->refreshConnections();
102}
103
104void QgsTiledSceneDataItemGuiProvider::saveConnections()
105{
107 dlg.exec();
108}
109
110void QgsTiledSceneDataItemGuiProvider::loadConnections( QgsDataItem *item )
111{
112 const QString fileName = QFileDialog::getOpenFileName( nullptr, tr( "Load Connections" ), QDir::homePath(),
113 tr( "XML files (*.xml *.XML)" ) );
114 if ( fileName.isEmpty() )
115 {
116 return;
117 }
118
120 if ( dlg.exec() == QDialog::Accepted )
121 item->refreshConnections();
122}
123
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
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.