Skip to content

Commit b443627

Browse files
mbernasocchim-kuhn
authored andcommitted
Fix allow clicking on a tags in maptips (#3218)
this is done by listening to the linkClicked signal
1 parent 7697d79 commit b443627

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

python/gui/qgsmaptip.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* A maptip is a class to display a tip on a map canvas
44
* when a mouse is hovered over a feature.
55
*/
6-
class QgsMapTip
6+
class QgsMapTip: QWidget
77
{
88
%TypeHeaderCode
99
#include <qgsmaptip.h>

src/gui/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ SET(QGIS_GUI_MOC_HDRS
401401
qgsmaplayerproxymodel.h
402402
qgsmaplayerstylemanagerwidget.h
403403
qgsmapoverviewcanvas.h
404+
qgsmaptip.h
404405
qgsmaptool.h
405406
qgsmaptooladvanceddigitizing.h
406407
qgsmaptoolcapture.h

src/gui/qgsmaptip.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QToolTip>
2727
#include <QSettings>
2828
#include <QLabel>
29+
#include <QDesktopServices>
2930
#if WITH_QTWEBKIT
3031
#include <QWebElement>
3132
#endif
@@ -65,6 +66,13 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
6566
mWidget = new QWidget( pMapCanvas );
6667
mWebView = new QgsWebView( mWidget );
6768

69+
70+
#if WITH_QTWEBKIT
71+
mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
72+
mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
73+
connect( mWebView, SIGNAL( linkClicked( QUrl ) ), this, SLOT( onLinkClicked( QUrl ) ) );
74+
#endif
75+
6876
mWebView->page()->settings()->setAttribute(
6977
QWebSettings::DeveloperExtrasEnabled, true );
7078
mWebView->page()->settings()->setAttribute(
@@ -200,3 +208,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
200208
return feature.attribute( idx ).toString();
201209
}
202210
}
211+
212+
//This slot handles all clicks
213+
void QgsMapTip::onLinkClicked( const QUrl &url )
214+
{
215+
QDesktopServices::openUrl( url );
216+
}

src/gui/qgsmaptip.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ class QgsMapLayer;
1919
class QgsMapCanvas;
2020
class QPoint;
2121
class QString;
22+
class QgsPoint;
23+
class QgsVectorLayer;
2224
class QgsWebView;
2325

26+
#include <QWidget>
27+
#include <QUrl>
2428
#include "qgsfeature.h"
2529

2630
/** \ingroup gui
@@ -42,8 +46,9 @@ class QgsWebView;
4246
* discourages link rel="stylesheet" in the body, but all browsers allow it.
4347
* see https://jakearchibald.com/2016/link-in-body/
4448
*/
45-
class GUI_EXPORT QgsMapTip
49+
class GUI_EXPORT QgsMapTip: public QWidget
4650
{
51+
Q_OBJECT
4752
public:
4853
/** Default constructor
4954
*/
@@ -84,5 +89,7 @@ class GUI_EXPORT QgsMapTip
8489
QWidget* mWidget;
8590
QgsWebView* mWebView;
8691

92+
private slots:
93+
void onLinkClicked( const QUrl& url );
8794
};
8895
#endif // QGSMAPTIP_H

0 commit comments

Comments
 (0)