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,
|
children.append( new QgsSensorThingsEntityContainerItem( this,
|
||||||
QgsSensorThingsUtils::displayString( entity, true ),
|
QgsSensorThingsUtils::displayString( entity, true ),
|
||||||
mPath + '/' + qgsEnumValueToKey( entity ),
|
mPath + '/' + qgsEnumValueToKey( entity ),
|
||||||
QgsProviderRegistry::instance()->encodeUri(
|
entityUriParts, entity, mConnName ) );
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, entityUriParts ) ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
children.append( new QgsSensorThingsLayerEntityItem( this,
|
children.append( new QgsSensorThingsLayerEntityItem( this,
|
||||||
QgsSensorThingsUtils::displayString( entity, true ),
|
QgsSensorThingsUtils::displayString( entity, true ),
|
||||||
mPath + '/' + qgsEnumValueToKey( entity ),
|
mPath + '/' + qgsEnumValueToKey( entity ),
|
||||||
QgsProviderRegistry::instance()->encodeUri(
|
entityUriParts,
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, entityUriParts ),
|
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
||||||
Qgis::BrowserLayerType::TableLayer ) );
|
Qgis::BrowserLayerType::TableLayer, entity, mConnName ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,9 +117,11 @@ QVector<QgsDataItem *> QgsSensorThingsConnectionItem::createChildren()
|
|||||||
// QgsSensorThingsEntityContainerItem
|
// 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" ) )
|
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "sensorthings" ) )
|
||||||
, mEntityUri( entityUri )
|
, mEntityUriParts( entityUriParts )
|
||||||
|
, mEntityType( entityType )
|
||||||
|
, mConnectionName( connectionName )
|
||||||
{
|
{
|
||||||
mCapabilities |= Qgis::BrowserItemCapability::Collapse | Qgis::BrowserItemCapability::Fast;
|
mCapabilities |= Qgis::BrowserItemCapability::Collapse | Qgis::BrowserItemCapability::Fast;
|
||||||
populate();
|
populate();
|
||||||
@ -137,9 +137,6 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
|||||||
{
|
{
|
||||||
QVector<QgsDataItem *> children;
|
QVector<QgsDataItem *> children;
|
||||||
|
|
||||||
const QVariantMap entityUriParts = QgsProviderRegistry::instance()->decodeUri(
|
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, mEntityUri );
|
|
||||||
|
|
||||||
int sortKey = 1;
|
int sortKey = 1;
|
||||||
for ( const Qgis::WkbType wkbType :
|
for ( const Qgis::WkbType wkbType :
|
||||||
{
|
{
|
||||||
@ -149,7 +146,7 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
|||||||
Qgis::WkbType::MultiPolygon
|
Qgis::WkbType::MultiPolygon
|
||||||
} )
|
} )
|
||||||
{
|
{
|
||||||
QVariantMap geometryUriParts = entityUriParts;
|
QVariantMap geometryUriParts = mEntityUriParts;
|
||||||
QString name;
|
QString name;
|
||||||
Qgis::BrowserLayerType layerType = Qgis::BrowserLayerType::TableLayer;
|
Qgis::BrowserLayerType layerType = Qgis::BrowserLayerType::TableLayer;
|
||||||
switch ( wkbType )
|
switch ( wkbType )
|
||||||
@ -180,10 +177,9 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
|||||||
children.append( new QgsSensorThingsLayerEntityItem( this,
|
children.append( new QgsSensorThingsLayerEntityItem( this,
|
||||||
name,
|
name,
|
||||||
mPath + '/' + name,
|
mPath + '/' + name,
|
||||||
QgsProviderRegistry::instance()->encodeUri(
|
geometryUriParts,
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY, geometryUriParts ),
|
|
||||||
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
QgsSensorThingsProvider::SENSORTHINGS_PROVIDER_KEY,
|
||||||
layerType ) );
|
layerType, mEntityType, mConnectionName ) );
|
||||||
children.last()->setSortKey( sortKey++ );
|
children.last()->setSortKey( sortKey++ );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,12 +190,60 @@ QVector<QgsDataItem *> QgsSensorThingsEntityContainerItem::createChildren()
|
|||||||
// QgsSensorThingsLayerEntityItem
|
// QgsSensorThingsLayerEntityItem
|
||||||
//
|
//
|
||||||
|
|
||||||
QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri, const QString &provider, Qgis::BrowserLayerType type )
|
QgsSensorThingsLayerEntityItem::QgsSensorThingsLayerEntityItem( QgsDataItem *parent, const QString &name, const QString &path,
|
||||||
: QgsLayerItem( parent, name, path, encodedUri, type, provider )
|
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 );
|
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
|
// QgsSensorThingsDataItemProvider
|
||||||
//
|
//
|
||||||
|
@ -52,11 +52,14 @@ class CORE_EXPORT QgsSensorThingsEntityContainerItem : public QgsDataCollectionI
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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;
|
bool equal( const QgsDataItem *other ) override;
|
||||||
QVector<QgsDataItem *> createChildren() override;
|
QVector<QgsDataItem *> createChildren() override;
|
||||||
private:
|
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
|
Q_OBJECT
|
||||||
public:
|
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
|
//! Provider for sensor things root data item
|
||||||
|
Loading…
x
Reference in New Issue
Block a user