QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "moc_qgssensorthingsdataitems.cpp"
25
27
28//
29// QgsSensorThingsRootItem
30//
31
32QgsSensorThingsRootItem::QgsSensorThingsRootItem( QgsDataItem *parent, QString name, QString path )
33 : QgsConnectionsRootItem( parent, name, path, QStringLiteral( "sensorthings" ) )
34{
35 mCapabilities |= Qgis::BrowserItemCapability::Fast;
36 mIconName = QStringLiteral( "mIconSensorThings.svg" );
37 populate();
38}
39
40QVector<QgsDataItem *> QgsSensorThingsRootItem::createChildren()
41{
42 QVector<QgsDataItem *> connections;
43 const auto connectionList = QgsSensorThingsProviderConnection::connectionList();
44 for ( const QString &connName : connectionList )
45 {
46 QgsDataItem *conn = new QgsSensorThingsConnectionItem( this, connName, mPath + '/' + connName );
47 connections.append( conn );
48 }
49 return connections;
50}
51
52//
53// QgsSensorThingsConnectionItem
54//
55
56QgsSensorThingsConnectionItem::QgsSensorThingsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
57 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
58 , mConnName( name )
59{
60 mIconName = QStringLiteral( "mIconConnect.svg" );
62 populate();
63
64
65}
66
67bool QgsSensorThingsConnectionItem::equal( const QgsDataItem *other )
68{
69 const QgsSensorThingsConnectionItem *o = qobject_cast<const QgsSensorThingsConnectionItem *>( other );
70 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
71}
72
73QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
74{
75 QVector<QgsDataItem *> children;
76
78 const QString uri = QgsSensorThingsProviderConnection::encodedLayerUri( connectionData );
79 const QVariantMap connectionUriParts = QgsProviderRegistry::instance()->decodeUri(
80 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uri );
81
82 for ( Qgis::SensorThingsEntity entity :
83 {
93 } )
94 {
95 QVariantMap entityUriParts = connectionUriParts;
96 entityUriParts.insert( QStringLiteral( "entity" ), qgsEnumValueToKey( entity ) );
97
99 {
100 children.append( new QgsSensorThingsEntityContainerItem( this,
102 mPath + '/' + qgsEnumValueToKey( entity ),
103 entityUriParts, entity, mConnName ) );
104 }
105 else
106 {
107 children.append( new QgsSensorThingsLayerEntityItem( this,
109 mPath + '/' + qgsEnumValueToKey( entity ),
110 entityUriParts,
111 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
112 Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
113 }
114 }
115
116 return children;
117}
118
119
120//
121// QgsSensorThingsEntityContainerItem
122//
123
124QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName )
125 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
126 , mEntityUriParts( entityUriParts )
127 , mEntityType( entityType )
128 , mConnectionName( connectionName )
129{
131 populate();
132}
133
134bool QgsSensorThingsEntityContainerItem::equal( const QgsDataItem *other )
135{
136 const QgsSensorThingsEntityContainerItem *o = qobject_cast<const QgsSensorThingsEntityContainerItem *>( other );
137 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
138}
139
140QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
141{
142 QVector<QgsDataItem *> children;
143
144 int sortKey = 1;
145 QList< Qgis::WkbType > compatibleTypes;
146 // we always expose "no geometry" types for these, even though they have a restricted fixed type
147 // according to the spec. This is because not all services respect the mandated geometry types!
148 switch ( QgsSensorThingsUtils::geometryTypeForEntity( mEntityType ) )
149 {
152 break;
155 break;
158 break;
161 break;
163 compatibleTypes << Qgis::WkbType::NoGeometry;
164 }
165
166 for ( const Qgis::WkbType wkbType : std::as_const( compatibleTypes ) )
167 {
168 QVariantMap geometryUriParts = mEntityUriParts;
169 QString name;
171 switch ( wkbType )
172 {
174 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "point" ) );
175 name = tr( "Points" );
177 break;
179 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "multipoint" ) );
180 name = tr( "MultiPoints" );
182 break;
184 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "line" ) );
185 name = tr( "Lines" );
187 break;
189 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "polygon" ) );
190 name = tr( "Polygons" );
192 break;
194 geometryUriParts.remove( QStringLiteral( "geometryType" ) );
195 name = tr( "No Geometry" );
197 break;
198 default:
199 break;
200 }
201 children.append( new QgsSensorThingsLayerEntityItem( this,
202 name,
203 mPath + '/' + name,
204 geometryUriParts,
205 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
206 layerType, mEntityType, mConnectionName ) );
207 children.last()->setSortKey( sortKey++ );
208 }
209
210 return children;
211}
212
213//
214// QgsSensorThingsLayerEntityItem
215//
216
217QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
218 const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName )
219 : QgsLayerItem( parent, name, path,
220 QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ),
221 type, provider )
222 , mUriParts( uriParts )
223 , mEntityType( entityType )
224 , mConnectionName( connectionName )
225{
227}
228
229QString QgsSensorThingsLayerEntityItem::layerName() const
230{
231 QString baseName;
233 {
234 const QString geometryType = mUriParts.value( QStringLiteral( "geometryType" ) ).toString();
235 QString geometryNamePart;
236 if ( geometryType.compare( QLatin1String( "point" ), Qt::CaseInsensitive ) == 0 ||
237 geometryType.compare( QLatin1String( "multipoint" ), Qt::CaseInsensitive ) == 0 )
238 {
239 geometryNamePart = tr( "Points" );
240 }
241 else if ( geometryType.compare( QLatin1String( "line" ), Qt::CaseInsensitive ) == 0 )
242 {
243 geometryNamePart = tr( "Lines" );
244 }
245 else if ( geometryType.compare( QLatin1String( "polygon" ), Qt::CaseInsensitive ) == 0 )
246 {
247 geometryNamePart = tr( "Polygons" );
248 }
249
250 if ( !geometryNamePart.isEmpty() )
251 {
252 baseName = QStringLiteral( "%1 - %2 (%3)" ).arg( mConnectionName,
253 QgsSensorThingsUtils::displayString( mEntityType, true ),
254 geometryNamePart );
255 }
256 else
257 {
258 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
259 QgsSensorThingsUtils::displayString( mEntityType, true ) );
260 }
261 }
262 else
263 {
264 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
265 QgsSensorThingsUtils::displayString( mEntityType, true ) );
266 }
267
268 return baseName;
269}
270
271//
272// QgsSensorThingsDataItemProvider
273//
274
275QString QgsSensorThingsDataItemProvider::name()
276{
277 return QStringLiteral( "SensorThings" );
278}
279
280QString QgsSensorThingsDataItemProvider::dataProviderKey() const
281{
282 return QStringLiteral( "sensorthings" );
283}
284
285Qgis::DataItemProviderCapabilities QgsSensorThingsDataItemProvider::capabilities() const
286{
288}
289
290QgsDataItem *QgsSensorThingsDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
291{
292 if ( path.isEmpty() )
293 return new QgsSensorThingsRootItem( parentItem, QObject::tr( "SensorThings" ), QStringLiteral( "sensorthings:" ) );
294
295 return nullptr;
296}
297
299
@ NetworkSources
Network/internet source.
Definition qgis.h:981
@ Populated
Children created.
Definition qgis.h:941
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
Definition qgis.h:956
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:955
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:992
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:5966
@ Sensor
A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estima...
Definition qgis.h:5972
@ MultiDatastream
A MultiDatastream groups a collection of Observations and the Observations in a MultiDatastream have ...
Definition qgis.h:5976
@ ObservedProperty
An ObservedProperty specifies the phenomenon of an Observation.
Definition qgis.h:5973
@ FeatureOfInterest
In the context of the Internet of Things, many Observations’ FeatureOfInterest can be the Location of...
Definition qgis.h:5975
@ Datastream
A Datastream groups a collection of Observations measuring the same ObservedProperty and produced by ...
Definition qgis.h:5971
@ Observation
An Observation is the act of measuring or otherwise determining the value of a property.
Definition qgis.h:5974
@ Location
A Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is de...
Definition qgis.h:5969
@ Thing
A Thing is an object of the physical world (physical things) or the information world (virtual things...
Definition qgis.h:5968
@ HistoricalLocation
A Thing’s HistoricalLocation entity set provides the times of the current (i.e., last known) and prev...
Definition qgis.h:5970
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
BrowserLayerType
Browser item layer types.
Definition qgis.h:1001
@ Point
Vector point layer.
Definition qgis.h:1005
@ Line
Vector line layer.
Definition qgis.h:1006
@ Polygon
Vector polygon layer.
Definition qgis.h:1007
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1008
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ Point
Point.
Definition qgis.h:279
@ MultiPoint
MultiPoint.
Definition qgis.h:283
@ MultiPolygon
MultiPolygon.
Definition qgis.h:285
@ NoGeometry
No geometry.
Definition qgis.h:294
@ MultiLineString
MultiLineString.
Definition qgis.h:284
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:47
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:6798
Represents decoded data of a SensorThings connection.