Skip to content
Permalink
Browse files

[FEATURE][AFS] Add new browser context menu entry to visit the

service info page for AFS layer/featureservice/folder items

It's very handy for troubleshooting connections and seeing
extended service properties
  • Loading branch information
nyalldawson committed Nov 7, 2018
1 parent b2d2634 commit 85bc01f5fc5f43297ae08444b20f097414f40529
@@ -21,6 +21,9 @@
#ifdef HAVE_GUI
#include "qgsnewhttpconnection.h"
#include "qgsafssourceselect.h"
#include <QMenu>
#include <QAction>
#include <QDesktopServices>
#endif

#include <QMessageBox>
@@ -185,6 +188,12 @@ bool QgsAfsConnectionItem::equal( const QgsDataItem *other )
return ( type() == other->type() && o && mPath == o->mPath && mName == o->mName );
}

QString QgsAfsConnectionItem::url() const
{
const QgsOwsConnection connection( QStringLiteral( "ARCGISFEATURESERVER" ), mConnName );
return connection.uri().param( QStringLiteral( "url" ) );
}

#ifdef HAVE_GUI
QList<QAction *> QgsAfsConnectionItem::actions( QWidget *parent )
{
@@ -381,3 +390,66 @@ QgsDataItem *QgsAfsDataItemProvider::createDataItem( const QString &path, QgsDat

return nullptr;
}

#ifdef HAVE_GUI

//
// QgsAfsItemGuiProvider
//

QString QgsAfsItemGuiProvider::name()
{
return QStringLiteral( "afs_items" );
}

void QgsAfsItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
{
if ( QgsAfsConnectionItem *connectionItem = qobject_cast< QgsAfsConnectionItem * >( item ) )
{
QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
connect( viewInfo, &QAction::triggered, this, [ = ]
{
QDesktopServices::openUrl( QUrl( connectionItem->url() ) );
} );
menu->addAction( viewInfo );
}
else if ( QgsAfsFolderItem *folderItem = qobject_cast< QgsAfsFolderItem * >( item ) )
{
QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
connect( viewInfo, &QAction::triggered, this, [ = ]
{
QDesktopServices::openUrl( QUrl( folderItem->path() ) );
} );
menu->addAction( viewInfo );
}
else if ( QgsAfsServiceItem *serviceItem = qobject_cast< QgsAfsServiceItem * >( item ) )
{
QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
connect( viewInfo, &QAction::triggered, this, [ = ]
{
QDesktopServices::openUrl( QUrl( serviceItem->path() ) );
} );
menu->addAction( viewInfo );
}
else if ( QgsAfsParentLayerItem *layerItem = qobject_cast< QgsAfsParentLayerItem * >( item ) )
{
QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
connect( viewInfo, &QAction::triggered, this, [ = ]
{
QDesktopServices::openUrl( QUrl( layerItem->path() ) );
} );
menu->addAction( viewInfo );
}
else if ( QgsAfsLayerItem *layerItem = qobject_cast< QgsAfsLayerItem * >( item ) )
{
QAction *viewInfo = new QAction( tr( "View Service Info" ), menu );
connect( viewInfo, &QAction::triggered, this, [ = ]
{
QDesktopServices::openUrl( QUrl( layerItem->path() ) );
} );
menu->addAction( viewInfo );
menu->addSeparator();
}
}

#endif
@@ -20,6 +20,10 @@
#include "qgswkbtypes.h"
#include "qgsdataitemprovider.h"

#ifdef HAVE_GUI
#include "qgsdataitemguiprovider.h"
#endif

class QgsAfsRootItem : public QgsDataCollectionItem
{
Q_OBJECT
@@ -49,6 +53,7 @@ class QgsAfsConnectionItem : public QgsDataCollectionItem
QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &connectionName );
QVector<QgsDataItem *> createChildren() override;
bool equal( const QgsDataItem *other ) override;
QString url() const;
#ifdef HAVE_GUI
QList<QAction *> actions( QWidget *parent ) override;
#endif
@@ -127,4 +132,24 @@ class QgsAfsDataItemProvider : public QgsDataItemProvider
QgsDataItem *createDataItem( const QString &path, QgsDataItem *parentItem ) override;
};

#ifdef HAVE_GUI

class QgsAfsItemGuiProvider : public QObject, public QgsDataItemGuiProvider
{
Q_OBJECT

public:

QgsAfsItemGuiProvider() = default;

QString name() override;

void populateContextMenu( QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;


};

#endif

#endif // QGSAFSDATAITEMS_H
@@ -346,4 +346,16 @@ QGISEXTERN QList<QgsDataItemProvider *> *dataItemProviders()
return providers;
}

#ifdef HAVE_GUI
QGISEXTERN QList<QgsDataItemGuiProvider *> *dataItemGuiProviders()
{
QList<QgsDataItemGuiProvider *> *providers = new QList<QgsDataItemGuiProvider *>();

*providers
<< new QgsAfsItemGuiProvider();

return providers;
}
#endif

#endif

0 comments on commit 85bc01f

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