QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  {
74  sipType = sipType_QgsHighlight;
75  // We need to tweak the pointer as sip believes it is single inheritance
76  // from QgsMapCanvasItem, but the raw address of QgsHighlight (sipCpp)
77  // is actually a QObject
78  *sipCppRet = dynamic_cast<QgsHighlight *>( sipCpp );
79  }
80  else
81  sipType = nullptr;
82  SIP_END
83 #endif
84  public:
85 
86  Q_PROPERTY( QColor color READ color WRITE setColor )
87  Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
88  Q_PROPERTY( int width READ width WRITE setWidth )
89  Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
90 
97  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
98 
106  QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
107  ~QgsHighlight() override;
108 
113  QColor color( ) const { return mColor; }
114 
119  void setColor( const QColor &color );
120 
125  QColor fillColor( ) const { return mFillColor; }
126 
133  void setFillColor( const QColor &fillColor );
134 
139  int width( ) const { return mWidth; }
140 
146  void setWidth( int width );
147 
152  double buffer( ) const { return mBuffer; }
153 
159  void setBuffer( double buffer ) { mBuffer = buffer; }
160 
166  void setMinWidth( double width ) { mMinWidth = width; }
167 
171  QgsMapLayer *layer() const { return mLayer; }
172 
173  void updatePosition() override;
174 
175  protected:
176  void paint( QPainter *p ) override;
177 
179  void updateRect();
180 
181  private slots:
182  void updateTransformedGeometry();
183 
184  private:
185  enum PointSymbol
186  {
187  Square,
188  Circle
189  };
190 
191  void init();
192  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
193  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
195  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
196  void paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, QgsUnitTypes::RenderUnit sizeUnit, PointSymbol symbol );
197  void paintLine( QPainter *p, QgsPolylineXY line );
198  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
199  QgsRenderContext createRenderContext();
200 
201  int mWidth = 1; // line / stroke width property
202  QColor mColor; // line / stroke color property
203  QColor mFillColor; // line / stroke fillColor property
204  QBrush mBrush;
205  QPen mPen;
206  QgsGeometry mOriginalGeometry;
207  QgsGeometry mGeometry;
208  QPointer< QgsMapLayer > mLayer;
209  QgsFeature mFeature;
210  double mBuffer = 0; // line / stroke buffer in pixels
211  double mMinWidth = 0; // line / stroke minimum width in pixels
212  QgsRenderContext mRenderContext;
213 };
214 
215 #endif
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsPolygonXY
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:76
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsPolylineXY
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:52
QgsHighlight::width
int width() const
Returns the stroke width.
Definition: qgshighlight.h:139
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
qgsfeature.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsHighlight::setBuffer
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:159
QgsHighlight
A class for highlight features on the map.
Definition: qgshighlight.h:61
QgsHighlight::setMinWidth
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:166
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:186
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:33
qgsrendercontext.h
qgsgeometry.h
QgsHighlight::fillColor
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:125
qgshighlight.h
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsHighlight::layer
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:171
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:152
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53