mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Fix allow clicking on a tags in maptips (#3218)
this is done by listening to the linkClicked signal
This commit is contained in:
parent
7697d79a21
commit
b4436271fe
@ -3,7 +3,7 @@
|
|||||||
* A maptip is a class to display a tip on a map canvas
|
* A maptip is a class to display a tip on a map canvas
|
||||||
* when a mouse is hovered over a feature.
|
* when a mouse is hovered over a feature.
|
||||||
*/
|
*/
|
||||||
class QgsMapTip
|
class QgsMapTip: QWidget
|
||||||
{
|
{
|
||||||
%TypeHeaderCode
|
%TypeHeaderCode
|
||||||
#include <qgsmaptip.h>
|
#include <qgsmaptip.h>
|
||||||
|
@ -401,6 +401,7 @@ SET(QGIS_GUI_MOC_HDRS
|
|||||||
qgsmaplayerproxymodel.h
|
qgsmaplayerproxymodel.h
|
||||||
qgsmaplayerstylemanagerwidget.h
|
qgsmaplayerstylemanagerwidget.h
|
||||||
qgsmapoverviewcanvas.h
|
qgsmapoverviewcanvas.h
|
||||||
|
qgsmaptip.h
|
||||||
qgsmaptool.h
|
qgsmaptool.h
|
||||||
qgsmaptooladvanceddigitizing.h
|
qgsmaptooladvanceddigitizing.h
|
||||||
qgsmaptoolcapture.h
|
qgsmaptoolcapture.h
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QDesktopServices>
|
||||||
#if WITH_QTWEBKIT
|
#if WITH_QTWEBKIT
|
||||||
#include <QWebElement>
|
#include <QWebElement>
|
||||||
#endif
|
#endif
|
||||||
@ -65,6 +66,13 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
|
|||||||
mWidget = new QWidget( pMapCanvas );
|
mWidget = new QWidget( pMapCanvas );
|
||||||
mWebView = new QgsWebView( mWidget );
|
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(
|
mWebView->page()->settings()->setAttribute(
|
||||||
QWebSettings::DeveloperExtrasEnabled, true );
|
QWebSettings::DeveloperExtrasEnabled, true );
|
||||||
mWebView->page()->settings()->setAttribute(
|
mWebView->page()->settings()->setAttribute(
|
||||||
@ -200,3 +208,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
|
|||||||
return feature.attribute( idx ).toString();
|
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 QgsMapCanvas;
|
||||||
class QPoint;
|
class QPoint;
|
||||||
class QString;
|
class QString;
|
||||||
|
class QgsPoint;
|
||||||
|
class QgsVectorLayer;
|
||||||
class QgsWebView;
|
class QgsWebView;
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QUrl>
|
||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
|
|
||||||
/** \ingroup gui
|
/** \ingroup gui
|
||||||
@ -42,8 +46,9 @@ class QgsWebView;
|
|||||||
* discourages link rel="stylesheet" in the body, but all browsers allow it.
|
* discourages link rel="stylesheet" in the body, but all browsers allow it.
|
||||||
* see https://jakearchibald.com/2016/link-in-body/
|
* see https://jakearchibald.com/2016/link-in-body/
|
||||||
*/
|
*/
|
||||||
class GUI_EXPORT QgsMapTip
|
class GUI_EXPORT QgsMapTip: public QWidget
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/** Default constructor
|
/** Default constructor
|
||||||
*/
|
*/
|
||||||
@ -84,5 +89,7 @@ class GUI_EXPORT QgsMapTip
|
|||||||
QWidget* mWidget;
|
QWidget* mWidget;
|
||||||
QgsWebView* mWebView;
|
QgsWebView* mWebView;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onLinkClicked( const QUrl& url );
|
||||||
};
|
};
|
||||||
#endif // QGSMAPTIP_H
|
#endif // QGSMAPTIP_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user