Skip to content

Commit

Permalink
Fix allow clicking on a tags in maptips (#3218)
Browse files Browse the repository at this point in the history
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 b443627
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmaptip.sip
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -401,6 +401,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsmaplayerproxymodel.h
qgsmaplayerstylemanagerwidget.h
qgsmapoverviewcanvas.h
qgsmaptip.h
qgsmaptool.h
qgsmaptooladvanceddigitizing.h
qgsmaptoolcapture.h
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -26,6 +26,7 @@
#include <QToolTip>
#include <QSettings>
#include <QLabel>
#include <QDesktopServices>
#if WITH_QTWEBKIT
#include <QWebElement>
#endif
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 );
}
9 changes: 8 additions & 1 deletion src/gui/qgsmaptip.h
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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.