diff --git a/src/providers/wms/qgswmscapabilities.h b/src/providers/wms/qgswmscapabilities.h index f04d585eb68..472e03ac63e 100644 --- a/src/providers/wms/qgswmscapabilities.h +++ b/src/providers/wms/qgswmscapabilities.h @@ -320,6 +320,20 @@ struct QgsWmsLayerProperty bool noSubsets; int fixedWidth; int fixedHeight; + + // TODO need to expand this to cover more of layer properties + bool equal( const QgsWmsLayerProperty &layerProperty ) + { + if ( !( name == layerProperty.name ) ) + return false; + if ( !( title == layerProperty.title ) ) + return false; + if ( !( abstract == layerProperty.abstract ) ) + return false; + + return true; + } + }; struct QgsWmtsTheme diff --git a/src/providers/wms/qgswmsdataitemguiproviders.cpp b/src/providers/wms/qgswmsdataitemguiproviders.cpp index 3fdfbadf8c8..ef966f6a338 100644 --- a/src/providers/wms/qgswmsdataitemguiproviders.cpp +++ b/src/providers/wms/qgswmsdataitemguiproviders.cpp @@ -105,10 +105,8 @@ void QgsWmsDataItemGuiProvider::newConnection( QgsDataItem *item ) void QgsWmsDataItemGuiProvider::refreshConnection( QgsDataItem *item ) { + // Updating the item and its children only item->refresh(); - // the parent should be updated - if ( item->parent() ) - item->parent()->refreshConnections(); } diff --git a/src/providers/wms/qgswmsdataitems.cpp b/src/providers/wms/qgswmsdataitems.cpp index 4dd0d560681..ab6d1eda98a 100644 --- a/src/providers/wms/qgswmsdataitems.cpp +++ b/src/providers/wms/qgswmsdataitems.cpp @@ -96,10 +96,14 @@ QVector QgsWMSConnectionItem::createChildren() // Attention, the name may be empty QgsDebugMsgLevel( QString::number( layerProperty.orderId ) + ' ' + layerProperty.name + ' ' + layerProperty.title, 2 ); QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name; + QgsDataItem *layer; - QgsWMSLayerItem *layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + '/' + pathName, capabilitiesProperty, uri, layerProperty ); + if ( layerProperty.name.isEmpty() ) + layer = new QgsWMSLayerCollectionItem( this, layerProperty.title, mPath + '/' + pathName, capabilitiesProperty, uri, layerProperty ); + else + layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + '/' + pathName, capabilitiesProperty, uri, layerProperty ); - children << layer; + children << layer ; } } @@ -233,17 +237,13 @@ bool QgsWMSConnectionItem::equal( const QgsDataItem *other ) // --------------------------------------------------------------------------- -QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem *parent, QString name, QString path, const QgsWmsCapabilitiesProperty &capabilitiesProperty, const QgsDataSourceUri &dataSourceUri, const QgsWmsLayerProperty &layerProperty ) - : QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, QStringLiteral( "wms" ) ) +QgsWMSLayerCollectionItem::QgsWMSLayerCollectionItem( QgsDataItem *parent, QString name, QString path, const QgsWmsCapabilitiesProperty &capabilitiesProperty, const QgsDataSourceUri &dataSourceUri, const QgsWmsLayerProperty &layerProperty ) + : QgsDataCollectionItem( parent, name, path ) , mCapabilitiesProperty( capabilitiesProperty ) , mDataSourceUri( dataSourceUri ) , mLayerProperty( layerProperty ) { - mSupportedCRS = mLayerProperty.crs; - mSupportFormats = mCapabilitiesProperty.capability.request.getMap.format; - QgsDebugMsgLevel( "uri = " + mDataSourceUri.encodedUri(), 2 ); - - mUri = createUri(); + mIconName = QStringLiteral( "mIconWms.svg" ); // Populate everything, it costs nothing, all info about layers is collected for ( const QgsWmsLayerProperty &layerProperty : qgis::as_const( mLayerProperty.layer ) ) @@ -256,8 +256,67 @@ QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem *parent, QString name, QString pat addChildItem( layer ); } - mIconName = QStringLiteral( "mIconWms.svg" ); + setState( Populated ); +} +bool QgsWMSLayerCollectionItem::equal( const QgsDataItem *other ) +{ + if ( type() != other->type() ) + { + return false; + } + const QgsWMSLayerCollectionItem *otherCollectionItem = dynamic_cast( other ); + if ( !otherCollectionItem ) + { + return false; + } + + // Check if the children are not the same then they are not equal + if ( mChildren.isEmpty() & !otherCollectionItem->mChildren.isEmpty() ) + return false; + if ( mChildren.size() != otherCollectionItem->mChildren.size() ) + return false; + + // compare children content, if the content differs then the parents are not equal + for ( QgsDataItem *child : mChildren ) + { + if ( !child ) + continue; + for ( QgsDataItem *otherChild : otherCollectionItem->mChildren ) + { + if ( !otherChild ) + continue; + // In case they have same path, check if they have same content + if ( child->path() == otherChild->path() ) + { + if ( !child->equal( otherChild ) ) + return false; + } + else + { + continue; + } + } + } + + + return ( mPath == otherCollectionItem->mPath && mName == otherCollectionItem->mName ); +} + +// --------------------------------------------------------------------------- + +QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem *parent, QString name, QString path, const QgsWmsCapabilitiesProperty &capabilitiesProperty, const QgsDataSourceUri &dataSourceUri, const QgsWmsLayerProperty &layerProperty ) + : QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, QStringLiteral( "wms" ) ) + , mCapabilitiesProperty( capabilitiesProperty ) + , mDataSourceUri( dataSourceUri ) + , mLayerProperty( layerProperty ) +{ + mSupportedCRS = mLayerProperty.crs; + mSupportFormats = mCapabilitiesProperty.capability.request.getMap.format; + QgsDebugMsgLevel( "uri = " + mDataSourceUri.encodedUri(), 2 ); + + mUri = createUri(); + mIconName = QStringLiteral( "mIconWms.svg" ); setState( Populated ); } @@ -307,6 +366,26 @@ QString QgsWMSLayerItem::createUri() return mDataSourceUri.encodedUri(); } +bool QgsWMSLayerItem::equal( const QgsDataItem *other ) +{ + if ( type() != other->type() ) + { + return false; + } + const QgsWMSLayerItem *otherLayer = dynamic_cast( other ); + if ( !otherLayer ) + { + return false; + } + + if ( !mLayerProperty.equal( otherLayer->mLayerProperty ) ) + return false; + + + return ( mPath == otherLayer->mPath && mName == otherLayer->mName ); +} + + // --------------------------------------------------------------------------- QgsWMTSLayerItem::QgsWMTSLayerItem( QgsDataItem *parent, diff --git a/src/providers/wms/qgswmsdataitems.h b/src/providers/wms/qgswmsdataitems.h index 27acadd16d6..4fa9ac0aaaa 100644 --- a/src/providers/wms/qgswmsdataitems.h +++ b/src/providers/wms/qgswmsdataitems.h @@ -41,6 +41,22 @@ class QgsWMSConnectionItem : public QgsDataCollectionItem QgsWmsCapabilitiesDownload *mCapabilitiesDownload = nullptr; }; +class QgsWMSLayerCollectionItem : public QgsDataCollectionItem +{ + Q_OBJECT + public: + QgsWMSLayerCollectionItem( QgsDataItem *parent, QString name, QString path, + const QgsWmsCapabilitiesProperty &capabilitiesProperty, + const QgsDataSourceUri &dataSourceUri, + const QgsWmsLayerProperty &layerProperty ); + + bool equal( const QgsDataItem *other ) override; + + QgsWmsCapabilitiesProperty mCapabilitiesProperty; + QgsDataSourceUri mDataSourceUri; + QgsWmsLayerProperty mLayerProperty; +}; + // WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem // We have to use QgsDataCollectionItem and support layer methods if necessary class QgsWMSLayerItem : public QgsLayerItem @@ -52,6 +68,7 @@ class QgsWMSLayerItem : public QgsLayerItem const QgsDataSourceUri &dataSourceUri, const QgsWmsLayerProperty &layerProperty ); + bool equal( const QgsDataItem *other ) override; QString createUri(); QgsWmsCapabilitiesProperty mCapabilitiesProperty;