QGIS API Documentation 3.99.0-Master (21b3aa880ba)
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 "qgis_gui.h"
27#include "qgsfeature.h"
28
29#include <QTimer>
30#include <QUrl>
31#include <QWidget>
32
52class GUI_EXPORT QgsMapTip : public QWidget
53{
54 Q_OBJECT
55 public:
56
60 QgsMapTip();
61
72 void showMapTip( QgsMapLayer *thepLayer, QgsPointXY &mapPosition, const QPoint &pixelPosition, QgsMapCanvas *mpMapCanvas );
73
79 void clear( QgsMapCanvas *mpMapCanvas = nullptr, int msDelay = 0 );
80
86 static QString vectorMapTipPreviewText( QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate, const QString &displayExpression );
87
93 static QString rasterMapTipPreviewText( QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate );
94
95 private slots:
96 void onLinkClicked( const QUrl &url );
97 void resizeAndMoveToolTip();
98
99 private:
100 // Fetch the feature to use for the maptip text.
101 // Only the first feature in the search radius is used
102 QString fetchFeature( QgsMapLayer *thepLayer, QgsPointXY &mapPosition, QgsMapCanvas *mapCanvas );
103
104 // Sample the raster and get the maptip text
105 QString fetchRaster( QgsMapLayer *layer, QgsPointXY &mapPosition, QgsMapCanvas *mapCanvas );
106
107 // Insert the raw map tip text into an HTML template and return the result
108 static QString htmlText( const QString &text, int maxWidth = -1 );
109
110 // Flag to indicate if a maptip is currently being displayed
111 bool mMapTipVisible;
112
113 QgsWebView *mWebView = nullptr;
114
115 static const int MARGIN_VALUE = 5;
116
117 QTimer mDelayedClearTimer;
118
119 // Template for the actual HTML content that will be displayed in QgsWebView
120 static const QString sMapTipTemplate;
121
122 QPoint mPosition;
123 const QgsMapCanvas *mMapCanvas = nullptr;
124};
125#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:80
void showMapTip(QgsMapLayer *thepLayer, QgsPointXY &mapPosition, const QPoint &pixelPosition, QgsMapCanvas *mpMapCanvas)
Show a maptip at a given point on the map canvas.
Definition qgsmaptip.cpp:87
static QString rasterMapTipPreviewText(QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate)
Returns the html that would be displayed in a maptip for a given layer.
static QString vectorMapTipPreviewText(QgsMapLayer *layer, QgsMapCanvas *mapCanvas, const QString &mapTemplate, const QString &displayExpression)
Returns the html that would be displayed in a maptip for a given layer.
QgsMapTip()
Default constructor.
Definition qgsmaptip.cpp:78
void clear(QgsMapCanvas *mpMapCanvas=nullptr, int msDelay=0)
Clear the current maptip if it exists.
Represents a 2D point.
Definition qgspointxy.h:60
Represents a vector layer which manages a vector based dataset.
A collection of stubs to mimic the API of QWebView on systems where the real library is not available...
Definition qgswebview.h:66