QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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
69bool QgsSensorThingsConnectionItem::equal( const QgsDataItem *other )
70{
71 const QgsSensorThingsConnectionItem *o = qobject_cast<const QgsSensorThingsConnectionItem *>( other );
72 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
73}
74
75QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
76{
77 QVector<QgsDataItem *> children;
78
80 const QString uri = QgsSensorThingsProviderConnection::encodedLayerUri( connectionData );
81 const QVariantMap connectionUriParts = QgsProviderRegistry::instance()->decodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uri );
82
83 for ( Qgis::SensorThingsEntity entity : {
93 } )
94 {
95 QVariantMap entityUriParts = connectionUriParts;
96 entityUriParts.insert( u"entity"_s, qgsEnumValueToKey( entity ) );
97
99 {
100 children.append( new QgsSensorThingsEntityContainerItem( this, QgsSensorThingsUtils::displayString( entity, true ), mPath + '/' + qgsEnumValueToKey( entity ), entityUriParts, entity, mConnName ) );
101 }
102 else
103 {
104 children.append(
105 new QgsSensorThingsLayerEntityItem( this, QgsSensorThingsUtils::displayString( entity, true ), mPath + '/' + qgsEnumValueToKey( entity ), entityUriParts, QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, Qgis::BrowserLayerType::TableLayer, entity, mConnName )
106 );
107 }
108 }
109
110 return children;
111}
112
113
114//
115// QgsSensorThingsEntityContainerItem
116//
117
118QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem(
119 QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName
120)
121 : QgsDataCollectionItem( parent, name, path, u"sensorthings"_s )
122 , mEntityUriParts( entityUriParts )
123 , mEntityType( entityType )
124 , mConnectionName( connectionName )
125{
127 populate();
128}
129
130bool QgsSensorThingsEntityContainerItem::equal( const QgsDataItem *other )
131{
132 const QgsSensorThingsEntityContainerItem *o = qobject_cast<const QgsSensorThingsEntityContainerItem *>( other );
133 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
134}
135
136QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
137{
138 QVector<QgsDataItem *> children;
139
140 int sortKey = 1;
141 QList< Qgis::WkbType > compatibleTypes;
142 // we always expose "no geometry" types for these, even though they have a restricted fixed type
143 // according to the spec. This is because not all services respect the mandated geometry types!
144 switch ( QgsSensorThingsUtils::geometryTypeForEntity( mEntityType ) )
145 {
148 break;
151 break;
154 break;
157 break;
159 compatibleTypes << Qgis::WkbType::NoGeometry;
160 }
161
162 for ( const Qgis::WkbType wkbType : std::as_const( compatibleTypes ) )
163 {
164 QVariantMap geometryUriParts = mEntityUriParts;
165 QString name;
167 switch ( wkbType )
168 {
170 geometryUriParts.insert( u"geometryType"_s, u"point"_s );
171 name = tr( "Points" );
173 break;
175 geometryUriParts.insert( u"geometryType"_s, u"multipoint"_s );
176 name = tr( "MultiPoints" );
178 break;
180 geometryUriParts.insert( u"geometryType"_s, u"line"_s );
181 name = tr( "Lines" );
183 break;
185 geometryUriParts.insert( u"geometryType"_s, u"polygon"_s );
186 name = tr( "Polygons" );
188 break;
190 geometryUriParts.remove( u"geometryType"_s );
191 name = tr( "No Geometry" );
193 break;
194 default:
195 break;
196 }
197 children.append( new QgsSensorThingsLayerEntityItem( this, name, mPath + '/' + name, geometryUriParts, QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, layerType, mEntityType, mConnectionName ) );
198 children.last()->setSortKey( sortKey++ );
199 }
200
201 return children;
202}
203
204//
205// QgsSensorThingsLayerEntityItem
206//
207
208QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem(
209 QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName
210)
211 : QgsLayerItem( parent, name, path, QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ), type, provider )
212 , mUriParts( uriParts )
213 , mEntityType( entityType )
214 , mConnectionName( connectionName )
215{
217}
218
219QString QgsSensorThingsLayerEntityItem::layerName() const
220{
221 QString baseName;
223 {
224 const QString geometryType = mUriParts.value( u"geometryType"_s ).toString();
225 QString geometryNamePart;
226 if ( geometryType.compare( "point"_L1, Qt::CaseInsensitive ) == 0 || geometryType.compare( "multipoint"_L1, Qt::CaseInsensitive ) == 0 )
227 {
228 geometryNamePart = tr( "Points" );
229 }
230 else if ( geometryType.compare( "line"_L1, Qt::CaseInsensitive ) == 0 )
231 {
232 geometryNamePart = tr( "Lines" );
233 }
234 else if ( geometryType.compare( "polygon"_L1, Qt::CaseInsensitive ) == 0 )
235 {
236 geometryNamePart = tr( "Polygons" );
237 }
238
239 if ( !geometryNamePart.isEmpty() )
240 {
241 baseName = u"%1 - %2 (%3)"_s.arg( mConnectionName, QgsSensorThingsUtils::displayString( mEntityType, true ), geometryNamePart );
242 }
243 else
244 {
245 baseName = u"%1 - %2"_s.arg( mConnectionName, QgsSensorThingsUtils::displayString( mEntityType, true ) );
246 }
247 }
248 else
249 {
250 baseName = u"%1 - %2"_s.arg( mConnectionName, QgsSensorThingsUtils::displayString( mEntityType, true ) );
251 }
252
253 return baseName;
254}
255
256//
257// QgsSensorThingsDataItemProvider
258//
259
260QString QgsSensorThingsDataItemProvider::name()
261{
262 return u"SensorThings"_s;
263}
264
265QString QgsSensorThingsDataItemProvider::dataProviderKey() const
266{
267 return u"sensorthings"_s;
268}
269
270Qgis::DataItemProviderCapabilities QgsSensorThingsDataItemProvider::capabilities() const
271{
273}
274
275QgsDataItem *QgsSensorThingsDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
276{
277 if ( path.isEmpty() )
278 return new QgsSensorThingsRootItem( parentItem, QObject::tr( "SensorThings" ), u"sensorthings:"_s );
279
280 return nullptr;
281}
282
@ NetworkSources
Network/internet source.
Definition qgis.h:1007
@ Populated
Children created.
Definition qgis.h:967
@ Collapse
The collapse/expand status for this items children should be ignored in order to avoid undesired netw...
Definition qgis.h:982
@ Fast
CreateChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,...
Definition qgis.h:981
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1018
SensorThingsEntity
OGC SensorThings API entity types.
Definition qgis.h:6324
@ Sensor
A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estima...
Definition qgis.h:6330
@ MultiDatastream
A MultiDatastream groups a collection of Observations and the Observations in a MultiDatastream have ...
Definition qgis.h:6334
@ ObservedProperty
An ObservedProperty specifies the phenomenon of an Observation.
Definition qgis.h:6331
@ FeatureOfInterest
In the context of the Internet of Things, many Observations’ FeatureOfInterest can be the Location of...
Definition qgis.h:6333
@ Datastream
A Datastream groups a collection of Observations measuring the same ObservedProperty and produced by ...
Definition qgis.h:6329
@ Observation
An Observation is the act of measuring or otherwise determining the value of a property.
Definition qgis.h:6332
@ Location
A Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is de...
Definition qgis.h:6327
@ Thing
A Thing is an object of the physical world (physical things) or the information world (virtual things...
Definition qgis.h:6326
@ HistoricalLocation
A Thing’s HistoricalLocation entity set provides the times of the current (i.e., last known) and prev...
Definition qgis.h:6328
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
BrowserLayerType
Browser item layer types.
Definition qgis.h:1027
@ Point
Vector point layer.
Definition qgis.h:1031
@ Line
Vector line layer.
Definition qgis.h:1032
@ Polygon
Vector polygon layer.
Definition qgis.h:1033
@ TableLayer
Vector non-spatial layer.
Definition qgis.h:1034
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ Point
Point.
Definition qgis.h:296
@ MultiPoint
MultiPoint.
Definition qgis.h:300
@ MultiPolygon
MultiPolygon.
Definition qgis.h:302
@ NoGeometry
No geometry.
Definition qgis.h:312
@ MultiLineString
MultiLineString.
Definition qgis.h:301
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:7157
Represents decoded data of a SensorThings connection.