Skip to content
Permalink
Browse files

added fix for #33621

  • Loading branch information
Samweli authored and nyalldawson committed Jan 7, 2020
1 parent b9a1945 commit 91604f189628745f9c0da724003ab5fff32d9871
@@ -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
@@ -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();
}


@@ -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 ;
}
}

@@ -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<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 );
}

@@ -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,
@@ -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;

0 comments on commit 91604f1

Please sign in to comment.
You can’t perform that action at this time.