QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsgeometry.h"
21#include "qgsmapcanvasitem.h"
22#include "qgsrendercontext.h"
23
24#include <QBrush>
25#include <QColor>
26#include <QList>
27#include <QPainter>
28#include <QPainterPath>
29#include <QPen>
30#include <QPointer>
31
32class QgsMapLayer;
33class QgsVectorLayer;
34class QgsSymbol;
36
37
38#ifdef SIP_RUN
39//%ModuleHeaderCode
40// For ConvertToSubClassCode.
41#include <qgshighlight.h>
42//%End
43#endif
44
61#ifndef SIP_RUN
62class GUI_EXPORT QgsHighlight : public QObject, public QgsMapCanvasItem
63{
64#else
65class GUI_EXPORT QgsHighlight : public QgsMapCanvasItem
66{
67#endif
68
69 Q_OBJECT
70
71#ifdef SIP_RUN
73 if ( dynamic_cast<QgsHighlight *>( sipCpp ) )
74 {
75 sipType = sipType_QgsHighlight;
76 // We need to tweak the pointer as sip believes it is single inheritance
77 // from QgsMapCanvasItem, but the raw address of QgsHighlight (sipCpp)
78 // is actually a QObject
79 *sipCppRet = dynamic_cast<QgsHighlight *>( sipCpp );
80 }
81 else
82 sipType = nullptr;
84#endif
85 public:
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
98
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
132 void setFillColor( const QColor &fillColor );
133
138 int width() const { return mWidth; }
139
145 void setWidth( int width );
146
154 double buffer() const { return mBuffer; }
155
161 void setBuffer( double buffer ) { mBuffer = buffer; }
162
166 void setMinWidth( double width ) { mMinWidth = width; }
167
171 QgsMapLayer *layer() const { return mLayer; }
172
173 void updatePosition() override;
174
180 void applyDefaultStyle();
181
182 protected:
183 void paint( QPainter *p ) override;
184
186 void updateRect();
187
188 private slots:
189 void updateTransformedGeometry();
190
191 private:
192 enum PointSymbol
193 {
194 Square,
195 Circle
196 };
197
198 void init();
199 void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
200 double getSymbolWidth( const QgsRenderContext &context, double width, Qgis::RenderUnit unit );
202 std::unique_ptr<QgsFeatureRenderer> createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
203 void paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, Qgis::RenderUnit sizeUnit, PointSymbol symbol );
204 void paintLine( QPainter *p, QgsPolylineXY line );
205 void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
206 QgsRenderContext createRenderContext();
207
208 int mWidth = 1; // line / stroke width property
209 QColor mColor; // line / stroke color property
210 QColor mFillColor; // line / stroke fillColor property
211 QBrush mBrush;
212 QPen mPen;
213 QgsGeometry mOriginalGeometry;
214 QgsGeometry mGeometry;
215 QPointer<QgsMapLayer> mLayer;
216 QgsFeature mFeature;
217 double mBuffer = 0; // line / stroke buffer in millimeters
218 double mMinWidth = 0; // line / stroke minimum width in millimeters
219 QgsRenderContext mRenderContext;
220
221 // we don't want to make PointSymbol public for now, so just grant access selectively via a friend
224 double mPointSizeRadiusMM = 1.5;
225 PointSymbol mPointSymbol = PointSymbol::Square;
226};
227
228#endif
RenderUnit
Rendering size units.
Definition qgis.h:5183
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
A geometry is the spatial representation of a feature.
friend class QgsMapToolAddFeature
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
double buffer() const
Returns the line/stroke buffer size (in millimeters).
QgsHighlight(QgsMapCanvas *mapCanvas, const QgsGeometry &geom, QgsMapLayer *layer)
Constructor for QgsHighlight.
void setBuffer(double buffer)
Sets the line/stroke buffer size (in millimeters).
QColor fillColor
friend class QgsUpdateGpsDetailsAction
int width() const
Returns the stroke width.
QColor fillColor() const
Returns the fill color.
void setMinWidth(double width)
Sets the minimum line/stroke width (in millimeters).
void setFillColor(const QColor &fillColor)
Fill color for the highlight.
void setWidth(int width)
Set stroke width.
void setColor(const QColor &color)
Set line/stroke to color, polygon fill to color with alpha = 63.
QgsMapCanvasItem(QgsMapCanvas *mapCanvas)
protected constructor: cannot be constructed directly
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
Represents a vector layer which manages a vector based dataset.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:216
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition qgsgeometry.h:90
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:61