Skip to content

Commit

Permalink
added fix for #33621
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Jan 18, 2020
1 parent b9a1945 commit 91604f1
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/providers/wms/qgswmscapabilities.h
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/providers/wms/qgswmsdataitemguiproviders.cpp
Expand Up @@ -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();
}


Expand Down
99 changes: 89 additions & 10 deletions src/providers/wms/qgswmsdataitems.cpp
Expand Up @@ -96,10 +96,14 @@ QVector<QgsDataItem *> 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 ;
}
}

Expand Down Expand Up @@ -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 ) )
Expand All @@ -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<const QgsWMSLayerCollectionItem *>( 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 );
}

Expand Down Expand Up @@ -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<const QgsWMSLayerItem *>( other );
if ( !otherLayer )
{
return false;
}

if ( !mLayerProperty.equal( otherLayer->mLayerProperty ) )
return false;


return ( mPath == otherLayer->mPath && mName == otherLayer->mName );
}


// ---------------------------------------------------------------------------

QgsWMTSLayerItem::QgsWMTSLayerItem( QgsDataItem *parent,
Expand Down
17 changes: 17 additions & 0 deletions src/providers/wms/qgswmsdataitems.h
Expand Up @@ -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
Expand All @@ -52,6 +68,7 @@ class QgsWMSLayerItem : public QgsLayerItem
const QgsDataSourceUri &dataSourceUri,
const QgsWmsLayerProperty &layerProperty );

bool equal( const QgsDataItem *other ) override;
QString createUri();

QgsWmsCapabilitiesProperty mCapabilitiesProperty;
Expand Down

0 comments on commit 91604f1

Please sign in to comment.