QGIS API Documentation 3.99.0-Master (357b655ed83)
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
17#include "qgsdataprovider.h"
18#include "qgsprovidermetadata.h"
19#include "qgsproviderregistry.h"
23
24#include <QString>
25
26#include "moc_qgssensorthingsdataitems.cpp"
27
28using namespace Qt::StringLiterals;
29
31
32//
33// QgsSensorThingsRootItem
34//
35
36QgsSensorThingsRootItem::QgsSensorThingsRootItem( QgsDataItem *parent, QString name, QString path )
37 : QgsConnectionsRootItem( parent, name, path, u"sensorthings"_s )
38{
39 mCapabilities |= Qgis::BrowserItemCapability::Fast;
40 mIconName = u"mIconSensorThings.svg"_s;
41 populate();
42}
43
44QVector<QgsDataItem *> QgsSensorThingsRootItem::createChildren()
45{
46 QVector<QgsDataItem *> connections;
47 const auto connectionList = QgsSensorThingsProviderConnection::connectionList();
48 for ( const QString &connName : connectionList )
49 {
50 QgsDataItem *conn = new QgsSensorThingsConnectionItem( this, connName, mPath + '/' + connName );
51 connections.append( conn );
52 }
53 return connections;
54}
55
56//
57// QgsSensorThingsConnectionItem
58//
59
60QgsSensorThingsConnectionItem::QgsSensorThingsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
61 : QgsDataCollectionItem( parent, name, path, u"sensorthings"_s )
62 , mConnName( name )
63{
64 mIconName = u"mIconConnect.svg"_s;
66 populate();
67
68
69}
70
71bool QgsSensorThingsConnectionItem::equal( const QgsDataItem *other )
72{
73 const QgsSensorThingsConnectionItem *o = qobject_cast<const QgsSensorThingsConnectionItem *>( other );
74 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
75}
76
77QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
78{
79 QVector<QgsDataItem *> children;
80
82 const QString uri = QgsSensorThingsProviderConnection::encodedLayerUri( connectionData );
83 const QVariantMap connectionUriParts = QgsProviderRegistry::instance()->decodeUri(
84 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uri );
85
86 for ( Qgis::SensorThingsEntity entity :
87 {
97 } )
98 {
99 QVariantMap entityUriParts = connectionUriParts;
100 entityUriParts.insert( u"entity"_s, qgsEnumValueToKey( entity ) );
101
103 {
104 children.append( new QgsSensorThingsEntityContainerItem( this,
106 mPath + '/' + qgsEnumValueToKey( entity ),
107 entityUriParts, entity, mConnName ) );
108 }
109 else
110 {
111 children.append( new QgsSensorThingsLayerEntityItem( this,
113 mPath + '/' + qgsEnumValueToKey( entity ),
114 entityUriParts,
115 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
116 Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
117 }
118 }
119
120 return children;
121}
122
123
124//
125// QgsSensorThingsEntityContainerItem
126//
127
128QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName )
129 : QgsDataCollectionItem( parent, name, path, u"sensorthings"_s )
130 , mEntityUriParts( entityUriParts )
131 , mEntityType( entityType )
132 , mConnectionName( connectionName )
133{
135 populate();
136}
137
138bool QgsSensorThingsEntityContainerItem::equal( const QgsDataItem *other )
139{
140 const QgsSensorThingsEntityContainerItem *o = qobject_cast<const QgsSensorThingsEntityContainerItem *>( other );
141 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
142}
143
144QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
145{
146 QVector<QgsDataItem *> children;
147
148 int sortKey = 1;
149 QList< Qgis::WkbType > compatibleTypes;
150 // we always expose "no geometry" types for these, even though they have a restricted fixed type
151 // according to the spec. This is because not all services respect the mandated geometry types!
152 switch ( QgsSensorThingsUtils::geometryTypeForEntity( mEntityType ) )
153 {
156 break;
159 break;
162 break;
165 break;
167 compatibleTypes << Qgis::WkbType::NoGeometry;
168 }
169
170 for ( const Qgis::WkbType wkbType : std::as_const( compatibleTypes ) )
171 {
172 QVariantMap geometryUriParts = mEntityUriParts;
173 QString name;
175 switch ( wkbType )
176 {
178 geometryUriParts.insert( u"geometryType"_s, u"point"_s );
179 name = tr( "Points" );
181 break;
183 geometryUriParts.insert( u"geometryType"_s, u"multipoint"_s );
184 name = tr( "MultiPoints" );
186 break;
188 geometryUriParts.insert( u"geometryType"_s, u"line"_s );
189 name = tr( "Lines" );
191 break;
193 geometryUriParts.insert( u"geometryType"_s, u"polygon"_s );
194 name = tr( "Polygons" );
196 break;
198 geometryUriParts.remove( u"geometryType"_s );
199 name = tr( "No Geometry" );
201 break;
202 default:
203 break;
204 }
205 children.append( new QgsSensorThingsLayerEntityItem( this,
206 name,
207 mPath + '/' + name,
208 geometryUriParts,
209 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
210 layerType, mEntityType, mConnectionName ) );
211 children.last()->setSortKey( sortKey++ );
212 }
213
214 return children;
215}
216
217//
218// QgsSensorThingsLayerEntityItem
219//
220
221QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
222 const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName )
223 : QgsLayerItem( parent, name, path,
224 QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ),
225 type, provider )
226 , mUriParts( uriParts )
227 , mEntityType( entityType )
228 , mConnectionName( connectionName )
229{
231}
232
233QString QgsSensorThingsLayerEntityItem::layerName() const
234{
235 QString baseName;
237 {
238 const QString geometryType = mUriParts.value( u"geometryType"_s ).toString();
239 QString geometryNamePart;
240 if ( geometryType.compare( "point"_L1, Qt::CaseInsensitive ) == 0 ||
241 geometryType.compare( "multipoint"_L1, Qt::CaseInsensitive ) == 0 )
242 {
243 geometryNamePart = tr( "Points" );
244 }
245 else if ( geometryType.compare( "line"_L1, Qt::CaseInsensitive ) == 0 )
246 {
247 geometryNamePart = tr( "Lines" );
248 }
249 else if ( geometryType.compare( "polygon"_L1, Qt::CaseInsensitive ) == 0 )
250 {
251 geometryNamePart = tr( "Polygons" );
252 }
253
254 if ( !geometryNamePart.isEmpty() )
255 {
256 baseName = u"%1 - %2 (%3)"_s.arg( mConnectionName,
257 QgsSensorThingsUtils::displayString( mEntityType, true ),
258 geometryNamePart );
259 }
260 else
261 {
262 baseName = u"%1 - %2"_s.arg( mConnectionName,
263 QgsSensorThingsUtils::displayString( mEntityType, true ) );
264 }
265 }
266 else
267 {
268 baseName = u"%1 - %2"_s.arg( mConnectionName,
269 QgsSensorThingsUtils::displayString( mEntityType, true ) );
270 }
271
272 return baseName;
273}
274
275//
276// QgsSensorThingsDataItemProvider
277//
278
279QString QgsSensorThingsDataItemProvider::name()
280{
281 return u"SensorThings"_s;
282}
283
284QString QgsSensorThingsDataItemProvider::dataProviderKey() const
285{
286 return u"sensorthings"_s;
287}
288
289Qgis::DataItemProviderCapabilities QgsSensorThingsDataItemProvider::capabilities() const
290{
292}
293
294QgsDataItem *QgsSensorThingsDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
295{
296 if ( path.isEmpty() )
297 return new QgsSensorThingsRootItem( parentItem, QObject::tr( "SensorThings" ), u"sensorthings:"_s );
298
299 return nullptr;
300}
301
303
@ NetworkSources
Network/internet source.
Definition qgis.h:1000
@ Populated
Children created.
Definition qgis.h:960
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
Definition qgis.h:975
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:974
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1011
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:6267
@ Sensor
A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estima...
Definition qgis.h:6273
@ MultiDatastream
A MultiDatastream groups a collection of Observations and the Observations in a MultiDatastream have ...
Definition qgis.h:6277
@ ObservedProperty
An ObservedProperty specifies the phenomenon of an Observation.
Definition qgis.h:6274
@ FeatureOfInterest
In the context of the Internet of Things, many Observations’ FeatureOfInterest can be the Location of...
Definition qgis.h:6276
@ Datastream
A Datastream groups a collection of Observations measuring the same ObservedProperty and produced by ...
Definition qgis.h:6272
@ Observation
An Observation is the act of measuring or otherwise determining the value of a property.
Definition qgis.h:6275
@ Location
A Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is de...
Definition qgis.h:6270
@ Thing
A Thing is an object of the physical world (physical things) or the information world (virtual things...
Definition qgis.h:6269
@ HistoricalLocation
A Thing’s HistoricalLocation entity set provides the times of the current (i.e., last known) and prev...
Definition qgis.h:6271
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
BrowserLayerType
Browser item layer types.
Definition qgis.h:1020
@ Point
Vector point layer.
Definition qgis.h:1024
@ Line
Vector line layer.
Definition qgis.h:1025
@ Polygon
Vector polygon layer.
Definition qgis.h:1026
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1027
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Point
Point.
Definition qgis.h:282
@ MultiPoint
MultiPoint.
Definition qgis.h:286
@ MultiPolygon
MultiPolygon.
Definition qgis.h:288
@ NoGeometry
No geometry.
Definition qgis.h:298
@ MultiLineString
MultiLineString.
Definition qgis.h:287
A browser item that represents a root group of connections from a single data provider.
A browser item for collections of data.
Base class for all items in the model.
Definition qgsdataitem.h:50
Qgis::BrowserItemType type() const
A browser 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:7126
Represents decoded data of a SensorThings connection.