QGIS API Documentation 3.43.0-Master (4c60628727b)
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
31class QgsMapLayer;
32class QgsVectorLayer;
33class QgsSymbol;
35
36
37#ifdef SIP_RUN
38//%ModuleHeaderCode
39// For ConvertToSubClassCode.
40#include <qgshighlight.h>
41//%End
42#endif
43
60#ifndef SIP_RUN
61class GUI_EXPORT QgsHighlight : public QObject, public QgsMapCanvasItem
62{
63#else
64class 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;
83#endif
84 public:
85 Q_PROPERTY( QColor color READ color WRITE setColor )
86 Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
87 Q_PROPERTY( int width READ width WRITE setWidth )
88 Q_PROPERTY( int buffer READ buffer WRITE setBuffer )
89
96 QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsGeometry &geom, QgsMapLayer *layer );
97
105 QgsHighlight( QgsMapCanvas *mapCanvas SIP_TRANSFERTHIS, const QgsFeature &feature, QgsVectorLayer *layer );
106 ~QgsHighlight() override;
107
112 QColor color() const { return mColor; }
113
118 void setColor( const QColor &color );
119
124 QColor fillColor() const { return mFillColor; }
125
131 void setFillColor( const QColor &fillColor );
132
137 int width() const { return mWidth; }
138
144 void setWidth( int width );
145
153 double buffer() const { return mBuffer; }
154
160 void setBuffer( double buffer ) { mBuffer = buffer; }
161
165 void setMinWidth( double width ) { mMinWidth = width; }
166
170 QgsMapLayer *layer() const { return mLayer; }
171
172 void updatePosition() override;
173
179 void applyDefaultStyle();
180
181 protected:
182 void paint( QPainter *p ) override;
183
185 void updateRect();
186
187 private slots:
188 void updateTransformedGeometry();
189
190 private:
191 enum PointSymbol
192 {
193 Square,
194 Circle
195 };
196
197 void init();
198 void setSymbol( QgsSymbol *symbol, const QgsRenderContext &context, const QColor &color, const QColor &fillColor );
199 double getSymbolWidth( const QgsRenderContext &context, double width, Qgis::RenderUnit unit );
201 std::unique_ptr<QgsFeatureRenderer> createRenderer( QgsRenderContext &context, const QColor &color, const QColor &fillColor );
202 void paintPoint( QgsRenderContext &context, const QgsPoint *point, double size, Qgis::RenderUnit sizeUnit, PointSymbol symbol );
203 void paintLine( QPainter *p, QgsPolylineXY line );
204 void paintPolygon( QPainter *p, const QgsPolygonXY &polygon );
205 QgsRenderContext createRenderContext();
206
207 int mWidth = 1; // line / stroke width property
208 QColor mColor; // line / stroke color property
209 QColor mFillColor; // line / stroke fillColor property
210 QBrush mBrush;
211 QPen mPen;
212 QgsGeometry mOriginalGeometry;
213 QgsGeometry mGeometry;
214 QPointer<QgsMapLayer> mLayer;
215 QgsFeature mFeature;
216 double mBuffer = 0; // line / stroke buffer in millimeters
217 double mMinWidth = 0; // line / stroke minimum width in millimeters
218 QgsRenderContext mRenderContext;
219
220 // we don't want to make PointSymbol public for now, so just grant access selectively via a friend
221 friend class QgsMapToolAddFeature;
222 friend class QgsUpdateGpsDetailsAction;
223 double mPointSizeRadiusMM = 1.5;
224 PointSymbol mPointSymbol = PointSymbol::Square;
225};
226
227#endif
RenderUnit
Rendering size units.
Definition qgis.h:5029
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.
Highlights features on the map.
QgsMapLayer * layer() const
Returns the layer for which this highlight has been created.
double buffer() const
Returns the line/stroke buffer size (in millimeters)
void setBuffer(double buffer)
Sets the line/stroke buffer size (in millimeters).
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).
An abstract class for items that can be placed on the map canvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:77
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Contains information about the context of a rendering operation.
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:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:208
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition qgsgeometry.h:74
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Definition qgsgeometry.h:62