Skip to content
Permalink
Browse files

Fix allow clicking on a tags in maptips (#3218)

this is done by listening to the linkClicked signal
  • Loading branch information
mbernasocchi authored and m-kuhn committed Jun 21, 2016
1 parent 7697d79 commit b4436271fe46da6970eb9a6fceefdf6af268cc37
Showing with 24 additions and 2 deletions.
  1. +1 −1 python/gui/qgsmaptip.sip
  2. +1 −0 src/gui/CMakeLists.txt
  3. +14 −0 src/gui/qgsmaptip.cpp
  4. +8 −1 src/gui/qgsmaptip.h
@@ -3,7 +3,7 @@
* A maptip is a class to display a tip on a map canvas
* when a mouse is hovered over a feature.
*/
class QgsMapTip
class QgsMapTip: QWidget
{
%TypeHeaderCode
#include <qgsmaptip.h>
@@ -401,6 +401,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsmaplayerproxymodel.h
qgsmaplayerstylemanagerwidget.h
qgsmapoverviewcanvas.h
qgsmaptip.h
qgsmaptool.h
qgsmaptooladvanceddigitizing.h
qgsmaptoolcapture.h
@@ -26,6 +26,7 @@
#include <QToolTip>
#include <QSettings>
#include <QLabel>
#include <QDesktopServices>
#if WITH_QTWEBKIT
#include <QWebElement>
#endif
@@ -65,6 +66,13 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
mWidget = new QWidget( pMapCanvas );
mWebView = new QgsWebView( mWidget );


#if WITH_QTWEBKIT
mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
connect( mWebView, SIGNAL( linkClicked( QUrl ) ), this, SLOT( onLinkClicked( QUrl ) ) );
#endif

mWebView->page()->settings()->setAttribute(
QWebSettings::DeveloperExtrasEnabled, true );
mWebView->page()->settings()->setAttribute(
@@ -200,3 +208,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
return feature.attribute( idx ).toString();
}
}

//This slot handles all clicks
void QgsMapTip::onLinkClicked( const QUrl &url )
{
QDesktopServices::openUrl( url );
}
@@ -19,8 +19,12 @@ class QgsMapLayer;
class QgsMapCanvas;
class QPoint;
class QString;
class QgsPoint;
class QgsVectorLayer;
class QgsWebView;

#include <QWidget>
#include <QUrl>
#include "qgsfeature.h"

/** \ingroup gui
@@ -42,8 +46,9 @@ class QgsWebView;
* discourages link rel="stylesheet" in the body, but all browsers allow it.
* see https://jakearchibald.com/2016/link-in-body/
*/
class GUI_EXPORT QgsMapTip
class GUI_EXPORT QgsMapTip: public QWidget
{
Q_OBJECT
public:
/** Default constructor
*/
@@ -84,5 +89,7 @@ class GUI_EXPORT QgsMapTip
QWidget* mWidget;
QgsWebView* mWebView;

private slots:
void onLinkClicked( const QUrl& url );
};
#endif // QGSMAPTIP_H

0 comments on commit b443627

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