QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 "qgsprovidermetadata.h"
20#include "qgsdataprovider.h"
21#include "qgsproviderregistry.h"
22
24
25//
26// QgsSensorThingsRootItem
27//
28
29QgsSensorThingsRootItem::QgsSensorThingsRootItem( QgsDataItem *parent, QString name, QString path )
30 : QgsConnectionsRootItem( parent, name, path, QStringLiteral( "sensorthings" ) )
31{
32 mCapabilities |= Qgis::BrowserItemCapability::Fast;
33 mIconName = QStringLiteral( "mIconSensorThings.svg" );
34 populate();
35}
36
37QVector<QgsDataItem *> QgsSensorThingsRootItem::createChildren()
38{
39 QVector<QgsDataItem *> connections;
40 const auto connectionList = QgsSensorThingsProviderConnection::connectionList();
41 for ( const QString &connName : connectionList )
42 {
43 QgsDataItem *conn = new QgsSensorThingsConnectionItem( this, connName, mPath + '/' + connName );
44 connections.append( conn );
45 }
46 return connections;
47}
48
49//
50// QgsSensorThingsConnectionItem
51//
52
53QgsSensorThingsConnectionItem::QgsSensorThingsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
54 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
55 , mConnName( name )
56{
57 mIconName = QStringLiteral( "mIconConnect.svg" );
59 populate();
60
61
62}
63
64bool QgsSensorThingsConnectionItem::equal( const QgsDataItem *other )
65{
66 const QgsSensorThingsConnectionItem *o = qobject_cast<const QgsSensorThingsConnectionItem *>( other );
67 return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
68}
69
70QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
71{
72 QVector<QgsDataItem *> children;
73
75 const QString uri = QgsSensorThingsProviderConnection::encodedLayerUri( connectionData );
76 const QVariantMap connectionUriParts = QgsProviderRegistry::instance()->decodeUri(
77 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uri );
78
79 for ( Qgis::SensorThingsEntity entity :
80 {
89 } )
90 {
91 QVariantMap entityUriParts = connectionUriParts;
92 entityUriParts.insert( QStringLiteral( "entity" ), qgsEnumValueToKey( entity ) );
93
95 {
96 children.append( new QgsSensorThingsEntityContainerItem( this,
98 mPath + '/' + qgsEnumValueToKey( entity ),
99 entityUriParts, entity, mConnName ) );
100 }
101 else
102 {
103 children.append( new QgsSensorThingsLayerEntityItem( this,
105 mPath + '/' + qgsEnumValueToKey( entity ),
106 entityUriParts,
107 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
108 Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
109 }
110 }
111
112 return children;
113}
114
115
116//
117// QgsSensorThingsEntityContainerItem
118//
119
120QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName )
121 : QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
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 for ( const Qgis::WkbType wkbType :
142 {
147 } )
148 {
149 QVariantMap geometryUriParts = mEntityUriParts;
150 QString name;
152 switch ( wkbType )
153 {
155 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "point" ) );
156 name = tr( "Points" );
158 break;
160 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "multipoint" ) );
161 name = tr( "MultiPoints" );
163 break;
165 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "line" ) );
166 name = tr( "Lines" );
168 break;
170 geometryUriParts.insert( QStringLiteral( "geometryType" ), QStringLiteral( "polygon" ) );
171 name = tr( "Polygons" );
173 break;
174 default:
175 break;
176 }
177 children.append( new QgsSensorThingsLayerEntityItem( this,
178 name,
179 mPath + '/' + name,
180 geometryUriParts,
181 QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
182 layerType, mEntityType, mConnectionName ) );
183 children.last()->setSortKey( sortKey++ );
184 }
185
186 return children;
187}
188
189//
190// QgsSensorThingsLayerEntityItem
191//
192
193QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
194 const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName )
195 : QgsLayerItem( parent, name, path,
196 QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ),
197 type, provider )
198 , mUriParts( uriParts )
199 , mEntityType( entityType )
200 , mConnectionName( connectionName )
201{
203}
204
205QString QgsSensorThingsLayerEntityItem::layerName() const
206{
207 QString baseName;
209 {
210 const QString geometryType = mUriParts.value( QStringLiteral( "geometryType" ) ).toString();
211 QString geometryNamePart;
212 if ( geometryType.compare( QLatin1String( "point" ), Qt::CaseInsensitive ) == 0 ||
213 geometryType.compare( QLatin1String( "multipoint" ), Qt::CaseInsensitive ) == 0 )
214 {
215 geometryNamePart = tr( "Points" );
216 }
217 else if ( geometryType.compare( QLatin1String( "line" ), Qt::CaseInsensitive ) == 0 )
218 {
219 geometryNamePart = tr( "Lines" );
220 }
221 else if ( geometryType.compare( QLatin1String( "polygon" ), Qt::CaseInsensitive ) == 0 )
222 {
223 geometryNamePart = tr( "Polygons" );
224 }
225
226 if ( !geometryNamePart.isEmpty() )
227 {
228 baseName = QStringLiteral( "%1 - %2 (%3)" ).arg( mConnectionName,
229 QgsSensorThingsUtils::displayString( mEntityType, true ),
230 geometryNamePart );
231 }
232 else
233 {
234 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
235 QgsSensorThingsUtils::displayString( mEntityType, true ) );
236 }
237 }
238 else
239 {
240 baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
241 QgsSensorThingsUtils::displayString( mEntityType, true ) );
242 }
243
244 return baseName;
245}
246
247//
248// QgsSensorThingsDataItemProvider
249//
250
251QString QgsSensorThingsDataItemProvider::name()
252{
253 return QStringLiteral( "SensorThings" );
254}
255
256QString QgsSensorThingsDataItemProvider::dataProviderKey() const
257{
258 return QStringLiteral( "sensorthings" );
259}
260
261Qgis::DataItemProviderCapabilities QgsSensorThingsDataItemProvider::capabilities() const
262{
264}
265
266QgsDataItem *QgsSensorThingsDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
267{
268 if ( path.isEmpty() )
269 return new QgsSensorThingsRootItem( parentItem, QObject::tr( "SensorThings" ), QStringLiteral( "sensorthings:" ) );
270
271 return nullptr;
272}
273
275
@ 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:727
SensorThingsEntity
OGC SensorThings API entity types.
Definition: qgis.h:4865
@ Sensor
A Sensor is an instrument that observes a property or phenomenon with the goal of producing an estima...
@ 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...
BrowserLayerType
Browser item layer types.
Definition: qgis.h:736
@ 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:182
@ MultiPoint
MultiPoint.
@ MultiPolygon
MultiPolygon.
@ 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
Definition: qgsdataitem.h:318
Item that represents a layer that can be opened with one of the providers.
Definition: qgslayeritem.h:31
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 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:5398
Represents decoded data of a SensorThings connection.