QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 class GUI_EXPORT QgsHighlight: public QObject, public QgsMapCanvasItem
57 {
58  Q_OBJECT
59 
60 #ifdef SIP_RUN
62  if ( dynamic_cast<QgsHighlight *>( sipCpp ) )
63  sipType = sipType_QgsHighlight;
64  else
65  sipType = nullptr;
66  SIP_END
67 #endif
68  public:
69 
70  Q_PROPERTY( QColor color READ color WRITE setColor )
71  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
72  Q_PROPERTY( int width READ width WRITE setWidth )
73  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
74 
81  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
82 
90  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
91  ~QgsHighlight() override;
92 
97  QColor color( ) const { return mColor; }
98 
102  void setColor( const QColor &color );
103 
108  QColor fillColor( ) const { return mFillColor; }
109 
116  void setFillColor( const QColor &fillColor );
117 
122  int width( ) const { return mWidth; }
123 
129  void setWidth( int width );
130 
135  double buffer( ) const { return mBuffer; }
136 
142  void setBuffer( double buffer ) { mBuffer = buffer; }
143 
149  void setMinWidth( double width ) { mMinWidth = width; }
150 
154  QgsMapLayer *layer() const { return mLayer; }
155 
156  void updatePosition() override;
157 
158  protected:
159  void paint( QPainter *p ) override;
160 
162  void updateRect();
163 
164  private:
165  void init();
166  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
167  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
169  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
170  void paintPoint( QPainter *p, const QgsPointXY &point );
171  void paintLine( QPainter *p, QgsPolylineXY line );
172  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
173 
174  int mWidth = 1; // line / stroke width property
175  QColor mColor; // line / stroke color property
176  QColor mFillColor; // line / stroke fillColor property
177  QBrush mBrush;
178  QPen mPen;
179  QgsGeometry *mGeometry = nullptr;
180  QgsMapLayer *mLayer = nullptr;
181  QgsFeature mFeature;
182  double mBuffer = 0; // line / stroke buffer in pixels
183  double mMinWidth = 0; // line / stroke minimum width in pixels
184 };
185 
186 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:79
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:154
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
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:74
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:122
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:75
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:142
A class for highlight features on the map.
Definition: qgshighlight.h:56
#define SIP_END
Definition: qgis_sip.h:189
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:108
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:50
Contains information about the context of a rendering operation.
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:135
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
int width() const
Returns the stroke width.
Definition: qgshighlight.h:122
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:145
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:149