QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 <QPointer>
28 #include "qgis_gui.h"
29 
30 class QgsMapLayer;
31 class QgsVectorLayer;
32 class QgsSymbol;
33 
34 #ifdef SIP_RUN
35 % ModuleHeaderCode
36 // For ConvertToSubClassCode.
37 #include <qgshighlight.h>
38 % End
39 #endif
40 
57 #ifndef SIP_RUN
58 class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
59 {
60 #else
61 class GUI_EXPORT QgsHighlight : public QgsMapCanvasItem
62 {
63 #endif
64 
65  Q_OBJECT
66 
67 #ifdef SIP_RUN
69  if ( dynamic_cast<QgsHighlight *>( sipCpp ) )
70  sipType = sipType_QgsHighlight;
71  else
72  sipType = nullptr;
73  SIP_END
74 #endif
75  public:
76 
77  Q_PROPERTY( QColor color READ color WRITE setColor )
78  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
79  Q_PROPERTY( int width READ width WRITE setWidth )
80  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
81 
82 
88  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
89 
97  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
98  ~QgsHighlight() override;
99 
104  QColor color( ) const { return mColor; }
105 
110  void setColor( const QColor &color );
111 
116  QColor fillColor( ) const { return mFillColor; }
117 
124  void setFillColor( const QColor &fillColor );
125 
130  int width( ) const { return mWidth; }
131 
137  void setWidth( int width );
138 
143  double buffer( ) const { return mBuffer; }
144 
150  void setBuffer( double buffer ) { mBuffer = buffer; }
151 
157  void setMinWidth( double width ) { mMinWidth = width; }
158 
162  QgsMapLayer *layer() const { return mLayer; }
163 
164  void updatePosition() override;
165 
166  protected:
167  void paint( QPainter *p ) override;
168 
170  void updateRect();
171 
172  private slots:
173  void updateTransformedGeometry();
174 
175  private:
176  enum PointSymbol
177  {
178  Square,
179  Circle
180  };
181 
182  void init();
183  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
184  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
186  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
187  void paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, QgsUnitTypes::RenderUnit sizeUnit, PointSymbol symbol );
188  void paintLine( QPainter *p, QgsPolylineXY line );
189  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
190  QgsRenderContext createRenderContext();
191 
192  int mWidth = 1; // line / stroke width property
193  QColor mColor; // line / stroke color property
194  QColor mFillColor; // line / stroke fillColor property
195  QBrush mBrush;
196  QPen mPen;
197  QgsGeometry mOriginalGeometry;
198  QgsGeometry mGeometry;
199  QPointer< QgsMapLayer > mLayer;
200  QgsFeature mFeature;
201  double mBuffer = 0; // line / stroke buffer in pixels
202  double mMinWidth = 0; // line / stroke minimum width in pixels
203  QgsRenderContext mRenderContext;
204 };
205 
206 #endif
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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:59
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:143
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:150
int width() const
Returns the stroke width.
Definition: qgshighlight.h:130
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:116
~QgsHighlight() override
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:162
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:157
QColor color() const
Returns the line/stroke color.
Definition: qgshighlight.h:104
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:85
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
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