QGIS API Documentation  2.99.0-Master (b058df7)
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 
49 class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
50 {
51  public:
52 
59  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer );
60 
68  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer );
69  ~QgsHighlight();
70 
74  void setColor( const QColor &color );
75 
82  void setFillColor( const QColor &fillColor );
83 
89  void setWidth( int width );
90 
96  void setBuffer( double buffer ) { mBuffer = buffer; }
97 
103  void setMinWidth( double width ) { mMinWidth = width; }
104 
108  QgsMapLayer *layer() const { return mLayer; }
109 
110  virtual void updatePosition() override;
111 
112  protected:
113  virtual void paint( QPainter *p ) override;
114 
116  void updateRect();
117 
118  private:
119  void init();
120  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
121  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
123  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
124  void paintPoint( QPainter *p, const QgsPointXY &point );
125  void paintLine( QPainter *p, QgsPolylineXY line );
126  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
127 
128  QBrush mBrush;
129  QPen mPen;
130  QgsGeometry *mGeometry = nullptr;
131  QgsMapLayer *mLayer = nullptr;
132  QgsFeature mFeature;
133  double mBuffer = 0; // line / stroke buffer in pixels
134  double mMinWidth = 0; // line / stroke minimum width in pixels
135 };
136 
137 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:56
QgsMapLayer * layer() const
Return the layer for which this highlight has been created.
Definition: qgshighlight.h:108
A class to represent a 2D point.
Definition: qgspointxy.h:43
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:73
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:111
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:96
A class for highlight features on the map.
Definition: qgshighlight.h:49
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:49
Contains information about the context of a rendering operation.
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:100
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:103