mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Use more descriptive default layer names when adding SensorThings
layers from browser panel Fixes #56838
This commit is contained in:
parent
89731a78ef
commit
0f1649266b
@ -96,18 +96,16 @@ QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
|
||||
children.append( new QgsSensorThingsEntityContainerItem( this,
|
||||
QgsSensorThingsUtils::displayString( entity, true ),
|
||||
mPath + '/' + qgsEnumValueToKey( entity ),
|
||||
QgsProviderRegistry::instance()->encodeUri(
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, entityUriParts ) ) );
|
||||
entityUriParts, entity, mConnName ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
children.append( new QgsSensorThingsLayerEntityItem( this,
|
||||
QgsSensorThingsUtils::displayString( entity, true ),
|
||||
mPath + '/' + qgsEnumValueToKey( entity ),
|
||||
QgsProviderRegistry::instance()->encodeUri(
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, entityUriParts ),
|
||||
entityUriParts,
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
||||
Qgis::BrowserLayerType::TableLayer ) );
|
||||
Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,9 +117,11 @@ QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
|
||||
// QgsSensorThingsEntityContainerItem
|
||||
//
|
||||
|
||||
QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &entityUri )
|
||||
QgsSensorThingsEntityContainerItem::QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts, Qgis::SensorThingsEntity entityType, const QString &connectionName )
|
||||
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
|
||||
, mEntityUri( entityUri )
|
||||
, mEntityUriParts( entityUriParts )
|
||||
, mEntityType( entityType )
|
||||
, mConnectionName( connectionName )
|
||||
{
|
||||
mCapabilities |= Qgis::BrowserItemCapability::Collapse | Qgis::BrowserItemCapability::Fast;
|
||||
populate();
|
||||
@ -137,9 +137,6 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
||||
{
|
||||
QVector<QgsDataItem *> children;
|
||||
|
||||
const QVariantMap entityUriParts = QgsProviderRegistry::instance()->decodeUri(
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, mEntityUri );
|
||||
|
||||
int sortKey = 1;
|
||||
for ( const Qgis::WkbType wkbType :
|
||||
{
|
||||
@ -149,7 +146,7 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
||||
Qgis::WkbType::MultiPolygon
|
||||
} )
|
||||
{
|
||||
QVariantMap geometryUriParts = entityUriParts;
|
||||
QVariantMap geometryUriParts = mEntityUriParts;
|
||||
QString name;
|
||||
Qgis::BrowserLayerType layerType = Qgis::BrowserLayerType::TableLayer;
|
||||
switch ( wkbType )
|
||||
@ -180,10 +177,9 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
||||
children.append( new QgsSensorThingsLayerEntityItem( this,
|
||||
name,
|
||||
mPath + '/' + name,
|
||||
QgsProviderRegistry::instance()->encodeUri(
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, geometryUriParts ),
|
||||
geometryUriParts,
|
||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
||||
layerType ) );
|
||||
layerType, mEntityType, mConnectionName ) );
|
||||
children.last()->setSortKey( sortKey++ );
|
||||
}
|
||||
|
||||
@ -194,12 +190,60 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
||||
// QgsSensorThingsLayerEntityItem
|
||||
//
|
||||
|
||||
QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri, const QString &provider, Qgis::BrowserLayerType type )
|
||||
: QgsLayerItem( parent, name, path, encodedUri, type, provider )
|
||||
QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
|
||||
const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type, Qgis::SensorThingsEntity entityType, const QString &connectionName )
|
||||
: QgsLayerItem( parent, name, path,
|
||||
QgsProviderRegistry::instance()->encodeUri( QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, uriParts ),
|
||||
type, provider )
|
||||
, mUriParts( uriParts )
|
||||
, mEntityType( entityType )
|
||||
, mConnectionName( connectionName )
|
||||
{
|
||||
setState( Qgis::BrowserItemState::Populated );
|
||||
}
|
||||
|
||||
QString QgsSensorThingsLayerEntityItem::layerName() const
|
||||
{
|
||||
QString baseName;
|
||||
if ( QgsSensorThingsUtils::entityTypeHasGeometry( mEntityType ) )
|
||||
{
|
||||
const QString geometryType = mUriParts.value( QStringLiteral( "geometryType" ) ).toString();
|
||||
QString geometryNamePart;
|
||||
if ( geometryType.compare( QLatin1String( "point" ), Qt::CaseInsensitive ) == 0 ||
|
||||
geometryType.compare( QLatin1String( "multipoint" ), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
geometryNamePart = tr( "Points" );
|
||||
}
|
||||
else if ( geometryType.compare( QLatin1String( "line" ), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
geometryNamePart = tr( "Lines" );
|
||||
}
|
||||
else if ( geometryType.compare( QLatin1String( "polygon" ), Qt::CaseInsensitive ) == 0 )
|
||||
{
|
||||
geometryNamePart = tr( "Polygons" );
|
||||
}
|
||||
|
||||
if ( !geometryNamePart.isEmpty() )
|
||||
{
|
||||
baseName = QStringLiteral( "%1 - %2 (%3)" ).arg( mConnectionName,
|
||||
QgsSensorThingsUtils::displayString( mEntityType, true ),
|
||||
geometryNamePart );
|
||||
}
|
||||
else
|
||||
{
|
||||
baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
|
||||
QgsSensorThingsUtils::displayString( mEntityType, true ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
baseName = QStringLiteral( "%1 - %2" ).arg( mConnectionName,
|
||||
QgsSensorThingsUtils::displayString( mEntityType, true ) );
|
||||
}
|
||||
|
||||
return baseName;
|
||||
}
|
||||
|
||||
//
|
||||
// QgsSensorThingsDataItemProvider
|
||||
//
|
||||
|
@ -52,11 +52,14 @@ class CORE_EXPORT QgsSensorThingsEntityContainerItem : public QgsDataCollectionI
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &entityUri );
|
||||
QgsSensorThingsEntityContainerItem( QgsDataItem *parent, const QString &name, const QString &path, const QVariantMap &entityUriParts,
|
||||
Qgis::SensorThingsEntity entityType, const QString &connectionName );
|
||||
bool equal( const QgsDataItem *other ) override;
|
||||
QVector<QgsDataItem *> createChildren() override;
|
||||
private:
|
||||
QString mEntityUri;
|
||||
QVariantMap mEntityUriParts;
|
||||
Qgis::SensorThingsEntity mEntityType = Qgis::SensorThingsEntity::Invalid;
|
||||
QString mConnectionName;
|
||||
};
|
||||
|
||||
|
||||
@ -64,8 +67,14 @@ class CORE_EXPORT QgsSensorThingsLayerEntityItem : public QgsLayerItem
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsSensorThingsLayerEntityItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri, const QString &provider, Qgis::BrowserLayerType type );
|
||||
|
||||
QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
|
||||
const QVariantMap &uriParts, const QString &provider, Qgis::BrowserLayerType type,
|
||||
Qgis::SensorThingsEntity entityType, const QString &connectionName );
|
||||
QString layerName() const final;
|
||||
private:
|
||||
QVariantMap mUriParts;
|
||||
Qgis::SensorThingsEntity mEntityType = Qgis::SensorThingsEntity::Invalid;
|
||||
QString mConnectionName;
|
||||
};
|
||||
|
||||
//! Provider for sensor things root data item
|
||||
|
Loading…
x
Reference in New Issue
Block a user