29 #include <QDesktopServices> 31 #include <QWebElement> 33 #include <QHBoxLayout> 39 : mWidget( nullptr ), mWebView( nullptr )
42 mMapTipVisible =
false;
62 QString tipText, lastTipText, tipHtml, bodyStyle, containerStyle,
63 backgroundColor, borderColor;
66 mWidget =
new QWidget( pMapCanvas );
71 mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
73 connect( mWebView, SIGNAL( linkClicked(
QUrl ) ),
this, SLOT( onLinkClicked(
QUrl ) ) );
77 QWebSettings::DeveloperExtrasEnabled,
true );
79 QWebSettings::JavascriptEnabled,
true );
84 mWidget->
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
88 const int MAX_WIDTH = pMapCanvas->
geometry().width() / 2;
89 const int MAX_HEIGHT = pMapCanvas->
geometry().height() / 2;
96 backgroundColor = mWidget->
palette().base().color().name();
97 borderColor = mWidget->
palette().shadow().color().name();
100 "border: 1px solid %1;" 101 "background-color: %2;}" ).arg(
102 borderColor, backgroundColor ) );
104 tipText = fetchFeature( pLayer, mapPosition, pMapCanvas );
106 mMapTipVisible = !tipText.
isEmpty();
107 if ( !mMapTipVisible )
113 if ( tipText == lastTipText )
119 "background-color: %1;" 120 "margin: 0;" ).
arg( backgroundColor );
123 "display: inline-block;" 129 "<div id='QgsWebViewContainer' style='%2'>%3</div>" 131 "</html>" ).
arg( bodyStyle, containerStyle, tipText );
133 mWidget->
move( thePixelPosition.
x(),
134 thePixelPosition.
y() );
137 lastTipText = tipText;
142 int scrollbarWidth = mWebView->page()->mainFrame()->scrollBarGeometry(
143 Qt::Vertical ).
width();
144 int scrollbarHeight = mWebView->page()->mainFrame()->scrollBarGeometry(
145 Qt::Horizontal ).
height();
147 if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
150 QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
151 "#QgsWebViewContainer" );
155 mWidget->
resize( width, height );
162 if ( !mMapTipVisible )
169 mMapTipVisible =
false;
213 void QgsMapTip::onLinkClicked(
const QUrl &url )
A rectangle specified with double values.
Base class for all map layer types.
void setXMaximum(double x)
Set the maximum x value.
Use exact geometry intersection (slower) instead of bounding boxes.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setHtml(const QString &text)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
virtual ~QgsMapTip()
Destructor.
Map canvas is a class for displaying all GIS data types on a canvas.
double y() const
Get the y value of the point.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void setYMinimum(double y)
Set the minimum y value.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void clear(QgsMapCanvas *mpMapCanvas=nullptr)
Clear the current maptip if it exists.
void showMapTip(QgsMapLayer *thepLayer, QgsPoint &theMapPosition, QPoint &thePixelPosition, QgsMapCanvas *mpMapCanvas)
Show a maptip at a given point on the map canvas.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
The QgsWebView class is a collection of stubs to mimic the API of QWebView on systems where the real ...
A class to represent a point.
QString displayField() const
Returns the primary display field name used in the identify results dialog.
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from output CRS to layer's CRS
void setYMaximum(double y)
Set the maximum y value.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
static Q_DECL_DEPRECATED QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=nullptr, const QgsDistanceArea *distanceArea=nullptr)
This function currently replaces each expression between [% and %] in the string with the result of i...
QgsMapTip()
Default constructor.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
bool openUrl(const QUrl &url)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
double x() const
Get the x value of the point.
void setXMinimum(double x)
Set the minimum x value.