QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgsfeaturestore.h"
20 #include "qgsgeometry.h"
21 #include "qgsrendererv2.h"
22 #include "qgssymbolv2.h"
23 #include <QBrush>
24 #include <QColor>
25 #include <QList>
26 #include <QPen>
27 #include <QPainter>
28 #include <QPainterPath>
29 
30 class QgsMapLayer;
31 class QgsVectorLayer;
32 class QgsSymbolV2;
33 
37 class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
38 {
39  public:
40  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry *geom, QgsMapLayer *layer );
41  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsGeometry *geom, QgsVectorLayer *layer );
48  QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature& feature, QgsVectorLayer *layer );
49  ~QgsHighlight();
50 
53  void setColor( const QColor & color );
54 
57  void setFillColor( const QColor & fillColor );
58 
60  void setWidth( int width );
61 
64  void setBuffer( double buffer ) { mBuffer = buffer; }
65 
68  void setMinWidth( double width ) { mMinWidth = width; }
69 
70  const QgsMapLayer *layer() const { return mLayer; }
71 
72  virtual void updatePosition() override;
73 
74  protected:
75  virtual void paint( QPainter* p ) override;
76 
78  void updateRect();
79 
80  private:
81  void init();
82  void setSymbol( QgsSymbolV2* symbol, const QgsRenderContext & context, const QColor & color, const QColor & fillColor );
83  double getSymbolWidth( const QgsRenderContext & context, double width, QgsSymbolV2::OutputUnit unit );
85  QgsFeatureRendererV2 * getRenderer( QgsRenderContext &context, const QColor & color, const QColor & fillColor );
86  void paintPoint( QPainter *p, const QgsPoint& point );
87  void paintLine( QPainter *p, QgsPolyline line );
88  void paintPolygon( QPainter *p, QgsPolygon polygon );
89 
90  QBrush mBrush;
91  QPen mPen;
92  QgsGeometry *mGeometry;
93  QgsMapLayer *mLayer;
94  QgsFeature mFeature;
95  double mBuffer; // line / outline buffer in pixels
96  double mMinWidth; // line / outline minimum width in pixels
97 };
98 
99 #endif
Base class for all map layer types.
Definition: qgsmaplayer.h:49
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
An abstract class for items that can be placed on the map canvas.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
void setBuffer(double buffer)
Set line / outline buffer in millimeters.
Definition: qgshighlight.h:64
A class for highlight features on the map.
Definition: qgshighlight.h:37
A class to represent a point.
Definition: qgspoint.h:117
virtual void paint(QPainter *painter)=0
function to be implemented by derived classes
Contains information about the context of a rendering operation.
const QgsMapLayer * layer() const
Definition: qgshighlight.h:70
Represents a vector layer which manages a vector based data sets.
virtual void updatePosition()
called on changed extent or resize event to update position of the item
void setMinWidth(double width)
Set minimum line / outline width in millimeters.
Definition: qgshighlight.h:68