QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
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 
108  void setColor( const QColor &color );
109 
114  QColor fillColor( ) const { return mFillColor; }
115 
122  void setFillColor( const QColor &fillColor );
123 
128  int width( ) const { return mWidth; }
129 
135  void setWidth( int width );
136 
141  double buffer( ) const { return mBuffer; }
142 
148  void setBuffer( double buffer ) { mBuffer = buffer; }
149 
155  void setMinWidth( double width ) { mMinWidth = width; }
156 
160  QgsMapLayer *layer() const { return mLayer; }
161 
162  void updatePosition() override;
163 
164  protected:
165  void paint( QPainter *p ) override;
166 
168  void updateRect();
169 
170  private:
171  void init();
172  void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
173  double getSymbolWidth( const QgsRenderContext &context, double width, QgsUnitTypes::RenderUnit unit );
175  std::unique_ptr< QgsFeatureRenderer > createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
176  void paintPoint( QPainter *p, const QgsPointXY &point );
177  void paintLine( QPainter *p, QgsPolylineXY line );
178  void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
179 
180  int mWidth = 1; // line / stroke width property
181  QColor mColor; // line / stroke color property
182  QColor mFillColor; // line / stroke fillColor property
183  QBrush mBrush;
184  QPen mPen;
185  QgsGeometry *mGeometry = nullptr;
186  QgsMapLayer *mLayer = nullptr;
187  QgsFeature mFeature;
188  double mBuffer = 0; // line / stroke buffer in pixels
189  double mMinWidth = 0; // line / stroke minimum width in pixels
190 };
191 
192 #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:128
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsSymbol
Definition: qgssymbol.h:63
QgsHighlight::setBuffer
void setBuffer(double buffer)
Set line / stroke buffer in millimeters.
Definition: qgshighlight.h:148
QgsHighlight
Definition: qgshighlight.h:57
QgsHighlight::setMinWidth
void setMinWidth(double width)
Set minimum line / stroke width in millimeters.
Definition: qgshighlight.h:155
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:114
qgshighlight.h
QgsHighlight::layer
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
Definition: qgshighlight.h:160
QgsGeometry
Definition: qgsgeometry.h:122
QgsHighlight::buffer
double buffer() const
Returns the buffer.
Definition: qgshighlight.h:141
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapLayer
Definition: qgsmaplayer.h:81
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