Skip to content

Commit

Permalink
Fix AFS browser items not correctly repopulated after changing AFS co…
Browse files Browse the repository at this point in the history
…nnection URL

(cherry-picked from e3c7dff)
  • Loading branch information
nyalldawson committed Jul 25, 2018
1 parent 29b24aa commit a6650f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
37 changes: 27 additions & 10 deletions src/providers/arcgisrest/qgsafsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ QVector<QgsDataItem *> QgsAfsRootItem::createChildren()
{
QVector<QgsDataItem *> connections;

Q_FOREACH ( const QString &connName, QgsOwsConnection::connectionList( "arcgisfeatureserver" ) )
const QStringList connectionList = QgsOwsConnection::connectionList( "arcgisfeatureserver" );
for ( const QString &connName : connectionList )
{
QgsOwsConnection connection( QStringLiteral( "arcgisfeatureserver" ), connName );
QString path = "afs:/" + connName;
connections.append( new QgsAfsConnectionItem( this, connName, path, connection.uri().param( QStringLiteral( "url" ) ) ) );
const QString path = QStringLiteral( "afs:/" ) + connName;
connections.append( new QgsAfsConnectionItem( this, connName, path, connName ) );
}
return connections;
}
Expand Down Expand Up @@ -84,19 +84,22 @@ void QgsAfsRootItem::newConnection()

///////////////////////////////////////////////////////////////////////////////

QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &url )
QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &connectionName )
: QgsDataCollectionItem( parent, name, path )
, mUrl( url )
, mConnName( connectionName )
{
mIconName = QStringLiteral( "mIconConnect.svg" );
mCapabilities |= Collapse;
}

QVector<QgsDataItem *> QgsAfsConnectionItem::createChildren()
{
const QgsOwsConnection connection( QStringLiteral( "arcgisfeatureserver" ), mConnName );
const QString url = connection.uri().param( QStringLiteral( "url" ) );

QVector<QgsDataItem *> layers;
QString errorTitle, errorMessage;
const QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( mUrl, errorTitle, errorMessage );
const QVariantMap serviceData = QgsArcGisRestUtils::getServiceInfo( url, errorTitle, errorMessage );
if ( serviceData.isEmpty() )
{
return layers;
Expand All @@ -114,7 +117,7 @@ QVector<QgsDataItem *> QgsAfsConnectionItem::createChildren()
continue;
}
const QString id = layerInfoMap.value( QStringLiteral( "id" ) ).toString();
QgsAfsLayerItem *layer = new QgsAfsLayerItem( this, mName, mUrl + "/" + id, layerInfoMap.value( QStringLiteral( "name" ) ).toString(), authid );
QgsAfsLayerItem *layer = new QgsAfsLayerItem( this, mName, url + '/' + id, layerInfoMap.value( QStringLiteral( "name" ) ).toString(), authid );
layers.append( layer );
}

Expand Down Expand Up @@ -158,7 +161,10 @@ void QgsAfsConnectionItem::editConnection()

if ( nc.exec() )
{
mParent->refresh();
// the parent should be updated
refresh();
if ( mParent )
mParent->refreshConnections();
}
}

Expand All @@ -170,7 +176,18 @@ void QgsAfsConnectionItem::deleteConnection()
return;

QgsOwsConnection::deleteConnection( QStringLiteral( "arcgisfeatureserver" ), mName );
mParent->refresh();

// the parent should be updated
if ( mParent )
mParent->refreshConnections();
}

void QgsAfsConnectionItem::refreshConnection()
{
refresh();
// the parent should be updated
if ( mParent )
mParent->refreshConnections();
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/providers/arcgisrest/qgsafsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class QgsAfsConnectionItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &url );
QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &connectionName );
QVector<QgsDataItem *> createChildren() override;
bool equal( const QgsDataItem *other ) override;
#ifdef HAVE_GUI
Expand All @@ -60,7 +60,7 @@ class QgsAfsConnectionItem : public QgsDataCollectionItem
#endif

private:
QString mUrl;
QString mConnName;
};


Expand Down

0 comments on commit a6650f4

Please sign in to comment.