QGIS API Documentation  3.13.0-Master (788156190c)
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
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsPolygonXY
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:74
QgsPolylineXY
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition: qgsgeometry.h:50
QgsHighlight::width
int width() const
Returns the stroke width.
Definition: qgshighlight.h:122
QgsMapCanvas
Definition: qgsmapcanvas.h:78
QgsRenderContext
Definition: qgsrendercontext.h:56
QgsSymbol
Definition: qgssymbol.h:62
QgsHighlight::setBuffer
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:142
QgsHighlight
Definition: qgshighlight.h:56
QgsHighlight::setMinWidth
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:149
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:172
QgsMapCanvasItem::paint
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
qgsmapcanvasitem.h
QgsMapCanvasItem
Definition: qgsmapcanvasitem.h:33
QgsPointXY
Definition: qgspointxy.h:43
qgsgeometry.h
QgsHighlight::fillColor
QColor fillColor() const
Returns the fill color.
Definition: qgshighlight.h:108
qgshighlight.h
QgsHighlight::layer
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:154
QgsGeometry
Definition: qgsgeometry.h:122
QgsHighlight::buffer
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:135
QgsVectorLayer
Definition: qgsvectorlayer.h:386
QgsMapLayer
Definition: qgsmaplayer.h:80
QgsFeature
Definition: qgsfeature.h:55
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
qgssymbol.h