QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 QObject, public QgsMapCanvasItem
50 {
51 
52  Q_OBJECT
53  Q_PROPERTY( QColor color READ color WRITE setColor )
54  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
55  Q_PROPERTY( int width READ width WRITE setWidth )
56  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
57 
58  public:
59 
66  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer );
67 
75  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature &feature, QgsVectorLayer *layer );
76  ~QgsHighlight() override;
77 
82  QColor color( ) const { return mColor; }
83 
87  void setColor( const QColor &color );
88 
93  QColor fillColor( ) const { return mFillColor; }
94 
101  void setFillColor( const QColor &fillColor );
102 
107  int width( ) const { return mWidth; }
108 
114  void setWidth( int width );
115 
120  double buffer( ) const { return mBuffer; }
121 
127  void setBuffer( double buffer ) { mBuffer = buffer; }
128 
134  void setMinWidth( double width ) { mMinWidth = width; }
135 
139  QgsMapLayer *layer() const { return mLayer; }
140 
141  void updatePosition() override;
142 
143  protected:
144  void paint( QPainter *p ) override;
145 
147  void updateRect();
148 
149  private:
150  void init();
151  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
152  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
154  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
155  void paintPoint( QPainter *p, const QgsPointXY &point );
156  void paintLine( QPainter *p, QgsPolylineXY line );
157  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
158 
159  int mWidth = 1; // line / stroke width property
160  QColor mColor; // line / stroke color property
161  QColor mFillColor; // line / stroke fillColor property
162  QBrush mBrush;
163  QPen mPen;
164  QgsGeometry *mGeometry = nullptr;
165  QgsMapLayer *mLayer = nullptr;
166  QgsFeature mFeature;
167  double mBuffer = 0; // line / stroke buffer in pixels
168  double mMinWidth = 0; // line / stroke minimum width in pixels
169 };
170 
171 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:63
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:139
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
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:68
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:106
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
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:127
A class for highlight features on the map.
Definition: qgshighlight.h:49
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:93
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:44
Contains information about the context of a rendering operation.
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:120
int width() const
Returns the stroke width.
Definition: qgshighlight.h:107
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:110
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:134