QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgssensorthingsdataitems.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssensorthingsdataitems.cpp
3 ---------------------
4 begin : December 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 ***************************************************************************/
16#include "moc_qgssensorthingsdataitems.cpp"
17#include "qgsprovidermetadata.h"
21#include "qgsdataprovider.h"
22#include "qgsproviderregistry.h"
23
25
26//
27// QgsSensorThingsRootItem
28//
29
30QgsSensorThingsRootItem::QgsSensorThingsRootItem( QgsDataItem *parent, QString name, QString path )
31 : QgsConnectionsRootItem( parent, name, path, QStringLiteral( "sensorthings" ) )
32{
33 mCapabilities |= Qgis::BrowserItemCapability::Fast;
34 mIconName = QStringLiteral( "mIconSensorThings.svg" );
35 populate();
36}
37
38QVector<QgsDataItem *> QgsSensorThingsRootItem::createChildren()
39{
40 QVector<QgsDataItem *> connections;
41 const auto connectionList = QgsSensorThingsProviderConnection::connectionList();
42 for ( const QString &connName : connectionList )
43 {
44 QgsDataItem *conn = new QgsSensorThingsConnectionItem( this, connName, mPath + '/' + connName );
45 connections.append( conn );
46 }
47 return connections;
48}
49
50//
51// QgsSensorThingsConnectionItem
52//
53
54QgsSensorThingsConnectionItem::QgsSensorThingsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
55 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
56 , mConnName( name )
57{
58 mIconName = QStringLiteral( "mIconConnect.svg" );
60 populate();
61
62
63}
64
65bool QgsSensorThingsConnectionItem::equal( const QgsDataItem *other )
66{
67 const QgsSensorThingsConnectionItem *o = qobject_cast<const QgsSensorThingsConnectionItem *>( other );
68 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
69}
70
71QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
72{
73 QVector<QgsDataItem *> children;
74
76 const QString uri = QgsSensorThingsProviderConnection::encodedLayerUri( connectionData );
77 const QVariantMap connectionUriParts = QgsProviderRegistry::instance()->decodeUri(
78 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uri );
79
80 for ( Qgis::SensorThingsEntity entity :
81 {
91 } )
92 {
93 QVariantMap entityUriParts = connectionUriParts;
94 entityUriParts.insert( QStringLiteral( "entity" ), qgsEnumValueToKey( entity ) );
95
97 {
98 children.append( new QgsSensorThingsEntityContainerItem( this,
100 mPath + '/' + qgsEnumValueToKey( entity ),
101 entityUriParts, entity, mConnName ) );
102 }
103 else
104 {
105 children.append( new QgsSensorThingsLayerEntityItem( this,
107 mPath + '/' + qgsEnumValueToKey( entity ),
108 entityUriParts,
109 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
110 Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
111 }
112 }
113
114 return children;
115}
116
117
118//
119// QgsSensorThingsEntityContainerItem
120//
121
122QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName )
123 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
124 , mEntityUriParts( entityUriParts )
125 , mEntityType( entityType )
126 , mConnectionName( connectionName )
127{
129 populate();
130}
131
132bool QgsSensorThingsEntityContainerItem::equal( const QgsDataItem *other )
133{
134 const QgsSensorThingsEntityContainerItem *o = qobject_cast<const QgsSensorThingsEntityContainerItem *>( other );
135 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
136}
137
138QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
139{
140 QVector<QgsDataItem *> children;
141
142 int sortKey = 1;
143 QList< Qgis::WkbType > compatibleTypes;
144 // we always expose "no geometry" types for these, even though they have a restricted fixed type
145 // according to the spec. This is because not all services respect the mandated geometry types!
146 switch ( QgsSensorThingsUtils::geometryTypeForEntity( mEntityType ) )
147 {
150 break;
153 break;
156 break;
159 break;
161 compatibleTypes << Qgis::WkbType::NoGeometry;;
162 }
163
164 for ( const Qgis::WkbType wkbType : std::as_const( compatibleTypes ) )
165 {
166 QVariantMap geometryUriParts = mEntityUriParts;
167 QString name;
169 switch ( wkbType )
170 {
172 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "point" ) );
173 name = tr( "Points" );
175 break;
177 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "multipoint" ) );
178 name = tr( "MultiPoints" );
180 break;
182 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "line" ) );
183 name = tr( "Lines" );
185 break;
187 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "polygon" ) );
188 name = tr( "Polygons" );
190 break;
192 geometryUriParts.remove( QStringLiteral( "geometryType" ) );
193 name = tr( "No Geometry" );
195 break;
196 default:
197 break;
198 }
199 children.append( new QgsSensorThingsLayerEntityItem( this,
200 name,
201 mPath + '/' + name,
202 geometryUriParts,
203 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
204 layerType, mEntityType, mConnectionName ) );
205 children.last()->setSortKey( sortKey++ );
206 }
207
208 return children;
209}
210
211//
212// QgsSensorThingsLayerEntityItem
213//
214
215QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
216 const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName )
217 : QgsLayerItem( parent, name, path,
218 QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ),
219 type, provider )
220 , mUriParts( uriParts )
221 , mEntityType( entityType )
222 , mConnectionName( connectionName )
223{
225}
226
227QString QgsSensorThingsLayerEntityItem::layerName() const
228{
229 QString baseName;
231 {
232 const QString geometryType = mUriParts.value( QStringLiteral( "geometryType" ) ).toString();
233 QString geometryNamePart;
234 if ( geometryType.compare( QLatin1String( "point" ), Qt::CaseInsensitive ) == 0 ||
235 geometryType.compare( QLatin1String( "multipoint" ), Qt::CaseInsensitive ) == 0 )
236 {
237 geometryNamePart = tr( "Points" );
238 }
239 else if ( geometryType.compare( QLatin1String( "line" ), Qt::CaseInsensitive ) == 0 )
240 {
241 geometryNamePart = tr( "Lines" );
242 }
243 else if ( geometryType.compare( QLatin1String( "polygon" ), Qt::CaseInsensitive ) == 0 )
244 {
245 geometryNamePart = tr( "Polygons" );
246 }
247
248 if ( !geometryNamePart.isEmpty() )
249 {
250 baseName = QStringLiteral( "%1 - %2 (%3)" ).arg( mConnectionName,
251 QgsSensorThingsUtils::displayString( mEntityType, true ),
252 geometryNamePart );
253 }
254 else
255 {
256 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
257 QgsSensorThingsUtils::displayString( mEntityType, true ) );
258 }
259 }
260 else
261 {
262 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
263 QgsSensorThingsUtils::displayString( mEntityType, true ) );
264 }
265
266 return baseName;
267}
268
269//
270// QgsSensorThingsDataItemProvider
271//
272
273QString QgsSensorThingsDataItemProvider::name()
274{
275 return QStringLiteral( "SensorThings" );
276}
277
278QString QgsSensorThingsDataItemProvider::dataProviderKey() const
279{
280 return QStringLiteral( "sensorthings" );
281}
282
283Qgis::DataItemProviderCapabilities QgsSensorThingsDataItemProvider::capabilities() const
284{
286}
287
288QgsDataItem *QgsSensorThingsDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
289{
290 if ( path.isEmpty() )
291 return new QgsSensorThingsRootItem( parentItem, QObject::tr( "SensorThings" ), QStringLiteral( "sensorthings:" ) );
292
293 return nullptr;
294}
295
297
@ NetworkSources
Network/internet source.
@ Populated
Children created.
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:926
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:5609
@ Sensor
A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estima...
@ MultiDatastream
A MultiDatastream groups a collection of Observations and the Observations in a MultiDatastream have ...
@ ObservedProperty
An ObservedProperty specifies the phenomenon of an Observation.
@ FeatureOfInterest
In the context of the Internet of Things, many Observations’ FeatureOfInterest can be the Location of...
@ Datastream
A Datastream groups a collection of Observations measuring the same ObservedProperty and produced by ...
@ Observation
An Observation is the act of measuring or otherwise determining the value of a property.
@ Location
A Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is de...
@ Thing
A Thing is an object of the physical world (physical things) or the information world (virtual things...
@ HistoricalLocation
A Thing’s HistoricalLocation entity set provides the times of the current (i.e., last known) and prev...
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
BrowserLayerType
Browser item layer types.
Definition qgis.h:935
@ Point
Vector point layer.
@ Line
Vector line layer.
@ Polygon
Vector polygon layer.
@ TableLayer
Vector non-spatial layer.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ MultiPoint
MultiPoint.
@ MultiPolygon
MultiPolygon.
@ NoGeometry
No geometry.
@ MultiLineString
MultiLineString.
A Collection that represents a root group of connections from a single data provider.
A Collection: logical collection of layers or subcollections, e.g.
Base class for all items in the model.
Definition qgsdataitem.h:46
Qgis::BrowserItemType type() const
Item that represents a layer that can be opened with one of the providers.
A registry / canonical manager of data providers.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
static QString encodedLayerUri(const Data &data)
Returns connection data encoded as a string containing a URI for a SensorThings vector data provider.
static QStringList connectionList()
Returns a list of the stored connection names.
static Data connection(const QString &name)
Returns connection details for the stored connection with the specified name.
static Qgis::GeometryType geometryTypeForEntity(Qgis::SensorThingsEntity type)
Returns the geometry type for if the specified entity type.
static QString displayString(Qgis::SensorThingsEntity type, bool plural=false)
Converts a Qgis::SensorThingsEntity type to a user-friendly translated string.
static bool entityTypeHasGeometry(Qgis::SensorThingsEntity type)
Returns true if the specified entity type can have geometry attached.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6215
Represents decoded data of a SensorThings connection.