QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 "qgis_gui.h"
19 #include "qgsfeature.h"
20 #include "qgsrendercontext.h"
21 #include "qgsmapcanvasitem.h"
22 #include "qgsgeometry.h"
23 #include <QBrush>
24 #include <QColor>
25 #include <QList>
26 #include <QPen>
27 #include <QPainter>
28 #include <QPainterPath>
29 #include <QPointer>
30 
31 class QgsMapLayer;
32 class QgsVectorLayer;
33 class QgsSymbol;
34 class QgsFeatureRenderer;
35 
36 
37 #ifdef SIP_RUN
38 % ModuleHeaderCode
39 // For ConvertToSubClassCode.
40 #include <qgshighlight.h>
41 % End
42 #endif
43 
60 #ifndef SIP_RUN
61 class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
62 {
63 #else
64 class GUI_EXPORT QgsHighlight : public QgsMapCanvasItem
65 {
66 #endif
67 
68  Q_OBJECT
69 
70 #ifdef SIP_RUN
72  if ( dynamic_cast<QgsHighlight *>( sipCpp ) )
73  sipType = sipType_QgsHighlight;
74  else
75  sipType = nullptr;
76  SIP_END
77 #endif
78  public:
79 
80  Q_PROPERTY( QColor color READ color WRITE setColor )
81  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
82  Q_PROPERTY( int width READ width WRITE setWidth )
83  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
84 
85 
91  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
92 
100  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
101  ~QgsHighlight() override;
102 
107  QColor color( ) const { return mColor; }
108 
113  void setColor( const QColor &color );
114 
119  QColor fillColor( ) const { return mFillColor; }
120 
127  void setFillColor( const QColor &fillColor );
128 
133  int width( ) const { return mWidth; }
134 
140  void setWidth( int width );
141 
146  double buffer( ) const { return mBuffer; }
147 
153  void setBuffer( double buffer ) { mBuffer = buffer; }
154 
160  void setMinWidth( double width ) { mMinWidth = width; }
161 
165  QgsMapLayer *layer() const { return mLayer; }
166 
167  void updatePosition() override;
168 
169  protected:
170  void paint( QPainter *p ) override;
171 
173  void updateRect();
174 
175  private slots:
176  void updateTransformedGeometry();
177 
178  private:
179  enum PointSymbol
180  {
181  Square,
182  Circle
183  };
184 
185  void init();
186  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
187  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
189  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
190  void paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, QgsUnitTypes::RenderUnit sizeUnit, PointSymbol symbol );
191  void paintLine( QPainter *p, QgsPolylineXY line );
192  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
193  QgsRenderContext createRenderContext();
194 
195  int mWidth = 1; // line / stroke width property
196  QColor mColor; // line / stroke color property
197  QColor mFillColor; // line / stroke fillColor property
198  QBrush mBrush;
199  QPen mPen;
200  QgsGeometry mOriginalGeometry;
201  QgsGeometry mGeometry;
202  QPointer< QgsMapLayer > mLayer;
203  QgsFeature mFeature;
204  double mBuffer = 0; // line / stroke buffer in pixels
205  double mMinWidth = 0; // line / stroke minimum width in pixels
206  QgsRenderContext mRenderContext;
207 };
208 
209 #endif
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
A class for highlight features on the map.
Definition: qgshighlight.h:62
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:146
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:153
int width() const
Returns the stroke width.
Definition: qgshighlight.h:133
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:119
~QgsHighlight() override
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:165
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:160
QColor color() const
Returns the line/stroke color.
Definition: qgshighlight.h:107
An abstract class for items that can be placed on the map canvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:86
Base class for all map layer types.
Definition: qgsmaplayer.h:70
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:38
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
Represents a vector layer which manages a vector based data sets.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_END
Definition: qgis_sip.h:194
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:75
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:51