QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
33 #ifdef SIP_RUN
34 % ModuleHeaderCode
35 // For ConvertToSubClassCode.
36 #include <qgshighlight.h>
37 % End
38 #endif
39 
56 #ifndef SIP_RUN
57 class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
58 {
59 #else
60 class GUI_EXPORT QgsHighlight : public QgsMapCanvasItem
61 {
62 #endif
63 
64  Q_OBJECT
65 
66 #ifdef SIP_RUN
68  if ( dynamic_cast<QgsHighlight *>( sipCpp ) )
69  sipType = sipType_QgsHighlight;
70  else
71  sipType = nullptr;
72  SIP_END
73 #endif
74  public:
75 
76  Q_PROPERTY( QColor color READ color WRITE setColor )
77  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
78  Q_PROPERTY( int width READ width WRITE setWidth )
79  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
80 
81 
87  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
88 
96  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
97  ~QgsHighlight() override;
98 
103  QColor color( ) const { return mColor; }
104 
109  void setColor( const QColor &color );
110 
115  QColor fillColor( ) const { return mFillColor; }
116 
123  void setFillColor( const QColor &fillColor );
124 
129  int width( ) const { return mWidth; }
130 
136  void setWidth( int width );
137 
142  double buffer( ) const { return mBuffer; }
143 
149  void setBuffer( double buffer ) { mBuffer = buffer; }
150 
156  void setMinWidth( double width ) { mMinWidth = width; }
157 
161  QgsMapLayer *layer() const { return mLayer; }
162 
163  void updatePosition() override;
164 
165  protected:
166  void paint( QPainter *p ) override;
167 
169  void updateRect();
170 
171  private:
172  void init();
173  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
174  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
176  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
177  void paintPoint( QPainter *p, const QgsPointXY &point );
178  void paintLine( QPainter *p, QgsPolylineXY line );
179  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
180 
181  int mWidth = 1; // line / stroke width property
182  QColor mColor; // line / stroke color property
183  QColor mFillColor; // line / stroke fillColor property
184  QBrush mBrush;
185  QPen mPen;
186  QgsGeometry *mGeometry = nullptr;
187  QgsMapLayer *mLayer = nullptr;
188  QgsFeature mFeature;
189  double mBuffer = 0; // line / stroke buffer in pixels
190  double mMinWidth = 0; // line / stroke minimum width in pixels
191 };
192 
193 #endif
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsHighlight::color
QColor color() const
Returns the line/stroke color.
Definition: qgshighlight.h:103
QgsPolygonXY
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:75
QgsPolylineXY
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:51
QgsHighlight::width
int width() const
Returns the stroke width.
Definition: qgshighlight.h:129
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsHighlight::setBuffer
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:149
QgsHighlight
A class for highlight features on the map.
Definition: qgshighlight.h:58
QgsHighlight::setMinWidth
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:156
QgsMapCanvasItem::updatePosition
virtual void updatePosition()
called on changed extent or resize event to update position of the item
Definition: qgsmapcanvasitem.cpp:135
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QgsMapCanvasItem::paint
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
qgsmapcanvasitem.h
QgsMapCanvasItem
An abstract class for items that can be placed on the map canvas.
Definition: qgsmapcanvasitem.h:34
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
qgsgeometry.h
QgsHighlight::fillColor
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:115
qgshighlight.h
QgsHighlight::layer
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:161
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsHighlight::buffer
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:142
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgssymbol.h