QGIS API Documentation  2.99.0-Master (23ddace)
qgshighlight.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgshighlight.h - widget to highlight geometries
3  --------------------------------------
4  Date : 02-Mar-2011
5  Copyright : (C) 2011 by Juergen E. Fischer, norBIT GmbH
6  Email : jef at norbit dot de
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 QGSHIGHLIGHT_H
16 #define QGSHIGHLIGHT_H
17 
18 #include "qgsmapcanvasitem.h"
19 #include "qgsgeometry.h"
20 #include "qgssymbol.h"
21 #include <QBrush>
22 #include <QColor>
23 #include <QList>
24 #include <QPen>
25 #include <QPainter>
26 #include <QPainterPath>
27 #include "qgis_gui.h"
28 
29 class QgsMapLayer;
30 class QgsVectorLayer;
31 class QgsSymbol;
32 
39 class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
40 {
41  public:
42 
49  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer ) SIP_SKIP;
50 
56  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsVectorLayer *layer );
57 
64  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer );
65  ~QgsHighlight();
66 
69  void setColor( const QColor &color );
70 
73  void setFillColor( const QColor &fillColor );
74 
76  void setWidth( int width );
77 
80  void setBuffer( double buffer ) { mBuffer = buffer; }
81 
84  void setMinWidth( double width ) { mMinWidth = width; }
85 
86  const QgsMapLayer *layer() const { return mLayer; }
87 
88  virtual void updatePosition() override;
89 
90  protected:
91  virtual void paint( QPainter *p ) override;
92 
94  void updateRect();
95 
96  private:
97  void init();
98  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
99  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
101  QgsFeatureRenderer *getRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
102  void paintPoint( QPainter *p, const QgsPointXY &point );
103  void paintLine( QPainter *p, QgsPolyline line );
104  void paintPolygon( QPainter *p, QgsPolygon polygon );
105 
106  QBrush mBrush;
107  QPen mPen;
108  QgsGeometry *mGeometry = nullptr;
109  QgsMapLayer *mLayer = nullptr;
110  QgsFeature mFeature;
111  double mBuffer; // line / stroke buffer in pixels
112  double mMinWidth; // line / stroke minimum width in pixels
113 };
114 
115 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:54
A class to represent a 2D point.
Definition: qgspointxy.h:42
An abstract class for items that can be placed on the map canvas.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:96
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:61
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:73
QVector< QgsPointXY > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:48
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:80
#define SIP_SKIP
Definition: qgis_sip.h:107
A class for highlight features on the map.
Definition: qgshighlight.h:39
QVector< QgsPolyline > QgsPolygon
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:55
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
Contains information about the context of a rendering operation.
const QgsMapLayer * layer() const
Definition: qgshighlight.h:86
Represents a vector layer which manages a vector based data sets.
virtual void updatePosition()
called on changed extent or resize event to update position of the item
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:95
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:84