Skip to content

Commit

Permalink
[FEATURE][AFS] Add new browser context menu entry to visit the
Browse files Browse the repository at this point in the history
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 8, 2018
1 parent b2d2634 commit 85bc01f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/providers/arcgisrest/qgsafsdataitems.cpp
Expand Up @@ -21,6 +21,9 @@
#ifdef HAVE_GUI
#include "qgsnewhttpconnection.h"
#include "qgsafssourceselect.h"
#include <QMenu>
#include <QAction>
#include <QDesktopServices>
#endif

#include <QMessageBox>
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions src/providers/arcgisrest/qgsafsdataitems.h
Expand Up @@ -20,6 +20,10 @@
#include "qgswkbtypes.h"
#include "qgsdataitemprovider.h"

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

class QgsAfsRootItem : public QgsDataCollectionItem
{
Q_OBJECT
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions src/providers/arcgisrest/qgsafsprovider.cpp
Expand Up @@ -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.