QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsvertexmarker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvertexmarker.cpp - canvas item which shows a simple vertex marker
3  ---------------------
4  begin : February 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
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 
16 #include <QPainter>
17 
18 #include "qgsvertexmarker.h"
19 
20 
22  : QgsMapCanvasItem( mapCanvas )
23 {}
24 
26 {
27  mIconType = type;
28 }
29 
30 void QgsVertexMarker::setIconSize( int iconSize )
31 {
32  mIconSize = iconSize;
33 }
34 
36 {
37  mCenter = point;
38  QPointF pt = toCanvasCoordinates( mCenter );
39  setPos( pt );
40 }
41 
42 void QgsVertexMarker::setColor( const QColor &color )
43 {
44  mColor = color;
45  update();
46 }
47 
48 void QgsVertexMarker::setFillColor( const QColor &color )
49 {
50  mFillColor = color;
51  update();
52 }
53 
55 {
56  mPenWidth = width;
57 }
58 
59 void QgsVertexMarker::paint( QPainter *p )
60 {
61  qreal s = ( mIconSize - 1 ) / 2.0;
62 
63  QPen pen( mColor );
64  pen.setWidth( mPenWidth );
65  p->setPen( pen );
66  QBrush brush( mFillColor );
67  p->setBrush( brush );
68 
69  switch ( mIconType )
70  {
71  case ICON_NONE:
72  break;
73 
74  case ICON_CROSS:
75  p->drawLine( QLineF( -s, 0, s, 0 ) );
76  p->drawLine( QLineF( 0, -s, 0, s ) );
77  break;
78 
79  case ICON_X:
80  p->drawLine( QLineF( -s, -s, s, s ) );
81  p->drawLine( QLineF( -s, s, s, -s ) );
82  break;
83 
84  case ICON_BOX:
85  p->drawLine( QLineF( -s, -s, s, -s ) );
86  p->drawLine( QLineF( s, -s, s, s ) );
87  p->drawLine( QLineF( s, s, -s, s ) );
88  p->drawLine( QLineF( -s, s, -s, -s ) );
89  break;
90 
91  case ICON_CIRCLE:
92  p->drawEllipse( QPointF( 0, 0 ), s, s );
93  break;
94 
96  p->drawLine( QLineF( -s, -s, s, -s ) );
97  p->drawLine( QLineF( -s, s, s, s ) );
98  p->drawLine( QLineF( -s, -s, s, s ) );
99  p->drawLine( QLineF( s, -s, -s, s ) );
100  break;
101  }
102 }
103 
104 
106 {
107  qreal s = qreal( mIconSize + mPenWidth ) / 2.0;
108  return QRectF( -s, -s, 2.0 * s, 2.0 * s );
109 }
110 
112 {
113  setCenter( mCenter );
114 }
void paint(QPainter *p) override
function to be implemented by derived classes
void updatePosition() override
called on changed extent or resize event to update position of the item
A class to represent a 2D point.
Definition: qgspointxy.h:43
An abstract class for items that can be placed on the map canvas.
void setPenWidth(int width)
QRectF boundingRect() const override
QColor color() const
Returns the stroke color for the marker.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
QgsVertexMarker(QgsMapCanvas *mapCanvas)
void setCenter(const QgsPointXY &point)
void setIconSize(int iconSize)
void setFillColor(const QColor &color)
Sets the fill color for the marker.
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
void setColor(const QColor &color)
Sets the stroke color for the marker.
void setIconType(int iconType)