QGIS API Documentation  2.99.0-Master (c558d51)
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 
28 class QgsMapLayer;
29 class QgsVectorLayer;
30 class QgsSymbol;
31 
35 class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
36 {
37  public:
38 
44  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry& geom, QgsMapLayer *layer );
45 
51  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry& geom, QgsVectorLayer *layer );
52 
59  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature& feature, QgsVectorLayer *layer );
60  ~QgsHighlight();
61 
64  void setColor( const QColor & color );
65 
68  void setFillColor( const QColor & fillColor );
69 
71  void setWidth( int width );
72 
75  void setBuffer( double buffer ) { mBuffer = buffer; }
76 
79  void setMinWidth( double width ) { mMinWidth = width; }
80 
81  const QgsMapLayer *layer() const { return mLayer; }
82 
83  virtual void updatePosition() override;
84 
85  protected:
86  virtual void paint( QPainter* p ) override;
87 
89  void updateRect();
90 
91  private:
92  void init();
93  void setSymbol( QgsSymbol* symbol, const QgsRenderContext & context, const QColor & color, const QColor & fillColor );
94  double getSymbolWidth( const QgsRenderContext & context, double width, QgsUnitTypes::RenderUnit unit );
96  QgsFeatureRenderer * getRenderer( QgsRenderContext &context, const QColor & color, const QColor & fillColor );
97  void paintPoint( QPainter *p, const QgsPoint& point );
98  void paintLine( QPainter *p, QgsPolyline line );
99  void paintPolygon( QPainter *p, QgsPolygon polygon );
100 
101  QBrush mBrush;
102  QPen mPen;
103  QgsGeometry *mGeometry;
104  QgsMapLayer *mLayer;
105  QgsFeature mFeature;
106  double mBuffer; // line / outline buffer in pixels
107  double mMinWidth; // line / outline minimum width in pixels
108 };
109 
110 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QVector< QgsPoint > QgsPolyline
Polyline is represented as a vector of points.
Definition: qgsgeometry.h:46
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:78
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:106
void setBuffer(double buffer)
Set line / outline buffer in millimeters.
Definition: qgshighlight.h:75
A class for highlight features on the map.
Definition: qgshighlight.h:35
QVector< QgsPolyline > QgsPolygon
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:52
const QgsMapLayer * layer() const
Definition: qgshighlight.h:81
A class to represent a point.
Definition: qgspoint.h:111
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
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:91
void setMinWidth(double width)
Set minimum line / outline width in millimeters.
Definition: qgshighlight.h:79