QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsmaptip.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptip.h - Query a layer and show a maptip on the canvas
3 ---------------------
4 begin : October 2007
5 copyright : (C) 2007 by Gary Sherman
6 email : sherman @ mrcc dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSMAPTIP_H
16#define QGSMAPTIP_H
17
18class QgsMapLayer;
19class QgsMapCanvas;
20class QPoint;
21class QString;
22class QgsPointXY;
23class QgsVectorLayer;
24class QgsWebView;
25
26#include <QWidget>
27#include <QUrl>
28#include <QTimer>
29#include "qgsfeature.h"
30#include "qgis_gui.h"
31
52class GUI_EXPORT QgsMapTip : public QWidget
53{
54 Q_OBJECT
55 public:
56
60 QgsMapTip();
61
72 void showMapTip( QgsMapLayer *thepLayer,
73 QgsPointXY &mapPosition,
74 const QPoint &pixelPosition,
75 QgsMapCanvas *mpMapCanvas );
76
82 void clear( QgsMapCanvas *mpMapCanvas = nullptr, int msDelay = 0 );
83
89 static QString vectorMapTipPreviewText( QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate, const QString &displayExpression );
90
96 static QString rasterMapTipPreviewText( QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate );
97
98 private slots:
99 void onLinkClicked( const QUrl &url );
100 void resizeAndMoveToolTip();
101
102 private:
103 // Fetch the feature to use for the maptip text.
104 // Only the first feature in the search radius is used
105 QString fetchFeature( QgsMapLayer *thepLayer,
106 QgsPointXY &mapPosition,
107 QgsMapCanvas *mapCanvas );
108
109 // Sample the raster and get the maptip text
110 QString fetchRaster( QgsMapLayer *layer,
111 QgsPointXY &mapPosition,
112 QgsMapCanvas *mapCanvas );
113
114 // Insert the raw map tip text into an HTML template and return the result
115 static QString htmlText( const QString &text, int maxWidth = -1 );
116
117 // Flag to indicate if a maptip is currently being displayed
118 bool mMapTipVisible;
119
120 QgsWebView *mWebView = nullptr;
121
122 static const int MARGIN_VALUE = 5;
123
124 QTimer mDelayedClearTimer;
125
126 // Template for the actual HTML content that will be displayed in QgsWebView
127 static const QString sMapTipTemplate;
128
129 QPoint mPosition;
130 const QgsMapCanvas *mMapCanvas = nullptr;
131};
132#endif // QGSMAPTIP_H
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:76
A maptip is a class to display a tip on a map canvas when a mouse is hovered over a feature.
Definition qgsmaptip.h:53
A class to represent a 2D point.
Definition qgspointxy.h:60
Represents a vector layer which manages a vector based data sets.
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...
Definition qgswebview.h:66